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

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

Issue 9557007: PPB_AudioInput_Dev: support multiple audio input devices - Part 1. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changes in response to Trung's comments. Created 8 years, 9 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
« no previous file with comments | « webkit/plugins/ppapi/ppb_audio_input_impl.h ('k') | webkit/plugins/ppapi/resource_creation_impl.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/plugins/ppapi/ppb_audio_input_impl.cc
diff --git a/webkit/plugins/ppapi/ppb_audio_input_impl.cc b/webkit/plugins/ppapi/ppb_audio_input_impl.cc
index ff9cb06e2322b93bb87d86a6bb95c07bcd56ff71..a46db98a14419565ad392548bd9093fe4ee365ad 100644
--- a/webkit/plugins/ppapi/ppb_audio_input_impl.cc
+++ b/webkit/plugins/ppapi/ppb_audio_input_impl.cc
@@ -4,22 +4,18 @@
#include "webkit/plugins/ppapi/ppb_audio_input_impl.h"
+#include "base/bind.h"
#include "base/logging.h"
-#include "ppapi/c/dev/ppb_audio_input_dev.h"
+#include "base/memory/ref_counted.h"
+#include "base/shared_memory.h"
+#include "base/sync_socket.h"
+#include "build/build_config.h"
#include "ppapi/c/pp_completion_callback.h"
-#include "ppapi/c/ppb_audio_config.h"
-#include "ppapi/c/trusted/ppb_audio_input_trusted_dev.h"
-#include "ppapi/shared_impl/resource_tracker.h"
-#include "ppapi/thunk/enter.h"
-#include "ppapi/thunk/ppb_audio_config_api.h"
-#include "ppapi/thunk/thunk.h"
+#include "ppapi/shared_impl/ppb_device_ref_shared.h"
+#include "ppapi/shared_impl/tracked_callback.h"
#include "webkit/plugins/ppapi/common.h"
#include "webkit/plugins/ppapi/resource_helper.h"
-using ppapi::PpapiGlobals;
-using ppapi::thunk::EnterResourceNoLock;
-using ppapi::thunk::PPB_AudioInput_API;
-using ppapi::thunk::PPB_AudioConfig_API;
using ppapi::TrackedCallback;
namespace webkit {
@@ -28,135 +24,154 @@ namespace ppapi {
// PPB_AudioInput_Impl ---------------------------------------------------------
PPB_AudioInput_Impl::PPB_AudioInput_Impl(PP_Instance instance)
- : Resource(::ppapi::OBJECT_IS_IMPL, instance),
+ : ::ppapi::PPB_AudioInput_Shared(instance),
audio_input_(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;
- }
+ Close();
}
// static
-PP_Resource PPB_AudioInput_Impl::Create(
+PP_Resource PPB_AudioInput_Impl::Create0_1(
PP_Instance instance,
PP_Resource config,
PPB_AudioInput_Callback audio_input_callback,
void* user_data) {
scoped_refptr<PPB_AudioInput_Impl>
audio_input(new PPB_AudioInput_Impl(instance));
- if (!audio_input->Init(config, audio_input_callback, user_data))
+ int32_t result = audio_input->Open(
+ "", config, audio_input_callback, user_data,
+ MakeIgnoredCompletionCallback());
+ if (result != PP_OK && result != PP_OK_COMPLETIONPENDING)
return 0;
return audio_input->GetReference();
}
-PPB_AudioInput_API* PPB_AudioInput_Impl::AsPPB_AudioInput_API() {
- return this;
+int32_t PPB_AudioInput_Impl::OpenTrusted(
+ const std::string& device_id,
+ PP_Resource config,
+ PP_CompletionCallback create_callback) {
+ return CommonOpen(device_id, config, NULL, NULL, create_callback);
}
-bool PPB_AudioInput_Impl::Init(PP_Resource config,
- PPB_AudioInput_Callback callback,
- void* user_data) {
- // Validate the config and keep a reference to it.
- EnterResourceNoLock<PPB_AudioConfig_API> enter(config, true);
- if (enter.failed())
- return false;
- config_ = config;
+int32_t PPB_AudioInput_Impl::GetSyncSocket(int* sync_socket) {
+ if (socket_.get()) {
+#if defined(OS_POSIX)
+ *sync_socket = socket_->handle();
+#elif defined(OS_WIN)
+ *sync_socket = reinterpret_cast<int>(socket_->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_.get()) {
+#if defined(OS_POSIX)
+ *shm_handle = shared_memory_->handle().fd;
+#elif defined(OS_WIN)
+ *shm_handle = reinterpret_cast<int>(shared_memory_->handle());
+#else
+ #error "Platform not supported."
+#endif
+ *shm_size = shared_memory_size_;
+ return PP_OK;
+ }
+ return PP_ERROR_FAILED;
+}
- if (!callback)
- return false;
- SetCallback(callback, user_data);
+const PPB_AudioInput_Impl::DeviceRefDataVector&
+ PPB_AudioInput_Impl::GetDeviceRefData() const {
+ return devices_data_;
+}
+void PPB_AudioInput_Impl::StreamCreated(
+ base::SharedMemoryHandle shared_memory_handle,
+ size_t shared_memory_size,
+ base::SyncSocket::Handle socket) {
+ // TODO(yzshen): Report open failure.
+ OnOpenComplete(PP_OK, shared_memory_handle, shared_memory_size, socket);
+}
+
+int32_t PPB_AudioInput_Impl::InternalEnumerateDevices(
+ PP_Resource* devices,
+ PP_CompletionCallback callback) {
PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
if (!plugin_delegate)
- return false;
+ return PP_ERROR_FAILED;
- // When the stream is created, we'll get called back on StreamCreated().
- CHECK(!audio_input_);
- audio_input_ = plugin_delegate->CreateAudioInput(
- enter.object()->GetSampleRate(),
- enter.object()->GetSampleFrameCount(),
- this);
- return audio_input_ != NULL;
+ devices_ = devices;
+ enumerate_devices_callback_ = new TrackedCallback(this, callback);
+ plugin_delegate->EnumerateDevices(
+ PP_DEVICETYPE_DEV_AUDIOCAPTURE,
+ base::Bind(&PPB_AudioInput_Impl::EnumerateDevicesCallbackFunc,
+ AsWeakPtr()));
+ return PP_OK_COMPLETIONPENDING;
}
-PP_Resource PPB_AudioInput_Impl::GetCurrentConfig() {
- // AddRef on behalf of caller, while keeping a ref for ourselves.
- PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(config_);
- return config_;
+int32_t PPB_AudioInput_Impl::InternalOpen(const std::string& device_id,
+ PP_AudioSampleRate sample_rate,
+ uint32_t sample_frame_count,
+ PP_CompletionCallback callback) {
+ PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this);
+ if (!plugin_delegate)
+ return PP_ERROR_FAILED;
+
+ // TODO(yzshen): Open the device specified by |device_id|.
+ // When the stream is created, we'll get called back on StreamCreated().
+ DCHECK(!audio_input_);
+ audio_input_ = plugin_delegate->CreateAudioInput(
+ sample_rate, sample_frame_count, this);
+ if (audio_input_) {
+ open_callback_ = new TrackedCallback(this, callback);
+ return PP_OK_COMPLETIONPENDING;
+ } else {
+ return PP_ERROR_FAILED;
+ }
}
-PP_Bool PPB_AudioInput_Impl::StartCapture() {
+PP_Bool PPB_AudioInput_Impl::InternalStartCapture() {
if (!audio_input_)
return PP_FALSE;
- if (capturing())
- return PP_TRUE;
SetStartCaptureState();
return BoolToPPBool(audio_input_->StartCapture());
}
-PP_Bool PPB_AudioInput_Impl::StopCapture() {
+PP_Bool PPB_AudioInput_Impl::InternalStopCapture() {
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_Resource config,
- PP_CompletionCallback create_callback) {
- // Validate the config and keep a reference to it.
- EnterResourceNoLock<PPB_AudioConfig_API> enter(config, true);
- if (enter.failed())
- return PP_ERROR_FAILED;
- config_ = config;
-
- 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(
- enter.object()->GetSampleRate(),
- enter.object()->GetSampleFrameCount(),
- 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.
- SetCreateCallback(new TrackedCallback(this, create_callback));
- return PP_OK_COMPLETIONPENDING;
-}
-
-int32_t PPB_AudioInput_Impl::GetSyncSocket(int* sync_socket) {
- return GetSyncSocketImpl(sync_socket);
+void PPB_AudioInput_Impl::InternalClose() {
+ // 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 OnOpenComplete() will clean up the handles and do nothing else in
+ // that case.
+ if (audio_input_) {
+ audio_input_->ShutDown();
+ audio_input_ = NULL;
+ }
}
-int32_t PPB_AudioInput_Impl::GetSharedMemory(int* shm_handle,
- uint32_t* shm_size) {
- return GetSharedMemoryImpl(shm_handle, shm_size);
-}
+void PPB_AudioInput_Impl::EnumerateDevicesCallbackFunc(
+ int request_id,
+ bool succeeded,
+ const DeviceRefDataVector& devices) {
+ devices_data_.clear();
+ if (succeeded)
+ devices_data_ = devices;
-void PPB_AudioInput_Impl::OnSetStreamInfo(
- base::SharedMemoryHandle shared_memory_handle,
- size_t shared_memory_size,
- base::SyncSocket::Handle socket_handle) {
- SetStreamInfo(shared_memory_handle, shared_memory_size, socket_handle);
+ OnEnumerateDevicesComplete(succeeded ? PP_OK : PP_ERROR_FAILED, devices);
}
} // namespace ppapi
« no previous file with comments | « webkit/plugins/ppapi/ppb_audio_input_impl.h ('k') | webkit/plugins/ppapi/resource_creation_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698