Bug 1378691 P4 - skip to next key frame if the playback position is very close to it; r=jwwang

MozReview-Commit-ID: Gm0iZAHVLpS

--HG--
extra : rebase_source : e1bc9da5b809cba474983b804085dca21473b3ac
This commit is contained in:
Kaku Kuo 2017-07-12 17:03:45 +08:00
parent 4175fed6b6
commit 5547aba3cd

View File

@ -1816,10 +1816,27 @@ protected:
void RequestVideoData() override
{
MOZ_ASSERT(!mDoneVideoSeeking);
mMaster->RequestVideoData(GetSeekTarget());
const auto& clock = mMaster->mMediaSink->IsStarted()
? mMaster->GetClock()
: mMaster->GetMediaTime();
const auto& nextKeyFrameTime = GetNextKeyFrameTime();
auto threshold = clock;
if (nextKeyFrameTime.IsValid() &&
clock >= (nextKeyFrameTime - sSkipToNextKeyFrameThreshold)) {
threshold = nextKeyFrameTime;
}
mMaster->RequestVideoData(threshold);
}
private:
// Trigger skip to next key frame if the current playback position is very
// close the next key frame's time.
static constexpr TimeUnit sSkipToNextKeyFrameThreshold = TimeUnit::FromMicroseconds(5000);
// If the media is playing, drop video until catch up playback position.
media::TimeUnit GetSeekTarget() const override
{
@ -1827,8 +1844,26 @@ private:
? mMaster->GetClock()
: mSeekJob.mTarget->GetTime();
}
media::TimeUnit GetNextKeyFrameTime() const
{
// We only call this method in RequestVideoData() and we only request video
// data if we haven't done video seeking.
MOZ_DIAGNOSTIC_ASSERT(!mDoneVideoSeeking);
MOZ_DIAGNOSTIC_ASSERT(mMaster->VideoQueue().GetSize() == 0);
if (mFirstVideoFrameAfterSeek) {
return mFirstVideoFrameAfterSeek->NextKeyFrameTime();
}
return TimeUnit::Invalid();
}
};
constexpr TimeUnit
MediaDecoderStateMachine::VideoOnlySeekingState::sSkipToNextKeyFrameThreshold;
RefPtr<MediaDecoder::SeekPromise>
MediaDecoderStateMachine::DormantState::HandleSeek(SeekTarget aTarget)
{