summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--content/content_renderer.gypi4
-rw-r--r--content/renderer/pepper/pepper_platform_audio_input_impl.cc140
-rw-r--r--content/renderer/pepper/pepper_platform_audio_input_impl.h68
-rw-r--r--content/renderer/pepper/pepper_platform_audio_output_impl.cc148
-rw-r--r--content/renderer/pepper/pepper_platform_audio_output_impl.h69
-rw-r--r--content/renderer/pepper/pepper_plugin_delegate_impl.cc363
-rw-r--r--content/renderer/pepper/pepper_plugin_delegate_impl.h2
-rw-r--r--webkit/plugins/ppapi/mock_plugin_delegate.cc2
-rw-r--r--webkit/plugins/ppapi/mock_plugin_delegate.h7
-rw-r--r--webkit/plugins/ppapi/plugin_delegate.h14
-rw-r--r--webkit/plugins/ppapi/ppb_audio_impl.cc12
-rw-r--r--webkit/plugins/ppapi/ppb_audio_impl.h2
12 files changed, 464 insertions, 367 deletions
diff --git a/content/content_renderer.gypi b/content/content_renderer.gypi
index a8371e0..573bde3 100644
--- a/content/content_renderer.gypi
+++ b/content/content_renderer.gypi
@@ -120,6 +120,10 @@
'renderer/paint_aggregator.h',
'renderer/pepper/pepper_parent_context_provider.cc',
'renderer/pepper/pepper_parent_context_provider.h',
+ 'renderer/pepper/pepper_platform_audio_input_impl.cc',
+ 'renderer/pepper/pepper_platform_audio_input_impl.h',
+ 'renderer/pepper/pepper_platform_audio_output_impl.cc',
+ 'renderer/pepper/pepper_platform_audio_output_impl.h',
'renderer/pepper/pepper_platform_context_3d_impl.cc',
'renderer/pepper/pepper_platform_context_3d_impl.h',
'renderer/pepper/pepper_platform_video_capture_impl.cc',
diff --git a/content/renderer/pepper/pepper_platform_audio_input_impl.cc b/content/renderer/pepper/pepper_platform_audio_input_impl.cc
new file mode 100644
index 0000000..3c3cbe6
--- /dev/null
+++ b/content/renderer/pepper/pepper_platform_audio_input_impl.cc
@@ -0,0 +1,140 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/renderer/pepper/pepper_platform_audio_input_impl.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "base/message_loop_proxy.h"
+#include "build/build_config.h"
+#include "content/common/child_process.h"
+#include "content/common/media/audio_messages.h"
+#include "content/renderer/render_thread_impl.h"
+#include "media/audio/audio_manager_base.h"
+
+PepperPlatformAudioInputImpl::PepperPlatformAudioInputImpl()
+ : client_(NULL),
+ stream_id_(0),
+ main_message_loop_proxy_(base::MessageLoopProxy::current()) {
+ filter_ = RenderThreadImpl::current()->audio_input_message_filter();
+}
+
+PepperPlatformAudioInputImpl::~PepperPlatformAudioInputImpl() {
+ // Make sure we have been shut down. Warning: this will usually happen on
+ // the I/O thread!
+ DCHECK_EQ(0, stream_id_);
+ DCHECK(!client_);
+}
+
+bool PepperPlatformAudioInputImpl::Initialize(
+ uint32_t sample_rate,
+ uint32_t sample_count,
+ webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client) {
+ DCHECK(client);
+ // Make sure we don't call init more than once.
+ DCHECK_EQ(0, stream_id_);
+
+ client_ = client;
+
+ AudioParameters params;
+ params.format = AudioParameters::AUDIO_PCM_LINEAR;
+ params.channels = 1;
+ params.sample_rate = sample_rate;
+ params.bits_per_sample = 16;
+ params.samples_per_packet = sample_count;
+
+ ChildProcess::current()->io_message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&PepperPlatformAudioInputImpl::InitializeOnIOThread,
+ this, params));
+ return true;
+}
+
+bool PepperPlatformAudioInputImpl::StartCapture() {
+ ChildProcess::current()->io_message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&PepperPlatformAudioInputImpl::StartCaptureOnIOThread, this));
+ return true;
+}
+
+bool PepperPlatformAudioInputImpl::StopCapture() {
+ ChildProcess::current()->io_message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&PepperPlatformAudioInputImpl::StopCaptureOnIOThread, this));
+ return true;
+}
+
+void PepperPlatformAudioInputImpl::ShutDown() {
+ // Called on the main thread to stop all audio callbacks. We must only change
+ // the client on the main thread, and the delegates from the I/O thread.
+ client_ = NULL;
+ ChildProcess::current()->io_message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&PepperPlatformAudioInputImpl::ShutDownOnIOThread, this));
+}
+
+void PepperPlatformAudioInputImpl::InitializeOnIOThread(
+ const AudioParameters& params) {
+ stream_id_ = filter_->AddDelegate(this);
+ filter_->Send(new AudioInputHostMsg_CreateStream(
+ stream_id_, params, AudioManagerBase::kDefaultDeviceId));
+}
+
+void PepperPlatformAudioInputImpl::StartCaptureOnIOThread() {
+ if (stream_id_)
+ filter_->Send(new AudioInputHostMsg_RecordStream(stream_id_));
+}
+
+void PepperPlatformAudioInputImpl::StopCaptureOnIOThread() {
+ if (stream_id_)
+ filter_->Send(new AudioInputHostMsg_CloseStream(stream_id_));
+}
+
+void PepperPlatformAudioInputImpl::ShutDownOnIOThread() {
+ // Make sure we don't call shutdown more than once.
+ if (!stream_id_)
+ return;
+
+ filter_->Send(new AudioInputHostMsg_CloseStream(stream_id_));
+ filter_->RemoveDelegate(stream_id_);
+ stream_id_ = 0;
+
+ Release(); // Release for the delegate, balances out the reference taken in
+ // PepperPluginDelegateImpl::CreateAudioInput.
+}
+
+void PepperPlatformAudioInputImpl::OnStreamCreated(
+ base::SharedMemoryHandle handle,
+ base::SyncSocket::Handle socket_handle,
+ uint32 length) {
+#if defined(OS_WIN)
+ DCHECK(handle);
+ DCHECK(socket_handle);
+#else
+ DCHECK_NE(-1, handle.fd);
+ DCHECK_NE(-1, socket_handle);
+#endif
+ DCHECK(length);
+
+ if (base::MessageLoopProxy::current() == main_message_loop_proxy_) {
+ // Must dereference the client only on the main thread. Shutdown may have
+ // occurred while the request was in-flight, so we need to NULL check.
+ if (client_)
+ client_->StreamCreated(handle, length, socket_handle);
+ } else {
+ main_message_loop_proxy_->PostTask(
+ FROM_HERE,
+ base::Bind(&PepperPlatformAudioInputImpl::OnStreamCreated, this,
+ handle, socket_handle, length));
+ }
+}
+
+void PepperPlatformAudioInputImpl::OnVolume(double volume) {
+}
+
+void PepperPlatformAudioInputImpl::OnStateChanged(AudioStreamState state) {
+}
+
+void PepperPlatformAudioInputImpl::OnDeviceReady(const std::string&) {
+}
diff --git a/content/renderer/pepper/pepper_platform_audio_input_impl.h b/content/renderer/pepper/pepper_platform_audio_input_impl.h
new file mode 100644
index 0000000..a4f48ea
--- /dev/null
+++ b/content/renderer/pepper/pepper_platform_audio_input_impl.h
@@ -0,0 +1,68 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_INPUT_IMPL_H_
+#define CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_INPUT_IMPL_H_
+
+#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
+#include "base/memory/scoped_ptr.h"
+#include "content/renderer/media/audio_input_message_filter.h"
+#include "webkit/plugins/ppapi/plugin_delegate.h"
+
+struct AudioParameters;
+
+class PepperPlatformAudioInputImpl
+ : public webkit::ppapi::PluginDelegate::PlatformAudioInput,
+ public AudioInputMessageFilter::Delegate,
+ public base::RefCountedThreadSafe<PepperPlatformAudioInputImpl> {
+ public:
+ PepperPlatformAudioInputImpl();
+ virtual ~PepperPlatformAudioInputImpl();
+
+ // Initialize this audio context. StreamCreated() will be called when the
+ // stream is created.
+ bool Initialize(
+ uint32_t sample_rate,
+ uint32_t sample_count,
+ webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client);
+
+ // PlatformAudioInput implementation (called on main thread).
+ virtual bool StartCapture() OVERRIDE;
+ virtual bool StopCapture() OVERRIDE;
+ virtual void ShutDown() OVERRIDE;
+
+ private:
+ // I/O thread backends to above functions.
+ void InitializeOnIOThread(const AudioParameters& params);
+ void StartCaptureOnIOThread();
+ void StopCaptureOnIOThread();
+ void ShutDownOnIOThread();
+
+ // AudioInputMessageFilter::Delegate.
+ virtual void OnStreamCreated(base::SharedMemoryHandle handle,
+ base::SyncSocket::Handle socket_handle,
+ uint32 length) OVERRIDE;
+ virtual void OnVolume(double volume) OVERRIDE;
+ virtual void OnStateChanged(AudioStreamState state) OVERRIDE;
+ virtual void OnDeviceReady(const std::string&) OVERRIDE;
+
+ // The client to notify when the stream is created. THIS MUST ONLY BE
+ // ACCESSED ON THE MAIN THREAD.
+ webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client_;
+
+ // MessageFilter used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE
+ // I/O thread except to send messages and get the message loop.
+ scoped_refptr<AudioInputMessageFilter> filter_;
+
+ // Our ID on the MessageFilter. THIS MUST ONLY BE ACCESSED ON THE I/O THREAD
+ // or else you could race with the initialize function which sets it.
+ int32 stream_id_;
+
+ base::MessageLoopProxy* main_message_loop_proxy_;
+
+ DISALLOW_COPY_AND_ASSIGN(PepperPlatformAudioInputImpl);
+};
+
+#endif // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_INPUT_IMPL_H_
diff --git a/content/renderer/pepper/pepper_platform_audio_output_impl.cc b/content/renderer/pepper/pepper_platform_audio_output_impl.cc
new file mode 100644
index 0000000..1b3a02e
--- /dev/null
+++ b/content/renderer/pepper/pepper_platform_audio_output_impl.cc
@@ -0,0 +1,148 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/renderer/pepper/pepper_platform_audio_output_impl.h"
+
+#include "base/bind.h"
+#include "base/logging.h"
+#include "base/message_loop_proxy.h"
+#include "build/build_config.h"
+#include "content/common/child_process.h"
+#include "content/common/media/audio_messages.h"
+#include "content/renderer/media/audio_hardware.h"
+#include "content/renderer/render_thread_impl.h"
+
+PepperPlatformAudioOutputImpl::PepperPlatformAudioOutputImpl()
+ : client_(NULL),
+ stream_id_(0),
+ main_message_loop_proxy_(base::MessageLoopProxy::current()) {
+ filter_ = RenderThreadImpl::current()->audio_message_filter();
+}
+
+PepperPlatformAudioOutputImpl::~PepperPlatformAudioOutputImpl() {
+ // Make sure we have been shut down. Warning: this will usually happen on
+ // the I/O thread!
+ DCHECK_EQ(0, stream_id_);
+ DCHECK(!client_);
+}
+
+bool PepperPlatformAudioOutputImpl::Initialize(
+ uint32_t sample_rate,
+ uint32_t sample_count,
+ webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client) {
+ DCHECK(client);
+ // Make sure we don't call init more than once.
+ DCHECK_EQ(0, stream_id_);
+
+ client_ = client;
+
+ AudioParameters params;
+ const uint32_t kMaxSampleCountForLowLatency = 2048;
+ // Use the low latency back end if the client request is compatible, and
+ // the sample count is low enough to justify using AUDIO_PCM_LOW_LATENCY.
+ if (sample_rate == audio_hardware::GetOutputSampleRate() &&
+ sample_count <= kMaxSampleCountForLowLatency &&
+ sample_count % audio_hardware::GetOutputBufferSize() == 0)
+ params.format = AudioParameters::AUDIO_PCM_LOW_LATENCY;
+ else
+ params.format = AudioParameters::AUDIO_PCM_LINEAR;
+ params.channels = 2;
+ params.sample_rate = sample_rate;
+ params.bits_per_sample = 16;
+ params.samples_per_packet = sample_count;
+
+ ChildProcess::current()->io_message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&PepperPlatformAudioOutputImpl::InitializeOnIOThread,
+ this, params));
+ return true;
+}
+
+bool PepperPlatformAudioOutputImpl::StartPlayback() {
+ if (filter_) {
+ ChildProcess::current()->io_message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&PepperPlatformAudioOutputImpl::StartPlaybackOnIOThread,
+ this));
+ return true;
+ }
+ return false;
+}
+
+bool PepperPlatformAudioOutputImpl::StopPlayback() {
+ if (filter_) {
+ ChildProcess::current()->io_message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&PepperPlatformAudioOutputImpl::StopPlaybackOnIOThread,
+ this));
+ return true;
+ }
+ return false;
+}
+
+void PepperPlatformAudioOutputImpl::ShutDown() {
+ // Called on the main thread to stop all audio callbacks. We must only change
+ // the client on the main thread, and the delegates from the I/O thread.
+ client_ = NULL;
+ ChildProcess::current()->io_message_loop()->PostTask(
+ FROM_HERE,
+ base::Bind(&PepperPlatformAudioOutputImpl::ShutDownOnIOThread, this));
+}
+
+void PepperPlatformAudioOutputImpl::InitializeOnIOThread(
+ const AudioParameters& params) {
+ stream_id_ = filter_->AddDelegate(this);
+ filter_->Send(new AudioHostMsg_CreateStream(stream_id_, params));
+}
+
+void PepperPlatformAudioOutputImpl::StartPlaybackOnIOThread() {
+ if (stream_id_)
+ filter_->Send(new AudioHostMsg_PlayStream(stream_id_));
+}
+
+void PepperPlatformAudioOutputImpl::StopPlaybackOnIOThread() {
+ if (stream_id_)
+ filter_->Send(new AudioHostMsg_PauseStream(stream_id_));
+}
+
+void PepperPlatformAudioOutputImpl::ShutDownOnIOThread() {
+ // Make sure we don't call shutdown more than once.
+ if (!stream_id_)
+ return;
+
+ filter_->Send(new AudioHostMsg_CloseStream(stream_id_));
+ filter_->RemoveDelegate(stream_id_);
+ stream_id_ = 0;
+
+ Release(); // Release for the delegate, balances out the reference taken in
+ // PepperPluginDelegateImpl::CreateAudio.
+}
+
+void PepperPlatformAudioOutputImpl::OnStateChanged(AudioStreamState state) {
+}
+
+void PepperPlatformAudioOutputImpl::OnStreamCreated(
+ base::SharedMemoryHandle handle,
+ base::SyncSocket::Handle socket_handle,
+ uint32 length) {
+#if defined(OS_WIN)
+ DCHECK(handle);
+ DCHECK(socket_handle);
+#else
+ DCHECK_NE(-1, handle.fd);
+ DCHECK_NE(-1, socket_handle);
+#endif
+ DCHECK(length);
+
+ if (base::MessageLoopProxy::current() == main_message_loop_proxy_) {
+ // Must dereference the client only on the main thread. Shutdown may have
+ // occurred while the request was in-flight, so we need to NULL check.
+ if (client_)
+ client_->StreamCreated(handle, length, socket_handle);
+ } else {
+ main_message_loop_proxy_->PostTask(FROM_HERE,
+ base::Bind(&PepperPlatformAudioOutputImpl::OnStreamCreated, this,
+ handle, socket_handle, length));
+ }
+}
diff --git a/content/renderer/pepper/pepper_platform_audio_output_impl.h b/content/renderer/pepper/pepper_platform_audio_output_impl.h
new file mode 100644
index 0000000..1615d25
--- /dev/null
+++ b/content/renderer/pepper/pepper_platform_audio_output_impl.h
@@ -0,0 +1,69 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_OUTPUT_IMPL_H_
+#define CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_OUTPUT_IMPL_H_
+
+#include "base/basictypes.h"
+#include "base/memory/ref_counted.h"
+#include "content/renderer/media/audio_message_filter.h"
+#include "webkit/plugins/ppapi/plugin_delegate.h"
+
+struct AudioParameters;
+
+namespace base {
+class MessageLoopProxy;
+}
+
+class PepperPlatformAudioOutputImpl
+ : public webkit::ppapi::PluginDelegate::PlatformAudioOutput,
+ public AudioMessageFilter::Delegate,
+ public base::RefCountedThreadSafe<PepperPlatformAudioOutputImpl> {
+ public:
+ PepperPlatformAudioOutputImpl();
+ virtual ~PepperPlatformAudioOutputImpl();
+
+ // Initialize this audio context. StreamCreated() will be called when the
+ // stream is created.
+ bool Initialize(
+ uint32_t sample_rate,
+ uint32_t sample_count,
+ webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client);
+
+ // PlatformAudioOutput implementation (called on main thread).
+ virtual bool StartPlayback() OVERRIDE;
+ virtual bool StopPlayback() OVERRIDE;
+ virtual void ShutDown() OVERRIDE;
+
+ private:
+ // I/O thread backends to above functions.
+ void InitializeOnIOThread(const AudioParameters& params);
+ void StartPlaybackOnIOThread();
+ void StopPlaybackOnIOThread();
+ void ShutDownOnIOThread();
+
+ // AudioMessageFilter::Delegate.
+ virtual void OnStateChanged(AudioStreamState state) OVERRIDE;
+ virtual void OnStreamCreated(base::SharedMemoryHandle handle,
+ base::SyncSocket::Handle socket_handle,
+ uint32 length) OVERRIDE;
+
+ // The client to notify when the stream is created. THIS MUST ONLY BE
+ // ACCESSED ON THE MAIN THREAD.
+ webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client_;
+
+ // MessageFilter used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE
+ // I/O thread except to send messages and get the message loop.
+ scoped_refptr<AudioMessageFilter> filter_;
+
+ // Our ID on the MessageFilter. THIS MUST ONLY BE ACCESSED ON THE I/O THREAD
+ // or else you could race with the initialize function which sets it.
+ int32 stream_id_;
+
+ base::MessageLoopProxy* main_message_loop_proxy_;
+
+ DISALLOW_COPY_AND_ASSIGN(PepperPlatformAudioOutputImpl);
+};
+
+#endif // CONTENT_RENDERER_PEPPER_PEPPER_PLATFORM_AUDIO_OUTPUT_IMPL_H_
diff --git a/content/renderer/pepper/pepper_plugin_delegate_impl.cc b/content/renderer/pepper/pepper_plugin_delegate_impl.cc
index 5dc90f6..e298387 100644
--- a/content/renderer/pepper/pepper_plugin_delegate_impl.cc
+++ b/content/renderer/pepper/pepper_plugin_delegate_impl.cc
@@ -24,7 +24,6 @@
#include "content/common/file_system_messages.h"
#include "content/common/gpu/client/content_gl_context.h"
#include "content/common/gpu/client/webgraphicscontext3d_command_buffer_impl.h"
-#include "content/common/media/audio_messages.h"
#include "content/common/pepper_file_messages.h"
#include "content/common/pepper_plugin_registry.h"
#include "content/common/pepper_messages.h"
@@ -36,12 +35,12 @@
#include "content/public/renderer/content_renderer_client.h"
#include "content/renderer/gamepad_shared_memory_reader.h"
#include "content/renderer/media/audio_hardware.h"
-#include "content/renderer/media/audio_input_message_filter.h"
-#include "content/renderer/media/audio_message_filter.h"
#include "content/renderer/media/media_stream_dispatcher.h"
#include "content/renderer/media/media_stream_dispatcher_eventhandler.h"
#include "content/renderer/media/pepper_platform_video_decoder_impl.h"
#include "content/renderer/p2p/p2p_transport_impl.h"
+#include "content/renderer/pepper/pepper_platform_audio_input_impl.h"
+#include "content/renderer/pepper/pepper_platform_audio_output_impl.h"
#include "content/renderer/pepper/pepper_platform_context_3d_impl.h"
#include "content/renderer/pepper/pepper_platform_video_capture_impl.h"
#include "content/renderer/render_thread_impl.h"
@@ -50,7 +49,6 @@
#include "content/renderer/renderer_clipboard_client.h"
#include "content/renderer/webplugin_delegate_proxy.h"
#include "ipc/ipc_channel_handle.h"
-#include "media/audio/audio_manager_base.h"
#include "media/video/capture/video_capture_proxy.h"
#include "ppapi/c/dev/pp_video_dev.h"
#include "ppapi/c/pp_errors.h"
@@ -165,340 +163,6 @@ class PlatformImage2DImpl
DISALLOW_COPY_AND_ASSIGN(PlatformImage2DImpl);
};
-class PlatformAudioImpl
- : public webkit::ppapi::PluginDelegate::PlatformAudio,
- public AudioMessageFilter::Delegate,
- public base::RefCountedThreadSafe<PlatformAudioImpl> {
- public:
- PlatformAudioImpl()
- : client_(NULL), stream_id_(0),
- main_message_loop_proxy_(base::MessageLoopProxy::current()) {
- filter_ = RenderThreadImpl::current()->audio_message_filter();
- }
-
- virtual ~PlatformAudioImpl() {
- // Make sure we have been shut down. Warning: this will usually happen on
- // the I/O thread!
- DCHECK_EQ(0, stream_id_);
- DCHECK(!client_);
- }
-
- // Initialize this audio context. StreamCreated() will be called when the
- // stream is created.
- bool Initialize(uint32_t sample_rate, uint32_t sample_count,
- webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client);
-
- // PlatformAudio implementation (called on main thread).
- virtual bool StartPlayback() OVERRIDE;
- virtual bool StopPlayback() OVERRIDE;
- virtual void ShutDown() OVERRIDE;
-
- private:
- // I/O thread backends to above functions.
- void InitializeOnIOThread(const AudioParameters& params);
- void StartPlaybackOnIOThread();
- void StopPlaybackOnIOThread();
- void ShutDownOnIOThread();
-
- virtual void OnStateChanged(AudioStreamState state) OVERRIDE {}
-
- virtual void OnStreamCreated(base::SharedMemoryHandle handle,
- base::SyncSocket::Handle socket_handle,
- uint32 length) OVERRIDE;
-
- // The client to notify when the stream is created. THIS MUST ONLY BE
- // ACCESSED ON THE MAIN THREAD.
- webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client_;
-
- // MessageFilter used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE
- // I/O thread except to send messages and get the message loop.
- scoped_refptr<AudioMessageFilter> filter_;
-
- // Our ID on the MessageFilter. THIS MUST ONLY BE ACCESSED ON THE I/O THREAD
- // or else you could race with the initialize function which sets it.
- int32 stream_id_;
-
- base::MessageLoopProxy* main_message_loop_proxy_;
-
- DISALLOW_COPY_AND_ASSIGN(PlatformAudioImpl);
-};
-
-bool PlatformAudioImpl::Initialize(
- uint32_t sample_rate, uint32_t sample_count,
- webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client) {
- DCHECK(client);
- // Make sure we don't call init more than once.
- DCHECK_EQ(0, stream_id_);
-
- client_ = client;
-
- AudioParameters params;
- const uint32_t kMaxSampleCountForLowLatency = 2048;
- // Use the low latency back end if the client request is compatible, and
- // the sample count is low enough to justify using AUDIO_PCM_LOW_LATENCY.
- if (sample_rate == audio_hardware::GetOutputSampleRate() &&
- sample_count <= kMaxSampleCountForLowLatency &&
- sample_count % audio_hardware::GetOutputBufferSize() == 0)
- params.format = AudioParameters::AUDIO_PCM_LOW_LATENCY;
- else
- params.format = AudioParameters::AUDIO_PCM_LINEAR;
- params.channels = 2;
- params.sample_rate = sample_rate;
- params.bits_per_sample = 16;
- params.samples_per_packet = sample_count;
-
- ChildProcess::current()->io_message_loop()->PostTask(
- FROM_HERE,
- base::Bind(&PlatformAudioImpl::InitializeOnIOThread, this, params));
- return true;
-}
-
-bool PlatformAudioImpl::StartPlayback() {
- if (filter_) {
- ChildProcess::current()->io_message_loop()->PostTask(
- FROM_HERE,
- base::Bind(&PlatformAudioImpl::StartPlaybackOnIOThread, this));
- return true;
- }
- return false;
-}
-
-bool PlatformAudioImpl::StopPlayback() {
- if (filter_) {
- ChildProcess::current()->io_message_loop()->PostTask(
- FROM_HERE,
- base::Bind(&PlatformAudioImpl::StopPlaybackOnIOThread, this));
- return true;
- }
- return false;
-}
-
-void PlatformAudioImpl::ShutDown() {
- // Called on the main thread to stop all audio callbacks. We must only change
- // the client on the main thread, and the delegates from the I/O thread.
- client_ = NULL;
- ChildProcess::current()->io_message_loop()->PostTask(
- FROM_HERE,
- base::Bind(&PlatformAudioImpl::ShutDownOnIOThread, this));
-}
-
-void PlatformAudioImpl::InitializeOnIOThread(const AudioParameters& params) {
- stream_id_ = filter_->AddDelegate(this);
- filter_->Send(new AudioHostMsg_CreateStream(stream_id_, params));
-}
-
-void PlatformAudioImpl::StartPlaybackOnIOThread() {
- if (stream_id_)
- filter_->Send(new AudioHostMsg_PlayStream(stream_id_));
-}
-
-void PlatformAudioImpl::StopPlaybackOnIOThread() {
- if (stream_id_)
- filter_->Send(new AudioHostMsg_PauseStream(stream_id_));
-}
-
-void PlatformAudioImpl::ShutDownOnIOThread() {
- // Make sure we don't call shutdown more than once.
- if (!stream_id_)
- return;
-
- filter_->Send(new AudioHostMsg_CloseStream(stream_id_));
- filter_->RemoveDelegate(stream_id_);
- stream_id_ = 0;
-
- Release(); // Release for the delegate, balances out the reference taken in
- // PepperPluginDelegateImpl::CreateAudio.
-}
-
-void PlatformAudioImpl::OnStreamCreated(
- base::SharedMemoryHandle handle, base::SyncSocket::Handle socket_handle,
- uint32 length) {
-#if defined(OS_WIN)
- DCHECK(handle);
- DCHECK(socket_handle);
-#else
- DCHECK_NE(-1, handle.fd);
- DCHECK_NE(-1, socket_handle);
-#endif
- DCHECK(length);
-
- if (base::MessageLoopProxy::current() == main_message_loop_proxy_) {
- // Must dereference the client only on the main thread. Shutdown may have
- // occurred while the request was in-flight, so we need to NULL check.
- if (client_)
- client_->StreamCreated(handle, length, socket_handle);
- } else {
- main_message_loop_proxy_->PostTask(FROM_HERE,
- base::Bind(&PlatformAudioImpl::OnStreamCreated, this, handle,
- socket_handle, length));
- }
-}
-
-class PlatformAudioInputImpl
- : public webkit::ppapi::PluginDelegate::PlatformAudioInput,
- public AudioInputMessageFilter::Delegate,
- public base::RefCountedThreadSafe<PlatformAudioInputImpl> {
- public:
- PlatformAudioInputImpl()
- : client_(NULL), stream_id_(0),
- main_message_loop_proxy_(base::MessageLoopProxy::current()) {
- filter_ = RenderThreadImpl::current()->audio_input_message_filter();
- }
-
- virtual ~PlatformAudioInputImpl() {
- // Make sure we have been shut down. Warning: this will usually happen on
- // the I/O thread!
- DCHECK_EQ(0, stream_id_);
- DCHECK(!client_);
- }
-
- // Initialize this audio context. StreamCreated() will be called when the
- // stream is created.
- bool Initialize(
- uint32_t sample_rate, uint32_t sample_count,
- webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client);
-
- // PlatformAudio implementation (called on main thread).
- virtual bool StartCapture() OVERRIDE;
- virtual bool StopCapture() OVERRIDE;
- virtual void ShutDown() OVERRIDE;
-
- private:
- // I/O thread backends to above functions.
- void InitializeOnIOThread(const AudioParameters& params);
- void StartCaptureOnIOThread();
- void StopCaptureOnIOThread();
- void ShutDownOnIOThread();
-
- virtual void OnStreamCreated(base::SharedMemoryHandle handle,
- base::SyncSocket::Handle socket_handle,
- uint32 length) OVERRIDE;
-
- virtual void OnVolume(double volume) OVERRIDE {}
-
- virtual void OnStateChanged(AudioStreamState state) OVERRIDE {}
-
- virtual void OnDeviceReady(const std::string&) OVERRIDE {}
-
- // The client to notify when the stream is created. THIS MUST ONLY BE
- // ACCESSED ON THE MAIN THREAD.
- webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client_;
-
- // MessageFilter used to send/receive IPC. THIS MUST ONLY BE ACCESSED ON THE
- // I/O thread except to send messages and get the message loop.
- scoped_refptr<AudioInputMessageFilter> filter_;
-
- // Our ID on the MessageFilter. THIS MUST ONLY BE ACCESSED ON THE I/O THREAD
- // or else you could race with the initialize function which sets it.
- int32 stream_id_;
-
- base::MessageLoopProxy* main_message_loop_proxy_;
-
- DISALLOW_COPY_AND_ASSIGN(PlatformAudioInputImpl);
-};
-
-bool PlatformAudioInputImpl::Initialize(
- uint32_t sample_rate, uint32_t sample_count,
- webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client) {
- DCHECK(client);
- // Make sure we don't call init more than once.
- DCHECK_EQ(0, stream_id_);
-
- client_ = client;
-
- AudioParameters params;
- params.format = AudioParameters::AUDIO_PCM_LINEAR;
- params.channels = 1;
- params.sample_rate = sample_rate;
- params.bits_per_sample = 16;
- params.samples_per_packet = sample_count;
-
- ChildProcess::current()->io_message_loop()->PostTask(
- FROM_HERE,
- base::Bind(&PlatformAudioInputImpl::InitializeOnIOThread, this, params));
- return true;
-}
-
-bool PlatformAudioInputImpl::StartCapture() {
- ChildProcess::current()->io_message_loop()->PostTask(
- FROM_HERE,
- base::Bind(&PlatformAudioInputImpl::StartCaptureOnIOThread, this));
- return true;
-}
-
-bool PlatformAudioInputImpl::StopCapture() {
- ChildProcess::current()->io_message_loop()->PostTask(
- FROM_HERE,
- base::Bind(&PlatformAudioInputImpl::StopCaptureOnIOThread, this));
- return true;
-}
-
-void PlatformAudioInputImpl::ShutDown() {
- // Called on the main thread to stop all audio callbacks. We must only change
- // the client on the main thread, and the delegates from the I/O thread.
- client_ = NULL;
- ChildProcess::current()->io_message_loop()->PostTask(
- FROM_HERE,
- base::Bind(&PlatformAudioInputImpl::ShutDownOnIOThread, this));
-}
-
-void PlatformAudioInputImpl::InitializeOnIOThread(
- const AudioParameters& params) {
- stream_id_ = filter_->AddDelegate(this);
- filter_->Send(new AudioInputHostMsg_CreateStream(
- stream_id_, params, AudioManagerBase::kDefaultDeviceId));
-}
-
-void PlatformAudioInputImpl::StartCaptureOnIOThread() {
- if (stream_id_)
- filter_->Send(new AudioInputHostMsg_RecordStream(stream_id_));
-}
-
-void PlatformAudioInputImpl::StopCaptureOnIOThread() {
- if (stream_id_)
- filter_->Send(new AudioInputHostMsg_CloseStream(stream_id_));
-}
-
-void PlatformAudioInputImpl::ShutDownOnIOThread() {
- // Make sure we don't call shutdown more than once.
- if (!stream_id_)
- return;
-
- filter_->Send(new AudioInputHostMsg_CloseStream(stream_id_));
- filter_->RemoveDelegate(stream_id_);
- stream_id_ = 0;
-
- Release(); // Release for the delegate, balances out the reference taken in
- // PepperPluginDelegateImpl::CreateAudioInput.
-}
-
-void PlatformAudioInputImpl::OnStreamCreated(
- base::SharedMemoryHandle handle,
- base::SyncSocket::Handle socket_handle,
- uint32 length) {
-
-#if defined(OS_WIN)
- DCHECK(handle);
- DCHECK(socket_handle);
-#else
- DCHECK_NE(-1, handle.fd);
- DCHECK_NE(-1, socket_handle);
-#endif
- DCHECK(length);
-
- if (base::MessageLoopProxy::current() == main_message_loop_proxy_) {
- // Must dereference the client only on the main thread. Shutdown may have
- // occurred while the request was in-flight, so we need to NULL check.
- if (client_)
- client_->StreamCreated(handle, length, socket_handle);
- } else {
- main_message_loop_proxy_->PostTask(
- FROM_HERE,
- base::Bind(&PlatformAudioInputImpl::OnStreamCreated, this,
- handle, socket_handle, length));
- }
-}
-
class DispatcherDelegate : public ppapi::proxy::ProxyChannel::Delegate {
public:
virtual ~DispatcherDelegate() {}
@@ -1378,18 +1042,19 @@ uint32_t PepperPluginDelegateImpl::GetAudioHardwareOutputBufferSize() {
return static_cast<uint32_t>(audio_hardware::GetOutputBufferSize());
}
-webkit::ppapi::PluginDelegate::PlatformAudio*
-PepperPluginDelegateImpl::CreateAudio(
+webkit::ppapi::PluginDelegate::PlatformAudioOutput*
+PepperPluginDelegateImpl::CreateAudioOutput(
uint32_t sample_rate,
uint32_t sample_count,
webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client) {
- scoped_refptr<PlatformAudioImpl> audio(new PlatformAudioImpl());
- if (audio->Initialize(sample_rate, sample_count, client)) {
- // Balanced by Release invoked in PlatformAudioImpl::ShutDownOnIOThread().
- return audio.release();
- } else {
- return NULL;
+ scoped_refptr<PepperPlatformAudioOutputImpl> audio_output(
+ new PepperPlatformAudioOutputImpl);
+ if (audio_output->Initialize(sample_rate, sample_count, client)) {
+ // Balanced by Release invoked in
+ // PepperPlatformAudioOutput::ShutDownOnIOThread().
+ return audio_output.release();
}
+ return NULL;
}
webkit::ppapi::PluginDelegate::PlatformAudioInput*
@@ -1397,11 +1062,11 @@ PepperPluginDelegateImpl::CreateAudioInput(
uint32_t sample_rate,
uint32_t sample_count,
webkit::ppapi::PluginDelegate::PlatformAudioCommonClient* client) {
- scoped_refptr<PlatformAudioInputImpl>
- audio_input(new PlatformAudioInputImpl());
+ scoped_refptr<PepperPlatformAudioInputImpl> audio_input(
+ new PepperPlatformAudioInputImpl);
if (audio_input->Initialize(sample_rate, sample_count, client)) {
// Balanced by Release invoked in
- // PlatformAudioInputImpl::ShutDownOnIOThread().
+ // PepperPlatformAudioInput::ShutDownOnIOThread().
return audio_input.release();
}
return NULL;
diff --git a/content/renderer/pepper/pepper_plugin_delegate_impl.h b/content/renderer/pepper/pepper_plugin_delegate_impl.h
index c82e869..9faca92 100644
--- a/content/renderer/pepper/pepper_plugin_delegate_impl.h
+++ b/content/renderer/pepper/pepper_plugin_delegate_impl.h
@@ -222,7 +222,7 @@ class PepperPluginDelegateImpl
virtual SkBitmap* GetSadPluginBitmap() OVERRIDE;
virtual uint32_t GetAudioHardwareOutputSampleRate() OVERRIDE;
virtual uint32_t GetAudioHardwareOutputBufferSize() OVERRIDE;
- virtual PlatformAudio* CreateAudio(
+ virtual PlatformAudioOutput* CreateAudioOutput(
uint32_t sample_rate,
uint32_t sample_count,
PlatformAudioCommonClient* client) OVERRIDE;
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.cc b/webkit/plugins/ppapi/mock_plugin_delegate.cc
index b1527e0..d73f763 100644
--- a/webkit/plugins/ppapi/mock_plugin_delegate.cc
+++ b/webkit/plugins/ppapi/mock_plugin_delegate.cc
@@ -79,7 +79,7 @@ uint32_t MockPluginDelegate::GetAudioHardwareOutputBufferSize() {
return 0;
}
-MockPluginDelegate::PlatformAudio* MockPluginDelegate::CreateAudio(
+MockPluginDelegate::PlatformAudioOutput* MockPluginDelegate::CreateAudioOutput(
uint32_t sample_rate,
uint32_t sample_count,
PlatformAudioCommonClient* client) {
diff --git a/webkit/plugins/ppapi/mock_plugin_delegate.h b/webkit/plugins/ppapi/mock_plugin_delegate.h
index ffaefa6..08e25b0 100644
--- a/webkit/plugins/ppapi/mock_plugin_delegate.h
+++ b/webkit/plugins/ppapi/mock_plugin_delegate.h
@@ -36,9 +36,10 @@ class MockPluginDelegate : public PluginDelegate {
PlatformVideoCaptureEventHandler* handler);
virtual uint32_t GetAudioHardwareOutputSampleRate();
virtual uint32_t GetAudioHardwareOutputBufferSize();
- virtual PlatformAudio* CreateAudio(uint32_t sample_rate,
- uint32_t sample_count,
- PlatformAudioCommonClient* client);
+ virtual PlatformAudioOutput* CreateAudioOutput(
+ uint32_t sample_rate,
+ uint32_t sample_count,
+ PlatformAudioCommonClient* client);
virtual PlatformAudioInput* CreateAudioInput(
uint32_t sample_rate,
uint32_t sample_count,
diff --git a/webkit/plugins/ppapi/plugin_delegate.h b/webkit/plugins/ppapi/plugin_delegate.h
index 67ad74a..3d02e1c 100644
--- a/webkit/plugins/ppapi/plugin_delegate.h
+++ b/webkit/plugins/ppapi/plugin_delegate.h
@@ -202,7 +202,7 @@ class PluginDelegate {
base::SyncSocket::Handle socket) = 0;
};
- class PlatformAudio {
+ class PlatformAudioOutput {
public:
// Starts the playback. Returns false on error or if called before the
// stream is created or after the stream is closed.
@@ -217,7 +217,7 @@ class PluginDelegate {
virtual void ShutDown() = 0;
protected:
- virtual ~PlatformAudio() {}
+ virtual ~PlatformAudioOutput() {}
};
class PlatformAudioInput {
@@ -336,13 +336,15 @@ class PluginDelegate {
// The caller is responsible for calling Shutdown() on the returned pointer
// to clean up the corresponding resources allocated during this call.
- virtual PlatformAudio* CreateAudio(uint32_t sample_rate,
- uint32_t sample_count,
- PlatformAudioCommonClient* client) = 0;
+ virtual PlatformAudioOutput* CreateAudioOutput(
+ uint32_t sample_rate,
+ uint32_t sample_count,
+ PlatformAudioCommonClient* client) = 0;
// The caller is responsible for calling Shutdown() on the returned pointer
// to clean up the corresponding resources allocated during this call.
- virtual PlatformAudioInput* CreateAudioInput(uint32_t sample_rate,
+ virtual PlatformAudioInput* CreateAudioInput(
+ uint32_t sample_rate,
uint32_t sample_count,
PlatformAudioCommonClient* client) = 0;
diff --git a/webkit/plugins/ppapi/ppb_audio_impl.cc b/webkit/plugins/ppapi/ppb_audio_impl.cc
index 152c4f5..a8c9806 100644
--- a/webkit/plugins/ppapi/ppb_audio_impl.cc
+++ b/webkit/plugins/ppapi/ppb_audio_impl.cc
@@ -77,9 +77,9 @@ bool PPB_Audio_Impl::Init(PP_Resource config,
// When the stream is created, we'll get called back on StreamCreated().
CHECK(!audio_);
- audio_ = plugin_delegate->CreateAudio(enter.object()->GetSampleRate(),
- enter.object()->GetSampleFrameCount(),
- this);
+ audio_ = plugin_delegate->CreateAudioOutput(
+ enter.object()->GetSampleRate(), enter.object()->GetSampleFrameCount(),
+ this);
return audio_ != NULL;
}
@@ -123,9 +123,9 @@ int32_t PPB_Audio_Impl::OpenTrusted(PP_Resource config,
// When the stream is created, we'll get called back on StreamCreated().
DCHECK(!audio_);
- audio_ = plugin_delegate->CreateAudio(enter.object()->GetSampleRate(),
- enter.object()->GetSampleFrameCount(),
- this);
+ audio_ = plugin_delegate->CreateAudioOutput(
+ enter.object()->GetSampleRate(), enter.object()->GetSampleFrameCount(),
+ this);
if (!audio_)
return PP_ERROR_FAILED;
diff --git a/webkit/plugins/ppapi/ppb_audio_impl.h b/webkit/plugins/ppapi/ppb_audio_impl.h
index d131090..19acfc3 100644
--- a/webkit/plugins/ppapi/ppb_audio_impl.h
+++ b/webkit/plugins/ppapi/ppb_audio_impl.h
@@ -73,7 +73,7 @@ class PPB_Audio_Impl : public ::ppapi::Resource,
// PluginDelegate audio object that we delegate audio IPC through. We don't
// own this pointer but are responsible for calling Shutdown on it.
- PluginDelegate::PlatformAudio* audio_;
+ PluginDelegate::PlatformAudioOutput* audio_;
DISALLOW_COPY_AND_ASSIGN(PPB_Audio_Impl);
};