Bug 894341 - Stop encoding data when the eos flag has written to ContainerWriter. r=roc
authorShelly Lin <slin@mozilla.com>
Mon, 29 Jul 2013 14:29:08 +0800
changeset 153035 84806fd237c051bf2d2965c275fc7445321015ff
parent 153034 89ce7c357c1cd55929ca1e62017c1179cf5da738
child 153036 9b6901ab265290830d6b4ae23d6e1f157545848a
push id2859
push userakeybl@mozilla.com
push dateMon, 16 Sep 2013 19:14:59 +0000
treeherdermozilla-beta@87d3c51cd2bf [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs894341
milestone25.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 894341 - Stop encoding data when the eos flag has written to ContainerWriter. r=roc
content/media/encoder/MediaEncoder.cpp
content/media/encoder/OpusTrackEncoder.cpp
--- a/content/media/encoder/MediaEncoder.cpp
+++ b/content/media/encoder/MediaEncoder.cpp
@@ -179,17 +179,16 @@ MediaEncoder::GetEncodedData(nsTArray<ns
           break;
         }
 
         rv = mWriter->GetContainerData(aOutputBufs,
                                        ContainerWriter::FLUSH_NEEDED);
         if (NS_SUCCEEDED(rv)) {
           // Successfully get the copy of final container data from writer.
           reloop = false;
-          break;
         }
       } else {
         // No more headers, starts to encode tracks.
         mState = ENCODE_TRACK;
       }
       break;
     }
 
@@ -214,17 +213,16 @@ MediaEncoder::GetEncodedData(nsTArray<ns
       }
 
       rv = mWriter->GetContainerData(aOutputBufs,
                                      mAudioEncoder->IsEncodingComplete() ?
                                      ContainerWriter::FLUSH_NEEDED : 0);
       if (NS_SUCCEEDED(rv)) {
         // Successfully get the copy of final container data from writer.
         reloop = false;
-        break;
       }
 
       mState = (mAudioEncoder->IsEncodingComplete()) ? ENCODE_DONE : ENCODE_TRACK;
       break;
     }
 
     case ENCODE_DONE:
       LOG("MediaEncoder has been shutdown.");
--- a/content/media/encoder/OpusTrackEncoder.cpp
+++ b/content/media/encoder/OpusTrackEncoder.cpp
@@ -178,17 +178,17 @@ OpusTrackEncoder::GetHeader(nsTArray<uin
   {
     // Wait if mEncoder is not initialized.
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
     while (!mCanceled && !mEncoder) {
       mReentrantMonitor.Wait();
     }
   }
 
-  if (mCanceled) {
+  if (mCanceled || mDoneEncoding) {
     return NS_ERROR_FAILURE;
   }
 
   switch (mEncoderState) {
   case ID_HEADER:
   {
     mLookahead = 0;
     int error = opus_encoder_ctl(mEncoder, OPUS_GET_LOOKAHEAD(&mLookahead));
@@ -237,17 +237,17 @@ OpusTrackEncoder::GetEncodedTrack(nsTArr
     // Wait if mEncoder is not initialized, or when not enough raw data, but is
     // not the end of stream nor is being canceled.
     while (!mCanceled && (!mEncoder || (mRawSegment->GetDuration() +
            mSourceSegment->GetDuration() < GetPacketDuration() &&
            !mEndOfStream))) {
       mReentrantMonitor.Wait();
     }
 
-    if (mCanceled) {
+    if (mCanceled || mDoneEncoding) {
       return NS_ERROR_FAILURE;
     }
 
     mSourceSegment->AppendFrom(mRawSegment);
 
     // Pad |mLookahead| samples to the end of source stream to prevent lost of
     // original data, the pcm duration will be calculated at rate 48K later.
     if (mEndOfStream) {