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.
5 #include "ppapi/cpp/dev/video_capture_client_dev.h"
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"
16 const char kPPPVideoCaptureInterface
[] = PPP_VIDEO_CAPTURE_DEV_INTERFACE
;
18 void OnDeviceInfo(PP_Instance instance
,
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
));
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
]));
33 client
->OnDeviceInfo(resource
, *info
, buffer_list
);
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
));
40 client
->OnStatus(resource
, status
);
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
));
47 client
->OnError(resource
, error_code
);
50 void OnBufferReady(PP_Instance instance
,
53 VideoCaptureClient_Dev
* client
= static_cast<VideoCaptureClient_Dev
*>(
54 Instance::GetPerInstanceObject(instance
, kPPPVideoCaptureInterface
));
56 client
->OnBufferReady(resource
, buffer
);
59 PPP_VideoCapture_Dev ppp_video_capture
= {
68 VideoCaptureClient_Dev::VideoCaptureClient_Dev(Instance
* instance
)
69 : instance_(instance
) {
70 Module::Get()->AddPluginInterface(kPPPVideoCaptureInterface
,
72 instance
->AddPerInstanceObject(kPPPVideoCaptureInterface
, this);
75 VideoCaptureClient_Dev::~VideoCaptureClient_Dev() {
76 Instance::RemovePerInstanceObject(instance_
,
77 kPPPVideoCaptureInterface
, this);