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

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

Issue 11573066: Add a method to tab_utils.h to find out whether a tab is playing audio. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review/rewrite Created 7 years, 10 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 | Annotate | Revision Log
« no previous file with comments | « chrome/chrome_browser.gypi ('k') | content/browser/renderer_host/media/mock_media_observer.h » ('j') | 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/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/media/media_internals.h"
13 #include "content/browser/renderer_host/media/audio_mirroring_manager.h" 13 #include "content/browser/renderer_host/media/audio_mirroring_manager.h"
14 #include "content/browser/renderer_host/media/audio_sync_reader.h" 14 #include "content/browser/renderer_host/media/audio_sync_reader.h"
15 #include "content/common/media/audio_messages.h" 15 #include "content/common/media/audio_messages.h"
16 #include "content/public/browser/content_browser_client.h"
17 #include "content/public/browser/media_observer.h"
16 #include "media/audio/shared_memory_util.h" 18 #include "media/audio/shared_memory_util.h"
17 #include "media/base/audio_bus.h" 19 #include "media/base/audio_bus.h"
18 #include "media/base/limits.h" 20 #include "media/base/limits.h"
19 21
20 using media::AudioBus; 22 using media::AudioBus;
21 23
22 namespace content { 24 namespace content {
23 25
24 struct AudioRendererHost::AudioEntry { 26 struct AudioRendererHost::AudioEntry {
25 AudioEntry(); 27 AudioEntry();
(...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 326
325 AudioEntry* const entry = LookupById(stream_id); 327 AudioEntry* const entry = LookupById(stream_id);
326 if (!entry) { 328 if (!entry) {
327 SendErrorMessage(stream_id); 329 SendErrorMessage(stream_id);
328 return; 330 return;
329 } 331 }
330 332
331 if (entry->render_view_id == render_view_id) 333 if (entry->render_view_id == render_view_id)
332 return; 334 return;
333 335
336 // TODO(miu): Merge "AssociateWithProducer" message into "CreateStream"
337 // message so AudioRendererHost can assume a simpler "render_view_id is set
338 // once" scheme. http://crbug.com/166779
334 if (mirroring_manager_) { 339 if (mirroring_manager_) {
335 mirroring_manager_->RemoveDiverter( 340 mirroring_manager_->RemoveDiverter(
336 render_process_id_, entry->render_view_id, entry->controller); 341 render_process_id_, entry->render_view_id, entry->controller);
337 } 342 }
338 entry->render_view_id = render_view_id; 343 entry->render_view_id = render_view_id;
339 if (mirroring_manager_) { 344 if (mirroring_manager_) {
340 mirroring_manager_->AddDiverter( 345 mirroring_manager_->AddDiverter(
341 render_process_id_, entry->render_view_id, entry->controller); 346 render_process_id_, entry->render_view_id, entry->controller);
342 } 347 }
343 } 348 }
344 349
345 void AudioRendererHost::OnPlayStream(int stream_id) { 350 void AudioRendererHost::OnPlayStream(int stream_id) {
346 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 351 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
347 352
348 AudioEntry* entry = LookupById(stream_id); 353 AudioEntry* entry = LookupById(stream_id);
349 if (!entry) { 354 if (!entry) {
350 SendErrorMessage(stream_id); 355 SendErrorMessage(stream_id);
351 return; 356 return;
352 } 357 }
353 358
354 entry->controller->Play(); 359 entry->controller->Play();
355 if (media_internals_) 360 if (media_internals_)
356 media_internals_->OnSetAudioStreamPlaying(this, stream_id, true); 361 media_internals_->OnSetAudioStreamPlaying(this, stream_id, true);
362
363 MediaObserver* media_observer =
364 GetContentClient()->browser()->GetMediaObserver();
365 if (media_observer) {
366 media_observer->OnAudioStreamPlayingChanged(
367 render_process_id_, entry->render_view_id, true);
368 }
357 } 369 }
358 370
359 void AudioRendererHost::OnPauseStream(int stream_id) { 371 void AudioRendererHost::OnPauseStream(int stream_id) {
360 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 372 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
361 373
362 AudioEntry* entry = LookupById(stream_id); 374 AudioEntry* entry = LookupById(stream_id);
363 if (!entry) { 375 if (!entry) {
364 SendErrorMessage(stream_id); 376 SendErrorMessage(stream_id);
365 return; 377 return;
366 } 378 }
367 379
368 entry->controller->Pause(); 380 entry->controller->Pause();
369 if (media_internals_) 381 if (media_internals_)
370 media_internals_->OnSetAudioStreamPlaying(this, stream_id, false); 382 media_internals_->OnSetAudioStreamPlaying(this, stream_id, false);
383
384 MediaObserver* media_observer =
385 GetContentClient()->browser()->GetMediaObserver();
386 if (media_observer) {
387 media_observer->OnAudioStreamPlayingChanged(
388 render_process_id_, entry->render_view_id, true);
miu 2013/02/05 23:18:25 I think you meant s/true/false/ here.
miu 2013/02/05 23:18:25 Also, note that streams are not necessarily paused
Bernhard Bauer 2013/02/08 16:44:14 Urr, yes. Done.
Bernhard Bauer 2013/02/08 16:44:14 Hm. I changed it to a map from RenderView ID to a
389 }
371 } 390 }
372 391
373 void AudioRendererHost::OnFlushStream(int stream_id) { 392 void AudioRendererHost::OnFlushStream(int stream_id) {
374 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 393 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
375 394
376 AudioEntry* entry = LookupById(stream_id); 395 AudioEntry* entry = LookupById(stream_id);
377 if (!entry) { 396 if (!entry) {
378 SendErrorMessage(stream_id); 397 SendErrorMessage(stream_id);
379 return; 398 return;
380 } 399 }
(...skipping 23 matching lines...) Expand all
404 SendErrorMessage(stream_id); 423 SendErrorMessage(stream_id);
405 return; 424 return;
406 } 425 }
407 426
408 // Make sure the volume is valid. 427 // Make sure the volume is valid.
409 if (volume < 0 || volume > 1.0) 428 if (volume < 0 || volume > 1.0)
410 return; 429 return;
411 entry->controller->SetVolume(volume); 430 entry->controller->SetVolume(volume);
412 if (media_internals_) 431 if (media_internals_)
413 media_internals_->OnSetAudioStreamVolume(this, stream_id, volume); 432 media_internals_->OnSetAudioStreamVolume(this, stream_id, volume);
414 } 433 }
miu 2013/02/05 23:18:25 If volume is set to zero (i.e., mute), or set back
Bernhard Bauer 2013/02/08 16:44:14 Done.
415 434
416 void AudioRendererHost::SendErrorMessage(int32 stream_id) { 435 void AudioRendererHost::SendErrorMessage(int32 stream_id) {
417 Send(new AudioMsg_NotifyStreamStateChanged( 436 Send(new AudioMsg_NotifyStreamStateChanged(
418 stream_id, media::AudioOutputIPCDelegate::kError)); 437 stream_id, media::AudioOutputIPCDelegate::kError));
419 } 438 }
420 439
421 void AudioRendererHost::DeleteEntries() { 440 void AudioRendererHost::DeleteEntries() {
422 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 441 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
423 442
424 for (AudioEntryMap::iterator i = audio_entries_.begin(); 443 for (AudioEntryMap::iterator i = audio_entries_.begin();
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
490 return NULL; 509 return NULL;
491 } 510 }
492 511
493 media::AudioOutputController* AudioRendererHost::LookupControllerByIdForTesting( 512 media::AudioOutputController* AudioRendererHost::LookupControllerByIdForTesting(
494 int stream_id) { 513 int stream_id) {
495 AudioEntry* const entry = LookupById(stream_id); 514 AudioEntry* const entry = LookupById(stream_id);
496 return entry ? entry->controller : NULL; 515 return entry ? entry->controller : NULL;
497 } 516 }
498 517
499 } // namespace content 518 } // namespace content
OLDNEW
« no previous file with comments | « chrome/chrome_browser.gypi ('k') | content/browser/renderer_host/media/mock_media_observer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698