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

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

Issue 9372122: Make VideoCapture_Dev backward compatible. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: sync Created 8 years, 10 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') | no next file » | 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 c1c60ec576d0baebdc639bc4dae10167074330e1..94ed933fec77a4e21f42d99bb1a7879899a7c74e 100644
--- a/ppapi/cpp/dev/video_capture_dev.cc
+++ b/ppapi/cpp/dev/video_capture_dev.cc
@@ -17,8 +17,12 @@ namespace pp {
namespace {
-template <> const char* interface_name<PPB_VideoCapture_Dev>() {
- return PPB_VIDEOCAPTURE_DEV_INTERFACE;
+template <> const char* interface_name<PPB_VideoCapture_Dev_0_2>() {
+ return PPB_VIDEOCAPTURE_DEV_INTERFACE_0_2;
+}
+
+template <> const char* interface_name<PPB_VideoCapture_Dev_0_1>() {
+ return PPB_VIDEOCAPTURE_DEV_INTERFACE_0_1;
}
} // namespace
@@ -40,21 +44,30 @@ struct VideoCapture_Dev::EnumerateDevicesState {
};
VideoCapture_Dev::VideoCapture_Dev(const InstanceHandle& instance)
- : enum_state_(NULL) {
- if (!has_interface<PPB_VideoCapture_Dev>())
- return;
- PassRefFromConstructor(get_interface<PPB_VideoCapture_Dev>()->Create(
- instance.pp_instance()));
+ : enum_state_(NULL),
+ requested_info_(),
+ buffer_count_(0) {
+ if (has_interface<PPB_VideoCapture_Dev_0_2>()) {
+ PassRefFromConstructor(get_interface<PPB_VideoCapture_Dev_0_2>()->Create(
+ instance.pp_instance()));
+ } else if (has_interface<PPB_VideoCapture_Dev_0_1>()) {
+ PassRefFromConstructor(get_interface<PPB_VideoCapture_Dev_0_1>()->Create(
+ instance.pp_instance()));
+ }
}
VideoCapture_Dev::VideoCapture_Dev(PP_Resource resource)
: Resource(resource),
- enum_state_(NULL) {
+ enum_state_(NULL),
+ requested_info_(),
+ buffer_count_(0) {
}
VideoCapture_Dev::VideoCapture_Dev(const VideoCapture_Dev& other)
: Resource(other),
- enum_state_(NULL) {
+ enum_state_(NULL),
+ requested_info_(other.requested_info_),
+ buffer_count_(other.buffer_count_) {
}
VideoCapture_Dev::~VideoCapture_Dev() {
@@ -66,17 +79,20 @@ VideoCapture_Dev& VideoCapture_Dev::operator=(
AbortEnumerateDevices();
Resource::operator=(other);
+ requested_info_ = other.requested_info_;
+ buffer_count_ = other.buffer_count_;
return *this;
}
// static
bool VideoCapture_Dev::IsAvailable() {
- return has_interface<PPB_VideoCapture_Dev>();
+ return has_interface<PPB_VideoCapture_Dev_0_2>() ||
+ has_interface<PPB_VideoCapture_Dev_0_1>();
}
int32_t VideoCapture_Dev::EnumerateDevices(std::vector<DeviceRef_Dev>* devices,
const CompletionCallback& callback) {
- if (!has_interface<PPB_VideoCapture_Dev>())
+ if (!has_interface<PPB_VideoCapture_Dev_0_2>())
return callback.MayForce(PP_ERROR_NOINTERFACE);
if (!devices)
return callback.MayForce(PP_ERROR_BADARGUMENT);
@@ -87,7 +103,7 @@ int32_t VideoCapture_Dev::EnumerateDevices(std::vector<DeviceRef_Dev>* devices,
// It will be deleted in OnEnumerateDevicesComplete().
enum_state_ = new EnumerateDevicesState(devices, callback, this);
- return get_interface<PPB_VideoCapture_Dev>()->EnumerateDevices(
+ return get_interface<PPB_VideoCapture_Dev_0_2>()->EnumerateDevices(
pp_resource(), &enum_state_->devices_resource,
PP_MakeCompletionCallback(&VideoCapture_Dev::OnEnumerateDevicesComplete,
enum_state_));
@@ -98,35 +114,69 @@ int32_t VideoCapture_Dev::Open(
const PP_VideoCaptureDeviceInfo_Dev& requested_info,
uint32_t buffer_count,
const CompletionCallback& callback) {
- if (!has_interface<PPB_VideoCapture_Dev>())
- return callback.MayForce(PP_ERROR_NOINTERFACE);
- return get_interface<PPB_VideoCapture_Dev>()->Open(
- pp_resource(), device_ref.pp_resource(), &requested_info, buffer_count,
- callback.pp_completion_callback());
+ if (has_interface<PPB_VideoCapture_Dev_0_2>()) {
+ return get_interface<PPB_VideoCapture_Dev_0_2>()->Open(
+ pp_resource(), device_ref.pp_resource(), &requested_info, buffer_count,
+ callback.pp_completion_callback());
+ }
+
+ if (has_interface<PPB_VideoCapture_Dev_0_1>()) {
+ if (device_ref.is_null()) {
+ requested_info_ = requested_info;
+ buffer_count_ = buffer_count;
+ return callback.MayForce(PP_OK);
+ }
+ return callback.MayForce(PP_ERROR_NOTSUPPORTED);
+ }
+
+ return callback.MayForce(PP_ERROR_NOINTERFACE);
}
int32_t VideoCapture_Dev::StartCapture() {
- if (!has_interface<PPB_VideoCapture_Dev>())
- return PP_ERROR_NOINTERFACE;
- return get_interface<PPB_VideoCapture_Dev>()->StartCapture(pp_resource());
+ if (has_interface<PPB_VideoCapture_Dev_0_2>()) {
+ return get_interface<PPB_VideoCapture_Dev_0_2>()->StartCapture(
+ pp_resource());
+ }
+
+ if (has_interface<PPB_VideoCapture_Dev_0_1>()) {
+ return get_interface<PPB_VideoCapture_Dev_0_1>()->StartCapture(
+ pp_resource(), &requested_info_, buffer_count_);
+ }
+
+ return PP_ERROR_NOINTERFACE;
}
int32_t VideoCapture_Dev::ReuseBuffer(uint32_t buffer) {
- if (!has_interface<PPB_VideoCapture_Dev>())
- return PP_ERROR_NOINTERFACE;
- return get_interface<PPB_VideoCapture_Dev>()->ReuseBuffer(
- pp_resource(), buffer);
+ if (has_interface<PPB_VideoCapture_Dev_0_2>()) {
+ return get_interface<PPB_VideoCapture_Dev_0_2>()->ReuseBuffer(pp_resource(),
+ buffer);
+ }
+
+ if (has_interface<PPB_VideoCapture_Dev_0_1>()) {
+ return get_interface<PPB_VideoCapture_Dev_0_1>()->ReuseBuffer(pp_resource(),
+ buffer);
+ }
+
+ return PP_ERROR_NOINTERFACE;
}
int32_t VideoCapture_Dev::StopCapture() {
- if (!has_interface<PPB_VideoCapture_Dev>())
- return PP_ERROR_NOINTERFACE;
- return get_interface<PPB_VideoCapture_Dev>()->StopCapture(pp_resource());
+ if (has_interface<PPB_VideoCapture_Dev_0_2>()) {
+ return get_interface<PPB_VideoCapture_Dev_0_2>()->StopCapture(
+ pp_resource());
+ }
+
+ if (has_interface<PPB_VideoCapture_Dev_0_1>()) {
+ return get_interface<PPB_VideoCapture_Dev_0_1>()->StopCapture(
+ pp_resource());
+ }
+
+ return PP_ERROR_NOINTERFACE;
}
void VideoCapture_Dev::Close() {
- if (has_interface<PPB_VideoCapture_Dev>())
- get_interface<PPB_VideoCapture_Dev>()->Close(pp_resource());
+ if (has_interface<PPB_VideoCapture_Dev_0_2>())
+ get_interface<PPB_VideoCapture_Dev_0_2>()->Close(pp_resource());
}
void VideoCapture_Dev::AbortEnumerateDevices() {
« no previous file with comments | « ppapi/cpp/dev/video_capture_dev.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698