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

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: fix Created 8 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/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"
(...skipping 21 matching lines...) Expand all
32 32
33 // Shared memory for transmission of the audio data. 33 // Shared memory for transmission of the audio data.
34 base::SharedMemory shared_memory; 34 base::SharedMemory shared_memory;
35 35
36 // The synchronous reader to be used by the controller. We have the 36 // The synchronous reader to be used by the controller. We have the
37 // ownership of the reader. 37 // ownership of the reader.
38 scoped_ptr<media::AudioOutputController::SyncReader> reader; 38 scoped_ptr<media::AudioOutputController::SyncReader> reader;
39 39
40 // Set to true after we called Close() for the controller. 40 // Set to true after we called Close() for the controller.
41 bool pending_close; 41 bool pending_close;
42
43 int render_view_id;
42 }; 44 };
43 45
44 AudioRendererHost::AudioEntry::AudioEntry() 46 AudioRendererHost::AudioEntry::AudioEntry()
45 : stream_id(0), 47 : stream_id(0),
46 pending_close(false) { 48 pending_close(false),
49 render_view_id(0) {
miu 2012/12/19 00:49:08 nit: This should probably default to MSG_ROUTING_N
47 } 50 }
48 51
49 AudioRendererHost::AudioEntry::~AudioEntry() {} 52 AudioRendererHost::AudioEntry::~AudioEntry() {}
50 53
51 /////////////////////////////////////////////////////////////////////////////// 54 ///////////////////////////////////////////////////////////////////////////////
52 // AudioRendererHost implementations. 55 // AudioRendererHost implementations.
53 AudioRendererHost::AudioRendererHost( 56 AudioRendererHost::AudioRendererHost(
54 media::AudioManager* audio_manager, MediaObserver* media_observer) 57 int render_process_id,
55 : audio_manager_(audio_manager), 58 media::AudioManager* audio_manager,
59 MediaObserver* media_observer)
60 : render_process_id_(render_process_id),
61 audio_manager_(audio_manager),
56 media_observer_(media_observer) { 62 media_observer_(media_observer) {
57 } 63 }
58 64
59 AudioRendererHost::~AudioRendererHost() { 65 AudioRendererHost::~AudioRendererHost() {
60 DCHECK(audio_entries_.empty()); 66 DCHECK(audio_entries_.empty());
61 } 67 }
62 68
63 void AudioRendererHost::OnChannelClosing() { 69 void AudioRendererHost::OnChannelClosing() {
64 BrowserMessageFilter::OnChannelClosing(); 70 BrowserMessageFilter::OnChannelClosing();
65 71
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 // If we have created the controller successfully, create an entry and add it 284 // If we have created the controller successfully, create an entry and add it
279 // to the map. 285 // to the map.
280 entry->stream_id = stream_id; 286 entry->stream_id = stream_id;
281 audio_entries_.insert(std::make_pair(stream_id, entry.release())); 287 audio_entries_.insert(std::make_pair(stream_id, entry.release()));
282 if (media_observer_) 288 if (media_observer_)
283 media_observer_->OnSetAudioStreamStatus(this, stream_id, "created"); 289 media_observer_->OnSetAudioStreamStatus(this, stream_id, "created");
284 } 290 }
285 291
286 void AudioRendererHost::OnAssociateStreamWithProducer(int stream_id, 292 void AudioRendererHost::OnAssociateStreamWithProducer(int stream_id,
287 int render_view_id) { 293 int render_view_id) {
288 // TODO(miu): Will use render_view_id in upcoming change. 294 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
289 DVLOG(1) << "AudioRendererHost@" << this 295
290 << "::OnAssociateStreamWithProducer(stream_id=" << stream_id 296 AudioEntry* entry = LookupById(stream_id);
291 << ", render_view_id=" << render_view_id << ")"; 297 if (!entry) {
298 SendErrorMessage(stream_id);
299 return;
300 }
301
302 entry->render_view_id = render_view_id;
miu 2012/12/19 00:49:08 While you're here, could you add a comment: TODO(
Bernhard Bauer 2013/02/05 18:45:18 Done.
292 } 303 }
293 304
294 void AudioRendererHost::OnPlayStream(int stream_id) { 305 void AudioRendererHost::OnPlayStream(int stream_id) {
295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 306 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
296 307
297 AudioEntry* entry = LookupById(stream_id); 308 AudioEntry* entry = LookupById(stream_id);
298 if (!entry) { 309 if (!entry) {
299 SendErrorMessage(stream_id); 310 SendErrorMessage(stream_id);
300 return; 311 return;
301 } 312 }
302 313
303 entry->controller->Play(); 314 entry->controller->Play();
304 if (media_observer_) 315 if (media_observer_)
305 media_observer_->OnSetAudioStreamPlaying(this, stream_id, true); 316 media_observer_->OnSetAudioStreamPlaying(
317 this, stream_id, render_process_id_, entry->render_view_id, true);
306 } 318 }
307 319
308 void AudioRendererHost::OnPauseStream(int stream_id) { 320 void AudioRendererHost::OnPauseStream(int stream_id) {
309 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 321 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
310 322
311 AudioEntry* entry = LookupById(stream_id); 323 AudioEntry* entry = LookupById(stream_id);
312 if (!entry) { 324 if (!entry) {
313 SendErrorMessage(stream_id); 325 SendErrorMessage(stream_id);
314 return; 326 return;
315 } 327 }
316 328
317 entry->controller->Pause(); 329 entry->controller->Pause();
318 if (media_observer_) 330 if (media_observer_) {
319 media_observer_->OnSetAudioStreamPlaying(this, stream_id, false); 331 media_observer_->OnSetAudioStreamPlaying(
332 this, stream_id, render_process_id_, entry->render_view_id, false);
333 }
320 } 334 }
321 335
322 void AudioRendererHost::OnFlushStream(int stream_id) { 336 void AudioRendererHost::OnFlushStream(int stream_id) {
323 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 337 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
324 338
325 AudioEntry* entry = LookupById(stream_id); 339 AudioEntry* entry = LookupById(stream_id);
326 if (!entry) { 340 if (!entry) {
327 SendErrorMessage(stream_id); 341 SendErrorMessage(stream_id);
328 return; 342 return;
329 } 343 }
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
435 return NULL; 449 return NULL;
436 } 450 }
437 451
438 media::AudioOutputController* AudioRendererHost::LookupControllerByIdForTesting( 452 media::AudioOutputController* AudioRendererHost::LookupControllerByIdForTesting(
439 int stream_id) { 453 int stream_id) {
440 AudioEntry* const entry = LookupById(stream_id); 454 AudioEntry* const entry = LookupById(stream_id);
441 return entry ? entry->controller : NULL; 455 return entry ? entry->controller : NULL;
442 } 456 }
443 457
444 } // namespace content 458 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698