Closed
Bug 838315
Opened 13 years ago
Closed 13 years ago
DASH: Fix intermittent mochitest failures on try
Categories
(Core :: Audio/Video, defect)
Core
Audio/Video
Tracking
()
RESOLVED
FIXED
mozilla21
People
(Reporter: sworkman, Assigned: sworkman)
References
Details
Attachments
(1 file)
|
13.58 KB,
patch
|
cpearce
:
review+
|
Details | Diff | Splinter Review |
Mochitest failures on try which are caused by DASH need to be fixed before DASH can be pref'd on.
| Assignee | ||
Comment 1•13 years ago
|
||
A race condition during seeking was discovered during try runs. It requires a lengthy comment to understand - sorry in advance.
Before discussing the problem, it's important to describe the normally observed behavior for switching streams and reading data from the correct one at the right byte offset. Normally, a series of switches during playback decoding are setup when byte ranges complete download to the MediaCache, and DASHDecoder::NotifyDownloadEnded is called. In this latter function, DASHDecoder decides if a switch is needed and which decoder to switch to. Data is downloaded into the cache, and DASHDecoder decides where to download it from - from the media engine point of view, this happens on the main thread. Then, on the decode thread, WebMReader::DecodeVideoFrame calls ::NextPacket to get WebM data from the cache - data is read from the cache, and DASHReader is setup by DASHDecoder to read from the right resource.
Most of the time, this is fine: switching decisions are made on the main thread before DASHReader and WebMReader need to know where to look in the cache. In the code this means that DASHDecoder::NotifyDownloadEnded on the main thread usually precedes WebMReader::DecoderVideoFrame, or more specifically, WebMReader::NextPacket. Note that because WebM frames only have start timestamps, and our VideoData classes require an end timestamp, it is necessary for WebMReader::NextPacket to always query the start time of the next frame. This means that DecodeVideoFrame always reads one WebM packet ahead in order to get the end time of the current frame. (For the last packet of data, WebMReader uses the encoded duration). This read ahead behavior is important to note, because at a switching point, the next packet has to be obtained not only from the next cluster (as cluster boundaries are switch access points), but also from the next reader. As such, this is the earliest point in the WebMReader code when a switch must be known, and the race condition was observed here.
Basically, when a seek happens to just before the end of a cluster, it is possible that the seek could complete and decoding could reach the start of the next cluster before a switching decision has been made. In terms of the code, this means that NextPacket could be called for the start of the next cluster, blocking until the data becomes available, before DASHDecoder::NotifyDownloadEnded has a chance to decide that a switch should take place. The blocking is actually buried in MediaCacheStream::Read, where it waits (using the MediaCache monitor) until ChannelMediaResource gets the data. Since DASHDecoder has decided to download from another stream, this data is not going to be downloaded, and decoding stops.
So, after some analysis, it became apparent that if NextPacket is to follow DASHDecoder's lead, it must wait at cluster boundaries until DASHDecoder::NotifyDownloadEnded has completed its switching decision. I played with other possible solutions, thinking about breaking the block in the media cache, i.e. failing gracefully and purposefully in NextPacket so that it would know to check if it should have switched. However, this doesn't work well if DASHDecoder decided to switch up after the seek, when it didn't during the first downloads - in this case, there would be no blocking in the media cache because data would already be available. In response to that I thought about WebMReader telling DASHDecoder if it had read from that cluster, but this would add two writers to the switching/loading history, and thus additional complexity that seems worse than using a monitor. Thus, I settled on re-using the existing decoder monitor to wait in NextPacket if a switching decision hadn't already been made.
This is the logic in the patch, mostly in WebMReader::NextPacket:
If a switch has been requested, carry on as normal.
If one has not been requested, check if we're at a cluster boundary.
If we are, then check with DASHDecoder (via DASHReader) to see if a switch is desired. Block until DASHDecoder has determined this.
If no switch is requested, carry on as normal, getting packets from this reader's resource.
If a switch is requested, then carry out the setup:
For this reader, call RequestSwitchAtSubsegment, setting up the appropriate vars.
For the next reader, tell it that it needs to seek to the start of the next cluster.
At this point, vars in WebMReader are setup as if a switch was requested from DASHReader, so it is ok to proceed as normal.
This seems to have fixed the issue - I've looped through test_seek for a few hours and no timeout has happened. This is much longer than it was needed to reproduce the timeout without the patch.
There is one potential issue I'm still looking at, in which Fx hangs sometimes at the end. It's not apparent why it's hanging, though, because it's not waiting at the decoder monitor, but instead the Media State thread is waiting in its own event queue. For some reason, MediaDecoder::Observe is not being called for Shutdown. I may need some help with this, specifically to understand the possible shutdown code paths in order to determine what is blocking it.
Let me know what you think.
Attachment #716922 -
Flags: review?(cpearce)
| Assignee | ||
Comment 2•13 years ago
|
||
Try results (still coming in, but looking good at time of posting):
https://tbpl.mozilla.org/?tree=Try&rev=7dd63cc106d0
Updated•13 years ago
|
Attachment #716922 -
Flags: review?(cpearce) → review+
Comment 3•13 years ago
|
||
(In reply to Steve Workman [:sworkman] from comment #1)
> There is one potential issue I'm still looking at, in which Fx hangs
> sometimes at the end. It's not apparent why it's hanging, though, because
> it's not waiting at the decoder monitor, but instead the Media State thread
> is waiting in its own event queue. For some reason, MediaDecoder::Observe is
> not being called for Shutdown. I may need some help with this, specifically
> to understand the possible shutdown code paths in order to determine what is
> blocking it.
Maybe you could try logging when the shutdown observer is added and removed, and ensure that we're not removing it too early or spuriously?
| Assignee | ||
Comment 4•13 years ago
|
||
Thanks for the r+ and advice. Tried that already, but I'll try it again to confirm.
| Assignee | ||
Comment 5•13 years ago
|
||
Pushed to inbound:
https://hg.mozilla.org/integration/mozilla-inbound/rev/6d8a6b1cb711
Landing the code in the tree, but DASH development has been halted.
Comment 6•13 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
You need to log in
before you can comment on or make changes to this bug.
Description
•