OLD | NEW |
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 16 matching lines...) Expand all Loading... |
27 #include "content/common/pepper_file_messages.h" | 27 #include "content/common/pepper_file_messages.h" |
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/renderer/content_renderer_client.h" | 32 #include "content/public/renderer/content_renderer_client.h" |
33 #include "content/renderer/gpu/command_buffer_proxy.h" | 33 #include "content/renderer/gpu/command_buffer_proxy.h" |
34 #include "content/renderer/gpu/gpu_channel_host.h" | 34 #include "content/renderer/gpu/gpu_channel_host.h" |
35 #include "content/renderer/gpu/renderer_gl_context.h" | 35 #include "content/renderer/gpu/renderer_gl_context.h" |
36 #include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h" | 36 #include "content/renderer/gpu/webgraphicscontext3d_command_buffer_impl.h" |
| 37 #include "content/renderer/media/audio_input_message_filter.h" |
37 #include "content/renderer/media/audio_message_filter.h" | 38 #include "content/renderer/media/audio_message_filter.h" |
38 #include "content/renderer/media/video_capture_impl_manager.h" | 39 #include "content/renderer/media/video_capture_impl_manager.h" |
39 #include "content/renderer/p2p/p2p_transport_impl.h" | 40 #include "content/renderer/p2p/p2p_transport_impl.h" |
40 #include "content/renderer/pepper_platform_context_3d_impl.h" | 41 #include "content/renderer/pepper_platform_context_3d_impl.h" |
41 #include "content/renderer/pepper_platform_video_decoder_impl.h" | 42 #include "content/renderer/pepper_platform_video_decoder_impl.h" |
42 #include "content/renderer/render_thread.h" | 43 #include "content/renderer/render_thread.h" |
43 #include "content/renderer/render_view.h" | 44 #include "content/renderer/render_view.h" |
44 #include "content/renderer/render_widget_fullscreen_pepper.h" | 45 #include "content/renderer/render_widget_fullscreen_pepper.h" |
45 #include "content/renderer/webplugin_delegate_proxy.h" | 46 #include "content/renderer/webplugin_delegate_proxy.h" |
46 #include "ipc/ipc_channel_handle.h" | 47 #include "ipc/ipc_channel_handle.h" |
| 48 #include "media/base/channel_layout.h" |
47 #include "media/video/capture/video_capture_proxy.h" | 49 #include "media/video/capture/video_capture_proxy.h" |
48 #include "ppapi/c/dev/pp_video_dev.h" | 50 #include "ppapi/c/dev/pp_video_dev.h" |
49 #include "ppapi/c/pp_errors.h" | 51 #include "ppapi/c/pp_errors.h" |
50 #include "ppapi/c/private/ppb_flash.h" | 52 #include "ppapi/c/private/ppb_flash.h" |
51 #include "ppapi/c/private/ppb_flash_net_connector.h" | 53 #include "ppapi/c/private/ppb_flash_net_connector.h" |
52 #include "ppapi/proxy/host_dispatcher.h" | 54 #include "ppapi/proxy/host_dispatcher.h" |
53 #include "ppapi/proxy/ppapi_messages.h" | 55 #include "ppapi/proxy/ppapi_messages.h" |
54 #include "ppapi/shared_impl/ppapi_preferences.h" | 56 #include "ppapi/shared_impl/ppapi_preferences.h" |
55 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" | 57 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
56 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserComplet
ion.h" | 58 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFileChooserComplet
ion.h" |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 // 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. |
329 if (client_) | 331 if (client_) |
330 client_->StreamCreated(handle, length, socket_handle); | 332 client_->StreamCreated(handle, length, socket_handle); |
331 } else { | 333 } else { |
332 main_message_loop_->PostTask(FROM_HERE, | 334 main_message_loop_->PostTask(FROM_HERE, |
333 NewRunnableMethod(this, &PlatformAudioImpl::OnLowLatencyCreated, | 335 NewRunnableMethod(this, &PlatformAudioImpl::OnLowLatencyCreated, |
334 handle, socket_handle, length)); | 336 handle, socket_handle, length)); |
335 } | 337 } |
336 } | 338 } |
337 | 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_(MessageLoop::current()) { |
| 348 filter_ = RenderThread::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::PlatformAudioInput::Client* 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::PlatformAudioInput::Client* 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 MessageLoop* main_message_loop_; |
| 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::PlatformAudioInput::Client* 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 NewRunnableMethod(this, &PlatformAudioInputImpl::ShutDownOnIOThread)); |
| 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 (MessageLoop::current() == main_message_loop_) { |
| 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_->PostTask(FROM_HERE, |
| 501 NewRunnableMethod(this, &PlatformAudioInputImpl::OnLowLatencyCreated, |
| 502 handle, socket_handle, length)); |
| 503 } |
| 504 } |
| 505 |
338 class DispatcherDelegate : public ppapi::proxy::ProxyChannel::Delegate { | 506 class DispatcherDelegate : public ppapi::proxy::ProxyChannel::Delegate { |
339 public: | 507 public: |
340 virtual ~DispatcherDelegate() {} | 508 virtual ~DispatcherDelegate() {} |
341 | 509 |
342 // ProxyChannel::Delegate implementation. | 510 // ProxyChannel::Delegate implementation. |
343 virtual base::MessageLoopProxy* GetIPCMessageLoop() { | 511 virtual base::MessageLoopProxy* GetIPCMessageLoop() { |
344 // 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. |
345 DCHECK(ChildProcess::current()) << "Must be in the renderer."; | 513 DCHECK(ChildProcess::current()) << "Must be in the renderer."; |
346 return ChildProcess::current()->io_message_loop_proxy(); | 514 return ChildProcess::current()->io_message_loop_proxy(); |
347 } | 515 } |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client) { | 1147 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client) { |
980 scoped_refptr<PlatformAudioImpl> audio(new PlatformAudioImpl()); | 1148 scoped_refptr<PlatformAudioImpl> audio(new PlatformAudioImpl()); |
981 if (audio->Initialize(sample_rate, sample_count, client)) { | 1149 if (audio->Initialize(sample_rate, sample_count, client)) { |
982 // Balanced by Release invoked in PlatformAudioImpl::ShutDownOnIOThread(). | 1150 // Balanced by Release invoked in PlatformAudioImpl::ShutDownOnIOThread(). |
983 return audio.release(); | 1151 return audio.release(); |
984 } else { | 1152 } else { |
985 return NULL; | 1153 return NULL; |
986 } | 1154 } |
987 } | 1155 } |
988 | 1156 |
| 1157 webkit::ppapi::PluginDelegate::PlatformAudioInput* |
| 1158 PepperPluginDelegateImpl::CreateAudioInput( |
| 1159 uint32_t sample_rate, uint32_t sample_count, |
| 1160 webkit::ppapi::PluginDelegate::PlatformAudioInput::Client* client) { |
| 1161 scoped_refptr<PlatformAudioInputImpl> |
| 1162 audio_input(new PlatformAudioInputImpl()); |
| 1163 if (audio_input->Initialize(sample_rate, sample_count, client)) { |
| 1164 // Balanced by Release invoked in |
| 1165 // PlatformAudioInputImpl::ShutDownOnIOThread(). |
| 1166 return audio_input.release(); |
| 1167 } |
| 1168 return NULL; |
| 1169 } |
| 1170 |
| 1171 |
989 // If a broker has not already been created for this plugin, creates one. | 1172 // If a broker has not already been created for this plugin, creates one. |
990 webkit::ppapi::PluginDelegate::PpapiBroker* | 1173 webkit::ppapi::PluginDelegate::PpapiBroker* |
991 PepperPluginDelegateImpl::ConnectToPpapiBroker( | 1174 PepperPluginDelegateImpl::ConnectToPpapiBroker( |
992 webkit::ppapi::PPB_Broker_Impl* client) { | 1175 webkit::ppapi::PPB_Broker_Impl* client) { |
993 CHECK(client); | 1176 CHECK(client); |
994 | 1177 |
995 // If a broker needs to be created, this will ensure it does not get deleted | 1178 // If a broker needs to be created, this will ensure it does not get deleted |
996 // before Connect() adds a reference. | 1179 // before Connect() adds a reference. |
997 scoped_refptr<PpapiBrokerImpl> broker_impl; | 1180 scoped_refptr<PpapiBrokerImpl> broker_impl; |
998 | 1181 |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1616 | 1799 |
1617 int PepperPluginDelegateImpl::GetRoutingId() const { | 1800 int PepperPluginDelegateImpl::GetRoutingId() const { |
1618 return render_view_->routing_id(); | 1801 return render_view_->routing_id(); |
1619 } | 1802 } |
1620 | 1803 |
1621 void PepperPluginDelegateImpl::PublishInitialPolicy( | 1804 void PepperPluginDelegateImpl::PublishInitialPolicy( |
1622 scoped_refptr<webkit::ppapi::PluginInstance> instance, | 1805 scoped_refptr<webkit::ppapi::PluginInstance> instance, |
1623 const std::string& policy) { | 1806 const std::string& policy) { |
1624 instance->HandlePolicyUpdate(policy); | 1807 instance->HandlePolicyUpdate(policy); |
1625 } | 1808 } |
OLD | NEW |