summaryrefslogtreecommitdiffstats
path: root/content/renderer/pepper/pepper_platform_audio_input_impl.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-25 22:26:11 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-02-25 22:26:11 +0000
commit60c331a16cba4f5347f77df8d5e3907bc3f24ae0 (patch)
treeda8d0eb8e23d24b4d05cf310114e77cfa0f26600 /content/renderer/pepper/pepper_platform_audio_input_impl.cc
parent7d018f7ff67d4f2febddaac5c98cfd76a79d58fd (diff)
downloadchromium_src-60c331a16cba4f5347f77df8d5e3907bc3f24ae0.zip
chromium_src-60c331a16cba4f5347f77df8d5e3907bc3f24ae0.tar.gz
chromium_src-60c331a16cba4f5347f77df8d5e3907bc3f24ae0.tar.bz2
Split out the pepper audio delegates.
This moves the audio input and output delegates into their own files. BUG= TEST= Review URL: https://chromiumcodereview.appspot.com/9430034 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123671 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/renderer/pepper/pepper_platform_audio_input_impl.cc')
-rw-r--r--content/renderer/pepper/pepper_platform_audio_input_impl.cc140
1 files changed, 140 insertions, 0 deletions
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&) {
+}