summaryrefslogtreecommitdiffstats
path: root/chrome/browser/renderer_host
diff options
context:
space:
mode:
authorhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-14 19:55:48 +0000
committerhclam@chromium.org <hclam@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-02-14 19:55:48 +0000
commitdda6fa35a307c5a77b85602159f434fd7c252836 (patch)
tree4515656a0a870939dbcf6892b48baa02c99c26ca /chrome/browser/renderer_host
parent5a23ee545578c03fa81a23d59d7f57528b1592e4 (diff)
downloadchromium_src-dda6fa35a307c5a77b85602159f434fd7c252836.zip
chromium_src-dda6fa35a307c5a77b85602159f434fd7c252836.tar.gz
chromium_src-dda6fa35a307c5a77b85602159f434fd7c252836.tar.bz2
Rollback my change that seems to break some tests.
TBR Review URL: http://codereview.chromium.org/21375 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@9825 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/renderer_host')
-rw-r--r--chrome/browser/renderer_host/audio_renderer_host.cc80
-rw-r--r--chrome/browser/renderer_host/audio_renderer_host.h78
2 files changed, 69 insertions, 89 deletions
diff --git a/chrome/browser/renderer_host/audio_renderer_host.cc b/chrome/browser/renderer_host/audio_renderer_host.cc
index f8851d4..5c0d0f9 100644
--- a/chrome/browser/renderer_host/audio_renderer_host.cc
+++ b/chrome/browser/renderer_host/audio_renderer_host.cc
@@ -8,15 +8,13 @@
AudioRendererHost::IPCAudioSource::IPCAudioSource(
AudioRendererHost* host,
- int32 render_view_id,
- int32 stream_id,
+ int32 id,
AudioOutputStream* stream,
IPC::Message::Sender* sender,
base::ProcessHandle process,
size_t packet_size)
: host_(host),
- render_view_id_(render_view_id),
- stream_id_(stream_id),
+ id_(id),
stream_(stream),
sender_(sender) {
// Make sure we can create and map the shared memory.
@@ -50,7 +48,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(render_view_id_, stream_id_);
+ host_->DestroySource(id_);
}
void AudioRendererHost::IPCAudioSource::OnError(AudioOutputStream* stream,
@@ -69,7 +67,8 @@ void AudioRendererHost::IPCAudioSource::NotifyPacketReady() {
}
AudioRendererHost::AudioRendererHost(MessageLoop* message_loop)
- : io_loop_(message_loop) {
+ : next_id_(INVALID_ID+1),
+ io_loop_(message_loop) {
// Make sure we perform actual initialization operations in the thread where
// this object should live.
io_loop_->PostTask(FROM_HERE,
@@ -79,35 +78,33 @@ AudioRendererHost::AudioRendererHost(MessageLoop* message_loop)
AudioRendererHost::~AudioRendererHost() {
}
-bool AudioRendererHost::CreateStream(
+int AudioRendererHost::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) {
+ 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 false;
+ return INVALID_ID;
// 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, 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;
+ new IPCAudioSource(this, next_id_++, stream, sender, handle,
+ packet_size);
+ sources_.AddWithID(source, source->id());
+ return source->id();
}
- return false;
+ return INVALID_ID;
}
-bool AudioRendererHost::Start(int32 render_view_id, int32 stream_id) {
+bool AudioRendererHost::Start(int stream_id) {
DCHECK(MessageLoop::current() == io_loop_);
- IPCAudioSource* source = Lookup(render_view_id, stream_id);
+ IPCAudioSource* source = sources_.Lookup(stream_id);
if (source) {
source->stream()->Start(source);
return true;
@@ -115,9 +112,9 @@ bool AudioRendererHost::Start(int32 render_view_id, int32 stream_id) {
return false;
}
-bool AudioRendererHost::Stop(int32 render_view_id, int32 stream_id) {
+bool AudioRendererHost::Stop(int stream_id) {
DCHECK(MessageLoop::current() == io_loop_);
- IPCAudioSource* source = Lookup(render_view_id, stream_id);
+ IPCAudioSource* source = sources_.Lookup(stream_id);
if (source) {
source->stream()->Stop();
return true;
@@ -125,9 +122,9 @@ bool AudioRendererHost::Stop(int32 render_view_id, int32 stream_id) {
return false;
}
-bool AudioRendererHost::Close(int32 render_view_id, int32 stream_id) {
+bool AudioRendererHost::Close(int stream_id) {
DCHECK(MessageLoop::current() == io_loop_);
- IPCAudioSource* source = Lookup(render_view_id, stream_id);
+ IPCAudioSource* source = sources_.Lookup(stream_id);
if (source) {
source->stream()->Close();
return true;
@@ -135,20 +132,20 @@ bool AudioRendererHost::Close(int32 render_view_id, int32 stream_id) {
return false;
}
-bool AudioRendererHost::SetVolume(int32 render_view_id, int32 stream_id,
- double left_channel, double right_channel) {
+bool AudioRendererHost::SetVolume(
+ int stream_id, double left_channel, double right_channel) {
DCHECK(MessageLoop::current() == io_loop_);
- IPCAudioSource* source = Lookup(render_view_id, stream_id);
+ IPCAudioSource* source = sources_.Lookup(stream_id);
if (source) {
source->stream()->SetVolume(left_channel, right_channel);
}
return false;
}
-bool AudioRendererHost::GetVolume(int32 render_view_id, int32 stream_id,
- double* left_channel, double* right_channel) {
+bool AudioRendererHost::GetVolume(
+ int stream_id, double* left_channel, double* right_channel) {
DCHECK(MessageLoop::current() == io_loop_);
- IPCAudioSource* source = Lookup(render_view_id, stream_id);
+ IPCAudioSource* source = sources_.Lookup(stream_id);
if (source) {
source->stream()->GetVolume(left_channel, right_channel);
return true;
@@ -156,10 +153,9 @@ bool AudioRendererHost::GetVolume(int32 render_view_id, int32 stream_id,
return false;
}
-void AudioRendererHost::NotifyPacketReady(int32 render_view_id,
- int32 stream_id) {
+void AudioRendererHost::NotifyPacketReady(int stream_id) {
DCHECK(MessageLoop::current() == io_loop_);
- IPCAudioSource* source = Lookup(render_view_id, stream_id);
+ IPCAudioSource* source = sources_.Lookup(stream_id);
if (source) {
source->NotifyPacketReady();
}
@@ -171,14 +167,12 @@ void AudioRendererHost::DestroyAllStreams() {
// the map.
}
-void AudioRendererHost::DestroySource(int32 render_view_id, int32 stream_id) {
+void AudioRendererHost::DestroySource(int stream_id) {
DCHECK(MessageLoop::current() == io_loop_);
- 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;
+ IPCAudioSource* source = sources_.Lookup(stream_id);
+ if (source) {
+ sources_.Remove(stream_id);
+ delete source;
}
}
@@ -213,11 +207,3 @@ 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;
-}
diff --git a/chrome/browser/renderer_host/audio_renderer_host.h b/chrome/browser/renderer_host/audio_renderer_host.h
index bcdf640..df2c14e 100644
--- a/chrome/browser/renderer_host/audio_renderer_host.h
+++ b/chrome/browser/renderer_host/audio_renderer_host.h
@@ -6,16 +6,17 @@
// 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 provided with
-// render view id and stream id.
+// 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.
//
// 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(|render_view_id|, |stream_id|) would be called when the
-// buffer is filled and ready to be consumed.
+// NotifyPacketReady(|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
@@ -40,8 +41,7 @@
#ifndef CHROME_BROWSER_RENDERER_HOST_AUDIO_RENDERER_HOST_H_
#define CHROME_BROWSER_RENDERER_HOST_AUDIO_RENDERER_HOST_H_
-#include <map>
-
+#include "base/id_map.h"
#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
- // 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);
+ // 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);
// Start the audio output strean, return false if stream doesn't exist or the
// cannot start.
- bool Start(int32 render_view_id, int32 stream_id);
+ bool Start(int32 stream_id);
// Stop the audio output stream, return false if stream doesn't exist or
// cannot stop.
- bool Stop(int32 render_view_id, int32 stream_id);
+ bool Stop(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 (|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);
+ // 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);
// 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 render_view_id, int32 stream_id,
- double left_channel, double right_channel);
+ bool SetVolume(
+ 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 render_view_id, int32 stream_id,
- double* left_channel, double* right_channel);
+ bool GetVolume(
+ int32 stream_id, double* left_channel, double* right_channel);
// Notify packet has been prepared for stream specified by |stream_id|. The
- // 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);
+ // buffer associated with |stream_id| has been filled and is ready to be
+ // consumed.
+ void NotifyPacketReady(int32 stream_id);
// Called from UI thread from the owner of this object.
void Destroy();
- // Destroy the stream specified by (|render_view_id|, |stream_id|) and remove
- // it from map.
+ // Destroy the stream specified by |stream_id| and remove it from map.
// *DO NOT* call this method other than from IPCAudioSource.
- void DestroySource(int32 render_view_id, int32 stream_id);
+ void DestroySource(int32 stream_id);
private:
// Methods called on IO thread.
@@ -117,8 +117,7 @@ class AudioRendererHost : public base::RefCountedThreadSafe<AudioRendererHost> {
class IPCAudioSource : public AudioOutputStream::AudioSourceCallback {
public:
IPCAudioSource(AudioRendererHost* host, // Host of this source.
- int32 render_view_id, // Routing ID to RenderView.
- int32 stream_id, // ID of this source.
+ int32 id, // ID of this source.
AudioOutputStream* stream, // Stream associated.
IPC::Message::Sender* sender, // IPC sender to user.
base::ProcessHandle process, // Render process handle.
@@ -136,28 +135,23 @@ class AudioRendererHost : public base::RefCountedThreadSafe<AudioRendererHost> {
// consumed.
void NotifyPacketReady();
- int32 render_view_id() { return render_view_id_; }
- int32 stream_id() { return stream_id_; }
+ int32 id() { return id_; }
AudioOutputStream* stream() { return stream_; }
private:
AudioRendererHost* host_;
- int32 render_view_id_;
- int32 stream_id_;
+ int32 id_;
AudioOutputStream* stream_;
IPC::Message::Sender* sender_;
base::SharedMemory shared_memory_;
base::SharedMemoryHandle foreign_memory_handle_;
};
- // 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);
-
// A map of id to audio sources.
- typedef std::pair<int32, int32> SourceID;
- typedef std::map<SourceID, IPCAudioSource*> SourceMap;
- SourceMap sources_;
+ IDMap<IPCAudioSource> sources_;
+
+ // An internal id for streams.
+ int32 next_id_;
// Only used for DCHECKs to make sure all methods calls are from the same
// thread as this object is created.