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 "media/video/picture.h" | 10 #include "media/video/picture.h" |
11 #include "ppapi/c/dev/pp_video_dev.h" | 11 #include "ppapi/c/dev/pp_video_dev.h" |
12 #include "ppapi/c/dev/ppb_video_decoder_dev.h" | 12 #include "ppapi/c/dev/ppb_video_decoder_dev.h" |
13 #include "ppapi/c/dev/ppp_video_decoder_dev.h" | 13 #include "ppapi/c/dev/ppp_video_decoder_dev.h" |
14 #include "ppapi/c/pp_completion_callback.h" | 14 #include "ppapi/c/pp_completion_callback.h" |
15 #include "ppapi/c/pp_errors.h" | 15 #include "ppapi/c/pp_errors.h" |
16 #include "ppapi/thunk/enter.h" | 16 #include "ppapi/thunk/enter.h" |
17 #include "webkit/plugins/ppapi/common.h" | 17 #include "webkit/plugins/ppapi/common.h" |
18 #include "webkit/plugins/ppapi/plugin_module.h" | 18 #include "webkit/plugins/ppapi/plugin_module.h" |
19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 19 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
20 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" | 20 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" |
21 #include "webkit/plugins/ppapi/resource_tracker.h" | 21 #include "webkit/plugins/ppapi/resource_tracker.h" |
22 #include "webkit/plugins/ppapi/var.h" | 22 #include "webkit/plugins/ppapi/var.h" |
23 | 23 |
24 namespace webkit { | 24 namespace webkit { |
25 namespace ppapi { | 25 namespace ppapi { |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
29 PP_Bool GetConfigs(PP_Instance instance_id, | 29 PP_Bool GetConfigs(PP_Instance instance_id, |
30 PP_VideoConfigElement* proto_config, | 30 const PP_VideoConfigElement* proto_config, |
31 PP_VideoConfigElement* matching_configs, | 31 PP_VideoConfigElement* matching_configs, |
32 uint32_t matching_configs_size, | 32 uint32_t matching_configs_size, |
33 uint32_t* num_of_matching_configs) { | 33 uint32_t* num_of_matching_configs) { |
34 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 34 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
35 if (!instance) | 35 if (!instance) |
36 return PP_FALSE; | 36 return PP_FALSE; |
37 | 37 |
38 scoped_refptr<PPB_VideoDecoder_Impl> decoder( | 38 scoped_refptr<PPB_VideoDecoder_Impl> decoder( |
39 new PPB_VideoDecoder_Impl(instance)); | 39 new PPB_VideoDecoder_Impl(instance)); |
40 | 40 |
41 return BoolToPPBool(decoder->GetConfigs(proto_config, | 41 return BoolToPPBool(decoder->GetConfigs(proto_config, |
42 matching_configs, | 42 matching_configs, |
43 matching_configs_size, | 43 matching_configs_size, |
44 num_of_matching_configs)); | 44 num_of_matching_configs)); |
45 } | 45 } |
46 | 46 |
47 PP_Resource Create(PP_Instance instance_id, | 47 PP_Resource Create(PP_Instance instance_id, |
48 PP_VideoConfigElement* decoder_config, | 48 const PP_VideoConfigElement* decoder_config, |
49 PP_CompletionCallback callback) { | 49 PP_CompletionCallback callback) { |
50 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); | 50 PluginInstance* instance = ResourceTracker::Get()->GetInstance(instance_id); |
51 if (!instance) | 51 if (!instance) |
52 return 0; | 52 return 0; |
53 | 53 |
54 scoped_refptr<PPB_VideoDecoder_Impl> decoder( | 54 scoped_refptr<PPB_VideoDecoder_Impl> decoder( |
55 new PPB_VideoDecoder_Impl(instance)); | 55 new PPB_VideoDecoder_Impl(instance)); |
56 | 56 |
57 if (!decoder->Init( | 57 if (!decoder->Init( |
58 const_cast<PP_VideoConfigElement*>(decoder_config), callback)) { | 58 const_cast<PP_VideoConfigElement*>(decoder_config), callback)) { |
59 return 0; | 59 return 0; |
60 } | 60 } |
61 | 61 |
62 return decoder->GetReference(); | 62 return decoder->GetReference(); |
63 } | 63 } |
64 | 64 |
65 PP_Bool IsVideoDecoder(PP_Resource resource) { | 65 PP_Bool IsVideoDecoder(PP_Resource resource) { |
66 return BoolToPPBool(!!Resource::GetAs<PPB_VideoDecoder_Impl>(resource)); | 66 return BoolToPPBool(!!Resource::GetAs<PPB_VideoDecoder_Impl>(resource)); |
67 } | 67 } |
68 | 68 |
69 PP_Bool Decode(PP_Resource decoder_id, | 69 PP_Bool Decode(PP_Resource decoder_id, |
70 PP_VideoBitstreamBuffer_Dev* bitstream_buffer, | 70 const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, |
71 PP_CompletionCallback callback) { | 71 PP_CompletionCallback callback) { |
72 scoped_refptr<PPB_VideoDecoder_Impl> decoder( | 72 scoped_refptr<PPB_VideoDecoder_Impl> decoder( |
73 Resource::GetAs<PPB_VideoDecoder_Impl>(decoder_id)); | 73 Resource::GetAs<PPB_VideoDecoder_Impl>(decoder_id)); |
74 if (!decoder) | 74 if (!decoder) |
75 return PP_FALSE; | 75 return PP_FALSE; |
76 | 76 |
77 return BoolToPPBool(decoder->Decode(bitstream_buffer, callback)); | 77 return BoolToPPBool(decoder->Decode(bitstream_buffer, callback)); |
78 } | 78 } |
79 | 79 |
80 void AssignGLESBuffers(PP_Resource video_decoder, | 80 void AssignGLESBuffers(PP_Resource video_decoder, |
81 uint32_t no_of_buffers, | 81 uint32_t no_of_buffers, |
82 PP_GLESBuffer_Dev* buffers) { | 82 const PP_GLESBuffer_Dev* buffers) { |
83 scoped_refptr<PPB_VideoDecoder_Impl> decoder( | 83 scoped_refptr<PPB_VideoDecoder_Impl> decoder( |
84 Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder)); | 84 Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder)); |
85 if (!decoder) | 85 if (!decoder) |
86 return; | 86 return; |
87 | 87 |
88 decoder->AssignGLESBuffers(no_of_buffers, buffers); | 88 decoder->AssignGLESBuffers(no_of_buffers, buffers); |
89 } | 89 } |
90 | 90 |
91 void AssignSysmemBuffers(PP_Resource video_decoder, | 91 void AssignSysmemBuffers(PP_Resource video_decoder, |
92 uint32_t no_of_buffers, | 92 uint32_t no_of_buffers, |
93 PP_SysmemBuffer_Dev* buffers) { | 93 const PP_SysmemBuffer_Dev* buffers) { |
94 scoped_refptr<PPB_VideoDecoder_Impl> decoder( | 94 scoped_refptr<PPB_VideoDecoder_Impl> decoder( |
95 Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder)); | 95 Resource::GetAs<PPB_VideoDecoder_Impl>(video_decoder)); |
96 if (!decoder) | 96 if (!decoder) |
97 return; | 97 return; |
98 | 98 |
99 decoder->AssignSysmemBuffers(no_of_buffers, buffers); | 99 decoder->AssignSysmemBuffers(no_of_buffers, buffers); |
100 } | 100 } |
101 | 101 |
102 void ReusePictureBuffer(PP_Resource video_decoder, int32_t picture_buffer_id) { | 102 void ReusePictureBuffer(PP_Resource video_decoder, int32_t picture_buffer_id) { |
103 scoped_refptr<PPB_VideoDecoder_Impl> decoder( | 103 scoped_refptr<PPB_VideoDecoder_Impl> decoder( |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 // static | 185 // static |
186 const PPB_VideoDecoder_Dev* PPB_VideoDecoder_Impl::GetInterface() { | 186 const PPB_VideoDecoder_Dev* PPB_VideoDecoder_Impl::GetInterface() { |
187 return &ppb_videodecoder; | 187 return &ppb_videodecoder; |
188 } | 188 } |
189 | 189 |
190 PPB_VideoDecoder_Impl* PPB_VideoDecoder_Impl::AsPPB_VideoDecoder_Impl() { | 190 PPB_VideoDecoder_Impl* PPB_VideoDecoder_Impl::AsPPB_VideoDecoder_Impl() { |
191 return this; | 191 return this; |
192 } | 192 } |
193 | 193 |
194 bool PPB_VideoDecoder_Impl::GetConfigs( | 194 bool PPB_VideoDecoder_Impl::GetConfigs( |
195 PP_VideoConfigElement* requested_configs, | 195 const PP_VideoConfigElement* requested_configs, |
196 PP_VideoConfigElement* matching_configs, | 196 PP_VideoConfigElement* matching_configs, |
197 uint32_t matching_configs_size, | 197 uint32_t matching_configs_size, |
198 uint32_t* num_of_matching_configs) { | 198 uint32_t* num_of_matching_configs) { |
199 if (!instance()) | 199 if (!instance()) |
200 return false; | 200 return false; |
201 if (!platform_video_decoder_.get()) | 201 if (!platform_video_decoder_.get()) |
202 return false; | 202 return false; |
203 if (!matching_configs) | 203 if (!matching_configs) |
204 return false; | 204 return false; |
205 | 205 |
206 std::vector<uint32> requested; | 206 std::vector<uint32> requested; |
207 CopyToConfigList(requested_configs, &requested); | 207 CopyToConfigList(requested_configs, &requested); |
208 std::vector<uint32> matched; | 208 std::vector<uint32> matched; |
209 platform_video_decoder_->GetConfigs(requested, &matched); | 209 platform_video_decoder_->GetConfigs(requested, &matched); |
210 | 210 |
211 uint32 i; | 211 uint32 i; |
212 for (i = 0; i < matched.size() && i < matching_configs_size; i++) | 212 for (i = 0; i < matched.size() && i < matching_configs_size; i++) |
213 matching_configs[i] = matched[i]; | 213 matching_configs[i] = matched[i]; |
214 *num_of_matching_configs = i; | 214 *num_of_matching_configs = i; |
215 | 215 |
216 return true; | 216 return true; |
217 } | 217 } |
218 | 218 |
219 bool PPB_VideoDecoder_Impl::Init(PP_VideoConfigElement* decoder_config, | 219 bool PPB_VideoDecoder_Impl::Init(const PP_VideoConfigElement* decoder_config, |
220 PP_CompletionCallback callback) { | 220 PP_CompletionCallback callback) { |
221 if (!instance()) | 221 if (!instance()) |
222 return false; | 222 return false; |
223 | 223 |
224 platform_video_decoder_.reset( | 224 platform_video_decoder_.reset( |
225 instance()->delegate()->CreateVideoDecoder(this)); | 225 instance()->delegate()->CreateVideoDecoder(this)); |
226 | 226 |
227 std::vector<uint32> copied; | 227 std::vector<uint32> copied; |
228 // TODO(vrk): Validate configs before copy. | 228 // TODO(vrk): Validate configs before copy. |
229 CopyToConfigList(decoder_config, &copied); | 229 CopyToConfigList(decoder_config, &copied); |
230 platform_video_decoder_->Initialize(copied); | 230 platform_video_decoder_->Initialize(copied); |
231 | 231 |
232 initialization_callback_ = callback; | 232 initialization_callback_ = callback; |
233 | 233 |
234 return platform_video_decoder_.get()? true : false; | 234 return platform_video_decoder_.get()? true : false; |
235 } | 235 } |
236 | 236 |
237 bool PPB_VideoDecoder_Impl::Decode( | 237 bool PPB_VideoDecoder_Impl::Decode( |
238 PP_VideoBitstreamBuffer_Dev* bitstream_buffer, | 238 const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, |
239 PP_CompletionCallback callback) { | 239 PP_CompletionCallback callback) { |
240 if (!platform_video_decoder_.get()) | 240 if (!platform_video_decoder_.get()) |
241 return false; | 241 return false; |
242 | 242 |
243 ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_Buffer_API> | 243 ::ppapi::thunk::EnterResourceNoLock< ::ppapi::thunk::PPB_Buffer_API> |
244 enter(bitstream_buffer->data, true); | 244 enter(bitstream_buffer->data, true); |
245 if (enter.failed()) | 245 if (enter.failed()) |
246 return false; | 246 return false; |
247 | 247 |
248 PPB_Buffer_Impl* buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); | 248 PPB_Buffer_Impl* buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); |
249 media::BitstreamBuffer decode_buffer(bitstream_buffer->id, | 249 media::BitstreamBuffer decode_buffer(bitstream_buffer->id, |
250 buffer->shared_memory()->handle(), | 250 buffer->shared_memory()->handle(), |
251 static_cast<size_t>(buffer->size())); | 251 static_cast<size_t>(buffer->size())); |
252 | 252 |
253 // Store the callback to inform when bitstream buffer has been processed. | 253 // Store the callback to inform when bitstream buffer has been processed. |
254 // TODO(vmr): handle simultaneous decodes + callbacks. | 254 // TODO(vmr): handle simultaneous decodes + callbacks. |
255 bitstream_buffer_callback_ = callback; | 255 bitstream_buffer_callback_ = callback; |
256 | 256 |
257 return platform_video_decoder_->Decode(decode_buffer); | 257 return platform_video_decoder_->Decode(decode_buffer); |
258 } | 258 } |
259 | 259 |
260 void PPB_VideoDecoder_Impl::AssignGLESBuffers( | 260 void PPB_VideoDecoder_Impl::AssignGLESBuffers( |
261 uint32_t no_of_buffers, | 261 uint32_t no_of_buffers, |
262 PP_GLESBuffer_Dev* buffers) { | 262 const PP_GLESBuffer_Dev* buffers) { |
263 if (!platform_video_decoder_.get()) | 263 if (!platform_video_decoder_.get()) |
264 return; | 264 return; |
265 | 265 |
266 std::vector<media::GLESBuffer> wrapped_buffers; | 266 std::vector<media::GLESBuffer> wrapped_buffers; |
267 for (uint32 i = 0; i < no_of_buffers; i++) { | 267 for (uint32 i = 0; i < no_of_buffers; i++) { |
268 PP_GLESBuffer_Dev in_buf = buffers[i]; | 268 PP_GLESBuffer_Dev in_buf = buffers[i]; |
269 media::GLESBuffer buffer(in_buf); | 269 media::GLESBuffer buffer(in_buf); |
270 wrapped_buffers.push_back(buffer); | 270 wrapped_buffers.push_back(buffer); |
271 } | 271 } |
272 platform_video_decoder_->AssignGLESBuffers(wrapped_buffers); | 272 platform_video_decoder_->AssignGLESBuffers(wrapped_buffers); |
273 } | 273 } |
274 | 274 |
275 void PPB_VideoDecoder_Impl::AssignSysmemBuffers( | 275 void PPB_VideoDecoder_Impl::AssignSysmemBuffers( |
276 uint32_t no_of_buffers, | 276 uint32_t no_of_buffers, |
277 PP_SysmemBuffer_Dev* buffers) { | 277 const PP_SysmemBuffer_Dev* buffers) { |
278 if (!platform_video_decoder_.get()) | 278 if (!platform_video_decoder_.get()) |
279 return; | 279 return; |
280 | 280 |
281 std::vector<media::SysmemBuffer> wrapped_buffers; | 281 std::vector<media::SysmemBuffer> wrapped_buffers; |
282 for (uint32 i = 0; i < no_of_buffers; i++) { | 282 for (uint32 i = 0; i < no_of_buffers; i++) { |
283 PP_SysmemBuffer_Dev in_buf = buffers[i]; | 283 PP_SysmemBuffer_Dev in_buf = buffers[i]; |
284 media::SysmemBuffer buffer(in_buf); | 284 media::SysmemBuffer buffer(in_buf); |
285 wrapped_buffers.push_back(buffer); | 285 wrapped_buffers.push_back(buffer); |
286 } | 286 } |
287 platform_video_decoder_->AssignSysmemBuffers(wrapped_buffers); | 287 platform_video_decoder_->AssignSysmemBuffers(wrapped_buffers); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 } | 434 } |
435 | 435 |
436 Picture::Picture(const PP_Picture_Dev& picture) | 436 Picture::Picture(const PP_Picture_Dev& picture) |
437 : picture_buffer_id_(picture.picture_buffer_id), | 437 : picture_buffer_id_(picture.picture_buffer_id), |
438 bitstream_buffer_id_(picture.bitstream_buffer_id), | 438 bitstream_buffer_id_(picture.bitstream_buffer_id), |
439 visible_size_(picture.visible_size.width, picture.visible_size.height), | 439 visible_size_(picture.visible_size.width, picture.visible_size.height), |
440 decoded_size_(picture.decoded_size.width, picture.decoded_size.height) { | 440 decoded_size_(picture.decoded_size.width, picture.decoded_size.height) { |
441 } | 441 } |
442 | 442 |
443 } // namespace media | 443 } // namespace media |
OLD | NEW |