Pepper_47_C++_interfaces
video_capture_client_dev.cc
Go to the documentation of this file.
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 
6 
7 #include "ppapi/c/dev/ppp_video_capture_dev.h"
8 #include "ppapi/cpp/instance.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 
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 
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 
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 
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 
69  : instance_(instance) {
70  Module::Get()->AddPluginInterface(kPPPVideoCaptureInterface,
71  &ppp_video_capture);
72  instance->AddPerInstanceObject(kPPPVideoCaptureInterface, this);
73 }
74 
77  kPPPVideoCaptureInterface, this);
78 }
79 
80 } // namespace pp
void AddPluginInterface(const std::string &interface_name, const void *vtable)
Definition: module.cc:190
void RemovePerInstanceObject(const std::string &interface_name, void *object)
Definition: instance.cc:219
static void * GetPerInstanceObject(PP_Instance instance, const std::string &interface_name)
Definition: instance.cc:249
void AddPerInstanceObject(const std::string &interface_name, void *object)
Definition: instance.cc:210
VideoCaptureClient_Dev(Instance *instance)
static Module * Get()