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

Side by Side Diff: webkit/plugins/ppapi/ppb_video_capture_impl.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) 2011 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/logging.h" 11 #include "base/logging.h"
12 #include "base/memory/scoped_ptr.h"
11 #include "ppapi/c/dev/pp_video_capture_dev.h" 13 #include "ppapi/c/dev/pp_video_capture_dev.h"
12 #include "ppapi/c/dev/ppb_video_capture_dev.h" 14 #include "ppapi/c/dev/ppb_video_capture_dev.h"
13 #include "ppapi/c/pp_completion_callback.h" 15 #include "ppapi/c/pp_completion_callback.h"
14 #include "ppapi/c/pp_errors.h" 16 #include "ppapi/c/pp_errors.h"
15 #include "ppapi/shared_impl/ppapi_globals.h" 17 #include "ppapi/shared_impl/ppapi_globals.h"
18 #include "ppapi/shared_impl/ppb_device_ref_shared.h"
16 #include "ppapi/shared_impl/resource_tracker.h" 19 #include "ppapi/shared_impl/resource_tracker.h"
17 #include "ppapi/thunk/enter.h" 20 #include "ppapi/thunk/enter.h"
18 #include "webkit/plugins/ppapi/common.h" 21 #include "webkit/plugins/ppapi/common.h"
19 #include "webkit/plugins/ppapi/plugin_module.h" 22 #include "webkit/plugins/ppapi/plugin_module.h"
20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" 23 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h"
21 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" 24 #include "webkit/plugins/ppapi/ppb_buffer_impl.h"
22 #include "webkit/plugins/ppapi/resource_helper.h" 25 #include "webkit/plugins/ppapi/resource_helper.h"
23 26
27 using ppapi::DeviceRefData;
24 using ppapi::PpapiGlobals; 28 using ppapi::PpapiGlobals;
25 using ppapi::thunk::EnterResourceNoLock; 29 using ppapi::thunk::EnterResourceNoLock;
26 using ppapi::thunk::PPB_Buffer_API; 30 using ppapi::thunk::PPB_Buffer_API;
27 using ppapi::thunk::PPB_VideoCapture_API; 31 using ppapi::thunk::PPB_VideoCapture_API;
32 using ppapi::TrackedCallback;
28 33
29 namespace { 34 namespace {
30 35
31 // Maximum number of buffers to actually allocate. 36 // Maximum number of buffers to actually allocate.
32 const uint32_t kMaxBuffers = 20; 37 const uint32_t kMaxBuffers = 20;
33 38
34 } // namespace 39 } // namespace
35 40
36 namespace webkit { 41 namespace webkit {
37 namespace ppapi { 42 namespace ppapi {
38 43
39 PPB_VideoCapture_Impl::PPB_VideoCapture_Impl(PP_Instance instance) 44 PPB_VideoCapture_Impl::PPB_VideoCapture_Impl(PP_Instance instance)
40 : Resource(instance), 45 : Resource(instance),
41 buffer_count_hint_(0), 46 buffer_count_hint_(0),
42 ppp_videocapture_(NULL), 47 ppp_videocapture_(NULL),
43 status_(PP_VIDEO_CAPTURE_STATUS_STOPPED), 48 status_(PP_VIDEO_CAPTURE_STATUS_STOPPED),
44 is_dead_(false) { 49 devices_(0),
50 capability_() {
45 } 51 }
46 52
47 PPB_VideoCapture_Impl::~PPB_VideoCapture_Impl() { 53 PPB_VideoCapture_Impl::~PPB_VideoCapture_Impl() {
54 StopCapture();
55 DCHECK(buffers_.empty());
56 ClearCachedDeviceResourceArray();
57 DetachPlatformVideoCapture();
48 } 58 }
49 59
50 bool PPB_VideoCapture_Impl::Init() { 60 bool PPB_VideoCapture_Impl::Init() {
51 DCHECK(!is_dead_);
52 PluginInstance* instance = ResourceHelper::GetPluginInstance(this); 61 PluginInstance* instance = ResourceHelper::GetPluginInstance(this);
53 if (!instance) 62 if (!instance)
54 return false; 63 return false;
55 ppp_videocapture_ = static_cast<const PPP_VideoCapture_Dev*>( 64 ppp_videocapture_ = static_cast<const PPP_VideoCapture_Dev*>(
56 instance->module()->GetPluginInterface(PPP_VIDEO_CAPTURE_DEV_INTERFACE)); 65 instance->module()->GetPluginInterface(PPP_VIDEO_CAPTURE_DEV_INTERFACE));
57 if (!ppp_videocapture_) 66 if (!ppp_videocapture_)
58 return false; 67 return false;
59 68
60 platform_video_capture_.reset( 69 return true;
61 instance->delegate()->CreateVideoCapture(this));
62 return !!platform_video_capture_.get();
63 } 70 }
64 71
65 PPB_VideoCapture_API* PPB_VideoCapture_Impl::AsPPB_VideoCapture_API() { 72 PPB_VideoCapture_API* PPB_VideoCapture_Impl::AsPPB_VideoCapture_API() {
66 return this; 73 return this;
67 } 74 }
68 75
69 void PPB_VideoCapture_Impl::LastPluginRefWasDeleted() { 76 int32_t PPB_VideoCapture_Impl::EnumerateDevices(
70 if (platform_video_capture_.get()) 77 PP_CompletionCallback callback) {
71 StopCapture(); 78 if (!callback.func)
72 DCHECK(buffers_.empty()); 79 return PP_ERROR_BLOCKS_MAIN_THREAD;
73 ppp_videocapture_ = NULL; 80 if (TrackedCallback::IsPending(enumerate_devices_callback_))
74 is_dead_ = true; 81 return PP_ERROR_INPROGRESS;
75 82
76 ::ppapi::Resource::LastPluginRefWasDeleted(); 83 PluginInstance* instance = ResourceHelper::GetPluginInstance(this);
84 if (!instance)
85 return PP_ERROR_FAILED;
86
87 enumerate_devices_callback_ = new TrackedCallback(this, callback);
88 instance->delegate()->EnumerateDevices(
89 PP_DEVICETYPE_DEV_VIDEOCAPTURE,
90 base::Bind(&PPB_VideoCapture_Impl::OnEnumerateDevicesComplete,
91 AsWeakPtr()));
92 return PP_OK_COMPLETIONPENDING;
93 }
94
95 PP_Resource PPB_VideoCapture_Impl::GetDevices() {
96 if (devices_)
97 PpapiGlobals::Get()->GetResourceTracker()->AddRefResource(devices_);
98 return devices_;
77 } 99 }
78 100
79 int32_t PPB_VideoCapture_Impl::StartCapture( 101 int32_t PPB_VideoCapture_Impl::StartCapture(
102 const std::string& device_id,
80 const PP_VideoCaptureDeviceInfo_Dev& requested_info, 103 const PP_VideoCaptureDeviceInfo_Dev& requested_info,
81 uint32_t buffer_count) { 104 uint32_t buffer_count) {
82 DCHECK(!is_dead_);
83 switch (status_) { 105 switch (status_) {
84 case PP_VIDEO_CAPTURE_STATUS_STARTING: 106 case PP_VIDEO_CAPTURE_STATUS_STARTING:
85 case PP_VIDEO_CAPTURE_STATUS_STARTED: 107 case PP_VIDEO_CAPTURE_STATUS_STARTED:
86 case PP_VIDEO_CAPTURE_STATUS_PAUSED: 108 case PP_VIDEO_CAPTURE_STATUS_PAUSED:
109 case PP_VIDEO_CAPTURE_STATUS_STOPPING:
87 default: 110 default:
88 return PP_ERROR_FAILED; 111 return PP_ERROR_FAILED;
89 case PP_VIDEO_CAPTURE_STATUS_STOPPED: 112 case PP_VIDEO_CAPTURE_STATUS_STOPPED:
90 case PP_VIDEO_CAPTURE_STATUS_STOPPING:
91 break; 113 break;
92 } 114 }
115
116 PluginInstance* instance = ResourceHelper::GetPluginInstance(this);
117 if (!instance)
118 return PP_ERROR_FAILED;
119
93 DCHECK(buffers_.empty()); 120 DCHECK(buffers_.empty());
94 121
95 // Clamp the buffer count to between 1 and |kMaxBuffers|. 122 // Clamp the buffer count to between 1 and |kMaxBuffers|.
96 buffer_count_hint_ = std::min(std::max(buffer_count, 1U), kMaxBuffers); 123 buffer_count_hint_ = std::min(std::max(buffer_count, 1U), kMaxBuffers);
97 media::VideoCapture::VideoCaptureCapability capability = { 124
98 requested_info.width, 125 capability_.width = requested_info.width;
99 requested_info.height, 126 capability_.height = requested_info.height;
100 requested_info.frames_per_second, 127 capability_.max_fps = requested_info.frames_per_second;
101 0, // ignored. 128 capability_.expected_capture_delay = 0; // Ignored.
102 media::VideoFrame::I420, 129 capability_.raw_type = media::VideoFrame::I420;
103 false, // ignored 130 capability_.interlaced = false; // Ignored.
104 }; 131
105 status_ = PP_VIDEO_CAPTURE_STATUS_STARTING; 132 status_ = PP_VIDEO_CAPTURE_STATUS_STARTING;
106 AddRef(); // Balanced in |OnRemoved()|. 133
107 platform_video_capture_->StartCapture(this, capability); 134 DetachPlatformVideoCapture();
135 platform_video_capture_ =
136 instance->delegate()->CreateVideoCapture(device_id, this);
137 // If |device_id| is not empty, StartCapture() will be performed in the
138 // OnInitialized() handler.
139 if (device_id.empty())
140 platform_video_capture_->StartCapture(this, capability_);
141
108 return PP_OK; 142 return PP_OK;
109 } 143 }
110 144
111 int32_t PPB_VideoCapture_Impl::ReuseBuffer(uint32_t buffer) { 145 int32_t PPB_VideoCapture_Impl::ReuseBuffer(uint32_t buffer) {
112 DCHECK(!is_dead_);
113 if (buffer >= buffers_.size() || !buffers_[buffer].in_use) 146 if (buffer >= buffers_.size() || !buffers_[buffer].in_use)
114 return PP_ERROR_BADARGUMENT; 147 return PP_ERROR_BADARGUMENT;
115 buffers_[buffer].in_use = false; 148 buffers_[buffer].in_use = false;
116 return PP_OK; 149 return PP_OK;
117 } 150 }
118 151
119 int32_t PPB_VideoCapture_Impl::StopCapture() { 152 int32_t PPB_VideoCapture_Impl::StopCapture() {
120 DCHECK(!is_dead_);
121 switch (status_) { 153 switch (status_) {
122 case PP_VIDEO_CAPTURE_STATUS_STOPPED: 154 case PP_VIDEO_CAPTURE_STATUS_STOPPED:
123 case PP_VIDEO_CAPTURE_STATUS_STOPPING: 155 case PP_VIDEO_CAPTURE_STATUS_STOPPING:
124 default: 156 default:
125 return PP_ERROR_FAILED; 157 return PP_ERROR_FAILED;
126 case PP_VIDEO_CAPTURE_STATUS_STARTING: 158 case PP_VIDEO_CAPTURE_STATUS_STARTING:
127 case PP_VIDEO_CAPTURE_STATUS_STARTED: 159 case PP_VIDEO_CAPTURE_STATUS_STARTED:
128 case PP_VIDEO_CAPTURE_STATUS_PAUSED: 160 case PP_VIDEO_CAPTURE_STATUS_PAUSED:
129 break; 161 break;
130 } 162 }
163 DCHECK(platform_video_capture_.get());
164
131 ReleaseBuffers(); 165 ReleaseBuffers();
132 status_ = PP_VIDEO_CAPTURE_STATUS_STOPPING; 166 status_ = PP_VIDEO_CAPTURE_STATUS_STOPPING;
133 platform_video_capture_->StopCapture(this); 167 platform_video_capture_->StopCapture(this);
134 return PP_OK; 168 return PP_OK;
135 } 169 }
136 170
171 const std::vector<DeviceRefData>&
172 PPB_VideoCapture_Impl::GetDeviceRefData() const {
173 return devices_data_;
174 }
175
137 void PPB_VideoCapture_Impl::OnStarted(media::VideoCapture* capture) { 176 void PPB_VideoCapture_Impl::OnStarted(media::VideoCapture* capture) {
138 if (is_dead_)
139 return;
140
141 switch (status_) { 177 switch (status_) {
142 case PP_VIDEO_CAPTURE_STATUS_STARTING: 178 case PP_VIDEO_CAPTURE_STATUS_STARTING:
143 case PP_VIDEO_CAPTURE_STATUS_PAUSED: 179 case PP_VIDEO_CAPTURE_STATUS_PAUSED:
144 break; 180 break;
145 case PP_VIDEO_CAPTURE_STATUS_STOPPED: 181 case PP_VIDEO_CAPTURE_STATUS_STOPPED:
146 case PP_VIDEO_CAPTURE_STATUS_STOPPING: 182 case PP_VIDEO_CAPTURE_STATUS_STOPPING:
147 case PP_VIDEO_CAPTURE_STATUS_STARTED: 183 case PP_VIDEO_CAPTURE_STATUS_STARTED:
148 default: 184 default:
149 return; 185 return;
150 } 186 }
151 status_ = PP_VIDEO_CAPTURE_STATUS_STARTED; 187 status_ = PP_VIDEO_CAPTURE_STATUS_STARTED;
152 SendStatus(); 188 SendStatus();
153 } 189 }
154 190
155 void PPB_VideoCapture_Impl::OnStopped(media::VideoCapture* capture) { 191 void PPB_VideoCapture_Impl::OnStopped(media::VideoCapture* capture) {
156 if (is_dead_)
157 return;
158
159 switch (status_) { 192 switch (status_) {
160 case PP_VIDEO_CAPTURE_STATUS_STOPPING: 193 case PP_VIDEO_CAPTURE_STATUS_STOPPING:
161 break; 194 break;
162 case PP_VIDEO_CAPTURE_STATUS_STARTING: 195 case PP_VIDEO_CAPTURE_STATUS_STARTING:
163 case PP_VIDEO_CAPTURE_STATUS_PAUSED: 196 case PP_VIDEO_CAPTURE_STATUS_PAUSED:
164 case PP_VIDEO_CAPTURE_STATUS_STOPPED: 197 case PP_VIDEO_CAPTURE_STATUS_STOPPED:
165 case PP_VIDEO_CAPTURE_STATUS_STARTED: 198 case PP_VIDEO_CAPTURE_STATUS_STARTED:
166 default: 199 default:
167 return; 200 return;
168 } 201 }
202
169 status_ = PP_VIDEO_CAPTURE_STATUS_STOPPED; 203 status_ = PP_VIDEO_CAPTURE_STATUS_STOPPED;
170 SendStatus(); 204 SendStatus();
171 } 205 }
172 206
173 void PPB_VideoCapture_Impl::OnPaused(media::VideoCapture* capture) { 207 void PPB_VideoCapture_Impl::OnPaused(media::VideoCapture* capture) {
174 if (is_dead_)
175 return;
176
177 switch (status_) { 208 switch (status_) {
178 case PP_VIDEO_CAPTURE_STATUS_STARTING: 209 case PP_VIDEO_CAPTURE_STATUS_STARTING:
179 case PP_VIDEO_CAPTURE_STATUS_STARTED: 210 case PP_VIDEO_CAPTURE_STATUS_STARTED:
180 break; 211 break;
181 case PP_VIDEO_CAPTURE_STATUS_STOPPED: 212 case PP_VIDEO_CAPTURE_STATUS_STOPPED:
182 case PP_VIDEO_CAPTURE_STATUS_STOPPING: 213 case PP_VIDEO_CAPTURE_STATUS_STOPPING:
183 case PP_VIDEO_CAPTURE_STATUS_PAUSED: 214 case PP_VIDEO_CAPTURE_STATUS_PAUSED:
184 default: 215 default:
185 return; 216 return;
186 } 217 }
187 status_ = PP_VIDEO_CAPTURE_STATUS_PAUSED; 218 status_ = PP_VIDEO_CAPTURE_STATUS_PAUSED;
188 SendStatus(); 219 SendStatus();
189 } 220 }
190 221
191 void PPB_VideoCapture_Impl::OnError(media::VideoCapture* capture, 222 void PPB_VideoCapture_Impl::OnError(media::VideoCapture* capture,
192 int error_code) { 223 int error_code) {
193 if (is_dead_)
194 return;
195
196 // Today, the media layer only sends "1" as an error. 224 // Today, the media layer only sends "1" as an error.
197 DCHECK(error_code == 1); 225 DCHECK(error_code == 1);
198 // It either comes because some error was detected while starting (e.g. 2 226 // It either comes because some error was detected while starting (e.g. 2
199 // conflicting "master" resolution), or because the browser failed to start 227 // conflicting "master" resolution), or because the browser failed to start
200 // the capture. 228 // the capture.
201 status_ = PP_VIDEO_CAPTURE_STATUS_STOPPED; 229 status_ = PP_VIDEO_CAPTURE_STATUS_STOPPED;
202 ppp_videocapture_->OnError(pp_instance(), pp_resource(), PP_ERROR_FAILED); 230 ppp_videocapture_->OnError(pp_instance(), pp_resource(), PP_ERROR_FAILED);
203 } 231 }
204 232
205 void PPB_VideoCapture_Impl::OnRemoved(media::VideoCapture* capture) { 233 void PPB_VideoCapture_Impl::OnRemoved(media::VideoCapture* capture) {
206 Release();
207 } 234 }
208 235
209 void PPB_VideoCapture_Impl::OnBufferReady( 236 void PPB_VideoCapture_Impl::OnBufferReady(
210 media::VideoCapture* capture, 237 media::VideoCapture* capture,
211 scoped_refptr<media::VideoCapture::VideoFrameBuffer> buffer) { 238 scoped_refptr<media::VideoCapture::VideoFrameBuffer> buffer) {
212 if (!is_dead_) { 239 DCHECK(buffer.get());
213 DCHECK(buffer.get()); 240 for (uint32_t i = 0; i < buffers_.size(); ++i) {
214 for (uint32_t i = 0; i < buffers_.size(); ++i) { 241 if (!buffers_[i].in_use) {
215 if (!buffers_[i].in_use) { 242 // TODO(ihf): Switch to a size calculation based on stride.
216 // TODO(ihf): Switch to a size calculation based on stride. 243 // Stride is filled out now but not more meaningful than size
217 // Stride is filled out now but not more meaningful than size 244 // until wjia unifies VideoFrameBuffer and media::VideoFrame.
218 // until wjia unifies VideoFrameBuffer and media::VideoFrame. 245 size_t size = std::min(static_cast<size_t>(buffers_[i].buffer->size()),
219 size_t size = std::min(static_cast<size_t>(buffers_[i].buffer->size()), 246 buffer->buffer_size);
220 buffer->buffer_size); 247 memcpy(buffers_[i].data, buffer->memory_pointer, size);
221 memcpy(buffers_[i].data, buffer->memory_pointer, size); 248 buffers_[i].in_use = true;
222 buffers_[i].in_use = true; 249 platform_video_capture_->FeedBuffer(buffer);
223 platform_video_capture_->FeedBuffer(buffer); 250 ppp_videocapture_->OnBufferReady(pp_instance(), pp_resource(), i);
224 ppp_videocapture_->OnBufferReady(pp_instance(), pp_resource(), i); 251 return;
225 return;
226 }
227 } 252 }
228 } 253 }
229 // Even after we have stopped and are dead we have to return buffers that
230 // are in flight to us. Otherwise VideoCaptureController will not tear down.
231 platform_video_capture_->FeedBuffer(buffer);
232 } 254 }
233 255
234 void PPB_VideoCapture_Impl::OnDeviceInfoReceived( 256 void PPB_VideoCapture_Impl::OnDeviceInfoReceived(
235 media::VideoCapture* capture, 257 media::VideoCapture* capture,
236 const media::VideoCaptureParams& device_info) { 258 const media::VideoCaptureParams& device_info) {
237 // No need to call |ReleaseBuffers()|: if we're dead, |StopCapture()| should
238 // already have been called.
239 if (is_dead_)
240 return;
241
242 PP_VideoCaptureDeviceInfo_Dev info = { 259 PP_VideoCaptureDeviceInfo_Dev info = {
243 device_info.width, 260 device_info.width,
244 device_info.height, 261 device_info.height,
245 device_info.frame_per_second 262 device_info.frame_per_second
246 }; 263 };
247 ReleaseBuffers(); 264 ReleaseBuffers();
248 265
249 // Allocate buffers. We keep a reference to them, that is released in 266 // Allocate buffers. We keep a reference to them, that is released in
250 // ReleaseBuffers. 267 // ReleaseBuffers.
251 // YUV 4:2:0 268 // YUV 4:2:0
(...skipping 27 matching lines...) Expand all
279 ppp_videocapture_->OnError(pp_instance(), pp_resource(), PP_ERROR_NOMEMORY); 296 ppp_videocapture_->OnError(pp_instance(), pp_resource(), PP_ERROR_NOMEMORY);
280 status_ = PP_VIDEO_CAPTURE_STATUS_STOPPING; 297 status_ = PP_VIDEO_CAPTURE_STATUS_STOPPING;
281 platform_video_capture_->StopCapture(this); 298 platform_video_capture_->StopCapture(this);
282 return; 299 return;
283 } 300 }
284 301
285 ppp_videocapture_->OnDeviceInfo(pp_instance(), pp_resource(), &info, 302 ppp_videocapture_->OnDeviceInfo(pp_instance(), pp_resource(), &info,
286 buffers_.size(), resources.get()); 303 buffers_.size(), resources.get());
287 } 304 }
288 305
306 void PPB_VideoCapture_Impl::OnInitialized(media::VideoCapture* capture,
307 bool succeeded) {
308 DCHECK(capture == platform_video_capture_.get());
309
310 if (status_ != PP_VIDEO_CAPTURE_STATUS_STARTING)
311 return;
312
313 if (succeeded) {
314 platform_video_capture_->StartCapture(this, capability_);
315 } else {
316 status_ = PP_VIDEO_CAPTURE_STATUS_STOPPED;
317 SendStatus();
318 }
319 }
320
289 void PPB_VideoCapture_Impl::ReleaseBuffers() { 321 void PPB_VideoCapture_Impl::ReleaseBuffers() {
290 DCHECK(!is_dead_);
291 ::ppapi::ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker(); 322 ::ppapi::ResourceTracker* tracker = PpapiGlobals::Get()->GetResourceTracker();
292 for (size_t i = 0; i < buffers_.size(); ++i) { 323 for (size_t i = 0; i < buffers_.size(); ++i) {
293 buffers_[i].buffer->Unmap(); 324 buffers_[i].buffer->Unmap();
294 tracker->ReleaseResource(buffers_[i].buffer->pp_resource()); 325 tracker->ReleaseResource(buffers_[i].buffer->pp_resource());
295 } 326 }
296 buffers_.clear(); 327 buffers_.clear();
297 } 328 }
298 329
299 void PPB_VideoCapture_Impl::SendStatus() { 330 void PPB_VideoCapture_Impl::SendStatus() {
300 DCHECK(!is_dead_);
301 ppp_videocapture_->OnStatus(pp_instance(), pp_resource(), status_); 331 ppp_videocapture_->OnStatus(pp_instance(), pp_resource(), status_);
302 } 332 }
303 333
334 void PPB_VideoCapture_Impl::ClearCachedDeviceResourceArray() {
335 if (devices_)
336 PpapiGlobals::Get()->GetResourceTracker()->ReleaseResource(devices_);
337 devices_ = 0;
338
339 devices_data_.clear();
340 }
341
342 void PPB_VideoCapture_Impl::DetachPlatformVideoCapture() {
343 if (platform_video_capture_.get()) {
344 platform_video_capture_->DetachEventHandler();
345 platform_video_capture_ = NULL;
346 }
347 }
348
349 void PPB_VideoCapture_Impl::OnEnumerateDevicesComplete(
350 int request_id,
351 bool succeeded,
352 const std::vector<::ppapi::DeviceRefData>& devices) {
353 ClearCachedDeviceResourceArray();
brettw 2012/02/06 21:51:52 This seems like it's a good opportunity to move in
yzshen1 2012/02/10 07:10:44 Done. I moved shared code into shared_impl and als
354 if (succeeded) {
355 devices_data_ = devices;
356 devices_ = ::ppapi::PPB_DeviceRef_Shared::CreateResourceArray(
357 true, pp_instance(), devices_data_);
358 }
359
360 if (!TrackedCallback::IsPending(enumerate_devices_callback_)) {
361 NOTREACHED();
362 return;
363 }
364 TrackedCallback::ClearAndRun(&enumerate_devices_callback_,
365 succeeded ? PP_OK : PP_ERROR_FAILED);
366 }
367
304 PPB_VideoCapture_Impl::BufferInfo::BufferInfo() 368 PPB_VideoCapture_Impl::BufferInfo::BufferInfo()
305 : in_use(false), 369 : in_use(false),
306 data(NULL), 370 data(NULL),
307 buffer() { 371 buffer() {
308 } 372 }
309 373
310 PPB_VideoCapture_Impl::BufferInfo::~BufferInfo() { 374 PPB_VideoCapture_Impl::BufferInfo::~BufferInfo() {
311 } 375 }
312 376
313 } // namespace ppapi 377 } // namespace ppapi
314 } // namespace webkit 378 } // namespace webkit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698