OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ppapi/c/pp_errors.h" | 5 #include "ppapi/c/pp_errors.h" |
| 6 #include "ppapi/shared_impl/ppb_device_ref_shared.h" |
6 #include "ppapi/thunk/common.h" | 7 #include "ppapi/thunk/common.h" |
7 #include "ppapi/thunk/enter.h" | 8 #include "ppapi/thunk/enter.h" |
8 #include "ppapi/thunk/thunk.h" | 9 #include "ppapi/thunk/ppb_device_ref_api.h" |
9 #include "ppapi/thunk/ppb_video_capture_api.h" | 10 #include "ppapi/thunk/ppb_video_capture_api.h" |
10 #include "ppapi/thunk/resource_creation_api.h" | 11 #include "ppapi/thunk/resource_creation_api.h" |
| 12 #include "ppapi/thunk/thunk.h" |
11 | 13 |
12 namespace ppapi { | 14 namespace ppapi { |
13 namespace thunk { | 15 namespace thunk { |
14 | 16 |
15 namespace { | 17 namespace { |
16 | 18 |
17 typedef EnterResource<PPB_VideoCapture_API> EnterVideoCapture; | 19 typedef EnterResource<PPB_VideoCapture_API> EnterVideoCapture; |
18 | 20 |
19 PP_Resource Create(PP_Instance instance) { | 21 PP_Resource Create(PP_Instance instance) { |
20 EnterFunction<ResourceCreationAPI> enter(instance, true); | 22 EnterFunction<ResourceCreationAPI> enter(instance, true); |
21 if (enter.failed()) | 23 if (enter.failed()) |
22 return 0; | 24 return 0; |
23 return enter.functions()->CreateVideoCapture(instance); | 25 return enter.functions()->CreateVideoCapture(instance); |
24 } | 26 } |
25 | 27 |
26 PP_Bool IsVideoCapture(PP_Resource resource) { | 28 PP_Bool IsVideoCapture(PP_Resource resource) { |
27 EnterVideoCapture enter(resource, false); | 29 EnterVideoCapture enter(resource, false); |
28 return PP_FromBool(enter.succeeded()); | 30 return PP_FromBool(enter.succeeded()); |
29 } | 31 } |
30 | 32 |
31 int32_t StartCapture(PP_Resource video_capture, | 33 int32_t EnumerateDevices(PP_Resource video_capture, |
32 const PP_VideoCaptureDeviceInfo_Dev* requested_info, | 34 PP_Resource* devices, |
33 uint32_t buffer_count) { | 35 PP_CompletionCallback callback) { |
| 36 EnterVideoCapture enter(video_capture, true); |
| 37 if (enter.failed()) |
| 38 return MayForceCallback(callback, PP_ERROR_BADRESOURCE); |
| 39 |
| 40 int32_t result = enter.object()->EnumerateDevices(devices, callback); |
| 41 return MayForceCallback(callback, result); |
| 42 } |
| 43 |
| 44 int32_t Open(PP_Resource video_capture, |
| 45 PP_Resource device_ref, |
| 46 const PP_VideoCaptureDeviceInfo_Dev* requested_info, |
| 47 uint32_t buffer_count, |
| 48 PP_CompletionCallback callback) { |
| 49 EnterVideoCapture enter(video_capture, true); |
| 50 if (enter.failed()) |
| 51 return MayForceCallback(callback, PP_ERROR_BADRESOURCE); |
| 52 |
| 53 std::string device_id; |
| 54 // |device_id| remains empty if |device_ref| is 0, which means the default |
| 55 // device. |
| 56 if (device_ref != 0) { |
| 57 EnterResourceNoLock<PPB_DeviceRef_API> enter_device_ref(device_ref, true); |
| 58 if (enter_device_ref.failed()) |
| 59 return MayForceCallback(callback, PP_ERROR_BADRESOURCE); |
| 60 device_id = enter_device_ref.object()->GetDeviceRefData().id; |
| 61 } |
| 62 |
| 63 int32_t result = enter.object()->Open( |
| 64 device_id, *requested_info, buffer_count, callback); |
| 65 return MayForceCallback(callback, result); |
| 66 } |
| 67 |
| 68 int32_t StartCapture(PP_Resource video_capture) { |
34 EnterVideoCapture enter(video_capture, true); | 69 EnterVideoCapture enter(video_capture, true); |
35 if (enter.failed()) | 70 if (enter.failed()) |
36 return PP_ERROR_BADRESOURCE; | 71 return PP_ERROR_BADRESOURCE; |
37 | 72 |
38 return enter.object()->StartCapture(*requested_info, buffer_count); | 73 return enter.object()->StartCapture(); |
39 } | 74 } |
40 | 75 |
41 int32_t ReuseBuffer(PP_Resource video_capture, | 76 int32_t ReuseBuffer(PP_Resource video_capture, |
42 uint32_t buffer) { | 77 uint32_t buffer) { |
43 EnterVideoCapture enter(video_capture, true); | 78 EnterVideoCapture enter(video_capture, true); |
44 if (enter.failed()) | 79 if (enter.failed()) |
45 return PP_ERROR_BADRESOURCE; | 80 return PP_ERROR_BADRESOURCE; |
46 | 81 |
47 return enter.object()->ReuseBuffer(buffer); | 82 return enter.object()->ReuseBuffer(buffer); |
48 } | 83 } |
49 | 84 |
50 int32_t StopCapture(PP_Resource video_capture) { | 85 int32_t StopCapture(PP_Resource video_capture) { |
51 EnterVideoCapture enter(video_capture, true); | 86 EnterVideoCapture enter(video_capture, true); |
52 if (enter.failed()) | 87 if (enter.failed()) |
53 return PP_ERROR_BADRESOURCE; | 88 return PP_ERROR_BADRESOURCE; |
54 | 89 |
55 return enter.object()->StopCapture(); | 90 return enter.object()->StopCapture(); |
56 } | 91 } |
57 | 92 |
58 const PPB_VideoCapture_Dev g_ppb_videocapture_thunk = { | 93 void Close(PP_Resource video_capture) { |
| 94 EnterVideoCapture enter(video_capture, true); |
| 95 if (enter.succeeded()) |
| 96 enter.object()->Close(); |
| 97 } |
| 98 |
| 99 int32_t StartCapture0_1(PP_Resource video_capture, |
| 100 const PP_VideoCaptureDeviceInfo_Dev* requested_info, |
| 101 uint32_t buffer_count) { |
| 102 EnterVideoCapture enter(video_capture, true); |
| 103 if (enter.failed()) |
| 104 return PP_ERROR_BADRESOURCE; |
| 105 |
| 106 return enter.object()->StartCapture0_1(*requested_info, buffer_count); |
| 107 } |
| 108 |
| 109 const PPB_VideoCapture_Dev_0_1 g_ppb_video_capture_0_1_thunk = { |
59 &Create, | 110 &Create, |
60 &IsVideoCapture, | 111 &IsVideoCapture, |
| 112 &StartCapture0_1, |
| 113 &ReuseBuffer, |
| 114 &StopCapture |
| 115 }; |
| 116 |
| 117 const PPB_VideoCapture_Dev_0_2 g_ppb_video_capture_0_2_thunk = { |
| 118 &Create, |
| 119 &IsVideoCapture, |
| 120 &EnumerateDevices, |
| 121 &Open, |
61 &StartCapture, | 122 &StartCapture, |
62 &ReuseBuffer, | 123 &ReuseBuffer, |
63 &StopCapture | 124 &StopCapture, |
| 125 &Close |
64 }; | 126 }; |
65 | 127 |
66 } // namespace | 128 } // namespace |
67 | 129 |
68 const PPB_VideoCapture_Dev_0_1* GetPPB_VideoCapture_Dev_0_1_Thunk() { | 130 const PPB_VideoCapture_Dev_0_1* GetPPB_VideoCapture_Dev_0_1_Thunk() { |
69 return &g_ppb_videocapture_thunk; | 131 return &g_ppb_video_capture_0_1_thunk; |
| 132 } |
| 133 |
| 134 const PPB_VideoCapture_Dev_0_2* GetPPB_VideoCapture_Dev_0_2_Thunk() { |
| 135 return &g_ppb_video_capture_0_2_thunk; |
70 } | 136 } |
71 | 137 |
72 } // namespace thunk | 138 } // namespace thunk |
73 } // namespace ppapi | 139 } // namespace ppapi |
OLD | NEW |