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

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

Issue 68173025: Introduce new interface for MediaInternals updates. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix JavaScript test. Use non-exported base. Created 7 years 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 | Annotate | Revision Log
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"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 110
111 AudioRendererHost::AudioRendererHost( 111 AudioRendererHost::AudioRendererHost(
112 int render_process_id, 112 int render_process_id,
113 media::AudioManager* audio_manager, 113 media::AudioManager* audio_manager,
114 AudioMirroringManager* mirroring_manager, 114 AudioMirroringManager* mirroring_manager,
115 MediaInternals* media_internals, 115 MediaInternals* media_internals,
116 MediaStreamManager* media_stream_manager) 116 MediaStreamManager* media_stream_manager)
117 : render_process_id_(render_process_id), 117 : render_process_id_(render_process_id),
118 audio_manager_(audio_manager), 118 audio_manager_(audio_manager),
119 mirroring_manager_(mirroring_manager), 119 mirroring_manager_(mirroring_manager),
120 media_internals_(media_internals), 120 audio_log_(media_internals->CreateAudioLog(
121 media::AudioLogFactory::AUDIO_OUTPUT_CONTROLLER)),
121 media_stream_manager_(media_stream_manager) { 122 media_stream_manager_(media_stream_manager) {
122 DCHECK(audio_manager_); 123 DCHECK(audio_manager_);
123 DCHECK(media_stream_manager_); 124 DCHECK(media_stream_manager_);
124 } 125 }
125 126
126 AudioRendererHost::~AudioRendererHost() { 127 AudioRendererHost::~AudioRendererHost() {
127 DCHECK(audio_entries_.empty()); 128 DCHECK(audio_entries_.empty());
128 } 129 }
129 130
130 void AudioRendererHost::GetOutputControllers( 131 void AudioRendererHost::GetOutputControllers(
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
372 373
373 scoped_ptr<AudioEntry> entry(new AudioEntry( 374 scoped_ptr<AudioEntry> entry(new AudioEntry(
374 this, stream_id, render_view_id, params, output_device_id, 375 this, stream_id, render_view_id, params, output_device_id,
375 input_device_id, shared_memory.Pass(), 376 input_device_id, shared_memory.Pass(),
376 reader.PassAs<media::AudioOutputController::SyncReader>())); 377 reader.PassAs<media::AudioOutputController::SyncReader>()));
377 if (mirroring_manager_) { 378 if (mirroring_manager_) {
378 mirroring_manager_->AddDiverter( 379 mirroring_manager_->AddDiverter(
379 render_process_id_, entry->render_view_id(), entry->controller()); 380 render_process_id_, entry->render_view_id(), entry->controller());
380 } 381 }
381 audio_entries_.insert(std::make_pair(stream_id, entry.release())); 382 audio_entries_.insert(std::make_pair(stream_id, entry.release()));
382 if (media_internals_) { 383 audio_log_->OnCreated(stream_id, params, input_device_id, output_device_id);
383 media_internals_->OnAudioStreamCreated(
384 this, stream_id, params, input_device_id);
385 }
386 } 384 }
387 385
388 void AudioRendererHost::OnPlayStream(int stream_id) { 386 void AudioRendererHost::OnPlayStream(int stream_id) {
389 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 387 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
390 388
391 AudioEntry* entry = LookupById(stream_id); 389 AudioEntry* entry = LookupById(stream_id);
392 if (!entry) { 390 if (!entry) {
393 SendErrorMessage(stream_id); 391 SendErrorMessage(stream_id);
394 return; 392 return;
395 } 393 }
396 394
397 entry->controller()->Play(); 395 entry->controller()->Play();
398 if (media_internals_) 396 audio_log_->OnStarted(stream_id);
399 media_internals_->OnSetAudioStreamPlaying(this, stream_id, true);
400 } 397 }
401 398
402 void AudioRendererHost::OnPauseStream(int stream_id) { 399 void AudioRendererHost::OnPauseStream(int stream_id) {
403 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 400 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
404 401
405 AudioEntry* entry = LookupById(stream_id); 402 AudioEntry* entry = LookupById(stream_id);
406 if (!entry) { 403 if (!entry) {
407 SendErrorMessage(stream_id); 404 SendErrorMessage(stream_id);
408 return; 405 return;
409 } 406 }
410 407
411 entry->controller()->Pause(); 408 entry->controller()->Pause();
412 if (media_internals_) 409 audio_log_->OnStopped(stream_id);
413 media_internals_->OnSetAudioStreamPlaying(this, stream_id, false);
414 } 410 }
415 411
416 void AudioRendererHost::OnSetVolume(int stream_id, double volume) { 412 void AudioRendererHost::OnSetVolume(int stream_id, double volume) {
417 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 413 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
418 414
419 AudioEntry* entry = LookupById(stream_id); 415 AudioEntry* entry = LookupById(stream_id);
420 if (!entry) { 416 if (!entry) {
421 SendErrorMessage(stream_id); 417 SendErrorMessage(stream_id);
422 return; 418 return;
423 } 419 }
424 420
425 // Make sure the volume is valid. 421 // Make sure the volume is valid.
426 if (volume < 0 || volume > 1.0) 422 if (volume < 0 || volume > 1.0)
427 return; 423 return;
428 entry->controller()->SetVolume(volume); 424 entry->controller()->SetVolume(volume);
429 if (media_internals_) 425 audio_log_->OnSetVolume(stream_id, volume);
430 media_internals_->OnSetAudioStreamVolume(this, stream_id, volume);
431 } 426 }
432 427
433 void AudioRendererHost::SendErrorMessage(int stream_id) { 428 void AudioRendererHost::SendErrorMessage(int stream_id) {
434 Send(new AudioMsg_NotifyStreamStateChanged( 429 Send(new AudioMsg_NotifyStreamStateChanged(
435 stream_id, media::AudioOutputIPCDelegate::kError)); 430 stream_id, media::AudioOutputIPCDelegate::kError));
436 } 431 }
437 432
438 void AudioRendererHost::OnCloseStream(int stream_id) { 433 void AudioRendererHost::OnCloseStream(int stream_id) {
439 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 434 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
440 435
441 // Prevent oustanding callbacks from attempting to close/delete the same 436 // Prevent oustanding callbacks from attempting to close/delete the same
442 // AudioEntry twice. 437 // AudioEntry twice.
443 AudioEntryMap::iterator i = audio_entries_.find(stream_id); 438 AudioEntryMap::iterator i = audio_entries_.find(stream_id);
444 if (i == audio_entries_.end()) 439 if (i == audio_entries_.end())
445 return; 440 return;
446 scoped_ptr<AudioEntry> entry(i->second); 441 scoped_ptr<AudioEntry> entry(i->second);
447 audio_entries_.erase(i); 442 audio_entries_.erase(i);
448 443
449 media::AudioOutputController* const controller = entry->controller(); 444 media::AudioOutputController* const controller = entry->controller();
450 if (mirroring_manager_) { 445 if (mirroring_manager_) {
451 mirroring_manager_->RemoveDiverter( 446 mirroring_manager_->RemoveDiverter(
452 render_process_id_, entry->render_view_id(), controller); 447 render_process_id_, entry->render_view_id(), controller);
453 } 448 }
454 controller->Close( 449 controller->Close(
455 base::Bind(&AudioRendererHost::DeleteEntry, this, base::Passed(&entry))); 450 base::Bind(&AudioRendererHost::DeleteEntry, this, base::Passed(&entry)));
456 451 audio_log_->OnClosed(stream_id);
457 if (media_internals_)
458 media_internals_->OnSetAudioStreamStatus(this, stream_id, "closed");
459 } 452 }
460 453
461 void AudioRendererHost::DeleteEntry(scoped_ptr<AudioEntry> entry) { 454 void AudioRendererHost::DeleteEntry(scoped_ptr<AudioEntry> entry) {
462 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 455 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
463 456
464 // At this point, make the final "say" in audio playback state. 457 // At this point, make the final "say" in audio playback state.
465 MediaObserver* const media_observer = 458 MediaObserver* const media_observer =
466 GetContentClient()->browser()->GetMediaObserver(); 459 GetContentClient()->browser()->GetMediaObserver();
467 if (media_observer) { 460 if (media_observer) {
468 media_observer->OnAudioStreamPlayingChanged( 461 media_observer->OnAudioStreamPlayingChanged(
469 render_process_id_, entry->render_view_id(), entry->stream_id(), 462 render_process_id_, entry->render_view_id(), entry->stream_id(),
470 false, -std::numeric_limits<float>::infinity(), false); 463 false, -std::numeric_limits<float>::infinity(), false);
471 } 464 }
472
473 // Notify the media observer.
474 if (media_internals_)
475 media_internals_->OnDeleteAudioStream(this, entry->stream_id());
476
477 // Note: |entry| will be deleted upon leaving this scope.
478 } 465 }
479 466
480 void AudioRendererHost::ReportErrorAndClose(int stream_id) { 467 void AudioRendererHost::ReportErrorAndClose(int stream_id) {
481 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 468 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
482 469
483 // Make sure this isn't a stray callback executing after the stream has been 470 // Make sure this isn't a stray callback executing after the stream has been
484 // closed, so error notifications aren't sent after clients believe the stream 471 // closed, so error notifications aren't sent after clients believe the stream
485 // is closed. 472 // is closed.
486 if (!LookupById(stream_id)) 473 if (!LookupById(stream_id))
487 return; 474 return;
488 475
489 SendErrorMessage(stream_id); 476 SendErrorMessage(stream_id);
490 477
491 if (media_internals_) 478 audio_log_->OnError(stream_id);
492 media_internals_->OnSetAudioStreamStatus(this, stream_id, "error");
493
494 OnCloseStream(stream_id); 479 OnCloseStream(stream_id);
495 } 480 }
496 481
497 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) { 482 AudioRendererHost::AudioEntry* AudioRendererHost::LookupById(int stream_id) {
498 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 483 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
499 484
500 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id); 485 AudioEntryMap::const_iterator i = audio_entries_.find(stream_id);
501 return i != audio_entries_.end() ? i->second : NULL; 486 return i != audio_entries_.end() ? i->second : NULL;
502 } 487 }
503 488
504 } // namespace content 489 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/renderer_host/media/audio_renderer_host.h ('k') | content/browser/resources/media/client_renderer.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698