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; |
| 124 if (min_picture_count > ppapi::proxy::kMaximumPictureCount) |
| 125 return PP_ERROR_BADARGUMENT; |
119 | 126 |
120 EnterResourceNoLock<PPB_Graphics3D_API> enter_graphics( | 127 EnterResourceNoLock<PPB_Graphics3D_API> enter_graphics( |
121 graphics_context.host_resource(), true); | 128 graphics_context.host_resource(), true); |
122 if (enter_graphics.failed()) | 129 if (enter_graphics.failed()) |
123 return PP_ERROR_FAILED; | 130 return PP_ERROR_FAILED; |
124 PPB_Graphics3D_Impl* graphics3d = | 131 PPB_Graphics3D_Impl* graphics3d = |
125 static_cast<PPB_Graphics3D_Impl*>(enter_graphics.object()); | 132 static_cast<PPB_Graphics3D_Impl*>(enter_graphics.object()); |
126 | 133 |
127 CommandBufferProxyImpl* command_buffer = graphics3d->GetCommandBufferProxy(); | 134 CommandBufferProxyImpl* command_buffer = graphics3d->GetCommandBufferProxy(); |
128 if (!command_buffer) | 135 if (!command_buffer) |
129 return PP_ERROR_FAILED; | 136 return PP_ERROR_FAILED; |
130 | 137 |
131 media::VideoCodecProfile media_profile = PepperToMediaVideoProfile(profile); | 138 media::VideoCodecProfile media_profile = PepperToMediaVideoProfile(profile); |
132 | 139 |
| 140 // Check for Dev API use |
| 141 // TODO(lpique): remove check when PPB_VideoDecoder_1_1 reaches beta/stable. |
| 142 // https://crbug.com/520323 |
| 143 if (min_picture_count != 0) { |
| 144 ContentRendererClient* client = GetContentClient()->renderer(); |
| 145 bool allowed = client->IsPluginAllowedToUseDevChannelAPIs(); |
| 146 if (!allowed) |
| 147 return PP_ERROR_NOTSUPPORTED; |
| 148 } |
| 149 min_picture_count_ = min_picture_count; |
| 150 |
133 if (acceleration != PP_HARDWAREACCELERATION_NONE) { | 151 if (acceleration != PP_HARDWAREACCELERATION_NONE) { |
134 // This is not synchronous, but subsequent IPC messages will be buffered, so | 152 // This is not synchronous, but subsequent IPC messages will be buffered, so |
135 // it is okay to immediately send IPC messages. | 153 // it is okay to immediately send IPC messages. |
136 decoder_ = command_buffer->CreateVideoDecoder(); | 154 decoder_ = command_buffer->CreateVideoDecoder(); |
137 if (decoder_ && decoder_->Initialize(media_profile, this)) { | 155 if (decoder_ && decoder_->Initialize(media_profile, this)) { |
138 initialized_ = true; | 156 initialized_ = true; |
139 return PP_OK; | 157 return PP_OK; |
140 } | 158 } |
141 decoder_.reset(); | 159 decoder_.reset(); |
142 if (acceleration == PP_HARDWAREACCELERATION_ONLY) | 160 if (acceleration == PP_HARDWAREACCELERATION_ONLY) |
143 return PP_ERROR_NOTSUPPORTED; | 161 return PP_ERROR_NOTSUPPORTED; |
144 } | 162 } |
145 | 163 |
146 #if defined(OS_ANDROID) | 164 #if defined(OS_ANDROID) |
147 return PP_ERROR_NOTSUPPORTED; | 165 return PP_ERROR_NOTSUPPORTED; |
148 #else | 166 #else |
149 decoder_.reset(new VideoDecoderShim(this)); | 167 uint32_t shim_texture_pool_size = media::limits::kMaxVideoFrames + 1; |
| 168 shim_texture_pool_size = std::max(shim_texture_pool_size, |
| 169 min_picture_count_); |
| 170 decoder_.reset(new VideoDecoderShim(this, shim_texture_pool_size)); |
150 initialize_reply_context_ = context->MakeReplyMessageContext(); | 171 initialize_reply_context_ = context->MakeReplyMessageContext(); |
151 decoder_->Initialize(media_profile, this); | 172 decoder_->Initialize(media_profile, this); |
152 | 173 |
153 return PP_OK_COMPLETIONPENDING; | 174 return PP_OK_COMPLETIONPENDING; |
154 #endif | 175 #endif |
155 } | 176 } |
156 | 177 |
157 int32_t PepperVideoDecoderHost::OnHostMsgGetShm( | 178 int32_t PepperVideoDecoderHost::OnHostMsgGetShm( |
158 ppapi::host::HostMessageContext* context, | 179 ppapi::host::HostMessageContext* context, |
159 uint32_t shm_id, | 180 uint32_t shm_id, |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 reset_reply_context_ = context->MakeReplyMessageContext(); | 331 reset_reply_context_ = context->MakeReplyMessageContext(); |
311 decoder_->Reset(); | 332 decoder_->Reset(); |
312 | 333 |
313 return PP_OK_COMPLETIONPENDING; | 334 return PP_OK_COMPLETIONPENDING; |
314 } | 335 } |
315 | 336 |
316 void PepperVideoDecoderHost::ProvidePictureBuffers( | 337 void PepperVideoDecoderHost::ProvidePictureBuffers( |
317 uint32 requested_num_of_buffers, | 338 uint32 requested_num_of_buffers, |
318 const gfx::Size& dimensions, | 339 const gfx::Size& dimensions, |
319 uint32 texture_target) { | 340 uint32 texture_target) { |
320 RequestTextures(requested_num_of_buffers, | 341 RequestTextures(std::max(min_picture_count_, requested_num_of_buffers), |
321 dimensions, | 342 dimensions, |
322 texture_target, | 343 texture_target, |
323 std::vector<gpu::Mailbox>()); | 344 std::vector<gpu::Mailbox>()); |
324 } | 345 } |
325 | 346 |
326 void PepperVideoDecoderHost::PictureReady(const media::Picture& picture) { | 347 void PepperVideoDecoderHost::PictureReady(const media::Picture& picture) { |
327 // Don't bother validating the visible rect, since the plugin process is less | 348 // Don't bother validating the visible rect, since the plugin process is less |
328 // trusted than the gpu process. | 349 // trusted than the gpu process. |
329 DCHECK(pictures_in_use_.find(picture.picture_buffer_id()) == | 350 DCHECK(pictures_in_use_.find(picture.picture_buffer_id()) == |
330 pictures_in_use_.end()); | 351 pictures_in_use_.end()); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
423 host()->SendUnsolicitedReply( | 444 host()->SendUnsolicitedReply( |
424 pp_resource(), | 445 pp_resource(), |
425 PpapiPluginMsg_VideoDecoder_RequestTextures( | 446 PpapiPluginMsg_VideoDecoder_RequestTextures( |
426 requested_num_of_buffers, | 447 requested_num_of_buffers, |
427 PP_MakeSize(dimensions.width(), dimensions.height()), | 448 PP_MakeSize(dimensions.width(), dimensions.height()), |
428 texture_target, | 449 texture_target, |
429 mailboxes)); | 450 mailboxes)); |
430 } | 451 } |
431 | 452 |
432 } // namespace content | 453 } // namespace content |
OLD | NEW |