| 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/location.h" | 8 #include "base/location.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/single_thread_task_runner.h" | 10 #include "base/single_thread_task_runner.h" |
| 11 #include "base/threading/thread_task_runner_handle.h" | 11 #include "base/threading/thread_task_runner_handle.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "content/child/child_process.h" | 13 #include "content/child/child_process.h" |
| 14 #include "content/renderer/media/audio_input_message_filter.h" | 14 #include "content/renderer/media/audio_input_message_filter.h" |
| 15 #include "content/renderer/pepper/pepper_audio_input_host.h" | 15 #include "content/renderer/pepper/pepper_audio_input_host.h" |
| 16 #include "content/renderer/pepper/pepper_media_device_manager.h" | 16 #include "content/renderer/pepper/pepper_media_device_manager.h" |
| 17 #include "content/renderer/render_frame_impl.h" | 17 #include "content/renderer/render_frame_impl.h" |
| 18 #include "content/renderer/render_thread_impl.h" | 18 #include "content/renderer/render_thread_impl.h" |
| 19 #include "content/renderer/render_view_impl.h" | 19 #include "content/renderer/render_view_impl.h" |
| 20 #include "media/audio/audio_device_description.h" | 20 #include "media/audio/audio_device_description.h" |
| 21 #include "ppapi/shared_impl/ppb_audio_config_shared.h" | 21 #include "ppapi/shared_impl/ppb_audio_config_shared.h" |
| 22 #include "url/gurl.h" | |
| 23 | 22 |
| 24 namespace content { | 23 namespace content { |
| 25 | 24 |
| 26 // static | 25 // static |
| 27 PepperPlatformAudioInput* PepperPlatformAudioInput::Create( | 26 PepperPlatformAudioInput* PepperPlatformAudioInput::Create( |
| 28 int render_frame_id, | 27 int render_frame_id, |
| 29 const std::string& device_id, | 28 const std::string& device_id, |
| 30 const GURL& document_url, | |
| 31 int sample_rate, | 29 int sample_rate, |
| 32 int frames_per_buffer, | 30 int frames_per_buffer, |
| 33 PepperAudioInputHost* client) { | 31 PepperAudioInputHost* client) { |
| 34 scoped_refptr<PepperPlatformAudioInput> audio_input( | 32 scoped_refptr<PepperPlatformAudioInput> audio_input( |
| 35 new PepperPlatformAudioInput()); | 33 new PepperPlatformAudioInput()); |
| 36 if (audio_input->Initialize(render_frame_id, | 34 if (audio_input->Initialize(render_frame_id, |
| 37 device_id, | 35 device_id, |
| 38 document_url, | |
| 39 sample_rate, | 36 sample_rate, |
| 40 frames_per_buffer, | 37 frames_per_buffer, |
| 41 client)) { | 38 client)) { |
| 42 // Balanced by Release invoked in | 39 // Balanced by Release invoked in |
| 43 // PepperPlatformAudioInput::ShutDownOnIOThread(). | 40 // PepperPlatformAudioInput::ShutDownOnIOThread(). |
| 44 audio_input->AddRef(); | 41 audio_input->AddRef(); |
| 45 return audio_input.get(); | 42 return audio_input.get(); |
| 46 } | 43 } |
| 47 return NULL; | 44 return NULL; |
| 48 } | 45 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 io_task_runner_(ChildProcess::current()->io_task_runner()), | 132 io_task_runner_(ChildProcess::current()->io_task_runner()), |
| 136 render_frame_id_(MSG_ROUTING_NONE), | 133 render_frame_id_(MSG_ROUTING_NONE), |
| 137 create_stream_sent_(false), | 134 create_stream_sent_(false), |
| 138 pending_open_device_(false), | 135 pending_open_device_(false), |
| 139 pending_open_device_id_(-1) { | 136 pending_open_device_id_(-1) { |
| 140 } | 137 } |
| 141 | 138 |
| 142 bool PepperPlatformAudioInput::Initialize( | 139 bool PepperPlatformAudioInput::Initialize( |
| 143 int render_frame_id, | 140 int render_frame_id, |
| 144 const std::string& device_id, | 141 const std::string& device_id, |
| 145 const GURL& document_url, | |
| 146 int sample_rate, | 142 int sample_rate, |
| 147 int frames_per_buffer, | 143 int frames_per_buffer, |
| 148 PepperAudioInputHost* client) { | 144 PepperAudioInputHost* client) { |
| 149 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 145 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 150 | 146 |
| 151 RenderFrameImpl* const render_frame = | 147 RenderFrameImpl* const render_frame = |
| 152 RenderFrameImpl::FromRoutingID(render_frame_id); | 148 RenderFrameImpl::FromRoutingID(render_frame_id); |
| 153 if (!render_frame || !client) | 149 if (!render_frame || !client) |
| 154 return false; | 150 return false; |
| 155 | 151 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 168 sample_rate, | 164 sample_rate, |
| 169 ppapi::kBitsPerAudioInputSample, | 165 ppapi::kBitsPerAudioInputSample, |
| 170 frames_per_buffer); | 166 frames_per_buffer); |
| 171 | 167 |
| 172 // We need to open the device and obtain the label and session ID before | 168 // We need to open the device and obtain the label and session ID before |
| 173 // initializing. | 169 // initializing. |
| 174 pending_open_device_id_ = GetMediaDeviceManager()->OpenDevice( | 170 pending_open_device_id_ = GetMediaDeviceManager()->OpenDevice( |
| 175 PP_DEVICETYPE_DEV_AUDIOCAPTURE, | 171 PP_DEVICETYPE_DEV_AUDIOCAPTURE, |
| 176 device_id.empty() ? media::AudioDeviceDescription::kDefaultDeviceId | 172 device_id.empty() ? media::AudioDeviceDescription::kDefaultDeviceId |
| 177 : device_id, | 173 : device_id, |
| 178 document_url, | 174 client->pp_instance(), |
| 179 base::Bind(&PepperPlatformAudioInput::OnDeviceOpened, this)); | 175 base::Bind(&PepperPlatformAudioInput::OnDeviceOpened, this)); |
| 180 pending_open_device_ = true; | 176 pending_open_device_ = true; |
| 181 | 177 |
| 182 return true; | 178 return true; |
| 183 } | 179 } |
| 184 | 180 |
| 185 void PepperPlatformAudioInput::InitializeOnIOThread(int session_id) { | 181 void PepperPlatformAudioInput::InitializeOnIOThread(int session_id) { |
| 186 DCHECK(io_task_runner_->BelongsToCurrentThread()); | 182 DCHECK(io_task_runner_->BelongsToCurrentThread()); |
| 187 | 183 |
| 188 if (!ipc_) | 184 if (!ipc_) |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 278 PepperMediaDeviceManager* PepperPlatformAudioInput::GetMediaDeviceManager() { | 274 PepperMediaDeviceManager* PepperPlatformAudioInput::GetMediaDeviceManager() { |
| 279 DCHECK(main_task_runner_->BelongsToCurrentThread()); | 275 DCHECK(main_task_runner_->BelongsToCurrentThread()); |
| 280 | 276 |
| 281 RenderFrameImpl* const render_frame = | 277 RenderFrameImpl* const render_frame = |
| 282 RenderFrameImpl::FromRoutingID(render_frame_id_); | 278 RenderFrameImpl::FromRoutingID(render_frame_id_); |
| 283 return render_frame ? | 279 return render_frame ? |
| 284 PepperMediaDeviceManager::GetForRenderFrame(render_frame).get() : NULL; | 280 PepperMediaDeviceManager::GetForRenderFrame(render_frame).get() : NULL; |
| 285 } | 281 } |
| 286 | 282 |
| 287 } // namespace content | 283 } // namespace content |
| OLD | NEW |