Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ppapi/proxy/ppb_video_decoder_proxy.h" | 5 #include "ppapi/proxy/ppb_video_decoder_proxy.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "gpu/command_buffer/client/gles2_implementation.h" | 8 #include "gpu/command_buffer/client/gles2_implementation.h" |
| 9 #include "ppapi/proxy/enter_proxy.h" | 9 #include "ppapi/proxy/enter_proxy.h" |
| 10 #include "ppapi/proxy/plugin_dispatcher.h" | 10 #include "ppapi/proxy/plugin_dispatcher.h" |
| 11 #include "ppapi/proxy/ppapi_messages.h" | 11 #include "ppapi/proxy/ppapi_messages.h" |
| 12 #include "ppapi/proxy/ppb_buffer_proxy.h" | 12 #include "ppapi/proxy/ppb_buffer_proxy.h" |
| 13 #include "ppapi/proxy/ppb_context_3d_proxy.h" | 13 #include "ppapi/proxy/ppb_context_3d_proxy.h" |
| 14 #include "ppapi/thunk/enter.h" | 14 #include "ppapi/thunk/enter.h" |
| 15 #include "ppapi/thunk/resource_creation_api.h" | 15 #include "ppapi/thunk/resource_creation_api.h" |
| 16 #include "ppapi/thunk/thunk.h" | 16 #include "ppapi/thunk/thunk.h" |
| 17 | 17 |
| 18 using ppapi::HostResource; | |
| 19 using ppapi::Resource; | |
| 20 using ppapi::thunk::EnterResourceNoLock; | 18 using ppapi::thunk::EnterResourceNoLock; |
| 21 using ppapi::thunk::PPB_Buffer_API; | 19 using ppapi::thunk::PPB_Buffer_API; |
| 22 using ppapi::thunk::PPB_Context3D_API; | 20 using ppapi::thunk::PPB_Context3D_API; |
| 23 using ppapi::thunk::PPB_VideoDecoder_API; | 21 using ppapi::thunk::PPB_VideoDecoder_API; |
|
bbudge
2011/08/16 22:40:49
There are lots of explicitly qualified 'thunk' typ
| |
| 24 | 22 |
| 25 namespace pp { | 23 namespace ppapi { |
| 26 namespace proxy { | 24 namespace proxy { |
| 27 | 25 |
| 28 class VideoDecoder : public Resource, | 26 class VideoDecoder : public Resource, public VideoDecoderImpl { |
| 29 public ::ppapi::VideoDecoderImpl { | |
| 30 public: | 27 public: |
| 31 // You must call Init() before using this class. | 28 // You must call Init() before using this class. |
| 32 explicit VideoDecoder(const HostResource& resource); | 29 explicit VideoDecoder(const HostResource& resource); |
| 33 virtual ~VideoDecoder(); | 30 virtual ~VideoDecoder(); |
| 34 | 31 |
| 35 static VideoDecoder* Create(const HostResource& resource, | 32 static VideoDecoder* Create(const HostResource& resource, |
| 36 PP_Resource context3d_id, | 33 PP_Resource context3d_id, |
| 37 const PP_VideoConfigElement* config); | 34 const PP_VideoConfigElement* config); |
| 38 | 35 |
| 39 // Resource overrides. | 36 // Resource overrides. |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 61 | 58 |
| 62 DISALLOW_COPY_AND_ASSIGN(VideoDecoder); | 59 DISALLOW_COPY_AND_ASSIGN(VideoDecoder); |
| 63 }; | 60 }; |
| 64 | 61 |
| 65 VideoDecoder::VideoDecoder(const HostResource& decoder) : Resource(decoder) { | 62 VideoDecoder::VideoDecoder(const HostResource& decoder) : Resource(decoder) { |
| 66 } | 63 } |
| 67 | 64 |
| 68 VideoDecoder::~VideoDecoder() { | 65 VideoDecoder::~VideoDecoder() { |
| 69 } | 66 } |
| 70 | 67 |
| 71 ::ppapi::thunk::PPB_VideoDecoder_API* VideoDecoder::AsPPB_VideoDecoder_API() { | 68 thunk::PPB_VideoDecoder_API* VideoDecoder::AsPPB_VideoDecoder_API() { |
| 72 return this; | 69 return this; |
| 73 } | 70 } |
| 74 | 71 |
| 75 int32_t VideoDecoder::Decode( | 72 int32_t VideoDecoder::Decode( |
| 76 const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, | 73 const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, |
| 77 PP_CompletionCallback callback) { | 74 PP_CompletionCallback callback) { |
| 78 ppapi::thunk::EnterResourceNoLock<PPB_Buffer_API> | 75 thunk::EnterResourceNoLock<PPB_Buffer_API> |
| 79 enter_buffer(bitstream_buffer->data, true); | 76 enter_buffer(bitstream_buffer->data, true); |
| 80 if (enter_buffer.failed()) | 77 if (enter_buffer.failed()) |
| 81 return PP_ERROR_BADRESOURCE; | 78 return PP_ERROR_BADRESOURCE; |
| 82 | 79 |
| 83 if (!SetBitstreamBufferCallback(bitstream_buffer->id, callback)) | 80 if (!SetBitstreamBufferCallback(bitstream_buffer->id, callback)) |
| 84 return PP_ERROR_BADARGUMENT; | 81 return PP_ERROR_BADARGUMENT; |
| 85 | 82 |
| 86 Buffer* ppb_buffer = | 83 Buffer* ppb_buffer = |
| 87 static_cast<Buffer*>(enter_buffer.object()); | 84 static_cast<Buffer*>(enter_buffer.object()); |
| 88 HostResource host_buffer = ppb_buffer->host_resource(); | 85 HostResource host_buffer = ppb_buffer->host_resource(); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 FlushCommandBuffer(); | 125 FlushCommandBuffer(); |
| 129 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Reset( | 126 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Reset( |
| 130 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource())); | 127 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource())); |
| 131 return PP_OK_COMPLETIONPENDING; | 128 return PP_OK_COMPLETIONPENDING; |
| 132 } | 129 } |
| 133 | 130 |
| 134 void VideoDecoder::Destroy() { | 131 void VideoDecoder::Destroy() { |
| 135 FlushCommandBuffer(); | 132 FlushCommandBuffer(); |
| 136 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Destroy( | 133 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Destroy( |
| 137 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource())); | 134 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource())); |
| 138 ::ppapi::VideoDecoderImpl::Destroy(); | 135 VideoDecoderImpl::Destroy(); |
| 139 } | 136 } |
| 140 | 137 |
| 141 PluginDispatcher* VideoDecoder::GetDispatcher() const { | 138 PluginDispatcher* VideoDecoder::GetDispatcher() const { |
| 142 return PluginDispatcher::GetForResource(this); | 139 return PluginDispatcher::GetForResource(this); |
| 143 } | 140 } |
| 144 | 141 |
| 145 void VideoDecoder::ResetACK(int32_t result) { | 142 void VideoDecoder::ResetACK(int32_t result) { |
| 146 RunResetCallback(result); | 143 RunResetCallback(result); |
| 147 } | 144 } |
| 148 | 145 |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 169 : InterfaceProxy(dispatcher, target_interface), | 166 : InterfaceProxy(dispatcher, target_interface), |
| 170 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 167 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
| 171 } | 168 } |
| 172 | 169 |
| 173 PPB_VideoDecoder_Proxy::~PPB_VideoDecoder_Proxy() { | 170 PPB_VideoDecoder_Proxy::~PPB_VideoDecoder_Proxy() { |
| 174 } | 171 } |
| 175 | 172 |
| 176 // static | 173 // static |
| 177 const InterfaceProxy::Info* PPB_VideoDecoder_Proxy::GetInfo() { | 174 const InterfaceProxy::Info* PPB_VideoDecoder_Proxy::GetInfo() { |
| 178 static const Info info = { | 175 static const Info info = { |
| 179 ::ppapi::thunk::GetPPB_VideoDecoder_Thunk(), | 176 thunk::GetPPB_VideoDecoder_Thunk(), |
| 180 PPB_VIDEODECODER_DEV_INTERFACE, | 177 PPB_VIDEODECODER_DEV_INTERFACE, |
| 181 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, | 178 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, |
| 182 false, | 179 false, |
| 183 &CreateVideoDecoderProxy, | 180 &CreateVideoDecoderProxy, |
| 184 }; | 181 }; |
| 185 return &info; | 182 return &info; |
| 186 } | 183 } |
| 187 | 184 |
| 188 bool PPB_VideoDecoder_Proxy::OnMessageReceived(const IPC::Message& msg) { | 185 bool PPB_VideoDecoder_Proxy::OnMessageReceived(const IPC::Message& msg) { |
| 189 bool handled = true; | 186 bool handled = true; |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 211 PP_Resource PPB_VideoDecoder_Proxy::CreateProxyResource( | 208 PP_Resource PPB_VideoDecoder_Proxy::CreateProxyResource( |
| 212 PP_Instance instance, PP_Resource context3d_id, | 209 PP_Instance instance, PP_Resource context3d_id, |
| 213 const PP_VideoConfigElement* config) { | 210 const PP_VideoConfigElement* config) { |
| 214 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); | 211 PluginDispatcher* dispatcher = PluginDispatcher::GetForInstance(instance); |
| 215 // Dispatcher is null if it cannot find the instance passed to it (i.e. if the | 212 // Dispatcher is null if it cannot find the instance passed to it (i.e. if the |
| 216 // client passes in an invalid instance). | 213 // client passes in an invalid instance). |
| 217 if (!dispatcher) | 214 if (!dispatcher) |
| 218 return 0; | 215 return 0; |
| 219 | 216 |
| 220 std::vector<PP_VideoConfigElement> copied; | 217 std::vector<PP_VideoConfigElement> copied; |
| 221 if (!ppapi::VideoDecoderImpl::CopyConfigsToVector(config, &copied)) | 218 if (!VideoDecoderImpl::CopyConfigsToVector(config, &copied)) |
| 222 return 0; | 219 return 0; |
| 223 | 220 |
| 224 ppapi::thunk::EnterResourceNoLock<PPB_Context3D_API> | 221 thunk::EnterResourceNoLock<PPB_Context3D_API> enter_context(context3d_id, |
| 225 enter_context(context3d_id, true); | 222 true); |
| 226 if (enter_context.failed()) | 223 if (enter_context.failed()) |
| 227 return 0; | 224 return 0; |
| 228 Context3D* ppb_context = | 225 Context3D* ppb_context = |
| 229 static_cast<Context3D*>(enter_context.object()); | 226 static_cast<Context3D*>(enter_context.object()); |
| 230 HostResource host_context = ppb_context->host_resource(); | 227 HostResource host_context = ppb_context->host_resource(); |
| 231 | 228 |
| 232 HostResource result; | 229 HostResource result; |
| 233 dispatcher->Send(new PpapiHostMsg_PPBVideoDecoder_Create( | 230 dispatcher->Send(new PpapiHostMsg_PPBVideoDecoder_Create( |
| 234 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, instance, | 231 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, instance, |
| 235 host_context, copied, &result)); | 232 host_context, copied, &result)); |
| 236 if (result.is_null()) | 233 if (result.is_null()) |
| 237 return 0; | 234 return 0; |
| 238 | 235 |
| 239 scoped_refptr<VideoDecoder> decoder(new VideoDecoder(result)); | 236 scoped_refptr<VideoDecoder> decoder(new VideoDecoder(result)); |
| 240 if (!decoder->Init(context3d_id, enter_context.object(), config)) | 237 if (!decoder->Init(context3d_id, enter_context.object(), config)) |
| 241 return 0; | 238 return 0; |
| 242 return decoder->GetReference(); | 239 return decoder->GetReference(); |
| 243 } | 240 } |
| 244 | 241 |
| 245 void PPB_VideoDecoder_Proxy::OnMsgCreate( | 242 void PPB_VideoDecoder_Proxy::OnMsgCreate( |
| 246 PP_Instance instance, const HostResource& context3d_id, | 243 PP_Instance instance, const HostResource& context3d_id, |
| 247 const std::vector<PP_VideoConfigElement>& config, | 244 const std::vector<PP_VideoConfigElement>& config, |
| 248 HostResource* result) { | 245 HostResource* result) { |
| 249 ::ppapi::thunk::EnterFunction< ::ppapi::thunk::ResourceCreationAPI> | 246 thunk::EnterFunction<thunk::ResourceCreationAPI> resource_creation(instance, |
| 250 resource_creation(instance, true); | 247 true); |
| 251 if (resource_creation.failed()) | 248 if (resource_creation.failed()) |
| 252 return; | 249 return; |
| 253 | 250 |
| 254 std::vector<PP_VideoConfigElement> copied = config; | 251 std::vector<PP_VideoConfigElement> copied = config; |
| 255 copied.push_back(PP_VIDEOATTR_DICTIONARY_TERMINATOR); | 252 copied.push_back(PP_VIDEOATTR_DICTIONARY_TERMINATOR); |
| 256 | 253 |
| 257 // Make the resource and get the API pointer to its interface. | 254 // Make the resource and get the API pointer to its interface. |
| 258 result->SetHostResource( | 255 result->SetHostResource( |
| 259 instance, resource_creation.functions()->CreateVideoDecoder( | 256 instance, resource_creation.functions()->CreateVideoDecoder( |
| 260 instance, context3d_id.host_resource(), &copied.front())); | 257 instance, context3d_id.host_resource(), &copied.front())); |
| 261 } | 258 } |
| 262 | 259 |
| 263 void PPB_VideoDecoder_Proxy::OnMsgDecode( | 260 void PPB_VideoDecoder_Proxy::OnMsgDecode( |
| 264 const HostResource& decoder, | 261 const HostResource& decoder, |
| 265 const HostResource& buffer, int32 id, int32 size) { | 262 const HostResource& buffer, int32 id, int32 size) { |
| 266 CompletionCallback callback = callback_factory_.NewRequiredCallback( | 263 pp::CompletionCallback callback = callback_factory_.NewRequiredCallback( |
| 267 &PPB_VideoDecoder_Proxy::SendMsgEndOfBitstreamACKToPlugin, decoder, id); | 264 &PPB_VideoDecoder_Proxy::SendMsgEndOfBitstreamACKToPlugin, decoder, id); |
| 268 | 265 |
| 269 PP_VideoBitstreamBuffer_Dev bitstream = { id, buffer.host_resource(), size }; | 266 PP_VideoBitstreamBuffer_Dev bitstream = { id, buffer.host_resource(), size }; |
| 270 ppb_video_decoder_target()->Decode( | 267 ppb_video_decoder_target()->Decode( |
| 271 decoder.host_resource(), &bitstream, callback.pp_completion_callback()); | 268 decoder.host_resource(), &bitstream, callback.pp_completion_callback()); |
| 272 } | 269 } |
| 273 | 270 |
| 274 void PPB_VideoDecoder_Proxy::OnMsgAssignPictureBuffers( | 271 void PPB_VideoDecoder_Proxy::OnMsgAssignPictureBuffers( |
| 275 const HostResource& decoder, | 272 const HostResource& decoder, |
| 276 const std::vector<PP_PictureBuffer_Dev>& buffers) { | 273 const std::vector<PP_PictureBuffer_Dev>& buffers) { |
| 277 DCHECK(!buffers.empty()); | 274 DCHECK(!buffers.empty()); |
| 278 const PP_PictureBuffer_Dev* buffer_array = &buffers.front(); | 275 const PP_PictureBuffer_Dev* buffer_array = &buffers.front(); |
| 279 | 276 |
| 280 ppb_video_decoder_target()->AssignPictureBuffers( | 277 ppb_video_decoder_target()->AssignPictureBuffers( |
| 281 decoder.host_resource(), buffers.size(), buffer_array); | 278 decoder.host_resource(), buffers.size(), buffer_array); |
| 282 } | 279 } |
| 283 | 280 |
| 284 void PPB_VideoDecoder_Proxy::OnMsgReusePictureBuffer( | 281 void PPB_VideoDecoder_Proxy::OnMsgReusePictureBuffer( |
| 285 const HostResource& decoder, int32 picture_buffer_id) { | 282 const HostResource& decoder, int32 picture_buffer_id) { |
| 286 ppb_video_decoder_target()->ReusePictureBuffer( | 283 ppb_video_decoder_target()->ReusePictureBuffer( |
| 287 decoder.host_resource(), picture_buffer_id); | 284 decoder.host_resource(), picture_buffer_id); |
| 288 } | 285 } |
| 289 | 286 |
| 290 void PPB_VideoDecoder_Proxy::OnMsgFlush(const HostResource& decoder) { | 287 void PPB_VideoDecoder_Proxy::OnMsgFlush(const HostResource& decoder) { |
| 291 CompletionCallback callback = callback_factory_.NewRequiredCallback( | 288 pp::CompletionCallback callback = callback_factory_.NewRequiredCallback( |
| 292 &PPB_VideoDecoder_Proxy::SendMsgFlushACKToPlugin, decoder); | 289 &PPB_VideoDecoder_Proxy::SendMsgFlushACKToPlugin, decoder); |
| 293 ppb_video_decoder_target()->Flush( | 290 ppb_video_decoder_target()->Flush( |
| 294 decoder.host_resource(), callback.pp_completion_callback()); | 291 decoder.host_resource(), callback.pp_completion_callback()); |
| 295 } | 292 } |
| 296 | 293 |
| 297 void PPB_VideoDecoder_Proxy::OnMsgReset(const HostResource& decoder) { | 294 void PPB_VideoDecoder_Proxy::OnMsgReset(const HostResource& decoder) { |
| 298 CompletionCallback callback = callback_factory_.NewRequiredCallback( | 295 pp::CompletionCallback callback = callback_factory_.NewRequiredCallback( |
| 299 &PPB_VideoDecoder_Proxy::SendMsgResetACKToPlugin, decoder); | 296 &PPB_VideoDecoder_Proxy::SendMsgResetACKToPlugin, decoder); |
| 300 ppb_video_decoder_target()->Reset( | 297 ppb_video_decoder_target()->Reset( |
| 301 decoder.host_resource(), callback.pp_completion_callback()); | 298 decoder.host_resource(), callback.pp_completion_callback()); |
| 302 } | 299 } |
| 303 | 300 |
| 304 void PPB_VideoDecoder_Proxy::OnMsgDestroy(const HostResource& decoder) { | 301 void PPB_VideoDecoder_Proxy::OnMsgDestroy(const HostResource& decoder) { |
| 305 ppb_video_decoder_target()->Destroy(decoder.host_resource()); | 302 ppb_video_decoder_target()->Destroy(decoder.host_resource()); |
| 306 } | 303 } |
| 307 | 304 |
| 308 void PPB_VideoDecoder_Proxy::SendMsgEndOfBitstreamACKToPlugin( | 305 void PPB_VideoDecoder_Proxy::SendMsgEndOfBitstreamACKToPlugin( |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 338 } | 335 } |
| 339 | 336 |
| 340 void PPB_VideoDecoder_Proxy::OnMsgResetACK( | 337 void PPB_VideoDecoder_Proxy::OnMsgResetACK( |
| 341 const HostResource& decoder, int32_t result) { | 338 const HostResource& decoder, int32_t result) { |
| 342 EnterPluginFromHostResource<PPB_VideoDecoder_API> enter(decoder); | 339 EnterPluginFromHostResource<PPB_VideoDecoder_API> enter(decoder); |
| 343 if (enter.succeeded()) | 340 if (enter.succeeded()) |
| 344 static_cast<VideoDecoder*>(enter.object())->ResetACK(result); | 341 static_cast<VideoDecoder*>(enter.object())->ResetACK(result); |
| 345 } | 342 } |
| 346 | 343 |
| 347 } // namespace proxy | 344 } // namespace proxy |
| 348 } // namespace pp | 345 } // namespace ppapi |
| OLD | NEW |