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/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/renderer_host/media/audio_mirroring_manager.h" |
12 #include "content/browser/renderer_host/media/audio_sync_reader.h" | 13 #include "content/browser/renderer_host/media/audio_sync_reader.h" |
13 #include "content/common/media/audio_messages.h" | 14 #include "content/common/media/audio_messages.h" |
14 #include "content/public/browser/media_observer.h" | 15 #include "content/public/browser/media_observer.h" |
15 #include "media/audio/shared_memory_util.h" | 16 #include "media/audio/shared_memory_util.h" |
16 #include "media/base/audio_bus.h" | 17 #include "media/base/audio_bus.h" |
17 #include "media/base/limits.h" | 18 #include "media/base/limits.h" |
18 | 19 |
19 using media::AudioBus; | 20 using media::AudioBus; |
20 | 21 |
21 namespace content { | 22 namespace content { |
22 | 23 |
23 struct AudioRendererHost::AudioEntry { | 24 struct AudioRendererHost::AudioEntry { |
24 AudioEntry(); | 25 AudioEntry(); |
25 ~AudioEntry(); | 26 ~AudioEntry(); |
26 | 27 |
27 // The AudioOutputController that manages the audio stream. | 28 // The AudioOutputController that manages the audio stream. |
28 scoped_refptr<media::AudioOutputController> controller; | 29 scoped_refptr<media::AudioOutputController> controller; |
29 | 30 |
30 // The audio stream ID. | 31 // The audio stream ID. |
31 int stream_id; | 32 int stream_id; |
32 | 33 |
| 34 // The routing ID of the source render view. |
| 35 int render_view_id; |
| 36 |
33 // Shared memory for transmission of the audio data. | 37 // Shared memory for transmission of the audio data. |
34 base::SharedMemory shared_memory; | 38 base::SharedMemory shared_memory; |
35 | 39 |
36 // The synchronous reader to be used by the controller. We have the | 40 // The synchronous reader to be used by the controller. We have the |
37 // ownership of the reader. | 41 // ownership of the reader. |
38 scoped_ptr<media::AudioOutputController::SyncReader> reader; | 42 scoped_ptr<media::AudioOutputController::SyncReader> reader; |
39 | 43 |
40 // Set to true after we called Close() for the controller. | 44 // Set to true after we called Close() for the controller. |
41 bool pending_close; | 45 bool pending_close; |
42 }; | 46 }; |
43 | 47 |
44 AudioRendererHost::AudioEntry::AudioEntry() | 48 AudioRendererHost::AudioEntry::AudioEntry() |
45 : stream_id(0), | 49 : stream_id(0), |
| 50 render_view_id(MSG_ROUTING_NONE), |
46 pending_close(false) { | 51 pending_close(false) { |
47 } | 52 } |
48 | 53 |
49 AudioRendererHost::AudioEntry::~AudioEntry() {} | 54 AudioRendererHost::AudioEntry::~AudioEntry() {} |
50 | 55 |
51 /////////////////////////////////////////////////////////////////////////////// | 56 /////////////////////////////////////////////////////////////////////////////// |
52 // AudioRendererHost implementations. | 57 // AudioRendererHost implementations. |
53 AudioRendererHost::AudioRendererHost( | 58 AudioRendererHost::AudioRendererHost( |
54 media::AudioManager* audio_manager, MediaObserver* media_observer) | 59 int render_process_id, |
55 : audio_manager_(audio_manager), | 60 media::AudioManager* audio_manager, |
| 61 AudioMirroringManager* mirroring_manager, |
| 62 MediaObserver* media_observer) |
| 63 : render_process_id_(render_process_id), |
| 64 audio_manager_(audio_manager), |
| 65 mirroring_manager_(mirroring_manager), |
56 media_observer_(media_observer) { | 66 media_observer_(media_observer) { |
| 67 DCHECK(audio_manager_); |
57 } | 68 } |
58 | 69 |
59 AudioRendererHost::~AudioRendererHost() { | 70 AudioRendererHost::~AudioRendererHost() { |
60 DCHECK(audio_entries_.empty()); | 71 DCHECK(audio_entries_.empty()); |
61 } | 72 } |
62 | 73 |
63 void AudioRendererHost::OnChannelClosing() { | 74 void AudioRendererHost::OnChannelClosing() { |
64 BrowserMessageFilter::OnChannelClosing(); | 75 BrowserMessageFilter::OnChannelClosing(); |
65 | 76 |
66 // Since the IPC channel is gone, close all requested audio streams. | 77 // Since the IPC channel is gone, close all requested audio streams. |
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
274 // If we have created the controller successfully, create an entry and add it | 285 // If we have created the controller successfully, create an entry and add it |
275 // to the map. | 286 // to the map. |
276 entry->stream_id = stream_id; | 287 entry->stream_id = stream_id; |
277 audio_entries_.insert(std::make_pair(stream_id, entry.release())); | 288 audio_entries_.insert(std::make_pair(stream_id, entry.release())); |
278 if (media_observer_) | 289 if (media_observer_) |
279 media_observer_->OnSetAudioStreamStatus(this, stream_id, "created"); | 290 media_observer_->OnSetAudioStreamStatus(this, stream_id, "created"); |
280 } | 291 } |
281 | 292 |
282 void AudioRendererHost::OnAssociateStreamWithProducer(int stream_id, | 293 void AudioRendererHost::OnAssociateStreamWithProducer(int stream_id, |
283 int render_view_id) { | 294 int render_view_id) { |
284 // TODO(miu): Will use render_view_id in upcoming change. | 295 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 296 |
285 DVLOG(1) << "AudioRendererHost@" << this | 297 DVLOG(1) << "AudioRendererHost@" << this |
286 << "::OnAssociateStreamWithProducer(stream_id=" << stream_id | 298 << "::OnAssociateStreamWithProducer(stream_id=" << stream_id |
287 << ", render_view_id=" << render_view_id << ")"; | 299 << ", render_view_id=" << render_view_id << ")"; |
| 300 |
| 301 AudioEntry* const entry = LookupById(stream_id); |
| 302 if (!entry) { |
| 303 SendErrorMessage(stream_id); |
| 304 return; |
| 305 } |
| 306 |
| 307 if (entry->render_view_id == render_view_id) |
| 308 return; |
| 309 |
| 310 if (mirroring_manager_) { |
| 311 mirroring_manager_->RemoveDiverter( |
| 312 render_process_id_, entry->render_view_id, entry->controller); |
| 313 } |
| 314 entry->render_view_id = render_view_id; |
| 315 if (mirroring_manager_) { |
| 316 mirroring_manager_->AddDiverter( |
| 317 render_process_id_, entry->render_view_id, entry->controller); |
| 318 } |
288 } | 319 } |
289 | 320 |
290 void AudioRendererHost::OnPlayStream(int stream_id) { | 321 void AudioRendererHost::OnPlayStream(int stream_id) { |
291 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 322 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
292 | 323 |
293 AudioEntry* entry = LookupById(stream_id); | 324 AudioEntry* entry = LookupById(stream_id); |
294 if (!entry) { | 325 if (!entry) { |
295 SendErrorMessage(stream_id); | 326 SendErrorMessage(stream_id); |
296 return; | 327 return; |
297 } | 328 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 for (AudioEntryMap::iterator i = audio_entries_.begin(); | 400 for (AudioEntryMap::iterator i = audio_entries_.begin(); |
370 i != audio_entries_.end(); ++i) { | 401 i != audio_entries_.end(); ++i) { |
371 CloseAndDeleteStream(i->second); | 402 CloseAndDeleteStream(i->second); |
372 } | 403 } |
373 } | 404 } |
374 | 405 |
375 void AudioRendererHost::CloseAndDeleteStream(AudioEntry* entry) { | 406 void AudioRendererHost::CloseAndDeleteStream(AudioEntry* entry) { |
376 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 407 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
377 | 408 |
378 if (!entry->pending_close) { | 409 if (!entry->pending_close) { |
| 410 if (mirroring_manager_) { |
| 411 mirroring_manager_->RemoveDiverter( |
| 412 render_process_id_, entry->render_view_id, entry->controller); |
| 413 } |
379 entry->controller->Close( | 414 entry->controller->Close( |
380 base::Bind(&AudioRendererHost::DeleteEntry, this, entry)); | 415 base::Bind(&AudioRendererHost::DeleteEntry, this, entry)); |
381 entry->pending_close = true; | 416 entry->pending_close = true; |
382 } | 417 } |
383 } | 418 } |
384 | 419 |
385 void AudioRendererHost::DeleteEntry(AudioEntry* entry) { | 420 void AudioRendererHost::DeleteEntry(AudioEntry* entry) { |
386 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 421 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
387 | 422 |
388 // Delete the entry when this method goes out of scope. | 423 // Delete the entry when this method goes out of scope. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 return NULL; | 466 return NULL; |
432 } | 467 } |
433 | 468 |
434 media::AudioOutputController* AudioRendererHost::LookupControllerByIdForTesting( | 469 media::AudioOutputController* AudioRendererHost::LookupControllerByIdForTesting( |
435 int stream_id) { | 470 int stream_id) { |
436 AudioEntry* const entry = LookupById(stream_id); | 471 AudioEntry* const entry = LookupById(stream_id); |
437 return entry ? entry->controller : NULL; | 472 return entry ? entry->controller : NULL; |
438 } | 473 } |
439 | 474 |
440 } // namespace content | 475 } // namespace content |
OLD | NEW |