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