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

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: ready for review 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 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 } 96 }
97 } 97 }
98 } 98 }
99 99
100 void PepperPlatformAudioInputImpl::OnVolume(double volume) {} 100 void PepperPlatformAudioInputImpl::OnVolume(double volume) {}
101 101
102 void PepperPlatformAudioInputImpl::OnStateChanged( 102 void PepperPlatformAudioInputImpl::OnStateChanged(
103 media::AudioInputIPCDelegate::State state) { 103 media::AudioInputIPCDelegate::State state) {
104 } 104 }
105 105
106 void PepperPlatformAudioInputImpl::OnDeviceReady(const std::string& device_id) {
107 DCHECK(ChildProcess::current()->io_message_loop_proxy()->
108 BelongsToCurrentThread());
109
110 if (shutdown_called_)
111 return;
112
113 if (device_id.empty()) {
114 main_message_loop_proxy_->PostTask(
115 FROM_HERE,
116 base::Bind(&PepperPlatformAudioInputImpl::NotifyStreamCreationFailed,
117 this));
118 } else {
119 // We will be notified by OnStreamCreated().
120 ipc_->CreateStream(stream_id_, params_, device_id, false);
121 }
122 }
123
124 void PepperPlatformAudioInputImpl::OnIPCClosed() { 106 void PepperPlatformAudioInputImpl::OnIPCClosed() {
125 ipc_ = NULL; 107 ipc_ = NULL;
126 } 108 }
127 109
128 PepperPlatformAudioInputImpl::~PepperPlatformAudioInputImpl() { 110 PepperPlatformAudioInputImpl::~PepperPlatformAudioInputImpl() {
129 // Make sure we have been shut down. Warning: this may happen on the I/O 111 // Make sure we have been shut down. Warning: this may happen on the I/O
130 // thread! 112 // thread!
131 // Although these members should be accessed on a specific thread (either the 113 // Although these members should be accessed on a specific thread (either the
132 // main thread or the I/O thread), it should be fine to examine their value 114 // main thread or the I/O thread), it should be fine to examine their value
133 // here. 115 // here.
(...skipping 25 matching lines...) Expand all
159 141
160 plugin_delegate_ = plugin_delegate; 142 plugin_delegate_ = plugin_delegate;
161 render_view_id_ = plugin_delegate_->GetRoutingID(); 143 render_view_id_ = plugin_delegate_->GetRoutingID();
162 client_ = client; 144 client_ = client;
163 145
164 params_.Reset(media::AudioParameters::AUDIO_PCM_LINEAR, 146 params_.Reset(media::AudioParameters::AUDIO_PCM_LINEAR,
165 media::CHANNEL_LAYOUT_MONO, 0, 147 media::CHANNEL_LAYOUT_MONO, 0,
166 sample_rate, 16, frames_per_buffer); 148 sample_rate, 16, frames_per_buffer);
167 149
168 if (device_id.empty()) { 150 if (device_id.empty()) {
169 // Use the default device. 151 // TODO(xians): this bypasses the permission and create a stream using the
palmer 2013/03/12 17:45:11 Is that safe? (Doesn't sound safe.) Is this change
no longer working on chromium 2013/03/14 10:47:32 We allow pepper flash to use the default device wi
152 // default device, we should remove it once Pepper completely switches to
153 // OpenDevice().
170 ChildProcess::current()->io_message_loop()->PostTask( 154 ChildProcess::current()->io_message_loop()->PostTask(
171 FROM_HERE, 155 FROM_HERE,
172 base::Bind(&PepperPlatformAudioInputImpl::InitializeOnIOThread, 156 base::Bind(&PepperPlatformAudioInputImpl::InitializeOnIOThread,
173 this, 0)); 157 this, 1));
174 } else { 158 } else {
175 // We need to open the device and obtain the label and session ID before 159 // We need to open the device and obtain the label and session ID before
176 // initializing. 160 // initializing.
177 plugin_delegate_->OpenDevice( 161 plugin_delegate_->OpenDevice(
178 PP_DEVICETYPE_DEV_AUDIOCAPTURE, device_id, 162 PP_DEVICETYPE_DEV_AUDIOCAPTURE, device_id,
179 base::Bind(&PepperPlatformAudioInputImpl::OnDeviceOpened, this)); 163 base::Bind(&PepperPlatformAudioInputImpl::OnDeviceOpened, this));
180 } 164 }
181 return true; 165 return true;
182 } 166 }
183 167
184 void PepperPlatformAudioInputImpl::InitializeOnIOThread(int session_id) { 168 void PepperPlatformAudioInputImpl::InitializeOnIOThread(int session_id) {
185 DCHECK(ChildProcess::current()->io_message_loop_proxy()-> 169 DCHECK(ChildProcess::current()->io_message_loop_proxy()->
186 BelongsToCurrentThread()); 170 BelongsToCurrentThread());
187 171
188 if (shutdown_called_) 172 if (shutdown_called_)
189 return; 173 return;
190 174
191 // Make sure we don't call init more than once. 175 // Make sure we don't call init more than once.
192 DCHECK_EQ(0, stream_id_); 176 DCHECK_EQ(0, stream_id_);
193 stream_id_ = ipc_->AddDelegate(this); 177 stream_id_ = ipc_->AddDelegate(this);
194 DCHECK_NE(0, stream_id_); 178 DCHECK_NE(0, stream_id_);
195 179
196 if (!session_id) { 180 // We will be notified by OnStreamCreated().
197 // We will be notified by OnStreamCreated(). 181 ipc_->CreateStream(stream_id_, session_id, params_, false);
198 ipc_->CreateStream(stream_id_, params_,
199 media::AudioManagerBase::kDefaultDeviceId, false);
200 } else {
201 // We will be notified by OnDeviceReady().
202 ipc_->StartDevice(stream_id_, session_id);
203 }
204 } 182 }
205 183
206 void PepperPlatformAudioInputImpl::StartCaptureOnIOThread() { 184 void PepperPlatformAudioInputImpl::StartCaptureOnIOThread() {
207 DCHECK(ChildProcess::current()->io_message_loop_proxy()-> 185 DCHECK(ChildProcess::current()->io_message_loop_proxy()->
208 BelongsToCurrentThread()); 186 BelongsToCurrentThread());
209 187
210 if (stream_id_) { 188 if (stream_id_) {
211 ipc_->AssociateStreamWithConsumer(stream_id_, render_view_id_); 189 ipc_->AssociateStreamWithConsumer(stream_id_, render_view_id_);
212 ipc_->RecordStream(stream_id_); 190 ipc_->RecordStream(stream_id_);
213 } 191 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 } 258 }
281 259
282 void PepperPlatformAudioInputImpl::NotifyStreamCreationFailed() { 260 void PepperPlatformAudioInputImpl::NotifyStreamCreationFailed() {
283 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread()); 261 DCHECK(main_message_loop_proxy_->BelongsToCurrentThread());
284 262
285 if (client_) 263 if (client_)
286 client_->StreamCreationFailed(); 264 client_->StreamCreationFailed();
287 } 265 }
288 266
289 } // namespace content 267 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698