Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(75)

Side by Side Diff: ppapi/thunk/ppb_video_capture_thunk.cc

Issue 9234064: Implement device enumeration for PPB_VideoCapture_Dev. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Changes in response to Antoine's comments. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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_CompletionCallback callback) {
33 uint32_t buffer_count) { 35 EnterVideoCapture enter(video_capture, true);
36 if (enter.failed())
37 return MayForceCallback(callback, PP_ERROR_BADRESOURCE);
38
39 int32_t result = enter.object()->EnumerateDevices(callback);
40 return MayForceCallback(callback, result);
41 }
42
43 PP_Resource GetDevices(PP_Resource video_capture) {
44 EnterVideoCapture enter(video_capture, true);
45 if (enter.failed())
46 return 0;
47
48 return enter.object()->GetDevices();
49 }
50
51 int32_t StartCapture0_2(PP_Resource video_capture,
52 PP_Resource device_ref,
53 const PP_VideoCaptureDeviceInfo_Dev* requested_info,
54 uint32_t buffer_count) {
34 EnterVideoCapture enter(video_capture, true); 55 EnterVideoCapture enter(video_capture, true);
35 if (enter.failed()) 56 if (enter.failed())
36 return PP_ERROR_BADRESOURCE; 57 return PP_ERROR_BADRESOURCE;
37 58
38 return enter.object()->StartCapture(*requested_info, buffer_count); 59 std::string device_id;
60 // |device_id| remains empty if |device_ref| is 0, which means the default
61 // device.
62 if (device_ref != 0) {
63 EnterResourceNoLock<PPB_DeviceRef_API> enter_device_ref(device_ref, true);
64 if (enter_device_ref.failed())
65 return PP_ERROR_BADRESOURCE;
66 device_id = enter_device_ref.object()->GetDeviceRefData().id;
67 }
68
69 return enter.object()->StartCapture(device_id, *requested_info, buffer_count);
70 }
71
72 int32_t StartCapture0_1(PP_Resource video_capture,
73 const PP_VideoCaptureDeviceInfo_Dev* requested_info,
74 uint32_t buffer_count) {
75 return StartCapture0_2(video_capture, 0, requested_info, buffer_count);
39 } 76 }
40 77
41 int32_t ReuseBuffer(PP_Resource video_capture, 78 int32_t ReuseBuffer(PP_Resource video_capture,
42 uint32_t buffer) { 79 uint32_t buffer) {
43 EnterVideoCapture enter(video_capture, true); 80 EnterVideoCapture enter(video_capture, true);
44 if (enter.failed()) 81 if (enter.failed())
45 return PP_ERROR_BADRESOURCE; 82 return PP_ERROR_BADRESOURCE;
46 83
47 return enter.object()->ReuseBuffer(buffer); 84 return enter.object()->ReuseBuffer(buffer);
48 } 85 }
49 86
50 int32_t StopCapture(PP_Resource video_capture) { 87 int32_t StopCapture(PP_Resource video_capture) {
51 EnterVideoCapture enter(video_capture, true); 88 EnterVideoCapture enter(video_capture, true);
52 if (enter.failed()) 89 if (enter.failed())
53 return PP_ERROR_BADRESOURCE; 90 return PP_ERROR_BADRESOURCE;
54 91
55 return enter.object()->StopCapture(); 92 return enter.object()->StopCapture();
56 } 93 }
57 94
58 const PPB_VideoCapture_Dev g_ppb_videocapture_thunk = { 95 const PPB_VideoCapture_Dev_0_1 g_ppb_video_capture_0_1_thunk = {
59 &Create, 96 &Create,
60 &IsVideoCapture, 97 &IsVideoCapture,
61 &StartCapture, 98 &StartCapture0_1,
62 &ReuseBuffer, 99 &ReuseBuffer,
63 &StopCapture 100 &StopCapture
64 }; 101 };
102
103 const PPB_VideoCapture_Dev_0_2 g_ppb_video_capture_0_2_thunk = {
104 &Create,
105 &IsVideoCapture,
106 &EnumerateDevices,
107 &GetDevices,
108 &StartCapture0_2,
109 &ReuseBuffer,
110 &StopCapture
111 };
65 112
66 } // namespace 113 } // namespace
67 114
68 const PPB_VideoCapture_Dev_0_1* GetPPB_VideoCapture_Dev_0_1_Thunk() { 115 const PPB_VideoCapture_Dev_0_1* GetPPB_VideoCapture_Dev_0_1_Thunk() {
69 return &g_ppb_videocapture_thunk; 116 return &g_ppb_video_capture_0_1_thunk;
117 }
118
119 const PPB_VideoCapture_Dev_0_2* GetPPB_VideoCapture_Dev_0_2_Thunk() {
120 return &g_ppb_video_capture_0_2_thunk;
70 } 121 }
71 122
72 } // namespace thunk 123 } // namespace thunk
73 } // namespace ppapi 124 } // namespace ppapi
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698