OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #include "content/renderer/media/renderer_audio_output_device.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/message_loop_proxy.h" | |
9 #include "content/renderer/media/audio_message_filter.h" | |
10 | |
11 namespace content { | |
12 | |
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) { | |
19 } | |
20 | |
21 RendererAudioOutputDevice::~RendererAudioOutputDevice() {} | |
22 | |
23 void RendererAudioOutputDevice::Start() { | |
24 AudioOutputDevice::Start(); | |
25 message_loop()->PostTask( | |
26 FROM_HERE, | |
27 base::Bind(&RendererAudioOutputDevice::OnStart, this)); | |
28 } | |
29 | |
30 void RendererAudioOutputDevice::Stop() { | |
31 AudioOutputDevice::Stop(); | |
32 message_loop()->PostTask( | |
33 FROM_HERE, | |
34 base::Bind(&RendererAudioOutputDevice::OnStop, this)); | |
35 } | |
36 | |
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)); | |
42 } | |
43 | |
44 void RendererAudioOutputDevice::OnStart() { | |
45 DCHECK(message_loop()->BelongsToCurrentThread()); | |
46 is_after_stream_created_ = true; | |
47 OnSourceChange(source_render_view_id_); | |
48 } | |
49 | |
50 void RendererAudioOutputDevice::OnStop() { | |
51 DCHECK(message_loop()->BelongsToCurrentThread()); | |
52 is_after_stream_created_ = false; | |
53 } | |
54 | |
55 void RendererAudioOutputDevice::OnSourceChange(int render_view_id) { | |
56 DCHECK(message_loop()->BelongsToCurrentThread()); | |
57 source_render_view_id_ = render_view_id; | |
58 if (is_after_stream_created_ && source_render_view_id_ != MSG_ROUTING_NONE) { | |
59 AudioMessageFilter* const filter = | |
60 static_cast<AudioMessageFilter*>(audio_output_ipc()); | |
61 if (filter) | |
62 filter->AssociateStreamWithProducer(stream_id(), source_render_view_id_); | |
63 } | |
64 } | |
65 | |
66 } // namespace content | |
OLD | NEW |