diff options
author | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-17 06:28:08 +0000 |
---|---|---|
committer | hclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-02-17 06:28:08 +0000 |
commit | c582e3c3b199e92be95d37b7b4d99619f94c034c (patch) | |
tree | b72eca27c6ef5d65246b87cf2bd5ba933866f1d1 /chrome/browser/renderer_host/audio_renderer_host.cc | |
parent | 001093ee6111ab841b56b620a20c9d5ce9e1a524 (diff) | |
download | chromium_src-c582e3c3b199e92be95d37b7b4d99619f94c034c.zip chromium_src-c582e3c3b199e92be95d37b7b4d99619f94c034c.tar.gz chromium_src-c582e3c3b199e92be95d37b7b4d99619f94c034c.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@9872 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/renderer_host/audio_renderer_host.cc')
-rw-r--r-- | chrome/browser/renderer_host/audio_renderer_host.cc | 80 |
1 files changed, 47 insertions, 33 deletions
diff --git a/chrome/browser/renderer_host/audio_renderer_host.cc b/chrome/browser/renderer_host/audio_renderer_host.cc index 5c0d0f9..f8851d4 100644 --- a/chrome/browser/renderer_host/audio_renderer_host.cc +++ b/chrome/browser/renderer_host/audio_renderer_host.cc @@ -8,13 +8,15 @@ AudioRendererHost::IPCAudioSource::IPCAudioSource( AudioRendererHost* host, - int32 id, + int32 render_view_id, + int32 stream_id, AudioOutputStream* stream, IPC::Message::Sender* sender, base::ProcessHandle process, size_t packet_size) : host_(host), - id_(id), + render_view_id_(render_view_id), + stream_id_(stream_id), stream_(stream), sender_(sender) { // Make sure we can create and map the shared memory. @@ -48,7 +50,7 @@ void AudioRendererHost::IPCAudioSource::OnClose(AudioOutputStream* stream) { // Stuff to do here: // 1. Send an IPC to renderer about close complete. // 2. Remove this object from host. - host_->DestroySource(id_); + host_->DestroySource(render_view_id_, stream_id_); } void AudioRendererHost::IPCAudioSource::OnError(AudioOutputStream* stream, @@ -67,8 +69,7 @@ void AudioRendererHost::IPCAudioSource::NotifyPacketReady() { } AudioRendererHost::AudioRendererHost(MessageLoop* message_loop) - : next_id_(INVALID_ID+1), - io_loop_(message_loop) { + : io_loop_(message_loop) { // Make sure we perform actual initialization operations in the thread where // this object should live. io_loop_->PostTask(FROM_HERE, @@ -78,33 +79,35 @@ AudioRendererHost::AudioRendererHost(MessageLoop* message_loop) AudioRendererHost::~AudioRendererHost() { } -int AudioRendererHost::CreateStream( +bool AudioRendererHost::CreateStream( IPC::Message::Sender* sender, base::ProcessHandle handle, - AudioManager::Format format, int channels, int sample_rate, - int bits_per_sample, size_t packet_size) { + int32 render_view_id, int32 stream_id, AudioManager::Format format, + int channels, int sample_rate, int bits_per_sample, size_t packet_size) { DCHECK(MessageLoop::current() == io_loop_); + DCHECK(Lookup(render_view_id, stream_id) == NULL); // Create the stream in the first place. AudioOutputStream* stream = AudioManager::GetAudioManager()->MakeAudioStream( format, channels, sample_rate, bits_per_sample); if (!stream) - return INVALID_ID; + return false; // Try to open the stream if we can create it. if (stream->Open(packet_size)) { // Create the containing IPCAudioSource and save it to the map. IPCAudioSource* source = - new IPCAudioSource(this, next_id_++, stream, sender, handle, - packet_size); - sources_.AddWithID(source, source->id()); - return source->id(); + new IPCAudioSource(this, render_view_id, stream_id, stream, sender, + handle, packet_size); + sources_.insert(make_pair( + SourceID(source->render_view_id(), source->stream_id()), source)); + return true; } - return INVALID_ID; + return false; } -bool AudioRendererHost::Start(int stream_id) { +bool AudioRendererHost::Start(int32 render_view_id, int32 stream_id) { DCHECK(MessageLoop::current() == io_loop_); - IPCAudioSource* source = sources_.Lookup(stream_id); + IPCAudioSource* source = Lookup(render_view_id, stream_id); if (source) { source->stream()->Start(source); return true; @@ -112,9 +115,9 @@ bool AudioRendererHost::Start(int stream_id) { return false; } -bool AudioRendererHost::Stop(int stream_id) { +bool AudioRendererHost::Stop(int32 render_view_id, int32 stream_id) { DCHECK(MessageLoop::current() == io_loop_); - IPCAudioSource* source = sources_.Lookup(stream_id); + IPCAudioSource* source = Lookup(render_view_id, stream_id); if (source) { source->stream()->Stop(); return true; @@ -122,9 +125,9 @@ bool AudioRendererHost::Stop(int stream_id) { return false; } -bool AudioRendererHost::Close(int stream_id) { +bool AudioRendererHost::Close(int32 render_view_id, int32 stream_id) { DCHECK(MessageLoop::current() == io_loop_); - IPCAudioSource* source = sources_.Lookup(stream_id); + IPCAudioSource* source = Lookup(render_view_id, stream_id); if (source) { source->stream()->Close(); return true; @@ -132,20 +135,20 @@ bool AudioRendererHost::Close(int stream_id) { return false; } -bool AudioRendererHost::SetVolume( - int stream_id, double left_channel, double right_channel) { +bool AudioRendererHost::SetVolume(int32 render_view_id, int32 stream_id, + double left_channel, double right_channel) { DCHECK(MessageLoop::current() == io_loop_); - IPCAudioSource* source = sources_.Lookup(stream_id); + IPCAudioSource* source = Lookup(render_view_id, stream_id); if (source) { source->stream()->SetVolume(left_channel, right_channel); } return false; } -bool AudioRendererHost::GetVolume( - int stream_id, double* left_channel, double* right_channel) { +bool AudioRendererHost::GetVolume(int32 render_view_id, int32 stream_id, + double* left_channel, double* right_channel) { DCHECK(MessageLoop::current() == io_loop_); - IPCAudioSource* source = sources_.Lookup(stream_id); + IPCAudioSource* source = Lookup(render_view_id, stream_id); if (source) { source->stream()->GetVolume(left_channel, right_channel); return true; @@ -153,9 +156,10 @@ bool AudioRendererHost::GetVolume( return false; } -void AudioRendererHost::NotifyPacketReady(int stream_id) { +void AudioRendererHost::NotifyPacketReady(int32 render_view_id, + int32 stream_id) { DCHECK(MessageLoop::current() == io_loop_); - IPCAudioSource* source = sources_.Lookup(stream_id); + IPCAudioSource* source = Lookup(render_view_id, stream_id); if (source) { source->NotifyPacketReady(); } @@ -167,12 +171,14 @@ void AudioRendererHost::DestroyAllStreams() { // the map. } -void AudioRendererHost::DestroySource(int stream_id) { +void AudioRendererHost::DestroySource(int32 render_view_id, int32 stream_id) { DCHECK(MessageLoop::current() == io_loop_); - IPCAudioSource* source = sources_.Lookup(stream_id); - if (source) { - sources_.Remove(stream_id); - delete source; + SourceMap::iterator i = sources_.find(SourceID(render_view_id, stream_id)); + if (i != sources_.end()) { + // Remove the entry from the map. + sources_.erase(i); + // Also delete the IPCAudioSource object. + delete i->second; } } @@ -207,3 +213,11 @@ void AudioRendererHost::OnDestroyed() { // Decrease the reference to this object, which may lead to self-destruction. Release(); } + +AudioRendererHost::IPCAudioSource* AudioRendererHost::Lookup(int render_view_id, + int stream_id) { + SourceMap::iterator i = sources_.find(SourceID(render_view_id, stream_id)); + if (i != sources_.end()) + return i->second; + return NULL; +} |