Revert of Update WV test license server config to use portable sdk server. (https...
[chromium-blink-merge.git] / ppapi / thunk / ppb_video_capture_thunk.cc
blob83772a53f5ca7dcc15df35dd9bc10515fc644713
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/c/pp_errors.h"
6 #include "ppapi/shared_impl/ppb_device_ref_shared.h"
7 #include "ppapi/shared_impl/tracked_callback.h"
8 #include "ppapi/thunk/enter.h"
9 #include "ppapi/thunk/ppb_device_ref_api.h"
10 #include "ppapi/thunk/ppb_video_capture_api.h"
11 #include "ppapi/thunk/resource_creation_api.h"
12 #include "ppapi/thunk/thunk.h"
14 namespace ppapi {
15 namespace thunk {
17 namespace {
19 typedef EnterResource<PPB_VideoCapture_API> EnterVideoCapture;
21 PP_Resource Create(PP_Instance instance) {
22 EnterResourceCreation enter(instance);
23 if (enter.failed())
24 return 0;
25 return enter.functions()->CreateVideoCapture(instance);
28 PP_Bool IsVideoCapture(PP_Resource resource) {
29 EnterVideoCapture enter(resource, false);
30 return PP_FromBool(enter.succeeded());
33 int32_t EnumerateDevices(PP_Resource video_capture,
34 PP_ArrayOutput output,
35 PP_CompletionCallback callback) {
36 EnterVideoCapture enter(video_capture, callback, true);
37 if (enter.failed())
38 return enter.retval();
40 return enter.SetResult(enter.object()->EnumerateDevices(output,
41 enter.callback()));
44 int32_t MonitorDeviceChange(PP_Resource video_capture,
45 PP_MonitorDeviceChangeCallback callback,
46 void* user_data) {
47 EnterVideoCapture enter(video_capture, true);
48 if (enter.failed())
49 return enter.retval();
50 return enter.object()->MonitorDeviceChange(callback, user_data);
53 int32_t Open(PP_Resource video_capture,
54 PP_Resource device_ref,
55 const PP_VideoCaptureDeviceInfo_Dev* requested_info,
56 uint32_t buffer_count,
57 PP_CompletionCallback callback) {
58 EnterVideoCapture enter(video_capture, callback, true);
59 if (enter.failed())
60 return enter.retval();
62 std::string device_id;
63 // |device_id| remains empty if |device_ref| is 0, which means the default
64 // device.
65 if (device_ref != 0) {
66 EnterResourceNoLock<PPB_DeviceRef_API> enter_device_ref(device_ref, true);
67 if (enter_device_ref.failed())
68 return enter.SetResult(PP_ERROR_BADRESOURCE);
69 device_id = enter_device_ref.object()->GetDeviceRefData().id;
72 return enter.SetResult(enter.object()->Open(
73 device_id, *requested_info, buffer_count, enter.callback()));
76 int32_t StartCapture(PP_Resource video_capture) {
77 EnterVideoCapture enter(video_capture, true);
78 if (enter.failed())
79 return enter.retval();
80 return enter.object()->StartCapture();
83 int32_t ReuseBuffer(PP_Resource video_capture,
84 uint32_t buffer) {
85 EnterVideoCapture enter(video_capture, true);
86 if (enter.failed())
87 return enter.retval();
88 return enter.object()->ReuseBuffer(buffer);
91 int32_t StopCapture(PP_Resource video_capture) {
92 EnterVideoCapture enter(video_capture, true);
93 if (enter.failed())
94 return enter.retval();
95 return enter.object()->StopCapture();
98 void Close(PP_Resource video_capture) {
99 EnterVideoCapture enter(video_capture, true);
100 if (enter.succeeded())
101 enter.object()->Close();
104 const PPB_VideoCapture_Dev_0_3 g_ppb_video_capture_0_3_thunk = {
105 &Create,
106 &IsVideoCapture,
107 &EnumerateDevices,
108 &MonitorDeviceChange,
109 &Open,
110 &StartCapture,
111 &ReuseBuffer,
112 &StopCapture,
113 &Close
116 } // namespace
118 const PPB_VideoCapture_Dev_0_3* GetPPB_VideoCapture_Dev_0_3_Thunk() {
119 return &g_ppb_video_capture_0_3_thunk;
122 } // namespace thunk
123 } // namespace ppapi