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

Side by Side Diff: ppapi/proxy/ppb_video_capture_proxy.cc

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

Powered by Google App Engine
This is Rietveld 408576698