Bug 1106547 - Return EOS after drain is complete, rather than before. r=cpearce, a=sledru
authorAndreas Pehrson <pehrsons@gmail.com>
Mon, 01 Dec 2014 22:10:00 +0100
changeset 242438 fae568d40c7224131bb6e2a7540e26cccc5b310e
parent 242437 139ac36c80f9f5f19a52211f2a0d1ba59c3a0ea7
child 242439 683b0185016af350adbbb14611a8f990c9f7d525
push id4311
push userraliiev@mozilla.com
push dateMon, 12 Jan 2015 19:37:41 +0000
treeherdermozilla-beta@150c9fed433b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce, sledru
bugs1106547
milestone36.0a2
Bug 1106547 - Return EOS after drain is complete, rather than before. r=cpearce, a=sledru
dom/media/fmp4/MP4Reader.cpp
dom/media/fmp4/MP4Reader.h
--- a/dom/media/fmp4/MP4Reader.cpp
+++ b/dom/media/fmp4/MP4Reader.cpp
@@ -578,33 +578,31 @@ MP4Reader::NeedInput(DecoderData& aDecod
 
 void
 MP4Reader::Update(TrackType aTrack)
 {
   MOZ_ASSERT(GetTaskQueue()->IsCurrentThreadIn());
 
   bool needInput = false;
   bool needOutput = false;
-  bool eos = false;
   auto& decoder = GetDecoderData(aTrack);
   nsRefPtr<MediaData> output;
   {
     MonitorAutoLock lock(decoder.mMonitor);
     decoder.mUpdateScheduled = false;
     if (NeedInput(decoder)) {
       needInput = true;
       decoder.mInputExhausted = false;
       decoder.mNumSamplesInput++;
     }
     needOutput = decoder.mOutputRequested;
     if (needOutput && !decoder.mOutput.IsEmpty()) {
       output = decoder.mOutput[0];
       decoder.mOutput.RemoveElementAt(0);
     }
-    eos = decoder.mEOS;
   }
   VLOG("Update(%s) ni=%d no=%d iex=%d or=%d fl=%d",
        TrackTypeToStr(aTrack),
        needInput,
        needOutput,
        decoder.mInputExhausted,
        decoder.mOutputRequested,
        decoder.mIsFlushing);
@@ -612,26 +610,25 @@ MP4Reader::Update(TrackType aTrack)
   if (needInput) {
     MP4Sample* sample = PopSample(aTrack);
     if (sample) {
       decoder.mDecoder->Input(sample);
     } else {
       {
         MonitorAutoLock lock(decoder.mMonitor);
         MOZ_ASSERT(!decoder.mEOS);
-        eos = decoder.mEOS = true;
+        decoder.mEOS = true;
       }
+      // DrainComplete takes care of reporting EOS upwards
       decoder.mDecoder->Drain();
     }
   }
   if (needOutput) {
     if (output) {
       ReturnOutput(output, aTrack);
-    } else if (eos) {
-      ReturnEOS(aTrack);
     }
   }
 }
 
 void
 MP4Reader::ReturnOutput(MediaData* aData, TrackType aTrack)
 {
   auto& decoder = GetDecoderData(aTrack);
@@ -725,19 +722,24 @@ MP4Reader::Output(TrackType aTrack, Medi
     ScheduleUpdate(aTrack);
   }
 }
 
 void
 MP4Reader::DrainComplete(TrackType aTrack)
 {
   DecoderData& data = GetDecoderData(aTrack);
-  MonitorAutoLock mon(data.mMonitor);
-  data.mDrainComplete = true;
-  mon.NotifyAll();
+  bool eos;
+  {
+    MonitorAutoLock mon(data.mMonitor);
+    eos = data.mEOS;
+  }
+  if (eos) {
+    ReturnEOS(aTrack);
+  }
 }
 
 void
 MP4Reader::InputExhausted(TrackType aTrack)
 {
   DecoderData& data = GetDecoderData(aTrack);
   MonitorAutoLock mon(data.mMonitor);
   data.mInputExhausted = true;
@@ -766,17 +768,16 @@ MP4Reader::Flush(TrackType aTrack)
     return;
   }
   // Purge the current decoder's state.
   // Set a flag so that we ignore all output while we call
   // MediaDataDecoder::Flush().
   {
     MonitorAutoLock mon(data.mMonitor);
     data.mIsFlushing = true;
-    data.mDrainComplete = false;
     data.mEOS = false;
   }
   data.mDecoder->Flush();
   {
     MonitorAutoLock mon(data.mMonitor);
     data.mIsFlushing = false;
     data.mOutput.Clear();
     data.mNumSamplesInput = 0;
--- a/dom/media/fmp4/MP4Reader.h
+++ b/dom/media/fmp4/MP4Reader.h
@@ -151,17 +151,16 @@ private:
       : mMonitor(aMonitorName)
       , mNumSamplesInput(0)
       , mNumSamplesOutput(0)
       , mDecodeAhead(aDecodeAhead)
       , mActive(false)
       , mInputExhausted(false)
       , mError(false)
       , mIsFlushing(false)
-      , mDrainComplete(false)
       , mOutputRequested(false)
       , mUpdateScheduled(false)
       , mEOS(false)
       , mDiscontinuity(false)
     {
     }
 
     // The platform decoder.
@@ -181,17 +180,16 @@ private:
     uint64_t mNumSamplesInput;
     uint64_t mNumSamplesOutput;
     uint32_t mDecodeAhead;
     // Whether this stream exists in the media.
     bool mActive;
     bool mInputExhausted;
     bool mError;
     bool mIsFlushing;
-    bool mDrainComplete;
     bool mOutputRequested;
     bool mUpdateScheduled;
     bool mEOS;
     bool mDiscontinuity;
   };
   DecoderData mAudio;
   DecoderData mVideo;
   // Queued samples extracted by the demuxer, but not yet sent to the platform