OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/proxy/ppb_video_capture_proxy.h" | 5 #include "ppapi/proxy/ppb_video_capture_proxy.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
11 #include "ppapi/c/pp_errors.h" | 11 #include "ppapi/c/pp_errors.h" |
12 #include "ppapi/c/pp_resource.h" | 12 #include "ppapi/c/pp_resource.h" |
13 #include "ppapi/c/ppb_core.h" | 13 #include "ppapi/c/ppb_core.h" |
14 #include "ppapi/c/dev/ppb_video_capture_dev.h" | 14 #include "ppapi/c/dev/ppb_video_capture_dev.h" |
15 #include "ppapi/c/dev/ppp_video_capture_dev.h" | 15 #include "ppapi/c/dev/ppp_video_capture_dev.h" |
16 #include "ppapi/proxy/enter_proxy.h" | 16 #include "ppapi/proxy/enter_proxy.h" |
17 #include "ppapi/proxy/host_dispatcher.h" | 17 #include "ppapi/proxy/host_dispatcher.h" |
18 #include "ppapi/proxy/plugin_dispatcher.h" | 18 #include "ppapi/proxy/plugin_dispatcher.h" |
19 #include "ppapi/proxy/ppapi_messages.h" | 19 #include "ppapi/proxy/ppapi_messages.h" |
20 #include "ppapi/proxy/ppb_buffer_proxy.h" | 20 #include "ppapi/proxy/ppb_buffer_proxy.h" |
21 #include "ppapi/thunk/ppb_buffer_api.h" | 21 #include "ppapi/thunk/ppb_buffer_api.h" |
22 #include "ppapi/thunk/ppb_buffer_trusted_api.h" | 22 #include "ppapi/thunk/ppb_buffer_trusted_api.h" |
23 #include "ppapi/thunk/ppb_video_capture_api.h" | 23 #include "ppapi/thunk/ppb_video_capture_api.h" |
24 #include "ppapi/thunk/resource_creation_api.h" | |
25 #include "ppapi/thunk/thunk.h" | 24 #include "ppapi/thunk/thunk.h" |
26 | 25 |
27 using ppapi::thunk::EnterResourceNoLock; | 26 using ppapi::thunk::EnterResourceNoLock; |
28 using ppapi::thunk::PPB_Buffer_API; | 27 using ppapi::thunk::PPB_Buffer_API; |
29 using ppapi::thunk::PPB_BufferTrusted_API; | 28 using ppapi::thunk::PPB_BufferTrusted_API; |
30 using ppapi::thunk::PPB_VideoCapture_API; | 29 using ppapi::thunk::PPB_VideoCapture_API; |
31 | 30 |
32 namespace ppapi { | 31 namespace ppapi { |
33 namespace proxy { | 32 namespace proxy { |
34 | 33 |
35 namespace { | 34 namespace { |
36 | 35 |
37 InterfaceProxy* CreatePPPVideoCaptureProxy(Dispatcher* dispatcher) { | 36 InterfaceProxy* CreatePPBVideoCaptureProxy(Dispatcher* dispatcher, |
38 return new PPP_VideoCapture_Proxy(dispatcher); | 37 const void* target_interface) { |
| 38 return new PPB_VideoCapture_Proxy(dispatcher, target_interface); |
| 39 } |
| 40 |
| 41 InterfaceProxy* CreatePPPVideoCaptureProxy(Dispatcher* dispatcher, |
| 42 const void* target_interface) { |
| 43 return new PPP_VideoCapture_Proxy(dispatcher, target_interface); |
39 } | 44 } |
40 | 45 |
41 void OnDeviceInfo(PP_Instance instance, | 46 void OnDeviceInfo(PP_Instance instance, |
42 PP_Resource resource, | 47 PP_Resource resource, |
43 const PP_VideoCaptureDeviceInfo_Dev* info, | 48 const PP_VideoCaptureDeviceInfo_Dev* info, |
44 uint32_t buffer_count, | 49 uint32_t buffer_count, |
45 const PP_Resource* resources) { | 50 const PP_Resource* resources) { |
46 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); | 51 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
47 if (!dispatcher) { | 52 if (!dispatcher) { |
48 NOTREACHED(); | 53 NOTREACHED(); |
49 return; | 54 return; |
50 } | 55 } |
51 HostResource host_resource; | 56 HostResource host_resource; |
52 host_resource.SetHostResource(instance, resource); | 57 host_resource.SetHostResource(instance, resource); |
53 std::vector<PPPVideoCapture_Buffer> buffers(buffer_count); | 58 std::vector<PPPVideoCapture_Buffer> buffers(buffer_count); |
54 const PPB_Core* core = static_cast<const PPB_Core*>( | 59 const PPB_Core* core = static_cast<const PPB_Core*>( |
55 dispatcher->local_get_interface()(PPB_CORE_INTERFACE)); | 60 dispatcher->GetLocalInterface(PPB_CORE_INTERFACE)); |
56 DCHECK(core); | 61 DCHECK(core); |
57 for (uint32_t i = 0; i < buffer_count; ++i) { | 62 for (uint32_t i = 0; i < buffer_count; ++i) { |
58 // We need to take a ref on the resource now. The browser may drop | 63 // We need to take a ref on the resource now. The browser may drop |
59 // references once we return from here, but we're sending an asynchronous | 64 // references once we return from here, but we're sending an asynchronous |
60 // message. The plugin side takes ownership of that reference. | 65 // message. The plugin side takes ownership of that reference. |
61 core->AddRefResource(resources[i]); | 66 core->AddRefResource(resources[i]); |
62 buffers[i].resource.SetHostResource(instance, resources[i]); | 67 buffers[i].resource.SetHostResource(instance, resources[i]); |
63 { | 68 { |
64 EnterResourceNoLock<PPB_Buffer_API> enter(resources[i], true); | 69 EnterResourceNoLock<PPB_Buffer_API> enter(resources[i], true); |
65 DCHECK(enter.succeeded()); | 70 DCHECK(enter.succeeded()); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 status_(PP_VIDEO_CAPTURE_STATUS_STOPPED) { | 258 status_(PP_VIDEO_CAPTURE_STATUS_STOPPED) { |
254 } | 259 } |
255 | 260 |
256 VideoCapture::~VideoCapture() { | 261 VideoCapture::~VideoCapture() { |
257 } | 262 } |
258 | 263 |
259 ppapi::thunk::PPB_VideoCapture_API* VideoCapture::AsPPB_VideoCapture_API() { | 264 ppapi::thunk::PPB_VideoCapture_API* VideoCapture::AsPPB_VideoCapture_API() { |
260 return this; | 265 return this; |
261 } | 266 } |
262 | 267 |
263 PPB_VideoCapture_Proxy::PPB_VideoCapture_Proxy(Dispatcher* dispatcher) | 268 PPB_VideoCapture_Proxy::PPB_VideoCapture_Proxy(Dispatcher* dispatcher, |
264 : InterfaceProxy(dispatcher) { | 269 const void* target_interface) |
| 270 : InterfaceProxy(dispatcher, target_interface) { |
265 } | 271 } |
266 | 272 |
267 PPB_VideoCapture_Proxy::~PPB_VideoCapture_Proxy() { | 273 PPB_VideoCapture_Proxy::~PPB_VideoCapture_Proxy() { |
268 } | 274 } |
269 | 275 |
270 // static | 276 // static |
| 277 const InterfaceProxy::Info* PPB_VideoCapture_Proxy::GetInfo() { |
| 278 static const Info info = { |
| 279 ppapi::thunk::GetPPB_VideoCapture_Thunk(), |
| 280 PPB_VIDEO_CAPTURE_DEV_INTERFACE, |
| 281 INTERFACE_ID_PPB_VIDEO_CAPTURE_DEV, |
| 282 false, |
| 283 &CreatePPBVideoCaptureProxy, |
| 284 }; |
| 285 return &info; |
| 286 } |
| 287 |
| 288 // static |
271 PP_Resource PPB_VideoCapture_Proxy::CreateProxyResource(PP_Instance instance) { | 289 PP_Resource PPB_VideoCapture_Proxy::CreateProxyResource(PP_Instance instance) { |
272 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 290 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
273 if (!dispatcher) | 291 if (!dispatcher) |
274 return 0; | 292 return 0; |
275 | 293 |
276 HostResource result; | 294 HostResource result; |
277 dispatcher->Send(new PpapiHostMsg_PPBVideoCapture_Create( | 295 dispatcher->Send(new PpapiHostMsg_PPBVideoCapture_Create( |
278 INTERFACE_ID_PPB_VIDEO_CAPTURE_DEV, instance, &result)); | 296 INTERFACE_ID_PPB_VIDEO_CAPTURE_DEV, instance, &result)); |
279 if (result.is_null()) | 297 if (result.is_null()) |
280 return 0; | 298 return 0; |
(...skipping 11 matching lines...) Expand all Loading... |
292 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoCapture_StopCapture, | 310 IPC_MESSAGE_HANDLER(PpapiHostMsg_PPBVideoCapture_StopCapture, |
293 OnMsgStopCapture) | 311 OnMsgStopCapture) |
294 IPC_MESSAGE_UNHANDLED(handled = false) | 312 IPC_MESSAGE_UNHANDLED(handled = false) |
295 IPC_END_MESSAGE_MAP() | 313 IPC_END_MESSAGE_MAP() |
296 // TODO(brettw) handle bad messages! | 314 // TODO(brettw) handle bad messages! |
297 return handled; | 315 return handled; |
298 } | 316 } |
299 | 317 |
300 void PPB_VideoCapture_Proxy::OnMsgCreate(PP_Instance instance, | 318 void PPB_VideoCapture_Proxy::OnMsgCreate(PP_Instance instance, |
301 HostResource* result_resource) { | 319 HostResource* result_resource) { |
302 thunk::EnterResourceCreation enter(instance); | 320 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance); |
303 if (enter.succeeded()) { | 321 if (!dispatcher) |
304 result_resource->SetHostResource( | 322 return; |
305 instance, | 323 PP_Resource resource = ppb_video_capture_target()->Create(instance); |
306 enter.functions()->CreateVideoCapture(instance)); | 324 result_resource->SetHostResource(instance, resource); |
307 } | |
308 } | 325 } |
309 | 326 |
310 void PPB_VideoCapture_Proxy::OnMsgStartCapture( | 327 void PPB_VideoCapture_Proxy::OnMsgStartCapture( |
311 const HostResource& resource, | 328 const HostResource& resource, |
312 const PP_VideoCaptureDeviceInfo_Dev& info, | 329 const PP_VideoCaptureDeviceInfo_Dev& info, |
313 uint32_t buffers) { | 330 uint32_t buffers) { |
314 EnterHostFromHostResource<PPB_VideoCapture_API> enter(resource); | 331 EnterHostFromHostResource<PPB_VideoCapture_API> enter(resource); |
315 if (enter.succeeded()) | 332 if (enter.succeeded()) |
316 enter.object()->StartCapture(info, buffers); | 333 enter.object()->StartCapture(info, buffers); |
317 } | 334 } |
318 | 335 |
319 void PPB_VideoCapture_Proxy::OnMsgReuseBuffer(const HostResource& resource, | 336 void PPB_VideoCapture_Proxy::OnMsgReuseBuffer(const HostResource& resource, |
320 uint32_t buffer) { | 337 uint32_t buffer) { |
321 EnterHostFromHostResource<PPB_VideoCapture_API> enter(resource); | 338 EnterHostFromHostResource<PPB_VideoCapture_API> enter(resource); |
322 if (enter.succeeded()) | 339 if (enter.succeeded()) |
323 enter.object()->ReuseBuffer(buffer); | 340 enter.object()->ReuseBuffer(buffer); |
324 } | 341 } |
325 | 342 |
326 void PPB_VideoCapture_Proxy::OnMsgStopCapture(const HostResource& resource) { | 343 void PPB_VideoCapture_Proxy::OnMsgStopCapture(const HostResource& resource) { |
327 EnterHostFromHostResource<PPB_VideoCapture_API> enter(resource); | 344 EnterHostFromHostResource<PPB_VideoCapture_API> enter(resource); |
328 if (enter.succeeded()) | 345 if (enter.succeeded()) |
329 enter.object()->StopCapture(); | 346 enter.object()->StopCapture(); |
330 } | 347 } |
331 | 348 |
332 PPP_VideoCapture_Proxy::PPP_VideoCapture_Proxy(Dispatcher* dispatcher) | 349 PPP_VideoCapture_Proxy::PPP_VideoCapture_Proxy(Dispatcher* dispatcher, |
333 : InterfaceProxy(dispatcher), | 350 const void* target_interface) |
334 ppp_video_capture_impl_(NULL) { | 351 : InterfaceProxy(dispatcher, target_interface) { |
335 if (dispatcher->IsPlugin()) { | |
336 ppp_video_capture_impl_ = static_cast<const PPP_VideoCapture_Dev*>( | |
337 dispatcher->local_get_interface()(PPP_VIDEO_CAPTURE_DEV_INTERFACE)); | |
338 } | |
339 } | 352 } |
340 | 353 |
341 PPP_VideoCapture_Proxy::~PPP_VideoCapture_Proxy() { | 354 PPP_VideoCapture_Proxy::~PPP_VideoCapture_Proxy() { |
342 } | 355 } |
343 | 356 |
344 // static | 357 // static |
345 const InterfaceProxy::Info* PPP_VideoCapture_Proxy::GetInfo() { | 358 const InterfaceProxy::Info* PPP_VideoCapture_Proxy::GetInfo() { |
346 static const Info info = { | 359 static const Info info = { |
347 &ppp_video_capture, | 360 &ppp_video_capture, |
348 PPP_VIDEO_CAPTURE_DEV_INTERFACE, | 361 PPP_VIDEO_CAPTURE_DEV_INTERFACE, |
(...skipping 19 matching lines...) Expand all Loading... |
368 return handled; | 381 return handled; |
369 } | 382 } |
370 | 383 |
371 void PPP_VideoCapture_Proxy::OnMsgOnDeviceInfo( | 384 void PPP_VideoCapture_Proxy::OnMsgOnDeviceInfo( |
372 const HostResource& host_resource, | 385 const HostResource& host_resource, |
373 const PP_VideoCaptureDeviceInfo_Dev& info, | 386 const PP_VideoCaptureDeviceInfo_Dev& info, |
374 const std::vector<PPPVideoCapture_Buffer>& buffers) { | 387 const std::vector<PPPVideoCapture_Buffer>& buffers) { |
375 EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource); | 388 EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource); |
376 PluginResourceTracker* tracker = PluginResourceTracker::GetInstance(); | 389 PluginResourceTracker* tracker = PluginResourceTracker::GetInstance(); |
377 PP_Resource resource = tracker->PluginResourceForHostResource(host_resource); | 390 PP_Resource resource = tracker->PluginResourceForHostResource(host_resource); |
378 if (!resource || !ppp_video_capture_impl_ || enter.failed()) | 391 if (!resource || !ppp_video_capture_target() || enter.failed()) |
379 return; | 392 return; |
380 | 393 |
381 scoped_array<PP_Resource> resources(new PP_Resource[buffers.size()]); | 394 scoped_array<PP_Resource> resources(new PP_Resource[buffers.size()]); |
382 for (size_t i = 0; i < buffers.size(); ++i) { | 395 for (size_t i = 0; i < buffers.size(); ++i) { |
383 // We assume that the browser created a new set of resources. | 396 // We assume that the browser created a new set of resources. |
384 DCHECK(!tracker->PluginResourceForHostResource(buffers[i].resource)); | 397 DCHECK(!tracker->PluginResourceForHostResource(buffers[i].resource)); |
385 resources[i] = PPB_Buffer_Proxy::AddProxyResource(buffers[i].resource, | 398 resources[i] = PPB_Buffer_Proxy::AddProxyResource(buffers[i].resource, |
386 buffers[i].handle, | 399 buffers[i].handle, |
387 buffers[i].size); | 400 buffers[i].size); |
388 } | 401 } |
389 static_cast<VideoCapture*>(enter.object())->SetBufferCount(buffers.size()); | 402 static_cast<VideoCapture*>(enter.object())->SetBufferCount(buffers.size()); |
390 ppp_video_capture_impl_->OnDeviceInfo( | 403 ppp_video_capture_target()->OnDeviceInfo( |
391 host_resource.instance(), | 404 host_resource.instance(), |
392 resource, | 405 resource, |
393 &info, | 406 &info, |
394 buffers.size(), | 407 buffers.size(), |
395 resources.get()); | 408 resources.get()); |
396 for (size_t i = 0; i < buffers.size(); ++i) | 409 for (size_t i = 0; i < buffers.size(); ++i) |
397 tracker->ReleaseResource(resources[i]); | 410 tracker->ReleaseResource(resources[i]); |
398 } | 411 } |
399 | 412 |
400 void PPP_VideoCapture_Proxy::OnMsgOnStatus(const HostResource& host_resource, | 413 void PPP_VideoCapture_Proxy::OnMsgOnStatus(const HostResource& host_resource, |
401 uint32_t status) { | 414 uint32_t status) { |
402 EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource); | 415 EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource); |
403 PluginResourceTracker* tracker = PluginResourceTracker::GetInstance(); | 416 PluginResourceTracker* tracker = PluginResourceTracker::GetInstance(); |
404 PP_Resource resource = tracker->PluginResourceForHostResource(host_resource); | 417 PP_Resource resource = tracker->PluginResourceForHostResource(host_resource); |
405 if (!resource || !ppp_video_capture_impl_ || enter.failed()) | 418 if (!resource || !ppp_video_capture_target() || enter.failed()) |
406 return; | 419 return; |
407 | 420 |
408 if (!static_cast<VideoCapture*>(enter.object())->OnStatus(status)) | 421 if (!static_cast<VideoCapture*>(enter.object())->OnStatus(status)) |
409 return; | 422 return; |
410 ppp_video_capture_impl_->OnStatus( | 423 ppp_video_capture_target()->OnStatus( |
411 host_resource.instance(), resource, status); | 424 host_resource.instance(), resource, status); |
412 } | 425 } |
413 | 426 |
414 void PPP_VideoCapture_Proxy::OnMsgOnError(const HostResource& host_resource, | 427 void PPP_VideoCapture_Proxy::OnMsgOnError(const HostResource& host_resource, |
415 uint32_t error_code) { | 428 uint32_t error_code) { |
416 EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource); | 429 EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource); |
417 PluginResourceTracker* tracker = PluginResourceTracker::GetInstance(); | 430 PluginResourceTracker* tracker = PluginResourceTracker::GetInstance(); |
418 PP_Resource resource = tracker->PluginResourceForHostResource(host_resource); | 431 PP_Resource resource = tracker->PluginResourceForHostResource(host_resource); |
419 if (!resource || !ppp_video_capture_impl_ || enter.failed()) | 432 if (!resource || !ppp_video_capture_target() || enter.failed()) |
420 return; | 433 return; |
421 static_cast<VideoCapture*>(enter.object())->set_status( | 434 static_cast<VideoCapture*>(enter.object())->set_status( |
422 PP_VIDEO_CAPTURE_STATUS_STOPPED); | 435 PP_VIDEO_CAPTURE_STATUS_STOPPED); |
423 ppp_video_capture_impl_->OnError( | 436 ppp_video_capture_target()->OnError( |
424 host_resource.instance(), resource, error_code); | 437 host_resource.instance(), resource, error_code); |
425 } | 438 } |
426 | 439 |
427 void PPP_VideoCapture_Proxy::OnMsgOnBufferReady( | 440 void PPP_VideoCapture_Proxy::OnMsgOnBufferReady( |
428 const HostResource& host_resource, uint32_t buffer) { | 441 const HostResource& host_resource, uint32_t buffer) { |
429 EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource); | 442 EnterPluginFromHostResource<PPB_VideoCapture_API> enter(host_resource); |
430 PluginResourceTracker* tracker = PluginResourceTracker::GetInstance(); | 443 PluginResourceTracker* tracker = PluginResourceTracker::GetInstance(); |
431 PP_Resource resource = tracker->PluginResourceForHostResource(host_resource); | 444 PP_Resource resource = tracker->PluginResourceForHostResource(host_resource); |
432 if (!resource || !ppp_video_capture_impl_ || enter.failed()) | 445 if (!resource || !ppp_video_capture_target() || enter.failed()) |
433 return; | 446 return; |
434 static_cast<VideoCapture*>(enter.object())->SetBufferInUse(buffer); | 447 static_cast<VideoCapture*>(enter.object())->SetBufferInUse(buffer); |
435 ppp_video_capture_impl_->OnBufferReady( | 448 ppp_video_capture_target()->OnBufferReady( |
436 host_resource.instance(), resource, buffer); | 449 host_resource.instance(), resource, buffer); |
437 } | 450 } |
438 | 451 |
439 } // namespace proxy | 452 } // namespace proxy |
440 } // namespace ppapi | 453 } // namespace ppapi |
OLD | NEW |