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

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

Issue 8574029: Microphone support for Pepper Flash. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: MessageLoop -> base::MessageLoopProxy 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
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"
38 #include "content/renderer/media/audio_message_filter.h" 39 #include "content/renderer/media/audio_message_filter.h"
39 #include "content/renderer/media/video_capture_impl_manager.h" 40 #include "content/renderer/media/video_capture_impl_manager.h"
40 #include "content/renderer/p2p/p2p_transport_impl.h" 41 #include "content/renderer/p2p/p2p_transport_impl.h"
41 #include "content/renderer/pepper_platform_context_3d_impl.h" 42 #include "content/renderer/pepper_platform_context_3d_impl.h"
42 #include "content/renderer/pepper_platform_video_decoder_impl.h" 43 #include "content/renderer/pepper_platform_video_decoder_impl.h"
43 #include "content/renderer/render_thread_impl.h" 44 #include "content/renderer/render_thread_impl.h"
44 #include "content/renderer/render_view_impl.h" 45 #include "content/renderer/render_view_impl.h"
45 #include "content/renderer/render_widget_fullscreen_pepper.h" 46 #include "content/renderer/render_widget_fullscreen_pepper.h"
46 #include "content/renderer/webplugin_delegate_proxy.h" 47 #include "content/renderer/webplugin_delegate_proxy.h"
47 #include "ipc/ipc_channel_handle.h" 48 #include "ipc/ipc_channel_handle.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 }; 164 };
164 165
165 166
166 class PlatformAudioImpl 167 class PlatformAudioImpl
167 : public webkit::ppapi::PluginDelegate::PlatformAudio, 168 : public webkit::ppapi::PluginDelegate::PlatformAudio,
168 public AudioMessageFilter::Delegate, 169 public AudioMessageFilter::Delegate,
169 public base::RefCountedThreadSafe<PlatformAudioImpl> { 170 public base::RefCountedThreadSafe<PlatformAudioImpl> {
170 public: 171 public:
171 PlatformAudioImpl() 172 PlatformAudioImpl()
172 : client_(NULL), stream_id_(0), 173 : client_(NULL), stream_id_(0),
173 main_message_loop_(MessageLoop::current()) { 174 main_message_loop_proxy_(base::MessageLoopProxy::current()) {
174 filter_ = RenderThreadImpl::current()->audio_message_filter(); 175 filter_ = RenderThreadImpl::current()->audio_message_filter();
175 } 176 }
176 177
177 virtual ~PlatformAudioImpl() { 178 virtual ~PlatformAudioImpl() {
178 // Make sure we have been shut down. Warning: this will usually happen on 179 // Make sure we have been shut down. Warning: this will usually happen on
179 // the I/O thread! 180 // the I/O thread!
180 DCHECK_EQ(0, stream_id_); 181 DCHECK_EQ(0, stream_id_);
181 DCHECK(!client_); 182 DCHECK(!client_);
182 } 183 }
183 184
184 // Initialize this audio context. StreamCreated() will be called when the 185 // Initialize this audio context. StreamCreated() will be called when the
185 // stream is created. 186 // stream is created.
186 bool Initialize(uint32_t sample_rate, uint32_t sample_count, 187 bool Initialize(uint32_t sample_rate, uint32_t sample_count,
187 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client); 188 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client);
188 189
189 // PlatformAudio implementation (called on main thread). 190 // PlatformAudio implementation (called on main thread).
190 virtual bool StartPlayback(); 191 virtual bool StartPlayback();
191 virtual bool StopPlayback(); 192 virtual bool StopPlayback();
192 virtual void ShutDown(); 193 virtual void ShutDown();
193 194
194 private: 195 private:
195 // I/O thread backends to above functions. 196 // I/O thread backends to above functions.
196 void InitializeOnIOThread(const AudioParameters& params); 197 void InitializeOnIOThread(const AudioParameters& params);
197 void StartPlaybackOnIOThread(); 198 void StartPlaybackOnIOThread();
(...skipping 11 matching lines...) Expand all
209 } 210 }
210 211
211 virtual void OnLowLatencyCreated(base::SharedMemoryHandle handle, 212 virtual void OnLowLatencyCreated(base::SharedMemoryHandle handle,
212 base::SyncSocket::Handle socket_handle, 213 base::SyncSocket::Handle socket_handle,
213 uint32 length); 214 uint32 length);
214 215
215 virtual void OnVolume(double volume) {} 216 virtual void OnVolume(double volume) {}
216 217
217 // The client to notify when the stream is created. THIS MUST ONLY BE 218 // The client to notify when the stream is created. THIS MUST ONLY BE
218 // ACCESSED ON THE MAIN THREAD. 219 // ACCESSED ON THE MAIN THREAD.
219 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client_; 220 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client_;
220 221
221 // MessageFilter used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE 222 // MessageFilter used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE
222 // I/O thread except to send messages and get the message loop. 223 // I/O thread except to send messages and get the message loop.
223 scoped_refptr<AudioMessageFilter> filter_; 224 scoped_refptr<AudioMessageFilter> filter_;
224 225
225 // Our ID on the MessageFilter. THIS MUST ONLY BE ACCESSED ON THE I/O THREAD 226 // Our ID on the MessageFilter. THIS MUST ONLY BE ACCESSED ON THE I/O THREAD
226 // or else you could race with the initialize function which sets it. 227 // or else you could race with the initialize function which sets it.
227 int32 stream_id_; 228 int32 stream_id_;
228 229
229 MessageLoop* main_message_loop_; 230 base::MessageLoopProxy* main_message_loop_proxy_;
230 231
231 DISALLOW_COPY_AND_ASSIGN(PlatformAudioImpl); 232 DISALLOW_COPY_AND_ASSIGN(PlatformAudioImpl);
232 }; 233 };
233 234
234 bool PlatformAudioImpl::Initialize( 235 bool PlatformAudioImpl::Initialize(
235 uint32_t sample_rate, uint32_t sample_count, 236 uint32_t sample_rate, uint32_t sample_count,
236 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client) { 237 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client) {
237 238
238 DCHECK(client); 239 DCHECK(client);
239 // Make sure we don't call init more than once. 240 // Make sure we don't call init more than once.
240 DCHECK_EQ(0, stream_id_); 241 DCHECK_EQ(0, stream_id_);
241 242
242 client_ = client; 243 client_ = client;
243 244
244 AudioParameters params; 245 AudioParameters params;
245 params.format = AudioParameters::AUDIO_PCM_LINEAR; 246 params.format = AudioParameters::AUDIO_PCM_LINEAR;
246 params.channels = 2; 247 params.channels = 2;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 uint32 length) { 318 uint32 length) {
318 #if defined(OS_WIN) 319 #if defined(OS_WIN)
319 DCHECK(handle); 320 DCHECK(handle);
320 DCHECK(socket_handle); 321 DCHECK(socket_handle);
321 #else 322 #else
322 DCHECK_NE(-1, handle.fd); 323 DCHECK_NE(-1, handle.fd);
323 DCHECK_NE(-1, socket_handle); 324 DCHECK_NE(-1, socket_handle);
324 #endif 325 #endif
325 DCHECK(length); 326 DCHECK(length);
326 327
327 if (MessageLoop::current() == main_message_loop_) { 328 if (base::MessageLoopProxy::current() == main_message_loop_proxy_) {
328 // Must dereference the client only on the main thread. Shutdown may have 329 // Must dereference the client only on the main thread. Shutdown may have
329 // occurred while the request was in-flight, so we need to NULL check. 330 // occurred while the request was in-flight, so we need to NULL check.
330 if (client_) 331 if (client_)
331 client_->StreamCreated(handle, length, socket_handle); 332 client_->StreamCreated(handle, length, socket_handle);
332 } else { 333 } else {
333 main_message_loop_->PostTask(FROM_HERE, 334 main_message_loop_proxy_->PostTask(FROM_HERE,
334 NewRunnableMethod(this, &PlatformAudioImpl::OnLowLatencyCreated, 335 NewRunnableMethod(this, &PlatformAudioImpl::OnLowLatencyCreated,
335 handle, socket_handle, length)); 336 handle, socket_handle, length));
336 } 337 }
337 } 338 }
338 339
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();
dmichael (off chromium) 2011/11/17 04:05:21 OVERRIDE?
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
339 class DispatcherDelegate : public ppapi::proxy::ProxyChannel::Delegate { 506 class DispatcherDelegate : public ppapi::proxy::ProxyChannel::Delegate {
340 public: 507 public:
341 virtual ~DispatcherDelegate() {} 508 virtual ~DispatcherDelegate() {}
342 509
343 // ProxyChannel::Delegate implementation. 510 // ProxyChannel::Delegate implementation.
344 virtual base::MessageLoopProxy* GetIPCMessageLoop() { 511 virtual base::MessageLoopProxy* GetIPCMessageLoop() {
345 // This is called only in the renderer so we know we have a child process. 512 // This is called only in the renderer so we know we have a child process.
346 DCHECK(ChildProcess::current()) << "Must be in the renderer."; 513 DCHECK(ChildProcess::current()) << "Must be in the renderer.";
347 return ChildProcess::current()->io_message_loop_proxy(); 514 return ChildProcess::current()->io_message_loop_proxy();
348 } 515 }
(...skipping 731 matching lines...) Expand 10 before | Expand all | Expand 10 after
1080 } 1247 }
1081 1248
1082 void PepperPluginDelegateImpl::SelectedFindResultChanged(int identifier, 1249 void PepperPluginDelegateImpl::SelectedFindResultChanged(int identifier,
1083 int index) { 1250 int index) {
1084 render_view_->reportFindInPageSelection( 1251 render_view_->reportFindInPageSelection(
1085 identifier, index + 1, WebKit::WebRect()); 1252 identifier, index + 1, WebKit::WebRect());
1086 } 1253 }
1087 1254
1088 webkit::ppapi::PluginDelegate::PlatformAudio* 1255 webkit::ppapi::PluginDelegate::PlatformAudio*
1089 PepperPluginDelegateImpl::CreateAudio( 1256 PepperPluginDelegateImpl::CreateAudio(
1090 uint32_t sample_rate, uint32_t sample_count, 1257 uint32_t sample_rate,
1091 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client) { 1258 uint32_t sample_count,
1259 webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client) {
1092 scoped_refptr<PlatformAudioImpl> audio(new PlatformAudioImpl()); 1260 scoped_refptr<PlatformAudioImpl> audio(new PlatformAudioImpl());
1093 if (audio->Initialize(sample_rate, sample_count, client)) { 1261 if (audio->Initialize(sample_rate, sample_count, client)) {
1094 // Balanced by Release invoked in PlatformAudioImpl::ShutDownOnIOThread(). 1262 // Balanced by Release invoked in PlatformAudioImpl::ShutDownOnIOThread().
1095 return audio.release(); 1263 return audio.release();
1096 } else { 1264 } else {
1097 return NULL; 1265 return NULL;
1098 } 1266 }
1099 } 1267 }
1100 1268
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
1101 // If a broker has not already been created for this plugin, creates one. 1284 // If a broker has not already been created for this plugin, creates one.
1102 webkit::ppapi::PluginDelegate::PpapiBroker* 1285 webkit::ppapi::PluginDelegate::PpapiBroker*
1103 PepperPluginDelegateImpl::ConnectToPpapiBroker( 1286 PepperPluginDelegateImpl::ConnectToPpapiBroker(
1104 webkit::ppapi::PPB_Broker_Impl* client) { 1287 webkit::ppapi::PPB_Broker_Impl* client) {
1105 CHECK(client); 1288 CHECK(client);
1106 1289
1107 // If a broker needs to be created, this will ensure it does not get deleted 1290 // If a broker needs to be created, this will ensure it does not get deleted
1108 // before Connect() adds a reference. 1291 // before Connect() adds a reference.
1109 scoped_refptr<PpapiBrokerImpl> broker_impl; 1292 scoped_refptr<PpapiBrokerImpl> broker_impl;
1110 1293
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
1754 if (!context) 1937 if (!context)
1755 return NULL; 1938 return NULL;
1756 if (!context->makeContextCurrent() || context->isContextLost()) 1939 if (!context->makeContextCurrent() || context->isContextLost())
1757 return NULL; 1940 return NULL;
1758 1941
1759 RendererGLContext* parent_context = context->context(); 1942 RendererGLContext* parent_context = context->context();
1760 if (!parent_context) 1943 if (!parent_context)
1761 return NULL; 1944 return NULL;
1762 return parent_context; 1945 return parent_context;
1763 } 1946 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698