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

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

Issue 311853005: Implement software fallback for PPB_VideoDecoder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use WeakPtr to tie VideoDecoderProxy and Delegate. Created 6 years, 6 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 | Annotate | Revision Log
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/gpu_channel_host.h" 9 #include "content/common/gpu/client/gpu_channel_host.h"
10 #include "content/public/renderer/render_thread.h" 10 #include "content/public/renderer/render_thread.h"
11 #include "content/public/renderer/renderer_ppapi_host.h" 11 #include "content/public/renderer/renderer_ppapi_host.h"
12 #include "content/renderer/pepper/ppb_graphics_3d_impl.h" 12 #include "content/renderer/pepper/ppb_graphics_3d_impl.h"
13 #include "content/renderer/render_thread_impl.h"
14 #include "content/renderer/render_view_impl.h"
15 #include "media/video/picture.h"
16 #include "media/video/video_decode_accelerator.h" 13 #include "media/video/video_decode_accelerator.h"
17 #include "ppapi/c/pp_completion_callback.h" 14 #include "ppapi/c/pp_completion_callback.h"
18 #include "ppapi/c/pp_errors.h" 15 #include "ppapi/c/pp_errors.h"
19 #include "ppapi/host/dispatch_host_message.h" 16 #include "ppapi/host/dispatch_host_message.h"
20 #include "ppapi/host/ppapi_host.h" 17 #include "ppapi/host/ppapi_host.h"
21 #include "ppapi/proxy/ppapi_messages.h" 18 #include "ppapi/proxy/ppapi_messages.h"
22 #include "ppapi/proxy/video_decoder_constants.h" 19 #include "ppapi/proxy/video_decoder_constants.h"
23 #include "ppapi/thunk/enter.h" 20 #include "ppapi/thunk/enter.h"
24 #include "ppapi/thunk/ppb_graphics_3d_api.h" 21 #include "ppapi/thunk/ppb_graphics_3d_api.h"
25 22
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 const ppapi::HostResource& graphics_context, 109 const ppapi::HostResource& graphics_context,
113 PP_VideoProfile profile, 110 PP_VideoProfile profile,
114 bool allow_software_fallback) { 111 bool allow_software_fallback) {
115 if (initialized_) 112 if (initialized_)
116 return PP_ERROR_FAILED; 113 return PP_ERROR_FAILED;
117 114
118 EnterResourceNoLock<PPB_Graphics3D_API> enter_graphics( 115 EnterResourceNoLock<PPB_Graphics3D_API> enter_graphics(
119 graphics_context.host_resource(), true); 116 graphics_context.host_resource(), true);
120 if (enter_graphics.failed()) 117 if (enter_graphics.failed())
121 return PP_ERROR_FAILED; 118 return PP_ERROR_FAILED;
122 graphics3d_ = static_cast<PPB_Graphics3D_Impl*>(enter_graphics.object()); 119 PPB_Graphics3D_Impl* graphics3d =
120 static_cast<PPB_Graphics3D_Impl*>(enter_graphics.object());
123 121
124 int command_buffer_route_id = graphics3d_->GetCommandBufferRouteId(); 122 int command_buffer_route_id = graphics3d->GetCommandBufferRouteId();
125 if (!command_buffer_route_id) 123 if (!command_buffer_route_id)
126 return PP_ERROR_FAILED; 124 return PP_ERROR_FAILED;
127 125
128 media::VideoCodecProfile media_profile = PepperToMediaVideoProfile(profile); 126 media::VideoCodecProfile media_profile = PepperToMediaVideoProfile(profile);
129 127
130 // This is not synchronous, but subsequent IPC messages will be buffered, so 128 // This is not synchronous, but subsequent IPC messages will be buffered, so
131 // it is okay to immediately send IPC messages through the returned channel. 129 // it is okay to immediately send IPC messages through the returned channel.
132 GpuChannelHost* channel = graphics3d_->channel(); 130 GpuChannelHost* channel = graphics3d->channel();
133 DCHECK(channel); 131 DCHECK(channel);
134 decoder_ = channel->CreateVideoDecoder(command_buffer_route_id); 132 decoder_ = channel->CreateVideoDecoder(command_buffer_route_id);
135 if (decoder_ && decoder_->Initialize(media_profile, this)) { 133 if (decoder_ && decoder_->Initialize(media_profile, this)) {
136 initialized_ = true; 134 initialized_ = true;
137 return PP_OK; 135 return PP_OK;
138 } 136 }
139 decoder_.reset(); 137 decoder_.reset();
140 138
141 // TODO(bbudge) Implement software fallback. 139 if (!allow_software_fallback)
142 return PP_ERROR_NOTSUPPORTED; 140 return PP_ERROR_NOTSUPPORTED;
141
142 software_decoder_.reset(new VideoDecoderProxy(this));
143 initialize_reply_context_ = context->MakeReplyMessageContext();
144 software_decoder_->Initialize(media_profile);
145
146 return PP_OK_COMPLETIONPENDING;
143 } 147 }
144 148
145 int32_t PepperVideoDecoderHost::OnHostMsgGetShm( 149 int32_t PepperVideoDecoderHost::OnHostMsgGetShm(
146 ppapi::host::HostMessageContext* context, 150 ppapi::host::HostMessageContext* context,
147 uint32_t shm_id, 151 uint32_t shm_id,
148 uint32_t shm_size) { 152 uint32_t shm_size) {
149 if (!initialized_) 153 if (!initialized_)
150 return PP_ERROR_FAILED; 154 return PP_ERROR_FAILED;
151 155
152 // Make the buffers larger since we hope to reuse them. 156 // Make the buffers larger since we hope to reuse them.
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 return PP_OK_COMPLETIONPENDING; 205 return PP_OK_COMPLETIONPENDING;
202 } 206 }
203 207
204 int32_t PepperVideoDecoderHost::OnHostMsgDecode( 208 int32_t PepperVideoDecoderHost::OnHostMsgDecode(
205 ppapi::host::HostMessageContext* context, 209 ppapi::host::HostMessageContext* context,
206 uint32_t shm_id, 210 uint32_t shm_id,
207 uint32_t size, 211 uint32_t size,
208 int32_t decode_id) { 212 int32_t decode_id) {
209 if (!initialized_) 213 if (!initialized_)
210 return PP_ERROR_FAILED; 214 return PP_ERROR_FAILED;
211 DCHECK(decoder_); 215 DCHECK(decoder_ || software_decoder_);
212 // |shm_id| is just an index into shm_buffers_. Make sure it's in range. 216 // |shm_id| is just an index into shm_buffers_. Make sure it's in range.
213 if (static_cast<size_t>(shm_id) >= shm_buffers_.size()) 217 if (static_cast<size_t>(shm_id) >= shm_buffers_.size())
214 return PP_ERROR_FAILED; 218 return PP_ERROR_FAILED;
215 // Reject an attempt to pass a busy buffer to the decoder again. 219 // Reject an attempt to pass a busy buffer to the decoder again.
216 if (shm_buffer_busy_[shm_id]) 220 if (shm_buffer_busy_[shm_id])
217 return PP_ERROR_FAILED; 221 return PP_ERROR_FAILED;
218 // Reject non-unique decode_id values. 222 // Reject non-unique decode_id values.
219 if (pending_decodes_.find(decode_id) != pending_decodes_.end()) 223 if (pending_decodes_.find(decode_id) != pending_decodes_.end())
220 return PP_ERROR_FAILED; 224 return PP_ERROR_FAILED;
221 225
222 if (flush_reply_context_.is_valid() || reset_reply_context_.is_valid()) 226 if (flush_reply_context_.is_valid() || reset_reply_context_.is_valid())
223 return PP_ERROR_FAILED; 227 return PP_ERROR_FAILED;
224 228
225 pending_decodes_.insert(std::make_pair( 229 pending_decodes_.insert(std::make_pair(
226 decode_id, PendingDecode(shm_id, context->MakeReplyMessageContext()))); 230 decode_id, PendingDecode(shm_id, context->MakeReplyMessageContext())));
227 231
228 shm_buffer_busy_[shm_id] = true; 232 shm_buffer_busy_[shm_id] = true;
229 decoder_->Decode( 233 base::SharedMemory* shm = shm_buffers_[shm_id];
230 media::BitstreamBuffer(decode_id, shm_buffers_[shm_id]->handle(), size)); 234 if (decoder_) {
235 decoder_->Decode(media::BitstreamBuffer(decode_id, shm->handle(), size));
236 } else {
237 software_decoder_->Decode(
238 decode_id, static_cast<uint8_t*>(shm->memory()), size);
239 }
231 240
232 return PP_OK_COMPLETIONPENDING; 241 return PP_OK_COMPLETIONPENDING;
233 } 242 }
234 243
235 int32_t PepperVideoDecoderHost::OnHostMsgAssignTextures( 244 int32_t PepperVideoDecoderHost::OnHostMsgAssignTextures(
236 ppapi::host::HostMessageContext* context, 245 ppapi::host::HostMessageContext* context,
237 const PP_Size& size, 246 const PP_Size& size,
238 const std::vector<uint32_t>& texture_ids) { 247 const std::vector<uint32_t>& texture_ids) {
239 if (!initialized_) 248 if (!initialized_)
240 return PP_ERROR_FAILED; 249 return PP_ERROR_FAILED;
241 DCHECK(decoder_); 250 DCHECK(decoder_ || software_decoder_);
242 251
243 std::vector<media::PictureBuffer> picture_buffers; 252 if (decoder_) {
244 for (uint32 i = 0; i < texture_ids.size(); i++) { 253 std::vector<media::PictureBuffer> picture_buffers;
245 media::PictureBuffer buffer( 254 for (uint32 i = 0; i < texture_ids.size(); i++) {
246 texture_ids[i], // Use the texture_id to identify the buffer. 255 media::PictureBuffer buffer(
247 gfx::Size(size.width, size.height), 256 texture_ids[i], // Use the texture_id to identify the buffer.
248 texture_ids[i]); 257 gfx::Size(size.width, size.height),
249 picture_buffers.push_back(buffer); 258 texture_ids[i]);
259 picture_buffers.push_back(buffer);
260 }
261 decoder_->AssignPictureBuffers(picture_buffers);
262 } else {
263 software_decoder_->AssignTextures(texture_ids);
250 } 264 }
251 decoder_->AssignPictureBuffers(picture_buffers);
252 return PP_OK; 265 return PP_OK;
253 } 266 }
254 267
255 int32_t PepperVideoDecoderHost::OnHostMsgRecyclePicture( 268 int32_t PepperVideoDecoderHost::OnHostMsgRecyclePicture(
256 ppapi::host::HostMessageContext* context, 269 ppapi::host::HostMessageContext* context,
257 uint32_t texture_id) { 270 uint32_t texture_id) {
258 if (!initialized_) 271 if (!initialized_)
259 return PP_ERROR_FAILED; 272 return PP_ERROR_FAILED;
260 DCHECK(decoder_); 273 DCHECK(decoder_ || software_decoder_);
261 if (reset_reply_context_.is_valid()) 274 if (reset_reply_context_.is_valid())
262 return PP_ERROR_FAILED; 275 return PP_ERROR_FAILED;
263 276 if (decoder_) {
264 decoder_->ReusePictureBuffer(texture_id); 277 decoder_->ReusePictureBuffer(texture_id);
278 } else {
279 software_decoder_->RecycleTexture(texture_id);
280 }
265 281
266 return PP_OK; 282 return PP_OK;
267 } 283 }
268 284
269 int32_t PepperVideoDecoderHost::OnHostMsgFlush( 285 int32_t PepperVideoDecoderHost::OnHostMsgFlush(
270 ppapi::host::HostMessageContext* context) { 286 ppapi::host::HostMessageContext* context) {
271 if (!initialized_) 287 if (!initialized_)
272 return PP_ERROR_FAILED; 288 return PP_ERROR_FAILED;
273 DCHECK(decoder_); 289 DCHECK(decoder_ || software_decoder_);
274 if (flush_reply_context_.is_valid() || reset_reply_context_.is_valid()) 290 if (flush_reply_context_.is_valid() || reset_reply_context_.is_valid())
275 return PP_ERROR_FAILED; 291 return PP_ERROR_FAILED;
276 292
277 flush_reply_context_ = context->MakeReplyMessageContext(); 293 flush_reply_context_ = context->MakeReplyMessageContext();
278 decoder_->Flush(); 294 if (decoder_)
295 decoder_->Flush();
296 else
297 software_decoder_->Flush();
279 298
280 return PP_OK_COMPLETIONPENDING; 299 return PP_OK_COMPLETIONPENDING;
281 } 300 }
282 301
283 int32_t PepperVideoDecoderHost::OnHostMsgReset( 302 int32_t PepperVideoDecoderHost::OnHostMsgReset(
284 ppapi::host::HostMessageContext* context) { 303 ppapi::host::HostMessageContext* context) {
285 if (!initialized_) 304 if (!initialized_)
286 return PP_ERROR_FAILED; 305 return PP_ERROR_FAILED;
287 DCHECK(decoder_); 306 DCHECK(decoder_ || software_decoder_);
288 if (flush_reply_context_.is_valid() || reset_reply_context_.is_valid()) 307 if (flush_reply_context_.is_valid() || reset_reply_context_.is_valid())
289 return PP_ERROR_FAILED; 308 return PP_ERROR_FAILED;
290 309
291 reset_reply_context_ = context->MakeReplyMessageContext(); 310 reset_reply_context_ = context->MakeReplyMessageContext();
292 decoder_->Reset(); 311 if (decoder_)
312 decoder_->Reset();
313 else
314 software_decoder_->Reset();
293 315
294 return PP_OK_COMPLETIONPENDING; 316 return PP_OK_COMPLETIONPENDING;
295 } 317 }
296 318
297 void PepperVideoDecoderHost::ProvidePictureBuffers( 319 void PepperVideoDecoderHost::ProvidePictureBuffers(
298 uint32 requested_num_of_buffers, 320 uint32 requested_num_of_buffers,
299 const gfx::Size& dimensions, 321 const gfx::Size& dimensions,
300 uint32 texture_target) { 322 uint32 texture_target) {
301 DCHECK(RenderThreadImpl::current()); 323 RequestTextures(requested_num_of_buffers,
302 host()->SendUnsolicitedReply( 324 dimensions,
303 pp_resource(), 325 texture_target,
304 PpapiPluginMsg_VideoDecoder_RequestTextures( 326 std::vector<gpu::Mailbox>());
305 requested_num_of_buffers,
306 PP_MakeSize(dimensions.width(), dimensions.height()),
307 texture_target));
308 } 327 }
309 328
310 void PepperVideoDecoderHost::PictureReady(const media::Picture& picture) { 329 void PepperVideoDecoderHost::PictureReady(const media::Picture& picture) {
311 DCHECK(RenderThreadImpl::current());
312 host()->SendUnsolicitedReply( 330 host()->SendUnsolicitedReply(
313 pp_resource(), 331 pp_resource(),
314 PpapiPluginMsg_VideoDecoder_PictureReady(picture.bitstream_buffer_id(), 332 PpapiPluginMsg_VideoDecoder_PictureReady(picture.bitstream_buffer_id(),
315 picture.picture_buffer_id())); 333 picture.picture_buffer_id()));
316 } 334 }
317 335
318 void PepperVideoDecoderHost::DismissPictureBuffer(int32 picture_buffer_id) { 336 void PepperVideoDecoderHost::DismissPictureBuffer(int32 picture_buffer_id) {
319 DCHECK(RenderThreadImpl::current());
320 host()->SendUnsolicitedReply( 337 host()->SendUnsolicitedReply(
321 pp_resource(), 338 pp_resource(),
322 PpapiPluginMsg_VideoDecoder_DismissPicture(picture_buffer_id)); 339 PpapiPluginMsg_VideoDecoder_DismissPicture(picture_buffer_id));
323 } 340 }
324 341
342 void PepperVideoDecoderHost::NotifyEndOfBitstreamBuffer(
343 int32 bitstream_buffer_id) {
344 PendingDecodeMap::iterator it = pending_decodes_.find(bitstream_buffer_id);
345 if (it == pending_decodes_.end()) {
346 NOTREACHED();
347 return;
348 }
349 const PendingDecode& pending_decode = it->second;
350 host()->SendReply(
351 pending_decode.reply_context,
352 PpapiPluginMsg_VideoDecoder_DecodeReply(pending_decode.shm_id));
353 shm_buffer_busy_[pending_decode.shm_id] = false;
354 pending_decodes_.erase(it);
355 }
356
357 void PepperVideoDecoderHost::NotifyFlushDone() {
358 host()->SendReply(flush_reply_context_,
359 PpapiPluginMsg_VideoDecoder_FlushReply());
360 flush_reply_context_ = ppapi::host::ReplyMessageContext();
361 }
362
363 void PepperVideoDecoderHost::NotifyResetDone() {
364 host()->SendReply(reset_reply_context_,
365 PpapiPluginMsg_VideoDecoder_ResetReply());
366 reset_reply_context_ = ppapi::host::ReplyMessageContext();
367 }
368
325 void PepperVideoDecoderHost::NotifyError( 369 void PepperVideoDecoderHost::NotifyError(
326 media::VideoDecodeAccelerator::Error error) { 370 media::VideoDecodeAccelerator::Error error) {
327 DCHECK(RenderThreadImpl::current());
328 int32_t pp_error = PP_ERROR_FAILED; 371 int32_t pp_error = PP_ERROR_FAILED;
329 switch (error) { 372 switch (error) {
330 case media::VideoDecodeAccelerator::UNREADABLE_INPUT: 373 case media::VideoDecodeAccelerator::UNREADABLE_INPUT:
331 pp_error = PP_ERROR_MALFORMED_INPUT; 374 pp_error = PP_ERROR_MALFORMED_INPUT;
332 break; 375 break;
333 case media::VideoDecodeAccelerator::ILLEGAL_STATE: 376 case media::VideoDecodeAccelerator::ILLEGAL_STATE:
334 case media::VideoDecodeAccelerator::INVALID_ARGUMENT: 377 case media::VideoDecodeAccelerator::INVALID_ARGUMENT:
335 case media::VideoDecodeAccelerator::PLATFORM_FAILURE: 378 case media::VideoDecodeAccelerator::PLATFORM_FAILURE:
336 case media::VideoDecodeAccelerator::LARGEST_ERROR_ENUM: 379 case media::VideoDecodeAccelerator::LARGEST_ERROR_ENUM:
337 pp_error = PP_ERROR_RESOURCE_FAILED; 380 pp_error = PP_ERROR_RESOURCE_FAILED;
338 break; 381 break;
339 // No default case, to catch unhandled enum values. 382 // No default case, to catch unhandled enum values.
340 } 383 }
384 NotifyError(pp_error);
dmichael (off chromium) 2014/06/05 23:00:43 I don't think we should overload this method, espe
385 }
386
387 void PepperVideoDecoderHost::OnInitializeComplete(int32_t result) {
388 if (!initialized_) {
389 initialized_ = true;
390 initialize_reply_context_.params.set_result(result);
391 host()->SendReply(initialize_reply_context_,
392 PpapiPluginMsg_VideoDecoder_InitializeReply());
393 }
394 }
395
396 void PepperVideoDecoderHost::RequestTextures(
Ami GONE FROM CHROMIUM 2014/06/05 00:06:24 single call-site and single-statement impl; why no
bbudge 2014/06/06 02:03:44 This is also called by VideoDecoderProxy, which pr
397 uint32 requested_num_of_buffers,
398 const gfx::Size& dimensions,
399 uint32 texture_target,
400 const std::vector<gpu::Mailbox>& mailboxes) {
401 host()->SendUnsolicitedReply(
402 pp_resource(),
403 PpapiPluginMsg_VideoDecoder_RequestTextures(
404 requested_num_of_buffers,
405 PP_MakeSize(dimensions.width(), dimensions.height()),
406 texture_target,
407 mailboxes));
408 }
409
410 void PepperVideoDecoderHost::NotifyError(int32_t pp_error) {
341 host()->SendUnsolicitedReply( 411 host()->SendUnsolicitedReply(
342 pp_resource(), PpapiPluginMsg_VideoDecoder_NotifyError(pp_error)); 412 pp_resource(), PpapiPluginMsg_VideoDecoder_NotifyError(pp_error));
343 } 413 }
344 414
345 void PepperVideoDecoderHost::NotifyResetDone() {
346 DCHECK(RenderThreadImpl::current());
347 host()->SendReply(reset_reply_context_,
348 PpapiPluginMsg_VideoDecoder_ResetReply());
349 reset_reply_context_ = ppapi::host::ReplyMessageContext();
350 }
351
352 void PepperVideoDecoderHost::NotifyEndOfBitstreamBuffer(
353 int32 bitstream_buffer_id) {
354 DCHECK(RenderThreadImpl::current());
355 PendingDecodeMap::iterator it = pending_decodes_.find(bitstream_buffer_id);
356 if (it == pending_decodes_.end()) {
357 NOTREACHED();
358 return;
359 }
360 const PendingDecode& pending_decode = it->second;
361 host()->SendReply(
362 pending_decode.reply_context,
363 PpapiPluginMsg_VideoDecoder_DecodeReply(pending_decode.shm_id));
364 shm_buffer_busy_[pending_decode.shm_id] = false;
365 pending_decodes_.erase(it);
366 }
367
368 void PepperVideoDecoderHost::NotifyFlushDone() {
369 DCHECK(RenderThreadImpl::current());
370 host()->SendReply(flush_reply_context_,
371 PpapiPluginMsg_VideoDecoder_FlushReply());
372 flush_reply_context_ = ppapi::host::ReplyMessageContext();
373 }
374
375 } // namespace content 415 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698