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

Side by Side Diff: content/renderer/pepper_plugin_delegate_impl.cc

Issue 8569003: Revert 110587 - Microphone support for Pepper Flash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 1 month 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
« no previous file with comments | « content/renderer/pepper_plugin_delegate_impl.h ('k') | ppapi/api/dev/ppb_audio_input_dev.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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_plugin_delegate_impl.h" 5 #include "content/renderer/pepper_plugin_delegate_impl.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <queue> 8 #include <queue>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 17 matching lines...) Expand all
28 #include "content/common/pepper_plugin_registry.h" 28 #include "content/common/pepper_plugin_registry.h"
29 #include "content/common/pepper_messages.h" 29 #include "content/common/pepper_messages.h"
30 #include "content/common/quota_dispatcher.h" 30 #include "content/common/quota_dispatcher.h"
31 #include "content/common/view_messages.h" 31 #include "content/common/view_messages.h"
32 #include "content/public/common/content_switches.h" 32 #include "content/public/common/content_switches.h"
33 #include "content/public/renderer/content_renderer_client.h" 33 #include "content/public/renderer/content_renderer_client.h"
34 #include "content/renderer/gpu/command_buffer_proxy.h" 34 #include "content/renderer/gpu/command_buffer_proxy.h"
35 #include "content/renderer/gpu/gpu_channel_host.h" 35 #include "content/renderer/gpu/gpu_channel_host.h"
36 #include "content/renderer/gpu/renderer_gl_context.h" 36 #include "content/renderer/gpu/renderer_gl_context.h"
37 #include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h" 37 #include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h"
38 #include "content/renderer/media/audio_input_message_filter.h"
39 #include "content/renderer/media/audio_message_filter.h" 38 #include "content/renderer/media/audio_message_filter.h"
40 #include "content/renderer/media/video_capture_impl_manager.h" 39 #include "content/renderer/media/video_capture_impl_manager.h"
41 #include "content/renderer/p2p/p2p_transport_impl.h" 40 #include "content/renderer/p2p/p2p_transport_impl.h"
42 #include "content/renderer/pepper_platform_context_3d_impl.h" 41 #include "content/renderer/pepper_platform_context_3d_impl.h"
43 #include "content/renderer/pepper_platform_video_decoder_impl.h" 42 #include "content/renderer/pepper_platform_video_decoder_impl.h"
44 #include "content/renderer/render_thread_impl.h" 43 #include "content/renderer/render_thread_impl.h"
45 #include "content/renderer/render_view_impl.h" 44 #include "content/renderer/render_view_impl.h"
46 #include "content/renderer/render_widget_fullscreen_pepper.h" 45 #include "content/renderer/render_widget_fullscreen_pepper.h"
47 #include "content/renderer/webplugin_delegate_proxy.h" 46 #include "content/renderer/webplugin_delegate_proxy.h"
48 #include "ipc/ipc_channel_handle.h" 47 #include "ipc/ipc_channel_handle.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 }; 163 };
165 164
166 165
167 class PlatformAudioImpl 166 class PlatformAudioImpl
168 : public webkit::ppapi::PluginDelegate::PlatformAudio, 167 : public webkit::ppapi::PluginDelegate::PlatformAudio,
169 public AudioMessageFilter::Delegate, 168 public AudioMessageFilter::Delegate,
170 public base::RefCountedThreadSafe<PlatformAudioImpl> { 169 public base::RefCountedThreadSafe<PlatformAudioImpl> {
171 public: 170 public:
172 PlatformAudioImpl() 171 PlatformAudioImpl()
173 : client_(NULL), stream_id_(0), 172 : client_(NULL), stream_id_(0),
174 main_message_loop_proxy_(base::MessageLoopProxy::current()) { 173 main_message_loop_(MessageLoop::current()) {
175 filter_ = RenderThreadImpl::current()->audio_message_filter(); 174 filter_ = RenderThreadImpl::current()->audio_message_filter();
176 } 175 }
177 176
178 virtual ~PlatformAudioImpl() { 177 virtual ~PlatformAudioImpl() {
179 // Make sure we have been shut down. Warning: this will usually happen on 178 // Make sure we have been shut down. Warning: this will usually happen on
180 // the I/O thread! 179 // the I/O thread!
181 DCHECK_EQ(0, stream_id_); 180 DCHECK_EQ(0, stream_id_);
182 DCHECK(!client_); 181 DCHECK(!client_);
183 } 182 }
184 183
185 // Initialize this audio context. StreamCreated() will be called when the 184 // Initialize this audio context. StreamCreated() will be called when the
186 // stream is created. 185 // stream is created.
187 bool Initialize(uint32_t sample_rate, uint32_t sample_count, 186 bool Initialize(uint32_t sample_rate, uint32_t sample_count,
188 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client); 187 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client);
189 188
190 // PlatformAudio implementation (called on main thread). 189 // PlatformAudio implementation (called on main thread).
191 virtual bool StartPlayback(); 190 virtual bool StartPlayback();
192 virtual bool StopPlayback(); 191 virtual bool StopPlayback();
193 virtual void ShutDown(); 192 virtual void ShutDown();
194 193
195 private: 194 private:
196 // I/O thread backends to above functions. 195 // I/O thread backends to above functions.
197 void InitializeOnIOThread(const AudioParameters& params); 196 void InitializeOnIOThread(const AudioParameters& params);
198 void StartPlaybackOnIOThread(); 197 void StartPlaybackOnIOThread();
(...skipping 11 matching lines...) Expand all
210 } 209 }
211 210
212 virtual void OnLowLatencyCreated(base::SharedMemoryHandle handle, 211 virtual void OnLowLatencyCreated(base::SharedMemoryHandle handle,
213 base::SyncSocket::Handle socket_handle, 212 base::SyncSocket::Handle socket_handle,
214 uint32 length); 213 uint32 length);
215 214
216 virtual void OnVolume(double volume) {} 215 virtual void OnVolume(double volume) {}
217 216
218 // The client to notify when the stream is created. THIS MUST ONLY BE 217 // The client to notify when the stream is created. THIS MUST ONLY BE
219 // ACCESSED ON THE MAIN THREAD. 218 // ACCESSED ON THE MAIN THREAD.
220 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client_; 219 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client_;
221 220
222 // MessageFilter used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE 221 // MessageFilter used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE
223 // I/O thread except to send messages and get the message loop. 222 // I/O thread except to send messages and get the message loop.
224 scoped_refptr<AudioMessageFilter> filter_; 223 scoped_refptr<AudioMessageFilter> filter_;
225 224
226 // Our ID on the MessageFilter. THIS MUST ONLY BE ACCESSED ON THE I/O THREAD 225 // Our ID on the MessageFilter. THIS MUST ONLY BE ACCESSED ON THE I/O THREAD
227 // or else you could race with the initialize function which sets it. 226 // or else you could race with the initialize function which sets it.
228 int32 stream_id_; 227 int32 stream_id_;
229 228
230 base::MessageLoopProxy* main_message_loop_proxy_; 229 MessageLoop* main_message_loop_;
231 230
232 DISALLOW_COPY_AND_ASSIGN(PlatformAudioImpl); 231 DISALLOW_COPY_AND_ASSIGN(PlatformAudioImpl);
233 }; 232 };
234 233
235 bool PlatformAudioImpl::Initialize( 234 bool PlatformAudioImpl::Initialize(
236 uint32_t sample_rate, uint32_t sample_count, 235 uint32_t sample_rate, uint32_t sample_count,
237 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client) { 236 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client) {
238 237
239 DCHECK(client); 238 DCHECK(client);
240 // Make sure we don't call init more than once. 239 // Make sure we don't call init more than once.
241 DCHECK_EQ(0, stream_id_); 240 DCHECK_EQ(0, stream_id_);
242 241
243 client_ = client; 242 client_ = client;
244 243
245 AudioParameters params; 244 AudioParameters params;
246 params.format = AudioParameters::AUDIO_PCM_LINEAR; 245 params.format = AudioParameters::AUDIO_PCM_LINEAR;
247 params.channels = 2; 246 params.channels = 2;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
318 uint32 length) { 317 uint32 length) {
319 #if defined(OS_WIN) 318 #if defined(OS_WIN)
320 DCHECK(handle); 319 DCHECK(handle);
321 DCHECK(socket_handle); 320 DCHECK(socket_handle);
322 #else 321 #else
323 DCHECK_NE(-1, handle.fd); 322 DCHECK_NE(-1, handle.fd);
324 DCHECK_NE(-1, socket_handle); 323 DCHECK_NE(-1, socket_handle);
325 #endif 324 #endif
326 DCHECK(length); 325 DCHECK(length);
327 326
328 if (base::MessageLoopProxy::current() == main_message_loop_proxy_) { 327 if (MessageLoop::current() == main_message_loop_) {
329 // Must dereference the client only on the main thread. Shutdown may have 328 // Must dereference the client only on the main thread. Shutdown may have
330 // occurred while the request was in-flight, so we need to NULL check. 329 // occurred while the request was in-flight, so we need to NULL check.
331 if (client_) 330 if (client_)
332 client_->StreamCreated(handle, length, socket_handle); 331 client_->StreamCreated(handle, length, socket_handle);
333 } else { 332 } else {
334 main_message_loop_proxy_->PostTask(FROM_HERE, 333 main_message_loop_->PostTask(FROM_HERE,
335 NewRunnableMethod(this, &PlatformAudioImpl::OnLowLatencyCreated, 334 NewRunnableMethod(this, &PlatformAudioImpl::OnLowLatencyCreated,
336 handle, socket_handle, length)); 335 handle, socket_handle, length));
337 } 336 }
338 } 337 }
339 338
340 class PlatformAudioInputImpl
341 : public webkit::ppapi::PluginDelegate::PlatformAudioInput,
342 public AudioInputMessageFilter::Delegate,
343 public base::RefCountedThreadSafe<PlatformAudioInputImpl> {
344 public:
345 PlatformAudioInputImpl()
346 : client_(NULL), stream_id_(0),
347 main_message_loop_proxy_(base::MessageLoopProxy::current()) {
348 filter_ = RenderThreadImpl::current()->audio_input_message_filter();
349 }
350
351 virtual ~PlatformAudioInputImpl() {
352 // Make sure we have been shut down. Warning: this will usually happen on
353 // the I/O thread!
354 DCHECK_EQ(0, stream_id_);
355 DCHECK(!client_);
356 }
357
358 // Initialize this audio context. StreamCreated() will be called when the
359 // stream is created.
360 bool Initialize(
361 uint32_t sample_rate, uint32_t sample_count,
362 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client);
363
364 // PlatformAudio implementation (called on main thread).
365 virtual bool StartCapture();
366 virtual bool StopCapture();
367 virtual void ShutDown();
368
369 private:
370 // I/O thread backends to above functions.
371 void InitializeOnIOThread(const AudioParameters& params);
372 void StartCaptureOnIOThread();
373 void StopCaptureOnIOThread();
374 void ShutDownOnIOThread();
375
376 virtual void OnLowLatencyCreated(base::SharedMemoryHandle handle,
377 base::SyncSocket::Handle socket_handle,
378 uint32 length);
379
380 virtual void OnVolume(double volume) {}
381
382 virtual void OnStateChanged(AudioStreamState state) {}
383
384 virtual void OnDeviceReady(int index) {}
385
386 // The client to notify when the stream is created. THIS MUST ONLY BE
387 // ACCESSED ON THE MAIN THREAD.
388 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client_;
389
390 // MessageFilter used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE
391 // I/O thread except to send messages and get the message loop.
392 scoped_refptr<AudioInputMessageFilter> filter_;
393
394 // Our ID on the MessageFilter. THIS MUST ONLY BE ACCESSED ON THE I/O THREAD
395 // or else you could race with the initialize function which sets it.
396 int32 stream_id_;
397
398 base::MessageLoopProxy* main_message_loop_proxy_;
399
400 DISALLOW_COPY_AND_ASSIGN(PlatformAudioInputImpl);
401 };
402
403 bool PlatformAudioInputImpl::Initialize(
404 uint32_t sample_rate, uint32_t sample_count,
405 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client) {
406 DCHECK(client);
407 // Make sure we don't call init more than once.
408 DCHECK_EQ(0, stream_id_);
409
410 client_ = client;
411
412 AudioParameters params;
413 params.format = AudioParameters::AUDIO_PCM_LINEAR;
414 params.channels = 1;
415 params.sample_rate = sample_rate;
416 params.bits_per_sample = 16;
417 params.samples_per_packet = sample_count;
418
419 ChildProcess::current()->io_message_loop()->PostTask(
420 FROM_HERE,
421 NewRunnableMethod(this, &PlatformAudioInputImpl::InitializeOnIOThread,
422 params));
423 return true;
424 }
425
426 bool PlatformAudioInputImpl::StartCapture() {
427 ChildProcess::current()->io_message_loop()->PostTask(
428 FROM_HERE,
429 NewRunnableMethod(this,
430 &PlatformAudioInputImpl::StartCaptureOnIOThread));
431 return true;
432 }
433
434 bool PlatformAudioInputImpl::StopCapture() {
435 ChildProcess::current()->io_message_loop()->PostTask(
436 FROM_HERE,
437 NewRunnableMethod(this,
438 &PlatformAudioInputImpl::StopCaptureOnIOThread));
439 return true;
440 }
441
442 void PlatformAudioInputImpl::ShutDown() {
443 // Called on the main thread to stop all audio callbacks. We must only change
444 // the client on the main thread, and the delegates from the I/O thread.
445 client_ = NULL;
446 ChildProcess::current()->io_message_loop()->PostTask(
447 FROM_HERE,
448 base::Bind(&PlatformAudioInputImpl::ShutDownOnIOThread, this));
449 }
450
451 void PlatformAudioInputImpl::InitializeOnIOThread(
452 const AudioParameters& params) {
453 stream_id_ = filter_->AddDelegate(this);
454 filter_->Send(new AudioInputHostMsg_CreateStream(stream_id_, params, true));
455 }
456
457 void PlatformAudioInputImpl::StartCaptureOnIOThread() {
458 if (stream_id_)
459 filter_->Send(new AudioInputHostMsg_RecordStream(stream_id_));
460 }
461
462 void PlatformAudioInputImpl::StopCaptureOnIOThread() {
463 if (stream_id_)
464 filter_->Send(new AudioInputHostMsg_CloseStream(stream_id_));
465 }
466
467 void PlatformAudioInputImpl::ShutDownOnIOThread() {
468 // Make sure we don't call shutdown more than once.
469 if (!stream_id_)
470 return;
471
472 filter_->Send(new AudioInputHostMsg_CloseStream(stream_id_));
473 filter_->RemoveDelegate(stream_id_);
474 stream_id_ = 0;
475
476 Release(); // Release for the delegate, balances out the reference taken in
477 // PepperPluginDelegateImpl::CreateAudioInput.
478 }
479
480 void PlatformAudioInputImpl::OnLowLatencyCreated(
481 base::SharedMemoryHandle handle,
482 base::SyncSocket::Handle socket_handle,
483 uint32 length) {
484
485 #if defined(OS_WIN)
486 DCHECK(handle);
487 DCHECK(socket_handle);
488 #else
489 DCHECK_NE(-1, handle.fd);
490 DCHECK_NE(-1, socket_handle);
491 #endif
492 DCHECK(length);
493
494 if (base::MessageLoopProxy::current() == main_message_loop_proxy_) {
495 // Must dereference the client only on the main thread. Shutdown may have
496 // occurred while the request was in-flight, so we need to NULL check.
497 if (client_)
498 client_->StreamCreated(handle, length, socket_handle);
499 } else {
500 main_message_loop_proxy_->PostTask(FROM_HERE,
501 NewRunnableMethod(this, &PlatformAudioInputImpl::OnLowLatencyCreated,
502 handle, socket_handle, length));
503 }
504 }
505
506 class DispatcherDelegate : public ppapi::proxy::ProxyChannel::Delegate { 339 class DispatcherDelegate : public ppapi::proxy::ProxyChannel::Delegate {
507 public: 340 public:
508 virtual ~DispatcherDelegate() {} 341 virtual ~DispatcherDelegate() {}
509 342
510 // ProxyChannel::Delegate implementation. 343 // ProxyChannel::Delegate implementation.
511 virtual base::MessageLoopProxy* GetIPCMessageLoop() { 344 virtual base::MessageLoopProxy* GetIPCMessageLoop() {
512 // This is called only in the renderer so we know we have a child process. 345 // This is called only in the renderer so we know we have a child process.
513 DCHECK(ChildProcess::current()) << "Must be in the renderer."; 346 DCHECK(ChildProcess::current()) << "Must be in the renderer.";
514 return ChildProcess::current()->io_message_loop_proxy(); 347 return ChildProcess::current()->io_message_loop_proxy();
515 } 348 }
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 } 1080 }
1248 1081
1249 void PepperPluginDelegateImpl::SelectedFindResultChanged(int identifier, 1082 void PepperPluginDelegateImpl::SelectedFindResultChanged(int identifier,
1250 int index) { 1083 int index) {
1251 render_view_->reportFindInPageSelection( 1084 render_view_->reportFindInPageSelection(
1252 identifier, index + 1, WebKit::WebRect()); 1085 identifier, index + 1, WebKit::WebRect());
1253 } 1086 }
1254 1087
1255 webkit::ppapi::PluginDelegate::PlatformAudio* 1088 webkit::ppapi::PluginDelegate::PlatformAudio*
1256 PepperPluginDelegateImpl::CreateAudio( 1089 PepperPluginDelegateImpl::CreateAudio(
1257 uint32_t sample_rate, 1090 uint32_t sample_rate, uint32_t sample_count,
1258 uint32_t sample_count, 1091 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client) {
1259 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client) {
1260 scoped_refptr<PlatformAudioImpl> audio(new PlatformAudioImpl()); 1092 scoped_refptr<PlatformAudioImpl> audio(new PlatformAudioImpl());
1261 if (audio->Initialize(sample_rate, sample_count, client)) { 1093 if (audio->Initialize(sample_rate, sample_count, client)) {
1262 // Balanced by Release invoked in PlatformAudioImpl::ShutDownOnIOThread(). 1094 // Balanced by Release invoked in PlatformAudioImpl::ShutDownOnIOThread().
1263 return audio.release(); 1095 return audio.release();
1264 } else { 1096 } else {
1265 return NULL; 1097 return NULL;
1266 } 1098 }
1267 } 1099 }
1268 1100
1269 webkit::ppapi::PluginDelegate::PlatformAudioInput*
1270 PepperPluginDelegateImpl::CreateAudioInput(
1271 uint32_t sample_rate,
1272 uint32_t sample_count,
1273 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client) {
1274 scoped_refptr<PlatformAudioInputImpl>
1275 audio_input(new PlatformAudioInputImpl());
1276 if (audio_input->Initialize(sample_rate, sample_count, client)) {
1277 // Balanced by Release invoked in
1278 // PlatformAudioInputImpl::ShutDownOnIOThread().
1279 return audio_input.release();
1280 }
1281 return NULL;
1282 }
1283
1284 // If a broker has not already been created for this plugin, creates one. 1101 // If a broker has not already been created for this plugin, creates one.
1285 webkit::ppapi::PluginDelegate::PpapiBroker* 1102 webkit::ppapi::PluginDelegate::PpapiBroker*
1286 PepperPluginDelegateImpl::ConnectToPpapiBroker( 1103 PepperPluginDelegateImpl::ConnectToPpapiBroker(
1287 webkit::ppapi::PPB_Broker_Impl* client) { 1104 webkit::ppapi::PPB_Broker_Impl* client) {
1288 CHECK(client); 1105 CHECK(client);
1289 1106
1290 // If a broker needs to be created, this will ensure it does not get deleted 1107 // If a broker needs to be created, this will ensure it does not get deleted
1291 // before Connect() adds a reference. 1108 // before Connect() adds a reference.
1292 scoped_refptr<PpapiBrokerImpl> broker_impl; 1109 scoped_refptr<PpapiBrokerImpl> broker_impl;
1293 1110
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
1937 if (!context) 1754 if (!context)
1938 return NULL; 1755 return NULL;
1939 if (!context->makeContextCurrent() || context->isContextLost()) 1756 if (!context->makeContextCurrent() || context->isContextLost())
1940 return NULL; 1757 return NULL;
1941 1758
1942 RendererGLContext* parent_context = context->context(); 1759 RendererGLContext* parent_context = context->context();
1943 if (!parent_context) 1760 if (!parent_context)
1944 return NULL; 1761 return NULL;
1945 return parent_context; 1762 return parent_context;
1946 } 1763 }
OLDNEW
« no previous file with comments | « content/renderer/pepper_plugin_delegate_impl.h ('k') | ppapi/api/dev/ppb_audio_input_dev.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698