Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: content/browser/renderer_host/media/audio_renderer_host.cc

Issue 562273008: Add audio signal to the ResourceScheduler. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed comments. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/browser/renderer_host/media/audio_renderer_host.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
250 251
251 Send(new AudioMsg_NotifyStreamCreated( 252 Send(new AudioMsg_NotifyStreamCreated(
252 entry->stream_id(), foreign_memory_handle, socket_descriptor, 253 entry->stream_id(), foreign_memory_handle, socket_descriptor,
253 entry->shared_memory()->requested_size())); 254 entry->shared_memory()->requested_size()));
254 } 255 }
255 256
256 void AudioRendererHost::DoNotifyStreamStateChanged(int stream_id, 257 void AudioRendererHost::DoNotifyStreamStateChanged(int stream_id,
257 bool is_playing) { 258 bool is_playing) {
258 DCHECK_CURRENTLY_ON(BrowserThread::IO); 259 DCHECK_CURRENTLY_ON(BrowserThread::IO);
259 260
260 AudioEntry* const entry = LookupById(stream_id); 261 AudioEntry* const entry(LookupById(stream_id));
261 if (!entry) 262 if (!entry)
262 return; 263 return;
263 264
264 Send(new AudioMsg_NotifyStreamStateChanged( 265 Send(new AudioMsg_NotifyStreamStateChanged(
265 stream_id, 266 stream_id,
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());
284 // TODO(dalecurtis): See about using AudioStreamMonitor instead.
285 if (entry->playing()) {
286 entry->set_playing(false);
287 base::AtomicRefCountDec(&num_playing_streams_);
288 }
289 } 280 }
281 UpdateNumPlayingStreams(entry, is_playing);
290 } 282 }
291 283
292 RenderViewHost::AudioOutputControllerList 284 RenderViewHost::AudioOutputControllerList
293 AudioRendererHost::DoGetOutputControllers(int render_view_id) const { 285 AudioRendererHost::DoGetOutputControllers(int render_view_id) const {
294 DCHECK_CURRENTLY_ON(BrowserThread::IO); 286 DCHECK_CURRENTLY_ON(BrowserThread::IO);
295 287
296 RenderViewHost::AudioOutputControllerList controllers; 288 RenderViewHost::AudioOutputControllerList controllers;
297 AudioEntryMap::const_iterator it = audio_entries_.begin(); 289 AudioEntryMap::const_iterator it = audio_entries_.begin();
298 for (; it != audio_entries_.end(); ++it) { 290 for (; it != audio_entries_.end(); ++it) {
299 AudioEntry* entry = it->second; 291 AudioEntry* entry = it->second;
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 mirroring_manager_->RemoveDiverter(controller); 439 mirroring_manager_->RemoveDiverter(controller);
448 controller->Close( 440 controller->Close(
449 base::Bind(&AudioRendererHost::DeleteEntry, this, base::Passed(&entry))); 441 base::Bind(&AudioRendererHost::DeleteEntry, this, base::Passed(&entry)));
450 audio_log_->OnClosed(stream_id); 442 audio_log_->OnClosed(stream_id);
451 } 443 }
452 444
453 void AudioRendererHost::DeleteEntry(scoped_ptr<AudioEntry> entry) { 445 void AudioRendererHost::DeleteEntry(scoped_ptr<AudioEntry> entry) {
454 DCHECK_CURRENTLY_ON(BrowserThread::IO); 446 DCHECK_CURRENTLY_ON(BrowserThread::IO);
455 AudioStreamMonitor::StopMonitoringStream( 447 AudioStreamMonitor::StopMonitoringStream(
456 render_process_id_, entry->render_frame_id(), entry->stream_id()); 448 render_process_id_, entry->render_frame_id(), entry->stream_id());
457 if (entry->playing()) 449 UpdateNumPlayingStreams(entry.get(), false);
458 base::AtomicRefCountDec(&num_playing_streams_);
459 } 450 }
460 451
461 void AudioRendererHost::ReportErrorAndClose(int stream_id) { 452 void AudioRendererHost::ReportErrorAndClose(int stream_id) {
462 DCHECK_CURRENTLY_ON(BrowserThread::IO); 453 DCHECK_CURRENTLY_ON(BrowserThread::IO);
463 454
464 // Make sure this isn't a stray callback executing after the stream has been 455 // 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 456 // closed, so error notifications aren't sent after clients believe the stream
466 // is closed. 457 // is closed.
467 if (!LookupById(stream_id)) 458 if (!LookupById(stream_id))
468 return; 459 return;
469 460
470 SendErrorMessage(stream_id); 461 SendErrorMessage(stream_id);
471 462
472 audio_log_->OnError(stream_id); 463 audio_log_->OnError(stream_id);
473 OnCloseStream(stream_id); 464 OnCloseStream(stream_id);
474 } 465 }
475 466
476 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { 467 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) {
477 DCHECK_CURRENTLY_ON(BrowserThread::IO); 468 DCHECK_CURRENTLY_ON(BrowserThread::IO);
478 469
479 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id); 470 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id);
480 return i != audio_entries_.end() ? i->second : NULL; 471 return i != audio_entries_.end() ? i->second : NULL;
481 } 472 }
482 473
474 void AudioRendererHost::UpdateNumPlayingStreams(AudioEntry* entry,
475 bool is_playing) {
476 bool had_active_audio = HasActiveAudio();
mmenke 2014/09/18 21:55:51 This is for the entire renderer process, not a par
aiolos (Not reviewing) 2014/09/18 22:23:11 Ah, good catch. Dale, is there a better way to tel
DaleCurtis 2014/09/18 22:57:38 Ah, no there isn't. The list shouldn't be large a
aiolos (Not reviewing) 2014/09/19 00:37:36 Done.
477 if (entry->playing() != is_playing) {
478 entry->set_playing(is_playing);
479 if (is_playing) {
480 base::AtomicRefCountInc(&num_playing_streams_);
481 } else {
482 base::AtomicRefCountDec(&num_playing_streams_);
483 }
484 if (had_active_audio != HasActiveAudio()) {
485 DCHECK_CURRENTLY_ON(BrowserThread::IO);
486 ResourceDispatcherHostImpl::Get()->OnAudioRenderHostStreamStateChanged(
487 render_process_id_, entry->render_view_id(), is_playing);
488 }
489 }
490 }
491
483 bool AudioRendererHost::HasActiveAudio() { 492 bool AudioRendererHost::HasActiveAudio() {
484 return !base::AtomicRefCountIsZero(&num_playing_streams_); 493 return !base::AtomicRefCountIsZero(&num_playing_streams_);
485 } 494 }
486 495
487 } // namespace content 496 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/audio_renderer_host.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698