| 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" |
| 11 #include "content/browser/browser_main_loop.h" | 11 #include "content/browser/browser_main_loop.h" |
| 12 #include "content/browser/media/media_internals.h" |
| 12 #include "content/browser/renderer_host/media/audio_mirroring_manager.h" | 13 #include "content/browser/renderer_host/media/audio_mirroring_manager.h" |
| 13 #include "content/browser/renderer_host/media/audio_sync_reader.h" | 14 #include "content/browser/renderer_host/media/audio_sync_reader.h" |
| 14 #include "content/common/media/audio_messages.h" | 15 #include "content/common/media/audio_messages.h" |
| 15 #include "content/public/browser/media_observer.h" | |
| 16 #include "media/audio/shared_memory_util.h" | 16 #include "media/audio/shared_memory_util.h" |
| 17 #include "media/base/audio_bus.h" | 17 #include "media/base/audio_bus.h" |
| 18 #include "media/base/limits.h" | 18 #include "media/base/limits.h" |
| 19 | 19 |
| 20 using media::AudioBus; | 20 using media::AudioBus; |
| 21 | 21 |
| 22 namespace content { | 22 namespace content { |
| 23 | 23 |
| 24 struct AudioRendererHost::AudioEntry { | 24 struct AudioRendererHost::AudioEntry { |
| 25 AudioEntry(); | 25 AudioEntry(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 52 } | 52 } |
| 53 | 53 |
| 54 AudioRendererHost::AudioEntry::~AudioEntry() {} | 54 AudioRendererHost::AudioEntry::~AudioEntry() {} |
| 55 | 55 |
| 56 /////////////////////////////////////////////////////////////////////////////// | 56 /////////////////////////////////////////////////////////////////////////////// |
| 57 // AudioRendererHost implementations. | 57 // AudioRendererHost implementations. |
| 58 AudioRendererHost::AudioRendererHost( | 58 AudioRendererHost::AudioRendererHost( |
| 59 int render_process_id, | 59 int render_process_id, |
| 60 media::AudioManager* audio_manager, | 60 media::AudioManager* audio_manager, |
| 61 AudioMirroringManager* mirroring_manager, | 61 AudioMirroringManager* mirroring_manager, |
| 62 MediaObserver* media_observer) | 62 MediaInternals* media_internals) |
| 63 : render_process_id_(render_process_id), | 63 : render_process_id_(render_process_id), |
| 64 audio_manager_(audio_manager), | 64 audio_manager_(audio_manager), |
| 65 mirroring_manager_(mirroring_manager), | 65 mirroring_manager_(mirroring_manager), |
| 66 media_observer_(media_observer) { | 66 media_internals_(media_internals) { |
| 67 DCHECK(audio_manager_); | 67 DCHECK(audio_manager_); |
| 68 } | 68 } |
| 69 | 69 |
| 70 AudioRendererHost::~AudioRendererHost() { | 70 AudioRendererHost::~AudioRendererHost() { |
| 71 DCHECK(audio_entries_.empty()); | 71 DCHECK(audio_entries_.empty()); |
| 72 } | 72 } |
| 73 | 73 |
| 74 void AudioRendererHost::OnChannelClosing() { | 74 void AudioRendererHost::OnChannelClosing() { |
| 75 BrowserMessageFilter::OnChannelClosing(); | 75 BrowserMessageFilter::OnChannelClosing(); |
| 76 | 76 |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 279 | 279 |
| 280 if (!entry->controller) { | 280 if (!entry->controller) { |
| 281 SendErrorMessage(stream_id); | 281 SendErrorMessage(stream_id); |
| 282 return; | 282 return; |
| 283 } | 283 } |
| 284 | 284 |
| 285 // If we have created the controller successfully, create an entry and add it | 285 // If we have created the controller successfully, create an entry and add it |
| 286 // to the map. | 286 // to the map. |
| 287 entry->stream_id = stream_id; | 287 entry->stream_id = stream_id; |
| 288 audio_entries_.insert(std::make_pair(stream_id, entry.release())); | 288 audio_entries_.insert(std::make_pair(stream_id, entry.release())); |
| 289 if (media_observer_) | 289 if (media_internals_) |
| 290 media_observer_->OnSetAudioStreamStatus(this, stream_id, "created"); | 290 media_internals_->OnSetAudioStreamStatus(this, stream_id, "created"); |
| 291 } | 291 } |
| 292 | 292 |
| 293 void AudioRendererHost::OnAssociateStreamWithProducer(int stream_id, | 293 void AudioRendererHost::OnAssociateStreamWithProducer(int stream_id, |
| 294 int render_view_id) { | 294 int render_view_id) { |
| 295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 296 | 296 |
| 297 DVLOG(1) << "AudioRendererHost@" << this | 297 DVLOG(1) << "AudioRendererHost@" << this |
| 298 << "::OnAssociateStreamWithProducer(stream_id=" << stream_id | 298 << "::OnAssociateStreamWithProducer(stream_id=" << stream_id |
| 299 << ", render_view_id=" << render_view_id << ")"; | 299 << ", render_view_id=" << render_view_id << ")"; |
| 300 | 300 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 321 void AudioRendererHost::OnPlayStream(int stream_id) { | 321 void AudioRendererHost::OnPlayStream(int stream_id) { |
| 322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 323 | 323 |
| 324 AudioEntry* entry = LookupById(stream_id); | 324 AudioEntry* entry = LookupById(stream_id); |
| 325 if (!entry) { | 325 if (!entry) { |
| 326 SendErrorMessage(stream_id); | 326 SendErrorMessage(stream_id); |
| 327 return; | 327 return; |
| 328 } | 328 } |
| 329 | 329 |
| 330 entry->controller->Play(); | 330 entry->controller->Play(); |
| 331 if (media_observer_) | 331 if (media_internals_) |
| 332 media_observer_->OnSetAudioStreamPlaying(this, stream_id, true); | 332 media_internals_->OnSetAudioStreamPlaying(this, stream_id, true); |
| 333 } | 333 } |
| 334 | 334 |
| 335 void AudioRendererHost::OnPauseStream(int stream_id) { | 335 void AudioRendererHost::OnPauseStream(int stream_id) { |
| 336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 336 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 337 | 337 |
| 338 AudioEntry* entry = LookupById(stream_id); | 338 AudioEntry* entry = LookupById(stream_id); |
| 339 if (!entry) { | 339 if (!entry) { |
| 340 SendErrorMessage(stream_id); | 340 SendErrorMessage(stream_id); |
| 341 return; | 341 return; |
| 342 } | 342 } |
| 343 | 343 |
| 344 entry->controller->Pause(); | 344 entry->controller->Pause(); |
| 345 if (media_observer_) | 345 if (media_internals_) |
| 346 media_observer_->OnSetAudioStreamPlaying(this, stream_id, false); | 346 media_internals_->OnSetAudioStreamPlaying(this, stream_id, false); |
| 347 } | 347 } |
| 348 | 348 |
| 349 void AudioRendererHost::OnFlushStream(int stream_id) { | 349 void AudioRendererHost::OnFlushStream(int stream_id) { |
| 350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 350 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 351 | 351 |
| 352 AudioEntry* entry = LookupById(stream_id); | 352 AudioEntry* entry = LookupById(stream_id); |
| 353 if (!entry) { | 353 if (!entry) { |
| 354 SendErrorMessage(stream_id); | 354 SendErrorMessage(stream_id); |
| 355 return; | 355 return; |
| 356 } | 356 } |
| 357 | 357 |
| 358 entry->controller->Flush(); | 358 entry->controller->Flush(); |
| 359 if (media_observer_) | 359 if (media_internals_) |
| 360 media_observer_->OnSetAudioStreamStatus(this, stream_id, "flushed"); | 360 media_internals_->OnSetAudioStreamStatus(this, stream_id, "flushed"); |
| 361 } | 361 } |
| 362 | 362 |
| 363 void AudioRendererHost::OnCloseStream(int stream_id) { | 363 void AudioRendererHost::OnCloseStream(int stream_id) { |
| 364 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 364 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 365 | 365 |
| 366 if (media_observer_) | 366 if (media_internals_) |
| 367 media_observer_->OnSetAudioStreamStatus(this, stream_id, "closed"); | 367 media_internals_->OnSetAudioStreamStatus(this, stream_id, "closed"); |
| 368 | 368 |
| 369 AudioEntry* entry = LookupById(stream_id); | 369 AudioEntry* entry = LookupById(stream_id); |
| 370 | 370 |
| 371 if (entry) | 371 if (entry) |
| 372 CloseAndDeleteStream(entry); | 372 CloseAndDeleteStream(entry); |
| 373 } | 373 } |
| 374 | 374 |
| 375 void AudioRendererHost::OnSetVolume(int stream_id, double volume) { | 375 void AudioRendererHost::OnSetVolume(int stream_id, double volume) { |
| 376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 377 | 377 |
| 378 AudioEntry* entry = LookupById(stream_id); | 378 AudioEntry* entry = LookupById(stream_id); |
| 379 if (!entry) { | 379 if (!entry) { |
| 380 SendErrorMessage(stream_id); | 380 SendErrorMessage(stream_id); |
| 381 return; | 381 return; |
| 382 } | 382 } |
| 383 | 383 |
| 384 // Make sure the volume is valid. | 384 // Make sure the volume is valid. |
| 385 if (volume < 0 || volume > 1.0) | 385 if (volume < 0 || volume > 1.0) |
| 386 return; | 386 return; |
| 387 entry->controller->SetVolume(volume); | 387 entry->controller->SetVolume(volume); |
| 388 if (media_observer_) | 388 if (media_internals_) |
| 389 media_observer_->OnSetAudioStreamVolume(this, stream_id, volume); | 389 media_internals_->OnSetAudioStreamVolume(this, stream_id, volume); |
| 390 } | 390 } |
| 391 | 391 |
| 392 void AudioRendererHost::SendErrorMessage(int32 stream_id) { | 392 void AudioRendererHost::SendErrorMessage(int32 stream_id) { |
| 393 Send(new AudioMsg_NotifyStreamStateChanged( | 393 Send(new AudioMsg_NotifyStreamStateChanged( |
| 394 stream_id, media::AudioOutputIPCDelegate::kError)); | 394 stream_id, media::AudioOutputIPCDelegate::kError)); |
| 395 } | 395 } |
| 396 | 396 |
| 397 void AudioRendererHost::DeleteEntries() { | 397 void AudioRendererHost::DeleteEntries() { |
| 398 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 398 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 399 | 399 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 420 void AudioRendererHost::DeleteEntry(AudioEntry* entry) { | 420 void AudioRendererHost::DeleteEntry(AudioEntry* entry) { |
| 421 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 421 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 422 | 422 |
| 423 // Delete the entry when this method goes out of scope. | 423 // Delete the entry when this method goes out of scope. |
| 424 scoped_ptr<AudioEntry> entry_deleter(entry); | 424 scoped_ptr<AudioEntry> entry_deleter(entry); |
| 425 | 425 |
| 426 // Erase the entry identified by |stream_id| from the map. | 426 // Erase the entry identified by |stream_id| from the map. |
| 427 audio_entries_.erase(entry->stream_id); | 427 audio_entries_.erase(entry->stream_id); |
| 428 | 428 |
| 429 // Notify the media observer. | 429 // Notify the media observer. |
| 430 if (media_observer_) | 430 if (media_internals_) |
| 431 media_observer_->OnDeleteAudioStream(this, entry->stream_id); | 431 media_internals_->OnDeleteAudioStream(this, entry->stream_id); |
| 432 } | 432 } |
| 433 | 433 |
| 434 void AudioRendererHost::DeleteEntryOnError(AudioEntry* entry) { | 434 void AudioRendererHost::DeleteEntryOnError(AudioEntry* entry) { |
| 435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 435 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 436 | 436 |
| 437 // Sends the error message first before we close the stream because | 437 // Sends the error message first before we close the stream because |
| 438 // |entry| is destroyed in DeleteEntry(). | 438 // |entry| is destroyed in DeleteEntry(). |
| 439 SendErrorMessage(entry->stream_id); | 439 SendErrorMessage(entry->stream_id); |
| 440 | 440 |
| 441 if (media_observer_) | 441 if (media_internals_) |
| 442 media_observer_->OnSetAudioStreamStatus(this, entry->stream_id, "error"); | 442 media_internals_->OnSetAudioStreamStatus(this, entry->stream_id, "error"); |
| 443 CloseAndDeleteStream(entry); | 443 CloseAndDeleteStream(entry); |
| 444 } | 444 } |
| 445 | 445 |
| 446 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { | 446 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { |
| 447 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 447 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 448 | 448 |
| 449 AudioEntryMap::iterator i = audio_entries_.find(stream_id); | 449 AudioEntryMap::iterator i = audio_entries_.find(stream_id); |
| 450 if (i != audio_entries_.end() && !i->second->pending_close) | 450 if (i != audio_entries_.end() && !i->second->pending_close) |
| 451 return i->second; | 451 return i->second; |
| 452 return NULL; | 452 return NULL; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 466 return NULL; | 466 return NULL; |
| 467 } | 467 } |
| 468 | 468 |
| 469 media::AudioOutputController* AudioRendererHost::LookupControllerByIdForTesting( | 469 media::AudioOutputController* AudioRendererHost::LookupControllerByIdForTesting( |
| 470 int stream_id) { | 470 int stream_id) { |
| 471 AudioEntry* const entry = LookupById(stream_id); | 471 AudioEntry* const entry = LookupById(stream_id); |
| 472 return entry ? entry->controller : NULL; | 472 return entry ? entry->controller : NULL; |
| 473 } | 473 } |
| 474 | 474 |
| 475 } // namespace content | 475 } // namespace content |
| OLD | NEW |