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 17 matching lines...) Expand all Loading... |
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_message_filter.h" | 37 #include "content/renderer/media/audio_message_filter.h" |
| 38 #include "content/renderer/media/audio_input_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" |
47 #include "media/video/capture/video_capture_proxy.h" | 48 #include "media/video/capture/video_capture_proxy.h" |
(...skipping 280 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. | 329 // occurred while the request was in-flight, so we need to NULL check. |
329 if (client_) | 330 if (client_) |
330 client_->StreamCreated(handle, length, socket_handle); | 331 client_->StreamCreated(handle, length, socket_handle); |
331 } else { | 332 } else { |
332 main_message_loop_->PostTask(FROM_HERE, | 333 main_message_loop_->PostTask(FROM_HERE, |
333 NewRunnableMethod(this, &PlatformAudioImpl::OnLowLatencyCreated, | 334 NewRunnableMethod(this, &PlatformAudioImpl::OnLowLatencyCreated, |
334 handle, socket_handle, length)); | 335 handle, socket_handle, length)); |
335 } | 336 } |
336 } | 337 } |
337 | 338 |
| 339 class PlatformAudioInputImpl |
| 340 : public webkit::ppapi::PluginDelegate::PlatformAudioInput, |
| 341 public AudioInputMessageFilter::Delegate, |
| 342 public base::RefCountedThreadSafe<PlatformAudioInputImpl> { |
| 343 public: |
| 344 PlatformAudioInputImpl() |
| 345 : client_(NULL), stream_id_(0), |
| 346 main_message_loop_(MessageLoop::current()) { |
| 347 //pbbb - add |
| 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(webkit::ppapi::PluginDelegate::PlatformAudioInput::Client* cli
ent); |
| 361 |
| 362 // PlatformAudio implementation (called on main thread). |
| 363 virtual bool StartCapture(); |
| 364 virtual bool StopCapture(); |
| 365 virtual void ShutDown(); |
| 366 |
| 367 private: |
| 368 // I/O thread backends to above functions. |
| 369 void InitializeOnIOThread(const AudioParameters& params); |
| 370 void StartCaptureOnIOThread(); |
| 371 void StopCaptureOnIOThread(); |
| 372 void ShutDownOnIOThread(); |
| 373 |
| 374 virtual void OnLowLatencyCreated(base::SharedMemoryHandle handle, |
| 375 base::SyncSocket::Handle socket_handle, |
| 376 uint32 length); |
| 377 |
| 378 virtual void OnVolume(double volume) {} |
| 379 |
| 380 virtual void OnStateChanged(AudioStreamState state) {} |
| 381 |
| 382 //pbbb need to add |
| 383 virtual void OnDeviceReady(int index) {}; |
| 384 |
| 385 // The client to notify when the stream is created. THIS MUST ONLY BE |
| 386 // ACCESSED ON THE MAIN THREAD. |
| 387 webkit::ppapi::PluginDelegate::PlatformAudioInput::Client* client_; |
| 388 |
| 389 // MessageFilter used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE |
| 390 // I/O thread except to send messages and get the message loop. |
| 391 scoped_refptr<AudioInputMessageFilter> filter_; |
| 392 |
| 393 // Our ID on the MessageFilter. THIS MUST ONLY BE ACCESSED ON THE I/O THREAD |
| 394 // or else you could race with the initialize function which sets it. |
| 395 int32 stream_id_; |
| 396 |
| 397 MessageLoop* main_message_loop_; |
| 398 |
| 399 DISALLOW_COPY_AND_ASSIGN(PlatformAudioInputImpl); |
| 400 }; |
| 401 |
| 402 bool PlatformAudioInputImpl::Initialize( |
| 403 webkit::ppapi::PluginDelegate::PlatformAudioInput::Client* client) { |
| 404 |
| 405 DCHECK(client); |
| 406 // Make sure we don't call init more than once. |
| 407 DCHECK_EQ(0, stream_id_); |
| 408 |
| 409 client_ = client; |
| 410 |
| 411 AudioParameters params; |
| 412 params.format = AudioParameters::AUDIO_PCM_LINEAR; |
| 413 params.channels = 2; |
| 414 //pbbb4 params.sample_rate = sample_rate; |
| 415 params.sample_rate = 44100; |
| 416 params.bits_per_sample = 16; |
| 417 // params.samples_per_packet = sample_count; |
| 418 params.samples_per_packet = 2048; |
| 419 |
| 420 ChildProcess::current()->io_message_loop()->PostTask( |
| 421 FROM_HERE, |
| 422 NewRunnableMethod(this, &PlatformAudioInputImpl::InitializeOnIOThread, |
| 423 params)); |
| 424 return true; |
| 425 } |
| 426 |
| 427 bool PlatformAudioInputImpl::StartCapture() { |
| 428 if (filter_) { |
| 429 ChildProcess::current()->io_message_loop()->PostTask( |
| 430 FROM_HERE, |
| 431 NewRunnableMethod(this, &PlatformAudioInputImpl::StartCaptureOnIOThread)
); |
| 432 return true; |
| 433 } |
| 434 return false; |
| 435 } |
| 436 |
| 437 bool PlatformAudioInputImpl::StopCapture() { |
| 438 if (filter_) { |
| 439 ChildProcess::current()->io_message_loop()->PostTask( |
| 440 FROM_HERE, |
| 441 NewRunnableMethod(this, &PlatformAudioInputImpl::StopCaptureOnIOThread))
; |
| 442 return true; |
| 443 } |
| 444 return false; |
| 445 } |
| 446 |
| 447 void PlatformAudioInputImpl::ShutDown() { |
| 448 // Called on the main thread to stop all audio callbacks. We must only change |
| 449 // the client on the main thread, and the delegates from the I/O thread. |
| 450 client_ = NULL; |
| 451 ChildProcess::current()->io_message_loop()->PostTask( |
| 452 FROM_HERE, |
| 453 NewRunnableMethod(this, &PlatformAudioInputImpl::ShutDownOnIOThread)); |
| 454 } |
| 455 |
| 456 void PlatformAudioInputImpl::InitializeOnIOThread(const AudioParameters& params)
{ |
| 457 stream_id_ = filter_->AddDelegate(this); |
| 458 filter_->Send(new AudioInputHostMsg_CreateStream(stream_id_, params, true)); |
| 459 } |
| 460 |
| 461 void PlatformAudioInputImpl::StartCaptureOnIOThread() { |
| 462 if (stream_id_) |
| 463 filter_->Send(new AudioInputHostMsg_RecordStream(stream_id_)); |
| 464 } |
| 465 |
| 466 void PlatformAudioInputImpl::StopCaptureOnIOThread() { |
| 467 if (stream_id_) |
| 468 filter_->Send(new AudioInputHostMsg_CloseStream(stream_id_)); |
| 469 } |
| 470 |
| 471 void PlatformAudioInputImpl::ShutDownOnIOThread() { |
| 472 // Make sure we don't call shutdown more than once. |
| 473 if (!stream_id_) |
| 474 return; |
| 475 |
| 476 filter_->Send(new AudioInputHostMsg_CloseStream(stream_id_)); |
| 477 filter_->RemoveDelegate(stream_id_); |
| 478 stream_id_ = 0; |
| 479 |
| 480 Release(); // Release for the delegate, balances out the reference taken in |
| 481 // PepperPluginDelegateImpl::CreateAudioInput. |
| 482 } |
| 483 |
| 484 void PlatformAudioInputImpl::OnLowLatencyCreated( |
| 485 base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle, |
| 486 uint32 length) { |
| 487 |
| 488 #if defined(OS_WIN) |
| 489 DCHECK(handle); |
| 490 DCHECK(socket_handle); |
| 491 #else |
| 492 DCHECK_NE(-1, handle.fd); |
| 493 DCHECK_NE(-1, socket_handle); |
| 494 #endif |
| 495 DCHECK(length); |
| 496 |
| 497 if (MessageLoop::current() == main_message_loop_) { |
| 498 // Must dereference the client only on the main thread. Shutdown may have |
| 499 // occurred while the request was in-flight, so we need to NULL check. |
| 500 if (client_) |
| 501 client_->StreamCreated(handle, length, socket_handle); |
| 502 } else { |
| 503 main_message_loop_->PostTask(FROM_HERE, |
| 504 NewRunnableMethod(this, &PlatformAudioInputImpl::OnLowLatencyCreated, |
| 505 handle, socket_handle, length)); |
| 506 } |
| 507 } |
| 508 |
338 class DispatcherDelegate : public ppapi::proxy::ProxyChannel::Delegate { | 509 class DispatcherDelegate : public ppapi::proxy::ProxyChannel::Delegate { |
339 public: | 510 public: |
340 virtual ~DispatcherDelegate() {} | 511 virtual ~DispatcherDelegate() {} |
341 | 512 |
342 // ProxyChannel::Delegate implementation. | 513 // ProxyChannel::Delegate implementation. |
343 virtual base::MessageLoopProxy* GetIPCMessageLoop() { | 514 virtual base::MessageLoopProxy* GetIPCMessageLoop() { |
344 // This is called only in the renderer so we know we have a child process. | 515 // This is called only in the renderer so we know we have a child process. |
345 DCHECK(ChildProcess::current()) << "Must be in the renderer."; | 516 DCHECK(ChildProcess::current()) << "Must be in the renderer."; |
346 return ChildProcess::current()->io_message_loop_proxy(); | 517 return ChildProcess::current()->io_message_loop_proxy(); |
347 } | 518 } |
(...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
979 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client) { | 1150 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client) { |
980 scoped_refptr<PlatformAudioImpl> audio(new PlatformAudioImpl()); | 1151 scoped_refptr<PlatformAudioImpl> audio(new PlatformAudioImpl()); |
981 if (audio->Initialize(sample_rate, sample_count, client)) { | 1152 if (audio->Initialize(sample_rate, sample_count, client)) { |
982 // Balanced by Release invoked in PlatformAudioImpl::ShutDownOnIOThread(). | 1153 // Balanced by Release invoked in PlatformAudioImpl::ShutDownOnIOThread(). |
983 return audio.release(); | 1154 return audio.release(); |
984 } else { | 1155 } else { |
985 return NULL; | 1156 return NULL; |
986 } | 1157 } |
987 } | 1158 } |
988 | 1159 |
| 1160 webkit::ppapi::PluginDelegate::PlatformAudioInput* |
| 1161 PepperPluginDelegateImpl::CreateAudioInput( |
| 1162 webkit::ppapi::PluginDelegate::PlatformAudioInput::Client* client) { |
| 1163 scoped_refptr<PlatformAudioInputImpl> audio_input(new PlatformAudioInputImpl()
); |
| 1164 if (audio_input->Initialize(client)) { |
| 1165 // Balanced by Release invoked in PlatformAudioInputImpl::ShutDownOnIOThread
(). |
| 1166 return audio_input.release(); |
| 1167 } else { |
| 1168 return NULL; |
| 1169 } |
| 1170 return NULL; |
| 1171 } |
| 1172 |
| 1173 |
989 // If a broker has not already been created for this plugin, creates one. | 1174 // If a broker has not already been created for this plugin, creates one. |
990 webkit::ppapi::PluginDelegate::PpapiBroker* | 1175 webkit::ppapi::PluginDelegate::PpapiBroker* |
991 PepperPluginDelegateImpl::ConnectToPpapiBroker( | 1176 PepperPluginDelegateImpl::ConnectToPpapiBroker( |
992 webkit::ppapi::PPB_Broker_Impl* client) { | 1177 webkit::ppapi::PPB_Broker_Impl* client) { |
993 CHECK(client); | 1178 CHECK(client); |
994 | 1179 |
995 // If a broker needs to be created, this will ensure it does not get deleted | 1180 // If a broker needs to be created, this will ensure it does not get deleted |
996 // before Connect() adds a reference. | 1181 // before Connect() adds a reference. |
997 scoped_refptr<PpapiBrokerImpl> broker_impl; | 1182 scoped_refptr<PpapiBrokerImpl> broker_impl; |
998 | 1183 |
(...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1616 | 1801 |
1617 int PepperPluginDelegateImpl::GetRoutingId() const { | 1802 int PepperPluginDelegateImpl::GetRoutingId() const { |
1618 return render_view_->routing_id(); | 1803 return render_view_->routing_id(); |
1619 } | 1804 } |
1620 | 1805 |
1621 void PepperPluginDelegateImpl::PublishInitialPolicy( | 1806 void PepperPluginDelegateImpl::PublishInitialPolicy( |
1622 scoped_refptr<webkit::ppapi::PluginInstance> instance, | 1807 scoped_refptr<webkit::ppapi::PluginInstance> instance, |
1623 const std::string& policy) { | 1808 const std::string& policy) { |
1624 instance->HandlePolicyUpdate(policy); | 1809 instance->HandlePolicyUpdate(policy); |
1625 } | 1810 } |
OLD | NEW |