Bug 1231091. Part 3 - resolve the end promise when all frames are rendered. r=roc.

This commit is contained in:
JW Wang 2015-12-22 08:42:38 +08:00
parent e3352b92a8
commit 92bb73de79
2 changed files with 26 additions and 4 deletions

View File

@ -183,7 +183,7 @@ VideoSink::Stop()
mUpdateScheduler.Reset();
if (mHasVideo) {
DisconnectListener();
mEndPromiseHolder.Resolve(true, __func__);
mEndPromiseHolder.ResolveIfExists(true, __func__);
mEndPromise = nullptr;
}
mVideoFrameEndTime = -1;
@ -216,7 +216,7 @@ VideoSink::Shutdown()
}
void
VideoSink::OnVideoQueueEvent(RefPtr<MediaData>&& aSample)
VideoSink::OnVideoQueuePushed(RefPtr<MediaData>&& aSample)
{
AssertOwnerThread();
// Listen to push event, VideoSink should try rendering ASAP if first frame
@ -230,6 +230,18 @@ VideoSink::OnVideoQueueEvent(RefPtr<MediaData>&& aSample)
}
}
void
VideoSink::OnVideoQueueFinished()
{
AssertOwnerThread();
// Run render loop if the end promise is not resolved yet.
if (!mUpdateScheduler.IsScheduled() &&
mAudioSink->IsPlaying() &&
!mEndPromiseHolder.IsEmpty()) {
UpdateRenderedVideoFrames();
}
}
void
VideoSink::Redraw()
{
@ -260,7 +272,9 @@ VideoSink::ConnectListener()
{
AssertOwnerThread();
mPushListener = VideoQueue().PushEvent().Connect(
mOwnerThread, this, &VideoSink::OnVideoQueueEvent);
mOwnerThread, this, &VideoSink::OnVideoQueuePushed);
mFinishListener = VideoQueue().FinishEvent().Connect(
mOwnerThread, this, &VideoSink::OnVideoQueueFinished);
}
void
@ -268,6 +282,7 @@ VideoSink::DisconnectListener()
{
AssertOwnerThread();
mPushListener.Disconnect();
mFinishListener.Disconnect();
}
void
@ -371,6 +386,11 @@ VideoSink::UpdateRenderedVideoFrames()
}
}
// All frames are rendered, Let's resolve the promise.
if (VideoQueue().IsFinished() && VideoQueue().GetSize() <= 1) {
mEndPromiseHolder.ResolveIfExists(true, __func__);
}
RenderVideoFrames(mVideoQueueSendToCompositorSize, clockTime, nowTime);
// No next fame to render. There is no need to schedule next render

View File

@ -72,7 +72,8 @@ private:
virtual ~VideoSink();
// VideoQueue listener related.
void OnVideoQueueEvent(RefPtr<MediaData>&& aSample);
void OnVideoQueuePushed(RefPtr<MediaData>&& aSample);
void OnVideoQueueFinished();
void ConnectListener();
void DisconnectListener();
@ -129,6 +130,7 @@ private:
// Event listeners for VideoQueue
MediaEventListener mPushListener;
MediaEventListener mFinishListener;
// True if this sink is going to handle video track.
bool mHasVideo;