Bug 1397307 - P10. Remove uncessary loop. r=gerald
authorJean-Yves Avenard <jyavenard@mozilla.com>
Thu, 14 Sep 2017 14:45:10 +0200
changeset 665558 ba8d3ecc2412f0025e715a8ecd9a527ca44ef5e0
parent 665557 7558fb4b16997621dab4b82e3dd0a5d81e0c4488
child 665559 6cf651d919d1aa049d0b88c1ca8f91c0c33ee56b
push id80115
push userbmo:eoger@fastmail.com
push dateFri, 15 Sep 2017 18:29:01 +0000
reviewersgerald
bugs1397307
milestone57.0a1
Bug 1397307 - P10. Remove uncessary loop. r=gerald We only process a demuxed sample at a time. Waiting until one is decoded to do the next pending ones. MozReview-Commit-ID: JlXhyPzso8U
dom/media/MediaFormatReader.cpp
--- a/dom/media/MediaFormatReader.cpp
+++ b/dom/media/MediaFormatReader.cpp
@@ -2042,99 +2042,95 @@ MediaFormatReader::HandleDemuxedSamples(
     LOGV("Decoder operation in progress, let it complete.");
     return;
   }
 
   if (decoder.mQueuedSamples.IsEmpty()) {
     return;
   }
 
-  // Decode all our demuxed frames.
-  while (decoder.mQueuedSamples.Length()) {
-    RefPtr<MediaRawData> sample = decoder.mQueuedSamples[0];
-    const RefPtr<TrackInfoSharedPtr> info = sample->mTrackInfo;
-
-    if (info && decoder.mLastStreamSourceID != info->GetID()) {
-      nsTArray<RefPtr<MediaRawData>> samples;
-      if (decoder.mDecoder) {
-        bool recyclable = MediaPrefs::MediaDecoderCheckRecycling() &&
-                          decoder.mDecoder->SupportDecoderRecycling();
-        if (!recyclable && decoder.mTimeThreshold.isNothing() &&
-            (decoder.mNextStreamSourceID.isNothing() ||
-             decoder.mNextStreamSourceID.ref() != info->GetID())) {
-          LOG("%s stream id has changed from:%d to:%d, draining decoder.",
-              TrackTypeToStr(aTrack),
-              decoder.mLastStreamSourceID,
-              info->GetID());
-          decoder.RequestDrain();
-          decoder.mNextStreamSourceID = Some(info->GetID());
-          ScheduleUpdate(aTrack);
-          return;
-        }
-
-        // If flushing is required, it will clear our array of queued samples.
-        // So we may need to make a copy.
-        samples = decoder.mQueuedSamples;
-        if (!recyclable) {
-          LOG("Decoder does not support recycling, recreate decoder.");
-          ShutdownDecoder(aTrack);
-        } else if (decoder.HasWaitingPromise()) {
-          decoder.Flush();
-        }
-      }
-
-      LOG("%s stream id has changed from:%d to:%d.",
-          TrackTypeToStr(aTrack),
-          decoder.mLastStreamSourceID,
-          info->GetID());
-
-      decoder.mNextStreamSourceID.reset();
-      decoder.mLastStreamSourceID = info->GetID();
-      decoder.mInfo = info;
-
-      decoder.mMeanRate.Reset();
-
-      if (sample->mKeyframe) {
-        if (samples.Length()) {
-          decoder.mQueuedSamples = Move(samples);
-        }
-      } else {
-        auto time = TimeInterval(sample->mTime, sample->GetEndTime());
-        InternalSeekTarget seekTarget =
-          decoder.mTimeThreshold.refOr(InternalSeekTarget(time, false));
-        LOG("Stream change occurred on a non-keyframe. Seeking to:%" PRId64,
-            sample->mTime.ToMicroseconds());
-        InternalSeek(aTrack, seekTarget);
+  RefPtr<MediaRawData> sample = decoder.mQueuedSamples[0];
+  const RefPtr<TrackInfoSharedPtr> info = sample->mTrackInfo;
+
+  if (info && decoder.mLastStreamSourceID != info->GetID()) {
+    nsTArray<RefPtr<MediaRawData>> samples;
+    if (decoder.mDecoder) {
+      bool recyclable = MediaPrefs::MediaDecoderCheckRecycling() &&
+                        decoder.mDecoder->SupportDecoderRecycling();
+      if (!recyclable && decoder.mTimeThreshold.isNothing() &&
+          (decoder.mNextStreamSourceID.isNothing() ||
+            decoder.mNextStreamSourceID.ref() != info->GetID())) {
+        LOG("%s stream id has changed from:%d to:%d, draining decoder.",
+            TrackTypeToStr(aTrack),
+            decoder.mLastStreamSourceID,
+            info->GetID());
+        decoder.RequestDrain();
+        decoder.mNextStreamSourceID = Some(info->GetID());
+        ScheduleUpdate(aTrack);
         return;
       }
+
+      // If flushing is required, it will clear our array of queued samples.
+      // So we may need to make a copy.
+      samples = decoder.mQueuedSamples;
+      if (!recyclable) {
+        LOG("Decoder does not support recycling, recreate decoder.");
+        ShutdownDecoder(aTrack);
+      } else if (decoder.HasWaitingPromise()) {
+        decoder.Flush();
+      }
     }
 
-    // Calculate the average frame rate. The first frame will be accounted
-    // for twice.
-    decoder.mMeanRate.Update(sample->mDuration);
-
-    if (!decoder.mDecoder) {
-      mDecoderFactory->CreateDecoder(aTrack);
+    LOG("%s stream id has changed from:%d to:%d.",
+        TrackTypeToStr(aTrack),
+        decoder.mLastStreamSourceID,
+        info->GetID());
+
+    decoder.mNextStreamSourceID.reset();
+    decoder.mLastStreamSourceID = info->GetID();
+    decoder.mInfo = info;
+
+    decoder.mMeanRate.Reset();
+
+    if (sample->mKeyframe) {
+      if (samples.Length()) {
+        decoder.mQueuedSamples = Move(samples);
+      }
+    } else {
+      auto time = TimeInterval(sample->mTime, sample->GetEndTime());
+      InternalSeekTarget seekTarget =
+        decoder.mTimeThreshold.refOr(InternalSeekTarget(time, false));
+      LOG("Stream change occurred on a non-keyframe. Seeking to:%" PRId64,
+          sample->mTime.ToMicroseconds());
+      InternalSeek(aTrack, seekTarget);
       return;
     }
-
-    LOGV("Input:%" PRId64 " (dts:%" PRId64 " kf:%d)",
-         sample->mTime.ToMicroseconds(), sample->mTimecode.ToMicroseconds(),
-         sample->mKeyframe);
-    decoder.mNumSamplesInput++;
-    decoder.mSizeOfQueue++;
-    if (aTrack == TrackInfo::kVideoTrack) {
-      aA.mStats.mParsedFrames++;
-    }
-
-    DecodeDemuxedSamples(aTrack, sample);
-
-    decoder.mQueuedSamples.RemoveElementAt(0);
-    break;
+  }
+
+  // Calculate the average frame rate. The first frame will be accounted
+  // for twice.
+  decoder.mMeanRate.Update(sample->mDuration);
+
+  if (!decoder.mDecoder) {
+    mDecoderFactory->CreateDecoder(aTrack);
+    return;
   }
+
+  LOGV("Input:%" PRId64 " (dts:%" PRId64 " kf:%d)",
+        sample->mTime.ToMicroseconds(), sample->mTimecode.ToMicroseconds(),
+        sample->mKeyframe);
+  decoder.mNumSamplesInput++;
+  decoder.mSizeOfQueue++;
+  if (aTrack == TrackInfo::kVideoTrack) {
+    aA.mStats.mParsedFrames++;
+  }
+
+  DecodeDemuxedSamples(aTrack, sample);
+
+  decoder.mQueuedSamples.RemoveElementAt(0);
 }
 
 void
 MediaFormatReader::InternalSeek(TrackType aTrack,
                                 const InternalSeekTarget& aTarget)
 {
   MOZ_ASSERT(OnTaskQueue());
   LOG("%s internal seek to %f",