Closed Bug 1053008 Opened 10 years ago Closed 10 years ago

MediaDecoderStateMachine::FlushDecoding() not giving ResetDecode a chance to run

Categories

(Core :: Audio/Video, defect)

29 Branch
defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla34

People

(Reporter: cpearce, Assigned: cpearce)

References

Details

Attachments

(1 file, 1 obsolete file)

Spin off from bug 1046837

https://bugzilla.mozilla.org/show_bug.cgi?id=1046837#c38

> mDecodeTaskQueue->Flush(); at [1] is suspicious to me.
> 
> Flush() doesn't guarantee MediaDecoderReader::ResetDecode() dispatched above
> will be executed. It looks like we should call AwaitIdle() or reverse the
> order of Flush()/MediaDecoderReader::ResetDecode().
> 
> 
> [1]
> http://hg.mozilla.org/mozilla-central/file/e6614d8d85f9/content/media/
> MediaDecoderStateMachine.cpp#l2462


(In reply to Chris Pearce (:cpearce) from comment #48)
> (In reply to JW Wang [:jwwang] from comment #38)
> > mDecodeTaskQueue->Flush(); at [1] is suspicious to me.
> > 
> > Flush() doesn't guarantee MediaDecoderReader::ResetDecode() dispatched above
> > will be executed. It looks like we should call AwaitIdle() or reverse the
> > order of Flush()/MediaDecoderReader::ResetDecode().
> 
> You're right. That Flush() should be an AwaitIdle(). Good catch!
> 
> The idea here was to purge events in the task queue that would deliver
> samples. But in hindsight, I don't think that's safe; the Reader may be
> using the task queue for something else, and it will likely not expect this
> behaviour.
Flags: needinfo?(cpearce)
The purpose of Flush() is to abort any existing decoding tasks (since SHUTDOWN doesn't care about it anymore) so that SHUTDOWN can proceed as fast as possible. It looks sub-optimal for AwaitIdle() waits for decoding tasks to finish which we don't need anymore during SHUTDOWN.

However, I don't think it will make a noticable difference as long as the machine runs fast enough.
Btw, for the async behavior of Request{Audio|Video}Data (though it is not truly async for now), it is possible for tasks to be enqueued and run later than MediaDecoderReader::ResetDecode which is the situation we want to prevent.
Yeah. Based on the comment there, we do need the Flush(), otherwise we get problems on B2G... I recall I got backed out without the Flush there.

We could do Flush(), syncDispatch(ResetDecode task), Flush().
Flags: needinfo?(cpearce)
Sounds promising. Given the code complexity of our media stack, I would also like to add some assertions to ensure the code flow proceed as expected and no tasks enqueued/run after the 2nd Flush().
Attached patch WIP Patch (obsolete) — Splinter Review
Here's a WIP patch. Once Try re-opens, we can test this cross platforms easier...
Compile errors in first push, trying again:
https://tbpl.mozilla.org/?tree=Try&rev=85a60179fb27
Bug 1033912 will allow running decoding tasks in separate MediaTaskQueues. It is possible for MediaCodecReader::DecodeAudioDataTask() to call GetCallback()->OnAudioDecoded() which will post a task back to |MediaDecoderStateMachine::mDecodeTaskQueue|, even after MediaDecoderReader::ResetDecode() is run. Is that something we want to avoid too?
After a seek, all samples up to the next "discontinuity" are ignored, so if OnAudioDecoded() is called after a seek with data from before the seek, it will just be ignored. The Reader therefore, needs to be careful that after ResetDecode is called, only the first sample that is input and decoded after the ResetDecode() is marked as a discontinuity, not any samples that were pending before the ResetDecode.
Attached patch PatchSplinter Review
Patch; ensure the ResetDecode() task actually runs, and we flush other tasks and reject tasks while flushing.
Attachment #8472074 - Attachment is obsolete: true
Attachment #8473462 - Flags: review?(kinetik)
Attachment #8473462 - Flags: review?(kinetik) → review+
https://hg.mozilla.org/mozilla-central/rev/5211f7049dc0
Status: NEW → RESOLVED
Closed: 10 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla34
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: