diff options
-rw-r--r-- | ppapi/api/dev/ppb_video_capture_dev.idl | 2 | ||||
-rw-r--r-- | ppapi/cpp/dev/video_capture_dev.cc | 108 | ||||
-rw-r--r-- | ppapi/cpp/dev/video_capture_dev.h | 4 |
3 files changed, 84 insertions, 30 deletions
diff --git a/ppapi/api/dev/ppb_video_capture_dev.idl b/ppapi/api/dev/ppb_video_capture_dev.idl index dd96874..10da4a8 100644 --- a/ppapi/api/dev/ppb_video_capture_dev.idl +++ b/ppapi/api/dev/ppb_video_capture_dev.idl @@ -8,7 +8,7 @@ */ label Chrome { M14 = 0.1, - M18 = 0.2 + M19 = 0.2 }; /** diff --git a/ppapi/cpp/dev/video_capture_dev.cc b/ppapi/cpp/dev/video_capture_dev.cc index c1c60ec..94ed933 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() { diff --git a/ppapi/cpp/dev/video_capture_dev.h b/ppapi/cpp/dev/video_capture_dev.h index 712f9e8..57f6e1d 100644 --- a/ppapi/cpp/dev/video_capture_dev.h +++ b/ppapi/cpp/dev/video_capture_dev.h @@ -53,6 +53,10 @@ class VideoCapture_Dev : public Resource { // Not owned by this object. EnumerateDevicesState* enum_state_; + + // Used to store the arguments of Open() when using the v0.1 interface. + PP_VideoCaptureDeviceInfo_Dev requested_info_; + uint32_t buffer_count_; }; } // namespace pp |