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
3 // found in the LICENSE file.
5 #include "content/renderer/media/renderer_audio_output_device.h"
8 #include "base/message_loop_proxy.h"
9 #include "content/renderer/media/audio_message_filter.h"
13 RendererAudioOutputDevice::RendererAudioOutputDevice(
14 AudioMessageFilter
* message_filter
,
15 const scoped_refptr
<base::MessageLoopProxy
>& io_loop
)
16 : AudioOutputDevice(message_filter
, io_loop
),
17 source_render_view_id_(MSG_ROUTING_NONE
),
18 is_after_stream_created_(false) {
21 RendererAudioOutputDevice::~RendererAudioOutputDevice() {}
23 void RendererAudioOutputDevice::Start() {
24 AudioOutputDevice::Start();
25 message_loop()->PostTask(
27 base::Bind(&RendererAudioOutputDevice::OnStart
, this));
30 void RendererAudioOutputDevice::Stop() {
31 AudioOutputDevice::Stop();
32 message_loop()->PostTask(
34 base::Bind(&RendererAudioOutputDevice::OnStop
, this));
37 void RendererAudioOutputDevice::SetSourceRenderView(int render_view_id
) {
38 message_loop()->PostTask(
40 base::Bind(&RendererAudioOutputDevice::OnSourceChange
, this,
44 void RendererAudioOutputDevice::OnStart() {
45 is_after_stream_created_
= true;
46 OnSourceChange(source_render_view_id_
);
49 void RendererAudioOutputDevice::OnStop() {
50 is_after_stream_created_
= false;
53 void RendererAudioOutputDevice::OnSourceChange(int render_view_id
) {
54 source_render_view_id_
= render_view_id
;
55 if (is_after_stream_created_
&& source_render_view_id_
!= MSG_ROUTING_NONE
) {
56 AudioMessageFilter
* const filter
=
57 static_cast<AudioMessageFilter
*>(audio_output_ipc());
59 filter
->AssociateStreamWithProducer(stream_id(), source_render_view_id_
);
63 } // namespace content