[email protected] | c80a0ba | 2012-01-13 00:02:29 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 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" |
[email protected] | 794d83cd | 2011-10-20 19:09:20 | [diff] [blame] | 8 | #include "ppapi/proxy/plugin_globals.h" |
[email protected] | 7f8b26b | 2011-08-18 15:41:01 | [diff] [blame] | 9 | #include "ppapi/proxy/plugin_resource_tracker.h" |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 10 | #include "ppapi/proxy/ppapi_messages.h" |
| 11 | #include "ppapi/proxy/ppb_video_decoder_proxy.h" |
| 12 | #include "ppapi/thunk/enter.h" |
[email protected] | 4ba60db | 2014-05-06 07:08:19 | [diff] [blame] | 13 | #include "ppapi/thunk/ppb_video_decoder_dev_api.h" |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 14 | #include "ppapi/thunk/thunk.h" |
| 15 | |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 16 | namespace ppapi { |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 17 | namespace proxy { |
| 18 | |
| 19 | namespace { |
| 20 | |
| 21 | void ProvidePictureBuffers(PP_Instance instance, PP_Resource decoder, |
[email protected] | dd439314 | 2011-10-07 21:28:28 | [diff] [blame] | 22 | uint32_t req_num_of_bufs, |
[email protected] | 08bab53 | 2012-06-08 19:39:45 | [diff] [blame] | 23 | const PP_Size* dimensions, |
| 24 | uint32_t texture_target) { |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 25 | HostResource decoder_resource; |
| 26 | decoder_resource.SetHostResource(instance, decoder); |
| 27 | |
brettw | d1edc257 | 2016-09-28 21:53:47 | [diff] [blame] | 28 | // 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] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | void DismissPictureBuffer(PP_Instance instance, PP_Resource decoder, |
| 40 | int32_t picture_buffer_id) { |
| 41 | HostResource decoder_resource; |
| 42 | decoder_resource.SetHostResource(instance, decoder); |
| 43 | |
brettw | d1edc257 | 2016-09-28 21:53:47 | [diff] [blame] | 44 | // 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] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 51 | } |
| 52 | |
| 53 | void PictureReady(PP_Instance instance, PP_Resource decoder, |
[email protected] | dd439314 | 2011-10-07 21:28:28 | [diff] [blame] | 54 | const PP_Picture_Dev* picture) { |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 55 | HostResource decoder_resource; |
| 56 | decoder_resource.SetHostResource(instance, decoder); |
| 57 | |
brettw | d1edc257 | 2016-09-28 21:53:47 | [diff] [blame] | 58 | // 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] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 64 | } |
| 65 | |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 66 | void 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] | fb9f74a | 2013-05-08 19:05:10 | [diff] [blame] | 71 | // 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] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 77 | new PpapiMsg_PPPVideoDecoder_NotifyError( |
[email protected] | ac4b54d | 2011-10-20 23:09:28 | [diff] [blame] | 78 | API_ID_PPP_VIDEO_DECODER_DEV, decoder_resource, error)); |
[email protected] | fb9f74a | 2013-05-08 19:05:10 | [diff] [blame] | 79 | } |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | static const PPP_VideoDecoder_Dev video_decoder_interface = { |
| 83 | &ProvidePictureBuffers, |
| 84 | &DismissPictureBuffer, |
| 85 | &PictureReady, |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 86 | &NotifyError |
| 87 | }; |
| 88 | |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 89 | } // namespace |
| 90 | |
[email protected] | 5c96602 | 2011-09-13 18:09:37 | [diff] [blame] | 91 | PPP_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] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 98 | } |
| 99 | |
| 100 | PPP_VideoDecoder_Proxy::~PPP_VideoDecoder_Proxy() { |
| 101 | } |
| 102 | |
| 103 | // static |
[email protected] | 6642ebf | 2013-12-17 20:49:30 | [diff] [blame] | 104 | const PPP_VideoDecoder_Dev* PPP_VideoDecoder_Proxy::GetProxyInterface() { |
| 105 | return &video_decoder_interface; |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | bool PPP_VideoDecoder_Proxy::OnMessageReceived(const IPC::Message& msg) { |
[email protected] | d5f5dc1 | 2013-01-22 23:05:03 | [diff] [blame] | 109 | if (!dispatcher()->IsPlugin()) |
| 110 | return false; |
| 111 | |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 112 | 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] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 120 | 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 | |
| 128 | void PPP_VideoDecoder_Proxy::OnMsgProvidePictureBuffers( |
[email protected] | 08bab53 | 2012-06-08 19:39:45 | [diff] [blame] | 129 | const HostResource& decoder, |
| 130 | uint32_t req_num_of_bufs, |
| 131 | const PP_Size& dimensions, |
| 132 | uint32_t texture_target) { |
[email protected] | 794d83cd | 2011-10-20 19:09:20 | [diff] [blame] | 133 | PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()-> |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 134 | PluginResourceForHostResource(decoder); |
[email protected] | fe1f67a | 2012-08-23 02:15:34 | [diff] [blame] | 135 | if (!plugin_decoder) |
| 136 | return; |
[email protected] | 4c41d3f | 2012-02-15 01:44:47 | [diff] [blame] | 137 | CallWhileUnlocked(ppp_video_decoder_impl_->ProvidePictureBuffers, |
| 138 | decoder.instance(), |
| 139 | plugin_decoder, |
| 140 | req_num_of_bufs, |
[email protected] | 08bab53 | 2012-06-08 19:39:45 | [diff] [blame] | 141 | &dimensions, |
| 142 | texture_target); |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | void PPP_VideoDecoder_Proxy::OnMsgDismissPictureBuffer( |
| 146 | const HostResource& decoder, int32_t picture_id) { |
[email protected] | 794d83cd | 2011-10-20 19:09:20 | [diff] [blame] | 147 | PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()-> |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 148 | PluginResourceForHostResource(decoder); |
[email protected] | fe1f67a | 2012-08-23 02:15:34 | [diff] [blame] | 149 | if (!plugin_decoder) |
| 150 | return; |
[email protected] | 4c41d3f | 2012-02-15 01:44:47 | [diff] [blame] | 151 | CallWhileUnlocked(ppp_video_decoder_impl_->DismissPictureBuffer, |
| 152 | decoder.instance(), |
| 153 | plugin_decoder, |
| 154 | picture_id); |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | void PPP_VideoDecoder_Proxy::OnMsgPictureReady( |
| 158 | const HostResource& decoder, const PP_Picture_Dev& picture) { |
[email protected] | 794d83cd | 2011-10-20 19:09:20 | [diff] [blame] | 159 | PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()-> |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 160 | PluginResourceForHostResource(decoder); |
[email protected] | fe1f67a | 2012-08-23 02:15:34 | [diff] [blame] | 161 | if (!plugin_decoder) |
| 162 | return; |
[email protected] | 4c41d3f | 2012-02-15 01:44:47 | [diff] [blame] | 163 | CallWhileUnlocked(ppp_video_decoder_impl_->PictureReady, |
| 164 | decoder.instance(), |
| 165 | plugin_decoder, |
| 166 | &picture); |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 167 | } |
| 168 | |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 169 | void PPP_VideoDecoder_Proxy::OnMsgNotifyError( |
| 170 | const HostResource& decoder, PP_VideoDecodeError_Dev error) { |
[email protected] | 794d83cd | 2011-10-20 19:09:20 | [diff] [blame] | 171 | PP_Resource plugin_decoder = PluginGlobals::Get()->plugin_resource_tracker()-> |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 172 | PluginResourceForHostResource(decoder); |
[email protected] | fe1f67a | 2012-08-23 02:15:34 | [diff] [blame] | 173 | if (!plugin_decoder) |
| 174 | return; |
[email protected] | 4c41d3f | 2012-02-15 01:44:47 | [diff] [blame] | 175 | CallWhileUnlocked(ppp_video_decoder_impl_->NotifyError, |
| 176 | decoder.instance(), |
| 177 | plugin_decoder, |
| 178 | error); |
[email protected] | 7ace8ad | 2011-08-06 03:23:58 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | } // namespace proxy |
[email protected] | 4d2efd2 | 2011-08-18 21:58:02 | [diff] [blame] | 182 | } // namespace ppapi |