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" |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 } | 99 } |
100 } | 100 } |
101 } | 101 } |
102 | 102 |
103 void PepperPlatformAudioInputImpl::OnVolume(double volume) {} | 103 void PepperPlatformAudioInputImpl::OnVolume(double volume) {} |
104 | 104 |
105 void PepperPlatformAudioInputImpl::OnStateChanged( | 105 void PepperPlatformAudioInputImpl::OnStateChanged( |
106 media::AudioInputIPCDelegate::State state) { | 106 media::AudioInputIPCDelegate::State state) { |
107 } | 107 } |
108 | 108 |
109 void PepperPlatformAudioInputImpl::OnDeviceReady(const std::string& device_id) { | |
110 DCHECK(ChildProcess::current()->io_message_loop_proxy()-> | |
111 BelongsToCurrentThread()); | |
112 | |
113 if (shutdown_called_) | |
114 return; | |
115 | |
116 if (device_id.empty()) { | |
117 main_message_loop_proxy_->PostTask( | |
118 FROM_HERE, | |
119 base::Bind(&PepperPlatformAudioInputImpl::NotifyStreamCreationFailed, | |
120 this)); | |
121 } else { | |
122 // We will be notified by OnStreamCreated(). | |
123 ipc_->CreateStream(stream_id_, params_, device_id, false, 1); | |
124 } | |
125 } | |
126 | |
127 void PepperPlatformAudioInputImpl::OnIPCClosed() { | 109 void PepperPlatformAudioInputImpl::OnIPCClosed() { |
128 ipc_ = NULL; | 110 ipc_ = NULL; |
129 } | 111 } |
130 | 112 |
131 PepperPlatformAudioInputImpl::~PepperPlatformAudioInputImpl() { | 113 PepperPlatformAudioInputImpl::~PepperPlatformAudioInputImpl() { |
132 // Make sure we have been shut down. Warning: this may happen on the I/O | 114 // Make sure we have been shut down. Warning: this may happen on the I/O |
133 // thread! | 115 // thread! |
134 // Although these members should be accessed on a specific thread (either the | 116 // Although these members should be accessed on a specific thread (either the |
135 // main thread or the I/O thread), it should be fine to examine their value | 117 // main thread or the I/O thread), it should be fine to examine their value |
136 // here. | 118 // here. |
(...skipping 24 matching lines...) Expand all Loading... |
161 return false; | 143 return false; |
162 | 144 |
163 plugin_delegate_ = plugin_delegate; | 145 plugin_delegate_ = plugin_delegate; |
164 render_view_id_ = plugin_delegate_->GetRoutingID(); | 146 render_view_id_ = plugin_delegate_->GetRoutingID(); |
165 client_ = client; | 147 client_ = client; |
166 | 148 |
167 params_.Reset(media::AudioParameters::AUDIO_PCM_LINEAR, | 149 params_.Reset(media::AudioParameters::AUDIO_PCM_LINEAR, |
168 media::CHANNEL_LAYOUT_MONO, 1, 0, | 150 media::CHANNEL_LAYOUT_MONO, 1, 0, |
169 sample_rate, 16, frames_per_buffer); | 151 sample_rate, 16, frames_per_buffer); |
170 | 152 |
171 if (device_id.empty()) { | 153 // We need to open the device and obtain the label and session ID before |
172 // Use the default device. | 154 // initializing. |
173 ChildProcess::current()->io_message_loop()->PostTask( | 155 plugin_delegate_->OpenDevice( |
174 FROM_HERE, | 156 PP_DEVICETYPE_DEV_AUDIOCAPTURE, |
175 base::Bind(&PepperPlatformAudioInputImpl::InitializeOnIOThread, | 157 device_id.empty() ? media::AudioManagerBase::kDefaultDeviceId : device_id, |
176 this, 0)); | 158 base::Bind(&PepperPlatformAudioInputImpl::OnDeviceOpened, this)); |
177 } else { | 159 |
178 // We need to open the device and obtain the label and session ID before | |
179 // initializing. | |
180 plugin_delegate_->OpenDevice( | |
181 PP_DEVICETYPE_DEV_AUDIOCAPTURE, device_id, | |
182 base::Bind(&PepperPlatformAudioInputImpl::OnDeviceOpened, this)); | |
183 } | |
184 return true; | 160 return true; |
185 } | 161 } |
186 | 162 |
187 void PepperPlatformAudioInputImpl::InitializeOnIOThread(int session_id) { | 163 void PepperPlatformAudioInputImpl::InitializeOnIOThread(int session_id) { |
188 DCHECK(ChildProcess::current()->io_message_loop_proxy()-> | 164 DCHECK(ChildProcess::current()->io_message_loop_proxy()-> |
189 BelongsToCurrentThread()); | 165 BelongsToCurrentThread()); |
190 | 166 |
191 if (shutdown_called_) | 167 if (shutdown_called_) |
192 return; | 168 return; |
193 | 169 |
194 // Make sure we don't call init more than once. | 170 // Make sure we don't call init more than once. |
195 DCHECK_EQ(0, stream_id_); | 171 DCHECK_EQ(0, stream_id_); |
196 stream_id_ = ipc_->AddDelegate(this); | 172 stream_id_ = ipc_->AddDelegate(this); |
197 DCHECK_NE(0, stream_id_); | 173 DCHECK_NE(0, stream_id_); |
198 | 174 |
199 if (!session_id) { | 175 // We will be notified by OnStreamCreated(). |
200 // We will be notified by OnStreamCreated(). | 176 ipc_->CreateStream(stream_id_, session_id, params_, false, 1); |
201 ipc_->CreateStream(stream_id_, params_, | |
202 media::AudioManagerBase::kDefaultDeviceId, false, 1); | |
203 } else { | |
204 // We will be notified by OnDeviceReady(). | |
205 ipc_->StartDevice(stream_id_, session_id); | |
206 } | |
207 } | 177 } |
208 | 178 |
209 void PepperPlatformAudioInputImpl::StartCaptureOnIOThread() { | 179 void PepperPlatformAudioInputImpl::StartCaptureOnIOThread() { |
210 DCHECK(ChildProcess::current()->io_message_loop_proxy()-> | 180 DCHECK(ChildProcess::current()->io_message_loop_proxy()-> |
211 BelongsToCurrentThread()); | 181 BelongsToCurrentThread()); |
212 | 182 |
213 if (stream_id_) { | 183 if (stream_id_) { |
214 ipc_->AssociateStreamWithConsumer(stream_id_, render_view_id_); | 184 ipc_->AssociateStreamWithConsumer(stream_id_, render_view_id_); |
215 ipc_->RecordStream(stream_id_); | 185 ipc_->RecordStream(stream_id_); |
216 } | 186 } |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 } | 253 } |
284 | 254 |
285 void PepperPlatformAudioInputImpl::NotifyStreamCreationFailed() { | 255 void PepperPlatformAudioInputImpl::NotifyStreamCreationFailed() { |
286 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); | 256 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); |
287 | 257 |
288 if (client_) | 258 if (client_) |
289 client_->StreamCreationFailed(); | 259 client_->StreamCreationFailed(); |
290 } | 260 } |
291 | 261 |
292 } // namespace content | 262 } // namespace content |
OLD | NEW |