diff options
author | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-21 19:19:24 +0000 |
---|---|---|
committer | jam@chromium.org <jam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-21 19:19:24 +0000 |
commit | 4460ee53d9a79830f9445778d6473a49a22c4ba6 (patch) | |
tree | d3d3f740e7350c6b50cbf3bf5c9f9f01e3da9696 | |
parent | 224b6c13741261566e9e9c5a39adb3cef9d79213 (diff) | |
download | chromium_src-4460ee53d9a79830f9445778d6473a49a22c4ba6.zip chromium_src-4460ee53d9a79830f9445778d6473a49a22c4ba6.tar.gz chromium_src-4460ee53d9a79830f9445778d6473a49a22c4ba6.tar.bz2 |
Move audio messages to their own file.
TBR=hclam
Review URL: http://codereview.chromium.org/6717001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@78903 0039d316-1c4b-4281-b951-d872f2087c98
20 files changed, 262 insertions, 438 deletions
diff --git a/chrome/common/render_messages.cc b/chrome/common/render_messages.cc index 124a259..c05d761 100644 --- a/chrome/common/render_messages.cc +++ b/chrome/common/render_messages.cc @@ -714,29 +714,4 @@ void ParamTraits<webkit_glue::WebAccessibility>::Log(const param_type& p, l->append(")"); } -void ParamTraits<AudioBuffersState>::Write(Message* m, const param_type& p) { - WriteParam(m, p.pending_bytes); - WriteParam(m, p.hardware_delay_bytes); - WriteParam(m, p.timestamp); -} - -bool ParamTraits<AudioBuffersState>::Read(const Message* m, - void** iter, - param_type* p) { - return - ReadParam(m, iter, &p->pending_bytes) && - ReadParam(m, iter, &p->hardware_delay_bytes) && - ReadParam(m, iter, &p->timestamp); -} - -void ParamTraits<AudioBuffersState>::Log(const param_type& p, std::string* l) { - l->append("("); - LogParam(p.pending_bytes, l); - l->append(", "); - LogParam(p.hardware_delay_bytes, l); - l->append(", "); - LogParam(p.timestamp, l); - l->append(")"); -} - } // namespace IPC diff --git a/chrome/common/render_messages.h b/chrome/common/render_messages.h index a2e82b5..081247b 100644 --- a/chrome/common/render_messages.h +++ b/chrome/common/render_messages.h @@ -46,7 +46,6 @@ #include "ipc/ipc_message_macros.h" #include "ipc/ipc_message_utils.h" #include "ipc/ipc_platform_file.h" // ifdefed typedef. -#include "media/audio/audio_buffers_state.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderline.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebFindOptions.h" #include "third_party/WebKit/Source/WebKit/chromium/public/WebMediaPlayerAction.h" @@ -290,15 +289,6 @@ struct ParamTraits<webkit_glue::WebAccessibility> { static void Log(const param_type& p, std::string* l); }; -// Traits for AudioBuffersState structure. -template <> -struct ParamTraits<AudioBuffersState> { - typedef AudioBuffersState param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, void** iter, param_type* p); - static void Log(const param_type& p, std::string* l); -}; - } // namespace IPC #endif // CHROME_COMMON_RENDER_MESSAGES_H_ @@ -846,46 +836,6 @@ IPC_MESSAGE_ROUTED0(ViewMsg_DisassociateFromPopupCount) IPC_MESSAGE_ROUTED1(ViewMsg_AllowScriptToClose, bool /* script_can_close */) -// Sent by AudioRendererHost to renderer to request an audio packet. -IPC_MESSAGE_ROUTED2(ViewMsg_RequestAudioPacket, - int /* stream id */, - AudioBuffersState) - -// Tell the renderer process that the audio stream has been created, renderer -// process would be given a ShareMemoryHandle that it should write to from -// then on. -IPC_MESSAGE_ROUTED3(ViewMsg_NotifyAudioStreamCreated, - int /* stream id */, - base::SharedMemoryHandle /* handle */, - uint32 /* length */) - -// Tell the renderer process that a low latency audio stream has been created, -// renderer process would be given a SyncSocket that it should write to from -// then on. -#if defined(OS_WIN) -IPC_MESSAGE_ROUTED4(ViewMsg_NotifyLowLatencyAudioStreamCreated, - int /* stream id */, - base::SharedMemoryHandle /* handle */, - base::SyncSocket::Handle /* socket handle */, - uint32 /* length */) -#else -IPC_MESSAGE_ROUTED4(ViewMsg_NotifyLowLatencyAudioStreamCreated, - int /* stream id */, - base::SharedMemoryHandle /* handle */, - base::FileDescriptor /* socket handle */, - uint32 /* length */) -#endif - -// Notification message sent from AudioRendererHost to renderer for state -// update after the renderer has requested a Create/Start/Close. -IPC_MESSAGE_ROUTED2(ViewMsg_NotifyAudioStreamStateChanged, - int /* stream id */, - ViewMsg_AudioStreamState_Params /* new state */) - -IPC_MESSAGE_ROUTED2(ViewMsg_NotifyAudioStreamVolume, - int /* stream id */, - double /* volume */) - // Notification that a move or resize renderer's containing window has // started. IPC_MESSAGE_ROUTED0(ViewMsg_MoveOrResizeStarted) @@ -1898,45 +1848,6 @@ IPC_SYNC_MESSAGE_ROUTED1_1(ViewHostMsg_GetRootWindowRect, gfx::NativeViewId /* window */, gfx::Rect /* Out: Window location */) -// Request that got sent to browser for creating an audio output stream -IPC_MESSAGE_ROUTED3(ViewHostMsg_CreateAudioStream, - int /* stream_id */, - ViewHostMsg_Audio_CreateStream_Params, - bool /* low-latency */) - -// Tell the browser the audio buffer prepared for stream -// (render_view_id, stream_id) is filled and is ready to be consumed. -IPC_MESSAGE_ROUTED2(ViewHostMsg_NotifyAudioPacketReady, - int /* stream_id */, - uint32 /* packet size */) - -// Start buffering and play the audio stream specified by -// (render_view_id, stream_id). -IPC_MESSAGE_ROUTED1(ViewHostMsg_PlayAudioStream, - int /* stream_id */) - -// Pause the audio stream specified by (render_view_id, stream_id). -IPC_MESSAGE_ROUTED1(ViewHostMsg_PauseAudioStream, - int /* stream_id */) - -// Discard all buffered audio data for the specified audio stream. -IPC_MESSAGE_ROUTED1(ViewHostMsg_FlushAudioStream, - int /* stream_id */) - -// Close an audio stream specified by (render_view_id, stream_id). -IPC_MESSAGE_ROUTED1(ViewHostMsg_CloseAudioStream, - int /* stream_id */) - -// Get audio volume of the stream specified by (render_view_id, stream_id). -IPC_MESSAGE_ROUTED1(ViewHostMsg_GetAudioVolume, - int /* stream_id */) - -// Set audio volume of the stream specified by (render_view_id, stream_id). -// TODO(hclam): change this to vector if we have channel numbers other than 2. -IPC_MESSAGE_ROUTED2(ViewHostMsg_SetAudioVolume, - int /* stream_id */, - double /* volume */) - // A renderer sends this message when an extension process starts an API // request. The browser will always respond with a ViewMsg_ExtensionResponse. IPC_MESSAGE_ROUTED1(ViewHostMsg_ExtensionRequest, diff --git a/chrome/common/render_messages_params.cc b/chrome/common/render_messages_params.cc index e9a89c8..d91ab9f 100644 --- a/chrome/common/render_messages_params.cc +++ b/chrome/common/render_messages_params.cc @@ -139,13 +139,6 @@ ViewHostMsg_DidPrintPage_Params::ViewHostMsg_DidPrintPage_Params() ViewHostMsg_DidPrintPage_Params::~ViewHostMsg_DidPrintPage_Params() { } -ViewHostMsg_Audio_CreateStream_Params::ViewHostMsg_Audio_CreateStream_Params() { -} - -ViewHostMsg_Audio_CreateStream_Params:: - ~ViewHostMsg_Audio_CreateStream_Params() { -} - ViewHostMsg_ShowPopup_Params::ViewHostMsg_ShowPopup_Params() : item_height(0), item_font_size(0), @@ -381,40 +374,6 @@ struct ParamTraits<NavigationGesture> { } }; -// Traits for AudioManager::Format. -template <> -struct ParamTraits<AudioParameters::Format> { - typedef AudioParameters::Format param_type; - static void Write(Message* m, const param_type& p) { - m->WriteInt(p); - } - static bool Read(const Message* m, void** iter, param_type* p) { - int type; - if (!m->ReadInt(iter, &type)) - return false; - *p = static_cast<AudioParameters::Format>(type); - return true; - } - static void Log(const param_type& p, std::string* l) { - std::string format; - switch (p) { - case AudioParameters::AUDIO_PCM_LINEAR: - format = "AUDIO_PCM_LINEAR"; - break; - case AudioParameters::AUDIO_PCM_LOW_LATENCY: - format = "AUDIO_PCM_LOW_LATENCY"; - break; - case AudioParameters::AUDIO_MOCK: - format = "AUDIO_MOCK"; - break; - default: - format = "AUDIO_LAST_FORMAT"; - break; - } - LogParam(format, l); - } -}; - template <> struct ParamTraits<WindowContainerType> { typedef WindowContainerType param_type; @@ -532,41 +491,6 @@ void ParamTraits<ViewMsg_Navigate_Params>::Log(const param_type& p, l->append(")"); } -void ParamTraits<ViewMsg_AudioStreamState_Params>::Write(Message* m, - const param_type& p) { - m->WriteInt(p.state); -} - -bool ParamTraits<ViewMsg_AudioStreamState_Params>::Read(const Message* m, - void** iter, - param_type* p) { - int type; - if (!m->ReadInt(iter, &type)) - return false; - p->state = static_cast<ViewMsg_AudioStreamState_Params::State>(type); - return true; -} - -void ParamTraits<ViewMsg_AudioStreamState_Params>::Log(const param_type& p, - std::string* l) { - std::string state; - switch (p.state) { - case ViewMsg_AudioStreamState_Params::kPlaying: - state = "ViewMsg_AudioStreamState_Params::kPlaying"; - break; - case ViewMsg_AudioStreamState_Params::kPaused: - state = "ViewMsg_AudioStreamState_Params::kPaused"; - break; - case ViewMsg_AudioStreamState_Params::kError: - state = "ViewMsg_AudioStreamState_Params::kError"; - break; - default: - state = "UNKNOWN"; - break; - } - LogParam(state, l); -} - void ParamTraits<ViewMsg_StopFinding_Params>::Write(Message* m, const param_type& p) { m->WriteInt(p.action); @@ -981,43 +905,6 @@ void ParamTraits<ViewHostMsg_DidPrintPage_Params>::Log(const param_type& p, l->append("<ViewHostMsg_DidPrintPage_Params>"); } -void ParamTraits<ViewHostMsg_Audio_CreateStream_Params>::Write( - Message* m, - const param_type& p) { - WriteParam(m, p.params.format); - WriteParam(m, p.params.channels); - WriteParam(m, p.params.sample_rate); - WriteParam(m, p.params.bits_per_sample); - WriteParam(m, p.params.samples_per_packet); -} - -bool ParamTraits<ViewHostMsg_Audio_CreateStream_Params>::Read(const Message* m, - void** iter, - param_type* p) { - return - ReadParam(m, iter, &p->params.format) && - ReadParam(m, iter, &p->params.channels) && - ReadParam(m, iter, &p->params.sample_rate) && - ReadParam(m, iter, &p->params.bits_per_sample) && - ReadParam(m, iter, &p->params.samples_per_packet); -} - -void ParamTraits<ViewHostMsg_Audio_CreateStream_Params>::Log( - const param_type& p, - std::string* l) { - l->append("<ViewHostMsg_Audio_CreateStream_Params>("); - LogParam(p.params.format, l); - l->append(", "); - LogParam(p.params.channels, l); - l->append(", "); - LogParam(p.params.sample_rate, l); - l->append(", "); - LogParam(p.params.bits_per_sample, l); - l->append(", "); - LogParam(p.params.samples_per_packet, l); - l->append(")"); -} - void ParamTraits<ViewHostMsg_ShowPopup_Params>::Write(Message* m, const param_type& p) { WriteParam(m, p.bounds); diff --git a/chrome/common/render_messages_params.h b/chrome/common/render_messages_params.h index 2736df5..4fe75b2 100644 --- a/chrome/common/render_messages_params.h +++ b/chrome/common/render_messages_params.h @@ -26,7 +26,6 @@ #include "content/common/serialized_script_value.h" #include "googleurl/src/gurl.h" #include "ipc/ipc_param_traits.h" -#include "media/audio/audio_parameters.h" #include "net/base/host_port_pair.h" #include "ui/gfx/rect.h" #include "ui/gfx/size.h" @@ -110,28 +109,6 @@ struct ViewMsg_Navigate_Params { std::string extra_headers; }; -// Current status of the audio output stream in the browser process. Browser -// sends information about the current playback state and error to the -// renderer process using this type. -struct ViewMsg_AudioStreamState_Params { - enum State { - kPlaying, - kPaused, - kError - }; - - ViewMsg_AudioStreamState_Params() - : state(kPlaying) { - } - - explicit ViewMsg_AudioStreamState_Params(State s) - : state(s) { - } - - // Carries the current playback state. - State state; -}; - // The user has completed a find-in-page; this type defines what actions the // renderer should take next. struct ViewMsg_StopFinding_Params { @@ -545,17 +522,6 @@ struct ViewHostMsg_DidPrintPage_Params { bool has_visible_overlays; }; -// Parameters for creating an audio output stream. -struct ViewHostMsg_Audio_CreateStream_Params { - ViewHostMsg_Audio_CreateStream_Params(); - ~ViewHostMsg_Audio_CreateStream_Params(); - - // Parameters for the new audio stream. - // If |samples_per_packet| is set 0, the audio packet size is selected - // automatically by the browser process. - AudioParameters params; -}; - // This message is used for supporting popup menus on Mac OS X using native // Cocoa controls. The renderer sends us this message which we use to populate // the popup menu. @@ -866,14 +832,6 @@ struct ParamTraits<ViewMsg_Navigate_Params> { }; template <> -struct ParamTraits<ViewMsg_AudioStreamState_Params> { - typedef ViewMsg_AudioStreamState_Params param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, void** iter, param_type* p); - static void Log(const param_type& p, std::string* l); -}; - -template <> struct ParamTraits<ViewMsg_StopFinding_Params> { typedef ViewMsg_StopFinding_Params param_type; static void Write(Message* m, const param_type& p); @@ -962,14 +920,6 @@ struct ParamTraits<ViewHostMsg_DidPrintPage_Params> { }; template <> -struct ParamTraits<ViewHostMsg_Audio_CreateStream_Params> { - typedef ViewHostMsg_Audio_CreateStream_Params param_type; - static void Write(Message* m, const param_type& p); - static bool Read(const Message* m, void** iter, param_type* p); - static void Log(const param_type& p, std::string* l); -}; - -template <> struct ParamTraits<ViewHostMsg_ShowPopup_Params> { typedef ViewHostMsg_ShowPopup_Params param_type; static void Write(Message* m, const param_type& p); diff --git a/content/browser/renderer_host/audio_renderer_host.cc b/content/browser/renderer_host/audio_renderer_host.cc index da542e6..55980e0 100644 --- a/content/browser/renderer_host/audio_renderer_host.cc +++ b/content/browser/renderer_host/audio_renderer_host.cc @@ -7,9 +7,8 @@ #include "base/metrics/histogram.h" #include "base/process.h" #include "base/shared_memory.h" -#include "chrome/common/render_messages.h" -#include "chrome/common/render_messages_params.h" #include "content/browser/renderer_host/audio_sync_reader.h" +#include "content/common/audio_messages.h" #include "ipc/ipc_logging.h" namespace { @@ -167,7 +166,7 @@ void AudioRendererHost::DoCompleteCreation( return; } - Send(new ViewMsg_NotifyLowLatencyAudioStreamCreated( + Send(new AudioMsg_NotifyLowLatencyStreamCreated( entry->render_view_id, entry->stream_id, foreign_memory_handle, foreign_socket_handle, entry->shared_memory.created_size())); return; @@ -175,7 +174,7 @@ void AudioRendererHost::DoCompleteCreation( // The normal audio stream has created, send a message to the renderer // process. - Send(new ViewMsg_NotifyAudioStreamCreated( + Send(new AudioMsg_NotifyStreamCreated( entry->render_view_id, entry->stream_id, foreign_memory_handle, entry->shared_memory.created_size())); } @@ -188,10 +187,8 @@ void AudioRendererHost::DoSendPlayingMessage( if (!entry) return; - ViewMsg_AudioStreamState_Params params; - params.state = ViewMsg_AudioStreamState_Params::kPlaying; - Send(new ViewMsg_NotifyAudioStreamStateChanged( - entry->render_view_id, entry->stream_id, params)); + Send(new AudioMsg_NotifyStreamStateChanged( + entry->render_view_id, entry->stream_id, kAudioStreamPlaying)); } void AudioRendererHost::DoSendPausedMessage( @@ -202,10 +199,8 @@ void AudioRendererHost::DoSendPausedMessage( if (!entry) return; - ViewMsg_AudioStreamState_Params params; - params.state = ViewMsg_AudioStreamState_Params::kPaused; - Send(new ViewMsg_NotifyAudioStreamStateChanged( - entry->render_view_id, entry->stream_id, params)); + Send(new AudioMsg_NotifyStreamStateChanged( + entry->render_view_id, entry->stream_id, kAudioStreamPaused)); } void AudioRendererHost::DoRequestMoreData( @@ -220,7 +215,7 @@ void AudioRendererHost::DoRequestMoreData( DCHECK(!entry->controller->LowLatencyMode()); entry->pending_buffer_request = true; - Send(new ViewMsg_RequestAudioPacket( + Send(new AudioMsg_RequestPacket( entry->render_view_id, entry->stream_id, buffers_state)); } @@ -241,14 +236,14 @@ bool AudioRendererHost::OnMessageReceived(const IPC::Message& message, bool* message_was_ok) { bool handled = true; IPC_BEGIN_MESSAGE_MAP_EX(AudioRendererHost, message, *message_was_ok) - IPC_MESSAGE_HANDLER(ViewHostMsg_CreateAudioStream, OnCreateStream) - IPC_MESSAGE_HANDLER(ViewHostMsg_PlayAudioStream, OnPlayStream) - IPC_MESSAGE_HANDLER(ViewHostMsg_PauseAudioStream, OnPauseStream) - IPC_MESSAGE_HANDLER(ViewHostMsg_FlushAudioStream, OnFlushStream) - IPC_MESSAGE_HANDLER(ViewHostMsg_CloseAudioStream, OnCloseStream) - IPC_MESSAGE_HANDLER(ViewHostMsg_NotifyAudioPacketReady, OnNotifyPacketReady) - IPC_MESSAGE_HANDLER(ViewHostMsg_GetAudioVolume, OnGetVolume) - IPC_MESSAGE_HANDLER(ViewHostMsg_SetAudioVolume, OnSetVolume) + IPC_MESSAGE_HANDLER(AudioHostMsg_CreateStream, OnCreateStream) + IPC_MESSAGE_HANDLER(AudioHostMsg_PlayStream, OnPlayStream) + IPC_MESSAGE_HANDLER(AudioHostMsg_PauseStream, OnPauseStream) + IPC_MESSAGE_HANDLER(AudioHostMsg_FlushStream, OnFlushStream) + IPC_MESSAGE_HANDLER(AudioHostMsg_CloseStream, OnCloseStream) + IPC_MESSAGE_HANDLER(AudioHostMsg_NotifyPacketReady, OnNotifyPacketReady) + IPC_MESSAGE_HANDLER(AudioHostMsg_GetVolume, OnGetVolume) + IPC_MESSAGE_HANDLER(AudioHostMsg_SetVolume, OnSetVolume) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP_EX() @@ -257,11 +252,11 @@ bool AudioRendererHost::OnMessageReceived(const IPC::Message& message, void AudioRendererHost::OnCreateStream( const IPC::Message& msg, int stream_id, - const ViewHostMsg_Audio_CreateStream_Params& params, bool low_latency) { + const AudioParameters& params, bool low_latency) { DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); DCHECK(LookupById(msg.routing_id(), stream_id) == NULL); - AudioParameters audio_params(params.params); + AudioParameters audio_params(params); // Select the hardware packet size if not specified. if (!audio_params.samples_per_packet) { @@ -408,10 +403,8 @@ void AudioRendererHost::OnNotifyPacketReady( void AudioRendererHost::SendErrorMessage(int32 render_view_id, int32 stream_id) { - ViewMsg_AudioStreamState_Params state; - state.state = ViewMsg_AudioStreamState_Params::kError; - Send(new ViewMsg_NotifyAudioStreamStateChanged( - render_view_id, stream_id, state)); + Send(new AudioMsg_NotifyStreamStateChanged( + render_view_id, stream_id, kAudioStreamError)); } void AudioRendererHost::DeleteEntries() { diff --git a/content/browser/renderer_host/audio_renderer_host.h b/content/browser/renderer_host/audio_renderer_host.h index d1d94e9..498ab64 100644 --- a/content/browser/renderer_host/audio_renderer_host.h +++ b/content/browser/renderer_host/audio_renderer_host.h @@ -67,7 +67,7 @@ #include "media/audio/simple_sources.h" class AudioManager; -struct ViewHostMsg_Audio_CreateStream_Params; +struct AudioParameters; class AudioRendererHost : public BrowserMessageFilter, public media::AudioOutputController::EventHandler { @@ -143,7 +143,7 @@ class AudioRendererHost : public BrowserMessageFilter, // successful this object would keep an internal entry of the stream for the // required properties. void OnCreateStream(const IPC::Message& msg, int stream_id, - const ViewHostMsg_Audio_CreateStream_Params& params, + const AudioParameters& params, bool low_latency); // Play the audio stream referenced by |stream_id|. diff --git a/content/browser/renderer_host/audio_renderer_host_unittest.cc b/content/browser/renderer_host/audio_renderer_host_unittest.cc index b28a96d..ac2e7ff 100644 --- a/content/browser/renderer_host/audio_renderer_host_unittest.cc +++ b/content/browser/renderer_host/audio_renderer_host_unittest.cc @@ -7,10 +7,9 @@ #include "base/process_util.h" #include "base/scoped_ptr.h" #include "base/sync_socket.h" -#include "chrome/common/render_messages.h" -#include "chrome/common/render_messages_params.h" #include "content/browser/browser_thread.h" #include "content/browser/renderer_host/audio_renderer_host.h" +#include "content/common/audio_messages.h" #include "ipc/ipc_message_utils.h" #include "media/audio/audio_manager.h" #include "media/audio/fake_audio_output_stream.h" @@ -74,13 +73,13 @@ class MockAudioRendererHost : public AudioRendererHost { // we are the renderer. bool handled = true; IPC_BEGIN_MESSAGE_MAP(MockAudioRendererHost, *message) - IPC_MESSAGE_HANDLER(ViewMsg_RequestAudioPacket, OnRequestPacket) - IPC_MESSAGE_HANDLER(ViewMsg_NotifyAudioStreamCreated, OnStreamCreated) - IPC_MESSAGE_HANDLER(ViewMsg_NotifyLowLatencyAudioStreamCreated, + IPC_MESSAGE_HANDLER(AudioMsg_RequestPacket, OnRequestPacket) + IPC_MESSAGE_HANDLER(AudioMsg_NotifyStreamCreated, OnStreamCreated) + IPC_MESSAGE_HANDLER(AudioMsg_NotifyLowLatencyStreamCreated, OnLowLatencyStreamCreated) - IPC_MESSAGE_HANDLER(ViewMsg_NotifyAudioStreamStateChanged, + IPC_MESSAGE_HANDLER(AudioMsg_NotifyStreamStateChanged, OnStreamStateChanged) - IPC_MESSAGE_HANDLER(ViewMsg_NotifyAudioStreamVolume, OnStreamVolume) + IPC_MESSAGE_HANDLER(AudioMsg_NotifyStreamVolume, OnStreamVolume) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() EXPECT_TRUE(handled); @@ -135,12 +134,12 @@ class MockAudioRendererHost : public AudioRendererHost { } void OnStreamStateChanged(const IPC::Message& msg, int stream_id, - const ViewMsg_AudioStreamState_Params& params) { - if (params.state == ViewMsg_AudioStreamState_Params::kPlaying) { + AudioStreamState state) { + if (state == kAudioStreamPlaying) { OnStreamPlaying(msg.routing_id(), stream_id); - } else if (params.state == ViewMsg_AudioStreamState_Params::kPaused) { + } else if (state == kAudioStreamPaused) { OnStreamPaused(msg.routing_id(), stream_id); - } else if (params.state == ViewMsg_AudioStreamState_Params::kError) { + } else if (state == kAudioStreamError) { OnStreamError(msg.routing_id(), stream_id); } else { FAIL() << "Unknown stream state"; @@ -206,15 +205,15 @@ class AudioRendererHostTest : public testing::Test { IPC::Message msg; msg.set_routing_id(kRouteId); - ViewHostMsg_Audio_CreateStream_Params params; + AudioParameters params; if (mock_stream_) - params.params.format = AudioParameters::AUDIO_MOCK; + params.format = AudioParameters::AUDIO_MOCK; else - params.params.format = AudioParameters::AUDIO_PCM_LINEAR; - params.params.channels = 2; - params.params.sample_rate = AudioParameters::kAudioCDSampleRate; - params.params.bits_per_sample = 16; - params.params.samples_per_packet = 0; + params.format = AudioParameters::AUDIO_PCM_LINEAR; + params.channels = 2; + params.sample_rate = AudioParameters::kAudioCDSampleRate; + params.bits_per_sample = 16; + params.samples_per_packet = 0; // Send a create stream message to the audio output stream and wait until // we receive the created message. @@ -232,15 +231,15 @@ class AudioRendererHostTest : public testing::Test { IPC::Message msg; msg.set_routing_id(kRouteId); - ViewHostMsg_Audio_CreateStream_Params params; + AudioParameters params; if (mock_stream_) - params.params.format = AudioParameters::AUDIO_MOCK; + params.format = AudioParameters::AUDIO_MOCK; else - params.params.format = AudioParameters::AUDIO_PCM_LINEAR; - params.params.channels = 2; - params.params.sample_rate = AudioParameters::kAudioCDSampleRate; - params.params.bits_per_sample = 16; - params.params.samples_per_packet = 0; + params.format = AudioParameters::AUDIO_PCM_LINEAR; + params.channels = 2; + params.sample_rate = AudioParameters::kAudioCDSampleRate; + params.bits_per_sample = 16; + params.samples_per_packet = 0; // Send a create stream message to the audio output stream and wait until // we receive the created message. diff --git a/content/common/audio_messages.h b/content/common/audio_messages.h new file mode 100644 index 0000000..e4c995493 --- /dev/null +++ b/content/common/audio_messages.h @@ -0,0 +1,115 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// IPC messages for the audio. +// Multiply-included message file, hence no include guard. + +#include "base/shared_memory.h" +#include "base/sync_socket.h" +#include "content/common/audio_stream_state.h" +#include "ipc/ipc_message_macros.h" +#include "media/audio/audio_buffers_state.h" +#include "media/audio/audio_parameters.h" + +#define IPC_MESSAGE_START AudioMsgStart + +IPC_ENUM_TRAITS(AudioStreamState) +IPC_ENUM_TRAITS(AudioParameters::Format) + +IPC_STRUCT_TRAITS_BEGIN(AudioBuffersState) + IPC_STRUCT_TRAITS_MEMBER(pending_bytes) + IPC_STRUCT_TRAITS_MEMBER(hardware_delay_bytes) + IPC_STRUCT_TRAITS_MEMBER(timestamp) +IPC_STRUCT_TRAITS_END() + +IPC_STRUCT_TRAITS_BEGIN(AudioParameters) + IPC_STRUCT_TRAITS_MEMBER(format) + IPC_STRUCT_TRAITS_MEMBER(channels) + IPC_STRUCT_TRAITS_MEMBER(sample_rate) + IPC_STRUCT_TRAITS_MEMBER(bits_per_sample) + IPC_STRUCT_TRAITS_MEMBER(samples_per_packet) +IPC_STRUCT_TRAITS_END() + +// Messages sent from the browser to the renderer. + +// Sent by AudioRendererHost to renderer to request an audio packet. +IPC_MESSAGE_ROUTED2(AudioMsg_RequestPacket, + int /* stream id */, + AudioBuffersState) + +// Tell the renderer process that the audio stream has been created, renderer +// process would be given a ShareMemoryHandle that it should write to from +// then on. +IPC_MESSAGE_ROUTED3(AudioMsg_NotifyStreamCreated, + int /* stream id */, + base::SharedMemoryHandle /* handle */, + uint32 /* length */) + +// Tell the renderer process that a low latency audio stream has been created, +// renderer process would be given a SyncSocket that it should write to from +// then on. +#if defined(OS_WIN) +IPC_MESSAGE_ROUTED4(AudioMsg_NotifyLowLatencyStreamCreated, + int /* stream id */, + base::SharedMemoryHandle /* handle */, + base::SyncSocket::Handle /* socket handle */, + uint32 /* length */) +#else +IPC_MESSAGE_ROUTED4(AudioMsg_NotifyLowLatencyStreamCreated, + int /* stream id */, + base::SharedMemoryHandle /* handle */, + base::FileDescriptor /* socket handle */, + uint32 /* length */) +#endif + +// Notification message sent from AudioRendererHost to renderer for state +// update after the renderer has requested a Create/Start/Close. +IPC_MESSAGE_ROUTED2(AudioMsg_NotifyStreamStateChanged, + int /* stream id */, + AudioStreamState /* new state */) + +IPC_MESSAGE_ROUTED2(AudioMsg_NotifyStreamVolume, + int /* stream id */, + double /* volume */) + +// Messages sent from the renderer to the browser. + +// Request that got sent to browser for creating an audio output stream +IPC_MESSAGE_ROUTED3(AudioHostMsg_CreateStream, + int /* stream_id */, + AudioParameters /* params */, + bool /* low-latency */) + +// Tell the browser the audio buffer prepared for stream +// (render_view_id, stream_id) is filled and is ready to be consumed. +IPC_MESSAGE_ROUTED2(AudioHostMsg_NotifyPacketReady, + int /* stream_id */, + uint32 /* packet size */) + +// Start buffering and play the audio stream specified by +// (render_view_id, stream_id). +IPC_MESSAGE_ROUTED1(AudioHostMsg_PlayStream, + int /* stream_id */) + +// Pause the audio stream specified by (render_view_id, stream_id). +IPC_MESSAGE_ROUTED1(AudioHostMsg_PauseStream, + int /* stream_id */) + +// Discard all buffered audio data for the specified audio stream. +IPC_MESSAGE_ROUTED1(AudioHostMsg_FlushStream, + int /* stream_id */) + +// Close an audio stream specified by (render_view_id, stream_id). +IPC_MESSAGE_ROUTED1(AudioHostMsg_CloseStream, + int /* stream_id */) + +// Get audio volume of the stream specified by (render_view_id, stream_id). +IPC_MESSAGE_ROUTED1(AudioHostMsg_GetVolume, + int /* stream_id */) + +// Set audio volume of the stream specified by (render_view_id, stream_id). +// TODO(hclam): change this to vector if we have channel numbers other than 2. +IPC_MESSAGE_ROUTED2(AudioHostMsg_SetVolume, + int /* stream_id */, + double /* volume */) diff --git a/content/common/audio_stream_state.h b/content/common/audio_stream_state.h new file mode 100644 index 0000000..9557772 --- /dev/null +++ b/content/common/audio_stream_state.h @@ -0,0 +1,18 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_COMMON_AUDIO_STREAM_STATE_H_ +#define CONTENT_COMMON_AUDIO_STREAM_STATE_H_ +#pragma once + +// Current status of the audio output stream in the browser process. Browser +// sends information about the current playback state and error to the +// renderer process using this type. +enum AudioStreamState { + kAudioStreamPlaying, + kAudioStreamPaused, + kAudioStreamError +}; + +#endif // CONTENT_COMMON_AUDIO_STREAM_STATE_H_ diff --git a/content/common/content_message_generator.h b/content/common/content_message_generator.h index f244c90..3c8448d 100644 --- a/content/common/content_message_generator.h +++ b/content/common/content_message_generator.h @@ -5,6 +5,7 @@ // Multiply-included file, hence no include guard. #include "content/common/appcache_messages.h" +#include "content/common/audio_messages.h" #include "content/common/child_process_messages.h" #include "content/common/clipboard_messages.h" #include "content/common/database_messages.h" diff --git a/content/renderer/audio_device.cc b/content/renderer/audio_device.cc index cf1dd7d..df00851 100644 --- a/content/renderer/audio_device.cc +++ b/content/renderer/audio_device.cc @@ -6,8 +6,8 @@ #include "base/singleton.h" #include "chrome/common/render_messages.h" -#include "chrome/common/render_messages_params.h" #include "chrome/renderer/render_thread.h" +#include "content/common/audio_messages.h" #include "media/audio/audio_util.h" scoped_refptr<AudioMessageFilter> AudioDevice::filter_; @@ -76,15 +76,14 @@ bool AudioDevice::Start() { stream_id_ = filter_->AddDelegate(this); - ViewHostMsg_Audio_CreateStream_Params params; - params.params.format = AudioParameters::AUDIO_PCM_LOW_LATENCY; - params.params.channels = channels_; - params.params.sample_rate = static_cast<int>(sample_rate_); - params.params.bits_per_sample = 16; - params.params.samples_per_packet = buffer_size_; + AudioParameters params; + params.format = AudioParameters::AUDIO_PCM_LOW_LATENCY; + params.channels = channels_; + params.sample_rate = static_cast<int>(sample_rate_); + params.bits_per_sample = 16; + params.samples_per_packet = buffer_size_; - filter_->Send( - new ViewHostMsg_CreateAudioStream(0, stream_id_, params, true)); + filter_->Send(new AudioHostMsg_CreateStream(0, stream_id_, params, true)); return true; } @@ -104,7 +103,7 @@ void AudioDevice::OnDestroy() { return; filter_->RemoveDelegate(stream_id_); - filter_->Send(new ViewHostMsg_CloseAudioStream(0, stream_id_)); + filter_->Send(new AudioHostMsg_CloseStream(0, stream_id_)); stream_id_ = 0; if (audio_thread_.get()) { socket_->Close(); @@ -117,8 +116,7 @@ void AudioDevice::OnRequestPacket(AudioBuffersState buffers_state) { NOTIMPLEMENTED(); } -void AudioDevice::OnStateChanged( - const ViewMsg_AudioStreamState_Params& state) { +void AudioDevice::OnStateChanged(AudioStreamState state) { // Not needed in this simple implementation. NOTIMPLEMENTED(); } @@ -158,7 +156,7 @@ void AudioDevice::OnLowLatencyCreated( new base::DelegateSimpleThread(this, "renderer_audio_thread")); audio_thread_->Start(); - filter_->Send(new ViewHostMsg_PlayAudioStream(0, stream_id_)); + filter_->Send(new AudioHostMsg_PlayStream(0, stream_id_)); } void AudioDevice::OnVolume(double volume) { diff --git a/content/renderer/audio_device.h b/content/renderer/audio_device.h index 9f152bf..d76492b 100644 --- a/content/renderer/audio_device.h +++ b/content/renderer/audio_device.h @@ -42,7 +42,7 @@ class AudioDevice : public AudioMessageFilter::Delegate, private: // AudioMessageFilter::Delegate implementation. virtual void OnRequestPacket(AudioBuffersState buffers_state); - virtual void OnStateChanged(const ViewMsg_AudioStreamState_Params& state); + virtual void OnStateChanged(AudioStreamState state); virtual void OnCreated(base::SharedMemoryHandle handle, uint32 length); virtual void OnLowLatencyCreated(base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle, diff --git a/content/renderer/audio_message_filter.cc b/content/renderer/audio_message_filter.cc index 317943c..e3d5cff 100644 --- a/content/renderer/audio_message_filter.cc +++ b/content/renderer/audio_message_filter.cc @@ -6,8 +6,7 @@ #include "base/message_loop.h" #include "base/time.h" -#include "chrome/common/render_messages.h" -#include "chrome/common/render_messages_params.h" +#include "content/common/audio_messages.h" #include "ipc/ipc_logging.h" AudioMessageFilter::AudioMessageFilter(int32 route_id) @@ -44,13 +43,12 @@ bool AudioMessageFilter::OnMessageReceived(const IPC::Message& message) { bool handled = true; IPC_BEGIN_MESSAGE_MAP(AudioMessageFilter, message) - IPC_MESSAGE_HANDLER(ViewMsg_RequestAudioPacket, OnRequestPacket) - IPC_MESSAGE_HANDLER(ViewMsg_NotifyAudioStreamCreated, OnStreamCreated) - IPC_MESSAGE_HANDLER(ViewMsg_NotifyLowLatencyAudioStreamCreated, + IPC_MESSAGE_HANDLER(AudioMsg_RequestPacket, OnRequestPacket) + IPC_MESSAGE_HANDLER(AudioMsg_NotifyStreamCreated, OnStreamCreated) + IPC_MESSAGE_HANDLER(AudioMsg_NotifyLowLatencyStreamCreated, OnLowLatencyStreamCreated) - IPC_MESSAGE_HANDLER(ViewMsg_NotifyAudioStreamStateChanged, - OnStreamStateChanged) - IPC_MESSAGE_HANDLER(ViewMsg_NotifyAudioStreamVolume, OnStreamVolume) + IPC_MESSAGE_HANDLER(AudioMsg_NotifyStreamStateChanged, OnStreamStateChanged) + IPC_MESSAGE_HANDLER(AudioMsg_NotifyStreamVolume, OnStreamVolume) IPC_MESSAGE_UNHANDLED(handled = false) IPC_END_MESSAGE_MAP() return handled; @@ -117,8 +115,7 @@ void AudioMessageFilter::OnLowLatencyStreamCreated( } void AudioMessageFilter::OnStreamStateChanged( - int stream_id, - const ViewMsg_AudioStreamState_Params& state) { + int stream_id, AudioStreamState state) { Delegate* delegate = delegates_.Lookup(stream_id); if (!delegate) { DLOG(WARNING) << "Got audio stream event for a non-existent or removed" diff --git a/content/renderer/audio_message_filter.h b/content/renderer/audio_message_filter.h index e362839..806dd60 100644 --- a/content/renderer/audio_message_filter.h +++ b/content/renderer/audio_message_filter.h @@ -15,11 +15,10 @@ #include "base/id_map.h" #include "base/shared_memory.h" #include "base/sync_socket.h" +#include "content/common/audio_stream_state.h" #include "ipc/ipc_channel_proxy.h" #include "media/audio/audio_buffers_state.h" -struct ViewMsg_AudioStreamState_Params; - namespace base { class Time; } @@ -32,8 +31,7 @@ class AudioMessageFilter : public IPC::ChannelProxy::MessageFilter { virtual void OnRequestPacket(AudioBuffersState buffers_state) = 0; // Called when state of an audio stream has changed in the browser process. - virtual void OnStateChanged( - const ViewMsg_AudioStreamState_Params& state) = 0; + virtual void OnStateChanged(AudioStreamState state) = 0; // Called when an audio stream has been created in the browser process. virtual void OnCreated(base::SharedMemoryHandle handle, uint32 length) = 0; @@ -100,8 +98,7 @@ class AudioMessageFilter : public IPC::ChannelProxy::MessageFilter { // Received when internal state of browser process' audio output device has // changed. - void OnStreamStateChanged(int stream_id, - const ViewMsg_AudioStreamState_Params& state); + void OnStreamStateChanged(int stream_id, AudioStreamState state); // Notification of volume property of an audio output stream. void OnStreamVolume(int stream_id, double volume); diff --git a/content/renderer/audio_message_filter_unittest.cc b/content/renderer/audio_message_filter_unittest.cc index bfd42eb..1920823 100644 --- a/content/renderer/audio_message_filter_unittest.cc +++ b/content/renderer/audio_message_filter_unittest.cc @@ -3,8 +3,7 @@ // found in the LICENSE file. #include "base/message_loop.h" -#include "chrome/common/render_messages.h" -#include "chrome/common/render_messages_params.h" +#include "content/common/audio_messages.h" #include "content/renderer/audio_message_filter.h" #include "testing/gtest/include/gtest/gtest.h" @@ -21,7 +20,7 @@ class MockAudioDelegate : public AudioMessageFilter::Delegate { buffers_state_ = buffers_state; } - virtual void OnStateChanged(const ViewMsg_AudioStreamState_Params& state) { + virtual void OnStateChanged(AudioStreamState state) { state_changed_received_ = true; state_ = state; } @@ -48,7 +47,7 @@ class MockAudioDelegate : public AudioMessageFilter::Delegate { buffers_state_.timestamp = base::Time(); state_changed_received_ = false; - state_.state = ViewMsg_AudioStreamState_Params::kError; + state_ = kAudioStreamError; created_received_ = false; handle_ = base::SharedMemory::NULLHandle(); @@ -62,7 +61,7 @@ class MockAudioDelegate : public AudioMessageFilter::Delegate { AudioBuffersState buffers_state() { return buffers_state_; } bool state_changed_received() { return state_changed_received_; } - ViewMsg_AudioStreamState_Params state() { return state_; } + AudioStreamState state() { return state_; } bool created_received() { return created_received_; } base::SharedMemoryHandle handle() { return handle_; } @@ -76,7 +75,7 @@ class MockAudioDelegate : public AudioMessageFilter::Delegate { AudioBuffersState buffers_state_; bool state_changed_received_; - ViewMsg_AudioStreamState_Params state_; + AudioStreamState state_; bool created_received_; base::SharedMemoryHandle handle_; @@ -99,12 +98,12 @@ TEST(AudioMessageFilterTest, Basic) { MockAudioDelegate delegate; int stream_id = filter->AddDelegate(&delegate); - // ViewMsg_RequestAudioPacket + // AudioMsg_RequestPacket const int kSizeInBuffer = 1024; AudioBuffersState buffers_state(kSizeInBuffer, 0); EXPECT_FALSE(delegate.request_packet_received()); - filter->OnMessageReceived(ViewMsg_RequestAudioPacket( + filter->OnMessageReceived(AudioMsg_RequestPacket( kRouteId, stream_id, buffers_state)); EXPECT_TRUE(delegate.request_packet_received()); EXPECT_EQ(kSizeInBuffer, delegate.buffers_state().pending_bytes); @@ -112,34 +111,33 @@ TEST(AudioMessageFilterTest, Basic) { EXPECT_TRUE(buffers_state.timestamp == delegate.buffers_state().timestamp); delegate.Reset(); - // ViewMsg_NotifyAudioStreamStateChanged - const ViewMsg_AudioStreamState_Params kState( - ViewMsg_AudioStreamState_Params::kPlaying); + // AudioMsg_NotifyStreamStateChanged EXPECT_FALSE(delegate.state_changed_received()); filter->OnMessageReceived( - ViewMsg_NotifyAudioStreamStateChanged(kRouteId, stream_id, kState)); + AudioMsg_NotifyStreamStateChanged(kRouteId, stream_id, + kAudioStreamPlaying)); EXPECT_TRUE(delegate.state_changed_received()); - EXPECT_TRUE(kState.state == delegate.state().state); + EXPECT_TRUE(kAudioStreamPlaying == delegate.state()); delegate.Reset(); - // ViewMsg_NotifyAudioStreamCreated + // AudioMsg_NotifyStreamCreated const uint32 kLength = 1024; EXPECT_FALSE(delegate.created_received()); filter->OnMessageReceived( - ViewMsg_NotifyAudioStreamCreated(kRouteId, - stream_id, - base::SharedMemory::NULLHandle(), - kLength)); + AudioMsg_NotifyStreamCreated(kRouteId, + stream_id, + base::SharedMemory::NULLHandle(), + kLength)); EXPECT_TRUE(delegate.created_received()); EXPECT_FALSE(base::SharedMemory::IsHandleValid(delegate.handle())); EXPECT_EQ(kLength, delegate.length()); delegate.Reset(); - // ViewMsg_NotifyAudioStreamVolume + // AudioMsg_NotifyStreamVolume const double kVolume = 1.0; EXPECT_FALSE(delegate.volume_received()); filter->OnMessageReceived( - ViewMsg_NotifyAudioStreamVolume(kRouteId, stream_id, kVolume)); + AudioMsg_NotifyStreamVolume(kRouteId, stream_id, kVolume)); EXPECT_TRUE(delegate.volume_received()); EXPECT_EQ(kVolume, delegate.volume()); delegate.Reset(); @@ -163,7 +161,7 @@ TEST(AudioMessageFilterTest, Delegates) { EXPECT_FALSE(delegate1.request_packet_received()); EXPECT_FALSE(delegate2.request_packet_received()); filter->OnMessageReceived( - ViewMsg_RequestAudioPacket(kRouteId, stream_id1, AudioBuffersState())); + AudioMsg_RequestPacket(kRouteId, stream_id1, AudioBuffersState())); EXPECT_TRUE(delegate1.request_packet_received()); EXPECT_FALSE(delegate2.request_packet_received()); delegate1.Reset(); @@ -171,7 +169,7 @@ TEST(AudioMessageFilterTest, Delegates) { EXPECT_FALSE(delegate1.request_packet_received()); EXPECT_FALSE(delegate2.request_packet_received()); filter->OnMessageReceived( - ViewMsg_RequestAudioPacket(kRouteId, stream_id2, AudioBuffersState())); + AudioMsg_RequestPacket(kRouteId, stream_id2, AudioBuffersState())); EXPECT_FALSE(delegate1.request_packet_received()); EXPECT_TRUE(delegate2.request_packet_received()); delegate2.Reset(); @@ -179,21 +177,20 @@ TEST(AudioMessageFilterTest, Delegates) { // Send a message of a different route id, a message is not received. EXPECT_FALSE(delegate1.request_packet_received()); filter->OnMessageReceived( - ViewMsg_RequestAudioPacket(kRouteId + 1, stream_id1, - AudioBuffersState())); + AudioMsg_RequestPacket(kRouteId + 1, stream_id1, AudioBuffersState())); EXPECT_FALSE(delegate1.request_packet_received()); // Remove the delegates. Make sure they won't get called. filter->RemoveDelegate(stream_id1); EXPECT_FALSE(delegate1.request_packet_received()); filter->OnMessageReceived( - ViewMsg_RequestAudioPacket(kRouteId, stream_id1, AudioBuffersState())); + AudioMsg_RequestPacket(kRouteId, stream_id1, AudioBuffersState())); EXPECT_FALSE(delegate1.request_packet_received()); filter->RemoveDelegate(stream_id2); EXPECT_FALSE(delegate2.request_packet_received()); filter->OnMessageReceived( - ViewMsg_RequestAudioPacket(kRouteId, stream_id2, AudioBuffersState())); + AudioMsg_RequestPacket(kRouteId, stream_id2, AudioBuffersState())); EXPECT_FALSE(delegate2.request_packet_received()); message_loop.RunAllPending(); diff --git a/content/renderer/media/audio_renderer_impl.cc b/content/renderer/media/audio_renderer_impl.cc index f982cb1..e4730cb 100644 --- a/content/renderer/media/audio_renderer_impl.cc +++ b/content/renderer/media/audio_renderer_impl.cc @@ -6,9 +6,8 @@ #include <math.h> -#include "chrome/common/render_messages.h" -#include "chrome/common/render_messages_params.h" #include "chrome/renderer/render_thread.h" +#include "content/common/audio_messages.h" #include "content/renderer/render_view.h" #include "media/base/filter_host.h" @@ -209,16 +208,15 @@ void AudioRendererImpl::OnRequestPacket(AudioBuffersState buffers_state) { NotifyPacketReadyTask(); } -void AudioRendererImpl::OnStateChanged( - const ViewMsg_AudioStreamState_Params& state) { +void AudioRendererImpl::OnStateChanged(AudioStreamState state) { DCHECK(MessageLoop::current() == io_loop_); base::AutoLock auto_lock(lock_); if (stopped_) return; - switch (state.state) { - case ViewMsg_AudioStreamState_Params::kError: + switch (state) { + case kAudioStreamError: // We receive this error if we counter an hardware error on the browser // side. We can proceed with ignoring the audio stream. // TODO(hclam): We need more handling of these kind of error. For example @@ -227,8 +225,8 @@ void AudioRendererImpl::OnStateChanged( host()->DisableAudioRenderer(); break; // TODO(hclam): handle these events. - case ViewMsg_AudioStreamState_Params::kPlaying: - case ViewMsg_AudioStreamState_Params::kPaused: + case kAudioStreamPlaying: + case kAudioStreamPaused: break; default: NOTREACHED(); @@ -253,34 +251,32 @@ void AudioRendererImpl::CreateStreamTask(const AudioParameters& audio_params) { stream_id_ = filter_->AddDelegate(this); io_loop_->AddDestructionObserver(this); - ViewHostMsg_Audio_CreateStream_Params params; - params.params = audio_params; - + AudioParameters params_to_send(audio_params); // Let the browser choose packet size. - params.params.samples_per_packet = 0; + params_to_send.samples_per_packet = 0; - filter_->Send(new ViewHostMsg_CreateAudioStream(0, stream_id_, params, - false)); + filter_->Send(new AudioHostMsg_CreateStream( + 0, stream_id_, params_to_send, false)); } void AudioRendererImpl::PlayTask() { DCHECK(MessageLoop::current() == io_loop_); - filter_->Send(new ViewHostMsg_PlayAudioStream(0, stream_id_)); + filter_->Send(new AudioHostMsg_PlayStream(0, stream_id_)); } void AudioRendererImpl::PauseTask() { DCHECK(MessageLoop::current() == io_loop_); - filter_->Send(new ViewHostMsg_PauseAudioStream(0, stream_id_)); + filter_->Send(new AudioHostMsg_PauseStream(0, stream_id_)); } void AudioRendererImpl::SeekTask() { DCHECK(MessageLoop::current() == io_loop_); // We have to pause the audio stream before we can flush. - filter_->Send(new ViewHostMsg_PauseAudioStream(0, stream_id_)); - filter_->Send(new ViewHostMsg_FlushAudioStream(0, stream_id_)); + filter_->Send(new AudioHostMsg_PauseStream(0, stream_id_)); + filter_->Send(new AudioHostMsg_FlushStream(0, stream_id_)); } void AudioRendererImpl::DestroyTask() { @@ -289,7 +285,7 @@ void AudioRendererImpl::DestroyTask() { // Make sure we don't call destroy more than once. DCHECK_NE(0, stream_id_); filter_->RemoveDelegate(stream_id_); - filter_->Send(new ViewHostMsg_CloseAudioStream(0, stream_id_)); + filter_->Send(new AudioHostMsg_CloseStream(0, stream_id_)); io_loop_->RemoveDestructionObserver(this); stream_id_ = 0; } @@ -300,7 +296,7 @@ void AudioRendererImpl::SetVolumeTask(double volume) { base::AutoLock auto_lock(lock_); if (stopped_) return; - filter_->Send(new ViewHostMsg_SetAudioVolume(0, stream_id_, volume)); + filter_->Send(new AudioHostMsg_SetVolume(0, stream_id_, volume)); } void AudioRendererImpl::NotifyPacketReadyTask() { @@ -343,8 +339,7 @@ void AudioRendererImpl::NotifyPacketReadyTask() { request_buffers_state_.pending_bytes == 0); pending_request_ = false; // Then tell browser process we are done filling into the buffer. - filter_->Send( - new ViewHostMsg_NotifyAudioPacketReady(0, stream_id_, filled)); + filter_->Send(new AudioHostMsg_NotifyPacketReady(0, stream_id_, filled)); } } diff --git a/content/renderer/media/audio_renderer_impl.h b/content/renderer/media/audio_renderer_impl.h index adb9674..664ee13 100644 --- a/content/renderer/media/audio_renderer_impl.h +++ b/content/renderer/media/audio_renderer_impl.h @@ -62,7 +62,7 @@ class AudioRendererImpl : public media::AudioRendererBase, // Methods called on IO thread ---------------------------------------------- // AudioMessageFilter::Delegate methods, called by AudioMessageFilter. virtual void OnRequestPacket(AudioBuffersState buffers_state); - virtual void OnStateChanged(const ViewMsg_AudioStreamState_Params& state); + virtual void OnStateChanged(AudioStreamState state); virtual void OnCreated(base::SharedMemoryHandle handle, uint32 length); virtual void OnLowLatencyCreated(base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle, diff --git a/content/renderer/media/audio_renderer_impl_unittest.cc b/content/renderer/media/audio_renderer_impl_unittest.cc index 43ff9e5..f29f39f 100644 --- a/content/renderer/media/audio_renderer_impl_unittest.cc +++ b/content/renderer/media/audio_renderer_impl_unittest.cc @@ -3,8 +3,7 @@ // found in the LICENSE file. #include "base/process_util.h" -#include "chrome/common/render_messages.h" -#include "chrome/common/render_messages_params.h" +#include "content/common/audio_messages.h" #include "content/renderer/media/audio_renderer_impl.h" #include "media/base/data_buffer.h" #include "media/base/media_format.h" @@ -95,14 +94,6 @@ TEST_F(AudioRendererImplTest, SetVolume) { } TEST_F(AudioRendererImplTest, Stop) { - // Declare some state messages. - const ViewMsg_AudioStreamState_Params kError( - ViewMsg_AudioStreamState_Params::kError); - const ViewMsg_AudioStreamState_Params kPlaying( - ViewMsg_AudioStreamState_Params::kPlaying); - const ViewMsg_AudioStreamState_Params kPaused( - ViewMsg_AudioStreamState_Params::kPaused); - // Execute Stop() codepath to create an IPC message. renderer_->Stop(media::NewExpectedCallback()); message_loop_->RunAllPending(); @@ -110,9 +101,9 @@ TEST_F(AudioRendererImplTest, Stop) { // Run AudioMessageFilter::Delegate methods, which can be executed after being // stopped. AudioRendererImpl shouldn't create any messages. renderer_->OnRequestPacket(AudioBuffersState(kSize, 0)); - renderer_->OnStateChanged(kError); - renderer_->OnStateChanged(kPlaying); - renderer_->OnStateChanged(kPaused); + renderer_->OnStateChanged(kAudioStreamError); + renderer_->OnStateChanged(kAudioStreamPlaying); + renderer_->OnStateChanged(kAudioStreamPaused); renderer_->OnCreated(shared_mem_.handle(), kSize); renderer_->OnVolume(0.5); diff --git a/content/renderer/pepper_plugin_delegate_impl.cc b/content/renderer/pepper_plugin_delegate_impl.cc index 2acad4d..6f701fb 100644 --- a/content/renderer/pepper_plugin_delegate_impl.cc +++ b/content/renderer/pepper_plugin_delegate_impl.cc @@ -19,6 +19,7 @@ #include "chrome/common/render_messages.h" #include "chrome/common/render_messages_params.h" #include "chrome/renderer/render_thread.h" +#include "content/common/audio_messages.h" #include "content/common/child_process_messages.h" #include "content/common/child_thread.h" #include "content/common/file_system/file_system_dispatcher.h" @@ -142,8 +143,7 @@ class PlatformAudioImpl private: // I/O thread backends to above functions. - void InitializeOnIOThread( - const ViewHostMsg_Audio_CreateStream_Params& params); + void InitializeOnIOThread(const AudioParameters& params); void StartPlaybackOnIOThread(); void StopPlaybackOnIOThread(); void ShutDownOnIOThread(); @@ -152,7 +152,7 @@ class PlatformAudioImpl LOG(FATAL) << "Should never get OnRequestPacket in PlatformAudioImpl"; } - virtual void OnStateChanged(const ViewMsg_AudioStreamState_Params& state) {} + virtual void OnStateChanged(AudioStreamState state) {} virtual void OnCreated(base::SharedMemoryHandle handle, uint32 length) { LOG(FATAL) << "Should never get OnCreated in PlatformAudioImpl"; @@ -191,12 +191,12 @@ bool PlatformAudioImpl::Initialize( client_ = client; - ViewHostMsg_Audio_CreateStream_Params params; - params.params.format = AudioParameters::AUDIO_PCM_LINEAR; - params.params.channels = 2; - params.params.sample_rate = sample_rate; - params.params.bits_per_sample = 16; - params.params.samples_per_packet = sample_count; + AudioParameters params; + params.format = AudioParameters::AUDIO_PCM_LINEAR; + params.channels = 2; + params.sample_rate = sample_rate; + params.bits_per_sample = 16; + params.samples_per_packet = sample_count; filter_->message_loop()->PostTask(FROM_HERE, NewRunnableMethod(this, &PlatformAudioImpl::InitializeOnIOThread, @@ -230,20 +230,19 @@ void PlatformAudioImpl::ShutDown() { NewRunnableMethod(this, &PlatformAudioImpl::ShutDownOnIOThread)); } -void PlatformAudioImpl::InitializeOnIOThread( - const ViewHostMsg_Audio_CreateStream_Params& params) { +void PlatformAudioImpl::InitializeOnIOThread(const AudioParameters& params) { stream_id_ = filter_->AddDelegate(this); - filter_->Send(new ViewHostMsg_CreateAudioStream(0, stream_id_, params, true)); + filter_->Send(new AudioHostMsg_CreateStream(0, stream_id_, params, true)); } void PlatformAudioImpl::StartPlaybackOnIOThread() { if (stream_id_) - filter_->Send(new ViewHostMsg_PlayAudioStream(0, stream_id_)); + filter_->Send(new AudioHostMsg_PlayStream(0, stream_id_)); } void PlatformAudioImpl::StopPlaybackOnIOThread() { if (stream_id_) - filter_->Send(new ViewHostMsg_PauseAudioStream(0, stream_id_)); + filter_->Send(new AudioHostMsg_PauseStream(0, stream_id_)); } void PlatformAudioImpl::ShutDownOnIOThread() { @@ -251,7 +250,7 @@ void PlatformAudioImpl::ShutDownOnIOThread() { if (!stream_id_) return; - filter_->Send(new ViewHostMsg_CloseAudioStream(0, stream_id_)); + filter_->Send(new AudioHostMsg_CloseStream(0, stream_id_)); filter_->RemoveDelegate(stream_id_); stream_id_ = 0; diff --git a/ipc/ipc_message_utils.h b/ipc/ipc_message_utils.h index c2e6a58..6aaa3f3 100644 --- a/ipc/ipc_message_utils.h +++ b/ipc/ipc_message_utils.h @@ -80,6 +80,7 @@ enum IPCMessageStart { DeviceOrientationMsgStart, DesktopNotificationMsgStart, GeolocationMsgStart, + AudioMsgStart, LastIPCMsgStart // Must come last. }; |