Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(958)

Unified Diff: webkit/plugins/ppapi/ppb_audio_input_impl.cc

Issue 8138008: Implementation of ppapi audio. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 9 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: webkit/plugins/ppapi/ppb_audio_input_impl.cc
===================================================================
--- webkit/plugins/ppapi/ppb_audio_input_impl.cc (revision 0)
+++ webkit/plugins/ppapi/ppb_audio_input_impl.cc (revision 0)
@@ -0,0 +1,184 @@
+// 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 "webkit/plugins/ppapi/ppb_audio_input_impl.h"
+
+#include "base/logging.h"
+#include "ppapi/c/pp_completion_callback.h"
+#include "ppapi/c/dev/ppb_audio_input_dev.h"
+#include "ppapi/shared_impl/resource_tracker.h"
+#include "ppapi/shared_impl/tracker_base.h"
+#include "ppapi/thunk/enter.h"
+#include "ppapi/thunk/thunk.h"
+#include "webkit/plugins/ppapi/common.h"
+#include "webkit/plugins/ppapi/resource_helper.h"
+
+using ppapi::thunk::EnterResourceNoLock;
+using ppapi::thunk::PPB_AudioInput_API;
+
+namespace webkit {
+namespace ppapi {
+
+// PPB_AudioInput_Impl ---------------------------------------------------------
+
+PPB_AudioInput_Impl::PPB_AudioInput_Impl(PP_Instance instance)
+ : Resource(instance),
+ audio_input_(NULL),
+ create_callback_pending_(false),
+ shared_memory_size_for_create_callback_(0) {
+ create_callback_ = PP_MakeCompletionCallback(NULL, NULL);
+}
+
+PPB_AudioInput_Impl::~PPB_AudioInput_Impl() {
+ // Calling ShutDown() makes sure StreamCreated cannot be called anymore and
+ // releases the audio data associated with the pointer. Note however, that
+ // until ShutDown returns, StreamCreated may still be called. This will be
+ // OK since we'll just immediately clean up the data it stored later in this
+ // destructor.
+ if (audio_input_) {
+ audio_input_->ShutDown();
+ audio_input_ = NULL;
+ }
+
+ // If the completion callback hasn't fired yet, do so here
+ // with an error condition.
+ if (create_callback_pending_) {
+ PP_RunCompletionCallback(&create_callback_, PP_ERROR_ABORTED);
+ create_callback_pending_ = false;
+ }
+}
+
+// static
+PP_Resource PPB_AudioInput_Impl::Create(PP_Instance instance,
+ PPB_AudioInput_Callback audio_input_callback,
brettw 2011/10/12 19:33:13 Since these don't fit, move all the args to 4 spac
+ void* user_data) {
+ scoped_refptr<PPB_AudioInput_Impl>
+ audio_input(new PPB_AudioInput_Impl(instance));
brettw 2011/10/12 19:33:13 4 space.
+ if (!audio_input->Init(audio_input_callback, user_data))
+ return 0;
+ return audio_input->GetReference();
+}
+
+PPB_AudioInput_API* PPB_AudioInput_Impl::AsPPB_AudioInput_API() {
+ return this;
+}
+
+bool PPB_AudioInput_Impl::Init(PPB_AudioInput_Callback callback,
+ void* user_data) {
+ if (!callback)
+ return false;
+ SetCallback(callback, user_data);
+
+ PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
+ if (!plugin_delegate)
+ return false;
+
+ // When the stream is created, we'll get called back on StreamCreated().
+ CHECK(!audio_input_);
+ audio_input_ = plugin_delegate->CreateAudioInput(this);
+ return audio_input_ != NULL;
+}
+
+PP_Bool PPB_AudioInput_Impl::StartCapture() {
+ if (!audio_input_)
+ return PP_FALSE;
+ if (capturing())
+ return PP_TRUE;
+ SetStartCaptureState();
+ return BoolToPPBool(audio_input_->StartCapture());
+}
+
+PP_Bool PPB_AudioInput_Impl::StopCapture() {
+ if (!audio_input_)
+ return PP_FALSE;
+ if (!capturing())
+ return PP_TRUE;
+ if (!audio_input_->StopCapture())
+ return PP_FALSE;
+ SetStopCaptureState();
+ return PP_TRUE;
+}
+
+int32_t PPB_AudioInput_Impl::OpenTrusted(
+ PP_CompletionCallback create_callback) {
brettw 2011/10/12 19:33:13 4 space indent.
+ PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
+ if (!plugin_delegate)
+ return PP_ERROR_FAILED;
+
+ // When the stream is created, we'll get called back on StreamCreated().
+ DCHECK(!audio_input_);
+ audio_input_ = plugin_delegate->CreateAudioInput(this);
+
+ if (!audio_input_)
+ return PP_ERROR_FAILED;
+
+ // At this point, we are guaranteeing ownership of the completion
+ // callback. Audio promises to fire the completion callback
+ // once and only once.
+ create_callback_ = create_callback;
+ create_callback_pending_ = true;
+ return PP_OK_COMPLETIONPENDING;
+}
+
+int32_t PPB_AudioInput_Impl::GetSyncSocket(int* sync_socket) {
brettw 2011/10/12 20:39:34 These 3 functions are exactly copied from audio ou
viettrungluu 2011/11/02 21:03:07 What Brett said here still applies, and his respon
+ if (socket_for_create_callback_.get()) {
+#if defined(OS_POSIX)
+ *sync_socket = socket_for_create_callback_->handle();
+#elif defined(OS_WIN)
+ *sync_socket = reinterpret_cast<int>(socket_for_create_callback_->handle());
+#else
+ #error "Platform not supported."
+#endif
+ return PP_OK;
+ }
+ return PP_ERROR_FAILED;
+}
+
+int32_t PPB_AudioInput_Impl::GetSharedMemory(int* shm_handle,
+ uint32_t* shm_size) {
+ if (shared_memory_for_create_callback_.get()) {
+#if defined(OS_POSIX)
+ *shm_handle = shared_memory_for_create_callback_->handle().fd;
+#elif defined(OS_WIN)
+ *shm_handle = reinterpret_cast<int>(
+ shared_memory_for_create_callback_->handle());
+#else
+ #error "Platform not supported."
+#endif
+ *shm_size = shared_memory_size_for_create_callback_;
+ return PP_OK;
+ }
+ return PP_ERROR_FAILED;
+}
+
+void PPB_AudioInput_Impl::StreamCreated(
+ base::SharedMemoryHandle shared_memory_handle,
+ size_t shared_memory_size,
+ base::SyncSocket::Handle socket_handle) {
+ if (create_callback_pending_) {
+ // Trusted side of proxy can specify a callback to recieve handles. In
+ // this case we don't need to map any data or start the thread since it
+ // will be handled by the proxy.
+ shared_memory_for_create_callback_.reset(
+ new base::SharedMemory(shared_memory_handle, false));
+ shared_memory_size_for_create_callback_ = shared_memory_size;
+ socket_for_create_callback_.reset(new base::SyncSocket(socket_handle));
+
+ PP_RunCompletionCallback(&create_callback_, 0);
+ create_callback_pending_ = false;
+
+ // It might be nice to close the handles here to free up some system
+ // resources, but we can't since there's a race condition. The handles must
+ // be valid until they're sent over IPC, which is done from the I/O thread
+ // which will often get done after this code executes. We could do
+ // something more elaborate like an ACK from the plugin or post a task to
+ // the I/O thread and back, but this extra complexity doesn't seem worth it
+ // just to clean up these handles faster.
+ } else {
+ SetStreamInfo(shared_memory_handle, shared_memory_size, socket_handle);
+ }
+}
+
+} // namespace ppapi
+} // namespace webkit
Property changes on: webkit/plugins/ppapi/ppb_audio_input_impl.cc
___________________________________________________________________
Added: svn:executable
+ *

Powered by Google App Engine
This is Rietveld 408576698