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"
19 typedef EnterResource
<PPB_VideoCapture_API
> EnterVideoCapture
;
21 PP_Resource
Create(PP_Instance instance
) {
22 EnterResourceCreation
enter(instance
);
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 EnumerateDevices0_2(PP_Resource video_capture
,
35 PP_CompletionCallback callback
) {
36 EnterVideoCapture
enter(video_capture
, callback
, true);
38 return enter
.retval();
40 return enter
.SetResult(enter
.object()->EnumerateDevices0_2(devices
,
44 int32_t EnumerateDevices(PP_Resource video_capture
,
45 PP_ArrayOutput output
,
46 PP_CompletionCallback callback
) {
47 EnterVideoCapture
enter(video_capture
, callback
, true);
49 return enter
.retval();
51 return enter
.SetResult(enter
.object()->EnumerateDevices(output
,
55 int32_t MonitorDeviceChange(PP_Resource video_capture
,
56 PP_MonitorDeviceChangeCallback callback
,
58 EnterVideoCapture
enter(video_capture
, true);
60 return enter
.retval();
61 return enter
.object()->MonitorDeviceChange(callback
, user_data
);
64 int32_t Open(PP_Resource video_capture
,
65 PP_Resource device_ref
,
66 const PP_VideoCaptureDeviceInfo_Dev
* requested_info
,
67 uint32_t buffer_count
,
68 PP_CompletionCallback callback
) {
69 EnterVideoCapture
enter(video_capture
, callback
, true);
71 return enter
.retval();
73 std::string device_id
;
74 // |device_id| remains empty if |device_ref| is 0, which means the default
76 if (device_ref
!= 0) {
77 EnterResourceNoLock
<PPB_DeviceRef_API
> enter_device_ref(device_ref
, true);
78 if (enter_device_ref
.failed())
79 return enter
.SetResult(PP_ERROR_BADRESOURCE
);
80 device_id
= enter_device_ref
.object()->GetDeviceRefData().id
;
83 return enter
.SetResult(enter
.object()->Open(
84 device_id
, *requested_info
, buffer_count
, enter
.callback()));
87 int32_t StartCapture(PP_Resource video_capture
) {
88 EnterVideoCapture
enter(video_capture
, true);
90 return enter
.retval();
91 return enter
.object()->StartCapture();
94 int32_t ReuseBuffer(PP_Resource video_capture
,
96 EnterVideoCapture
enter(video_capture
, true);
98 return enter
.retval();
99 return enter
.object()->ReuseBuffer(buffer
);
102 int32_t StopCapture(PP_Resource video_capture
) {
103 EnterVideoCapture
enter(video_capture
, true);
105 return enter
.retval();
106 return enter
.object()->StopCapture();
109 void Close(PP_Resource video_capture
) {
110 EnterVideoCapture
enter(video_capture
, true);
111 if (enter
.succeeded())
112 enter
.object()->Close();
115 const PPB_VideoCapture_Dev_0_2 g_ppb_video_capture_0_2_thunk
= {
118 &EnumerateDevices0_2
,
126 const PPB_VideoCapture_Dev_0_3 g_ppb_video_capture_0_3_thunk
= {
130 &MonitorDeviceChange
,
140 const PPB_VideoCapture_Dev_0_2
* GetPPB_VideoCapture_Dev_0_2_Thunk() {
141 return &g_ppb_video_capture_0_2_thunk
;
144 const PPB_VideoCapture_Dev_0_3
* GetPPB_VideoCapture_Dev_0_3_Thunk() {
145 return &g_ppb_video_capture_0_3_thunk
;