Bug 1299021. Part 1 - extract the code about resolving the end promise.
MozReview-Commit-ID: ECr058zKdUk
--- 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;
}