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
3 // found in the LICENSE file.
4
5 #include "ppapi/cpp/dev/video_capture_client_dev.h"
6
7 #include "ppapi/c/dev/ppp_video_capture_dev.h"
8 #include "ppapi/cpp/instance.h"
9 #include "ppapi/cpp/instance_handle.h"
10 #include "ppapi/cpp/module.h"
11
12 namespace pp {
13
14 namespace {
15
16 const char kPPPVideoCaptureInterface[] = PPP_VIDEO_CAPTURE_DEV_INTERFACE;
17
OnDeviceInfo(PP_Instance instance,PP_Resource resource,const struct PP_VideoCaptureDeviceInfo_Dev * info,uint32_t buffer_count,const PP_Resource buffers[])18 void OnDeviceInfo(PP_Instance instance,
19 PP_Resource resource,
20 const struct PP_VideoCaptureDeviceInfo_Dev* info,
21 uint32_t buffer_count,
22 const PP_Resource buffers[]) {
23 VideoCaptureClient_Dev* client = static_cast<VideoCaptureClient_Dev*>(
24 Instance::GetPerInstanceObject(instance, kPPPVideoCaptureInterface));
25 if (!client)
26 return;
27
28 std::vector<Buffer_Dev> buffer_list;
29 buffer_list.reserve(buffer_count);
30 for (uint32_t i = 0; i < buffer_count; ++i)
31 buffer_list.push_back(Buffer_Dev(buffers[i]));
32
33 client->OnDeviceInfo(resource, *info, buffer_list);
34 }
35
OnStatus(PP_Instance instance,PP_Resource resource,uint32_t status)36 void OnStatus(PP_Instance instance, PP_Resource resource, uint32_t status) {
37 VideoCaptureClient_Dev* client = static_cast<VideoCaptureClient_Dev*>(
38 Instance::GetPerInstanceObject(instance, kPPPVideoCaptureInterface));
39 if (client)
40 client->OnStatus(resource, status);
41 }
42
OnError(PP_Instance instance,PP_Resource resource,uint32_t error_code)43 void OnError(PP_Instance instance, PP_Resource resource, uint32_t error_code) {
44 VideoCaptureClient_Dev* client = static_cast<VideoCaptureClient_Dev*>(
45 Instance::GetPerInstanceObject(instance, kPPPVideoCaptureInterface));
46 if (client)
47 client->OnError(resource, error_code);
48 }
49
OnBufferReady(PP_Instance instance,PP_Resource resource,uint32_t buffer)50 void OnBufferReady(PP_Instance instance,
51 PP_Resource resource,
52 uint32_t buffer) {
53 VideoCaptureClient_Dev* client = static_cast<VideoCaptureClient_Dev*>(
54 Instance::GetPerInstanceObject(instance, kPPPVideoCaptureInterface));
55 if (client)
56 client->OnBufferReady(resource, buffer);
57 }
58
59 PPP_VideoCapture_Dev ppp_video_capture = {
60 OnDeviceInfo,
61 OnStatus,
62 OnError,
63 OnBufferReady
64 };
65
66 } // namespace
67
VideoCaptureClient_Dev(Instance * instance)68 VideoCaptureClient_Dev::VideoCaptureClient_Dev(Instance* instance)
69 : instance_(instance) {
70 Module::Get()->AddPluginInterface(kPPPVideoCaptureInterface,
71 &ppp_video_capture);
72 instance->AddPerInstanceObject(kPPPVideoCaptureInterface, this);
73 }
74
~VideoCaptureClient_Dev()75 VideoCaptureClient_Dev::~VideoCaptureClient_Dev() {
76 Instance::RemovePerInstanceObject(instance_,
77 kPPPVideoCaptureInterface, this);
78 }
79
80 } // namespace pp
81