Bug 1352319. P10 - let GetClock() return a TimeUnit.
MozReview-Commit-ID: Efl1FemHOmJ
--- a/dom/media/MediaDecoderStateMachine.cpp
+++ b/dom/media/MediaDecoderStateMachine.cpp
@@ -484,17 +484,17 @@ public:
void Enter()
{
if (mMaster->IsPlaying()) {
mMaster->StopPlayback();
}
// Calculate the position to seek to when exiting dormant.
auto t = mMaster->mMediaSink->IsStarted()
- ? mMaster->GetClock() : mMaster->GetMediaTime().ToMicroseconds();
+ ? mMaster->GetClock() : mMaster->GetMediaTime();
mPendingSeek.mTarget.emplace(t, SeekTarget::Accurate);
// SeekJob asserts |mTarget.IsValid() == !mPromise.IsEmpty()| so we
// need to create the promise even it is not used at all.
RefPtr<MediaDecoder::SeekPromise> x =
mPendingSeek.mPromise.Ensure(__func__);
mMaster->ResetDecode();
mMaster->StopMediaSink();
@@ -2311,17 +2311,17 @@ DecodingState::NeedToSkipToNextKeyframe(
// 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->mLowAudioThreshold.ToMicroseconds() * mMaster->mPlaybackRate);
bool isLowOnDecodedVideo =
- (mMaster->GetClock() - mMaster->mDecodedVideoEndTime)
+ (mMaster->GetClock().ToMicroseconds() - mMaster->mDecodedVideoEndTime)
* mMaster->mPlaybackRate
> LOW_VIDEO_THRESHOLD.ToMicroseconds();
bool lowBuffered = mMaster->HasLowBufferedData();
if ((isLowOnDecodedAudio || isLowOnDecodedVideo) && !lowBuffered) {
SLOG("Skipping video decode to the next keyframe lowAudio=%d lowVideo=%d "
"lowUndecoded=%d async=%d",
isLowOnDecodedAudio, isLowOnDecodedVideo, lowBuffered,
@@ -2754,17 +2754,18 @@ MediaDecoderStateMachine::CreateMediaSin
int64_t
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>(mDecodedAudioEndTime - GetClock(), 0);
+ return std::max<int64_t>(
+ mDecodedAudioEndTime - GetClock().ToMicroseconds(), 0);
}
// MediaSink not started. All audio samples are in the queue.
return AudioQueue().Duration();
}
bool
MediaDecoderStateMachine::HaveEnoughDecodedAudio()
{
@@ -3489,40 +3490,40 @@ MediaDecoderStateMachine::ResetDecode(Tr
mAudioWaitRequest.DisconnectIfExists();
}
mPlaybackOffset = 0;
mReader->ResetDecode(aTracks);
}
-int64_t
+media::TimeUnit
MediaDecoderStateMachine::GetClock(TimeStamp* aTimeStamp) const
{
MOZ_ASSERT(OnTaskQueue());
auto clockTime = mMediaSink->GetPosition(aTimeStamp);
NS_ASSERTION(GetMediaTime() <= clockTime, "Clock should go forwards.");
- return clockTime.ToMicroseconds();
+ return clockTime;
}
void
MediaDecoderStateMachine::UpdatePlaybackPositionPeriodically()
{
MOZ_ASSERT(OnTaskQueue());
if (!IsPlaying()) {
return;
}
// Cap the current time to the larger of the audio and video end time.
// This ensures that if we're running off the system clock, we don't
// advance the clock to after the media end time.
if (VideoEndTime() > TimeUnit::Zero() || AudioEndTime() > TimeUnit::Zero()) {
- const auto clockTime = TimeUnit::FromMicroseconds(GetClock());
+ const auto clockTime = GetClock();
// Skip frames up to the frame at the playback position, and figure out
// the time remaining until it's time to display the next frame and drop
// the current frame.
NS_ASSERTION(clockTime >= TimeUnit::Zero(), "Should have positive clock time.");
// These will be non -1 if we've displayed a video frame, or played an audio
// frame.
auto maxEndTime = std::max(VideoEndTime(), AudioEndTime());
@@ -3825,17 +3826,17 @@ MediaDecoderStateMachine::GetDebugInfo()
return nsPrintfCString(
"MediaDecoderStateMachine State: GetMediaTime=%" PRId64 " GetClock="
"%" PRId64 " mMediaSink=%p state=%s mPlayState=%d "
"mSentFirstFrameLoadedEvent=%d IsPlaying=%d mAudioStatus=%s "
"mVideoStatus=%s mDecodedAudioEndTime=%" PRId64
" mDecodedVideoEndTime=%" PRId64 "mAudioCompleted=%d "
"mVideoCompleted=%d",
GetMediaTime().ToMicroseconds(),
- mMediaSink->IsStarted() ? GetClock() : -1,
+ mMediaSink->IsStarted() ? GetClock().ToMicroseconds() : -1,
mMediaSink.get(), ToStateStr(), mPlayState.Ref(),
mSentFirstFrameLoadedEvent, IsPlaying(), AudioRequestStatus(),
VideoRequestStatus(), mDecodedAudioEndTime, mDecodedVideoEndTime,
mAudioCompleted, mVideoCompleted)
+ mStateObj->GetDebugInfo() + nsCString("\n")
+ mMediaSink->GetDebugInfo();
}
--- a/dom/media/MediaDecoderStateMachine.h
+++ b/dom/media/MediaDecoderStateMachine.h
@@ -367,17 +367,17 @@ protected:
void UpdateNextFrameStatus(NextFrameStatus aStatus);
// Return the current time, either the audio clock if available (if the media
// has audio, and the playback is possible), or a clock for the video.
// Called on the state machine thread.
// If aTimeStamp is non-null, set *aTimeStamp to the TimeStamp corresponding
// to the returned stream time.
- int64_t GetClock(TimeStamp* aTimeStamp = nullptr) const;
+ media::TimeUnit GetClock(TimeStamp* aTimeStamp = nullptr) const;
void SetStartTime(int64_t aStartTimeUsecs);
// Update only the state machine's current playback position (and duration,
// if unknown). Does not update the playback position on the decoder or
// media element -- use UpdatePlaybackPosition for that. Called on the state
// machine thread, caller must hold the decoder lock.
void UpdatePlaybackPositionInternal(const media::TimeUnit& aTime);