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 "webkit/plugins/ppapi/ppb_video_capture_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_video_capture_impl.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 166 |
167 void PPB_VideoCapture_Impl::OnInitialized(media::VideoCapture* capture, | 167 void PPB_VideoCapture_Impl::OnInitialized(media::VideoCapture* capture, |
168 bool succeeded) { | 168 bool succeeded) { |
169 DCHECK(capture == platform_video_capture_.get()); | 169 DCHECK(capture == platform_video_capture_.get()); |
170 | 170 |
171 OnOpenComplete(succeeded ? PP_OK : PP_ERROR_FAILED); | 171 OnOpenComplete(succeeded ? PP_OK : PP_ERROR_FAILED); |
172 } | 172 } |
173 | 173 |
174 int32_t PPB_VideoCapture_Impl::InternalEnumerateDevices( | 174 int32_t PPB_VideoCapture_Impl::InternalEnumerateDevices( |
175 PP_Resource* devices, | 175 PP_Resource* devices, |
176 const PP_CompletionCallback& callback) { | 176 scoped_refptr<TrackedCallback> callback) { |
177 PluginInstance* instance = ResourceHelper::GetPluginInstance(this); | 177 PluginInstance* instance = ResourceHelper::GetPluginInstance(this); |
178 if (!instance) | 178 if (!instance) |
179 return PP_ERROR_FAILED; | 179 return PP_ERROR_FAILED; |
180 | 180 |
181 devices_ = devices; | 181 devices_ = devices; |
182 enumerate_devices_callback_ = new TrackedCallback(this, callback); | 182 enumerate_devices_callback_ = callback; |
183 instance->delegate()->EnumerateDevices( | 183 instance->delegate()->EnumerateDevices( |
184 PP_DEVICETYPE_DEV_VIDEOCAPTURE, | 184 PP_DEVICETYPE_DEV_VIDEOCAPTURE, |
185 base::Bind(&PPB_VideoCapture_Impl::EnumerateDevicesCallbackFunc, | 185 base::Bind(&PPB_VideoCapture_Impl::EnumerateDevicesCallbackFunc, |
186 AsWeakPtr())); | 186 AsWeakPtr())); |
187 return PP_OK_COMPLETIONPENDING; | 187 return PP_OK_COMPLETIONPENDING; |
188 } | 188 } |
189 | 189 |
190 int32_t PPB_VideoCapture_Impl::InternalOpen( | 190 int32_t PPB_VideoCapture_Impl::InternalOpen( |
191 const std::string& device_id, | 191 const std::string& device_id, |
192 const PP_VideoCaptureDeviceInfo_Dev& requested_info, | 192 const PP_VideoCaptureDeviceInfo_Dev& requested_info, |
193 uint32_t buffer_count, | 193 uint32_t buffer_count, |
194 const PP_CompletionCallback& callback) { | 194 scoped_refptr<TrackedCallback> callback) { |
195 // It is able to complete synchronously if the default device is used. | 195 // It is able to complete synchronously if the default device is used. |
196 bool sync_completion = device_id.empty(); | 196 bool sync_completion = device_id.empty(); |
197 | 197 |
198 if (!callback.func && !sync_completion) | |
199 return PP_ERROR_BLOCKS_MAIN_THREAD; | |
200 | |
201 PluginInstance* instance = ResourceHelper::GetPluginInstance(this); | 198 PluginInstance* instance = ResourceHelper::GetPluginInstance(this); |
202 if (!instance) | 199 if (!instance) |
203 return PP_ERROR_FAILED; | 200 return PP_ERROR_FAILED; |
204 | 201 |
205 SetRequestedInfo(requested_info, buffer_count); | 202 SetRequestedInfo(requested_info, buffer_count); |
206 | 203 |
207 DCHECK(!platform_video_capture_.get()); | 204 DCHECK(!platform_video_capture_.get()); |
208 platform_video_capture_ = | 205 platform_video_capture_ = |
209 instance->delegate()->CreateVideoCapture(device_id, this); | 206 instance->delegate()->CreateVideoCapture(device_id, this); |
210 | 207 |
211 if (sync_completion) { | 208 if (sync_completion) { |
212 OnInitialized(platform_video_capture_.get(), true); | 209 OnInitialized(platform_video_capture_.get(), true); |
213 return PP_OK; | 210 return PP_OK; |
214 } else { | 211 } else { |
215 open_callback_ = new TrackedCallback(this, callback); | 212 open_callback_ = callback; |
216 return PP_OK_COMPLETIONPENDING; | 213 return PP_OK_COMPLETIONPENDING; |
217 } | 214 } |
218 } | 215 } |
219 | 216 |
220 int32_t PPB_VideoCapture_Impl::InternalStartCapture() { | 217 int32_t PPB_VideoCapture_Impl::InternalStartCapture() { |
221 DCHECK(buffers_.empty()); | 218 DCHECK(buffers_.empty()); |
222 platform_video_capture_->StartCapture(this, capability_); | 219 platform_video_capture_->StartCapture(this, capability_); |
223 return PP_OK; | 220 return PP_OK; |
224 } | 221 } |
225 | 222 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 : in_use(false), | 315 : in_use(false), |
319 data(NULL), | 316 data(NULL), |
320 buffer() { | 317 buffer() { |
321 } | 318 } |
322 | 319 |
323 PPB_VideoCapture_Impl::BufferInfo::~BufferInfo() { | 320 PPB_VideoCapture_Impl::BufferInfo::~BufferInfo() { |
324 } | 321 } |
325 | 322 |
326 } // namespace ppapi | 323 } // namespace ppapi |
327 } // namespace webkit | 324 } // namespace webkit |
OLD | NEW |