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 "media/video/picture.h" | 12 #include "media/video/picture.h" |
12 #include "ppapi/c/dev/pp_video_dev.h" | 13 #include "ppapi/c/dev/pp_video_dev.h" |
13 #include "ppapi/c/dev/ppb_video_decoder_dev.h" | 14 #include "ppapi/c/dev/ppb_video_decoder_dev.h" |
14 #include "ppapi/c/dev/ppp_video_decoder_dev.h" | 15 #include "ppapi/c/dev/ppp_video_decoder_dev.h" |
15 #include "ppapi/c/pp_completion_callback.h" | 16 #include "ppapi/c/pp_completion_callback.h" |
16 #include "ppapi/c/pp_errors.h" | 17 #include "ppapi/c/pp_errors.h" |
17 #include "ppapi/thunk/enter.h" | 18 #include "ppapi/thunk/enter.h" |
18 #include "webkit/plugins/ppapi/common.h" | 19 #include "webkit/plugins/ppapi/common.h" |
19 #include "webkit/plugins/ppapi/plugin_module.h" | 20 #include "webkit/plugins/ppapi/plugin_module.h" |
20 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 21 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
120 PPB_Context3D_Impl* context3d = | 121 PPB_Context3D_Impl* context3d = |
121 static_cast<PPB_Context3D_Impl*>(enter.object()); | 122 static_cast<PPB_Context3D_Impl*>(enter.object()); |
122 | 123 |
123 int command_buffer_route_id = | 124 int command_buffer_route_id = |
124 context3d->platform_context()->GetCommandBufferRouteId(); | 125 context3d->platform_context()->GetCommandBufferRouteId(); |
125 if (command_buffer_route_id == 0) | 126 if (command_buffer_route_id == 0) |
126 return PP_ERROR_FAILED; | 127 return PP_ERROR_FAILED; |
127 | 128 |
128 platform_video_decoder_.reset( | 129 platform_video_decoder_.reset( |
129 instance()->delegate()->CreateVideoDecoder( | 130 instance()->delegate()->CreateVideoDecoder( |
130 this, command_buffer_route_id)); | 131 this, command_buffer_route_id, context3d->gles2_impl()->helper())); |
131 | 132 |
132 if (!platform_video_decoder_.get()) | 133 if (!platform_video_decoder_.get()) |
133 return PP_ERROR_FAILED; | 134 return PP_ERROR_FAILED; |
134 | 135 |
135 std::vector<uint32> copied; | 136 std::vector<uint32> copied; |
136 // TODO(vrk): Validate configs before copy. | 137 // TODO(vrk): Validate configs before copy. |
137 CopyToConfigList(decoder_config, &copied); | 138 CopyToConfigList(decoder_config, &copied); |
138 if (platform_video_decoder_->Initialize(copied)) { | 139 if (platform_video_decoder_->Initialize(copied)) { |
139 initialization_callback_ = callback; | 140 initialization_callback_ = callback; |
140 return PP_OK_COMPLETIONPENDING; | 141 return PP_OK_COMPLETIONPENDING; |
(...skipping 12 matching lines...) Expand all Loading... |
153 if (enter.failed()) | 154 if (enter.failed()) |
154 return PP_ERROR_FAILED; | 155 return PP_ERROR_FAILED; |
155 | 156 |
156 PPB_Buffer_Impl* buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); | 157 PPB_Buffer_Impl* buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); |
157 media::BitstreamBuffer decode_buffer(bitstream_buffer->id, | 158 media::BitstreamBuffer decode_buffer(bitstream_buffer->id, |
158 buffer->shared_memory()->handle(), | 159 buffer->shared_memory()->handle(), |
159 static_cast<size_t>(buffer->size())); | 160 static_cast<size_t>(buffer->size())); |
160 CHECK(bitstream_buffer_callbacks_.insert(std::make_pair( | 161 CHECK(bitstream_buffer_callbacks_.insert(std::make_pair( |
161 bitstream_buffer->id, callback)).second); | 162 bitstream_buffer->id, callback)).second); |
162 | 163 |
163 if (platform_video_decoder_->Decode(decode_buffer)) | 164 platform_video_decoder_->Decode(decode_buffer); |
164 return PP_OK_COMPLETIONPENDING; | 165 return PP_OK_COMPLETIONPENDING; |
165 else | |
166 return PP_ERROR_FAILED; | |
167 } | 166 } |
168 | 167 |
169 void PPB_VideoDecoder_Impl::AssignGLESBuffers( | 168 void PPB_VideoDecoder_Impl::AssignGLESBuffers( |
170 uint32_t no_of_buffers, | 169 uint32_t no_of_buffers, |
171 const PP_GLESBuffer_Dev* buffers) { | 170 const PP_GLESBuffer_Dev* buffers) { |
172 if (!platform_video_decoder_.get()) | 171 if (!platform_video_decoder_.get()) |
173 return; | 172 return; |
174 | 173 |
175 std::vector<media::GLESBuffer> wrapped_buffers; | 174 std::vector<media::GLESBuffer> wrapped_buffers; |
176 for (uint32 i = 0; i < no_of_buffers; i++) { | 175 for (uint32 i = 0; i < no_of_buffers; i++) { |
177 PP_GLESBuffer_Dev in_buf = buffers[i]; | 176 PP_GLESBuffer_Dev in_buf = buffers[i]; |
178 media::GLESBuffer buffer(in_buf); | 177 media::GLESBuffer buffer( |
| 178 in_buf.info.id, |
| 179 gfx::Size(in_buf.info.size.width, in_buf.info.size.height), |
| 180 in_buf.texture_id); |
179 wrapped_buffers.push_back(buffer); | 181 wrapped_buffers.push_back(buffer); |
180 } | 182 } |
181 platform_video_decoder_->AssignGLESBuffers(wrapped_buffers); | 183 platform_video_decoder_->AssignGLESBuffers(wrapped_buffers); |
182 } | 184 } |
183 | 185 |
184 void PPB_VideoDecoder_Impl::AssignSysmemBuffers( | 186 void PPB_VideoDecoder_Impl::AssignSysmemBuffers( |
185 uint32_t no_of_buffers, | 187 uint32_t no_of_buffers, |
186 const PP_SysmemBuffer_Dev* buffers) { | 188 const PP_SysmemBuffer_Dev* buffers) { |
187 if (!platform_video_decoder_.get()) | 189 if (!platform_video_decoder_.get()) |
188 return; | 190 return; |
189 | 191 |
190 std::vector<media::SysmemBuffer> wrapped_buffers; | 192 std::vector<media::SysmemBuffer> wrapped_buffers; |
191 for (uint32 i = 0; i < no_of_buffers; i++) { | 193 for (uint32 i = 0; i < no_of_buffers; i++) { |
192 PP_SysmemBuffer_Dev in_buf = buffers[i]; | 194 PP_SysmemBuffer_Dev in_buf = buffers[i]; |
193 media::SysmemBuffer buffer(in_buf); | 195 // TODO(brettw) we should properly handle the errors here if the buffer |
| 196 // isn't a valid image rather than CHECKing. |
| 197 EnterResourceNoLock<PPB_Buffer_API> enter(in_buf.data, true); |
| 198 CHECK(enter.succeeded()); |
| 199 webkit::ppapi::PPB_Buffer_Impl* pepper_buffer = |
| 200 static_cast<webkit::ppapi::PPB_Buffer_Impl*>(enter.object()); |
| 201 CHECK(pepper_buffer->IsMapped()); |
| 202 media::SysmemBuffer buffer( |
| 203 in_buf.info.id, |
| 204 gfx::Size(in_buf.info.size.width, in_buf.info.size.height), |
| 205 pepper_buffer->Map()); |
194 wrapped_buffers.push_back(buffer); | 206 wrapped_buffers.push_back(buffer); |
195 } | 207 } |
196 platform_video_decoder_->AssignSysmemBuffers(wrapped_buffers); | 208 platform_video_decoder_->AssignSysmemBuffers(wrapped_buffers); |
197 } | 209 } |
198 | 210 |
199 void PPB_VideoDecoder_Impl::ReusePictureBuffer(int32_t picture_buffer_id) { | 211 void PPB_VideoDecoder_Impl::ReusePictureBuffer(int32_t picture_buffer_id) { |
200 if (!platform_video_decoder_.get()) | 212 if (!platform_video_decoder_.get()) |
201 return; | 213 return; |
202 platform_video_decoder_->ReusePictureBuffer(picture_buffer_id); | 214 platform_video_decoder_->ReusePictureBuffer(picture_buffer_id); |
203 } | 215 } |
204 | 216 |
205 int32_t PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) { | 217 int32_t PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) { |
206 if (!platform_video_decoder_.get()) | 218 if (!platform_video_decoder_.get()) |
207 return PP_ERROR_BADRESOURCE; | 219 return PP_ERROR_BADRESOURCE; |
208 | 220 |
209 // Store the callback to be called when Flush() is done. | 221 // Store the callback to be called when Flush() is done. |
210 // TODO(vmr): Check for current flush/abort operations. | 222 // TODO(vmr): Check for current flush/abort operations. |
211 flush_callback_ = callback; | 223 flush_callback_ = callback; |
212 | 224 |
213 if (platform_video_decoder_->Flush()) | 225 platform_video_decoder_->Flush(); |
214 return PP_OK_COMPLETIONPENDING; | 226 return PP_OK_COMPLETIONPENDING; |
215 else | |
216 return PP_ERROR_FAILED; | |
217 } | 227 } |
218 | 228 |
219 int32_t PPB_VideoDecoder_Impl::Abort(PP_CompletionCallback callback) { | 229 int32_t PPB_VideoDecoder_Impl::Abort(PP_CompletionCallback callback) { |
220 if (!platform_video_decoder_.get()) | 230 if (!platform_video_decoder_.get()) |
221 return PP_ERROR_BADRESOURCE; | 231 return PP_ERROR_BADRESOURCE; |
222 | 232 |
223 // Store the callback to be called when Abort() is done. | 233 // Store the callback to be called when Abort() is done. |
224 // TODO(vmr): Check for current flush/abort operations. | 234 // TODO(vmr): Check for current flush/abort operations. |
225 abort_callback_ = callback; | 235 abort_callback_ = callback; |
226 | 236 |
227 if (platform_video_decoder_->Abort()) | 237 platform_video_decoder_->Abort(); |
228 return PP_OK_COMPLETIONPENDING; | 238 return PP_OK_COMPLETIONPENDING; |
229 else | |
230 return PP_ERROR_FAILED; | |
231 } | 239 } |
232 | 240 |
233 void PPB_VideoDecoder_Impl::ProvidePictureBuffers( | 241 void PPB_VideoDecoder_Impl::ProvidePictureBuffers( |
234 uint32 requested_num_of_buffers, | 242 uint32 requested_num_of_buffers, |
235 const gfx::Size& dimensions, | 243 const gfx::Size& dimensions, |
236 media::VideoDecodeAccelerator::MemoryType type) { | 244 media::VideoDecodeAccelerator::MemoryType type) { |
237 if (!ppp_videodecoder_) | 245 if (!ppp_videodecoder_) |
238 return; | 246 return; |
239 | 247 |
240 // TODO(vrk): Compiler assert or use switch statement instead of making | 248 // TODO(vrk): Compiler assert or use switch statement instead of making |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 | 326 |
319 void PPB_VideoDecoder_Impl::NotifyInitializeDone() { | 327 void PPB_VideoDecoder_Impl::NotifyInitializeDone() { |
320 if (initialization_callback_.func == NULL) | 328 if (initialization_callback_.func == NULL) |
321 return; | 329 return; |
322 | 330 |
323 PP_RunAndClearCompletionCallback(&initialization_callback_, PP_OK); | 331 PP_RunAndClearCompletionCallback(&initialization_callback_, PP_OK); |
324 } | 332 } |
325 | 333 |
326 } // namespace ppapi | 334 } // namespace ppapi |
327 } // namespace webkit | 335 } // namespace webkit |
328 | |
329 // These functions are declared in picture.h but are defined here because of | |
330 // dependencies (we can't depend on ppapi types from media). | |
331 // TODO(fischman/vrk): Find a way to clean this up as it violates the spirit of | |
332 // checkdeps. | |
333 namespace media { | |
334 BaseBuffer::BaseBuffer(const PP_BufferInfo_Dev& info) | |
335 : id_(info.id), | |
336 size_(info.size.width, info.size.height) { | |
337 } | |
338 | |
339 GLESBuffer::GLESBuffer(const PP_GLESBuffer_Dev& buffer) | |
340 : BaseBuffer(buffer.info), | |
341 texture_id_(buffer.texture_id) { | |
342 } | |
343 | |
344 SysmemBuffer::SysmemBuffer(const PP_SysmemBuffer_Dev& buffer) | |
345 : BaseBuffer(buffer.info) { | |
346 // TODO(brettw) we should properly handle the errors here if the buffer | |
347 // isn't a valid image rather than CHECKing. | |
348 EnterResourceNoLock<PPB_Buffer_API> enter(buffer.data, true); | |
349 CHECK(enter.succeeded()); | |
350 webkit::ppapi::PPB_Buffer_Impl* pepper_buffer = | |
351 static_cast<webkit::ppapi::PPB_Buffer_Impl*>(enter.object()); | |
352 CHECK(pepper_buffer->IsMapped()); | |
353 data_ = pepper_buffer->Map(); | |
354 } | |
355 | |
356 Picture::Picture(const PP_Picture_Dev& picture) | |
357 : picture_buffer_id_(picture.picture_buffer_id), | |
358 bitstream_buffer_id_(picture.bitstream_buffer_id), | |
359 visible_size_(picture.visible_size.width, picture.visible_size.height), | |
360 decoded_size_(picture.decoded_size.width, picture.decoded_size.height) { | |
361 } | |
362 | |
363 } // namespace media | |
OLD | NEW |