| 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.h" | 5 #include "content/renderer/pepper/pepper_platform_audio_input.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/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 // PepperPlatformAudioInput::ShutDownOnIOThread(). | 41 // PepperPlatformAudioInput::ShutDownOnIOThread(). |
| 42 audio_input->AddRef(); | 42 audio_input->AddRef(); |
| 43 return audio_input.get(); | 43 return audio_input.get(); |
| 44 } | 44 } |
| 45 return NULL; | 45 return NULL; |
| 46 } | 46 } |
| 47 | 47 |
| 48 void PepperPlatformAudioInput::StartCapture() { | 48 void PepperPlatformAudioInput::StartCapture() { |
| 49 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); | 49 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); |
| 50 | 50 |
| 51 io_message_loop_proxy_->PostTask( | 51 io_task_runner_->PostTask( |
| 52 FROM_HERE, | 52 FROM_HERE, |
| 53 base::Bind(&PepperPlatformAudioInput::StartCaptureOnIOThread, this)); | 53 base::Bind(&PepperPlatformAudioInput::StartCaptureOnIOThread, this)); |
| 54 } | 54 } |
| 55 | 55 |
| 56 void PepperPlatformAudioInput::StopCapture() { | 56 void PepperPlatformAudioInput::StopCapture() { |
| 57 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); | 57 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); |
| 58 | 58 |
| 59 io_message_loop_proxy_->PostTask( | 59 io_task_runner_->PostTask( |
| 60 FROM_HERE, | 60 FROM_HERE, |
| 61 base::Bind(&PepperPlatformAudioInput::StopCaptureOnIOThread, this)); | 61 base::Bind(&PepperPlatformAudioInput::StopCaptureOnIOThread, this)); |
| 62 } | 62 } |
| 63 | 63 |
| 64 void PepperPlatformAudioInput::ShutDown() { | 64 void PepperPlatformAudioInput::ShutDown() { |
| 65 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); | 65 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); |
| 66 | 66 |
| 67 // Make sure we don't call shutdown more than once. | 67 // Make sure we don't call shutdown more than once. |
| 68 if (!client_) | 68 if (!client_) |
| 69 return; | 69 return; |
| 70 | 70 |
| 71 // Called on the main thread to stop all audio callbacks. We must only change | 71 // Called on the main thread to stop all audio callbacks. We must only change |
| 72 // the client on the main thread, and the delegates from the I/O thread. | 72 // the client on the main thread, and the delegates from the I/O thread. |
| 73 client_ = NULL; | 73 client_ = NULL; |
| 74 io_message_loop_proxy_->PostTask( | 74 io_task_runner_->PostTask( |
| 75 FROM_HERE, | 75 FROM_HERE, |
| 76 base::Bind(&PepperPlatformAudioInput::ShutDownOnIOThread, this)); | 76 base::Bind(&PepperPlatformAudioInput::ShutDownOnIOThread, this)); |
| 77 } | 77 } |
| 78 | 78 |
| 79 void PepperPlatformAudioInput::OnStreamCreated( | 79 void PepperPlatformAudioInput::OnStreamCreated( |
| 80 base::SharedMemoryHandle handle, | 80 base::SharedMemoryHandle handle, |
| 81 base::SyncSocket::Handle socket_handle, | 81 base::SyncSocket::Handle socket_handle, |
| 82 int length, | 82 int length, |
| 83 int total_segments) { | 83 int total_segments) { |
| 84 #if defined(OS_WIN) | 84 #if defined(OS_WIN) |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 132 // here. | 132 // here. |
| 133 DCHECK(!ipc_); | 133 DCHECK(!ipc_); |
| 134 DCHECK(!client_); | 134 DCHECK(!client_); |
| 135 DCHECK(label_.empty()); | 135 DCHECK(label_.empty()); |
| 136 DCHECK(!pending_open_device_); | 136 DCHECK(!pending_open_device_); |
| 137 } | 137 } |
| 138 | 138 |
| 139 PepperPlatformAudioInput::PepperPlatformAudioInput() | 139 PepperPlatformAudioInput::PepperPlatformAudioInput() |
| 140 : client_(NULL), | 140 : client_(NULL), |
| 141 main_message_loop_proxy_(base::MessageLoopProxy::current()), | 141 main_message_loop_proxy_(base::MessageLoopProxy::current()), |
| 142 io_message_loop_proxy_(ChildProcess::current()->io_message_loop_proxy()), | 142 io_task_runner_(ChildProcess::current()->io_task_runner()), |
| 143 render_frame_id_(MSG_ROUTING_NONE), | 143 render_frame_id_(MSG_ROUTING_NONE), |
| 144 create_stream_sent_(false), | 144 create_stream_sent_(false), |
| 145 pending_open_device_(false), | 145 pending_open_device_(false), |
| 146 pending_open_device_id_(-1) {} | 146 pending_open_device_id_(-1) { |
| 147 } |
| 147 | 148 |
| 148 bool PepperPlatformAudioInput::Initialize( | 149 bool PepperPlatformAudioInput::Initialize( |
| 149 int render_frame_id, | 150 int render_frame_id, |
| 150 const std::string& device_id, | 151 const std::string& device_id, |
| 151 const GURL& document_url, | 152 const GURL& document_url, |
| 152 int sample_rate, | 153 int sample_rate, |
| 153 int frames_per_buffer, | 154 int frames_per_buffer, |
| 154 PepperAudioInputHost* client) { | 155 PepperAudioInputHost* client) { |
| 155 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); | 156 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); |
| 156 | 157 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 182 PP_DEVICETYPE_DEV_AUDIOCAPTURE, | 183 PP_DEVICETYPE_DEV_AUDIOCAPTURE, |
| 183 device_id.empty() ? media::AudioManagerBase::kDefaultDeviceId : device_id, | 184 device_id.empty() ? media::AudioManagerBase::kDefaultDeviceId : device_id, |
| 184 document_url, | 185 document_url, |
| 185 base::Bind(&PepperPlatformAudioInput::OnDeviceOpened, this)); | 186 base::Bind(&PepperPlatformAudioInput::OnDeviceOpened, this)); |
| 186 pending_open_device_ = true; | 187 pending_open_device_ = true; |
| 187 | 188 |
| 188 return true; | 189 return true; |
| 189 } | 190 } |
| 190 | 191 |
| 191 void PepperPlatformAudioInput::InitializeOnIOThread(int session_id) { | 192 void PepperPlatformAudioInput::InitializeOnIOThread(int session_id) { |
| 192 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 193 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 193 | 194 |
| 194 if (!ipc_) | 195 if (!ipc_) |
| 195 return; | 196 return; |
| 196 | 197 |
| 197 // We will be notified by OnStreamCreated(). | 198 // We will be notified by OnStreamCreated(). |
| 198 create_stream_sent_ = true; | 199 create_stream_sent_ = true; |
| 199 ipc_->CreateStream(this, session_id, params_, false, 1); | 200 ipc_->CreateStream(this, session_id, params_, false, 1); |
| 200 } | 201 } |
| 201 | 202 |
| 202 void PepperPlatformAudioInput::StartCaptureOnIOThread() { | 203 void PepperPlatformAudioInput::StartCaptureOnIOThread() { |
| 203 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 204 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 204 | 205 |
| 205 if (ipc_) | 206 if (ipc_) |
| 206 ipc_->RecordStream(); | 207 ipc_->RecordStream(); |
| 207 } | 208 } |
| 208 | 209 |
| 209 void PepperPlatformAudioInput::StopCaptureOnIOThread() { | 210 void PepperPlatformAudioInput::StopCaptureOnIOThread() { |
| 210 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 211 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 211 | 212 |
| 212 // TODO(yzshen): We cannot re-start capturing if the stream is closed. | 213 // TODO(yzshen): We cannot re-start capturing if the stream is closed. |
| 213 if (ipc_ && create_stream_sent_) { | 214 if (ipc_ && create_stream_sent_) { |
| 214 ipc_->CloseStream(); | 215 ipc_->CloseStream(); |
| 215 } | 216 } |
| 216 ipc_.reset(); | 217 ipc_.reset(); |
| 217 } | 218 } |
| 218 | 219 |
| 219 void PepperPlatformAudioInput::ShutDownOnIOThread() { | 220 void PepperPlatformAudioInput::ShutDownOnIOThread() { |
| 220 DCHECK(io_message_loop_proxy_->BelongsToCurrentThread()); | 221 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 221 | 222 |
| 222 StopCaptureOnIOThread(); | 223 StopCaptureOnIOThread(); |
| 223 | 224 |
| 224 main_message_loop_proxy_->PostTask( | 225 main_message_loop_proxy_->PostTask( |
| 225 FROM_HERE, base::Bind(&PepperPlatformAudioInput::CloseDevice, this)); | 226 FROM_HERE, base::Bind(&PepperPlatformAudioInput::CloseDevice, this)); |
| 226 | 227 |
| 227 Release(); // Release for the delegate, balances out the reference taken in | 228 Release(); // Release for the delegate, balances out the reference taken in |
| 228 // PepperPlatformAudioInput::Create. | 229 // PepperPlatformAudioInput::Create. |
| 229 } | 230 } |
| 230 | 231 |
| 231 void PepperPlatformAudioInput::OnDeviceOpened(int request_id, | 232 void PepperPlatformAudioInput::OnDeviceOpened(int request_id, |
| 232 bool succeeded, | 233 bool succeeded, |
| 233 const std::string& label) { | 234 const std::string& label) { |
| 234 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); | 235 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); |
| 235 | 236 |
| 236 pending_open_device_ = false; | 237 pending_open_device_ = false; |
| 237 pending_open_device_id_ = -1; | 238 pending_open_device_id_ = -1; |
| 238 | 239 |
| 239 PepperMediaDeviceManager* const device_manager = GetMediaDeviceManager(); | 240 PepperMediaDeviceManager* const device_manager = GetMediaDeviceManager(); |
| 240 if (succeeded && device_manager) { | 241 if (succeeded && device_manager) { |
| 241 DCHECK(!label.empty()); | 242 DCHECK(!label.empty()); |
| 242 label_ = label; | 243 label_ = label; |
| 243 | 244 |
| 244 if (client_) { | 245 if (client_) { |
| 245 int session_id = device_manager->GetSessionID( | 246 int session_id = device_manager->GetSessionID( |
| 246 PP_DEVICETYPE_DEV_AUDIOCAPTURE, label); | 247 PP_DEVICETYPE_DEV_AUDIOCAPTURE, label); |
| 247 io_message_loop_proxy_->PostTask( | 248 io_task_runner_->PostTask( |
| 248 FROM_HERE, | 249 FROM_HERE, base::Bind(&PepperPlatformAudioInput::InitializeOnIOThread, |
| 249 base::Bind(&PepperPlatformAudioInput::InitializeOnIOThread, | 250 this, session_id)); |
| 250 this, | |
| 251 session_id)); | |
| 252 } else { | 251 } else { |
| 253 // Shutdown has occurred. | 252 // Shutdown has occurred. |
| 254 CloseDevice(); | 253 CloseDevice(); |
| 255 } | 254 } |
| 256 } else { | 255 } else { |
| 257 NotifyStreamCreationFailed(); | 256 NotifyStreamCreationFailed(); |
| 258 } | 257 } |
| 259 } | 258 } |
| 260 | 259 |
| 261 void PepperPlatformAudioInput::CloseDevice() { | 260 void PepperPlatformAudioInput::CloseDevice() { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 286 PepperMediaDeviceManager* PepperPlatformAudioInput::GetMediaDeviceManager() { | 285 PepperMediaDeviceManager* PepperPlatformAudioInput::GetMediaDeviceManager() { |
| 287 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); | 286 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); |
| 288 | 287 |
| 289 RenderFrameImpl* const render_frame = | 288 RenderFrameImpl* const render_frame = |
| 290 RenderFrameImpl::FromRoutingID(render_frame_id_); | 289 RenderFrameImpl::FromRoutingID(render_frame_id_); |
| 291 return render_frame ? | 290 return render_frame ? |
| 292 PepperMediaDeviceManager::GetForRenderFrame(render_frame).get() : NULL; | 291 PepperMediaDeviceManager::GetForRenderFrame(render_frame).get() : NULL; |
| 293 } | 292 } |
| 294 | 293 |
| 295 } // namespace content | 294 } // namespace content |
| OLD | NEW |