Bug 1299021. Part 1 - extract the code about resolving the end promise. draft
authorJW Wang <jwwang@mozilla.com>
Mon, 29 Aug 2016 20:56:00 +0800
changeset 407827 1a76a2cd2320a57f59500baa5380559e01a2584f
parent 406939 44168633e9efc6aebea8cc477522209cbdb7319c
child 407828 1982f49c4f6a572c69db6b333884d5799e3e8936
push id28048
push userjwwang@mozilla.com
push dateWed, 31 Aug 2016 02:13:28 +0000
bugs1299021
milestone51.0a1
Bug 1299021. Part 1 - extract the code about resolving the end promise. MozReview-Commit-ID: ECr058zKdUk
dom/media/mediasink/VideoSink.cpp
dom/media/mediasink/VideoSink.h
--- a/dom/media/mediasink/VideoSink.cpp
+++ b/dom/media/mediasink/VideoSink.cpp
@@ -413,22 +413,17 @@ VideoSink::UpdateRenderedVideoFrames()
 
   // The presentation end time of the last video frame displayed is either
   // the end time of the current frame, or if we dropped all frames in the
   // queue, the end time of the last frame we removed from the queue.
   RefPtr<MediaData> currentFrame = VideoQueue().PeekFront();
   mVideoFrameEndTime = std::max(mVideoFrameEndTime,
     currentFrame ? currentFrame->GetEndTime() : lastDisplayedFrameEndTime);
 
-  // All frames are rendered, Let's resolve the promise.
-  if (VideoQueue().IsFinished() &&
-      VideoQueue().GetSize() <= 1 &&
-      !mVideoSinkEndRequest.Exists()) {
-    mEndPromiseHolder.ResolveIfExists(true, __func__);
-  }
+  MaybeResolveEndPromise();
 
   RenderVideoFrames(mVideoQueueSendToCompositorSize, clockTime, nowTime);
 
   // Get the timestamp of the next frame. Schedule the next update at
   // the start time of the next frame. If we don't have a next frame,
   // we will run render loops again upon incoming frames.
   nsTArray<RefPtr<MediaData>> frames;
   VideoQueue().GetFirstElements(2, &frames);
@@ -444,16 +439,28 @@ VideoSink::UpdateRenderedVideoFrames()
   mUpdateScheduler.Ensure(target, [self] () {
     self->UpdateRenderedVideoFramesByTimer();
   }, [self] () {
     self->UpdateRenderedVideoFramesByTimer();
   });
 }
 
 void
+VideoSink::MaybeResolveEndPromise()
+{
+  AssertOwnerThread();
+  // All frames are rendered, Let's resolve the promise.
+  if (VideoQueue().IsFinished() &&
+      VideoQueue().GetSize() <= 1 &&
+      !mVideoSinkEndRequest.Exists()) {
+    mEndPromiseHolder.ResolveIfExists(true, __func__);
+  }
+}
+
+void
 VideoSink::DumpDebugInfo()
 {
   AssertOwnerThread();
   DUMP_LOG(
     "IsStarted=%d IsPlaying=%d, VideoQueue: finished=%d size=%d, "
     "mVideoFrameEndTime=%lld mHasVideo=%d mVideoSinkEndRequest.Exists()=%d "
     "mEndPromiseHolder.IsEmpty()=%d",
     IsStarted(), IsPlaying(), VideoQueue().IsFinished(), VideoQueue().GetSize(),
--- a/dom/media/mediasink/VideoSink.h
+++ b/dom/media/mediasink/VideoSink.h
@@ -94,16 +94,18 @@ private:
 
   // If we have video, display a video frame if it's time for display has
   // arrived, otherwise sleep until it's time for the next frame. Update the
   // current frame time as appropriate, and trigger ready state update.
   // Called on the shared state machine thread.
   void UpdateRenderedVideoFrames();
   void UpdateRenderedVideoFramesByTimer();
 
+  void MaybeResolveEndPromise();
+
   void AssertOwnerThread() const
   {
     MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn());
   }
 
   MediaQueue<MediaData>& VideoQueue() const {
     return mVideoQueue;
   }