Bug 1353607. P2 - let GetDecodedAudioDuration() return a TimeUnit.
MozReview-Commit-ID: 5pLyACshP3e
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -849,17 +849,17 @@ private:
uint32_t VideoPrerollFrames() const
{
return mMaster->GetAmpleVideoFrames() / 2;
}
bool DonePrerollingAudio()
{
return !mMaster->IsAudioDecoding()
- || mMaster->GetDecodedAudioDuration()
+ || mMaster->GetDecodedAudioDuration().ToMicroseconds()
>= AudioPrerollThreshold().ToMicroseconds() * mMaster->mPlaybackRate;
}
bool DonePrerollingVideo()
{
return !mMaster->IsVideoDecoding()
|| static_cast<uint32_t>(mMaster->VideoQueue().GetSize())
>= VideoPrerollFrames() * mMaster->mPlaybackRate + 1;
@@ -2315,17 +2315,17 @@ DecodingState::NeedToSkipToNextKeyframe(
// we won't start keyframe skipping, as we'll be pausing playback to buffer
// soon anyway and we'll want to be able to display frames immediately
// after buffering finishes. We ignore the low audio calculations for
// readers that are async, as since their audio decode runs on a different
// task queue it should never run low and skipping won't help their decode.
bool isLowOnDecodedAudio =
!Reader()->IsAsync()
&& mMaster->IsAudioDecoding()
- && (mMaster->GetDecodedAudioDuration()
+ && (mMaster->GetDecodedAudioDuration().ToMicroseconds()
< mMaster->mLowAudioThreshold.ToMicroseconds() * mMaster->mPlaybackRate);
bool isLowOnDecodedVideo =
(mMaster->GetClock().ToMicroseconds() - mMaster->mDecodedVideoEndTime)
* mMaster->mPlaybackRate
> LOW_VIDEO_THRESHOLD.ToMicroseconds();
bool lowBuffered = mMaster->HasLowBufferedData();
if ((isLowOnDecodedAudio || isLowOnDecodedVideo) && !lowBuffered) {
@@ -2752,38 +2752,39 @@ MediaDecoderStateMachine::CreateMediaSin
RefPtr<media::MediaSink> mediaSink =
new VideoSink(mTaskQueue, audioSink, mVideoQueue,
mVideoFrameContainer, *mFrameStats,
sVideoQueueSendToCompositorSize);
return mediaSink.forget();
}
-int64_t
+TimeUnit
MediaDecoderStateMachine::GetDecodedAudioDuration()
{
MOZ_ASSERT(OnTaskQueue());
if (mMediaSink->IsStarted()) {
// mDecodedAudioEndTime might be smaller than GetClock() when there is
// overlap between 2 adjacent audio samples or when we are playing
// a chained ogg file.
- return std::max<int64_t>(
+ auto t = std::max<int64_t>(
mDecodedAudioEndTime - GetClock().ToMicroseconds(), 0);
+ return TimeUnit::FromMicroseconds(t);
}
// MediaSink not started. All audio samples are in the queue.
- return AudioQueue().Duration();
+ return TimeUnit::FromMicroseconds(AudioQueue().Duration());
}
bool
MediaDecoderStateMachine::HaveEnoughDecodedAudio()
{
MOZ_ASSERT(OnTaskQueue());
auto ampleAudioUSecs = mAmpleAudioThreshold.ToMicroseconds() * mPlaybackRate;
return AudioQueue().GetSize() > 0
- && GetDecodedAudioDuration() >= ampleAudioUSecs;
+ && GetDecodedAudioDuration().ToMicroseconds() >= ampleAudioUSecs;
}
bool MediaDecoderStateMachine::HaveEnoughDecodedVideo()
{
MOZ_ASSERT(OnTaskQueue());
return VideoQueue().GetSize() >= GetAmpleVideoFrames() * mPlaybackRate + 1;
}
@@ -3302,17 +3303,17 @@ MediaDecoderStateMachine::StartMediaSink
}
}
bool
MediaDecoderStateMachine::HasLowDecodedAudio()
{
MOZ_ASSERT(OnTaskQueue());
return IsAudioDecoding()
- && GetDecodedAudioDuration()
+ && GetDecodedAudioDuration().ToMicroseconds()
< EXHAUSTED_DATA_MARGIN_USECS * mPlaybackRate;
}
bool
MediaDecoderStateMachine::HasLowDecodedVideo()
{
MOZ_ASSERT(OnTaskQueue());
return IsVideoDecoding()
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -454,17 +454,17 @@ protected:
// Returns an upper bound on the number of microseconds of audio that is
// decoded and playable. This is the sum of the number of usecs of audio which
// is decoded and in the reader's audio queue, and the usecs of unplayed audio
// which has been pushed to the audio hardware for playback. Note that after
// calling this, the audio hardware may play some of the audio pushed to
// hardware, so this can only be used as a upper bound. The decoder monitor
// must be held when calling this. Called on the decode thread.
- int64_t GetDecodedAudioDuration();
+ media::TimeUnit GetDecodedAudioDuration();
void FinishDecodeFirstFrame();
// Performs one "cycle" of the state machine.
void RunStateMachine();
bool IsStateMachineScheduled() const;