Associate audio streams with their source/destination RenderView.
[chromium-blink-merge.git] / content / renderer / media / renderer_audio_output_device.cc
blob1cbf1e30d7cf5329e1e553d42ec9da88b8b9e87d
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"
7 #include "base/bind.h"
8 #include "base/message_loop_proxy.h"
9 #include "content/renderer/media/audio_message_filter.h"
11 namespace content {
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(
26 FROM_HERE,
27 base::Bind(&RendererAudioOutputDevice::OnStart, this));
30 void RendererAudioOutputDevice::Stop() {
31 AudioOutputDevice::Stop();
32 message_loop()->PostTask(
33 FROM_HERE,
34 base::Bind(&RendererAudioOutputDevice::OnStop, this));
37 void RendererAudioOutputDevice::SetSourceRenderView(int render_view_id) {
38 message_loop()->PostTask(
39 FROM_HERE,
40 base::Bind(&RendererAudioOutputDevice::OnSourceChange, this,
41 render_view_id));
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());
58 if (filter)
59 filter->AssociateStreamWithProducer(stream_id(), source_render_view_id_);
63 } // namespace content