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 "webkit/plugins/ppapi/ppb_video_decoder_impl.h" | 5 #include "webkit/plugins/ppapi/ppb_video_decoder_impl.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
11 #include "gpu/command_buffer/client/gles2_implementation.h" | 11 #include "gpu/command_buffer/client/gles2_implementation.h" |
12 #include "media/video/picture.h" | 12 #include "media/video/picture.h" |
13 #include "ppapi/c/dev/pp_video_dev.h" | 13 #include "ppapi/c/dev/pp_video_dev.h" |
14 #include "ppapi/c/dev/ppb_video_decoder_dev.h" | 14 #include "ppapi/c/dev/ppb_video_decoder_dev.h" |
15 #include "ppapi/c/dev/ppp_video_decoder_dev.h" | 15 #include "ppapi/c/dev/ppp_video_decoder_dev.h" |
16 #include "ppapi/c/pp_completion_callback.h" | 16 #include "ppapi/c/pp_completion_callback.h" |
17 #include "ppapi/c/pp_errors.h" | 17 #include "ppapi/c/pp_errors.h" |
| 18 #include "webkit/plugins/ppapi/resource_helper.h" |
18 #include "ppapi/thunk/enter.h" | 19 #include "ppapi/thunk/enter.h" |
19 #include "webkit/plugins/ppapi/common.h" | 20 #include "webkit/plugins/ppapi/common.h" |
20 #include "webkit/plugins/ppapi/plugin_module.h" | 21 #include "webkit/plugins/ppapi/plugin_module.h" |
21 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 22 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
22 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" | 23 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" |
23 #include "webkit/plugins/ppapi/ppb_context_3d_impl.h" | 24 #include "webkit/plugins/ppapi/ppb_context_3d_impl.h" |
24 #include "webkit/plugins/ppapi/resource_tracker.h" | 25 #include "webkit/plugins/ppapi/resource_tracker.h" |
25 | 26 |
26 using ppapi::thunk::EnterResourceNoLock; | 27 using ppapi::thunk::EnterResourceNoLock; |
27 using ppapi::thunk::PPB_Buffer_API; | 28 using ppapi::thunk::PPB_Buffer_API; |
28 using ppapi::thunk::PPB_Context3D_API; | 29 using ppapi::thunk::PPB_Context3D_API; |
29 using ppapi::thunk::PPB_VideoDecoder_API; | 30 using ppapi::thunk::PPB_VideoDecoder_API; |
30 | 31 |
31 namespace webkit { | 32 namespace webkit { |
32 namespace ppapi { | 33 namespace ppapi { |
33 | 34 |
34 PPB_VideoDecoder_Impl::PPB_VideoDecoder_Impl(PluginInstance* instance) | 35 PPB_VideoDecoder_Impl::PPB_VideoDecoder_Impl(PP_Instance instance) |
35 : Resource(instance) { | 36 : Resource(instance), |
36 ppp_videodecoder_ = | 37 ppp_videodecoder_(NULL) { |
37 static_cast<const PPP_VideoDecoder_Dev*>(instance->module()-> | 38 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); |
38 GetPluginInterface(PPP_VIDEODECODER_DEV_INTERFACE)); | 39 if (plugin_module) { |
| 40 ppp_videodecoder_ = static_cast<const PPP_VideoDecoder_Dev*>( |
| 41 plugin_module->GetPluginInterface(PPP_VIDEODECODER_DEV_INTERFACE)); |
| 42 } |
39 } | 43 } |
40 | 44 |
41 PPB_VideoDecoder_Impl::~PPB_VideoDecoder_Impl() { | 45 PPB_VideoDecoder_Impl::~PPB_VideoDecoder_Impl() { |
42 } | 46 } |
43 | 47 |
44 PPB_VideoDecoder_API* PPB_VideoDecoder_Impl::AsPPB_VideoDecoder_API() { | 48 PPB_VideoDecoder_API* PPB_VideoDecoder_Impl::AsPPB_VideoDecoder_API() { |
45 return this; | 49 return this; |
46 } | 50 } |
47 | 51 |
48 // static | 52 // static |
49 PP_Resource PPB_VideoDecoder_Impl::Create(PluginInstance* instance, | 53 PP_Resource PPB_VideoDecoder_Impl::Create(PP_Instance instance, |
50 PP_Resource context3d_id, | 54 PP_Resource context3d_id, |
51 const PP_VideoConfigElement* config) { | 55 const PP_VideoConfigElement* config) { |
52 if (!context3d_id) | 56 if (!context3d_id) |
53 return 0; | 57 return 0; |
54 | 58 |
55 EnterResourceNoLock<PPB_Context3D_API> enter_context(context3d_id, true); | 59 EnterResourceNoLock<PPB_Context3D_API> enter_context(context3d_id, true); |
56 if (enter_context.failed()) | 60 if (enter_context.failed()) |
57 return 0; | 61 return 0; |
58 | 62 |
59 scoped_refptr<PPB_VideoDecoder_Impl> decoder( | 63 scoped_refptr<PPB_VideoDecoder_Impl> decoder( |
(...skipping 13 matching lines...) Expand all Loading... |
73 if (!CopyConfigsToVector(config, &copied)) | 77 if (!CopyConfigsToVector(config, &copied)) |
74 return false; | 78 return false; |
75 | 79 |
76 PPB_Context3D_Impl* context3d_impl = | 80 PPB_Context3D_Impl* context3d_impl = |
77 static_cast<PPB_Context3D_Impl*>(context3d); | 81 static_cast<PPB_Context3D_Impl*>(context3d); |
78 | 82 |
79 int command_buffer_route_id = | 83 int command_buffer_route_id = |
80 context3d_impl->platform_context()->GetCommandBufferRouteId(); | 84 context3d_impl->platform_context()->GetCommandBufferRouteId(); |
81 if (command_buffer_route_id == 0) | 85 if (command_buffer_route_id == 0) |
82 return false; | 86 return false; |
83 platform_video_decoder_ = instance()->delegate()->CreateVideoDecoder( | 87 |
| 88 |
| 89 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
| 90 if (!plugin_delegate) |
| 91 return false; |
| 92 |
| 93 platform_video_decoder_ = plugin_delegate->CreateVideoDecoder( |
84 this, command_buffer_route_id); | 94 this, command_buffer_route_id); |
85 if (!platform_video_decoder_) | 95 if (!platform_video_decoder_) |
86 return false; | 96 return false; |
87 | 97 |
88 FlushCommandBuffer(); | 98 FlushCommandBuffer(); |
89 return platform_video_decoder_->Initialize(copied); | 99 return platform_video_decoder_->Initialize(copied); |
90 } | 100 } |
91 | 101 |
92 int32_t PPB_VideoDecoder_Impl::Decode( | 102 int32_t PPB_VideoDecoder_Impl::Decode( |
93 const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, | 103 const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 platform_video_decoder_ = NULL; | 184 platform_video_decoder_ = NULL; |
175 ppp_videodecoder_ = NULL; | 185 ppp_videodecoder_ = NULL; |
176 } | 186 } |
177 | 187 |
178 void PPB_VideoDecoder_Impl::ProvidePictureBuffers( | 188 void PPB_VideoDecoder_Impl::ProvidePictureBuffers( |
179 uint32 requested_num_of_buffers, const gfx::Size& dimensions) { | 189 uint32 requested_num_of_buffers, const gfx::Size& dimensions) { |
180 if (!ppp_videodecoder_) | 190 if (!ppp_videodecoder_) |
181 return; | 191 return; |
182 | 192 |
183 PP_Size out_dim = PP_MakeSize(dimensions.width(), dimensions.height()); | 193 PP_Size out_dim = PP_MakeSize(dimensions.width(), dimensions.height()); |
184 ScopedResourceId resource(this); | 194 ppp_videodecoder_->ProvidePictureBuffers(pp_instance(), pp_resource(), |
185 ppp_videodecoder_->ProvidePictureBuffers( | 195 requested_num_of_buffers, out_dim); |
186 instance()->pp_instance(), resource.id, requested_num_of_buffers, | |
187 out_dim); | |
188 } | 196 } |
189 | 197 |
190 void PPB_VideoDecoder_Impl::PictureReady(const media::Picture& picture) { | 198 void PPB_VideoDecoder_Impl::PictureReady(const media::Picture& picture) { |
191 if (!ppp_videodecoder_) | 199 if (!ppp_videodecoder_) |
192 return; | 200 return; |
193 | 201 |
194 PP_Picture_Dev output; | 202 PP_Picture_Dev output; |
195 output.picture_buffer_id = picture.picture_buffer_id(); | 203 output.picture_buffer_id = picture.picture_buffer_id(); |
196 output.bitstream_buffer_id = picture.bitstream_buffer_id(); | 204 output.bitstream_buffer_id = picture.bitstream_buffer_id(); |
197 ScopedResourceId resource(this); | 205 ppp_videodecoder_->PictureReady(pp_instance(), pp_resource(), output); |
198 ppp_videodecoder_->PictureReady( | |
199 instance()->pp_instance(), resource.id, output); | |
200 } | 206 } |
201 | 207 |
202 void PPB_VideoDecoder_Impl::DismissPictureBuffer(int32 picture_buffer_id) { | 208 void PPB_VideoDecoder_Impl::DismissPictureBuffer(int32 picture_buffer_id) { |
203 if (!ppp_videodecoder_) | 209 if (!ppp_videodecoder_) |
204 return; | 210 return; |
205 | 211 ppp_videodecoder_->DismissPictureBuffer(pp_instance(), pp_resource(), |
206 ScopedResourceId resource(this); | 212 picture_buffer_id); |
207 ppp_videodecoder_->DismissPictureBuffer( | |
208 instance()->pp_instance(), resource.id, picture_buffer_id); | |
209 } | 213 } |
210 | 214 |
211 void PPB_VideoDecoder_Impl::NotifyEndOfStream() { | 215 void PPB_VideoDecoder_Impl::NotifyEndOfStream() { |
212 if (!ppp_videodecoder_) | 216 if (!ppp_videodecoder_) |
213 return; | 217 return; |
214 | 218 ppp_videodecoder_->EndOfStream(pp_instance(), pp_resource()); |
215 ScopedResourceId resource(this); | |
216 ppp_videodecoder_->EndOfStream(instance()->pp_instance(), resource.id); | |
217 } | 219 } |
218 | 220 |
219 void PPB_VideoDecoder_Impl::NotifyError( | 221 void PPB_VideoDecoder_Impl::NotifyError( |
220 media::VideoDecodeAccelerator::Error error) { | 222 media::VideoDecodeAccelerator::Error error) { |
221 if (!ppp_videodecoder_) | 223 if (!ppp_videodecoder_) |
222 return; | 224 return; |
223 | 225 |
224 ScopedResourceId resource(this); | |
225 // TODO(vrk): This is assuming VideoDecodeAccelerator::Error and | 226 // TODO(vrk): This is assuming VideoDecodeAccelerator::Error and |
226 // PP_VideoDecodeError_Dev have identical enum values. There is no compiler | 227 // PP_VideoDecodeError_Dev have identical enum values. There is no compiler |
227 // assert to guarantee this. We either need to add such asserts or | 228 // assert to guarantee this. We either need to add such asserts or |
228 // merge these two enums. | 229 // merge these two enums. |
229 ppp_videodecoder_->NotifyError(instance()->pp_instance(), resource.id, | 230 ppp_videodecoder_->NotifyError(pp_instance(), pp_resource(), |
230 static_cast<PP_VideoDecodeError_Dev>(error)); | 231 static_cast<PP_VideoDecodeError_Dev>(error)); |
231 } | 232 } |
232 | 233 |
233 void PPB_VideoDecoder_Impl::NotifyResetDone() { | 234 void PPB_VideoDecoder_Impl::NotifyResetDone() { |
234 RunResetCallback(PP_OK); | 235 RunResetCallback(PP_OK); |
235 } | 236 } |
236 | 237 |
237 void PPB_VideoDecoder_Impl::NotifyEndOfBitstreamBuffer( | 238 void PPB_VideoDecoder_Impl::NotifyEndOfBitstreamBuffer( |
238 int32 bitstream_buffer_id) { | 239 int32 bitstream_buffer_id) { |
239 RunBitstreamBufferCallback(bitstream_buffer_id, PP_OK); | 240 RunBitstreamBufferCallback(bitstream_buffer_id, PP_OK); |
240 } | 241 } |
241 | 242 |
242 void PPB_VideoDecoder_Impl::NotifyFlushDone() { | 243 void PPB_VideoDecoder_Impl::NotifyFlushDone() { |
243 RunFlushCallback(PP_OK); | 244 RunFlushCallback(PP_OK); |
244 } | 245 } |
245 | 246 |
246 void PPB_VideoDecoder_Impl::NotifyInitializeDone() { | 247 void PPB_VideoDecoder_Impl::NotifyInitializeDone() { |
247 NOTREACHED() << "PlatformVideoDecoder::Initialize() is synchronous!"; | 248 NOTREACHED() << "PlatformVideoDecoder::Initialize() is synchronous!"; |
248 } | 249 } |
249 | 250 |
250 } // namespace ppapi | 251 } // namespace ppapi |
251 } // namespace webkit | 252 } // namespace webkit |
OLD | NEW |