Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[sailfishos][gecko] Buffer when the video decoder lags behind. Fixes …
…JB#51730 MediaFormatReader assumes that decoders will only process one frame at a time, so it won't provide the extra frames that droidmedia needs when the stream switches to a higher resolution. For non-adaptive streams, preroll will make sure there's already enough of a lag. If we run out of decoded frames, then enter the buffering state even if we're waiting for the decoder. Stay in that state until we have ample frames again.
- Loading branch information
Showing
2 changed files
with
66 additions
and
0 deletions.
There are no files selected for viewing
65 changes: 65 additions & 0 deletions
65
rpm/0050-sailfishos-gecko-Buffer-when-the-video-decoder-lags-.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
From 65a5eb298c442386afe4de0b7ba03eb84f1f39f5 Tue, 24 Nov 2020 11:56:06 +0100 | ||
From: Andrew Branson <andrew.branson@jolla.com> | ||
Date: Tue, 24 Nov 2020 11:55:44 +0100 | ||
Subject: [PATCH] [sailfishos][gecko] Buffer when the video decoder lags behind. Fixes JB#51730 | ||
|
||
|
||
MediaFormatReader assumes that decoders will only process one frame at a | ||
time, so it won't provide the extra frames that droidmedia needs when | ||
the stream switches to a higher resolution. For non-adaptive streams, | ||
preroll will make sure there's already enough of a lag. | ||
|
||
If we run out of decoded frames, then enter the buffering state even if | ||
we're waiting for the decoder. Stay in that state until we have ample | ||
frames again. | ||
|
||
diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp | ||
index 0d5556d..ae4f437 100644 | ||
--- a/dom/media/MediaDecoderStateMachine.cpp | ||
+++ b/dom/media/MediaDecoderStateMachine.cpp | ||
@@ -2207,7 +2207,8 @@ | ||
|
||
// Note we could have a wait promise pending when playing non-MSE EME. | ||
if ((mMaster->OutOfDecodedAudio() && mMaster->IsWaitingAudioData()) || | ||
- (mMaster->OutOfDecodedVideo() && mMaster->IsWaitingVideoData())) { | ||
+ mMaster->OutOfDecodedVideo()) { | ||
+ // Can still buffer if the video codec doesn't have enough data | ||
SetState<BufferingState>(); | ||
return; | ||
} | ||
@@ -2291,13 +2292,14 @@ | ||
// With buffering heuristics, we exit buffering state when we: | ||
// 1. can play through or | ||
// 2. time out (specified by mBufferingWait) or | ||
- // 3. have enough buffered data. | ||
+ // 3. have enough buffered data (allow a larger head start for video streams). | ||
TimeDuration elapsed = now - mBufferingStart; | ||
TimeDuration timeout = | ||
TimeDuration::FromSeconds(mBufferingWait * mMaster->mPlaybackRate); | ||
bool stopBuffering = | ||
mMaster->mCanPlayThrough || elapsed >= timeout || | ||
- !mMaster->HasLowBufferedData(TimeUnit::FromSeconds(mBufferingWait)); | ||
+ (!mMaster->HasLowBufferedData(TimeUnit::FromSeconds(mBufferingWait)) && !mMaster->HasVideo()) || | ||
+ mMaster->HaveEnoughDecodedVideo(); | ||
if (!stopBuffering) { | ||
SLOG("Buffering: wait %ds, timeout in %.3lfs", mBufferingWait, | ||
mBufferingWait - elapsed.ToSeconds()); | ||
diff --git a/dom/media/MediaFormatReader.cpp b/dom/media/MediaFormatReader.cpp | ||
index bbedb53..65ea3b2 100644 | ||
--- a/dom/media/MediaFormatReader.cpp | ||
+++ b/dom/media/MediaFormatReader.cpp | ||
@@ -1960,11 +1960,12 @@ | ||
bool MediaFormatReader::NeedInput(DecoderData& aDecoder) { | ||
// The decoder will not be fed a new raw sample until the current decoding | ||
// requests has completed. | ||
+ // Above restriction removed as gmp-droid always needs more samples | ||
return (aDecoder.HasPromise() || aDecoder.mTimeThreshold.isSome()) && | ||
!aDecoder.HasPendingDrain() && !aDecoder.HasFatalError() && | ||
!aDecoder.mDemuxRequest.Exists() && !aDecoder.mOutput.Length() && | ||
- !aDecoder.HasInternalSeekPending() && | ||
- !aDecoder.mDecodeRequest.Exists(); | ||
+ !aDecoder.HasInternalSeekPending(); | ||
+ // !aDecoder.mDecodeRequest.Exists(); | ||
} | ||
|
||
void MediaFormatReader::ScheduleUpdate(TrackType aTrack) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters