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. 4 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" 13 14 namespace ppapi { 15 namespace thunk { 16 17 namespace { 18 19 typedef EnterResource<PPB_VideoCapture_API> EnterVideoCapture; 20 21 PP_Resource Create(PP_Instance instance) { 22 EnterResourceCreation enter(instance); 23 if (enter.failed()) 24 return 0; 25 return enter.functions()->CreateVideoCapture(instance); 26 } 27 28 PP_Bool IsVideoCapture(PP_Resource resource) { 29 EnterVideoCapture enter(resource, false); 30 return PP_FromBool(enter.succeeded()); 31 } 32 33 int32_t EnumerateDevices0_2(PP_Resource video_capture, 34 PP_Resource* devices, 35 PP_CompletionCallback callback) { 36 EnterVideoCapture enter(video_capture, callback, true); 37 if (enter.failed()) 38 return enter.retval(); 39 40 return enter.SetResult(enter.object()->EnumerateDevices0_2(devices, 41 enter.callback())); 42 } 43 44 int32_t EnumerateDevices(PP_Resource video_capture, 45 PP_ArrayOutput output, 46 PP_CompletionCallback callback) { 47 EnterVideoCapture enter(video_capture, callback, true); 48 if (enter.failed()) 49 return enter.retval(); 50 51 return enter.SetResult(enter.object()->EnumerateDevices(output, 52 enter.callback())); 53 } 54 55 int32_t MonitorDeviceChange(PP_Resource video_capture, 56 PP_MonitorDeviceChangeCallback callback, 57 void* user_data) { 58 EnterVideoCapture enter(video_capture, true); 59 if (enter.failed()) 60 return enter.retval(); 61 return enter.object()->MonitorDeviceChange(callback, user_data); 62 } 63 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); 70 if (enter.failed()) 71 return enter.retval(); 72 73 std::string device_id; 74 // |device_id| remains empty if |device_ref| is 0, which means the default 75 // device. 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; 81 } 82 83 return enter.SetResult(enter.object()->Open( 84 device_id, *requested_info, buffer_count, enter.callback())); 85 } 86 87 int32_t StartCapture(PP_Resource video_capture) { 88 EnterVideoCapture enter(video_capture, true); 89 if (enter.failed()) 90 return enter.retval(); 91 return enter.object()->StartCapture(); 92 } 93 94 int32_t ReuseBuffer(PP_Resource video_capture, 95 uint32_t buffer) { 96 EnterVideoCapture enter(video_capture, true); 97 if (enter.failed()) 98 return enter.retval(); 99 return enter.object()->ReuseBuffer(buffer); 100 } 101 102 int32_t StopCapture(PP_Resource video_capture) { 103 EnterVideoCapture enter(video_capture, true); 104 if (enter.failed()) 105 return enter.retval(); 106 return enter.object()->StopCapture(); 107 } 108 109 void Close(PP_Resource video_capture) { 110 EnterVideoCapture enter(video_capture, true); 111 if (enter.succeeded()) 112 enter.object()->Close(); 113 } 114 115 const PPB_VideoCapture_Dev_0_2 g_ppb_video_capture_0_2_thunk = { 116 &Create, 117 &IsVideoCapture, 118 &EnumerateDevices0_2, 119 &Open, 120 &StartCapture, 121 &ReuseBuffer, 122 &StopCapture, 123 &Close 124 }; 125 126 const PPB_VideoCapture_Dev_0_3 g_ppb_video_capture_0_3_thunk = { 127 &Create, 128 &IsVideoCapture, 129 &EnumerateDevices, 130 &MonitorDeviceChange, 131 &Open, 132 &StartCapture, 133 &ReuseBuffer, 134 &StopCapture, 135 &Close 136 }; 137 138 } // namespace 139 140 const PPB_VideoCapture_Dev_0_2* GetPPB_VideoCapture_Dev_0_2_Thunk() { 141 return &g_ppb_video_capture_0_2_thunk; 142 } 143 144 const PPB_VideoCapture_Dev_0_3* GetPPB_VideoCapture_Dev_0_3_Thunk() { 145 return &g_ppb_video_capture_0_3_thunk; 146 } 147 148 } // namespace thunk 149 } // namespace ppapi 150