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/cpp/dev/video_capture_dev.h" | 5 #include "ppapi/cpp/dev/video_capture_dev.h" |
6 | 6 |
7 #include "ppapi/c/dev/ppb_video_capture_dev.h" | 7 #include "ppapi/c/dev/ppb_video_capture_dev.h" |
8 #include "ppapi/c/pp_errors.h" | 8 #include "ppapi/c/pp_errors.h" |
9 #include "ppapi/cpp/completion_callback.h" | 9 #include "ppapi/cpp/completion_callback.h" |
10 #include "ppapi/cpp/dev/device_ref_dev.h" | 10 #include "ppapi/cpp/dev/device_ref_dev.h" |
11 #include "ppapi/cpp/dev/resource_array_dev.h" | 11 #include "ppapi/cpp/dev/resource_array_dev.h" |
12 #include "ppapi/cpp/instance.h" | 12 #include "ppapi/cpp/instance_handle.h" |
13 #include "ppapi/cpp/module.h" | 13 #include "ppapi/cpp/module.h" |
14 #include "ppapi/cpp/module_impl.h" | 14 #include "ppapi/cpp/module_impl.h" |
15 | 15 |
16 namespace pp { | 16 namespace pp { |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 template <> const char* interface_name<PPB_VideoCapture_Dev>() { | 20 template <> const char* interface_name<PPB_VideoCapture_Dev>() { |
21 return PPB_VIDEOCAPTURE_DEV_INTERFACE; | 21 return PPB_VIDEOCAPTURE_DEV_INTERFACE; |
22 } | 22 } |
23 | 23 |
24 } // namespace | 24 } // namespace |
25 | 25 |
26 struct VideoCapture_Dev::EnumerateDevicesState { | 26 struct VideoCapture_Dev::EnumerateDevicesState { |
27 EnumerateDevicesState(std::vector<DeviceRef_Dev>* in_devices, | 27 EnumerateDevicesState(std::vector<DeviceRef_Dev>* in_devices, |
28 const CompletionCallback& in_callback, | 28 const CompletionCallback& in_callback, |
29 VideoCapture_Dev* in_video_capture) | 29 VideoCapture_Dev* in_video_capture) |
30 : devices_resource(0), | 30 : devices_resource(0), |
31 devices(in_devices), | 31 devices(in_devices), |
32 callback(in_callback), | 32 callback(in_callback), |
33 video_capture(in_video_capture) { | 33 video_capture(in_video_capture) { |
34 } | 34 } |
35 | 35 |
36 PP_Resource devices_resource; | 36 PP_Resource devices_resource; |
37 std::vector<DeviceRef_Dev>* devices; | 37 std::vector<DeviceRef_Dev>* devices; |
38 CompletionCallback callback; | 38 CompletionCallback callback; |
39 VideoCapture_Dev* video_capture; | 39 VideoCapture_Dev* video_capture; |
40 }; | 40 }; |
41 | 41 |
42 VideoCapture_Dev::VideoCapture_Dev(const Instance& instance) | 42 VideoCapture_Dev::VideoCapture_Dev(const InstanceHandle& instance) |
43 : enum_state_(NULL) { | 43 : enum_state_(NULL) { |
44 if (!has_interface<PPB_VideoCapture_Dev>()) | 44 if (!has_interface<PPB_VideoCapture_Dev>()) |
45 return; | 45 return; |
46 PassRefFromConstructor(get_interface<PPB_VideoCapture_Dev>()->Create( | 46 PassRefFromConstructor(get_interface<PPB_VideoCapture_Dev>()->Create( |
47 instance.pp_instance())); | 47 instance.pp_instance())); |
48 } | 48 } |
49 | 49 |
50 VideoCapture_Dev::VideoCapture_Dev(PP_Resource resource) | 50 VideoCapture_Dev::VideoCapture_Dev(PP_Resource resource) |
51 : Resource(resource), | 51 : Resource(resource), |
52 enum_state_(NULL) { | 52 enum_state_(NULL) { |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 // static | 142 // static |
143 void VideoCapture_Dev::OnEnumerateDevicesComplete(void* user_data, | 143 void VideoCapture_Dev::OnEnumerateDevicesComplete(void* user_data, |
144 int32_t result) { | 144 int32_t result) { |
145 EnumerateDevicesState* enum_state = | 145 EnumerateDevicesState* enum_state = |
146 static_cast<EnumerateDevicesState*>(user_data); | 146 static_cast<EnumerateDevicesState*>(user_data); |
147 | 147 |
148 bool need_to_callback = !!enum_state->video_capture; | 148 bool need_to_callback = !!enum_state->video_capture; |
149 | 149 |
150 if (result == PP_OK) { | 150 if (result == PP_OK) { |
151 // It will take care of releasing the reference. | 151 // It will take care of releasing the reference. |
152 ResourceArray_Dev resources(ResourceArray_Dev::PassRef(), | 152 ResourceArray_Dev resources(pp::PASS_REF, enum_state->devices_resource); |
153 enum_state->devices_resource); | |
154 | 153 |
155 if (need_to_callback) { | 154 if (need_to_callback) { |
156 enum_state->devices->clear(); | 155 enum_state->devices->clear(); |
157 for (uint32_t index = 0; index < resources.size(); ++index) { | 156 for (uint32_t index = 0; index < resources.size(); ++index) { |
158 DeviceRef_Dev device(resources[index]); | 157 DeviceRef_Dev device(resources[index]); |
159 enum_state->devices->push_back(device); | 158 enum_state->devices->push_back(device); |
160 } | 159 } |
161 } | 160 } |
162 } | 161 } |
163 | 162 |
164 if (need_to_callback) { | 163 if (need_to_callback) { |
165 enum_state->video_capture->enum_state_ = NULL; | 164 enum_state->video_capture->enum_state_ = NULL; |
166 enum_state->callback.Run(result); | 165 enum_state->callback.Run(result); |
167 } | 166 } |
168 | 167 |
169 delete enum_state; | 168 delete enum_state; |
170 } | 169 } |
171 | 170 |
172 } // namespace pp | 171 } // namespace pp |
OLD | NEW |