From cf44edf4a7e7c60f53dd85e45316228d81b5341e Mon Sep 17 00:00:00 2001 From: JW Wang Date: Wed, 22 Mar 2017 14:55:59 +0800 Subject: [PATCH] Bug 1349485. P3 - rename DecodedAudioDataSink to AudioSink. r=kikuo MozReview-Commit-ID: 3Irf6be322j --HG-- extra : rebase_source : 31e3697757dabdc97aeb500030f79101eedcfc6e --- dom/media/MediaDecoderStateMachine.cpp | 2 +- dom/media/mediasink/AudioSinkWrapper.h | 8 +-- dom/media/mediasink/DecodedAudioDataSink.cpp | 76 ++++++++++---------- dom/media/mediasink/DecodedAudioDataSink.h | 26 +++---- 4 files changed, 55 insertions(+), 57 deletions(-) diff --git a/dom/media/MediaDecoderStateMachine.cpp b/dom/media/MediaDecoderStateMachine.cpp index 84b9cd7f7f18..3199827054c9 100644 --- a/dom/media/MediaDecoderStateMachine.cpp +++ b/dom/media/MediaDecoderStateMachine.cpp @@ -2701,7 +2701,7 @@ MediaDecoderStateMachine::CreateAudioSink() RefPtr self = this; auto audioSinkCreator = [self] () { MOZ_ASSERT(self->OnTaskQueue()); - DecodedAudioDataSink* audioSink = new DecodedAudioDataSink( + AudioSink* audioSink = new AudioSink( self->mTaskQueue, self->mAudioQueue, self->GetMediaTime(), self->Info().mAudio, self->mAudioChannel); diff --git a/dom/media/mediasink/AudioSinkWrapper.h b/dom/media/mediasink/AudioSinkWrapper.h index 7d2018f2409b..46d402ee6e48 100644 --- a/dom/media/mediasink/AudioSinkWrapper.h +++ b/dom/media/mediasink/AudioSinkWrapper.h @@ -22,7 +22,7 @@ template class MediaQueue; namespace media { -class DecodedAudioDataSink; +class AudioSink; /** * A wrapper around AudioSink to provide the interface of MediaSink. @@ -32,7 +32,7 @@ class AudioSinkWrapper : public MediaSink { class Creator { public: virtual ~Creator() {} - virtual DecodedAudioDataSink* Create() = 0; + virtual AudioSink* Create() = 0; }; // Wrap around a function object which creates AudioSinks. @@ -40,7 +40,7 @@ class AudioSinkWrapper : public MediaSink { class CreatorImpl : public Creator { public: explicit CreatorImpl(const Function& aFunc) : mFunction(aFunc) {} - DecodedAudioDataSink* Create() override { return mFunction(); } + AudioSink* Create() override { return mFunction(); } private: Function mFunction; }; @@ -89,7 +89,7 @@ private: const RefPtr mOwnerThread; UniquePtr mCreator; - RefPtr mAudioSink; + RefPtr mAudioSink; RefPtr mEndPromise; bool mIsStarted; diff --git a/dom/media/mediasink/DecodedAudioDataSink.cpp b/dom/media/mediasink/DecodedAudioDataSink.cpp index deeba647bad2..d3737fb17184 100644 --- a/dom/media/mediasink/DecodedAudioDataSink.cpp +++ b/dom/media/mediasink/DecodedAudioDataSink.cpp @@ -19,11 +19,9 @@ namespace mozilla { extern LazyLogModule gMediaDecoderLog; #define SINK_LOG(msg, ...) \ - MOZ_LOG(gMediaDecoderLog, LogLevel::Debug, \ - ("DecodedAudioDataSink=%p " msg, this, ##__VA_ARGS__)) + MOZ_LOG(gMediaDecoderLog, LogLevel::Debug, ("AudioSink=%p " msg, this, ##__VA_ARGS__)) #define SINK_LOG_V(msg, ...) \ - MOZ_LOG(gMediaDecoderLog, LogLevel::Verbose, \ - ("DecodedAudioDataSink=%p " msg, this, ##__VA_ARGS__)) + MOZ_LOG(gMediaDecoderLog, LogLevel::Verbose, ("AudioSink=%p " msg, this, ##__VA_ARGS__)) namespace media { @@ -33,17 +31,17 @@ static const int64_t AUDIO_FUZZ_FRAMES = 1; // Amount of audio frames we will be processing ahead of use static const int32_t LOW_AUDIO_USECS = 300000; -DecodedAudioDataSink::DecodedAudioDataSink(AbstractThread* aThread, - MediaQueue& aAudioQueue, - int64_t aStartTime, - const AudioInfo& aInfo, - dom::AudioChannel aChannel) +AudioSink::AudioSink(AbstractThread* aThread, + MediaQueue& aAudioQueue, + int64_t aStartTime, + const AudioInfo& aInfo, + dom::AudioChannel aChannel) : mStartTime(aStartTime) , mLastGoodPosition(0) , mInfo(aInfo) , mChannel(aChannel) , mPlaying(true) - , mMonitor("DecodedAudioDataSink") + , mMonitor("AudioSink") , mWritten(0) , mErrored(false) , mPlaybackComplete(false) @@ -78,21 +76,21 @@ DecodedAudioDataSink::DecodedAudioDataSink(AbstractThread* aThread, : (MediaPrefs::AudioSinkForceStereo() ? 2 : mInfo.mChannels); } -DecodedAudioDataSink::~DecodedAudioDataSink() +AudioSink::~AudioSink() { } RefPtr -DecodedAudioDataSink::Init(const PlaybackParams& aParams) +AudioSink::Init(const PlaybackParams& aParams) { MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn()); mAudioQueueListener = mAudioQueue.PushEvent().Connect( - mOwnerThread, this, &DecodedAudioDataSink::OnAudioPushed); + mOwnerThread, this, &AudioSink::OnAudioPushed); mAudioQueueFinishListener = mAudioQueue.FinishEvent().Connect( - mOwnerThread, this, &DecodedAudioDataSink::NotifyAudioNeeded); + mOwnerThread, this, &AudioSink::NotifyAudioNeeded); mProcessedQueueListener = mProcessedQueue.PopEvent().Connect( - mOwnerThread, this, &DecodedAudioDataSink::OnAudioPopped); + mOwnerThread, this, &AudioSink::OnAudioPopped); // To ensure at least one audio packet will be popped from AudioQueue and // ready to be played. @@ -106,7 +104,7 @@ DecodedAudioDataSink::Init(const PlaybackParams& aParams) } int64_t -DecodedAudioDataSink::GetPosition() +AudioSink::GetPosition() { int64_t pos; if (mAudioStream && @@ -123,7 +121,7 @@ DecodedAudioDataSink::GetPosition() } bool -DecodedAudioDataSink::HasUnplayedFrames() +AudioSink::HasUnplayedFrames() { // Experimentation suggests that GetPositionInFrames() is zero-indexed, // so we need to add 1 here before comparing it to mWritten. @@ -137,7 +135,7 @@ DecodedAudioDataSink::HasUnplayedFrames() } void -DecodedAudioDataSink::Shutdown() +AudioSink::Shutdown() { MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn()); @@ -155,7 +153,7 @@ DecodedAudioDataSink::Shutdown() } void -DecodedAudioDataSink::SetVolume(double aVolume) +AudioSink::SetVolume(double aVolume) { if (mAudioStream) { mAudioStream->SetVolume(aVolume); @@ -163,7 +161,7 @@ DecodedAudioDataSink::SetVolume(double aVolume) } void -DecodedAudioDataSink::SetPlaybackRate(double aPlaybackRate) +AudioSink::SetPlaybackRate(double aPlaybackRate) { MOZ_ASSERT(aPlaybackRate != 0, "Don't set the playbackRate to 0 on AudioStream"); if (mAudioStream) { @@ -172,7 +170,7 @@ DecodedAudioDataSink::SetPlaybackRate(double aPlaybackRate) } void -DecodedAudioDataSink::SetPreservesPitch(bool aPreservesPitch) +AudioSink::SetPreservesPitch(bool aPreservesPitch) { if (mAudioStream) { mAudioStream->SetPreservesPitch(aPreservesPitch); @@ -180,7 +178,7 @@ DecodedAudioDataSink::SetPreservesPitch(bool aPreservesPitch) } void -DecodedAudioDataSink::SetPlaying(bool aPlaying) +AudioSink::SetPlaying(bool aPlaying) { if (!mAudioStream || mPlaying == aPlaying || mPlaybackComplete) { return; @@ -195,7 +193,7 @@ DecodedAudioDataSink::SetPlaying(bool aPlaying) } nsresult -DecodedAudioDataSink::InitializeAudioStream(const PlaybackParams& aParams) +AudioSink::InitializeAudioStream(const PlaybackParams& aParams) { mAudioStream = new AudioStream(*this); // When AudioQueue is empty, there is no way to know the channel layout of @@ -224,7 +222,7 @@ DecodedAudioDataSink::InitializeAudioStream(const PlaybackParams& aParams) } int64_t -DecodedAudioDataSink::GetEndTime() const +AudioSink::GetEndTime() const { int64_t written; { @@ -242,7 +240,7 @@ DecodedAudioDataSink::GetEndTime() const } UniquePtr -DecodedAudioDataSink::PopFrames(uint32_t aFrames) +AudioSink::PopFrames(uint32_t aFrames) { class Chunk : public AudioStream::Chunk { public: @@ -337,14 +335,14 @@ DecodedAudioDataSink::PopFrames(uint32_t aFrames) } bool -DecodedAudioDataSink::Ended() const +AudioSink::Ended() const { // Return true when error encountered so AudioStream can start draining. return mProcessedQueue.IsFinished() || mErrored; } void -DecodedAudioDataSink::Drained() +AudioSink::Drained() { SINK_LOG("Drained"); mPlaybackComplete = true; @@ -352,7 +350,7 @@ DecodedAudioDataSink::Drained() } void -DecodedAudioDataSink::CheckIsAudible(const AudioData* aData) +AudioSink::CheckIsAudible(const AudioData* aData) { MOZ_ASSERT(aData); @@ -364,21 +362,21 @@ DecodedAudioDataSink::CheckIsAudible(const AudioData* aData) } void -DecodedAudioDataSink::OnAudioPopped(const RefPtr& aSample) +AudioSink::OnAudioPopped(const RefPtr& aSample) { SINK_LOG_V("AudioStream has used an audio packet."); NotifyAudioNeeded(); } void -DecodedAudioDataSink::OnAudioPushed(const RefPtr& aSample) +AudioSink::OnAudioPushed(const RefPtr& aSample) { SINK_LOG_V("One new audio packet available."); NotifyAudioNeeded(); } void -DecodedAudioDataSink::NotifyAudioNeeded() +AudioSink::NotifyAudioNeeded() { MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn(), "Not called from the owner's thread"); @@ -413,7 +411,7 @@ DecodedAudioDataSink::NotifyAudioNeeded() uint32_t newRate = data->mRate; CheckedInt64 result = SaferMultDiv(mFramesParsed, newRate, oldRate); if (!result.isValid()) { - NS_WARNING("Int overflow in DecodedAudioDataSink"); + NS_WARNING("Int overflow in AudioSink"); mErrored = true; return; } @@ -436,7 +434,7 @@ DecodedAudioDataSink::NotifyAudioNeeded() CheckedInt64 missingFrames = sampleTime - mFramesParsed; if (!missingFrames.isValid()) { - NS_WARNING("Int overflow in DecodedAudioDataSink"); + NS_WARNING("Int overflow in AudioSink"); mErrored = true; return; } @@ -453,7 +451,7 @@ DecodedAudioDataSink::NotifyAudioNeeded() missingFrames = SaferMultDiv(missingFrames.value(), mOutputRate, data->mRate); if (!missingFrames.isValid()) { - NS_WARNING("Int overflow in DecodedAudioDataSink"); + NS_WARNING("Int overflow in AudioSink"); mErrored = true; return; } @@ -464,7 +462,7 @@ DecodedAudioDataSink::NotifyAudioNeeded() if (missingFrames.value()) { AlignedAudioBuffer silenceData(missingFrames.value() * mOutputChannels); if (!silenceData) { - NS_WARNING("OOM in DecodedAudioDataSink"); + NS_WARNING("OOM in AudioSink"); mErrored = true; return; } @@ -499,7 +497,7 @@ DecodedAudioDataSink::NotifyAudioNeeded() } uint32_t -DecodedAudioDataSink::PushProcessedAudio(AudioData* aData) +AudioSink::PushProcessedAudio(AudioData* aData) { if (!aData || !aData->mFrames) { return 0; @@ -510,7 +508,7 @@ DecodedAudioDataSink::PushProcessedAudio(AudioData* aData) } already_AddRefed -DecodedAudioDataSink::CreateAudioFromBuffer(AlignedAudioBuffer&& aBuffer, +AudioSink::CreateAudioFromBuffer(AlignedAudioBuffer&& aBuffer, AudioData* aReference) { uint32_t frames = aBuffer.Length() / mOutputChannels; @@ -519,7 +517,7 @@ DecodedAudioDataSink::CreateAudioFromBuffer(AlignedAudioBuffer&& aBuffer, } CheckedInt64 duration = FramesToUsecs(frames, mOutputRate); if (!duration.isValid()) { - NS_WARNING("Int overflow in DecodedAudioDataSink"); + NS_WARNING("Int overflow in AudioSink"); mErrored = true; return nullptr; } @@ -535,7 +533,7 @@ DecodedAudioDataSink::CreateAudioFromBuffer(AlignedAudioBuffer&& aBuffer, } uint32_t -DecodedAudioDataSink::DrainConverter(uint32_t aMaxFrames) +AudioSink::DrainConverter(uint32_t aMaxFrames) { MOZ_ASSERT(mOwnerThread->IsCurrentThreadIn()); diff --git a/dom/media/mediasink/DecodedAudioDataSink.h b/dom/media/mediasink/DecodedAudioDataSink.h index 909c322ccf3b..5001cafba315 100644 --- a/dom/media/mediasink/DecodedAudioDataSink.h +++ b/dom/media/mediasink/DecodedAudioDataSink.h @@ -3,8 +3,8 @@ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -#if !defined(DecodedAudioDataSink_h__) -#define DecodedAudioDataSink_h__ +#ifndef AudioSink_h__ +#define AudioSink_h__ #include "AudioStream.h" #include "MediaEventSource.h" @@ -26,18 +26,18 @@ class AudioConverter; namespace media { -class DecodedAudioDataSink : private AudioStream::DataSource { +class AudioSink : private AudioStream::DataSource { using PlaybackParams = MediaSink::PlaybackParams; - NS_INLINE_DECL_THREADSAFE_REFCOUNTING(DecodedAudioDataSink) + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(AudioSink) public: - DecodedAudioDataSink(AbstractThread* aThread, - MediaQueue& aAudioQueue, - int64_t aStartTime, - const AudioInfo& aInfo, - dom::AudioChannel aChannel); + AudioSink(AbstractThread* aThread, + MediaQueue& aAudioQueue, + int64_t aStartTime, + const AudioInfo& aInfo, + dom::AudioChannel aChannel); - // Return a promise which will be resolved when DecodedAudioDataSink + // Return a promise which will be resolved when AudioSink // finishes playing, or rejected if any error. RefPtr Init(const PlaybackParams& aParams); @@ -52,7 +52,7 @@ public: // played. bool HasUnplayedFrames(); - // Shut down the DecodedAudioDataSink's resources. + // Shut down the AudioSink's resources. void Shutdown(); void SetVolume(double aVolume); @@ -65,7 +65,7 @@ public: } private: - virtual ~DecodedAudioDataSink(); + virtual ~AudioSink(); // Allocate and initialize mAudioStream. Returns NS_OK on success. nsresult InitializeAudioStream(const PlaybackParams& aParams); @@ -166,4 +166,4 @@ private: } // namespace media } // namespace mozilla -#endif +#endif // AudioSink_h__