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/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
9 #include "base/memory/shared_memory.h" | 9 #include "base/memory/shared_memory.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
11 #include "base/process/process.h" | 11 #include "base/process/process.h" |
12 #include "content/browser/browser_main_loop.h" | 12 #include "content/browser/browser_main_loop.h" |
13 #include "content/browser/loader/resource_dispatcher_host_impl.h" | |
13 #include "content/browser/media/audio_stream_monitor.h" | 14 #include "content/browser/media/audio_stream_monitor.h" |
14 #include "content/browser/media/capture/audio_mirroring_manager.h" | 15 #include "content/browser/media/capture/audio_mirroring_manager.h" |
15 #include "content/browser/media/media_internals.h" | 16 #include "content/browser/media/media_internals.h" |
16 #include "content/browser/renderer_host/media/audio_input_device_manager.h" | 17 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
17 #include "content/browser/renderer_host/media/audio_sync_reader.h" | 18 #include "content/browser/renderer_host/media/audio_sync_reader.h" |
18 #include "content/browser/renderer_host/media/media_stream_manager.h" | 19 #include "content/browser/renderer_host/media/media_stream_manager.h" |
19 #include "content/common/media/audio_messages.h" | 20 #include "content/common/media/audio_messages.h" |
20 #include "content/public/browser/content_browser_client.h" | 21 #include "content/public/browser/content_browser_client.h" |
21 #include "content/public/browser/media_observer.h" | 22 #include "content/public/browser/media_observer.h" |
22 #include "content/public/common/content_switches.h" | 23 #include "content/public/common/content_switches.h" |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
266 is_playing ? media::AudioOutputIPCDelegate::kPlaying | 267 is_playing ? media::AudioOutputIPCDelegate::kPlaying |
267 : media::AudioOutputIPCDelegate::kPaused)); | 268 : media::AudioOutputIPCDelegate::kPaused)); |
268 | 269 |
269 if (is_playing) { | 270 if (is_playing) { |
270 AudioStreamMonitor::StartMonitoringStream( | 271 AudioStreamMonitor::StartMonitoringStream( |
271 render_process_id_, | 272 render_process_id_, |
272 entry->render_frame_id(), | 273 entry->render_frame_id(), |
273 entry->stream_id(), | 274 entry->stream_id(), |
274 base::Bind(&media::AudioOutputController::ReadCurrentPowerAndClip, | 275 base::Bind(&media::AudioOutputController::ReadCurrentPowerAndClip, |
275 entry->controller())); | 276 entry->controller())); |
276 // TODO(dalecurtis): See about using AudioStreamMonitor instead. | |
277 if (!entry->playing()) { | |
278 entry->set_playing(true); | |
279 base::AtomicRefCountInc(&num_playing_streams_); | |
280 } | |
281 } else { | 277 } else { |
282 AudioStreamMonitor::StopMonitoringStream( | 278 AudioStreamMonitor::StopMonitoringStream( |
283 render_process_id_, entry->render_frame_id(), entry->stream_id()); | 279 render_process_id_, entry->render_frame_id(), entry->stream_id()); |
280 } | |
281 | |
282 if (entry->playing() != is_playing) { | |
mmenke
2014/09/18 14:12:42
Suggest making a method:
AudioRendererHost::Updat
| |
284 // TODO(dalecurtis): See about using AudioStreamMonitor instead. | 283 // TODO(dalecurtis): See about using AudioStreamMonitor instead. |
aiolos (Not reviewing)
2014/09/18 01:13:24
Dale, I wasn't quite sure where this TODO should g
DaleCurtis
2014/09/18 17:51:23
Hmm, I guess it's not actually all that clear. You
aiolos (Not reviewing)
2014/09/18 21:46:47
Done.
| |
285 if (entry->playing()) { | 284 entry->set_playing(is_playing); |
286 entry->set_playing(false); | 285 if (is_playing) { |
286 base::AtomicRefCountInc(&num_playing_streams_); | |
287 } else { | |
287 base::AtomicRefCountDec(&num_playing_streams_); | 288 base::AtomicRefCountDec(&num_playing_streams_); |
288 } | 289 } |
290 if (ResourceDispatcherHostImpl::Get()) { | |
291 BrowserThread::PostTask( | |
DaleCurtis
2014/09/18 17:51:23
Does this need to be a PostTask? You're already on
aiolos (Not reviewing)
2014/09/18 21:46:47
Done.
| |
292 BrowserThread::IO, | |
293 FROM_HERE, | |
294 base::Bind( | |
295 &ResourceDispatcherHostImpl::OnAudioRenderHostStreamStateChanged, | |
296 base::Unretained(ResourceDispatcherHostImpl::Get()), | |
297 render_process_id_, entry->render_view_id(), is_playing)); | |
mmenke
2014/09/18 14:12:42
Can't we have multiple playing streams per RenderV
DaleCurtis
2014/09/18 17:51:24
Yeah, this should probably just return HasActiveAu
aiolos (Not reviewing)
2014/09/18 21:46:47
Changed to check that we're actually changing the
| |
298 } | |
289 } | 299 } |
290 } | 300 } |
291 | 301 |
292 RenderViewHost::AudioOutputControllerList | 302 RenderViewHost::AudioOutputControllerList |
293 AudioRendererHost::DoGetOutputControllers(int render_view_id) const { | 303 AudioRendererHost::DoGetOutputControllers(int render_view_id) const { |
294 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 304 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
295 | 305 |
296 RenderViewHost::AudioOutputControllerList controllers; | 306 RenderViewHost::AudioOutputControllerList controllers; |
297 AudioEntryMap::const_iterator it = audio_entries_.begin(); | 307 AudioEntryMap::const_iterator it = audio_entries_.begin(); |
298 for (; it != audio_entries_.end(); ++it) { | 308 for (; it != audio_entries_.end(); ++it) { |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
447 mirroring_manager_->RemoveDiverter(controller); | 457 mirroring_manager_->RemoveDiverter(controller); |
448 controller->Close( | 458 controller->Close( |
449 base::Bind(&AudioRendererHost::DeleteEntry, this, base::Passed(&entry))); | 459 base::Bind(&AudioRendererHost::DeleteEntry, this, base::Passed(&entry))); |
450 audio_log_->OnClosed(stream_id); | 460 audio_log_->OnClosed(stream_id); |
451 } | 461 } |
452 | 462 |
453 void AudioRendererHost::DeleteEntry(scoped_ptr<AudioEntry> entry) { | 463 void AudioRendererHost::DeleteEntry(scoped_ptr<AudioEntry> entry) { |
454 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 464 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
455 AudioStreamMonitor::StopMonitoringStream( | 465 AudioStreamMonitor::StopMonitoringStream( |
456 render_process_id_, entry->render_frame_id(), entry->stream_id()); | 466 render_process_id_, entry->render_frame_id(), entry->stream_id()); |
457 if (entry->playing()) | 467 if (entry->playing()) { |
458 base::AtomicRefCountDec(&num_playing_streams_); | 468 base::AtomicRefCountDec(&num_playing_streams_); |
469 if (ResourceDispatcherHostImpl::Get()) { | |
470 BrowserThread::PostTask( | |
471 BrowserThread::IO, | |
472 FROM_HERE, | |
473 base::Bind( | |
474 &ResourceDispatcherHostImpl::OnAudioRenderHostStreamStateChanged, | |
475 base::Unretained(ResourceDispatcherHostImpl::Get()), | |
476 render_process_id_, entry->render_view_id(), false)); | |
mmenke
2014/09/18 14:12:42
Same here - if we have two playing entries for a s
DaleCurtis
2014/09/18 17:51:23
Ditto.
aiolos (Not reviewing)
2014/09/18 21:46:48
Done.
| |
477 } | |
478 } | |
459 } | 479 } |
460 | 480 |
461 void AudioRendererHost::ReportErrorAndClose(int stream_id) { | 481 void AudioRendererHost::ReportErrorAndClose(int stream_id) { |
462 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 482 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
463 | 483 |
464 // Make sure this isn't a stray callback executing after the stream has been | 484 // Make sure this isn't a stray callback executing after the stream has been |
465 // closed, so error notifications aren't sent after clients believe the stream | 485 // closed, so error notifications aren't sent after clients believe the stream |
466 // is closed. | 486 // is closed. |
467 if (!LookupById(stream_id)) | 487 if (!LookupById(stream_id)) |
468 return; | 488 return; |
469 | 489 |
470 SendErrorMessage(stream_id); | 490 SendErrorMessage(stream_id); |
471 | 491 |
472 audio_log_->OnError(stream_id); | 492 audio_log_->OnError(stream_id); |
473 OnCloseStream(stream_id); | 493 OnCloseStream(stream_id); |
474 } | 494 } |
475 | 495 |
476 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { | 496 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { |
477 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 497 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
478 | 498 |
479 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id); | 499 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id); |
480 return i != audio_entries_.end() ? i->second : NULL; | 500 return i != audio_entries_.end() ? i->second : NULL; |
481 } | 501 } |
482 | 502 |
483 bool AudioRendererHost::HasActiveAudio() { | 503 bool AudioRendererHost::HasActiveAudio() { |
484 return !base::AtomicRefCountIsZero(&num_playing_streams_); | 504 return !base::AtomicRefCountIsZero(&num_playing_streams_); |
485 } | 505 } |
486 | 506 |
487 } // namespace content | 507 } // namespace content |
OLD | NEW |