| 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 12 matching lines...) Expand all Loading... |
| 23 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" | 23 #include "webkit/plugins/ppapi/ppb_buffer_impl.h" |
| 24 #include "webkit/plugins/ppapi/ppb_context_3d_impl.h" | 24 #include "webkit/plugins/ppapi/ppb_context_3d_impl.h" |
| 25 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" | 25 #include "webkit/plugins/ppapi/ppb_graphics_3d_impl.h" |
| 26 #include "webkit/plugins/ppapi/resource_tracker.h" | 26 #include "webkit/plugins/ppapi/resource_tracker.h" |
| 27 | 27 |
| 28 using ppapi::thunk::EnterResourceNoLock; | 28 using ppapi::thunk::EnterResourceNoLock; |
| 29 using ppapi::thunk::PPB_Buffer_API; | 29 using ppapi::thunk::PPB_Buffer_API; |
| 30 using ppapi::thunk::PPB_Context3D_API; | 30 using ppapi::thunk::PPB_Context3D_API; |
| 31 using ppapi::thunk::PPB_Graphics3D_API; | 31 using ppapi::thunk::PPB_Graphics3D_API; |
| 32 using ppapi::thunk::PPB_VideoDecoder_API; | 32 using ppapi::thunk::PPB_VideoDecoder_API; |
| 33 typedef media::VideoDecodeAccelerator::Config Config; |
| 33 | 34 |
| 34 namespace webkit { | 35 namespace webkit { |
| 35 namespace ppapi { | 36 namespace ppapi { |
| 36 | 37 |
| 37 PPB_VideoDecoder_Impl::PPB_VideoDecoder_Impl(PP_Instance instance) | 38 PPB_VideoDecoder_Impl::PPB_VideoDecoder_Impl(PP_Instance instance) |
| 38 : Resource(instance), | 39 : Resource(instance), |
| 39 ppp_videodecoder_(NULL) { | 40 ppp_videodecoder_(NULL) { |
| 40 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); | 41 PluginModule* plugin_module = ResourceHelper::GetPluginModule(this); |
| 41 if (plugin_module) { | 42 if (plugin_module) { |
| 42 ppp_videodecoder_ = static_cast<const PPP_VideoDecoder_Dev*>( | 43 ppp_videodecoder_ = static_cast<const PPP_VideoDecoder_Dev*>( |
| 43 plugin_module->GetPluginInterface(PPP_VIDEODECODER_DEV_INTERFACE)); | 44 plugin_module->GetPluginInterface(PPP_VIDEODECODER_DEV_INTERFACE)); |
| 44 } | 45 } |
| 45 } | 46 } |
| 46 | 47 |
| 47 PPB_VideoDecoder_Impl::~PPB_VideoDecoder_Impl() { | 48 PPB_VideoDecoder_Impl::~PPB_VideoDecoder_Impl() { |
| 48 } | 49 } |
| 49 | 50 |
| 50 PPB_VideoDecoder_API* PPB_VideoDecoder_Impl::AsPPB_VideoDecoder_API() { | 51 PPB_VideoDecoder_API* PPB_VideoDecoder_Impl::AsPPB_VideoDecoder_API() { |
| 51 return this; | 52 return this; |
| 52 } | 53 } |
| 53 | 54 |
| 55 // Convert PP_VideoDecoderConfig_Dev to media::VideoDecodeAccelerator::Config. |
| 56 static media::VideoDecodeAccelerator::Config PPToMediaConfig( |
| 57 const PP_VideoDecoderConfig_Dev& pp_config) { |
| 58 Config media_config; |
| 59 // TODO(fischman,vrk): this assumes the enums in the two Config objects match |
| 60 // up, as do their fields. Add a COMPILE_ASSERT of these facts somewhere. |
| 61 media_config.format = static_cast<Config::Format>(pp_config.format); |
| 62 media_config.h264_profile = |
| 63 static_cast<Config::H264Profile>(pp_config.h264_profile); |
| 64 return media_config; |
| 65 } |
| 66 |
| 54 // static | 67 // static |
| 55 PP_Resource PPB_VideoDecoder_Impl::Create(PP_Instance instance, | 68 PP_Resource PPB_VideoDecoder_Impl::Create( |
| 56 PP_Resource graphics_context, | 69 PP_Instance instance, |
| 57 const PP_VideoConfigElement* config) { | 70 PP_Resource graphics_context, |
| 71 const PP_VideoDecoderConfig_Dev& config) { |
| 58 PluginDelegate::PlatformContext3D* platform_context = NULL; | 72 PluginDelegate::PlatformContext3D* platform_context = NULL; |
| 59 gpu::gles2::GLES2Implementation* gles2_impl = NULL; | 73 gpu::gles2::GLES2Implementation* gles2_impl = NULL; |
| 60 EnterResourceNoLock<PPB_Context3D_API> enter_context(graphics_context, false); | 74 EnterResourceNoLock<PPB_Context3D_API> enter_context(graphics_context, false); |
| 61 if (enter_context.succeeded()) { | 75 if (enter_context.succeeded()) { |
| 62 PPB_Context3D_Impl* context3d_impl = | 76 PPB_Context3D_Impl* context3d_impl = |
| 63 static_cast<PPB_Context3D_Impl*>(enter_context.object()); | 77 static_cast<PPB_Context3D_Impl*>(enter_context.object()); |
| 64 platform_context = context3d_impl->platform_context(); | 78 platform_context = context3d_impl->platform_context(); |
| 65 gles2_impl = context3d_impl->gles2_impl(); | 79 gles2_impl = context3d_impl->gles2_impl(); |
| 66 } else { | 80 } else { |
| 67 EnterResourceNoLock<PPB_Graphics3D_API> enter_context(graphics_context, | 81 EnterResourceNoLock<PPB_Graphics3D_API> enter_context(graphics_context, |
| (...skipping 10 matching lines...) Expand all Loading... |
| 78 new PPB_VideoDecoder_Impl(instance)); | 92 new PPB_VideoDecoder_Impl(instance)); |
| 79 if (decoder->Init(graphics_context, platform_context, gles2_impl, config)) | 93 if (decoder->Init(graphics_context, platform_context, gles2_impl, config)) |
| 80 return decoder->GetReference(); | 94 return decoder->GetReference(); |
| 81 return 0; | 95 return 0; |
| 82 } | 96 } |
| 83 | 97 |
| 84 bool PPB_VideoDecoder_Impl::Init( | 98 bool PPB_VideoDecoder_Impl::Init( |
| 85 PP_Resource graphics_context, | 99 PP_Resource graphics_context, |
| 86 PluginDelegate::PlatformContext3D* context, | 100 PluginDelegate::PlatformContext3D* context, |
| 87 gpu::gles2::GLES2Implementation* gles2_impl, | 101 gpu::gles2::GLES2Implementation* gles2_impl, |
| 88 const PP_VideoConfigElement* config) { | 102 const PP_VideoDecoderConfig_Dev& config) { |
| 89 InitCommon(graphics_context, gles2_impl); | 103 InitCommon(graphics_context, gles2_impl); |
| 90 | 104 |
| 91 int command_buffer_route_id = context->GetCommandBufferRouteId(); | 105 int command_buffer_route_id = context->GetCommandBufferRouteId(); |
| 92 if (command_buffer_route_id == 0) | 106 if (command_buffer_route_id == 0) |
| 93 return false; | 107 return false; |
| 94 | 108 |
| 95 std::vector<int32> copied; | |
| 96 if (!CopyConfigsToVector(config, &copied)) | |
| 97 return false; | |
| 98 | |
| 99 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); | 109 PluginDelegate* plugin_delegate = ResourceHelper::GetPluginDelegate(this); |
| 100 if (!plugin_delegate) | 110 if (!plugin_delegate) |
| 101 return false; | 111 return false; |
| 102 | 112 |
| 103 platform_video_decoder_ = plugin_delegate->CreateVideoDecoder( | 113 platform_video_decoder_ = plugin_delegate->CreateVideoDecoder( |
| 104 this, command_buffer_route_id); | 114 this, command_buffer_route_id); |
| 105 if (!platform_video_decoder_) | 115 if (!platform_video_decoder_) |
| 106 return false; | 116 return false; |
| 107 | 117 |
| 108 FlushCommandBuffer(); | 118 FlushCommandBuffer(); |
| 109 return platform_video_decoder_->Initialize(copied); | 119 return platform_video_decoder_->Initialize(PPToMediaConfig(config)); |
| 110 } | 120 } |
| 111 | 121 |
| 112 int32_t PPB_VideoDecoder_Impl::Decode( | 122 int32_t PPB_VideoDecoder_Impl::Decode( |
| 113 const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, | 123 const PP_VideoBitstreamBuffer_Dev* bitstream_buffer, |
| 114 PP_CompletionCallback callback) { | 124 PP_CompletionCallback callback) { |
| 115 if (!platform_video_decoder_) | 125 if (!platform_video_decoder_) |
| 116 return PP_ERROR_BADRESOURCE; | 126 return PP_ERROR_BADRESOURCE; |
| 117 | 127 |
| 118 EnterResourceNoLock<PPB_Buffer_API> enter(bitstream_buffer->data, true); | 128 EnterResourceNoLock<PPB_Buffer_API> enter(bitstream_buffer->data, true); |
| 119 if (enter.failed()) | 129 if (enter.failed()) |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 253 void PPB_VideoDecoder_Impl::NotifyFlushDone() { | 263 void PPB_VideoDecoder_Impl::NotifyFlushDone() { |
| 254 RunFlushCallback(PP_OK); | 264 RunFlushCallback(PP_OK); |
| 255 } | 265 } |
| 256 | 266 |
| 257 void PPB_VideoDecoder_Impl::NotifyInitializeDone() { | 267 void PPB_VideoDecoder_Impl::NotifyInitializeDone() { |
| 258 NOTREACHED() << "PlatformVideoDecoder::Initialize() is synchronous!"; | 268 NOTREACHED() << "PlatformVideoDecoder::Initialize() is synchronous!"; |
| 259 } | 269 } |
| 260 | 270 |
| 261 } // namespace ppapi | 271 } // namespace ppapi |
| 262 } // namespace webkit | 272 } // namespace webkit |
| OLD | NEW |