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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
58 output->push_back(static_cast<uint32>(*configs)); | 59 output->push_back(static_cast<uint32>(*configs)); |
59 current++; | 60 current++; |
60 } | 61 } |
61 } | 62 } |
62 | 63 |
63 } // namespace | 64 } // namespace |
64 | 65 |
65 PPB_VideoDecoder_Impl::PPB_VideoDecoder_Impl(PluginInstance* instance) | 66 PPB_VideoDecoder_Impl::PPB_VideoDecoder_Impl(PluginInstance* instance) |
66 : Resource(instance), | 67 : Resource(instance), |
67 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | 68 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), |
| 69 context3d_id_(0), |
68 abort_callback_(PP_BlockUntilComplete()), | 70 abort_callback_(PP_BlockUntilComplete()), |
69 flush_callback_(PP_BlockUntilComplete()) { | 71 flush_callback_(PP_BlockUntilComplete()) { |
70 ppp_videodecoder_ = | 72 ppp_videodecoder_ = |
71 static_cast<const PPP_VideoDecoder_Dev*>(instance->module()-> | 73 static_cast<const PPP_VideoDecoder_Dev*>(instance->module()-> |
72 GetPluginInterface(PPP_VIDEODECODER_DEV_INTERFACE)); | 74 GetPluginInterface(PPP_VIDEODECODER_DEV_INTERFACE)); |
73 } | 75 } |
74 | 76 |
75 PPB_VideoDecoder_Impl::~PPB_VideoDecoder_Impl() { | 77 PPB_VideoDecoder_Impl::~PPB_VideoDecoder_Impl() { |
| 78 if (context3d_id_) |
| 79 ResourceTracker::Get()->UnrefResource(context3d_id_); |
76 } | 80 } |
77 | 81 |
78 PPB_VideoDecoder_API* PPB_VideoDecoder_Impl::AsPPB_VideoDecoder_API() { | 82 PPB_VideoDecoder_API* PPB_VideoDecoder_Impl::AsPPB_VideoDecoder_API() { |
79 return this; | 83 return this; |
80 } | 84 } |
81 | 85 |
82 PP_Bool PPB_VideoDecoder_Impl::GetConfigs( | 86 PP_Bool PPB_VideoDecoder_Impl::GetConfigs( |
83 const PP_VideoConfigElement* requested_configs, | 87 const PP_VideoConfigElement* requested_configs, |
84 PP_VideoConfigElement* matching_configs, | 88 PP_VideoConfigElement* matching_configs, |
85 uint32_t matching_configs_size, | 89 uint32_t matching_configs_size, |
(...skipping 27 matching lines...) Expand all Loading... |
113 | 117 |
114 if (!instance()) | 118 if (!instance()) |
115 return PP_ERROR_FAILED; | 119 return PP_ERROR_FAILED; |
116 | 120 |
117 EnterResourceNoLock<PPB_Context3D_API> enter(context_id, true); | 121 EnterResourceNoLock<PPB_Context3D_API> enter(context_id, true); |
118 if (enter.failed()) | 122 if (enter.failed()) |
119 return PP_ERROR_BADRESOURCE; | 123 return PP_ERROR_BADRESOURCE; |
120 PPB_Context3D_Impl* context3d = | 124 PPB_Context3D_Impl* context3d = |
121 static_cast<PPB_Context3D_Impl*>(enter.object()); | 125 static_cast<PPB_Context3D_Impl*>(enter.object()); |
122 | 126 |
| 127 context3d_id_ = context_id; |
| 128 ResourceTracker::Get()->AddRefResource(context3d_id_); |
123 int command_buffer_route_id = | 129 int command_buffer_route_id = |
124 context3d->platform_context()->GetCommandBufferRouteId(); | 130 context3d->platform_context()->GetCommandBufferRouteId(); |
125 if (command_buffer_route_id == 0) | 131 if (command_buffer_route_id == 0) |
126 return PP_ERROR_FAILED; | 132 return PP_ERROR_FAILED; |
127 | 133 |
128 platform_video_decoder_.reset( | 134 platform_video_decoder_.reset( |
129 instance()->delegate()->CreateVideoDecoder( | 135 instance()->delegate()->CreateVideoDecoder( |
130 this, command_buffer_route_id)); | 136 this, command_buffer_route_id, context3d->gles2_impl()->helper())); |
131 | 137 |
132 if (!platform_video_decoder_.get()) | 138 if (!platform_video_decoder_.get()) |
133 return PP_ERROR_FAILED; | 139 return PP_ERROR_FAILED; |
134 | 140 |
135 std::vector<uint32> copied; | 141 std::vector<uint32> copied; |
136 // TODO(vrk): Validate configs before copy. | 142 // TODO(vrk): Validate configs before copy. |
137 CopyToConfigList(decoder_config, &copied); | 143 CopyToConfigList(decoder_config, &copied); |
138 if (platform_video_decoder_->Initialize(copied)) { | 144 if (platform_video_decoder_->Initialize(copied)) { |
139 initialization_callback_ = callback; | 145 initialization_callback_ = callback; |
140 return PP_OK_COMPLETIONPENDING; | 146 return PP_OK_COMPLETIONPENDING; |
(...skipping 12 matching lines...) Expand all Loading... |
153 if (enter.failed()) | 159 if (enter.failed()) |
154 return PP_ERROR_FAILED; | 160 return PP_ERROR_FAILED; |
155 | 161 |
156 PPB_Buffer_Impl* buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); | 162 PPB_Buffer_Impl* buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); |
157 media::BitstreamBuffer decode_buffer(bitstream_buffer->id, | 163 media::BitstreamBuffer decode_buffer(bitstream_buffer->id, |
158 buffer->shared_memory()->handle(), | 164 buffer->shared_memory()->handle(), |
159 static_cast<size_t>(buffer->size())); | 165 static_cast<size_t>(buffer->size())); |
160 CHECK(bitstream_buffer_callbacks_.insert(std::make_pair( | 166 CHECK(bitstream_buffer_callbacks_.insert(std::make_pair( |
161 bitstream_buffer->id, callback)).second); | 167 bitstream_buffer->id, callback)).second); |
162 | 168 |
163 if (platform_video_decoder_->Decode(decode_buffer)) | 169 platform_video_decoder_->Decode(decode_buffer); |
164 return PP_OK_COMPLETIONPENDING; | 170 return PP_OK_COMPLETIONPENDING; |
165 else | |
166 return PP_ERROR_FAILED; | |
167 } | 171 } |
168 | 172 |
169 void PPB_VideoDecoder_Impl::AssignGLESBuffers( | 173 void PPB_VideoDecoder_Impl::AssignGLESBuffers( |
170 uint32_t no_of_buffers, | 174 uint32_t no_of_buffers, |
171 const PP_GLESBuffer_Dev* buffers) { | 175 const PP_GLESBuffer_Dev* buffers) { |
172 if (!platform_video_decoder_.get()) | 176 if (!platform_video_decoder_.get()) |
173 return; | 177 return; |
174 | 178 |
175 std::vector<media::GLESBuffer> wrapped_buffers; | 179 std::vector<media::GLESBuffer> wrapped_buffers; |
176 for (uint32 i = 0; i < no_of_buffers; i++) { | 180 for (uint32 i = 0; i < no_of_buffers; i++) { |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
216 } | 220 } |
217 | 221 |
218 int32_t PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) { | 222 int32_t PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) { |
219 if (!platform_video_decoder_.get()) | 223 if (!platform_video_decoder_.get()) |
220 return PP_ERROR_BADRESOURCE; | 224 return PP_ERROR_BADRESOURCE; |
221 | 225 |
222 // Store the callback to be called when Flush() is done. | 226 // Store the callback to be called when Flush() is done. |
223 // TODO(vmr): Check for current flush/abort operations. | 227 // TODO(vmr): Check for current flush/abort operations. |
224 flush_callback_ = callback; | 228 flush_callback_ = callback; |
225 | 229 |
226 if (platform_video_decoder_->Flush()) | 230 platform_video_decoder_->Flush(); |
227 return PP_OK_COMPLETIONPENDING; | 231 return PP_OK_COMPLETIONPENDING; |
228 else | |
229 return PP_ERROR_FAILED; | |
230 } | 232 } |
231 | 233 |
232 int32_t PPB_VideoDecoder_Impl::Abort(PP_CompletionCallback callback) { | 234 int32_t PPB_VideoDecoder_Impl::Abort(PP_CompletionCallback callback) { |
233 if (!platform_video_decoder_.get()) | 235 if (!platform_video_decoder_.get()) |
234 return PP_ERROR_BADRESOURCE; | 236 return PP_ERROR_BADRESOURCE; |
235 | 237 |
236 // Store the callback to be called when Abort() is done. | 238 // Store the callback to be called when Abort() is done. |
237 // TODO(vmr): Check for current flush/abort operations. | 239 // TODO(vmr): Check for current flush/abort operations. |
238 abort_callback_ = callback; | 240 abort_callback_ = callback; |
239 | 241 |
240 if (platform_video_decoder_->Abort()) | 242 platform_video_decoder_->Abort(); |
241 return PP_OK_COMPLETIONPENDING; | 243 return PP_OK_COMPLETIONPENDING; |
242 else | |
243 return PP_ERROR_FAILED; | |
244 } | 244 } |
245 | 245 |
246 void PPB_VideoDecoder_Impl::ProvidePictureBuffers( | 246 void PPB_VideoDecoder_Impl::ProvidePictureBuffers( |
247 uint32 requested_num_of_buffers, | 247 uint32 requested_num_of_buffers, |
248 const gfx::Size& dimensions, | 248 const gfx::Size& dimensions, |
249 media::VideoDecodeAccelerator::MemoryType type) { | 249 media::VideoDecodeAccelerator::MemoryType type) { |
250 if (!ppp_videodecoder_) | 250 if (!ppp_videodecoder_) |
251 return; | 251 return; |
252 | 252 |
253 // TODO(vrk): Compiler assert or use switch statement instead of making | 253 // TODO(vrk): Compiler assert or use switch statement instead of making |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 | 331 |
332 void PPB_VideoDecoder_Impl::NotifyInitializeDone() { | 332 void PPB_VideoDecoder_Impl::NotifyInitializeDone() { |
333 if (initialization_callback_.func == NULL) | 333 if (initialization_callback_.func == NULL) |
334 return; | 334 return; |
335 | 335 |
336 PP_RunAndClearCompletionCallback(&initialization_callback_, PP_OK); | 336 PP_RunAndClearCompletionCallback(&initialization_callback_, PP_OK); |
337 } | 337 } |
338 | 338 |
339 } // namespace ppapi | 339 } // namespace ppapi |
340 } // namespace webkit | 340 } // namespace webkit |
OLD | NEW |