summaryrefslogtreecommitdiffstats
path: root/ppapi/shared_impl/audio_impl.cc
diff options
context:
space:
mode:
authorbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-07 00:01:30 +0000
committerbrettw@chromium.org <brettw@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-12-07 00:01:30 +0000
commit56d7ad42237c35d2b7653c7cad89e9ca6ea75d68 (patch)
treeb16971de9045c0f3524566b5a242bef0ac0ab1db /ppapi/shared_impl/audio_impl.cc
parentf26d7fa665143e0bf1c173e093f9eadce0a10e97 (diff)
downloadchromium_src-56d7ad42237c35d2b7653c7cad89e9ca6ea75d68.zip
chromium_src-56d7ad42237c35d2b7653c7cad89e9ca6ea75d68.tar.gz
chromium_src-56d7ad42237c35d2b7653c7cad89e9ca6ea75d68.tar.bz2
Revert 113290 - Rename the shared_impl resource files to give them more regular names.
I keep getting confused between things like AudioImpl and PPB_Audio_Impl. This uses _shared for the names, so now we have _impl, _proxy, and _shared which makes more sense. I also removed the ppb_opengles2_impl file since it was just a forward to the shared version. BUG= TEST= Review URL: http://codereview.chromium.org/8790004 TBR=brettw@chromium.org Review URL: http://codereview.chromium.org/8824015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113302 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/shared_impl/audio_impl.cc')
-rw-r--r--ppapi/shared_impl/audio_impl.cc92
1 files changed, 92 insertions, 0 deletions
diff --git a/ppapi/shared_impl/audio_impl.cc b/ppapi/shared_impl/audio_impl.cc
new file mode 100644
index 0000000..b684ab1
--- /dev/null
+++ b/ppapi/shared_impl/audio_impl.cc
@@ -0,0 +1,92 @@
+// Copyright (c) 2011 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 "ppapi/shared_impl/audio_impl.h"
+
+#include "base/logging.h"
+
+namespace ppapi {
+
+AudioImpl::AudioImpl()
+ : playing_(false),
+ shared_memory_size_(0),
+ callback_(NULL),
+ user_data_(NULL) {
+}
+
+AudioImpl::~AudioImpl() {
+ // Closing the socket causes the thread to exit - wait for it.
+ if (socket_.get())
+ socket_->Close();
+ if (audio_thread_.get()) {
+ audio_thread_->Join();
+ audio_thread_.reset();
+ }
+}
+
+void AudioImpl::SetCallback(PPB_Audio_Callback callback, void* user_data) {
+ callback_ = callback;
+ user_data_ = user_data;
+}
+
+void AudioImpl::SetStartPlaybackState() {
+ DCHECK(!playing_);
+ DCHECK(!audio_thread_.get());
+
+ // If the socket doesn't exist, that means that the plugin has started before
+ // the browser has had a chance to create all the shared memory info and
+ // notify us. This is a common case. In this case, we just set the playing_
+ // flag and the playback will automatically start when that data is available
+ // in SetStreamInfo.
+ if (callback_ && socket_.get())
+ StartThread();
+ playing_ = true;
+}
+
+void AudioImpl::SetStopPlaybackState() {
+ DCHECK(playing_);
+
+ if (audio_thread_.get()) {
+ audio_thread_->Join();
+ audio_thread_.reset();
+ }
+ playing_ = false;
+}
+
+void AudioImpl::SetStreamInfo(base::SharedMemoryHandle shared_memory_handle,
+ size_t shared_memory_size,
+ base::SyncSocket::Handle socket_handle) {
+ socket_.reset(new base::SyncSocket(socket_handle));
+ shared_memory_.reset(new base::SharedMemory(shared_memory_handle, false));
+ shared_memory_size_ = shared_memory_size;
+
+ if (callback_) {
+ shared_memory_->Map(shared_memory_size_);
+
+ // In common case StartPlayback() was called before StreamCreated().
+ if (playing_)
+ StartThread();
+ }
+}
+
+void AudioImpl::StartThread() {
+ DCHECK(callback_);
+ DCHECK(!audio_thread_.get());
+ audio_thread_.reset(new base::DelegateSimpleThread(
+ this, "plugin_audio_thread"));
+ audio_thread_->Start();
+}
+
+void AudioImpl::Run() {
+ int pending_data;
+ void* buffer = shared_memory_->memory();
+
+ while (sizeof(pending_data) ==
+ socket_->Receive(&pending_data, sizeof(pending_data)) &&
+ pending_data >= 0) {
+ callback_(buffer, shared_memory_size_, user_data_);
+ }
+}
+
+} // namespace ppapi