| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/renderer_host/media/audio_renderer_host.h" | 5 #include "content/browser/renderer_host/media/audio_renderer_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/metrics/histogram.h" | 8 #include "base/metrics/histogram.h" |
| 9 #include "base/process.h" | 9 #include "base/process.h" |
| 10 #include "base/shared_memory.h" | 10 #include "base/shared_memory.h" |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 DeleteEntryOnError(entry); | 233 DeleteEntryOnError(entry); |
| 234 } | 234 } |
| 235 | 235 |
| 236 /////////////////////////////////////////////////////////////////////////////// | 236 /////////////////////////////////////////////////////////////////////////////// |
| 237 // IPC Messages handler | 237 // IPC Messages handler |
| 238 bool AudioRendererHost::OnMessageReceived(const IPC::Message& message, | 238 bool AudioRendererHost::OnMessageReceived(const IPC::Message& message, |
| 239 bool* message_was_ok) { | 239 bool* message_was_ok) { |
| 240 bool handled = true; | 240 bool handled = true; |
| 241 IPC_BEGIN_MESSAGE_MAP_EX(AudioRendererHost, message, *message_was_ok) | 241 IPC_BEGIN_MESSAGE_MAP_EX(AudioRendererHost, message, *message_was_ok) |
| 242 IPC_MESSAGE_HANDLER(AudioHostMsg_CreateStream, OnCreateStream) | 242 IPC_MESSAGE_HANDLER(AudioHostMsg_CreateStream, OnCreateStream) |
| 243 IPC_MESSAGE_HANDLER(AudioHostMsg_AssociateStreamWithProducer, | |
| 244 OnAssociateStreamWithProducer) | |
| 245 IPC_MESSAGE_HANDLER(AudioHostMsg_PlayStream, OnPlayStream) | 243 IPC_MESSAGE_HANDLER(AudioHostMsg_PlayStream, OnPlayStream) |
| 246 IPC_MESSAGE_HANDLER(AudioHostMsg_PauseStream, OnPauseStream) | 244 IPC_MESSAGE_HANDLER(AudioHostMsg_PauseStream, OnPauseStream) |
| 247 IPC_MESSAGE_HANDLER(AudioHostMsg_FlushStream, OnFlushStream) | 245 IPC_MESSAGE_HANDLER(AudioHostMsg_FlushStream, OnFlushStream) |
| 248 IPC_MESSAGE_HANDLER(AudioHostMsg_CloseStream, OnCloseStream) | 246 IPC_MESSAGE_HANDLER(AudioHostMsg_CloseStream, OnCloseStream) |
| 249 IPC_MESSAGE_HANDLER(AudioHostMsg_SetVolume, OnSetVolume) | 247 IPC_MESSAGE_HANDLER(AudioHostMsg_SetVolume, OnSetVolume) |
| 250 IPC_MESSAGE_UNHANDLED(handled = false) | 248 IPC_MESSAGE_UNHANDLED(handled = false) |
| 251 IPC_END_MESSAGE_MAP_EX() | 249 IPC_END_MESSAGE_MAP_EX() |
| 252 | 250 |
| 253 return handled; | 251 return handled; |
| 254 } | 252 } |
| 255 | 253 |
| 256 void AudioRendererHost::OnCreateStream( | 254 void AudioRendererHost::OnCreateStream( |
| 257 int stream_id, const media::AudioParameters& params) { | 255 int stream_id, int render_view_id, const media::AudioParameters& params) { |
| 258 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 256 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 257 |
| 258 DVLOG(1) << "AudioRendererHost@" << this |
| 259 << "::OnCreateStream(stream_id=" << stream_id |
| 260 << ", render_view_id=" << render_view_id << ")"; |
| 261 |
| 259 // media::AudioParameters is validated in the deserializer. | 262 // media::AudioParameters is validated in the deserializer. |
| 260 int input_channels = params.input_channels(); | 263 int input_channels = params.input_channels(); |
| 261 if (input_channels < 0 || | 264 if (input_channels < 0 || |
| 262 input_channels > media::limits::kMaxChannels || | 265 input_channels > media::limits::kMaxChannels || |
| 263 LookupById(stream_id) != NULL) { | 266 LookupById(stream_id) != NULL) { |
| 264 SendErrorMessage(stream_id); | 267 SendErrorMessage(stream_id); |
| 265 return; | 268 return; |
| 266 } | 269 } |
| 267 | 270 |
| 268 media::AudioParameters audio_params(params); | 271 media::AudioParameters audio_params(params); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 // entry and construct an AudioOutputController. | 305 // entry and construct an AudioOutputController. |
| 303 entry->reader.reset(reader.release()); | 306 entry->reader.reset(reader.release()); |
| 304 entry->controller = media::AudioOutputController::Create( | 307 entry->controller = media::AudioOutputController::Create( |
| 305 audio_manager_, this, audio_params, entry->reader.get()); | 308 audio_manager_, this, audio_params, entry->reader.get()); |
| 306 | 309 |
| 307 if (!entry->controller) { | 310 if (!entry->controller) { |
| 308 SendErrorMessage(stream_id); | 311 SendErrorMessage(stream_id); |
| 309 return; | 312 return; |
| 310 } | 313 } |
| 311 | 314 |
| 312 // If we have created the controller successfully, create an entry and add it | 315 // Since the controller was created successfully, create an entry and add it |
| 313 // to the map. | 316 // to the map. |
| 314 entry->stream_id = stream_id; | 317 entry->stream_id = stream_id; |
| 318 DCHECK_LT(0, render_view_id); |
| 319 entry->render_view_id = render_view_id; |
| 320 if (mirroring_manager_) { |
| 321 mirroring_manager_->AddDiverter( |
| 322 render_process_id_, entry->render_view_id, entry->controller); |
| 323 } |
| 315 audio_entries_.insert(std::make_pair(stream_id, entry.release())); | 324 audio_entries_.insert(std::make_pair(stream_id, entry.release())); |
| 316 if (media_internals_) | 325 if (media_internals_) |
| 317 media_internals_->OnSetAudioStreamStatus(this, stream_id, "created"); | 326 media_internals_->OnSetAudioStreamStatus(this, stream_id, "created"); |
| 318 } | 327 } |
| 319 | 328 |
| 320 void AudioRendererHost::OnAssociateStreamWithProducer(int stream_id, | |
| 321 int render_view_id) { | |
| 322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 323 | |
| 324 DVLOG(1) << "AudioRendererHost@" << this | |
| 325 << "::OnAssociateStreamWithProducer(stream_id=" << stream_id | |
| 326 << ", render_view_id=" << render_view_id << ")"; | |
| 327 | |
| 328 AudioEntry* const entry = LookupById(stream_id); | |
| 329 if (!entry) { | |
| 330 SendErrorMessage(stream_id); | |
| 331 return; | |
| 332 } | |
| 333 | |
| 334 if (entry->render_view_id == render_view_id) | |
| 335 return; | |
| 336 | |
| 337 // TODO(miu): Merge "AssociateWithProducer" message into "CreateStream" | |
| 338 // message so AudioRendererHost can assume a simpler "render_view_id is set | |
| 339 // once" scheme. http://crbug.com/166779 | |
| 340 if (mirroring_manager_) { | |
| 341 mirroring_manager_->RemoveDiverter( | |
| 342 render_process_id_, entry->render_view_id, entry->controller); | |
| 343 } | |
| 344 entry->render_view_id = render_view_id; | |
| 345 if (mirroring_manager_) { | |
| 346 mirroring_manager_->AddDiverter( | |
| 347 render_process_id_, entry->render_view_id, entry->controller); | |
| 348 } | |
| 349 } | |
| 350 | |
| 351 void AudioRendererHost::OnPlayStream(int stream_id) { | 329 void AudioRendererHost::OnPlayStream(int stream_id) { |
| 352 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 330 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 353 | 331 |
| 354 AudioEntry* entry = LookupById(stream_id); | 332 AudioEntry* entry = LookupById(stream_id); |
| 355 if (!entry) { | 333 if (!entry) { |
| 356 SendErrorMessage(stream_id); | 334 SendErrorMessage(stream_id); |
| 357 return; | 335 return; |
| 358 } | 336 } |
| 359 | 337 |
| 360 entry->controller->Play(); | 338 entry->controller->Play(); |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 526 return NULL; | 504 return NULL; |
| 527 } | 505 } |
| 528 | 506 |
| 529 media::AudioOutputController* AudioRendererHost::LookupControllerByIdForTesting( | 507 media::AudioOutputController* AudioRendererHost::LookupControllerByIdForTesting( |
| 530 int stream_id) { | 508 int stream_id) { |
| 531 AudioEntry* const entry = LookupById(stream_id); | 509 AudioEntry* const entry = LookupById(stream_id); |
| 532 return entry ? entry->controller : NULL; | 510 return entry ? entry->controller : NULL; |
| 533 } | 511 } |
| 534 | 512 |
| 535 } // namespace content | 513 } // namespace content |
| OLD | NEW |