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 EnumerateDevices(PP_Resource video_capture
,
34 PP_ArrayOutput output
,
35 PP_CompletionCallback callback
) {
36 EnterVideoCapture
enter(video_capture
, callback
, true);
38 return enter
.retval();
40 return enter
.SetResult(enter
.object()->EnumerateDevices(output
,
44 int32_t MonitorDeviceChange(PP_Resource video_capture
,
45 PP_MonitorDeviceChangeCallback callback
,
47 EnterVideoCapture
enter(video_capture
, true);
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);
60 return enter
.retval();
62 std::string device_id
;
63 // |device_id| remains empty if |device_ref| is 0, which means the default
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);
79 return enter
.retval();
80 return enter
.object()->StartCapture();
83 int32_t ReuseBuffer(PP_Resource video_capture
,
85 EnterVideoCapture
enter(video_capture
, true);
87 return enter
.retval();
88 return enter
.object()->ReuseBuffer(buffer
);
91 int32_t StopCapture(PP_Resource video_capture
) {
92 EnterVideoCapture
enter(video_capture
, true);
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
= {
108 &MonitorDeviceChange
,
118 const PPB_VideoCapture_Dev_0_3
* GetPPB_VideoCapture_Dev_0_3_Thunk() {
119 return &g_ppb_video_capture_0_3_thunk
;