ppp_video_decoder_proxy.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
1// Copyright (c) 2012 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/proxy/ppp_video_decoder_proxy.h"
6
7#include "ppapi/proxy/host_dispatcher.h"
8#include "ppapi/proxy/plugin_globals.h"
9#include "ppapi/proxy/plugin_resource_tracker.h"
10#include "ppapi/proxy/ppapi_messages.h"
11#include "ppapi/proxy/ppb_video_decoder_proxy.h"
12#include "ppapi/thunk/enter.h"
13#include "ppapi/thunk/ppb_video_decoder_api.h"
14#include "ppapi/thunk/thunk.h"
15
16using ppapi::thunk::PPB_VideoDecoder_API;
17
18namespace ppapi {
19namespace proxy {
20
21namespace {
22
23void ProvidePictureBuffers(PP_Instance instance, PP_Resource decoder,
24                           uint32_t req_num_of_bufs,
25                           const PP_Size* dimensions,
26                           uint32_t texture_target) {
27  HostResource decoder_resource;
28  decoder_resource.SetHostResource(instance, decoder);
29
30  HostDispatcher::GetForInstance(instance)->Send(
31      new PpapiMsg_PPPVideoDecoder_ProvidePictureBuffers(
32          API_ID_PPP_VIDEO_DECODER_DEV,
33          decoder_resource, req_num_of_bufs, *dimensions, texture_target));
34}
35
36void DismissPictureBuffer(PP_Instance instance, PP_Resource decoder,
37                          int32_t picture_buffer_id) {
38  HostResource decoder_resource;
39  decoder_resource.SetHostResource(instance, decoder);
40
41  HostDispatcher::GetForInstance(instance)->Send(
42      new PpapiMsg_PPPVideoDecoder_DismissPictureBuffer(
43          API_ID_PPP_VIDEO_DECODER_DEV,
44          decoder_resource, picture_buffer_id));
45}
46
47void PictureReady(PP_Instance instance, PP_Resource decoder,
48                  const PP_Picture_Dev* picture) {
49  HostResource decoder_resource;
50  decoder_resource.SetHostResource(instance, decoder);
51
52  HostDispatcher::GetForInstance(instance)->Send(
53      new PpapiMsg_PPPVideoDecoder_PictureReady(
54          API_ID_PPP_VIDEO_DECODER_DEV, decoder_resource, *picture));
55}
56
57void NotifyError(PP_Instance instance, PP_Resource decoder,
58                 PP_VideoDecodeError_Dev error) {
59  HostResource decoder_resource;
60  decoder_resource.SetHostResource(instance, decoder);
61
62  HostDispatcher::GetForInstance(instance)->Send(
63      new PpapiMsg_PPPVideoDecoder_NotifyError(
64          API_ID_PPP_VIDEO_DECODER_DEV, decoder_resource, error));
65}
66
67static const PPP_VideoDecoder_Dev video_decoder_interface = {
68  &ProvidePictureBuffers,
69  &DismissPictureBuffer,
70  &PictureReady,
71  &NotifyError
72};
73
74InterfaceProxy* CreateVideoDecoderPPPProxy(Dispatcher* dispatcher) {
75  return new PPP_VideoDecoder_Proxy(dispatcher);
76}
77
78}  // namespace
79
80PPP_VideoDecoder_Proxy::PPP_VideoDecoder_Proxy(Dispatcher* dispatcher)
81    : InterfaceProxy(dispatcher),
82      ppp_video_decoder_impl_(NULL) {
83  if (dispatcher->IsPlugin()) {
84    ppp_video_decoder_impl_ = static_cast<const PPP_VideoDecoder_Dev*>(
85        dispatcher->local_get_interface()(PPP_VIDEODECODER_DEV_INTERFACE));
86  }
87}
88
89PPP_VideoDecoder_Proxy::~PPP_VideoDecoder_Proxy() {
90}
91
92// static
93const InterfaceProxy::Info* PPP_VideoDecoder_Proxy::GetInfo() {
94  static const Info info = {
95    &video_decoder_interface,
96    PPP_VIDEODECODER_DEV_INTERFACE,
97    API_ID_PPP_VIDEO_DECODER_DEV,
98    false,
99    &CreateVideoDecoderPPPProxy,
100  };
101  return &info;
102}
103
104bool PPP_VideoDecoder_Proxy::OnMessageReceived(const IPC::Message& msg) {
105  bool handled = true;
106  IPC_BEGIN_MESSAGE_MAP(PPP_VideoDecoder_Proxy, msg)
107    IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoDecoder_ProvidePictureBuffers,
108                        OnMsgProvidePictureBuffers)
109    IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoDecoder_DismissPictureBuffer,
110                        OnMsgDismissPictureBuffer)
111    IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoDecoder_PictureReady,
112                        OnMsgPictureReady)
113    IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoDecoder_NotifyError,
114                        OnMsgNotifyError)
115    IPC_MESSAGE_UNHANDLED(handled = false)
116  IPC_END_MESSAGE_MAP()
117  DCHECK(handled);
118  return handled;
119}
120
121void PPP_VideoDecoder_Proxy::OnMsgProvidePictureBuffers(
122    const HostResource& decoder,
123    uint32_t req_num_of_bufs,
124    const PP_Size& dimensions,
125    uint32_t texture_target) {
126  PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()->
127      PluginResourceForHostResource(decoder);
128  if (!plugin_decoder)
129    return;
130  CallWhileUnlocked(ppp_video_decoder_impl_->ProvidePictureBuffers,
131                    decoder.instance(),
132                    plugin_decoder,
133                    req_num_of_bufs,
134                    &dimensions,
135                    texture_target);
136}
137
138void PPP_VideoDecoder_Proxy::OnMsgDismissPictureBuffer(
139    const HostResource& decoder, int32_t picture_id) {
140  PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()->
141      PluginResourceForHostResource(decoder);
142  if (!plugin_decoder)
143    return;
144  CallWhileUnlocked(ppp_video_decoder_impl_->DismissPictureBuffer,
145                    decoder.instance(),
146                    plugin_decoder,
147                    picture_id);
148}
149
150void PPP_VideoDecoder_Proxy::OnMsgPictureReady(
151    const HostResource& decoder, const PP_Picture_Dev& picture) {
152  PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()->
153      PluginResourceForHostResource(decoder);
154  if (!plugin_decoder)
155    return;
156  CallWhileUnlocked(ppp_video_decoder_impl_->PictureReady,
157                    decoder.instance(),
158                    plugin_decoder,
159                    &picture);
160}
161
162void PPP_VideoDecoder_Proxy::OnMsgNotifyError(
163    const HostResource& decoder, PP_VideoDecodeError_Dev error) {
164  PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()->
165      PluginResourceForHostResource(decoder);
166  if (!plugin_decoder)
167    return;
168  CallWhileUnlocked(ppp_video_decoder_impl_->NotifyError,
169                    decoder.instance(),
170                    plugin_decoder,
171                    error);
172}
173
174}  // namespace proxy
175}  // namespace ppapi
176