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

Unified Diff: ppapi/cpp/dev/video_capture_dev.cc

Issue 9965080: Change the cpp wrappers of audio input/video capture to use CompletionCallbackWithOutput. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More changes in response to Brett'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 | « ppapi/cpp/dev/video_capture_dev.h ('k') | ppapi/cpp/output_traits.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/cpp/dev/video_capture_dev.cc
diff --git a/ppapi/cpp/dev/video_capture_dev.cc b/ppapi/cpp/dev/video_capture_dev.cc
index 94ed933fec77a4e21f42d99bb1a7879899a7c74e..4fc11d5f16a7307d8b26d17d6a2744a72f1f4772 100644
--- a/ppapi/cpp/dev/video_capture_dev.cc
+++ b/ppapi/cpp/dev/video_capture_dev.cc
@@ -6,11 +6,8 @@
#include "ppapi/c/dev/ppb_video_capture_dev.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 {
@@ -27,25 +24,8 @@ template <> const char* interface_name<PPB_VideoCapture_Dev_0_1>() {
} // namespace
-struct VideoCapture_Dev::EnumerateDevicesState {
- EnumerateDevicesState(std::vector<DeviceRef_Dev>* in_devices,
- const CompletionCallback& in_callback,
- VideoCapture_Dev* in_video_capture)
- : devices_resource(0),
- devices(in_devices),
- callback(in_callback),
- video_capture(in_video_capture) {
- }
-
- PP_Resource devices_resource;
- std::vector<DeviceRef_Dev>* devices;
- CompletionCallback callback;
- VideoCapture_Dev* video_capture;
-};
-
VideoCapture_Dev::VideoCapture_Dev(const InstanceHandle& instance)
- : enum_state_(NULL),
- requested_info_(),
+ : requested_info_(),
buffer_count_(0) {
if (has_interface<PPB_VideoCapture_Dev_0_2>()) {
PassRefFromConstructor(get_interface<PPB_VideoCapture_Dev_0_2>()->Create(
@@ -58,30 +38,11 @@ VideoCapture_Dev::VideoCapture_Dev(const InstanceHandle& instance)
VideoCapture_Dev::VideoCapture_Dev(PP_Resource resource)
: Resource(resource),
- enum_state_(NULL),
requested_info_(),
buffer_count_(0) {
}
-VideoCapture_Dev::VideoCapture_Dev(const VideoCapture_Dev& other)
- : Resource(other),
- enum_state_(NULL),
- requested_info_(other.requested_info_),
- buffer_count_(other.buffer_count_) {
-}
-
VideoCapture_Dev::~VideoCapture_Dev() {
- AbortEnumerateDevices();
-}
-
-VideoCapture_Dev& VideoCapture_Dev::operator=(
- const VideoCapture_Dev& other) {
- AbortEnumerateDevices();
-
- Resource::operator=(other);
- requested_info_ = other.requested_info_;
- buffer_count_ = other.buffer_count_;
- return *this;
}
// static
@@ -90,23 +51,21 @@ bool VideoCapture_Dev::IsAvailable() {
has_interface<PPB_VideoCapture_Dev_0_1>();
}
-int32_t VideoCapture_Dev::EnumerateDevices(std::vector<DeviceRef_Dev>* devices,
- const CompletionCallback& callback) {
+int32_t VideoCapture_Dev::EnumerateDevices(
+ const CompletionCallbackWithOutput<std::vector<DeviceRef_Dev> >& callback) {
if (!has_interface<PPB_VideoCapture_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_VideoCapture_Dev_0_2>()->EnumerateDevices(
- pp_resource(), &enum_state_->devices_resource,
- PP_MakeCompletionCallback(&VideoCapture_Dev::OnEnumerateDevicesComplete,
- enum_state_));
+ pp_resource(), &data->resource_array_output,
+ PP_MakeCompletionCallback(
+ &ResourceArray_Dev::ArrayOutputCallbackConverter, data));
}
int32_t VideoCapture_Dev::Open(
@@ -179,43 +138,4 @@ void VideoCapture_Dev::Close() {
get_interface<PPB_VideoCapture_Dev_0_2>()->Close(pp_resource());
}
-void VideoCapture_Dev::AbortEnumerateDevices() {
- if (enum_state_) {
- enum_state_->devices = NULL;
- Module::Get()->core()->CallOnMainThread(0, enum_state_->callback,
- PP_ERROR_ABORTED);
- enum_state_->video_capture = NULL;
- enum_state_ = NULL;
- }
-}
-
-// static
-void VideoCapture_Dev::OnEnumerateDevicesComplete(void* user_data,
- int32_t result) {
- EnumerateDevicesState* enum_state =
- static_cast<EnumerateDevicesState*>(user_data);
-
- bool need_to_callback = !!enum_state->video_capture;
-
- 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->video_capture->enum_state_ = NULL;
- enum_state->callback.Run(result);
- }
-
- delete enum_state;
-}
-
} // namespace pp
« no previous file with comments | « ppapi/cpp/dev/video_capture_dev.h ('k') | ppapi/cpp/output_traits.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698