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 EnumerateDevices(PP_Resource video_capture, 34 PP_ArrayOutput output, 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()->EnumerateDevices(output, 41 enter.callback())); 42 } 43 44 int32_t MonitorDeviceChange(PP_Resource video_capture, 45 PP_MonitorDeviceChangeCallback callback, 46 void* user_data) { 47 EnterVideoCapture enter(video_capture, true); 48 if (enter.failed()) 49 return enter.retval(); 50 return enter.object()->MonitorDeviceChange(callback, user_data); 51 } 52 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); 59 if (enter.failed()) 60 return enter.retval(); 61 62 std::string device_id; 63 // |device_id| remains empty if |device_ref| is 0, which means the default 64 // device. 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; 70 } 71 72 return enter.SetResult(enter.object()->Open( 73 device_id, *requested_info, buffer_count, enter.callback())); 74 } 75 76 int32_t StartCapture(PP_Resource video_capture) { 77 EnterVideoCapture enter(video_capture, true); 78 if (enter.failed()) 79 return enter.retval(); 80 return enter.object()->StartCapture(); 81 } 82 83 int32_t ReuseBuffer(PP_Resource video_capture, 84 uint32_t buffer) { 85 EnterVideoCapture enter(video_capture, true); 86 if (enter.failed()) 87 return enter.retval(); 88 return enter.object()->ReuseBuffer(buffer); 89 } 90 91 int32_t StopCapture(PP_Resource video_capture) { 92 EnterVideoCapture enter(video_capture, true); 93 if (enter.failed()) 94 return enter.retval(); 95 return enter.object()->StopCapture(); 96 } 97 98 void Close(PP_Resource video_capture) { 99 EnterVideoCapture enter(video_capture, true); 100 if (enter.succeeded()) 101 enter.object()->Close(); 102 } 103 104 const PPB_VideoCapture_Dev_0_3 g_ppb_video_capture_0_3_thunk = { 105 &Create, 106 &IsVideoCapture, 107 &EnumerateDevices, 108 &MonitorDeviceChange, 109 &Open, 110 &StartCapture, 111 &ReuseBuffer, 112 &StopCapture, 113 &Close 114 }; 115 116 } // namespace 117 118 const PPB_VideoCapture_Dev_0_3* GetPPB_VideoCapture_Dev_0_3_Thunk() { 119 return &g_ppb_video_capture_0_3_thunk; 120 } 121 122 } // namespace thunk 123 } // namespace ppapi 124