diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-14 06:36:58 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-14 06:36:58 +0000 |
commit | 5a23ee545578c03fa81a23d59d7f57528b1592e4 (patch) | |
tree | c342d7bb03eda2332cbea7e264e1bd693040d31b /chrome/browser/renderer_host/audio_renderer_host.h | |
parent | ee287e40bb740d7238717a97b5f635ae3e68c47a (diff) | |
download | chromium_src-5a23ee545578c03fa81a23d59d7f57528b1592e4.zip chromium_src-5a23ee545578c03fa81a23d59d7f57528b1592e4.tar.gz chromium_src-5a23ee545578c03fa81a23d59d7f57528b1592e4.tar.bz2 |
Add render view id to AudioRendererHost
AudioRendererHost were assigning ids in the browser process, that means
CreateStream has to be done in a synchronous IPC call. To avoid that we
allow renderer processes to provide the stream id when they do
CreateStrea. Then to identify a IPCAudioSource inside AudioRendererHost
we need a tuple of (render_view_id, stream_id). By doing this we can
create stream asynchronously just like BeginRequest in
ResourceDispatcherHost.
Review URL: http://codereview.chromium.org/21319
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9824 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/renderer_host/audio_renderer_host.h')
-rw-r--r-- | chrome/browser/renderer_host/audio_renderer_host.h | 78 |
1 files changed, 42 insertions, 36 deletions
diff --git a/chrome/browser/renderer_host/audio_renderer_host.h b/chrome/browser/renderer_host/audio_renderer_host.h index df2c14e..bcdf640 100644 --- a/chrome/browser/renderer_host/audio_renderer_host.h +++ b/chrome/browser/renderer_host/audio_renderer_host.h @@ -6,17 +6,16 @@ // lives inside the render process and provide access to audio hardware. It maps // an internal ID to AudioRendererHost::IPCAudioSource in a map, which is the // actual object providing audio packets through IPC. It creates the actual -// AudioOutputStream object when requested by the renderer and returns an -// internal ID. It then delegates calls to the AudioOutputStream object indexed -// by the internal id. +// AudioOutputStream object when requested by the renderer provided with +// render view id and stream id. // // AudioRendererHost::IPCAudioSource is a container of AudioOutputStream and // provide audio packets to the associated AudioOutputStream through IPC. It // transforms the pull data model to a push model used for IPC. When asked by // AudioOutputStream for an audio packet, it would send a message to renderer, // passing a SharedMemoryHandle for filling the buffer. -// NotifyPacketReady(|stream_id|) would be called when the buffer is filled -// and ready to be consumed. +// NotifyPacketReady(|render_view_id|, |stream_id|) would be called when the +// buffer is filled and ready to be consumed. // // This class is owned by BrowserRenderProcessHost, and instantiated on UI // thread, but all other operations and method calls (except Destroy()) happens @@ -41,7 +40,8 @@ #ifndef CHROME_BROWSER_RENDERER_HOST_AUDIO_RENDERER_HOST_H_ #define CHROME_BROWSER_RENDERER_HOST_AUDIO_RENDERER_HOST_H_ -#include "base/id_map.h" +#include <map> + #include "base/ref_counted.h" #include "base/shared_memory.h" #include "chrome/common/ipc_message.h" @@ -52,55 +52,55 @@ class MessageLoop; class AudioRendererHost : public base::RefCountedThreadSafe<AudioRendererHost> { public: - static const int32 INVALID_ID = 0; - explicit AudioRendererHost(MessageLoop* message_loop); ~AudioRendererHost(); // Creates an audio output stream with the specified format, returns the - // stream id if successful, otherwise INVALID_ID. If this call is successful - // this object would keep an internal entry of the stream about the - // required properties, renderer process handle and IPC channel for sending - // buffer request messages. - int32 CreateStream(IPC::Message::Sender* sender, base::ProcessHandle handle, - AudioManager::Format format, int channels, int sample_rate, - int bits_per_sample, size_t packet_size); + // true if successful. If this call is successful this object would keep an + // internal entry of the stream about the required properties, renderer + // process handle and IPC channel for sending buffer request messages. + bool CreateStream(IPC::Message::Sender* sender, base::ProcessHandle handle, + int32 render_view_id, int32 stream_id, + AudioManager::Format format, int channels, int sample_rate, + int bits_per_sample, size_t packet_size); // Start the audio output strean, return false if stream doesn't exist or the // cannot start. - bool Start(int32 stream_id); + bool Start(int32 render_view_id, int32 stream_id); // Stop the audio output stream, return false if stream doesn't exist or // cannot stop. - bool Stop(int32 stream_id); + bool Stop(int32 render_view_id, int32 stream_id); // Close the audio output stream, return false if stream doesn't exist or // cannot close. If this call is successful, the AudioOutputStream correspond - // to |stream_id| would go unmanaged by this class, subsequent calls to - // this object with the same |stream_id| would fail. - bool Close(int32 stream_id); + // to (|render_view_id|, |stream_id|) would go unmanaged by this class, + // subsequent calls to this object with the same + // (|render_view_id|, |stream_id|) would fail. + bool Close(int32 render_view_id, int32 stream_id); // Set the volume for the stream specified, returns true if successful, false // if stream doesn't exist or cann't set volume. - bool SetVolume( - int32 stream_id, double left_channel, double right_channel); + bool SetVolume(int32 render_view_id, int32 stream_id, + double left_channel, double right_channel); // Get the volume of the stream specified, returns true if successful, false // is stream doesn't exist or can't get volume. - bool GetVolume( - int32 stream_id, double* left_channel, double* right_channel); + bool GetVolume(int32 render_view_id, int32 stream_id, + double* left_channel, double* right_channel); // Notify packet has been prepared for stream specified by |stream_id|. The - // buffer associated with |stream_id| has been filled and is ready to be - // consumed. - void NotifyPacketReady(int32 stream_id); + // buffer associated with (|render_view_id|, |stream_id|) has been filled and + // is ready to be consumed. + void NotifyPacketReady(int32 render_view_id, int32 stream_id); // Called from UI thread from the owner of this object. void Destroy(); - // Destroy the stream specified by |stream_id| and remove it from map. + // Destroy the stream specified by (|render_view_id|, |stream_id|) and remove + // it from map. // *DO NOT* call this method other than from IPCAudioSource. - void DestroySource(int32 stream_id); + void DestroySource(int32 render_view_id, int32 stream_id); private: // Methods called on IO thread. @@ -117,7 +117,8 @@ class AudioRendererHost : public base::RefCountedThreadSafe<AudioRendererHost> { class IPCAudioSource : public AudioOutputStream::AudioSourceCallback { public: IPCAudioSource(AudioRendererHost* host, // Host of this source. - int32 id, // ID of this source. + int32 render_view_id, // Routing ID to RenderView. + int32 stream_id, // ID of this source. AudioOutputStream* stream, // Stream associated. IPC::Message::Sender* sender, // IPC sender to user. base::ProcessHandle process, // Render process handle. @@ -135,23 +136,28 @@ class AudioRendererHost : public base::RefCountedThreadSafe<AudioRendererHost> { // consumed. void NotifyPacketReady(); - int32 id() { return id_; } + int32 render_view_id() { return render_view_id_; } + int32 stream_id() { return stream_id_; } AudioOutputStream* stream() { return stream_; } private: AudioRendererHost* host_; - int32 id_; + int32 render_view_id_; + int32 stream_id_; AudioOutputStream* stream_; IPC::Message::Sender* sender_; base::SharedMemory shared_memory_; base::SharedMemoryHandle foreign_memory_handle_; }; - // A map of id to audio sources. - IDMap<IPCAudioSource> sources_; + // Look up a IPCAudioSource with a tuple of render view id and stream id. + // Return NULL if not found. + IPCAudioSource* Lookup(int render_view_id, int stream_id); - // An internal id for streams. - int32 next_id_; + // A map of id to audio sources. + typedef std::pair<int32, int32> SourceID; + typedef std::map<SourceID, IPCAudioSource*> SourceMap; + SourceMap sources_; // Only used for DCHECKs to make sure all methods calls are from the same // thread as this object is created. |