Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1369)

Side by Side Diff: content/renderer/pepper/pepper_video_decoder_host.cc

Issue 1207043002: Introduce a client minimum picture pool size (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moved range checking min_picture_count from proxy to host code. Created 5 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
26 using ppapi::proxy::SerializedHandle; 29 using ppapi::proxy::SerializedHandle;
27 using ppapi::thunk::EnterResourceNoLock; 30 using ppapi::thunk::EnterResourceNoLock;
28 using ppapi::thunk::PPB_Graphics3D_API; 31 using ppapi::thunk::PPB_Graphics3D_API;
29 32
30 namespace content { 33 namespace content {
31 34
32 namespace { 35 namespace {
33 36
37 // The maximum number of pictures that the client can pass in for
38 // min_picture_count, just as a sanity check on the argument.
39 // This should match the constant of the same name in test_video_decoder.cc.
40 const uint32_t kMaximumPictureCount = 100;
bbudge 2015/08/19 18:47:06 I forgot that we had a place for constants like th
lpique 2015/08/19 19:42:17 Sure. I saw it when looking for a location to shar
41
34 media::VideoCodecProfile PepperToMediaVideoProfile(PP_VideoProfile profile) { 42 media::VideoCodecProfile PepperToMediaVideoProfile(PP_VideoProfile profile) {
35 switch (profile) { 43 switch (profile) {
36 case PP_VIDEOPROFILE_H264BASELINE: 44 case PP_VIDEOPROFILE_H264BASELINE:
37 return media::H264PROFILE_BASELINE; 45 return media::H264PROFILE_BASELINE;
38 case PP_VIDEOPROFILE_H264MAIN: 46 case PP_VIDEOPROFILE_H264MAIN:
39 return media::H264PROFILE_MAIN; 47 return media::H264PROFILE_MAIN;
40 case PP_VIDEOPROFILE_H264EXTENDED: 48 case PP_VIDEOPROFILE_H264EXTENDED:
41 return media::H264PROFILE_EXTENDED; 49 return media::H264PROFILE_EXTENDED;
42 case PP_VIDEOPROFILE_H264HIGH: 50 case PP_VIDEOPROFILE_H264HIGH:
43 return media::H264PROFILE_HIGH; 51 return media::H264PROFILE_HIGH;
(...skipping 30 matching lines...) Expand all
74 } 82 }
75 83
76 PepperVideoDecoderHost::PendingDecode::~PendingDecode() { 84 PepperVideoDecoderHost::PendingDecode::~PendingDecode() {
77 } 85 }
78 86
79 PepperVideoDecoderHost::PepperVideoDecoderHost(RendererPpapiHost* host, 87 PepperVideoDecoderHost::PepperVideoDecoderHost(RendererPpapiHost* host,
80 PP_Instance instance, 88 PP_Instance instance,
81 PP_Resource resource) 89 PP_Resource resource)
82 : ResourceHost(host->GetPpapiHost(), instance, resource), 90 : ResourceHost(host->GetPpapiHost(), instance, resource),
83 renderer_ppapi_host_(host), 91 renderer_ppapi_host_(host),
92 min_picture_count_(0),
84 initialized_(false) { 93 initialized_(false) {
85 } 94 }
86 95
87 PepperVideoDecoderHost::~PepperVideoDecoderHost() { 96 PepperVideoDecoderHost::~PepperVideoDecoderHost() {
88 } 97 }
89 98
90 int32_t PepperVideoDecoderHost::OnResourceMessageReceived( 99 int32_t PepperVideoDecoderHost::OnResourceMessageReceived(
91 const IPC::Message& msg, 100 const IPC::Message& msg,
92 ppapi::host::HostMessageContext* context) { 101 ppapi::host::HostMessageContext* context) {
93 PPAPI_BEGIN_MESSAGE_MAP(PepperVideoDecoderHost, msg) 102 PPAPI_BEGIN_MESSAGE_MAP(PepperVideoDecoderHost, msg)
(...skipping 12 matching lines...) Expand all
106 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_VideoDecoder_Reset, 115 PPAPI_DISPATCH_HOST_RESOURCE_CALL_0(PpapiHostMsg_VideoDecoder_Reset,
107 OnHostMsgReset) 116 OnHostMsgReset)
108 PPAPI_END_MESSAGE_MAP() 117 PPAPI_END_MESSAGE_MAP()
109 return PP_ERROR_FAILED; 118 return PP_ERROR_FAILED;
110 } 119 }
111 120
112 int32_t PepperVideoDecoderHost::OnHostMsgInitialize( 121 int32_t PepperVideoDecoderHost::OnHostMsgInitialize(
113 ppapi::host::HostMessageContext* context, 122 ppapi::host::HostMessageContext* context,
114 const ppapi::HostResource& graphics_context, 123 const ppapi::HostResource& graphics_context,
115 PP_VideoProfile profile, 124 PP_VideoProfile profile,
116 PP_HardwareAcceleration acceleration) { 125 PP_HardwareAcceleration acceleration,
126 uint32_t min_picture_count) {
117 if (initialized_) 127 if (initialized_)
118 return PP_ERROR_FAILED; 128 return PP_ERROR_FAILED;
129 if (min_picture_count > kMaximumPictureCount)
130 return PP_ERROR_BADARGUMENT;
119 131
120 EnterResourceNoLock<PPB_Graphics3D_API> enter_graphics( 132 EnterResourceNoLock<PPB_Graphics3D_API> enter_graphics(
121 graphics_context.host_resource(), true); 133 graphics_context.host_resource(), true);
122 if (enter_graphics.failed()) 134 if (enter_graphics.failed())
123 return PP_ERROR_FAILED; 135 return PP_ERROR_FAILED;
124 PPB_Graphics3D_Impl* graphics3d = 136 PPB_Graphics3D_Impl* graphics3d =
125 static_cast<PPB_Graphics3D_Impl*>(enter_graphics.object()); 137 static_cast<PPB_Graphics3D_Impl*>(enter_graphics.object());
126 138
127 CommandBufferProxyImpl* command_buffer = graphics3d->GetCommandBufferProxy(); 139 CommandBufferProxyImpl* command_buffer = graphics3d->GetCommandBufferProxy();
128 if (!command_buffer) 140 if (!command_buffer)
129 return PP_ERROR_FAILED; 141 return PP_ERROR_FAILED;
130 142
131 media::VideoCodecProfile media_profile = PepperToMediaVideoProfile(profile); 143 media::VideoCodecProfile media_profile = PepperToMediaVideoProfile(profile);
132 144
145 // Check for Dev API use
146 // TODO(lpique): remove check when PPB_VideoDecoder_1_1 reaches beta/stable.
147 // https://crbug.com/520323
148 if (min_picture_count != 0) {
149 ContentRendererClient* client = GetContentClient()->renderer();
150 bool allowed = client->IsPluginAllowedToUseDevChannelAPIs();
151 if (!allowed)
152 return PP_ERROR_NOTSUPPORTED;
153 }
154 min_picture_count_ = min_picture_count;
155
133 if (acceleration != PP_HARDWAREACCELERATION_NONE) { 156 if (acceleration != PP_HARDWAREACCELERATION_NONE) {
134 // This is not synchronous, but subsequent IPC messages will be buffered, so 157 // This is not synchronous, but subsequent IPC messages will be buffered, so
135 // it is okay to immediately send IPC messages. 158 // it is okay to immediately send IPC messages.
136 decoder_ = command_buffer->CreateVideoDecoder(); 159 decoder_ = command_buffer->CreateVideoDecoder();
137 if (decoder_ && decoder_->Initialize(media_profile, this)) { 160 if (decoder_ && decoder_->Initialize(media_profile, this)) {
138 initialized_ = true; 161 initialized_ = true;
139 return PP_OK; 162 return PP_OK;
140 } 163 }
141 decoder_.reset(); 164 decoder_.reset();
142 if (acceleration == PP_HARDWAREACCELERATION_ONLY) 165 if (acceleration == PP_HARDWAREACCELERATION_ONLY)
143 return PP_ERROR_NOTSUPPORTED; 166 return PP_ERROR_NOTSUPPORTED;
144 } 167 }
145 168
146 #if defined(OS_ANDROID) 169 #if defined(OS_ANDROID)
147 return PP_ERROR_NOTSUPPORTED; 170 return PP_ERROR_NOTSUPPORTED;
148 #else 171 #else
149 decoder_.reset(new VideoDecoderShim(this)); 172 uint32_t shim_texture_pool_size = media::limits::kMaxVideoFrames + 1;
173 shim_texture_pool_size = std::max(shim_texture_pool_size,
174 min_picture_count_);
175 decoder_.reset(new VideoDecoderShim(this, shim_texture_pool_size));
150 initialize_reply_context_ = context->MakeReplyMessageContext(); 176 initialize_reply_context_ = context->MakeReplyMessageContext();
151 decoder_->Initialize(media_profile, this); 177 decoder_->Initialize(media_profile, this);
152 178
153 return PP_OK_COMPLETIONPENDING; 179 return PP_OK_COMPLETIONPENDING;
154 #endif 180 #endif
155 } 181 }
156 182
157 int32_t PepperVideoDecoderHost::OnHostMsgGetShm( 183 int32_t PepperVideoDecoderHost::OnHostMsgGetShm(
158 ppapi::host::HostMessageContext* context, 184 ppapi::host::HostMessageContext* context,
159 uint32_t shm_id, 185 uint32_t shm_id,
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 reset_reply_context_ = context->MakeReplyMessageContext(); 336 reset_reply_context_ = context->MakeReplyMessageContext();
311 decoder_->Reset(); 337 decoder_->Reset();
312 338
313 return PP_OK_COMPLETIONPENDING; 339 return PP_OK_COMPLETIONPENDING;
314 } 340 }
315 341
316 void PepperVideoDecoderHost::ProvidePictureBuffers( 342 void PepperVideoDecoderHost::ProvidePictureBuffers(
317 uint32 requested_num_of_buffers, 343 uint32 requested_num_of_buffers,
318 const gfx::Size& dimensions, 344 const gfx::Size& dimensions,
319 uint32 texture_target) { 345 uint32 texture_target) {
320 RequestTextures(requested_num_of_buffers, 346 RequestTextures(std::max(min_picture_count_, requested_num_of_buffers),
321 dimensions, 347 dimensions,
322 texture_target, 348 texture_target,
323 std::vector<gpu::Mailbox>()); 349 std::vector<gpu::Mailbox>());
324 } 350 }
325 351
326 void PepperVideoDecoderHost::PictureReady(const media::Picture& picture) { 352 void PepperVideoDecoderHost::PictureReady(const media::Picture& picture) {
327 // Don't bother validating the visible rect, since the plugin process is less 353 // Don't bother validating the visible rect, since the plugin process is less
328 // trusted than the gpu process. 354 // trusted than the gpu process.
329 DCHECK(pictures_in_use_.find(picture.picture_buffer_id()) == 355 DCHECK(pictures_in_use_.find(picture.picture_buffer_id()) ==
330 pictures_in_use_.end()); 356 pictures_in_use_.end());
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 host()->SendUnsolicitedReply( 449 host()->SendUnsolicitedReply(
424 pp_resource(), 450 pp_resource(),
425 PpapiPluginMsg_VideoDecoder_RequestTextures( 451 PpapiPluginMsg_VideoDecoder_RequestTextures(
426 requested_num_of_buffers, 452 requested_num_of_buffers,
427 PP_MakeSize(dimensions.width(), dimensions.height()), 453 PP_MakeSize(dimensions.width(), dimensions.height()),
428 texture_target, 454 texture_target,
429 mailboxes)); 455 mailboxes));
430 } 456 }
431 457
432 } // namespace content 458 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/pepper/pepper_video_decoder_host.h ('k') | content/renderer/pepper/video_decoder_shim.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698