| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 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 "content/renderer/pepper/pepper_video_decoder_host.h" | 5 #include "content/renderer/pepper/pepper_video_decoder_host.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/shared_memory.h" | 8 #include "base/memory/shared_memory.h" |
| 9 #include "content/common/gpu/client/gpu_channel_host.h" | 9 #include "content/common/gpu/client/gpu_channel_host.h" |
| 10 #include "content/common/pepper_file_util.h" | 10 #include "content/common/pepper_file_util.h" |
| 11 #include "content/public/renderer/render_thread.h" | 11 #include "content/public/renderer/render_thread.h" |
| 12 #include "content/public/renderer/renderer_ppapi_host.h" | 12 #include "content/public/renderer/renderer_ppapi_host.h" |
| 13 #include "content/renderer/pepper/gfx_conversion.h" | 13 #include "content/renderer/pepper/gfx_conversion.h" |
| 14 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" | 14 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" |
| 15 #include "content/renderer/pepper/video_decoder_shim.h" | 15 #include "content/renderer/pepper/video_decoder_shim.h" |
| 16 #include "media/base/limits.h" |
| 16 #include "media/video/video_decode_accelerator.h" | 17 #include "media/video/video_decode_accelerator.h" |
| 17 #include "ppapi/c/pp_completion_callback.h" | 18 #include "ppapi/c/pp_completion_callback.h" |
| 18 #include "ppapi/c/pp_errors.h" | 19 #include "ppapi/c/pp_errors.h" |
| 19 #include "ppapi/host/dispatch_host_message.h" | 20 #include "ppapi/host/dispatch_host_message.h" |
| 20 #include "ppapi/host/ppapi_host.h" | 21 #include "ppapi/host/ppapi_host.h" |
| 21 #include "ppapi/proxy/ppapi_messages.h" | 22 #include "ppapi/proxy/ppapi_messages.h" |
| 22 #include "ppapi/proxy/video_decoder_constants.h" | 23 #include "ppapi/proxy/video_decoder_constants.h" |
| 23 #include "ppapi/thunk/enter.h" | 24 #include "ppapi/thunk/enter.h" |
| 24 #include "ppapi/thunk/ppb_graphics_3d_api.h" | 25 #include "ppapi/thunk/ppb_graphics_3d_api.h" |
| 25 | 26 |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 } | 75 } |
| 75 | 76 |
| 76 PepperVideoDecoderHost::PendingDecode::~PendingDecode() { | 77 PepperVideoDecoderHost::PendingDecode::~PendingDecode() { |
| 77 } | 78 } |
| 78 | 79 |
| 79 PepperVideoDecoderHost::PepperVideoDecoderHost(RendererPpapiHost* host, | 80 PepperVideoDecoderHost::PepperVideoDecoderHost(RendererPpapiHost* host, |
| 80 PP_Instance instance, | 81 PP_Instance instance, |
| 81 PP_Resource resource) | 82 PP_Resource resource) |
| 82 : ResourceHost(host->GetPpapiHost(), instance, resource), | 83 : ResourceHost(host->GetPpapiHost(), instance, resource), |
| 83 renderer_ppapi_host_(host), | 84 renderer_ppapi_host_(host), |
| 85 min_picture_count_(0), |
| 84 initialized_(false) { | 86 initialized_(false) { |
| 85 } | 87 } |
| 86 | 88 |
| 87 PepperVideoDecoderHost::~PepperVideoDecoderHost() { | 89 PepperVideoDecoderHost::~PepperVideoDecoderHost() { |
| 88 } | 90 } |
| 89 | 91 |
| 90 int32_t PepperVideoDecoderHost::OnResourceMessageReceived( | 92 int32_t PepperVideoDecoderHost::OnResourceMessageReceived( |
| 91 const IPC::Message& msg, | 93 const IPC::Message& msg, |
| 92 ppapi::host::HostMessageContext* context) { | 94 ppapi::host::HostMessageContext* context) { |
| 93 PPAPI_BEGIN_MESSAGE_MAP(PepperVideoDecoderHost, msg) | 95 PPAPI_BEGIN_MESSAGE_MAP(PepperVideoDecoderHost, msg) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 106 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_VideoDecoder_Reset, | 108 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_VideoDecoder_Reset, |
| 107 OnHostMsgReset) | 109 OnHostMsgReset) |
| 108 PPAPI_END_MESSAGE_MAP() | 110 PPAPI_END_MESSAGE_MAP() |
| 109 return PP_ERROR_FAILED; | 111 return PP_ERROR_FAILED; |
| 110 } | 112 } |
| 111 | 113 |
| 112 int32_t PepperVideoDecoderHost::OnHostMsgInitialize( | 114 int32_t PepperVideoDecoderHost::OnHostMsgInitialize( |
| 113 ppapi::host::HostMessageContext* context, | 115 ppapi::host::HostMessageContext* context, |
| 114 const ppapi::HostResource& graphics_context, | 116 const ppapi::HostResource& graphics_context, |
| 115 PP_VideoProfile profile, | 117 PP_VideoProfile profile, |
| 116 PP_HardwareAcceleration acceleration) { | 118 PP_HardwareAcceleration acceleration, |
| 119 uint32_t min_picture_count) { |
| 117 if (initialized_) | 120 if (initialized_) |
| 118 return PP_ERROR_FAILED; | 121 return PP_ERROR_FAILED; |
| 119 | 122 |
| 120 EnterResourceNoLock<PPB_Graphics3D_API> enter_graphics( | 123 EnterResourceNoLock<PPB_Graphics3D_API> enter_graphics( |
| 121 graphics_context.host_resource(), true); | 124 graphics_context.host_resource(), true); |
| 122 if (enter_graphics.failed()) | 125 if (enter_graphics.failed()) |
| 123 return PP_ERROR_FAILED; | 126 return PP_ERROR_FAILED; |
| 124 PPB_Graphics3D_Impl* graphics3d = | 127 PPB_Graphics3D_Impl* graphics3d = |
| 125 static_cast<PPB_Graphics3D_Impl*>(enter_graphics.object()); | 128 static_cast<PPB_Graphics3D_Impl*>(enter_graphics.object()); |
| 126 | 129 |
| 127 int command_buffer_route_id = graphics3d->GetCommandBufferRouteId(); | 130 int command_buffer_route_id = graphics3d->GetCommandBufferRouteId(); |
| 128 if (!command_buffer_route_id) | 131 if (!command_buffer_route_id) |
| 129 return PP_ERROR_FAILED; | 132 return PP_ERROR_FAILED; |
| 130 | 133 |
| 131 media::VideoCodecProfile media_profile = PepperToMediaVideoProfile(profile); | 134 media::VideoCodecProfile media_profile = PepperToMediaVideoProfile(profile); |
| 132 | 135 |
| 136 min_picture_count_ = min_picture_count; |
| 137 |
| 133 if (acceleration != PP_HARDWAREACCELERATION_NONE) { | 138 if (acceleration != PP_HARDWAREACCELERATION_NONE) { |
| 134 // This is not synchronous, but subsequent IPC messages will be buffered, so | 139 // This is not synchronous, but subsequent IPC messages will be buffered, so |
| 135 // it is okay to immediately send IPC messages through the returned channel. | 140 // it is okay to immediately send IPC messages through the returned channel. |
| 136 GpuChannelHost* channel = graphics3d->channel(); | 141 GpuChannelHost* channel = graphics3d->channel(); |
| 137 DCHECK(channel); | 142 DCHECK(channel); |
| 138 decoder_ = channel->CreateVideoDecoder(command_buffer_route_id); | 143 decoder_ = channel->CreateVideoDecoder(command_buffer_route_id); |
| 139 if (decoder_ && decoder_->Initialize(media_profile, this)) { | 144 if (decoder_ && |
| 145 decoder_->Initialize(media_profile, this)) { |
| 140 initialized_ = true; | 146 initialized_ = true; |
| 141 return PP_OK; | 147 return PP_OK; |
| 142 } | 148 } |
| 143 decoder_.reset(); | 149 decoder_.reset(); |
| 144 if (acceleration == PP_HARDWAREACCELERATION_ONLY) | 150 if (acceleration == PP_HARDWAREACCELERATION_ONLY) |
| 145 return PP_ERROR_NOTSUPPORTED; | 151 return PP_ERROR_NOTSUPPORTED; |
| 146 } | 152 } |
| 147 | 153 |
| 148 #if defined(OS_ANDROID) | 154 #if defined(OS_ANDROID) |
| 149 return PP_ERROR_NOTSUPPORTED; | 155 return PP_ERROR_NOTSUPPORTED; |
| 150 #else | 156 #else |
| 151 decoder_.reset(new VideoDecoderShim(this)); | 157 uint32_t shim_texture_pool_size = media::limits::kMaxVideoFrames + 1; |
| 158 shim_texture_pool_size = std::max(shim_texture_pool_size, |
| 159 min_picture_count_); |
| 160 decoder_.reset(new VideoDecoderShim(this, shim_texture_pool_size)); |
| 152 initialize_reply_context_ = context->MakeReplyMessageContext(); | 161 initialize_reply_context_ = context->MakeReplyMessageContext(); |
| 153 decoder_->Initialize(media_profile, this); | 162 decoder_->Initialize(media_profile, this); |
| 154 | 163 |
| 155 return PP_OK_COMPLETIONPENDING; | 164 return PP_OK_COMPLETIONPENDING; |
| 156 #endif | 165 #endif |
| 157 } | 166 } |
| 158 | 167 |
| 159 int32_t PepperVideoDecoderHost::OnHostMsgGetShm( | 168 int32_t PepperVideoDecoderHost::OnHostMsgGetShm( |
| 160 ppapi::host::HostMessageContext* context, | 169 ppapi::host::HostMessageContext* context, |
| 161 uint32_t shm_id, | 170 uint32_t shm_id, |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 reset_reply_context_ = context->MakeReplyMessageContext(); | 321 reset_reply_context_ = context->MakeReplyMessageContext(); |
| 313 decoder_->Reset(); | 322 decoder_->Reset(); |
| 314 | 323 |
| 315 return PP_OK_COMPLETIONPENDING; | 324 return PP_OK_COMPLETIONPENDING; |
| 316 } | 325 } |
| 317 | 326 |
| 318 void PepperVideoDecoderHost::ProvidePictureBuffers( | 327 void PepperVideoDecoderHost::ProvidePictureBuffers( |
| 319 uint32 requested_num_of_buffers, | 328 uint32 requested_num_of_buffers, |
| 320 const gfx::Size& dimensions, | 329 const gfx::Size& dimensions, |
| 321 uint32 texture_target) { | 330 uint32 texture_target) { |
| 322 RequestTextures(requested_num_of_buffers, | 331 RequestTextures(std::max(min_picture_count_, requested_num_of_buffers), |
| 323 dimensions, | 332 dimensions, |
| 324 texture_target, | 333 texture_target, |
| 325 std::vector<gpu::Mailbox>()); | 334 std::vector<gpu::Mailbox>()); |
| 326 } | 335 } |
| 327 | 336 |
| 328 void PepperVideoDecoderHost::PictureReady(const media::Picture& picture) { | 337 void PepperVideoDecoderHost::PictureReady(const media::Picture& picture) { |
| 329 // Don't bother validating the visible rect, since the plugin process is less | 338 // Don't bother validating the visible rect, since the plugin process is less |
| 330 // trusted than the gpu process. | 339 // trusted than the gpu process. |
| 331 DCHECK(pictures_in_use_.find(picture.picture_buffer_id()) == | 340 DCHECK(pictures_in_use_.find(picture.picture_buffer_id()) == |
| 332 pictures_in_use_.end()); | 341 pictures_in_use_.end()); |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 425 host()->SendUnsolicitedReply( | 434 host()->SendUnsolicitedReply( |
| 426 pp_resource(), | 435 pp_resource(), |
| 427 PpapiPluginMsg_VideoDecoder_RequestTextures( | 436 PpapiPluginMsg_VideoDecoder_RequestTextures( |
| 428 requested_num_of_buffers, | 437 requested_num_of_buffers, |
| 429 PP_MakeSize(dimensions.width(), dimensions.height()), | 438 PP_MakeSize(dimensions.width(), dimensions.height()), |
| 430 texture_target, | 439 texture_target, |
| 431 mailboxes)); | 440 mailboxes)); |
| 432 } | 441 } |
| 433 | 442 |
| 434 } // namespace content | 443 } // namespace content |
| OLD | NEW |