blob: 576ba95a5d025d1964c6961b3496bcebb4674c99 [file] [log] [blame]
[email protected]c80a0ba2012-01-13 00:02:291// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]7ace8ad2011-08-06 03:23:582// 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"
[email protected]794d83cd2011-10-20 19:09:208#include "ppapi/proxy/plugin_globals.h"
[email protected]7f8b26b2011-08-18 15:41:019#include "ppapi/proxy/plugin_resource_tracker.h"
[email protected]7ace8ad2011-08-06 03:23:5810#include "ppapi/proxy/ppapi_messages.h"
11#include "ppapi/proxy/ppb_video_decoder_proxy.h"
12#include "ppapi/thunk/enter.h"
[email protected]4ba60db2014-05-06 07:08:1913#include "ppapi/thunk/ppb_video_decoder_dev_api.h"
[email protected]7ace8ad2011-08-06 03:23:5814#include "ppapi/thunk/thunk.h"
15
[email protected]4d2efd22011-08-18 21:58:0216namespace ppapi {
[email protected]7ace8ad2011-08-06 03:23:5817namespace proxy {
18
19namespace {
20
21void ProvidePictureBuffers(PP_Instance instance, PP_Resource decoder,
[email protected]dd4393142011-10-07 21:28:2822 uint32_t req_num_of_bufs,
[email protected]08bab532012-06-08 19:39:4523 const PP_Size* dimensions,
24 uint32_t texture_target) {
[email protected]7ace8ad2011-08-06 03:23:5825 HostResource decoder_resource;
26 decoder_resource.SetHostResource(instance, decoder);
27
brettwd1edc2572016-09-28 21:53:4728 // This is called by the graphics system in response to a message from the
29 // GPU process. These messages will not be synchronized with the lifetime
30 // of the plugin so we need to null-check here.
31 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
32 if (dispatcher) {
33 dispatcher->Send(new PpapiMsg_PPPVideoDecoder_ProvidePictureBuffers(
34 API_ID_PPP_VIDEO_DECODER_DEV,
35 decoder_resource, req_num_of_bufs, *dimensions, texture_target));
36 }
[email protected]7ace8ad2011-08-06 03:23:5837}
38
39void DismissPictureBuffer(PP_Instance instance, PP_Resource decoder,
40 int32_t picture_buffer_id) {
41 HostResource decoder_resource;
42 decoder_resource.SetHostResource(instance, decoder);
43
brettwd1edc2572016-09-28 21:53:4744 // Null check as in ProvidePictureBuffers above.
45 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
46 if (dispatcher) {
47 dispatcher->Send(new PpapiMsg_PPPVideoDecoder_DismissPictureBuffer(
48 API_ID_PPP_VIDEO_DECODER_DEV,
49 decoder_resource, picture_buffer_id));
50 }
[email protected]7ace8ad2011-08-06 03:23:5851}
52
53void PictureReady(PP_Instance instance, PP_Resource decoder,
[email protected]dd4393142011-10-07 21:28:2854 const PP_Picture_Dev* picture) {
[email protected]7ace8ad2011-08-06 03:23:5855 HostResource decoder_resource;
56 decoder_resource.SetHostResource(instance, decoder);
57
brettwd1edc2572016-09-28 21:53:4758 // Null check as in ProvidePictureBuffers above.
59 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
60 if (dispatcher) {
61 dispatcher->Send(new PpapiMsg_PPPVideoDecoder_PictureReady(
62 API_ID_PPP_VIDEO_DECODER_DEV, decoder_resource, *picture));
63 }
[email protected]7ace8ad2011-08-06 03:23:5864}
65
[email protected]7ace8ad2011-08-06 03:23:5866void NotifyError(PP_Instance instance, PP_Resource decoder,
67 PP_VideoDecodeError_Dev error) {
68 HostResource decoder_resource;
69 decoder_resource.SetHostResource(instance, decoder);
70
[email protected]fb9f74a2013-05-08 19:05:1071 // It's possible that the error we're being notified about is happening
72 // because the instance is shutting down. In this case, our instance may
73 // already have been removed from the HostDispatcher map.
74 HostDispatcher* dispatcher = HostDispatcher::GetForInstance(instance);
75 if (dispatcher) {
76 dispatcher->Send(
[email protected]7ace8ad2011-08-06 03:23:5877 new PpapiMsg_PPPVideoDecoder_NotifyError(
[email protected]ac4b54d2011-10-20 23:09:2878 API_ID_PPP_VIDEO_DECODER_DEV, decoder_resource, error));
[email protected]fb9f74a2013-05-08 19:05:1079 }
[email protected]7ace8ad2011-08-06 03:23:5880}
81
82static const PPP_VideoDecoder_Dev video_decoder_interface = {
83 &ProvidePictureBuffers,
84 &DismissPictureBuffer,
85 &PictureReady,
[email protected]7ace8ad2011-08-06 03:23:5886 &NotifyError
87};
88
[email protected]7ace8ad2011-08-06 03:23:5889} // namespace
90
[email protected]5c966022011-09-13 18:09:3791PPP_VideoDecoder_Proxy::PPP_VideoDecoder_Proxy(Dispatcher* dispatcher)
92 : InterfaceProxy(dispatcher),
93 ppp_video_decoder_impl_(NULL) {
94 if (dispatcher->IsPlugin()) {
95 ppp_video_decoder_impl_ = static_cast<const PPP_VideoDecoder_Dev*>(
96 dispatcher->local_get_interface()(PPP_VIDEODECODER_DEV_INTERFACE));
97 }
[email protected]7ace8ad2011-08-06 03:23:5898}
99
100PPP_VideoDecoder_Proxy::~PPP_VideoDecoder_Proxy() {
101}
102
103// static
[email protected]6642ebf2013-12-17 20:49:30104const PPP_VideoDecoder_Dev* PPP_VideoDecoder_Proxy::GetProxyInterface() {
105 return &video_decoder_interface;
[email protected]7ace8ad2011-08-06 03:23:58106}
107
108bool PPP_VideoDecoder_Proxy::OnMessageReceived(const IPC::Message& msg) {
[email protected]d5f5dc12013-01-22 23:05:03109 if (!dispatcher()->IsPlugin())
110 return false;
111
[email protected]7ace8ad2011-08-06 03:23:58112 bool handled = true;
113 IPC_BEGIN_MESSAGE_MAP(PPP_VideoDecoder_Proxy, msg)
114 IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoDecoder_ProvidePictureBuffers,
115 OnMsgProvidePictureBuffers)
116 IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoDecoder_DismissPictureBuffer,
117 OnMsgDismissPictureBuffer)
118 IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoDecoder_PictureReady,
119 OnMsgPictureReady)
[email protected]7ace8ad2011-08-06 03:23:58120 IPC_MESSAGE_HANDLER(PpapiMsg_PPPVideoDecoder_NotifyError,
121 OnMsgNotifyError)
122 IPC_MESSAGE_UNHANDLED(handled = false)
123 IPC_END_MESSAGE_MAP()
124 DCHECK(handled);
125 return handled;
126}
127
128void PPP_VideoDecoder_Proxy::OnMsgProvidePictureBuffers(
[email protected]08bab532012-06-08 19:39:45129 const HostResource& decoder,
130 uint32_t req_num_of_bufs,
131 const PP_Size& dimensions,
132 uint32_t texture_target) {
[email protected]794d83cd2011-10-20 19:09:20133 PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()->
[email protected]7ace8ad2011-08-06 03:23:58134 PluginResourceForHostResource(decoder);
[email protected]fe1f67a2012-08-23 02:15:34135 if (!plugin_decoder)
136 return;
[email protected]4c41d3f2012-02-15 01:44:47137 CallWhileUnlocked(ppp_video_decoder_impl_->ProvidePictureBuffers,
138 decoder.instance(),
139 plugin_decoder,
140 req_num_of_bufs,
[email protected]08bab532012-06-08 19:39:45141 &dimensions,
142 texture_target);
[email protected]7ace8ad2011-08-06 03:23:58143}
144
145void PPP_VideoDecoder_Proxy::OnMsgDismissPictureBuffer(
146 const HostResource& decoder, int32_t picture_id) {
[email protected]794d83cd2011-10-20 19:09:20147 PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()->
[email protected]7ace8ad2011-08-06 03:23:58148 PluginResourceForHostResource(decoder);
[email protected]fe1f67a2012-08-23 02:15:34149 if (!plugin_decoder)
150 return;
[email protected]4c41d3f2012-02-15 01:44:47151 CallWhileUnlocked(ppp_video_decoder_impl_->DismissPictureBuffer,
152 decoder.instance(),
153 plugin_decoder,
154 picture_id);
[email protected]7ace8ad2011-08-06 03:23:58155}
156
157void PPP_VideoDecoder_Proxy::OnMsgPictureReady(
158 const HostResource& decoder, const PP_Picture_Dev& picture) {
[email protected]794d83cd2011-10-20 19:09:20159 PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()->
[email protected]7ace8ad2011-08-06 03:23:58160 PluginResourceForHostResource(decoder);
[email protected]fe1f67a2012-08-23 02:15:34161 if (!plugin_decoder)
162 return;
[email protected]4c41d3f2012-02-15 01:44:47163 CallWhileUnlocked(ppp_video_decoder_impl_->PictureReady,
164 decoder.instance(),
165 plugin_decoder,
166 &picture);
[email protected]7ace8ad2011-08-06 03:23:58167}
168
[email protected]7ace8ad2011-08-06 03:23:58169void PPP_VideoDecoder_Proxy::OnMsgNotifyError(
170 const HostResource& decoder, PP_VideoDecodeError_Dev error) {
[email protected]794d83cd2011-10-20 19:09:20171 PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()->
[email protected]7ace8ad2011-08-06 03:23:58172 PluginResourceForHostResource(decoder);
[email protected]fe1f67a2012-08-23 02:15:34173 if (!plugin_decoder)
174 return;
[email protected]4c41d3f2012-02-15 01:44:47175 CallWhileUnlocked(ppp_video_decoder_impl_->NotifyError,
176 decoder.instance(),
177 plugin_decoder,
178 error);
[email protected]7ace8ad2011-08-06 03:23:58179}
180
181} // namespace proxy
[email protected]4d2efd22011-08-18 21:58:02182} // namespace ppapi