Chromium Code Reviews| 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 filter_ = RenderThread::current()->audio_input_message_filter(); | |
| 348 } | |
| 349 | |
| 350 virtual ~PlatformAudioInputImpl() { | |
| 351 // Make sure we have been shut down. Warning: this will usually happen on | |
| 352 // the I/O thread! | |
| 353 DCHECK_EQ(0, stream_id_); | |
| 354 DCHECK(!client_); | |
| 355 } | |
| 356 | |
| 357 // Initialize this audio context. StreamCreated() will be called when the | |
| 358 // stream is created. | |
| 359 bool Initialize( | |
| 360 webkit::ppapi::PluginDelegate::PlatformAudioInput::Client* client); | |
|
brettw
2011/10/12 19:33:13
Should be indented only 4 spaces
| |
| 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 //TODO(peterb) need to add | |
|
brettw
2011/10/12 20:39:34
This should be cleaned up or clarified.
| |
| 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 DCHECK(client); | |
| 405 // Make sure we don't call init more than once. | |
| 406 DCHECK_EQ(0, stream_id_); | |
| 407 | |
| 408 client_ = client; | |
| 409 | |
| 410 //TODO(peterb) figure out the params to use | |
|
brettw
2011/10/12 20:39:34
Did you figure out the proper params? Can this be
| |
| 411 AudioParameters params; | |
| 412 params.format = AudioParameters::AUDIO_PCM_LINEAR; | |
| 413 params.channels = 2; | |
| 414 //peterb params.sample_rate = sample_rate; | |
| 415 params.sample_rate = 44100; //peterb PP_AUDIOSAMPLERATE_44100; | |
| 416 params.bits_per_sample = 16; | |
| 417 //peterb 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_) { | |
|
brettw
2011/10/12 20:39:34
I don't think this can be NULL. I notice the exist
| |
| 429 ChildProcess::current()->io_message_loop()->PostTask( | |
| 430 FROM_HERE, | |
| 431 NewRunnableMethod(this, | |
| 432 &PlatformAudioInputImpl::StartCaptureOnIOThread)); | |
| 433 return true; | |
| 434 } | |
| 435 return false; | |
| 436 } | |
| 437 | |
| 438 bool PlatformAudioInputImpl::StopCapture() { | |
| 439 if (filter_) { | |
| 440 ChildProcess::current()->io_message_loop()->PostTask( | |
| 441 FROM_HERE, | |
| 442 NewRunnableMethod(this, | |
| 443 &PlatformAudioInputImpl::StopCaptureOnIOThread)); | |
| 444 return true; | |
| 445 } | |
| 446 return false; | |
| 447 } | |
| 448 | |
| 449 void PlatformAudioInputImpl::ShutDown() { | |
| 450 // Called on the main thread to stop all audio callbacks. We must only change | |
| 451 // the client on the main thread, and the delegates from the I/O thread. | |
| 452 client_ = NULL; | |
| 453 ChildProcess::current()->io_message_loop()->PostTask( | |
| 454 FROM_HERE, | |
| 455 NewRunnableMethod(this, &PlatformAudioInputImpl::ShutDownOnIOThread)); | |
| 456 } | |
| 457 | |
| 458 void PlatformAudioInputImpl::InitializeOnIOThread( | |
| 459 const AudioParameters& params) { | |
|
brettw
2011/10/12 19:33:13
Only 4 space indent.
| |
| 460 stream_id_ = filter_->AddDelegate(this); | |
| 461 filter_->Send(new AudioInputHostMsg_CreateStream(stream_id_, params, true)); | |
| 462 } | |
| 463 | |
| 464 void PlatformAudioInputImpl::StartCaptureOnIOThread() { | |
| 465 if (stream_id_) | |
| 466 filter_->Send(new AudioInputHostMsg_RecordStream(stream_id_)); | |
| 467 } | |
| 468 | |
| 469 void PlatformAudioInputImpl::StopCaptureOnIOThread() { | |
| 470 if (stream_id_) | |
| 471 filter_->Send(new AudioInputHostMsg_CloseStream(stream_id_)); | |
| 472 } | |
| 473 | |
| 474 void PlatformAudioInputImpl::ShutDownOnIOThread() { | |
| 475 // Make sure we don't call shutdown more than once. | |
| 476 if (!stream_id_) | |
| 477 return; | |
| 478 | |
| 479 filter_->Send(new AudioInputHostMsg_CloseStream(stream_id_)); | |
| 480 filter_->RemoveDelegate(stream_id_); | |
| 481 stream_id_ = 0; | |
| 482 | |
| 483 Release(); // Release for the delegate, balances out the reference taken in | |
| 484 // PepperPluginDelegateImpl::CreateAudioInput. | |
| 485 } | |
| 486 | |
| 487 void PlatformAudioInputImpl::OnLowLatencyCreated( | |
| 488 base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle, | |
|
brettw
2011/10/12 20:39:34
Style nit: I usually try to put each param on a se
| |
| 489 uint32 length) { | |
| 490 | |
| 491 #if defined(OS_WIN) | |
| 492 DCHECK(handle); | |
| 493 DCHECK(socket_handle); | |
| 494 #else | |
| 495 DCHECK_NE(-1, handle.fd); | |
| 496 DCHECK_NE(-1, socket_handle); | |
| 497 #endif | |
| 498 DCHECK(length); | |
| 499 | |
| 500 if (MessageLoop::current() == main_message_loop_) { | |
| 501 // Must dereference the client only on the main thread. Shutdown may have | |
| 502 // occurred while the request was in-flight, so we need to NULL check. | |
| 503 if (client_) | |
| 504 client_->StreamCreated(handle, length, socket_handle); | |
| 505 } else { | |
| 506 main_message_loop_->PostTask(FROM_HERE, | |
| 507 NewRunnableMethod(this, &PlatformAudioInputImpl::OnLowLatencyCreated, | |
| 508 handle, socket_handle, length)); | |
| 509 } | |
| 510 } | |
| 511 | |
| 338 class DispatcherDelegate : public ppapi::proxy::ProxyChannel::Delegate { | 512 class DispatcherDelegate : public ppapi::proxy::ProxyChannel::Delegate { |
| 339 public: | 513 public: |
| 340 virtual ~DispatcherDelegate() {} | 514 virtual ~DispatcherDelegate() {} |
| 341 | 515 |
| 342 // ProxyChannel::Delegate implementation. | 516 // ProxyChannel::Delegate implementation. |
| 343 virtual base::MessageLoopProxy* GetIPCMessageLoop() { | 517 virtual base::MessageLoopProxy* GetIPCMessageLoop() { |
| 344 // This is called only in the renderer so we know we have a child process. | 518 // This is called only in the renderer so we know we have a child process. |
| 345 DCHECK(ChildProcess::current()) << "Must be in the renderer."; | 519 DCHECK(ChildProcess::current()) << "Must be in the renderer."; |
| 346 return ChildProcess::current()->io_message_loop_proxy(); | 520 return ChildProcess::current()->io_message_loop_proxy(); |
| 347 } | 521 } |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 979 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client) { | 1153 webkit::ppapi::PluginDelegate::PlatformAudio::Client* client) { |
| 980 scoped_refptr<PlatformAudioImpl> audio(new PlatformAudioImpl()); | 1154 scoped_refptr<PlatformAudioImpl> audio(new PlatformAudioImpl()); |
| 981 if (audio->Initialize(sample_rate, sample_count, client)) { | 1155 if (audio->Initialize(sample_rate, sample_count, client)) { |
| 982 // Balanced by Release invoked in PlatformAudioImpl::ShutDownOnIOThread(). | 1156 // Balanced by Release invoked in PlatformAudioImpl::ShutDownOnIOThread(). |
| 983 return audio.release(); | 1157 return audio.release(); |
| 984 } else { | 1158 } else { |
| 985 return NULL; | 1159 return NULL; |
| 986 } | 1160 } |
| 987 } | 1161 } |
| 988 | 1162 |
| 1163 webkit::ppapi::PluginDelegate::PlatformAudioInput* | |
| 1164 PepperPluginDelegateImpl::CreateAudioInput( | |
| 1165 webkit::ppapi::PluginDelegate::PlatformAudioInput::Client* client) { | |
| 1166 scoped_refptr<PlatformAudioInputImpl> | |
| 1167 audio_input(new PlatformAudioInputImpl()); | |
|
brettw
2011/10/12 19:33:13
4 space indent.
| |
| 1168 if (audio_input->Initialize(client)) { | |
| 1169 // Balanced by Release invoked in | |
| 1170 // PlatformAudioInputImpl::ShutDownOnIOThread(). | |
| 1171 return audio_input.release(); | |
| 1172 } else { | |
|
brettw
2011/10/12 20:39:34
I'd just delete this else condition and use the re
| |
| 1173 return NULL; | |
| 1174 } | |
| 1175 return NULL; | |
| 1176 } | |
| 1177 | |
| 1178 | |
| 989 // If a broker has not already been created for this plugin, creates one. | 1179 // If a broker has not already been created for this plugin, creates one. |
| 990 webkit::ppapi::PluginDelegate::PpapiBroker* | 1180 webkit::ppapi::PluginDelegate::PpapiBroker* |
| 991 PepperPluginDelegateImpl::ConnectToPpapiBroker( | 1181 PepperPluginDelegateImpl::ConnectToPpapiBroker( |
| 992 webkit::ppapi::PPB_Broker_Impl* client) { | 1182 webkit::ppapi::PPB_Broker_Impl* client) { |
| 993 CHECK(client); | 1183 CHECK(client); |
| 994 | 1184 |
| 995 // If a broker needs to be created, this will ensure it does not get deleted | 1185 // If a broker needs to be created, this will ensure it does not get deleted |
| 996 // before Connect() adds a reference. | 1186 // before Connect() adds a reference. |
| 997 scoped_refptr<PpapiBrokerImpl> broker_impl; | 1187 scoped_refptr<PpapiBrokerImpl> broker_impl; |
| 998 | 1188 |
| (...skipping 617 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1616 | 1806 |
| 1617 int PepperPluginDelegateImpl::GetRoutingId() const { | 1807 int PepperPluginDelegateImpl::GetRoutingId() const { |
| 1618 return render_view_->routing_id(); | 1808 return render_view_->routing_id(); |
| 1619 } | 1809 } |
| 1620 | 1810 |
| 1621 void PepperPluginDelegateImpl::PublishInitialPolicy( | 1811 void PepperPluginDelegateImpl::PublishInitialPolicy( |
| 1622 scoped_refptr<webkit::ppapi::PluginInstance> instance, | 1812 scoped_refptr<webkit::ppapi::PluginInstance> instance, |
| 1623 const std::string& policy) { | 1813 const std::string& policy) { |
| 1624 instance->HandlePolicyUpdate(policy); | 1814 instance->HandlePolicyUpdate(policy); |
| 1625 } | 1815 } |
| OLD | NEW |