| 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" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 using ppapi::thunk::EnterResourceNoLock; | 26 using ppapi::thunk::EnterResourceNoLock; |
| 27 using ppapi::thunk::PPB_Buffer_API; | 27 using ppapi::thunk::PPB_Buffer_API; |
| 28 using ppapi::thunk::PPB_Context3D_API; | 28 using ppapi::thunk::PPB_Context3D_API; |
| 29 using ppapi::thunk::PPB_VideoDecoder_API; | 29 using ppapi::thunk::PPB_VideoDecoder_API; |
| 30 | 30 |
| 31 namespace webkit { | 31 namespace webkit { |
| 32 namespace ppapi { | 32 namespace ppapi { |
| 33 | 33 |
| 34 PPB_VideoDecoder_Impl::PPB_VideoDecoder_Impl(PluginInstance* instance) | 34 PPB_VideoDecoder_Impl::PPB_VideoDecoder_Impl(PluginInstance* instance) |
| 35 : Resource(instance), | 35 : Resource(instance) { |
| 36 callback_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), | |
| 37 context3d_id_(0), | |
| 38 flush_callback_(PP_BlockUntilComplete()), | |
| 39 reset_callback_(PP_BlockUntilComplete()), | |
| 40 gles2_impl_(NULL) { | |
| 41 ppp_videodecoder_ = | 36 ppp_videodecoder_ = |
| 42 static_cast<const PPP_VideoDecoder_Dev*>(instance->module()-> | 37 static_cast<const PPP_VideoDecoder_Dev*>(instance->module()-> |
| 43 GetPluginInterface(PPP_VIDEODECODER_DEV_INTERFACE)); | 38 GetPluginInterface(PPP_VIDEODECODER_DEV_INTERFACE)); |
| 44 } | 39 } |
| 45 | 40 |
| 46 PPB_VideoDecoder_Impl::~PPB_VideoDecoder_Impl() { | 41 PPB_VideoDecoder_Impl::~PPB_VideoDecoder_Impl() { |
| 47 } | 42 } |
| 48 | 43 |
| 49 PPB_VideoDecoder_API* PPB_VideoDecoder_Impl::AsPPB_VideoDecoder_API() { | 44 PPB_VideoDecoder_API* PPB_VideoDecoder_Impl::AsPPB_VideoDecoder_API() { |
| 50 return this; | 45 return this; |
| 51 } | 46 } |
| 52 | 47 |
| 53 // static | 48 // static |
| 54 PP_Resource PPB_VideoDecoder_Impl::Create(PluginInstance* instance, | 49 PP_Resource PPB_VideoDecoder_Impl::Create(PluginInstance* instance, |
| 55 PP_Resource context3d_id, | 50 PP_Resource context3d_id, |
| 56 const PP_VideoConfigElement* config) { | 51 const PP_VideoConfigElement* config) { |
| 52 if (!context3d_id) |
| 53 return NULL; |
| 54 |
| 55 EnterResourceNoLock<PPB_Context3D_API> enter_context(context3d_id, true); |
| 56 if (enter_context.failed()) |
| 57 return NULL; |
| 58 |
| 57 scoped_refptr<PPB_VideoDecoder_Impl> decoder( | 59 scoped_refptr<PPB_VideoDecoder_Impl> decoder( |
| 58 new PPB_VideoDecoder_Impl(instance)); | 60 new PPB_VideoDecoder_Impl(instance)); |
| 59 if (decoder->Init(context3d_id, config)) | 61 if (decoder->Init(context3d_id, enter_context.object(), config)) |
| 60 return decoder->GetReference(); | 62 return decoder->GetReference(); |
| 61 return 0; | 63 return 0; |
| 62 } | 64 } |
| 63 | 65 |
| 64 bool PPB_VideoDecoder_Impl::Init(PP_Resource context3d_id, | 66 bool PPB_VideoDecoder_Impl::Init(PP_Resource context3d_id, |
| 67 PPB_Context3D_API* context3d, |
| 65 const PP_VideoConfigElement* config) { | 68 const PP_VideoConfigElement* config) { |
| 66 if (!instance() || !context3d_id || !config) | 69 if (!::ppapi::VideoDecoderImpl::Init(context3d_id, context3d, config)) |
| 67 return false; | 70 return false; |
| 68 | 71 |
| 69 EnterResourceNoLock<PPB_Context3D_API> enter(context3d_id, true); | 72 std::vector<int32> copied; |
| 70 if (enter.failed()) | 73 if (!CopyConfigsToVector(config, &copied)) |
| 71 return false; | 74 return false; |
| 72 PPB_Context3D_Impl* context3d = | |
| 73 static_cast<PPB_Context3D_Impl*>(enter.object()); | |
| 74 | 75 |
| 75 context3d_id_ = context3d_id; | 76 PPB_Context3D_Impl* context3d_impl = |
| 76 ResourceTracker::Get()->AddRefResource(context3d_id_); | 77 static_cast<PPB_Context3D_Impl*>(context3d); |
| 77 | 78 |
| 78 int command_buffer_route_id = | 79 int command_buffer_route_id = |
| 79 context3d->platform_context()->GetCommandBufferRouteId(); | 80 context3d_impl->platform_context()->GetCommandBufferRouteId(); |
| 80 if (command_buffer_route_id == 0) | 81 if (command_buffer_route_id == 0) |
| 81 return false; | 82 return false; |
| 82 platform_video_decoder_ = instance()->delegate()->CreateVideoDecoder( | 83 platform_video_decoder_ = instance()->delegate()->CreateVideoDecoder( |
| 83 this, command_buffer_route_id); | 84 this, command_buffer_route_id); |
| 84 | |
| 85 gles2_impl_ = context3d->gles2_impl(); | |
| 86 | |
| 87 if (!platform_video_decoder_) | 85 if (!platform_video_decoder_) |
| 88 return false; | 86 return false; |
| 89 | 87 |
| 90 std::vector<uint32> copied; | |
| 91 // TODO(fischman,vrk): this is completely broken in that it fails to account | |
| 92 // for the semantic distinction between keys and values; it is certainly | |
| 93 // possible for a value to show up as 0, and that shouldn't terminate the | |
| 94 // config vector. Only a *key* of 0 should do so. | |
| 95 // TODO(vrk): This is assuming PP_VideoAttributeDictionary and | |
| 96 // VideoAttributeKey have identical enum values. There is no compiler | |
| 97 // assert to guarantee this. We either need to add such asserts or | |
| 98 // merge PP_VideoAttributeDictionary and VideoAttributeKey. | |
| 99 for (const PP_VideoConfigElement* current = config; | |
| 100 *current != PP_VIDEOATTR_DICTIONARY_TERMINATOR; ++current) { | |
| 101 copied.push_back(static_cast<uint32>(*current)); | |
| 102 } | |
| 103 | |
| 104 FlushCommandBuffer(); | 88 FlushCommandBuffer(); |
| 105 return platform_video_decoder_->Initialize(copied); | 89 return platform_video_decoder_->Initialize(copied); |
| 106 } | 90 } |
| 107 | 91 |
| 108 int32_t PPB_VideoDecoder_Impl::Decode( | 92 int32_t PPB_VideoDecoder_Impl::Decode( |
| 109 const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, | 93 const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, |
| 110 PP_CompletionCallback callback) { | 94 PP_CompletionCallback callback) { |
| 111 if (!platform_video_decoder_) | 95 if (!platform_video_decoder_) |
| 112 return PP_ERROR_BADRESOURCE; | 96 return PP_ERROR_BADRESOURCE; |
| 113 | 97 |
| 114 EnterResourceNoLock<PPB_Buffer_API> enter(bitstream_buffer->data, true); | 98 EnterResourceNoLock<PPB_Buffer_API> enter(bitstream_buffer->data, true); |
| 115 if (enter.failed()) | 99 if (enter.failed()) |
| 116 return PP_ERROR_FAILED; | 100 return PP_ERROR_FAILED; |
| 117 | 101 |
| 118 PPB_Buffer_Impl* buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); | 102 PPB_Buffer_Impl* buffer = static_cast<PPB_Buffer_Impl*>(enter.object()); |
| 119 media::BitstreamBuffer decode_buffer(bitstream_buffer->id, | 103 media::BitstreamBuffer decode_buffer(bitstream_buffer->id, |
| 120 buffer->shared_memory()->handle(), | 104 buffer->shared_memory()->handle(), |
| 121 static_cast<size_t>(buffer->size())); | 105 static_cast<size_t>(buffer->size())); |
| 122 CHECK(bitstream_buffer_callbacks_.insert(std::make_pair( | 106 SetBitstreamBufferCallback(bitstream_buffer->id, callback); |
| 123 bitstream_buffer->id, callback)).second); | |
| 124 | 107 |
| 125 FlushCommandBuffer(); | 108 FlushCommandBuffer(); |
| 126 platform_video_decoder_->Decode(decode_buffer); | 109 platform_video_decoder_->Decode(decode_buffer); |
| 127 return PP_OK_COMPLETIONPENDING; | 110 return PP_OK_COMPLETIONPENDING; |
| 128 } | 111 } |
| 129 | 112 |
| 130 void PPB_VideoDecoder_Impl::AssignPictureBuffers( | 113 void PPB_VideoDecoder_Impl::AssignPictureBuffers( |
| 131 uint32_t no_of_buffers, | 114 uint32_t no_of_buffers, |
| 132 const PP_PictureBuffer_Dev* buffers) { | 115 const PP_PictureBuffer_Dev* buffers) { |
| 133 if (!platform_video_decoder_) | 116 if (!platform_video_decoder_) |
| (...skipping 18 matching lines...) Expand all Loading... |
| 152 return; | 135 return; |
| 153 | 136 |
| 154 FlushCommandBuffer(); | 137 FlushCommandBuffer(); |
| 155 platform_video_decoder_->ReusePictureBuffer(picture_buffer_id); | 138 platform_video_decoder_->ReusePictureBuffer(picture_buffer_id); |
| 156 } | 139 } |
| 157 | 140 |
| 158 int32_t PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) { | 141 int32_t PPB_VideoDecoder_Impl::Flush(PP_CompletionCallback callback) { |
| 159 if (!platform_video_decoder_) | 142 if (!platform_video_decoder_) |
| 160 return PP_ERROR_BADRESOURCE; | 143 return PP_ERROR_BADRESOURCE; |
| 161 | 144 |
| 162 // Store the callback to be called when Flush() is done. | 145 SetFlushCallback(callback); |
| 163 // TODO(fischman,vrk): consider implications of already-outstanding callback. | |
| 164 flush_callback_ = callback; | |
| 165 | 146 |
| 166 FlushCommandBuffer(); | 147 FlushCommandBuffer(); |
| 167 platform_video_decoder_->Flush(); | 148 platform_video_decoder_->Flush(); |
| 168 return PP_OK_COMPLETIONPENDING; | 149 return PP_OK_COMPLETIONPENDING; |
| 169 } | 150 } |
| 170 | 151 |
| 171 int32_t PPB_VideoDecoder_Impl::Reset(PP_CompletionCallback callback) { | 152 int32_t PPB_VideoDecoder_Impl::Reset(PP_CompletionCallback callback) { |
| 172 if (!platform_video_decoder_) | 153 if (!platform_video_decoder_) |
| 173 return PP_ERROR_BADRESOURCE; | 154 return PP_ERROR_BADRESOURCE; |
| 174 | 155 |
| 175 // Store the callback to be called when Reset() is done. | 156 SetResetCallback(callback); |
| 176 // TODO(fischman,vrk): consider implications of already-outstanding callback. | |
| 177 reset_callback_ = callback; | |
| 178 | 157 |
| 179 FlushCommandBuffer(); | 158 FlushCommandBuffer(); |
| 180 platform_video_decoder_->Reset(); | 159 platform_video_decoder_->Reset(); |
| 181 return PP_OK_COMPLETIONPENDING; | 160 return PP_OK_COMPLETIONPENDING; |
| 182 } | 161 } |
| 183 | 162 |
| 184 void PPB_VideoDecoder_Impl::Destroy() { | 163 void PPB_VideoDecoder_Impl::Destroy() { |
| 185 if (!platform_video_decoder_) | 164 if (!platform_video_decoder_) |
| 186 return; | 165 return; |
| 187 | 166 |
| 188 FlushCommandBuffer(); | 167 FlushCommandBuffer(); |
| 189 platform_video_decoder_->Destroy(); | 168 platform_video_decoder_->Destroy(); |
| 190 gles2_impl_ = NULL; | 169 ::ppapi::VideoDecoderImpl::Destroy(); |
| 191 if (context3d_id_) | |
| 192 ResourceTracker::Get()->UnrefResource(context3d_id_); | |
| 193 platform_video_decoder_ = NULL; | 170 platform_video_decoder_ = NULL; |
| 194 ppp_videodecoder_ = NULL; | 171 ppp_videodecoder_ = NULL; |
| 195 } | 172 } |
| 196 | 173 |
| 197 void PPB_VideoDecoder_Impl::ProvidePictureBuffers( | 174 void PPB_VideoDecoder_Impl::ProvidePictureBuffers( |
| 198 uint32 requested_num_of_buffers, const gfx::Size& dimensions) { | 175 uint32 requested_num_of_buffers, const gfx::Size& dimensions) { |
| 199 if (!ppp_videodecoder_) | 176 if (!ppp_videodecoder_) |
| 200 return; | 177 return; |
| 201 | 178 |
| 202 PP_Size out_dim = PP_MakeSize(dimensions.width(), dimensions.height()); | 179 PP_Size out_dim = PP_MakeSize(dimensions.width(), dimensions.height()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 ScopedResourceId resource(this); | 220 ScopedResourceId resource(this); |
| 244 // TODO(vrk): This is assuming VideoDecodeAccelerator::Error and | 221 // TODO(vrk): This is assuming VideoDecodeAccelerator::Error and |
| 245 // PP_VideoDecodeError_Dev have identical enum values. There is no compiler | 222 // PP_VideoDecodeError_Dev have identical enum values. There is no compiler |
| 246 // assert to guarantee this. We either need to add such asserts or | 223 // assert to guarantee this. We either need to add such asserts or |
| 247 // merge these two enums. | 224 // merge these two enums. |
| 248 ppp_videodecoder_->NotifyError(instance()->pp_instance(), resource.id, | 225 ppp_videodecoder_->NotifyError(instance()->pp_instance(), resource.id, |
| 249 static_cast<PP_VideoDecodeError_Dev>(error)); | 226 static_cast<PP_VideoDecodeError_Dev>(error)); |
| 250 } | 227 } |
| 251 | 228 |
| 252 void PPB_VideoDecoder_Impl::NotifyResetDone() { | 229 void PPB_VideoDecoder_Impl::NotifyResetDone() { |
| 253 if (reset_callback_.func == NULL) | 230 RunResetCallback(PP_OK); |
| 254 return; | |
| 255 | |
| 256 // Call the callback that was stored to be called when Reset is done. | |
| 257 PP_RunAndClearCompletionCallback(&reset_callback_, PP_OK); | |
| 258 } | 231 } |
| 259 | 232 |
| 260 void PPB_VideoDecoder_Impl::NotifyEndOfBitstreamBuffer( | 233 void PPB_VideoDecoder_Impl::NotifyEndOfBitstreamBuffer( |
| 261 int32 bitstream_buffer_id) { | 234 int32 bitstream_buffer_id) { |
| 262 CallbackById::iterator it = | 235 RunBitstreamBufferCallback(bitstream_buffer_id, PP_OK); |
| 263 bitstream_buffer_callbacks_.find(bitstream_buffer_id); | |
| 264 DCHECK(it != bitstream_buffer_callbacks_.end()); | |
| 265 PP_CompletionCallback cc = it->second; | |
| 266 bitstream_buffer_callbacks_.erase(it); | |
| 267 PP_RunCompletionCallback(&cc, PP_OK); | |
| 268 } | 236 } |
| 269 | 237 |
| 270 void PPB_VideoDecoder_Impl::NotifyFlushDone() { | 238 void PPB_VideoDecoder_Impl::NotifyFlushDone() { |
| 271 if (flush_callback_.func == NULL) | 239 RunFlushCallback(PP_OK); |
| 272 return; | |
| 273 | |
| 274 // Call the callback that was stored to be called when Flush is done. | |
| 275 PP_RunAndClearCompletionCallback(&flush_callback_, PP_OK); | |
| 276 } | 240 } |
| 277 | 241 |
| 278 void PPB_VideoDecoder_Impl::NotifyInitializeDone() { | 242 void PPB_VideoDecoder_Impl::NotifyInitializeDone() { |
| 279 NOTREACHED() << "PlatformVideoDecoder::Initialize() is synchronous!"; | 243 NOTREACHED() << "PlatformVideoDecoder::Initialize() is synchronous!"; |
| 280 } | 244 } |
| 245 void PPB_VideoDecoder_Impl::AddRefResource(PP_Resource resource) { |
| 246 ResourceTracker::Get()->AddRefResource(resource); |
| 247 } |
| 281 | 248 |
| 282 void PPB_VideoDecoder_Impl::FlushCommandBuffer() { | 249 void PPB_VideoDecoder_Impl::UnrefResource(PP_Resource resource) { |
| 283 // For the out-of-process case, |gles2_impl_| will be NULL in the renderer | 250 ResourceTracker::Get()->UnrefResource(resource); |
| 284 // process. The VideoDecoder_Proxy is charged with the responsibility of | |
| 285 // doing this Flush() in the analogous places in the plugin process. | |
| 286 if (gles2_impl_) | |
| 287 gles2_impl_->Flush(); | |
| 288 } | 251 } |
| 289 | 252 |
| 290 } // namespace ppapi | 253 } // namespace ppapi |
| 291 } // namespace webkit | 254 } // namespace webkit |
| OLD | NEW |