Bug 1231091. Part 6 - fix test_streams_element_capture.html timeout. r=roc.

This commit is contained in:
JW Wang 2015-12-22 08:42:38 +08:00
Родитель a03dc1e4e1
Коммит bcd91fefed
1 изменённых файлов: 23 добавлений и 1 удалений

Просмотреть файл

@ -166,6 +166,25 @@ VideoSink::Start(int64_t aStartTime, const MediaInfo& aInfo)
if (mHasVideo) {
mEndPromise = mEndPromiseHolder.Ensure(__func__);
// If the underlying MediaSink has an end promise for the video track (which
// happens when mAudioSink refers to a DecodedStream), we must wait for it
// to complete before resolving our own end promise. Otherwise, MDSM might
// stop playback before DecodedStream plays to the end and cause
// test_streams_element_capture.html to time out.
RefPtr<GenericPromise> p = mAudioSink->OnEnded(TrackInfo::kVideoTrack);
if (p) {
RefPtr<VideoSink> self = this;
mVideoSinkEndRequest.Begin(p->Then(mOwnerThread, __func__,
[self] () {
self->mVideoSinkEndRequest.Complete();
self->TryUpdateRenderedVideoFrames();
}, [self] () {
self->mVideoSinkEndRequest.Complete();
self->TryUpdateRenderedVideoFrames();
}));
}
ConnectListener();
// Run the render loop at least once so we can resolve the end promise
// when video duration is 0.
@ -185,6 +204,7 @@ VideoSink::Stop()
mUpdateScheduler.Reset();
if (mHasVideo) {
DisconnectListener();
mVideoSinkEndRequest.DisconnectIfExists();
mEndPromiseHolder.ResolveIfExists(true, __func__);
mEndPromise = nullptr;
}
@ -389,7 +409,9 @@ VideoSink::UpdateRenderedVideoFrames()
}
// All frames are rendered, Let's resolve the promise.
if (VideoQueue().IsFinished() && VideoQueue().GetSize() <= 1) {
if (VideoQueue().IsFinished() &&
VideoQueue().GetSize() <= 1 &&
!mVideoSinkEndRequest.Exists()) {
mEndPromiseHolder.ResolveIfExists(true, __func__);
}