[WIP] Bug 1309492 part 2 - tune up the HTMLMediaElement::GetCurrentImage so that is won't return frames produced by the blank decoder module; r?jwwang draft
authorKaku Kuo <kaku@mozilla.com>
Wed, 19 Oct 2016 18:12:47 +0800
changeset 426906 c962f86d2f6dacf0ff3ad937a036f5fcc98a4dc3
parent 426905 777e5a7f41917c33026dbebfdeb6173488eba6e3
child 534308 76f1a69c9976dd92049a677f9fb590b71a04a7f1
push id32846
push userbmo:kaku@mozilla.com
push dateWed, 19 Oct 2016 10:24:14 +0000
reviewersjwwang
bugs1309492
milestone52.0a1
[WIP] Bug 1309492 part 2 - tune up the HTMLMediaElement::GetCurrentImage so that is won't return frames produced by the blank decoder module; r?jwwang MozReview-Commit-ID: CelDMGhzryR
dom/html/HTMLMediaElement.cpp
dom/media/MediaDecoder.cpp
--- a/dom/html/HTMLMediaElement.cpp
+++ b/dom/html/HTMLMediaElement.cpp
@@ -811,25 +811,29 @@ HTMLMediaElement::SetVisible(bool aVisib
 layers::Image*
 HTMLMediaElement::GetCurrentImage()
 {
   ImageContainer* container = GetImageContainer();
   if (!container) {
     return nullptr;
   }
 
+  // Only the first time this method is called should we try to block. After the
+  // first invocation, the video decoder will never be switched to blank decoder
+  // and so we should never need to block again.
+  if (mDecoder && !mHasSuspendTaint) {
+    // If element has a decoder, block and get next decoded image, otherwise use
+    // standard, non-blocking behavior.
+    mDecoder->WaitOnNextRenderedVideoFrame();
+  }
+
   // Mark the decoder owned by the element as tainted so that the video decode
   // won't be suspended. If the decoder is already in suspended state, this will
   // resume decoding.
   mHasSuspendTaint = true;
-  if (mDecoder) {
-    // If element has a decoder, block and get next decoded image, otherwise use
-    // standard, non-blocking behavior.
-    mDecoder->WaitOnNextRenderedVideoFrame();
-  }
 
   AutoLockImage lockImage(container);
   return lockImage.GetImage();
 }
 
 bool
 HTMLMediaElement::HasSuspendTaint() const
 {
--- a/dom/media/MediaDecoder.cpp
+++ b/dom/media/MediaDecoder.cpp
@@ -1308,20 +1308,23 @@ void
 MediaDecoder::DispatchPendingTasks()
 {
   mDecoderStateMachine->DispatchPendingTasks();
 }
 
 void
 MediaDecoder::WaitOnNextRenderedVideoFrame()
 {
-  if (GetImageContainer()->HasCurrentImage()) {
-    SetSuspendTaint(true);
-    return;
-  }
+  // We don't check if the |if (GetImageContainer()->HasCurrentImage())| and
+  // don't return early here because that this method is only called once and
+  // at the first time this method is called, the video decoder could be:
+  // (1) normal decoder: then the monitor will be notified soon at the
+  //                     MediaDecoderStateMachine::SuspendTaintChanged() method.
+  // (2) blank decoder: then the monitor will be notified after the resuming
+  //                    seek is completed.
 
   // Image container doesn't have a valid frame. Wait for the decoder
   // to produce a new frame.
   using WaitForFrame = MediaDecoderStateMachine::WaitForFrame;
   WaitForFrame state{ "WaitOnNextRenderedVideoFrame" };
 
   // Dispatch the variable setting before changing the suspend taint
   // that'll trigger the decoder to start up.