| Index: ppapi/cpp/dev/audio_input_dev.cc
|
| diff --git a/ppapi/cpp/dev/audio_input_dev.cc b/ppapi/cpp/dev/audio_input_dev.cc
|
| index 2429259512949385316a5c48351cba88fdbb0a67..92ad8382b07547e04dc15dc119a8b7f4466e1033 100644
|
| --- a/ppapi/cpp/dev/audio_input_dev.cc
|
| +++ b/ppapi/cpp/dev/audio_input_dev.cc
|
| @@ -4,14 +4,10 @@
|
|
|
| #include "ppapi/cpp/dev/audio_input_dev.h"
|
|
|
| -#include "ppapi/c/dev/ppb_audio_input_dev.h"
|
| #include "ppapi/c/pp_bool.h"
|
| #include "ppapi/c/pp_errors.h"
|
| -#include "ppapi/cpp/completion_callback.h"
|
| -#include "ppapi/cpp/dev/device_ref_dev.h"
|
| #include "ppapi/cpp/dev/resource_array_dev.h"
|
| #include "ppapi/cpp/instance_handle.h"
|
| -#include "ppapi/cpp/module.h"
|
| #include "ppapi/cpp/module_impl.h"
|
|
|
| namespace pp {
|
| @@ -28,25 +24,7 @@ template <> const char* interface_name<PPB_AudioInput_Dev_0_1>() {
|
|
|
| } // namespace
|
|
|
| -struct AudioInput_Dev::EnumerateDevicesState {
|
| - EnumerateDevicesState(std::vector<DeviceRef_Dev>* in_devices,
|
| - const CompletionCallback& in_callback,
|
| - AudioInput_Dev* in_audio_input)
|
| - : devices_resource(0),
|
| - devices(in_devices),
|
| - callback(in_callback),
|
| - audio_input(in_audio_input) {
|
| - }
|
| -
|
| - PP_Resource devices_resource;
|
| - // This is owned by the user of AudioInput_Dev::EnumerateDevices().
|
| - std::vector<DeviceRef_Dev>* devices;
|
| - CompletionCallback callback;
|
| - AudioInput_Dev* audio_input;
|
| -};
|
| -
|
| -AudioInput_Dev::AudioInput_Dev() : enum_state_(NULL),
|
| - audio_input_callback_(NULL),
|
| +AudioInput_Dev::AudioInput_Dev() : audio_input_callback_(NULL),
|
| user_data_(NULL) {
|
| }
|
|
|
| @@ -55,7 +33,6 @@ AudioInput_Dev::AudioInput_Dev(const InstanceHandle& instance,
|
| PPB_AudioInput_Callback callback,
|
| void* user_data)
|
| : config_(config),
|
| - enum_state_(NULL),
|
| audio_input_callback_(callback),
|
| user_data_(user_data) {
|
| if (has_interface<PPB_AudioInput_Dev_0_2>()) {
|
| @@ -68,8 +45,7 @@ AudioInput_Dev::AudioInput_Dev(const InstanceHandle& instance,
|
| }
|
|
|
| AudioInput_Dev::AudioInput_Dev(const InstanceHandle& instance)
|
| - : enum_state_(NULL),
|
| - audio_input_callback_(NULL),
|
| + : audio_input_callback_(NULL),
|
| user_data_(NULL) {
|
| if (has_interface<PPB_AudioInput_Dev_0_2>()) {
|
| PassRefFromConstructor(get_interface<PPB_AudioInput_Dev_0_2>()->Create(
|
| @@ -77,26 +53,7 @@ AudioInput_Dev::AudioInput_Dev(const InstanceHandle& instance)
|
| }
|
| }
|
|
|
| -AudioInput_Dev::AudioInput_Dev(const AudioInput_Dev& other)
|
| - : Resource(other),
|
| - config_(other.config_),
|
| - enum_state_(NULL),
|
| - audio_input_callback_(other.audio_input_callback_),
|
| - user_data_(other.user_data_) {
|
| -}
|
| -
|
| AudioInput_Dev::~AudioInput_Dev() {
|
| - AbortEnumerateDevices();
|
| -}
|
| -
|
| -AudioInput_Dev& AudioInput_Dev::operator=(const AudioInput_Dev& other) {
|
| - AbortEnumerateDevices();
|
| -
|
| - Resource::operator=(other);
|
| - config_ = other.config_;
|
| - audio_input_callback_ = other.audio_input_callback_;
|
| - user_data_ = other.user_data_;
|
| - return *this;
|
| }
|
|
|
| // static
|
| @@ -105,23 +62,21 @@ bool AudioInput_Dev::IsAvailable() {
|
| has_interface<PPB_AudioInput_Dev_0_1>();
|
| }
|
|
|
| -int32_t AudioInput_Dev::EnumerateDevices(std::vector<DeviceRef_Dev>* devices,
|
| - const CompletionCallback& callback) {
|
| +int32_t AudioInput_Dev::EnumerateDevices(
|
| + const CompletionCallbackWithOutput<std::vector<DeviceRef_Dev> >& callback) {
|
| if (!has_interface<PPB_AudioInput_Dev_0_2>())
|
| return callback.MayForce(PP_ERROR_NOINTERFACE);
|
| - if (!devices)
|
| - return callback.MayForce(PP_ERROR_BADARGUMENT);
|
| if (!callback.pp_completion_callback().func)
|
| return callback.MayForce(PP_ERROR_BLOCKS_MAIN_THREAD);
|
| - if (enum_state_)
|
| - return callback.MayForce(PP_ERROR_INPROGRESS);
|
|
|
| - // It will be deleted in OnEnumerateDevicesComplete().
|
| - enum_state_ = new EnumerateDevicesState(devices, callback, this);
|
| + // ArrayOutputCallbackConverter is responsible to delete it.
|
| + ResourceArray_Dev::ArrayOutputCallbackData* data =
|
| + new ResourceArray_Dev::ArrayOutputCallbackData(
|
| + callback.output(), callback.pp_completion_callback());
|
| return get_interface<PPB_AudioInput_Dev_0_2>()->EnumerateDevices(
|
| - pp_resource(), &enum_state_->devices_resource,
|
| - PP_MakeCompletionCallback(&AudioInput_Dev::OnEnumerateDevicesComplete,
|
| - enum_state_));
|
| + pp_resource(), &data->resource_array_output,
|
| + PP_MakeCompletionCallback(
|
| + &ResourceArray_Dev::ArrayOutputCallbackConverter, data));
|
| }
|
|
|
| int32_t AudioInput_Dev::Open(const DeviceRef_Dev& device_ref,
|
| @@ -196,44 +151,4 @@ void AudioInput_Dev::Close() {
|
| get_interface<PPB_AudioInput_Dev_0_2>()->Close(pp_resource());
|
| }
|
|
|
| -void AudioInput_Dev::AbortEnumerateDevices() {
|
| - if (enum_state_) {
|
| - enum_state_->devices = NULL;
|
| - Module::Get()->core()->CallOnMainThread(0, enum_state_->callback,
|
| - PP_ERROR_ABORTED);
|
| - enum_state_->audio_input = NULL;
|
| - enum_state_ = NULL;
|
| - }
|
| -}
|
| -
|
| -// static
|
| -void AudioInput_Dev::OnEnumerateDevicesComplete(void* user_data,
|
| - int32_t result) {
|
| - EnumerateDevicesState* enum_state =
|
| - static_cast<EnumerateDevicesState*>(user_data);
|
| -
|
| - bool need_to_callback = !!enum_state->audio_input;
|
| -
|
| - if (result == PP_OK) {
|
| - // It will take care of releasing the reference.
|
| - ResourceArray_Dev resources(pp::PASS_REF,
|
| - enum_state->devices_resource);
|
| -
|
| - if (need_to_callback) {
|
| - enum_state->devices->clear();
|
| - for (uint32_t index = 0; index < resources.size(); ++index) {
|
| - DeviceRef_Dev device(resources[index]);
|
| - enum_state->devices->push_back(device);
|
| - }
|
| - }
|
| - }
|
| -
|
| - if (need_to_callback) {
|
| - enum_state->audio_input->enum_state_ = NULL;
|
| - enum_state->callback.Run(result);
|
| - }
|
| -
|
| - delete enum_state;
|
| -}
|
| -
|
| } // namespace pp
|
|
|