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/renderer/pepper/pepper_platform_audio_input_impl.h" | 5 #include "content/renderer/pepper/pepper_platform_audio_input_impl.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "content/common/child_process.h" | 11 #include "content/common/child_process.h" |
12 #include "content/common/media/audio_messages.h" | 12 #include "content/common/media/audio_messages.h" |
| 13 #include "content/renderer/media/audio_input_message_filter.h" |
13 #include "content/renderer/pepper/pepper_plugin_delegate_impl.h" | 14 #include "content/renderer/pepper/pepper_plugin_delegate_impl.h" |
14 #include "content/renderer/render_thread_impl.h" | 15 #include "content/renderer/render_thread_impl.h" |
15 #include "media/audio/audio_manager_base.h" | 16 #include "media/audio/audio_manager_base.h" |
16 | 17 |
17 namespace content { | 18 namespace content { |
18 | 19 |
19 // static | 20 // static |
20 PepperPlatformAudioInputImpl* PepperPlatformAudioInputImpl::Create( | 21 PepperPlatformAudioInputImpl* PepperPlatformAudioInputImpl::Create( |
21 const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate, | 22 const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate, |
22 const std::string& device_id, | 23 const std::string& device_id, |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 // here. | 132 // here. |
132 DCHECK_EQ(0, stream_id_); | 133 DCHECK_EQ(0, stream_id_); |
133 DCHECK(!client_); | 134 DCHECK(!client_); |
134 DCHECK(label_.empty()); | 135 DCHECK(label_.empty()); |
135 DCHECK(shutdown_called_); | 136 DCHECK(shutdown_called_); |
136 } | 137 } |
137 | 138 |
138 PepperPlatformAudioInputImpl::PepperPlatformAudioInputImpl() | 139 PepperPlatformAudioInputImpl::PepperPlatformAudioInputImpl() |
139 : client_(NULL), | 140 : client_(NULL), |
140 stream_id_(0), | 141 stream_id_(0), |
| 142 render_view_id_(MSG_ROUTING_NONE), |
141 main_message_loop_proxy_(base::MessageLoopProxy::current()), | 143 main_message_loop_proxy_(base::MessageLoopProxy::current()), |
142 shutdown_called_(false) { | 144 shutdown_called_(false) { |
143 ipc_ = RenderThreadImpl::current()->audio_input_message_filter(); | 145 ipc_ = RenderThreadImpl::current()->audio_input_message_filter(); |
144 } | 146 } |
145 | 147 |
146 bool PepperPlatformAudioInputImpl::Initialize( | 148 bool PepperPlatformAudioInputImpl::Initialize( |
147 const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate, | 149 const base::WeakPtr<PepperPluginDelegateImpl>& plugin_delegate, |
148 const std::string& device_id, | 150 const std::string& device_id, |
149 int sample_rate, | 151 int sample_rate, |
150 int frames_per_buffer, | 152 int frames_per_buffer, |
151 webkit::ppapi::PluginDelegate::PlatformAudioInputClient* client) { | 153 webkit::ppapi::PluginDelegate::PlatformAudioInputClient* client) { |
152 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); | 154 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); |
153 | 155 |
154 if (!plugin_delegate || !client) | 156 if (!plugin_delegate || !client) |
155 return false; | 157 return false; |
156 | 158 |
157 plugin_delegate_ = plugin_delegate; | 159 plugin_delegate_ = plugin_delegate; |
| 160 render_view_id_ = plugin_delegate_->GetRoutingID(); |
158 client_ = client; | 161 client_ = client; |
159 | 162 |
160 params_.Reset(media::AudioParameters::AUDIO_PCM_LINEAR, | 163 params_.Reset(media::AudioParameters::AUDIO_PCM_LINEAR, |
161 media::CHANNEL_LAYOUT_MONO, sample_rate, 16, frames_per_buffer); | 164 media::CHANNEL_LAYOUT_MONO, sample_rate, 16, frames_per_buffer); |
162 | 165 |
163 if (device_id.empty()) { | 166 if (device_id.empty()) { |
164 // Use the default device. | 167 // Use the default device. |
165 ChildProcess::current()->io_message_loop()->PostTask( | 168 ChildProcess::current()->io_message_loop()->PostTask( |
166 FROM_HERE, | 169 FROM_HERE, |
167 base::Bind(&PepperPlatformAudioInputImpl::InitializeOnIOThread, | 170 base::Bind(&PepperPlatformAudioInputImpl::InitializeOnIOThread, |
(...skipping 27 matching lines...) Expand all Loading... |
195 } else { | 198 } else { |
196 // We will be notified by OnDeviceReady(). | 199 // We will be notified by OnDeviceReady(). |
197 ipc_->StartDevice(stream_id_, session_id); | 200 ipc_->StartDevice(stream_id_, session_id); |
198 } | 201 } |
199 } | 202 } |
200 | 203 |
201 void PepperPlatformAudioInputImpl::StartCaptureOnIOThread() { | 204 void PepperPlatformAudioInputImpl::StartCaptureOnIOThread() { |
202 DCHECK(ChildProcess::current()->io_message_loop_proxy()-> | 205 DCHECK(ChildProcess::current()->io_message_loop_proxy()-> |
203 BelongsToCurrentThread()); | 206 BelongsToCurrentThread()); |
204 | 207 |
205 if (stream_id_) | 208 if (stream_id_) { |
| 209 ipc_->AssociateStreamWithConsumer(stream_id_, render_view_id_); |
206 ipc_->RecordStream(stream_id_); | 210 ipc_->RecordStream(stream_id_); |
| 211 } |
207 } | 212 } |
208 | 213 |
209 void PepperPlatformAudioInputImpl::StopCaptureOnIOThread() { | 214 void PepperPlatformAudioInputImpl::StopCaptureOnIOThread() { |
210 DCHECK(ChildProcess::current()->io_message_loop_proxy()-> | 215 DCHECK(ChildProcess::current()->io_message_loop_proxy()-> |
211 BelongsToCurrentThread()); | 216 BelongsToCurrentThread()); |
212 | 217 |
213 // TODO(yzshen): We cannot re-start capturing if the stream is closed. | 218 // TODO(yzshen): We cannot re-start capturing if the stream is closed. |
214 if (stream_id_) | 219 if (stream_id_) |
215 ipc_->CloseStream(stream_id_); | 220 ipc_->CloseStream(stream_id_); |
216 } | 221 } |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 } | 278 } |
274 | 279 |
275 void PepperPlatformAudioInputImpl::NotifyStreamCreationFailed() { | 280 void PepperPlatformAudioInputImpl::NotifyStreamCreationFailed() { |
276 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); | 281 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); |
277 | 282 |
278 if (client_) | 283 if (client_) |
279 client_->StreamCreationFailed(); | 284 client_->StreamCreationFailed(); |
280 } | 285 } |
281 | 286 |
282 } // namespace content | 287 } // namespace content |
OLD | NEW |