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/command_buffer_proxy_impl.h" | 9 #include "content/common/gpu/client/command_buffer_proxy_impl.h" |
10 #include "content/common/pepper_file_util.h" | 10 #include "content/common/pepper_file_util.h" |
| 11 #include "content/public/common/content_client.h" |
| 12 #include "content/public/renderer/content_renderer_client.h" |
11 #include "content/public/renderer/render_thread.h" | 13 #include "content/public/renderer/render_thread.h" |
12 #include "content/public/renderer/renderer_ppapi_host.h" | 14 #include "content/public/renderer/renderer_ppapi_host.h" |
13 #include "content/renderer/pepper/gfx_conversion.h" | 15 #include "content/renderer/pepper/gfx_conversion.h" |
14 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" | 16 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" |
15 #include "content/renderer/pepper/video_decoder_shim.h" | 17 #include "content/renderer/pepper/video_decoder_shim.h" |
| 18 #include "media/base/limits.h" |
16 #include "media/video/video_decode_accelerator.h" | 19 #include "media/video/video_decode_accelerator.h" |
17 #include "ppapi/c/pp_completion_callback.h" | 20 #include "ppapi/c/pp_completion_callback.h" |
18 #include "ppapi/c/pp_errors.h" | 21 #include "ppapi/c/pp_errors.h" |
19 #include "ppapi/host/dispatch_host_message.h" | 22 #include "ppapi/host/dispatch_host_message.h" |
20 #include "ppapi/host/ppapi_host.h" | 23 #include "ppapi/host/ppapi_host.h" |
21 #include "ppapi/proxy/ppapi_messages.h" | 24 #include "ppapi/proxy/ppapi_messages.h" |
22 #include "ppapi/proxy/video_decoder_constants.h" | 25 #include "ppapi/proxy/video_decoder_constants.h" |
23 #include "ppapi/thunk/enter.h" | 26 #include "ppapi/thunk/enter.h" |
24 #include "ppapi/thunk/ppb_graphics_3d_api.h" | 27 #include "ppapi/thunk/ppb_graphics_3d_api.h" |
25 | 28 |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } | 77 } |
75 | 78 |
76 PepperVideoDecoderHost::PendingDecode::~PendingDecode() { | 79 PepperVideoDecoderHost::PendingDecode::~PendingDecode() { |
77 } | 80 } |
78 | 81 |
79 PepperVideoDecoderHost::PepperVideoDecoderHost(RendererPpapiHost* host, | 82 PepperVideoDecoderHost::PepperVideoDecoderHost(RendererPpapiHost* host, |
80 PP_Instance instance, | 83 PP_Instance instance, |
81 PP_Resource resource) | 84 PP_Resource resource) |
82 : ResourceHost(host->GetPpapiHost(), instance, resource), | 85 : ResourceHost(host->GetPpapiHost(), instance, resource), |
83 renderer_ppapi_host_(host), | 86 renderer_ppapi_host_(host), |
| 87 min_picture_count_(0), |
84 initialized_(false) { | 88 initialized_(false) { |
85 } | 89 } |
86 | 90 |
87 PepperVideoDecoderHost::~PepperVideoDecoderHost() { | 91 PepperVideoDecoderHost::~PepperVideoDecoderHost() { |
88 } | 92 } |
89 | 93 |
90 int32_t PepperVideoDecoderHost::OnResourceMessageReceived( | 94 int32_t PepperVideoDecoderHost::OnResourceMessageReceived( |
91 const IPC::Message& msg, | 95 const IPC::Message& msg, |
92 ppapi::host::HostMessageContext* context) { | 96 ppapi::host::HostMessageContext* context) { |
93 PPAPI_BEGIN_MESSAGE_MAP(PepperVideoDecoderHost, msg) | 97 PPAPI_BEGIN_MESSAGE_MAP(PepperVideoDecoderHost, msg) |
(...skipping 12 matching lines...) Expand all Loading... |
106 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_VideoDecoder_Reset, | 110 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_VideoDecoder_Reset, |
107 OnHostMsgReset) | 111 OnHostMsgReset) |
108 PPAPI_END_MESSAGE_MAP() | 112 PPAPI_END_MESSAGE_MAP() |
109 return PP_ERROR_FAILED; | 113 return PP_ERROR_FAILED; |
110 } | 114 } |
111 | 115 |
112 int32_t PepperVideoDecoderHost::OnHostMsgInitialize( | 116 int32_t PepperVideoDecoderHost::OnHostMsgInitialize( |
113 ppapi::host::HostMessageContext* context, | 117 ppapi::host::HostMessageContext* context, |
114 const ppapi::HostResource& graphics_context, | 118 const ppapi::HostResource& graphics_context, |
115 PP_VideoProfile profile, | 119 PP_VideoProfile profile, |
116 PP_HardwareAcceleration acceleration) { | 120 PP_HardwareAcceleration acceleration, |
| 121 uint32_t min_picture_count) { |
117 if (initialized_) | 122 if (initialized_) |
118 return PP_ERROR_FAILED; | 123 return PP_ERROR_FAILED; |
119 | 124 |
120 EnterResourceNoLock<PPB_Graphics3D_API> enter_graphics( | 125 EnterResourceNoLock<PPB_Graphics3D_API> enter_graphics( |
121 graphics_context.host_resource(), true); | 126 graphics_context.host_resource(), true); |
122 if (enter_graphics.failed()) | 127 if (enter_graphics.failed()) |
123 return PP_ERROR_FAILED; | 128 return PP_ERROR_FAILED; |
124 PPB_Graphics3D_Impl* graphics3d = | 129 PPB_Graphics3D_Impl* graphics3d = |
125 static_cast<PPB_Graphics3D_Impl*>(enter_graphics.object()); | 130 static_cast<PPB_Graphics3D_Impl*>(enter_graphics.object()); |
126 | 131 |
127 CommandBufferProxyImpl* command_buffer = graphics3d->GetCommandBufferProxy(); | 132 CommandBufferProxyImpl* command_buffer = graphics3d->GetCommandBufferProxy(); |
128 if (!command_buffer) | 133 if (!command_buffer) |
129 return PP_ERROR_FAILED; | 134 return PP_ERROR_FAILED; |
130 | 135 |
131 media::VideoCodecProfile media_profile = PepperToMediaVideoProfile(profile); | 136 media::VideoCodecProfile media_profile = PepperToMediaVideoProfile(profile); |
132 | 137 |
| 138 // Check for Dev API use |
| 139 // TODO(lpique): remove check when PPB_VideoDecoder_1_1 reaches beta/stable. |
| 140 // https://crbug.com/520323 |
| 141 if (min_picture_count != 0) { |
| 142 ContentRendererClient* client = GetContentClient()->renderer(); |
| 143 bool allowed = client->IsPluginAllowedToUseDevChannelAPIs(); |
| 144 if (!allowed) |
| 145 return PP_ERROR_NOTSUPPORTED; |
| 146 } |
| 147 min_picture_count_ = min_picture_count; |
| 148 |
133 if (acceleration != PP_HARDWAREACCELERATION_NONE) { | 149 if (acceleration != PP_HARDWAREACCELERATION_NONE) { |
134 // This is not synchronous, but subsequent IPC messages will be buffered, so | 150 // This is not synchronous, but subsequent IPC messages will be buffered, so |
135 // it is okay to immediately send IPC messages. | 151 // it is okay to immediately send IPC messages. |
136 decoder_ = command_buffer->CreateVideoDecoder(); | 152 decoder_ = command_buffer->CreateVideoDecoder(); |
137 if (decoder_ && decoder_->Initialize(media_profile, this)) { | 153 if (decoder_ && decoder_->Initialize(media_profile, this)) { |
138 initialized_ = true; | 154 initialized_ = true; |
139 return PP_OK; | 155 return PP_OK; |
140 } | 156 } |
141 decoder_.reset(); | 157 decoder_.reset(); |
142 if (acceleration == PP_HARDWAREACCELERATION_ONLY) | 158 if (acceleration == PP_HARDWAREACCELERATION_ONLY) |
143 return PP_ERROR_NOTSUPPORTED; | 159 return PP_ERROR_NOTSUPPORTED; |
144 } | 160 } |
145 | 161 |
146 #if defined(OS_ANDROID) | 162 #if defined(OS_ANDROID) |
147 return PP_ERROR_NOTSUPPORTED; | 163 return PP_ERROR_NOTSUPPORTED; |
148 #else | 164 #else |
149 decoder_.reset(new VideoDecoderShim(this)); | 165 uint32_t shim_texture_pool_size = media::limits::kMaxVideoFrames + 1; |
| 166 shim_texture_pool_size = std::max(shim_texture_pool_size, |
| 167 min_picture_count_); |
| 168 decoder_.reset(new VideoDecoderShim(this, shim_texture_pool_size)); |
150 initialize_reply_context_ = context->MakeReplyMessageContext(); | 169 initialize_reply_context_ = context->MakeReplyMessageContext(); |
151 decoder_->Initialize(media_profile, this); | 170 decoder_->Initialize(media_profile, this); |
152 | 171 |
153 return PP_OK_COMPLETIONPENDING; | 172 return PP_OK_COMPLETIONPENDING; |
154 #endif | 173 #endif |
155 } | 174 } |
156 | 175 |
157 int32_t PepperVideoDecoderHost::OnHostMsgGetShm( | 176 int32_t PepperVideoDecoderHost::OnHostMsgGetShm( |
158 ppapi::host::HostMessageContext* context, | 177 ppapi::host::HostMessageContext* context, |
159 uint32_t shm_id, | 178 uint32_t shm_id, |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 reset_reply_context_ = context->MakeReplyMessageContext(); | 329 reset_reply_context_ = context->MakeReplyMessageContext(); |
311 decoder_->Reset(); | 330 decoder_->Reset(); |
312 | 331 |
313 return PP_OK_COMPLETIONPENDING; | 332 return PP_OK_COMPLETIONPENDING; |
314 } | 333 } |
315 | 334 |
316 void PepperVideoDecoderHost::ProvidePictureBuffers( | 335 void PepperVideoDecoderHost::ProvidePictureBuffers( |
317 uint32 requested_num_of_buffers, | 336 uint32 requested_num_of_buffers, |
318 const gfx::Size& dimensions, | 337 const gfx::Size& dimensions, |
319 uint32 texture_target) { | 338 uint32 texture_target) { |
320 RequestTextures(requested_num_of_buffers, | 339 RequestTextures(std::max(min_picture_count_, requested_num_of_buffers), |
321 dimensions, | 340 dimensions, |
322 texture_target, | 341 texture_target, |
323 std::vector<gpu::Mailbox>()); | 342 std::vector<gpu::Mailbox>()); |
324 } | 343 } |
325 | 344 |
326 void PepperVideoDecoderHost::PictureReady(const media::Picture& picture) { | 345 void PepperVideoDecoderHost::PictureReady(const media::Picture& picture) { |
327 // Don't bother validating the visible rect, since the plugin process is less | 346 // Don't bother validating the visible rect, since the plugin process is less |
328 // trusted than the gpu process. | 347 // trusted than the gpu process. |
329 DCHECK(pictures_in_use_.find(picture.picture_buffer_id()) == | 348 DCHECK(pictures_in_use_.find(picture.picture_buffer_id()) == |
330 pictures_in_use_.end()); | 349 pictures_in_use_.end()); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 host()->SendUnsolicitedReply( | 442 host()->SendUnsolicitedReply( |
424 pp_resource(), | 443 pp_resource(), |
425 PpapiPluginMsg_VideoDecoder_RequestTextures( | 444 PpapiPluginMsg_VideoDecoder_RequestTextures( |
426 requested_num_of_buffers, | 445 requested_num_of_buffers, |
427 PP_MakeSize(dimensions.width(), dimensions.height()), | 446 PP_MakeSize(dimensions.width(), dimensions.height()), |
428 texture_target, | 447 texture_target, |
429 mailboxes)); | 448 mailboxes)); |
430 } | 449 } |
431 | 450 |
432 } // namespace content | 451 } // namespace content |
OLD | NEW |