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; | 18 using ppapi::HostResource; |
19 using ppapi::Resource; | |
19 using ppapi::thunk::EnterResourceNoLock; | 20 using ppapi::thunk::EnterResourceNoLock; |
20 using ppapi::thunk::PPB_Buffer_API; | 21 using ppapi::thunk::PPB_Buffer_API; |
21 using ppapi::thunk::PPB_Context3D_API; | 22 using ppapi::thunk::PPB_Context3D_API; |
22 using ppapi::thunk::PPB_VideoDecoder_API; | 23 using ppapi::thunk::PPB_VideoDecoder_API; |
23 | 24 |
24 namespace pp { | 25 namespace pp { |
25 namespace proxy { | 26 namespace proxy { |
26 | 27 |
27 class VideoDecoder : public PluginResource, | 28 class VideoDecoder : public Resource, |
28 public ::ppapi::VideoDecoderImpl { | 29 public ::ppapi::VideoDecoderImpl { |
29 public: | 30 public: |
31 // You must call Init() before using this class. | |
32 explicit VideoDecoder(const HostResource& resource); | |
30 virtual ~VideoDecoder(); | 33 virtual ~VideoDecoder(); |
31 | 34 |
32 static VideoDecoder* Create(const HostResource& resource, | 35 static VideoDecoder* Create(const HostResource& resource, |
33 PP_Resource context3d_id, | 36 PP_Resource context3d_id, |
34 const PP_VideoConfigElement* config); | 37 const PP_VideoConfigElement* config); |
35 | 38 |
36 // ResourceObjectBase overrides. | 39 // Resource overrides. |
37 virtual PPB_VideoDecoder_API* AsPPB_VideoDecoder_API() OVERRIDE; | 40 virtual PPB_VideoDecoder_API* AsPPB_VideoDecoder_API() OVERRIDE; |
38 | 41 |
39 // PPB_VideoDecoder_API implementation. | 42 // PPB_VideoDecoder_API implementation. |
40 virtual int32_t Decode(const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, | 43 virtual int32_t Decode(const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, |
41 PP_CompletionCallback callback) OVERRIDE; | 44 PP_CompletionCallback callback) OVERRIDE; |
42 virtual void AssignPictureBuffers( | 45 virtual void AssignPictureBuffers( |
43 uint32_t no_of_buffers, const PP_PictureBuffer_Dev* buffers) OVERRIDE; | 46 uint32_t no_of_buffers, const PP_PictureBuffer_Dev* buffers) OVERRIDE; |
44 virtual void ReusePictureBuffer(int32_t picture_buffer_id) OVERRIDE; | 47 virtual void ReusePictureBuffer(int32_t picture_buffer_id) OVERRIDE; |
45 virtual int32_t Flush(PP_CompletionCallback callback) OVERRIDE; | 48 virtual int32_t Flush(PP_CompletionCallback callback) OVERRIDE; |
46 virtual int32_t Reset(PP_CompletionCallback callback) OVERRIDE; | 49 virtual int32_t Reset(PP_CompletionCallback callback) OVERRIDE; |
47 virtual void Destroy() OVERRIDE; | 50 virtual void Destroy() OVERRIDE; |
48 | 51 |
49 protected: | |
50 virtual void AddRefResource(PP_Resource resource) OVERRIDE; | |
51 virtual void UnrefResource(PP_Resource resource) OVERRIDE; | |
52 | |
53 private: | 52 private: |
54 friend class PPB_VideoDecoder_Proxy; | 53 friend class PPB_VideoDecoder_Proxy; |
55 explicit VideoDecoder(const HostResource& resource); | 54 |
55 PluginDispatcher* GetDispatcher() const; | |
56 | 56 |
57 // Run the callbacks that were passed into the plugin interface. | 57 // Run the callbacks that were passed into the plugin interface. |
58 void FlushACK(int32_t result); | 58 void FlushACK(int32_t result); |
59 void ResetACK(int32_t result); | 59 void ResetACK(int32_t result); |
60 void EndOfBitstreamACK(int32_t buffer_id, int32_t result); | 60 void EndOfBitstreamACK(int32_t buffer_id, int32_t result); |
61 | 61 |
62 DISALLOW_COPY_AND_ASSIGN(VideoDecoder); | 62 DISALLOW_COPY_AND_ASSIGN(VideoDecoder); |
63 }; | 63 }; |
64 | 64 |
65 VideoDecoder::VideoDecoder(const HostResource& decoder) | 65 VideoDecoder::VideoDecoder(const HostResource& decoder) : Resource(decoder) { |
66 : PluginResource(decoder) { | |
67 } | |
68 | |
69 VideoDecoder* VideoDecoder::Create(const HostResource& resource, | |
70 PP_Resource context3d_id, | |
71 const PP_VideoConfigElement* config) { | |
72 if (!context3d_id) | |
73 return NULL; | |
74 | |
75 EnterResourceNoLock<PPB_Context3D_API> enter_context(context3d_id, true); | |
76 if (enter_context.failed()) | |
77 return NULL; | |
78 | |
79 scoped_refptr<VideoDecoder> decoder(new VideoDecoder(resource)); | |
80 if (decoder->Init(context3d_id, enter_context.object(), config)) | |
81 return decoder.release(); | |
82 return NULL; | |
83 } | 66 } |
84 | 67 |
85 VideoDecoder::~VideoDecoder() { | 68 VideoDecoder::~VideoDecoder() { |
86 } | 69 } |
87 | 70 |
88 ::ppapi::thunk::PPB_VideoDecoder_API* VideoDecoder::AsPPB_VideoDecoder_API() { | 71 ::ppapi::thunk::PPB_VideoDecoder_API* VideoDecoder::AsPPB_VideoDecoder_API() { |
89 return this; | 72 return this; |
90 } | 73 } |
91 | 74 |
92 int32_t VideoDecoder::Decode( | 75 int32_t VideoDecoder::Decode( |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
148 return PP_OK_COMPLETIONPENDING; | 131 return PP_OK_COMPLETIONPENDING; |
149 } | 132 } |
150 | 133 |
151 void VideoDecoder::Destroy() { | 134 void VideoDecoder::Destroy() { |
152 FlushCommandBuffer(); | 135 FlushCommandBuffer(); |
153 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Destroy( | 136 GetDispatcher()->Send(new PpapiHostMsg_PPBVideoDecoder_Destroy( |
154 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource())); | 137 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, host_resource())); |
155 ::ppapi::VideoDecoderImpl::Destroy(); | 138 ::ppapi::VideoDecoderImpl::Destroy(); |
156 } | 139 } |
157 | 140 |
158 void VideoDecoder::AddRefResource(PP_Resource resource) { | 141 PluginDispatcher* VideoDecoder::GetDispatcher() const { |
159 PluginResourceTracker::GetInstance()->AddRefResource(resource); | 142 return PluginDispatcher::GetForResource(this); |
160 } | |
161 | |
162 void VideoDecoder::UnrefResource(PP_Resource resource) { | |
163 PluginResourceTracker::GetInstance()->ReleaseResource(resource); | |
164 } | 143 } |
165 | 144 |
166 void VideoDecoder::ResetACK(int32_t result) { | 145 void VideoDecoder::ResetACK(int32_t result) { |
167 RunResetCallback(result); | 146 RunResetCallback(result); |
168 } | 147 } |
169 | 148 |
170 void VideoDecoder::FlushACK(int32_t result) { | 149 void VideoDecoder::FlushACK(int32_t result) { |
171 RunFlushCallback(result); | 150 RunFlushCallback(result); |
172 } | 151 } |
173 | 152 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
250 static_cast<Context3D*>(enter_context.object()); | 229 static_cast<Context3D*>(enter_context.object()); |
251 HostResource host_context = ppb_context->host_resource(); | 230 HostResource host_context = ppb_context->host_resource(); |
252 | 231 |
253 HostResource result; | 232 HostResource result; |
254 dispatcher->Send(new PpapiHostMsg_PPBVideoDecoder_Create( | 233 dispatcher->Send(new PpapiHostMsg_PPBVideoDecoder_Create( |
255 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, instance, | 234 INTERFACE_ID_PPB_VIDEO_DECODER_DEV, instance, |
256 host_context, copied, &result)); | 235 host_context, copied, &result)); |
257 if (result.is_null()) | 236 if (result.is_null()) |
258 return 0; | 237 return 0; |
259 | 238 |
260 return PluginResourceTracker::GetInstance()->AddResource( | 239 scoped_refptr<VideoDecoder> decoder(new VideoDecoder(result)); |
dmichael (off chromium)
2011/08/17 19:02:54
Why are you using scoped_refptr here but not elsew
| |
261 VideoDecoder::Create(result, context3d_id, config)); | 240 if (!decoder->Init(context3d_id, enter_context.object(), config)) |
241 return 0; | |
242 return decoder->GetReference(); | |
262 } | 243 } |
263 | 244 |
264 void PPB_VideoDecoder_Proxy::OnMsgCreate( | 245 void PPB_VideoDecoder_Proxy::OnMsgCreate( |
265 PP_Instance instance, const HostResource& context3d_id, | 246 PP_Instance instance, const HostResource& context3d_id, |
266 const std::vector<PP_VideoConfigElement>& config, | 247 const std::vector<PP_VideoConfigElement>& config, |
267 HostResource* result) { | 248 HostResource* result) { |
268 ::ppapi::thunk::EnterFunction< ::ppapi::thunk::ResourceCreationAPI> | 249 ::ppapi::thunk::EnterFunction< ::ppapi::thunk::ResourceCreationAPI> |
269 resource_creation(instance, true); | 250 resource_creation(instance, true); |
270 if (resource_creation.failed()) | 251 if (resource_creation.failed()) |
271 return; | 252 return; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
358 | 339 |
359 void PPB_VideoDecoder_Proxy::OnMsgResetACK( | 340 void PPB_VideoDecoder_Proxy::OnMsgResetACK( |
360 const HostResource& decoder, int32_t result) { | 341 const HostResource& decoder, int32_t result) { |
361 EnterPluginFromHostResource<PPB_VideoDecoder_API> enter(decoder); | 342 EnterPluginFromHostResource<PPB_VideoDecoder_API> enter(decoder); |
362 if (enter.succeeded()) | 343 if (enter.succeeded()) |
363 static_cast<VideoDecoder*>(enter.object())->ResetACK(result); | 344 static_cast<VideoDecoder*>(enter.object())->ResetACK(result); |
364 } | 345 } |
365 | 346 |
366 } // namespace proxy | 347 } // namespace proxy |
367 } // namespace pp | 348 } // namespace pp |
OLD | NEW |