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