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

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

Powered by Google App Engine
This is Rietveld 408576698