Bug 881512 - Switch video readers on EOF. r=cajbir
authorMatthew Gregan <kinetik@flim.org>
Tue, 22 Apr 2014 01:31:00 +1200
changeset 199954 cf3e31d2594483d0e79fd33b592cd4383543fa2c
parent 199953 59ffec98e96f7ada3270aaa2cc770539f5700974
child 199955 a14f9763bf8f8a0ccd0320149514696c1c43197e
push id486
push userasasaki@mozilla.com
push dateMon, 14 Jul 2014 18:39:42 +0000
treeherdermozilla-release@d33428174ff1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscajbir
bugs881512
milestone31.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 881512 - Switch video readers on EOF. r=cajbir
content/media/mediasource/MediaSourceDecoder.cpp
--- a/content/media/mediasource/MediaSourceDecoder.cpp
+++ b/content/media/mediasource/MediaSourceDecoder.cpp
@@ -75,17 +75,19 @@ public:
       return false;
     }
     bool rv = mVideoReaders[mActiveVideoReader]->DecodeVideoFrame(aKeyFrameSkip, aTimeThreshold);
     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);
+    }
     return false;
   }
 
   bool HasVideo() MOZ_OVERRIDE
   {
     return mInfo.HasVideo();
   }
 
@@ -143,16 +145,38 @@ public:
     }
     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
+    // has data for the current media time.
+    ReentrantMonitorAutoEnter mon(mDecoder->GetReentrantMonitor());
+
+    WaitForPendingDecoders();
+
+    if (mVideoReaders.Length() > uint32_t(mActiveVideoReader + 1)) {
+      mActiveVideoReader += 1;
+      MSE_DEBUG("%p MSR::DecodeVF switching to %d", this, mActiveVideoReader);
+
+      MOZ_ASSERT(mVideoReaders[mActiveVideoReader]->GetMediaInfo().HasVideo());
+      mVideoReaders[mActiveVideoReader]->SetActive();
+      mVideoReaders[mActiveVideoReader]->DecodeToTarget(aTimeThreshold);
+
+      return true;
+    }
+    return false;
+  }
+
   bool EnsureWorkQueueInitialized();
   nsresult EnqueueDecoderInitialization();
   void CallDecoderInitialization();
   void WaitForPendingDecoders();
 
   nsTArray<nsRefPtr<SubBufferDecoder>> mPendingDecoders;
   nsTArray<nsRefPtr<SubBufferDecoder>> mDecoders;