Bug 1002404 - Register subdecoders earlier to avoid missing initialization. r=cajbir
authorMatthew Gregan <kinetik@flim.org>
Mon, 28 Apr 2014 23:07:00 +1200
changeset 180745 b7be54db9ede
parent 180744 acea3d22d5b0
child 180746 b9f981ab229c
push id26680
push userryanvm@gmail.com
push dateTue, 29 Apr 2014 20:39:44 +0000
treeherdermozilla-central@ea9a192b47ac [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscajbir
bugs1002404
milestone32.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 1002404 - Register subdecoders earlier to avoid missing initialization. r=cajbir
content/media/mediasource/SourceBuffer.cpp
content/media/mediasource/SourceBuffer.h
--- a/content/media/mediasource/SourceBuffer.cpp
+++ b/content/media/mediasource/SourceBuffer.cpp
@@ -312,24 +312,27 @@ SourceBuffer::SourceBuffer(MediaSource* 
   : DOMEventTargetHelper(aMediaSource->GetParentObject())
   , mMediaSource(aMediaSource)
   , mType(aType)
   , mAppendWindowStart(0)
   , mAppendWindowEnd(PositiveInfinity<double>())
   , mTimestampOffset(0)
   , mAppendMode(SourceBufferAppendMode::Segments)
   , mUpdating(false)
+  , mDecoderInit(false)
 {
   MOZ_ASSERT(aMediaSource);
   if (mType.EqualsIgnoreCase("video/webm") || mType.EqualsIgnoreCase("audio/webm")) {
     mParser = new WebMContainerParser();
   } else {
     // XXX: Plug in parsers for MPEG4, etc. here.
     mParser = new ContainerParser();
   }
+  MSE_DEBUG("%p SourceBuffer: Creating initial decoder.", this);
+  InitNewDecoder();
 }
 
 already_AddRefed<SourceBuffer>
 SourceBuffer::Create(MediaSource* aMediaSource, const nsACString& aType)
 {
   nsRefPtr<SourceBuffer> sourceBuffer = new SourceBuffer(aMediaSource, aType);
   return sourceBuffer.forget();
 }
@@ -417,24 +420,27 @@ SourceBuffer::AppendData(const uint8_t* 
   if (mMediaSource->ReadyState() == MediaSourceReadyState::Ended) {
     mMediaSource->SetReadyState(MediaSourceReadyState::Open);
   }
   // TODO: Run coded frame eviction algorithm.
   // TODO: Test buffer full flag.
   StartUpdating();
   // TODO: Run buffer append algorithm asynchronously (would call StopUpdating()).
   if (!mDecoder || mParser->IsInitSegmentPresent(aData, aLength)) {
-    MSE_DEBUG("%p AppendBuffer: New initialization segment, creating decoder.", this);
-    if (mDecoder) {
+    if (!mDecoder || mDecoderInit) {
+      MSE_DEBUG("%p AppendBuffer: New initialization segment, creating decoder.", this);
       mDecoder->GetResource()->Ended();
+
+      if (!InitNewDecoder()) {
+        aRv.Throw(NS_ERROR_FAILURE); // XXX: Review error handling.
+        return;
+      }
     }
-    if (!InitNewDecoder()) {
-      aRv.Throw(NS_ERROR_FAILURE); // XXX: Review error handling.
-      return;
-    }
+    MSE_DEBUG("%p AppendBuffer: Decoder marked as initialized.", this);
+    mDecoderInit = true;
   }
   // XXX: For future reference: NDA call must run on the main thread.
   mDecoder->NotifyDataArrived(reinterpret_cast<const char*>(aData),
                               aLength,
                               mDecoder->GetResource()->GetLength());
   mDecoder->GetResource()->AppendData(aData, aLength);
 
   // Eviction uses a byte threshold. If the buffer is greater than the
--- a/content/media/mediasource/SourceBuffer.h
+++ b/content/media/mediasource/SourceBuffer.h
@@ -144,14 +144,16 @@ private:
 
   double mAppendWindowStart;
   double mAppendWindowEnd;
 
   double mTimestampOffset;
 
   SourceBufferAppendMode mAppendMode;
   bool mUpdating;
+
+  bool mDecoderInit;
 };
 
 } // namespace dom
 
 } // namespace mozilla
 #endif /* mozilla_dom_SourceBuffer_h_ */