Bug 1297265: P8. Rework LibVPX Decoder use of InputExhausted. r?kamidphish draft
authorJean-Yves Avenard <jyavenard@mozilla.com>
Tue, 30 Aug 2016 15:21:49 +1000
changeset 407296 ee405c931f9aff7e9b402f7a7bb8969f0dc37352
parent 407295 710efa15803ce3c5548dfbce16579a9d2593d30f
child 407297 29f81944bc870014bcb3036ea4cc9d0c43ae1dbe
push id27921
push userbmo:jyavenard@mozilla.com
push dateTue, 30 Aug 2016 07:23:20 +0000
reviewerskamidphish
bugs1297265
milestone51.0a1
Bug 1297265: P8. Rework LibVPX Decoder use of InputExhausted. r?kamidphish MozReview-Commit-ID: H7KnDpkcaeT
dom/media/platforms/agnostic/VPXDecoder.cpp
--- a/dom/media/platforms/agnostic/VPXDecoder.cpp
+++ b/dom/media/platforms/agnostic/VPXDecoder.cpp
@@ -116,16 +116,17 @@ VPXDecoder::DoDecode(MediaRawData* aSamp
 
   if (vpx_codec_err_t r = vpx_codec_decode(&mVPX, aSample->Data(), aSample->Size(), nullptr, 0)) {
     LOG("VPX Decode error: %s", vpx_codec_err_to_string(r));
     return -1;
   }
 
   vpx_codec_iter_t  iter = nullptr;
   vpx_image_t      *img;
+  bool didOutput = false;
 
   while ((img = vpx_codec_get_frame(&mVPX, &iter))) {
     NS_ASSERTION(img->fmt == VPX_IMG_FMT_I420 ||
                  img->fmt == VPX_IMG_FMT_I444,
                  "WebM image format not I420 or I444");
 
     // Chroma shifts are rounded down as per the decoding examples in the SDK
     VideoData::YCbCrBuffer b;
@@ -174,31 +175,33 @@ VPXDecoder::DoDecode(MediaRawData* aSamp
 
     if (!v) {
       LOG("Image allocation error source %ldx%ld display %ldx%ld picture %ldx%ld",
           img->d_w, img->d_h, mInfo.mDisplay.width, mInfo.mDisplay.height,
           mInfo.mImage.width, mInfo.mImage.height);
       return -1;
     }
     mCallback->Output(v);
+    didOutput = true;
+  }
+  if (!didOutput) {
+    mCallback->InputExhausted();
   }
   return 0;
 }
 
 void
 VPXDecoder::ProcessDecode(MediaRawData* aSample)
 {
   MOZ_ASSERT(mTaskQueue->IsCurrentThreadIn());
   if (mIsFlushing) {
     return;
   }
   if (DoDecode(aSample) == -1) {
     mCallback->Error(MediaDataDecoderError::DECODE_ERROR);
-  } else if (mTaskQueue->IsEmpty()) {
-    mCallback->InputExhausted();
   }
 }
 
 nsresult
 VPXDecoder::Input(MediaRawData* aSample)
 {
   MOZ_ASSERT(mCallback->OnReaderTaskQueue());
   mTaskQueue->Dispatch(NewRunnableMethod<RefPtr<MediaRawData>>(