Bug 881512 - Use the base video and audio queues. Currently works by shifting media data from the sub-reader queues on each decode call. Future work could allow the sub-readers to use the base queues directly. r=cajbir
authorMatthew Gregan <kinetik@flim.org>
Tue, 22 Apr 2014 01:33:00 +1200
changeset 180744 199c040d09f0ff14b4a10129e99effe0ec59166f
parent 180743 c116a4499d82d2fd95ef6a0544cc2a1ecb456714
child 180745 5fbc68a34f624ff119a54d6ce981c0f02c3ba977
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewerscajbir
bugs881512
milestone31.0a1
Bug 881512 - Use the base video and audio queues. Currently works by shifting media data from the sub-reader queues on each decode call. Future work could allow the sub-readers to use the base queues directly. r=cajbir
content/media/mediasource/MediaSourceDecoder.cpp
--- a/content/media/mediasource/MediaSourceDecoder.cpp
+++ b/content/media/mediasource/MediaSourceDecoder.cpp
@@ -59,36 +59,61 @@ public:
 
   bool DecodeAudioData() MOZ_OVERRIDE
   {
     if (mActiveAudioReader == -1) {
       MSE_DEBUG("%p DecodeAudioFrame called with no audio reader", this);
       MOZ_ASSERT(mPendingDecoders.IsEmpty());
       return false;
     }
-    return mAudioReaders[mActiveAudioReader]->DecodeAudioData();
+    bool rv = mAudioReaders[mActiveAudioReader]->DecodeAudioData();
+
+    nsAutoTArray<AudioData*, 10> audio;
+    mAudioReaders[mActiveAudioReader]->AudioQueue().GetElementsAfter(-1, &audio);
+    for (uint32_t i = 0; i < audio.Length(); ++i) {
+      AudioQueue().Push(audio[i]);
+    }
+    mAudioReaders[mActiveAudioReader]->AudioQueue().Empty();
+
+    return rv;
   }
 
   bool DecodeVideoFrame(bool& aKeyFrameSkip, int64_t aTimeThreshold) MOZ_OVERRIDE
   {
     if (mActiveVideoReader == -1) {
       MSE_DEBUG("%p DecodeVideoFrame called with no video reader", this);
       MOZ_ASSERT(mPendingDecoders.IsEmpty());
       return false;
     }
     bool rv = mVideoReaders[mActiveVideoReader]->DecodeVideoFrame(aKeyFrameSkip, aTimeThreshold);
+
+    nsAutoTArray<VideoData*, 10> video;
+    mVideoReaders[mActiveVideoReader]->VideoQueue().GetElementsAfter(-1, &video);
+    for (uint32_t i = 0; i < video.Length(); ++i) {
+      VideoQueue().Push(video[i]);
+    }
+    mVideoReaders[mActiveVideoReader]->VideoQueue().Empty();
+
     if (rv) {
       return true;
     }
+
     MSE_DEBUG("%p MSR::DecodeVF %d (%p) returned false (readers=%u)",
               this, mActiveVideoReader, mVideoReaders[mActiveVideoReader], mVideoReaders.Length());
     if (SwitchVideoReaders(aTimeThreshold)) {
-      return mVideoReaders[mActiveVideoReader]->DecodeVideoFrame(aKeyFrameSkip, aTimeThreshold);
+      rv = mVideoReaders[mActiveVideoReader]->DecodeVideoFrame(aKeyFrameSkip, aTimeThreshold);
+
+      nsAutoTArray<VideoData*, 10> video;
+      mVideoReaders[mActiveVideoReader]->VideoQueue().GetElementsAfter(-1, &video);
+      for (uint32_t i = 0; i < video.Length(); ++i) {
+        VideoQueue().Push(video[i]);
+      }
+      mVideoReaders[mActiveVideoReader]->VideoQueue().Empty();
     }
-    return false;
+    return rv;
   }
 
   bool HasVideo() MOZ_OVERRIDE
   {
     return mInfo.HasVideo();
   }
 
   bool HasAudio() MOZ_OVERRIDE
@@ -115,42 +140,16 @@ public:
       nsRefPtr<dom::TimeRanges> r = new dom::TimeRanges();
       mAudioReaders[i]->GetBuffered(r, aStartTime);
       aBuffered->Add(r->GetStartTime(), r->GetEndTime());
     }
     aBuffered->Normalize();
     return NS_OK;
   }
 
-  MediaQueue<AudioData>& AudioQueue() MOZ_OVERRIDE
-  {
-    // TODO: Share AudioQueue with SubReaders.
-    for (uint32_t i = 0; i < mAudioReaders.Length(); ++i) {
-      MediaQueue<AudioData>& audioQueue = mAudioReaders[i]->AudioQueue();
-      // Empty existing queues in order.
-      if (audioQueue.GetSize() > 0) {
-        return audioQueue;
-      }
-    }
-    return MediaDecoderReader::AudioQueue();
-  }
-
-  MediaQueue<VideoData>& VideoQueue() MOZ_OVERRIDE
-  {
-    // TODO: Share VideoQueue with SubReaders.
-    for (uint32_t i = 0; i < mVideoReaders.Length(); ++i) {
-      MediaQueue<VideoData>& videoQueue = mVideoReaders[i]->VideoQueue();
-      // Empty existing queues in order.
-      if (videoQueue.GetSize() > 0) {
-        return videoQueue;
-      }
-    }
-    return MediaDecoderReader::VideoQueue();
-  }
-
   already_AddRefed<SubBufferDecoder> CreateSubDecoder(const nsACString& aType,
                                                       MediaSourceDecoder* aParentDecoder);
 
 private:
   bool SwitchVideoReaders(int64_t aTimeThreshold) {
     MOZ_ASSERT(mActiveVideoReader != -1);
     // XXX: We switch when the first reader is depleted, but it might be
     // better to switch as soon as the next reader is ready to decode and