1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "ppapi/cpp/dev/video_capture_dev.h"
6
7 #include "ppapi/c/dev/ppb_video_capture_dev.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/cpp/instance_handle.h"
10 #include "ppapi/cpp/module_impl.h"
11
12 namespace pp {
13
14 namespace {
15
interface_name()16 template <> const char* interface_name<PPB_VideoCapture_Dev_0_3>() {
17 return PPB_VIDEOCAPTURE_DEV_INTERFACE_0_3;
18 }
19
20 } // namespace
21
VideoCapture_Dev(const InstanceHandle & instance)22 VideoCapture_Dev::VideoCapture_Dev(const InstanceHandle& instance) {
23 if (has_interface<PPB_VideoCapture_Dev_0_3>()) {
24 PassRefFromConstructor(get_interface<PPB_VideoCapture_Dev_0_3>()->Create(
25 instance.pp_instance()));
26 }
27 }
28
VideoCapture_Dev(PP_Resource resource)29 VideoCapture_Dev::VideoCapture_Dev(PP_Resource resource)
30 : Resource(resource) {
31 }
32
~VideoCapture_Dev()33 VideoCapture_Dev::~VideoCapture_Dev() {
34 }
35
36 // static
IsAvailable()37 bool VideoCapture_Dev::IsAvailable() {
38 return has_interface<PPB_VideoCapture_Dev_0_3>();
39 }
40
EnumerateDevices(const CompletionCallbackWithOutput<std::vector<DeviceRef_Dev>> & callback)41 int32_t VideoCapture_Dev::EnumerateDevices(
42 const CompletionCallbackWithOutput<std::vector<DeviceRef_Dev> >& callback) {
43 if (has_interface<PPB_VideoCapture_Dev_0_3>()) {
44 return get_interface<PPB_VideoCapture_Dev_0_3>()->EnumerateDevices(
45 pp_resource(), callback.output(), callback.pp_completion_callback());
46 }
47
48 return callback.MayForce(PP_ERROR_NOINTERFACE);
49 }
50
MonitorDeviceChange(PP_MonitorDeviceChangeCallback callback,void * user_data)51 int32_t VideoCapture_Dev::MonitorDeviceChange(
52 PP_MonitorDeviceChangeCallback callback,
53 void* user_data) {
54 if (has_interface<PPB_VideoCapture_Dev_0_3>()) {
55 return get_interface<PPB_VideoCapture_Dev_0_3>()->MonitorDeviceChange(
56 pp_resource(), callback, user_data);
57 }
58
59 return PP_ERROR_NOINTERFACE;
60 }
61
Open(const DeviceRef_Dev & device_ref,const PP_VideoCaptureDeviceInfo_Dev & requested_info,uint32_t buffer_count,const CompletionCallback & callback)62 int32_t VideoCapture_Dev::Open(
63 const DeviceRef_Dev& device_ref,
64 const PP_VideoCaptureDeviceInfo_Dev& requested_info,
65 uint32_t buffer_count,
66 const CompletionCallback& callback) {
67 if (has_interface<PPB_VideoCapture_Dev_0_3>()) {
68 return get_interface<PPB_VideoCapture_Dev_0_3>()->Open(
69 pp_resource(), device_ref.pp_resource(), &requested_info, buffer_count,
70 callback.pp_completion_callback());
71 }
72
73 return callback.MayForce(PP_ERROR_NOINTERFACE);
74 }
75
StartCapture()76 int32_t VideoCapture_Dev::StartCapture() {
77 if (has_interface<PPB_VideoCapture_Dev_0_3>()) {
78 return get_interface<PPB_VideoCapture_Dev_0_3>()->StartCapture(
79 pp_resource());
80 }
81
82 return PP_ERROR_NOINTERFACE;
83 }
84
ReuseBuffer(uint32_t buffer)85 int32_t VideoCapture_Dev::ReuseBuffer(uint32_t buffer) {
86 if (has_interface<PPB_VideoCapture_Dev_0_3>()) {
87 return get_interface<PPB_VideoCapture_Dev_0_3>()->ReuseBuffer(pp_resource(),
88 buffer);
89 }
90
91 return PP_ERROR_NOINTERFACE;
92 }
93
StopCapture()94 int32_t VideoCapture_Dev::StopCapture() {
95 if (has_interface<PPB_VideoCapture_Dev_0_3>()) {
96 return get_interface<PPB_VideoCapture_Dev_0_3>()->StopCapture(
97 pp_resource());
98 }
99
100 return PP_ERROR_NOINTERFACE;
101 }
102
Close()103 void VideoCapture_Dev::Close() {
104 if (has_interface<PPB_VideoCapture_Dev_0_3>()) {
105 get_interface<PPB_VideoCapture_Dev_0_3>()->Close(pp_resource());
106 }
107 }
108
109 } // namespace pp
110