Index: content/browser/renderer_host/media/audio_renderer_host.cc |
=================================================================== |
--- content/browser/renderer_host/media/audio_renderer_host.cc (revision 90030) |
+++ content/browser/renderer_host/media/audio_renderer_host.cc (working copy) |
@@ -14,16 +14,13 @@ |
AudioRendererHost::AudioEntry::AudioEntry() |
- : render_view_id(0), |
- stream_id(0), |
+ : stream_id(0), |
pending_buffer_request(false), |
pending_close(false) { |
} |
AudioRendererHost::AudioEntry::~AudioEntry() {} |
-/////////////////////////////////////////////////////////////////////////////// |
-// AudioRendererHost implementations. |
AudioRendererHost::AudioRendererHost() { |
} |
@@ -42,8 +39,6 @@ |
BrowserThread::DeleteOnIOThread::Destruct(this); |
} |
-/////////////////////////////////////////////////////////////////////////////// |
-// media::AudioOutputController::EventHandler implementations. |
void AudioRendererHost::OnCreated(media::AudioOutputController* controller) { |
BrowserThread::PostTask( |
BrowserThread::IO, |
@@ -140,7 +135,7 @@ |
} |
Send(new AudioMsg_NotifyLowLatencyStreamCreated( |
- entry->render_view_id, entry->stream_id, foreign_memory_handle, |
+ entry->stream_id, foreign_memory_handle, |
foreign_socket_handle, entry->shared_memory.created_size())); |
return; |
} |
@@ -148,7 +143,7 @@ |
// The normal audio stream has created, send a message to the renderer |
// process. |
Send(new AudioMsg_NotifyStreamCreated( |
- entry->render_view_id, entry->stream_id, foreign_memory_handle, |
+ entry->stream_id, foreign_memory_handle, |
entry->shared_memory.created_size())); |
} |
@@ -161,7 +156,7 @@ |
return; |
Send(new AudioMsg_NotifyStreamStateChanged( |
- entry->render_view_id, entry->stream_id, kAudioStreamPlaying)); |
+ entry->stream_id, kAudioStreamPlaying)); |
} |
void AudioRendererHost::DoSendPausedMessage( |
@@ -173,7 +168,7 @@ |
return; |
Send(new AudioMsg_NotifyStreamStateChanged( |
- entry->render_view_id, entry->stream_id, kAudioStreamPaused)); |
+ entry->stream_id, kAudioStreamPaused)); |
} |
void AudioRendererHost::DoRequestMoreData( |
@@ -188,8 +183,7 @@ |
DCHECK(!entry->controller->LowLatencyMode()); |
entry->pending_buffer_request = true; |
- Send(new AudioMsg_RequestPacket( |
- entry->render_view_id, entry->stream_id, buffers_state)); |
+ Send(new AudioMsg_RequestPacket(entry->stream_id, buffers_state)); |
} |
void AudioRendererHost::DoHandleError(media::AudioOutputController* controller, |
@@ -203,8 +197,6 @@ |
DeleteEntryOnError(entry); |
} |
-/////////////////////////////////////////////////////////////////////////////// |
-// IPC Messages handler |
bool AudioRendererHost::OnMessageReceived(const IPC::Message& message, |
bool* message_was_ok) { |
bool handled = true; |
@@ -224,10 +216,9 @@ |
} |
void AudioRendererHost::OnCreateStream( |
- const IPC::Message& msg, int stream_id, |
- const AudioParameters& params, bool low_latency) { |
+ int stream_id, const AudioParameters& params, bool low_latency) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- DCHECK(LookupById(msg.routing_id(), stream_id) == NULL); |
+ DCHECK(LookupById(stream_id) == NULL); |
AudioParameters audio_params(params); |
@@ -241,7 +232,7 @@ |
// Create the shared memory and share with the renderer process. |
if (!entry->shared_memory.CreateAndMapAnonymous(packet_size)) { |
// If creation of shared memory failed then send an error message. |
- SendErrorMessage(msg.routing_id(), stream_id); |
+ SendErrorMessage(stream_id); |
return; |
} |
@@ -252,7 +243,7 @@ |
// Then try to initialize the sync reader. |
if (!reader->Init()) { |
- SendErrorMessage(msg.routing_id(), stream_id); |
+ SendErrorMessage(stream_id); |
return; |
} |
@@ -270,72 +261,68 @@ |
} |
if (!entry->controller) { |
- SendErrorMessage(msg.routing_id(), stream_id); |
+ SendErrorMessage(stream_id); |
return; |
} |
// If we have created the controller successfully create a entry and add it |
// to the map. |
- entry->render_view_id = msg.routing_id(); |
entry->stream_id = stream_id; |
- |
- audio_entries_.insert(std::make_pair( |
- AudioEntryId(msg.routing_id(), stream_id), |
- entry.release())); |
+ audio_entries_.insert(std::make_pair(stream_id, entry.release())); |
} |
-void AudioRendererHost::OnPlayStream(const IPC::Message& msg, int stream_id) { |
+void AudioRendererHost::OnPlayStream(int stream_id) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- AudioEntry* entry = LookupById(msg.routing_id(), stream_id); |
+ AudioEntry* entry = LookupById(stream_id); |
if (!entry) { |
- SendErrorMessage(msg.routing_id(), stream_id); |
+ SendErrorMessage(stream_id); |
return; |
} |
entry->controller->Play(); |
} |
-void AudioRendererHost::OnPauseStream(const IPC::Message& msg, int stream_id) { |
+void AudioRendererHost::OnPauseStream(int stream_id) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- AudioEntry* entry = LookupById(msg.routing_id(), stream_id); |
+ AudioEntry* entry = LookupById(stream_id); |
if (!entry) { |
- SendErrorMessage(msg.routing_id(), stream_id); |
+ SendErrorMessage(stream_id); |
return; |
} |
entry->controller->Pause(); |
} |
-void AudioRendererHost::OnFlushStream(const IPC::Message& msg, int stream_id) { |
+void AudioRendererHost::OnFlushStream(int stream_id) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- AudioEntry* entry = LookupById(msg.routing_id(), stream_id); |
+ AudioEntry* entry = LookupById(stream_id); |
if (!entry) { |
- SendErrorMessage(msg.routing_id(), stream_id); |
+ SendErrorMessage(stream_id); |
return; |
} |
entry->controller->Flush(); |
} |
-void AudioRendererHost::OnCloseStream(const IPC::Message& msg, int stream_id) { |
+void AudioRendererHost::OnCloseStream(int stream_id) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- AudioEntry* entry = LookupById(msg.routing_id(), stream_id); |
+ AudioEntry* entry = LookupById(stream_id); |
if (entry) |
CloseAndDeleteStream(entry); |
} |
-void AudioRendererHost::OnSetVolume(const IPC::Message& msg, int stream_id, |
+void AudioRendererHost::OnSetVolume(int stream_id, |
double volume) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- AudioEntry* entry = LookupById(msg.routing_id(), stream_id); |
+ AudioEntry* entry = LookupById(stream_id); |
if (!entry) { |
- SendErrorMessage(msg.routing_id(), stream_id); |
+ SendErrorMessage(stream_id); |
return; |
} |
@@ -345,18 +332,17 @@ |
entry->controller->SetVolume(volume); |
} |
-void AudioRendererHost::OnGetVolume(const IPC::Message& msg, int stream_id) { |
+void AudioRendererHost::OnGetVolume(int stream_id) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
NOTREACHED() << "This message shouldn't be received"; |
} |
-void AudioRendererHost::OnNotifyPacketReady( |
- const IPC::Message& msg, int stream_id, uint32 packet_size) { |
+void AudioRendererHost::OnNotifyPacketReady(int stream_id, uint32 packet_size) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- AudioEntry* entry = LookupById(msg.routing_id(), stream_id); |
+ AudioEntry* entry = LookupById(stream_id); |
if (!entry) { |
- SendErrorMessage(msg.routing_id(), stream_id); |
+ SendErrorMessage(stream_id); |
return; |
} |
@@ -374,10 +360,9 @@ |
packet_size); |
} |
-void AudioRendererHost::SendErrorMessage(int32 render_view_id, |
- int32 stream_id) { |
+void AudioRendererHost::SendErrorMessage(int32 stream_id) { |
Send(new AudioMsg_NotifyStreamStateChanged( |
- render_view_id, stream_id, kAudioStreamError)); |
+ stream_id, kAudioStreamError)); |
} |
void AudioRendererHost::DeleteEntries() { |
@@ -410,9 +395,8 @@ |
// Delete the entry when this method goes out of scope. |
scoped_ptr<AudioEntry> entry_deleter(entry); |
- // Erase the entry from the map. |
- audio_entries_.erase( |
- AudioEntryId(entry->render_view_id, entry->stream_id)); |
+ // Erase the entry identified by |stream_id| from the map. |
+ audio_entries_.erase(entry->stream_id); |
} |
void AudioRendererHost::DeleteEntryOnError(AudioEntry* entry) { |
@@ -420,16 +404,14 @@ |
// Sends the error message first before we close the stream because |
// |entry| is destroyed in DeleteEntry(). |
- SendErrorMessage(entry->render_view_id, entry->stream_id); |
+ SendErrorMessage(entry->stream_id); |
CloseAndDeleteStream(entry); |
} |
-AudioRendererHost::AudioEntry* AudioRendererHost::LookupById( |
- int route_id, int stream_id) { |
+AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
- AudioEntryMap::iterator i = audio_entries_.find( |
- AudioEntryId(route_id, stream_id)); |
+ AudioEntryMap::iterator i = audio_entries_.find(stream_id); |
if (i != audio_entries_.end() && !i->second->pending_close) |
return i->second; |
return NULL; |
@@ -440,7 +422,6 @@ |
DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
// Iterate the map of entries. |
- // TODO(hclam): Implement a faster look up method. |
for (AudioEntryMap::iterator i = audio_entries_.begin(); |
i != audio_entries_.end(); ++i) { |
if (!i->second->pending_close && controller == i->second->controller.get()) |