From 2860ecd0e55c8c6192d73595c880631955934d16 Mon Sep 17 00:00:00 2001 From: JW Wang Date: Mon, 27 Mar 2017 11:37:17 +0800 Subject: [PATCH] Bug 1350814 - Replace use of int64_t for microseconds by TimeUnit in AudioSink. r=kikuo MozReview-Commit-ID: 3diOpJu7g8i --HG-- extra : rebase_source : 16d7050cd29ea774fce7e76a16ae9100c766b9f8 extra : source : cf6946ba307d04b00e02e353b4724655929eaa69 --- dom/media/MediaDecoderStateMachine.cpp | 3 ++- dom/media/mediasink/AudioSink.cpp | 27 ++++++++++++------------ dom/media/mediasink/AudioSink.h | 16 +++++++------- dom/media/mediasink/AudioSinkWrapper.cpp | 4 ++-- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index d9ad04baafc3..48f40f8001df 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -2700,7 +2700,8 @@ MediaDecoderStateMachine::CreateAudioSink() auto audioSinkCreator = [self] () { MOZ_ASSERT(self->OnTaskQueue()); AudioSink* audioSink = new AudioSink( - self->mTaskQueue, self->mAudioQueue, self->GetMediaTime(), + self->mTaskQueue, self->mAudioQueue, + TimeUnit::FromMicroseconds(self->GetMediaTime()), self->Info().mAudio, self->mAudioChannel); self->mAudibleListener = audioSink->AudibleEvent().Connect( diff --git a/dom/media/mediasink/AudioSink.cpp b/dom/media/mediasink/AudioSink.cpp index a5cd823249d1..e67ae4c68985 100644 --- a/dom/media/mediasink/AudioSink.cpp +++ b/dom/media/mediasink/AudioSink.cpp @@ -33,11 +33,10 @@ static const int32_t LOW_AUDIO_USECS = 300000; AudioSink::AudioSink(AbstractThread* aThread, MediaQueue& aAudioQueue, - int64_t aStartTime, + TimeUnit aStartTime, const AudioInfo& aInfo, dom::AudioChannel aChannel) : mStartTime(aStartTime) - , mLastGoodPosition(0) , mInfo(aInfo) , mChannel(aChannel) , mPlaying(true) @@ -48,7 +47,6 @@ AudioSink::AudioSink(AbstractThread* aThread, , mOwnerThread(aThread) , mProcessedQueueLength(0) , mFramesParsed(0) - , mLastEndTime(0) , mIsAudioDataAudible(false) , mAudioQueue(aAudioQueue) { @@ -103,12 +101,13 @@ AudioSink::Init(const PlaybackParams& aParams) return p; } -int64_t +TimeUnit AudioSink::GetPosition() { - int64_t pos; + int64_t tmp; if (mAudioStream && - (pos = mAudioStream->GetPosition()) >= 0) { + (tmp = mAudioStream->GetPosition()) >= 0) { + TimeUnit pos = TimeUnit::FromMicroseconds(tmp); NS_ASSERTION(pos >= mLastGoodPosition, "AudioStream position shouldn't go backward"); // Update the last good position when we got a good one. @@ -221,7 +220,7 @@ AudioSink::InitializeAudioStream(const PlaybackParams& aParams) return NS_OK; } -int64_t +TimeUnit AudioSink::GetEndTime() const { int64_t written; @@ -229,14 +228,14 @@ AudioSink::GetEndTime() const MonitorAutoLock mon(mMonitor); written = mWritten; } - CheckedInt64 playedUsecs = FramesToUsecs(written, mOutputRate) + mStartTime; - if (!playedUsecs.isValid()) { + TimeUnit played = FramesToTimeUnit(written, mOutputRate) + mStartTime; + if (!played.IsValid()) { NS_WARNING("Int overflow calculating audio end time"); - return 0; + return TimeUnit::Zero(); } // As we may be resampling, rounding errors may occur. Ensure we never get // past the original end time. - return std::min(mLastEndTime, playedUsecs.value()); + return std::min(mLastEndTime, played); } UniquePtr @@ -407,8 +406,8 @@ AudioSink::NotifyAudioNeeded() // audio hardware, so we can play across the gap. // Calculate the timestamp of the next chunk of audio in numbers of // samples. - CheckedInt64 sampleTime = UsecsToFrames(data->mTime - mStartTime, - data->mRate); + CheckedInt64 sampleTime = TimeUnitToFrames( + TimeUnit::FromMicroseconds(data->mTime) - mStartTime, data->mRate); // Calculate the number of frames that have been pushed onto the audio hardware. CheckedInt64 missingFrames = sampleTime - mFramesParsed; @@ -450,7 +449,7 @@ AudioSink::NotifyAudioNeeded() } } - mLastEndTime = data->GetEndTime(); + mLastEndTime = TimeUnit::FromMicroseconds(data->GetEndTime()); mFramesParsed += data->mFrames; if (mConverter->InputConfig() != mConverter->OutputConfig()) { diff --git a/dom/media/mediasink/AudioSink.h b/dom/media/mediasink/AudioSink.h index eb16bc014e54..dbefd17b97c7 100644 --- a/dom/media/mediasink/AudioSink.h +++ b/dom/media/mediasink/AudioSink.h @@ -32,7 +32,7 @@ class AudioSink : private AudioStream::DataSource { public: AudioSink(AbstractThread* aThread, MediaQueue& aAudioQueue, - int64_t aStartTime, + TimeUnit aStartTime, const AudioInfo& aInfo, dom::AudioChannel aChannel); @@ -46,8 +46,8 @@ public: * All public functions are not thread-safe. * Called on the task queue of MDSM only. */ - int64_t GetPosition(); - int64_t GetEndTime() const; + TimeUnit GetPosition(); + TimeUnit GetEndTime() const; // Check whether we've pushed more frames to the audio hardware than it has // played. @@ -80,15 +80,15 @@ private: // The audio stream resource. Used on the task queue of MDSM only. RefPtr mAudioStream; - // The presentation time of the first audio frame that was played in - // microseconds. We can add this to the audio stream position to determine + // The presentation time of the first audio frame that was played. + // We can add this to the audio stream position to determine // the current audio time. - const int64_t mStartTime; + const TimeUnit mStartTime; // Keep the last good position returned from the audio stream. Used to ensure // position returned by GetPosition() is mono-increasing in spite of audio // stream error. Used on the task queue of MDSM only. - int64_t mLastGoodPosition; + TimeUnit mLastGoodPosition; const AudioInfo mInfo; @@ -149,7 +149,7 @@ private: // at the current input framerate. int64_t mFramesParsed; Maybe> mLastProcessedPacket; - int64_t mLastEndTime; + TimeUnit mLastEndTime; // Never modifed after construction. uint32_t mOutputRate; uint32_t mOutputChannels; diff --git a/dom/media/mediasink/AudioSinkWrapper.cpp b/dom/media/mediasink/AudioSinkWrapper.cpp index 04e8da5ec72e..6c04af4ec8fb 100644 --- a/dom/media/mediasink/AudioSinkWrapper.cpp +++ b/dom/media/mediasink/AudioSinkWrapper.cpp @@ -58,7 +58,7 @@ AudioSinkWrapper::GetEndTime(TrackType aType) const AssertOwnerThread(); MOZ_ASSERT(mIsStarted, "Must be called after playback starts."); if (aType == TrackInfo::kAudioTrack && mAudioSink) { - return mAudioSink->GetEndTime(); + return mAudioSink->GetEndTime().ToMicroseconds(); } return 0; } @@ -85,7 +85,7 @@ AudioSinkWrapper::GetPosition(TimeStamp* aTimeStamp) const if (!mAudioEnded) { // Rely on the audio sink to report playback position when it is not ended. - pos = mAudioSink->GetPosition(); + pos = mAudioSink->GetPosition().ToMicroseconds(); } else if (!mPlayStartTime.IsNull()) { // Calculate playback position using system clock if we are still playing. pos = GetVideoPosition(t);