Roll leveldb from r73 to r75.
[chromium-blink-merge.git] / ppapi / cpp / dev / video_capture_dev.cc
blob46fdb5973ca84873eee0cfef9e8a6f8877dcfff9
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.
5 #include "ppapi/cpp/dev/video_capture_dev.h"
7 #include "ppapi/c/dev/ppb_video_capture_dev.h"
8 #include "ppapi/c/pp_errors.h"
9 #include "ppapi/cpp/dev/resource_array_dev.h"
10 #include "ppapi/cpp/instance_handle.h"
11 #include "ppapi/cpp/module_impl.h"
13 namespace pp {
15 namespace {
17 template <> const char* interface_name<PPB_VideoCapture_Dev_0_2>() {
18 return PPB_VIDEOCAPTURE_DEV_INTERFACE_0_2;
21 template <> const char* interface_name<PPB_VideoCapture_Dev_0_3>() {
22 return PPB_VIDEOCAPTURE_DEV_INTERFACE_0_3;
25 } // namespace
27 VideoCapture_Dev::VideoCapture_Dev(const InstanceHandle& instance) {
28 if (has_interface<PPB_VideoCapture_Dev_0_3>()) {
29 PassRefFromConstructor(get_interface<PPB_VideoCapture_Dev_0_3>()->Create(
30 instance.pp_instance()));
31 } else if (has_interface<PPB_VideoCapture_Dev_0_2>()) {
32 PassRefFromConstructor(get_interface<PPB_VideoCapture_Dev_0_2>()->Create(
33 instance.pp_instance()));
37 VideoCapture_Dev::VideoCapture_Dev(PP_Resource resource)
38 : Resource(resource) {
41 VideoCapture_Dev::~VideoCapture_Dev() {
44 // static
45 bool VideoCapture_Dev::IsAvailable() {
46 return has_interface<PPB_VideoCapture_Dev_0_3>() ||
47 has_interface<PPB_VideoCapture_Dev_0_2>();
50 int32_t VideoCapture_Dev::EnumerateDevices(
51 const CompletionCallbackWithOutput<std::vector<DeviceRef_Dev> >& callback) {
52 if (has_interface<PPB_VideoCapture_Dev_0_3>()) {
53 return get_interface<PPB_VideoCapture_Dev_0_3>()->EnumerateDevices(
54 pp_resource(), callback.output(), callback.pp_completion_callback());
57 if (has_interface<PPB_VideoCapture_Dev_0_2>()) {
58 if (!callback.pp_completion_callback().func)
59 return callback.MayForce(PP_ERROR_BLOCKS_MAIN_THREAD);
61 // ArrayOutputCallbackConverter is responsible to delete it.
62 ResourceArray_Dev::ArrayOutputCallbackData* data =
63 new ResourceArray_Dev::ArrayOutputCallbackData(
64 callback.output(), callback.pp_completion_callback());
65 return get_interface<PPB_VideoCapture_Dev_0_2>()->EnumerateDevices(
66 pp_resource(), &data->resource_array_output,
67 PP_MakeCompletionCallback(
68 &ResourceArray_Dev::ArrayOutputCallbackConverter, data));
71 return callback.MayForce(PP_ERROR_NOINTERFACE);
74 int32_t VideoCapture_Dev::MonitorDeviceChange(
75 PP_MonitorDeviceChangeCallback callback,
76 void* user_data) {
77 if (has_interface<PPB_VideoCapture_Dev_0_3>()) {
78 return get_interface<PPB_VideoCapture_Dev_0_3>()->MonitorDeviceChange(
79 pp_resource(), callback, user_data);
82 return PP_ERROR_NOINTERFACE;
85 int32_t VideoCapture_Dev::Open(
86 const DeviceRef_Dev& device_ref,
87 const PP_VideoCaptureDeviceInfo_Dev& requested_info,
88 uint32_t buffer_count,
89 const CompletionCallback& callback) {
90 if (has_interface<PPB_VideoCapture_Dev_0_3>()) {
91 return get_interface<PPB_VideoCapture_Dev_0_3>()->Open(
92 pp_resource(), device_ref.pp_resource(), &requested_info, buffer_count,
93 callback.pp_completion_callback());
95 if (has_interface<PPB_VideoCapture_Dev_0_2>()) {
96 return get_interface<PPB_VideoCapture_Dev_0_2>()->Open(
97 pp_resource(), device_ref.pp_resource(), &requested_info, buffer_count,
98 callback.pp_completion_callback());
101 return callback.MayForce(PP_ERROR_NOINTERFACE);
104 int32_t VideoCapture_Dev::StartCapture() {
105 if (has_interface<PPB_VideoCapture_Dev_0_3>()) {
106 return get_interface<PPB_VideoCapture_Dev_0_3>()->StartCapture(
107 pp_resource());
109 if (has_interface<PPB_VideoCapture_Dev_0_2>()) {
110 return get_interface<PPB_VideoCapture_Dev_0_2>()->StartCapture(
111 pp_resource());
114 return PP_ERROR_NOINTERFACE;
117 int32_t VideoCapture_Dev::ReuseBuffer(uint32_t buffer) {
118 if (has_interface<PPB_VideoCapture_Dev_0_3>()) {
119 return get_interface<PPB_VideoCapture_Dev_0_3>()->ReuseBuffer(pp_resource(),
120 buffer);
122 if (has_interface<PPB_VideoCapture_Dev_0_2>()) {
123 return get_interface<PPB_VideoCapture_Dev_0_2>()->ReuseBuffer(pp_resource(),
124 buffer);
127 return PP_ERROR_NOINTERFACE;
130 int32_t VideoCapture_Dev::StopCapture() {
131 if (has_interface<PPB_VideoCapture_Dev_0_3>()) {
132 return get_interface<PPB_VideoCapture_Dev_0_3>()->StopCapture(
133 pp_resource());
135 if (has_interface<PPB_VideoCapture_Dev_0_2>()) {
136 return get_interface<PPB_VideoCapture_Dev_0_2>()->StopCapture(
137 pp_resource());
140 return PP_ERROR_NOINTERFACE;
143 void VideoCapture_Dev::Close() {
144 if (has_interface<PPB_VideoCapture_Dev_0_3>()) {
145 get_interface<PPB_VideoCapture_Dev_0_3>()->Close(pp_resource());
146 } else if (has_interface<PPB_VideoCapture_Dev_0_2>()) {
147 get_interface<PPB_VideoCapture_Dev_0_2>()->Close(pp_resource());
151 } // namespace pp