Bug 1175058: P1. Properly handle partial init and media header. r=cajbir
authorJean-Yves Avenard <jyavenard@mozilla.com>
Tue, 16 Jun 2015 23:45:16 +1000
changeset 249726 97ace5e97d7b12bd550bff3f70e8269be755d4fa
parent 249725 77dfa576b46420965f4c3dc81736183025501fcb
child 249727 993db9bb30995667ac86c299ceb7047ec35b9454
push id28936
push userryanvm@gmail.com
push dateFri, 19 Jun 2015 20:34:42 +0000
treeherdermozilla-central@c319f262ce3e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscajbir
bugs1175058
milestone41.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 1175058: P1. Properly handle partial init and media header. r=cajbir
dom/media/mediasource/TrackBuffersManager.cpp
--- a/dom/media/mediasource/TrackBuffersManager.cpp
+++ b/dom/media/mediasource/TrackBuffersManager.cpp
@@ -659,30 +659,33 @@ TrackBuffersManager::SegmentParserLoop()
     int64_t start, end;
     mParser->ParseStartAndEndTimestamps(mInputBuffer, start, end);
     mProcessedInput += mInputBuffer->Length();
 
     // 5. If the append state equals PARSING_INIT_SEGMENT, then run the
     // following steps:
     if (mAppendState == AppendState::PARSING_INIT_SEGMENT) {
       if (mParser->InitSegmentRange().IsNull()) {
+        mInputBuffer = nullptr;
         NeedMoreData();
         return;
       }
       InitializationSegmentReceived();
       return;
     }
     if (mAppendState == AppendState::PARSING_MEDIA_SEGMENT) {
       // 1. If the first initialization segment received flag is false, then run the append error algorithm with the decode error parameter set to true and abort this algorithm.
       if (!mFirstInitializationSegmentReceived) {
         RejectAppend(NS_ERROR_FAILURE, __func__);
         return;
       }
       // 2. If the input buffer does not contain a complete media segment header yet, then jump to the need more data step below.
       if (mParser->MediaHeaderRange().IsNull()) {
+        mCurrentInputBuffer->AppendData(mInputBuffer);
+        mInputBuffer = nullptr;
         NeedMoreData();
         return;
       }
       // 3. If the input buffer contains one or more complete coded frames, then run the coded frame processing algorithm.
       nsRefPtr<TrackBuffersManager> self = this;
       mProcessingRequest.Begin(CodedFrameProcessing()
           ->Then(GetTaskQueue(), __func__,
                  [self] (bool aNeedMoreData) {
@@ -757,22 +760,19 @@ TrackBuffersManager::CreateDemuxerforMIM
 
 void
 TrackBuffersManager::InitializationSegmentReceived()
 {
   MOZ_ASSERT(mParser->HasCompleteInitData());
   mInitData = mParser->InitData();
   mCurrentInputBuffer = new SourceBufferResource(mType);
   mCurrentInputBuffer->AppendData(mInitData);
-  uint32_t initLength = mParser->InitSegmentRange().mEnd;
-  if (mInputBuffer->Length() == initLength) {
-    mInputBuffer = nullptr;
-  } else {
-    mInputBuffer->RemoveElementsAt(0, initLength);
-  }
+  uint32_t length =
+    mParser->InitSegmentRange().mEnd - (mProcessedInput - mInputBuffer->Length());
+  mInputBuffer->RemoveElementsAt(0, length);
   CreateDemuxerforMIMEType();
   if (!mInputDemuxer) {
     MOZ_ASSERT(false, "TODO type not supported");
     return;
   }
   mDemuxerInitRequest.Begin(mInputDemuxer->Init()
                       ->Then(GetTaskQueue(), __func__,
                              this,