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