diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-11 19:09:28 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-08-11 19:09:28 +0000 |
commit | 3ab20f3c57298ee24e15ec802b7e4b2e33598ca0 (patch) | |
tree | a10aa65bd80c00b2422f2ed94576677f1b5d2909 /chrome/browser/renderer_host | |
parent | 5e6aacc34dd3f8e9b6483e897fb7da1cf582edcd (diff) | |
download | chromium_src-3ab20f3c57298ee24e15ec802b7e4b2e33598ca0.zip chromium_src-3ab20f3c57298ee24e15ec802b7e4b2e33598ca0.tar.gz chromium_src-3ab20f3c57298ee24e15ec802b7e4b2e33598ca0.tar.bz2 |
AudioRendererHost send ViewMsg_AudioStreamState
AudioRendererHost should use ViewMsg_AudioStreamState to
notify renderer of its state instead of AudioOutputStream::State.
The enum of AudioOutputStream::State is not used anywhere, thus
removed.
TEST=unit_tests --gtest_filter=Audio*
Review URL: http://codereview.chromium.org/165255
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23061 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/renderer_host')
-rw-r--r-- | chrome/browser/renderer_host/audio_renderer_host.cc | 60 | ||||
-rw-r--r-- | chrome/browser/renderer_host/audio_renderer_host.h | 27 | ||||
-rw-r--r-- | chrome/browser/renderer_host/audio_renderer_host_unittest.cc | 20 |
3 files changed, 59 insertions, 48 deletions
diff --git a/chrome/browser/renderer_host/audio_renderer_host.cc b/chrome/browser/renderer_host/audio_renderer_host.cc index 495a8ea..962b570 100644 --- a/chrome/browser/renderer_host/audio_renderer_host.cc +++ b/chrome/browser/renderer_host/audio_renderer_host.cc @@ -68,15 +68,14 @@ AudioRendererHost::IPCAudioSource::IPCAudioSource( hardware_packet_size_(hardware_packet_size), decoded_packet_size_(decoded_packet_size), buffer_capacity_(buffer_capacity), - state_(AudioOutputStream::STATE_CREATED), + state_(kCreated), push_source_(hardware_packet_size), outstanding_request_(false), last_copied_bytes_(0) { } AudioRendererHost::IPCAudioSource::~IPCAudioSource() { - DCHECK(AudioOutputStream::STATE_STOPPED == state_ || - AudioOutputStream::STATE_CREATED == state_); + DCHECK(kClosed == state_ || kCreated == state_); } // static @@ -158,29 +157,29 @@ AudioRendererHost::IPCAudioSource* delete source; } - host->SendErrorMessage(route_id, stream_id, 0); + host->SendErrorMessage(route_id, stream_id); return NULL; } -void AudioRendererHost::IPCAudioSource::Start() { +void AudioRendererHost::IPCAudioSource::Play() { // We can start from created or paused state. - if (!stream_ || - (state_ != AudioOutputStream::STATE_CREATED && - state_ != AudioOutputStream::STATE_PAUSED)) + if (!stream_ || (state_ != kCreated && state_ != kPaused)) return; stream_->Start(this); // Update the state and notify renderer. - state_ = AudioOutputStream::STATE_STARTED; + state_ = kPaused; + + ViewMsg_AudioStreamState state; + state.state = ViewMsg_AudioStreamState::kPlaying; host_->Send(new ViewMsg_NotifyAudioStreamStateChanged( - route_id_, stream_id_, state_, 0)); + route_id_, stream_id_, state)); } void AudioRendererHost::IPCAudioSource::Pause() { // We can pause from started state. - if (!stream_ || - state_ != AudioOutputStream::STATE_STARTED) + if (!stream_ || state_ != kPlaying) return; // TODO(hclam): use stop to simulate pause, make sure the AudioOutpusStream @@ -188,9 +187,12 @@ void AudioRendererHost::IPCAudioSource::Pause() { stream_->Stop(); // Update the state and notify renderer. - state_ = AudioOutputStream::STATE_PAUSED; + state_ = kPaused; + + ViewMsg_AudioStreamState state; + state.state = ViewMsg_AudioStreamState::kPaused; host_->Send(new ViewMsg_NotifyAudioStreamStateChanged( - route_id_, stream_id_, state_, 0)); + route_id_, stream_id_, state)); } void AudioRendererHost::IPCAudioSource::Close() { @@ -203,7 +205,7 @@ void AudioRendererHost::IPCAudioSource::Close() { stream_ = NULL; // Update the current state. - state_ = AudioOutputStream::STATE_STOPPED; + state_ = kClosed; } void AudioRendererHost::IPCAudioSource::SetVolume(double left, double right) { @@ -243,7 +245,7 @@ void AudioRendererHost::IPCAudioSource::OnClose(AudioOutputStream* stream) { void AudioRendererHost::IPCAudioSource::OnError(AudioOutputStream* stream, int code) { - host_->SendErrorMessage(route_id_, stream_id_, code); + host_->SendErrorMessage(route_id_, stream_id_); // The following method call would cause this object to be destroyed on IO // thread. host_->DestroySource(this); @@ -379,7 +381,7 @@ bool AudioRendererHost::OnMessageReceived(const IPC::Message& message, IPC_BEGIN_MESSAGE_MAP_EX(AudioRendererHost, message, *message_was_ok) IPC_MESSAGE_HANDLER(ViewHostMsg_CreateAudioStream, OnCreateStream) - IPC_MESSAGE_HANDLER(ViewHostMsg_StartAudioStream, OnStartStream) + IPC_MESSAGE_HANDLER(ViewHostMsg_PlayAudioStream, OnPlayStream) IPC_MESSAGE_HANDLER(ViewHostMsg_PauseAudioStream, OnPauseStream) IPC_MESSAGE_HANDLER(ViewHostMsg_CloseAudioStream, OnCloseStream) IPC_MESSAGE_HANDLER(ViewHostMsg_NotifyAudioPacketReady, OnNotifyPacketReady) @@ -394,7 +396,7 @@ bool AudioRendererHost::IsAudioRendererHostMessage( const IPC::Message& message) { switch (message.type()) { case ViewHostMsg_CreateAudioStream::ID: - case ViewHostMsg_StartAudioStream::ID: + case ViewHostMsg_PlayAudioStream::ID: case ViewHostMsg_PauseAudioStream::ID: case ViewHostMsg_CloseAudioStream::ID: case ViewHostMsg_NotifyAudioPacketReady::ID: @@ -432,17 +434,17 @@ void AudioRendererHost::OnCreateStream( std::make_pair( SourceID(source->route_id(), source->stream_id()), source)); } else { - SendErrorMessage(msg.routing_id(), stream_id, 0); + SendErrorMessage(msg.routing_id(), stream_id); } } -void AudioRendererHost::OnStartStream(const IPC::Message& msg, int stream_id) { +void AudioRendererHost::OnPlayStream(const IPC::Message& msg, int stream_id) { DCHECK(MessageLoop::current() == io_loop_); IPCAudioSource* source = Lookup(msg.routing_id(), stream_id); if (source) { - source->Start(); + source->Play(); } else { - SendErrorMessage(msg.routing_id(), stream_id, 0); + SendErrorMessage(msg.routing_id(), stream_id); } } @@ -452,7 +454,7 @@ void AudioRendererHost::OnPauseStream(const IPC::Message& msg, int stream_id) { if (source) { source->Pause(); } else { - SendErrorMessage(msg.routing_id(), stream_id, 0); + SendErrorMessage(msg.routing_id(), stream_id); } } @@ -471,7 +473,7 @@ void AudioRendererHost::OnSetVolume(const IPC::Message& msg, int stream_id, if (source) { source->SetVolume(left_channel, right_channel); } else { - SendErrorMessage(msg.routing_id(), stream_id, 0); + SendErrorMessage(msg.routing_id(), stream_id); } } @@ -481,7 +483,7 @@ void AudioRendererHost::OnGetVolume(const IPC::Message& msg, int stream_id) { if (source) { source->GetVolume(); } else { - SendErrorMessage(msg.routing_id(), stream_id, 0); + SendErrorMessage(msg.routing_id(), stream_id); } } @@ -492,7 +494,7 @@ void AudioRendererHost::OnNotifyPacketReady(const IPC::Message& msg, if (source) { source->NotifyPacketReady(packet_size); } else { - SendErrorMessage(msg.routing_id(), stream_id, 0); + SendErrorMessage(msg.routing_id(), stream_id); } #ifdef IPC_MESSAGE_LOG_ENABLED if (IPC::Logging::current() && IPC::Logging::current()->Enabled()) { @@ -571,9 +573,11 @@ void AudioRendererHost::Send(IPC::Message* message) { } void AudioRendererHost::SendErrorMessage(int32 render_view_id, - int32 stream_id, int info) { + int32 stream_id) { + ViewMsg_AudioStreamState state; + state.state = ViewMsg_AudioStreamState::kError; Send(new ViewMsg_NotifyAudioStreamStateChanged( - render_view_id, stream_id, AudioOutputStream::STATE_ERROR, info)); + render_view_id, stream_id, state)); } void AudioRendererHost::DestroySource(IPCAudioSource* source) { diff --git a/chrome/browser/renderer_host/audio_renderer_host.h b/chrome/browser/renderer_host/audio_renderer_host.h index 9326cf7..de193519 100644 --- a/chrome/browser/renderer_host/audio_renderer_host.h +++ b/chrome/browser/renderer_host/audio_renderer_host.h @@ -31,7 +31,7 @@ // .---------> [ Stopped ] <--------. // | ^ | // | | | -// *[ Created ] --> [ Started ] --> [ Paused ] +// *[ Created ] --> [ Playing ] --> [ Paused ] // ^ | // | | // `-----------------` @@ -48,8 +48,8 @@ // | <<<<<< RequestAudioPacket <<<<<<<< | // | >>>>>>> AudioPacketReady >>>>>>>>> | // | | -// | >>>>>>>>>>>>> Start >>>>>>>>>>>>>> | -// | <<<<<<<<<<<< Started <<<<<<<<<<<<< | time +// | >>>>>>>>>>>>> Play >>>>>>>>>>>>>>> | +// | <<<<<<<<<<<< Playing <<<<<<<<<<<<< | time // | ... | // | <<<<<< RequestAudioPacket <<<<<<<< | // | >>>>>>> AudioPacketReady >>>>>>>>> | @@ -126,9 +126,7 @@ class AudioRendererHost : public base::RefCountedThreadSafe<AudioRendererHost> { virtual void Send(IPC::Message* message); // A helper method for sending error IPC messages. - virtual void SendErrorMessage(int32 render_view_id, - int32 stream_id, - int info); + virtual void SendErrorMessage(int32 render_view_id, int32 stream_id); // A helper method for calling OnDestroySource on IO thread. virtual void DestroySource(IPCAudioSource* source); @@ -143,6 +141,15 @@ class AudioRendererHost : public base::RefCountedThreadSafe<AudioRendererHost> { // via IPC. class IPCAudioSource : public AudioOutputStream::AudioSourceCallback { public: + // Internal state of the source. + enum State { + kCreated, + kPlaying, + kPaused, + kClosed, + kError, + }; + // Factory method for creating an IPCAudioSource, returns NULL if failed. // The IPCAudioSource object will have an internal state of // AudioOutputStream::STATE_CREATED after creation. @@ -170,7 +177,7 @@ class AudioRendererHost : public base::RefCountedThreadSafe<AudioRendererHost> { // Starts the playback of this audio output stream. The internal state will // be updated to AudioOutputStream::STATE_STARTED and the state update is // sent to the renderer. - void Start(); + void Play(); // Pause this audio output stream. The audio output stream will stop // reading from the |push_source_|. The internal state will be updated @@ -236,7 +243,7 @@ class AudioRendererHost : public base::RefCountedThreadSafe<AudioRendererHost> { size_t decoded_packet_size_; size_t buffer_capacity_; - AudioOutputStream::State state_; + State state_; base::SharedMemory shared_memory_; PushSource push_source_; @@ -269,11 +276,11 @@ class AudioRendererHost : public base::RefCountedThreadSafe<AudioRendererHost> { const ViewHostMsg_Audio_CreateStream& params); // Starts buffering for the audio output stream. Delegates the start method - // call to the corresponding IPCAudioSource::Start(). + // call to the corresponding IPCAudioSource::Play(). // ViewMsg_NotifyAudioStreamStateChanged with // AudioOutputStream::AUDIO_STREAM_ERROR is sent back to renderer if the // required IPCAudioSource is not found. - void OnStartStream(const IPC::Message& msg, int stream_id); + void OnPlayStream(const IPC::Message& msg, int stream_id); // Pauses the audio output stream. Delegates the pause method call to the // corresponding IPCAudioSource::Pause(), diff --git a/chrome/browser/renderer_host/audio_renderer_host_unittest.cc b/chrome/browser/renderer_host/audio_renderer_host_unittest.cc index 4a3f103..5418331 100644 --- a/chrome/browser/renderer_host/audio_renderer_host_unittest.cc +++ b/chrome/browser/renderer_host/audio_renderer_host_unittest.cc @@ -14,6 +14,7 @@ using ::testing::_; using ::testing::DoAll; using ::testing::InSequence; using ::testing::Return; +using ::testing::SaveArg; using ::testing::SetArgumentPointee; namespace { @@ -43,9 +44,9 @@ class MockAudioRendererHost : public AudioRendererHost { MOCK_METHOD3(OnStreamCreated, void(int routing_id, int stream_id, int length)); - MOCK_METHOD4(OnStreamStateChanged, + MOCK_METHOD3(OnStreamStateChanged, void(int routing_id, int stream_id, - AudioOutputStream::State state, int info)); + ViewMsg_AudioStreamState state)); MOCK_METHOD4(OnStreamVolume, void(int routing_id, int stream_id, double left, double right)); @@ -95,8 +96,8 @@ class MockAudioRendererHost : public AudioRendererHost { } void OnStreamStateChanged(const IPC::Message& msg, int stream_id, - AudioOutputStream::State state, int info) { - OnStreamStateChanged(msg.routing_id(), stream_id, state, info); + ViewMsg_AudioStreamState state) { + OnStreamStateChanged(msg.routing_id(), stream_id, state); } void OnStreamVolume(const IPC::Message& msg, int stream_id, @@ -206,10 +207,9 @@ TEST_F(AudioRendererHostTest, MockStreamDataConversation) { 2 * kPacketSize + 3 * kStep, _)); EXPECT_CALL(*host_, OnRequestPacket(kRouteId, current_stream_id_, 3 * kPacketSize, _)); - EXPECT_CALL(*host_, OnStreamStateChanged(kRouteId, - current_stream_id_, - AudioOutputStream::STATE_STARTED, - 0)); + ViewMsg_AudioStreamState state; + EXPECT_CALL(*host_, OnStreamStateChanged(kRouteId, current_stream_id_, _)) + .WillOnce(SaveArg<2>(&state)); source->NotifyPacketReady(kPacketSize); source->NotifyPacketReady(kPacketSize); @@ -217,7 +217,7 @@ TEST_F(AudioRendererHostTest, MockStreamDataConversation) { source->NotifyPacketReady(kStep); source->NotifyPacketReady(kStep); source->NotifyPacketReady(kStep); - source->Start(); + source->Play(); + EXPECT_EQ(ViewMsg_AudioStreamState::kPlaying, state.state); source->Close(); } - |