Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(113)

Side by Side Diff: content/renderer/pepper/pepper_platform_audio_input_impl.cc

Issue 12440027: Do not pass the string device_id via IPC message to create an audio input stream (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: addressed palmer's comments Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 25 matching lines...) Expand all
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, 0, 150 media::CHANNEL_LAYOUT_MONO, 0,
169 sample_rate, 16, frames_per_buffer); 151 sample_rate, 16, frames_per_buffer);
170 152
171 if (device_id.empty()) { 153 if (device_id.empty()) {
172 // Use the default device. 154 // TODO(xians): this bypasses the permission and create a stream using the
palmer 2013/03/14 21:05:14 NIT: Grammar and punctuation. "This bypasses... a
no longer working on chromium 2013/03/15 14:52:11 Done.
155 // default device, we should remove it once Pepper completely switches to
156 // OpenDevice().
173 ChildProcess::current()->io_message_loop()->PostTask( 157 ChildProcess::current()->io_message_loop()->PostTask(
174 FROM_HERE, 158 FROM_HERE,
175 base::Bind(&PepperPlatformAudioInputImpl::InitializeOnIOThread, 159 base::Bind(&PepperPlatformAudioInputImpl::InitializeOnIOThread,
176 this, 0)); 160 this, 1));
177 } else { 161 } else {
178 // We need to open the device and obtain the label and session ID before 162 // We need to open the device and obtain the label and session ID before
179 // initializing. 163 // initializing.
180 plugin_delegate_->OpenDevice( 164 plugin_delegate_->OpenDevice(
181 PP_DEVICETYPE_DEV_AUDIOCAPTURE, device_id, 165 PP_DEVICETYPE_DEV_AUDIOCAPTURE, device_id,
182 base::Bind(&PepperPlatformAudioInputImpl::OnDeviceOpened, this)); 166 base::Bind(&PepperPlatformAudioInputImpl::OnDeviceOpened, this));
183 } 167 }
184 return true; 168 return true;
185 } 169 }
186 170
187 void PepperPlatformAudioInputImpl::InitializeOnIOThread(int session_id) { 171 void PepperPlatformAudioInputImpl::InitializeOnIOThread(int session_id) {
188 DCHECK(ChildProcess::current()->io_message_loop_proxy()-> 172 DCHECK(ChildProcess::current()->io_message_loop_proxy()->
189 BelongsToCurrentThread()); 173 BelongsToCurrentThread());
190 174
191 if (shutdown_called_) 175 if (shutdown_called_)
192 return; 176 return;
193 177
194 // Make sure we don't call init more than once. 178 // Make sure we don't call init more than once.
195 DCHECK_EQ(0, stream_id_); 179 DCHECK_EQ(0, stream_id_);
196 stream_id_ = ipc_->AddDelegate(this); 180 stream_id_ = ipc_->AddDelegate(this);
197 DCHECK_NE(0, stream_id_); 181 DCHECK_NE(0, stream_id_);
198 182
199 if (!session_id) { 183 // We will be notified by OnStreamCreated().
200 // We will be notified by OnStreamCreated(). 184 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 } 185 }
208 186
209 void PepperPlatformAudioInputImpl::StartCaptureOnIOThread() { 187 void PepperPlatformAudioInputImpl::StartCaptureOnIOThread() {
210 DCHECK(ChildProcess::current()->io_message_loop_proxy()-> 188 DCHECK(ChildProcess::current()->io_message_loop_proxy()->
211 BelongsToCurrentThread()); 189 BelongsToCurrentThread());
212 190
213 if (stream_id_) { 191 if (stream_id_) {
214 ipc_->AssociateStreamWithConsumer(stream_id_, render_view_id_); 192 ipc_->AssociateStreamWithConsumer(stream_id_, render_view_id_);
215 ipc_->RecordStream(stream_id_); 193 ipc_->RecordStream(stream_id_);
216 } 194 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 } 261 }
284 262
285 void PepperPlatformAudioInputImpl::NotifyStreamCreationFailed() { 263 void PepperPlatformAudioInputImpl::NotifyStreamCreationFailed() {
286 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); 264 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread());
287 265
288 if (client_) 266 if (client_)
289 client_->StreamCreationFailed(); 267 client_->StreamCreationFailed();
290 } 268 }
291 269
292 } // namespace content 270 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698