OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "media/filters/gpu_video_decoder.h" | 5 #include "media/filters/gpu_video_decoder.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/callback_helpers.h" | 8 #include "base/callback_helpers.h" |
9 #include "base/cpu.h" | 9 #include "base/cpu.h" |
10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
(...skipping 414 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
425 } | 425 } |
426 const PictureBuffer& pb = it->second; | 426 const PictureBuffer& pb = it->second; |
427 | 427 |
428 // Update frame's timestamp. | 428 // Update frame's timestamp. |
429 base::TimeDelta timestamp; | 429 base::TimeDelta timestamp; |
430 gfx::Rect visible_rect; | 430 gfx::Rect visible_rect; |
431 gfx::Size natural_size; | 431 gfx::Size natural_size; |
432 GetBufferData(picture.bitstream_buffer_id(), ×tamp, &visible_rect, | 432 GetBufferData(picture.bitstream_buffer_id(), ×tamp, &visible_rect, |
433 &natural_size); | 433 &natural_size); |
434 DCHECK(decoder_texture_target_); | 434 DCHECK(decoder_texture_target_); |
435 | |
436 gpu::Mailbox mailbox = factories_->ProduceTextureToMailbox(pb.texture_id()); | |
piman
2013/04/11 22:57:58
The first time you produce (or when you consume),
danakj
2013/04/12 00:01:39
Oh okay. I had in my head that Gen and Produce are
| |
437 | |
435 scoped_refptr<VideoFrame> frame( | 438 scoped_refptr<VideoFrame> frame( |
436 VideoFrame::WrapNativeTexture( | 439 VideoFrame::WrapNativeTexture( |
437 pb.texture_id(), decoder_texture_target_, pb.size(), visible_rect, | 440 mailbox, decoder_texture_target_, |
441 pb.size(), visible_rect, | |
438 natural_size, timestamp, | 442 natural_size, timestamp, |
439 base::Bind(&Factories::ReadPixels, factories_, pb.texture_id(), | 443 base::Bind(&Factories::ReadPixels, factories_, pb.texture_id(), |
440 decoder_texture_target_, | 444 decoder_texture_target_, |
441 gfx::Size(visible_rect.width(), visible_rect.height())), | 445 gfx::Size(visible_rect.width(), visible_rect.height())), |
442 base::Bind(&GpuVideoDecoder::ReusePictureBuffer, this, | 446 base::Bind(&GpuVideoDecoder::ReusePictureBuffer, this, |
443 picture.picture_buffer_id()))); | 447 picture.picture_buffer_id(), |
448 mailbox))); | |
444 CHECK_GT(available_pictures_, 0); | 449 CHECK_GT(available_pictures_, 0); |
445 available_pictures_--; | 450 available_pictures_--; |
446 | 451 |
447 EnqueueFrameAndTriggerFrameDelivery(frame); | 452 EnqueueFrameAndTriggerFrameDelivery(frame); |
448 } | 453 } |
449 | 454 |
450 void GpuVideoDecoder::EnqueueFrameAndTriggerFrameDelivery( | 455 void GpuVideoDecoder::EnqueueFrameAndTriggerFrameDelivery( |
451 const scoped_refptr<VideoFrame>& frame) { | 456 const scoped_refptr<VideoFrame>& frame) { |
452 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); | 457 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); |
453 | 458 |
454 // During a pending vda->Reset(), we don't accumulate frames. Drop it on the | 459 // During a pending vda->Reset(), we don't accumulate frames. Drop it on the |
455 // floor and return. | 460 // floor and return. |
456 if (!pending_reset_cb_.is_null()) | 461 if (!pending_reset_cb_.is_null()) |
457 return; | 462 return; |
458 | 463 |
459 if (frame) | 464 if (frame) |
460 ready_video_frames_.push_back(frame); | 465 ready_video_frames_.push_back(frame); |
461 else | 466 else |
462 DCHECK(!ready_video_frames_.empty()); | 467 DCHECK(!ready_video_frames_.empty()); |
463 | 468 |
464 if (pending_read_cb_.is_null()) | 469 if (pending_read_cb_.is_null()) |
465 return; | 470 return; |
466 | 471 |
467 base::ResetAndReturn(&pending_read_cb_).Run(kOk, ready_video_frames_.front()); | 472 base::ResetAndReturn(&pending_read_cb_).Run(kOk, ready_video_frames_.front()); |
468 ready_video_frames_.pop_front(); | 473 ready_video_frames_.pop_front(); |
469 } | 474 } |
470 | 475 |
471 void GpuVideoDecoder::ReusePictureBuffer(int64 picture_buffer_id) { | 476 void GpuVideoDecoder::ReusePictureBuffer(int64 picture_buffer_id, |
477 gpu::Mailbox mailbox) { | |
472 if (!gvd_loop_proxy_->BelongsToCurrentThread()) { | 478 if (!gvd_loop_proxy_->BelongsToCurrentThread()) { |
473 gvd_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 479 gvd_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
474 &GpuVideoDecoder::ReusePictureBuffer, this, picture_buffer_id)); | 480 &GpuVideoDecoder::ReusePictureBuffer, |
481 this, | |
482 picture_buffer_id, | |
483 mailbox)); | |
475 return; | 484 return; |
476 } | 485 } |
477 CHECK_GE(available_pictures_, 0); | 486 CHECK_GE(available_pictures_, 0); |
478 available_pictures_++; | 487 available_pictures_++; |
479 | 488 |
480 if (!vda_.get()) | 489 if (!vda_.get()) |
481 return; | 490 return; |
491 | |
492 std::map<int32, PictureBuffer>::iterator it = | |
493 picture_buffers_in_decoder_.find(picture_buffer_id); | |
494 if (it == picture_buffers_in_decoder_.end()) { | |
495 NOTREACHED() << "Missing picture buffer: " << picture_buffer_id; | |
496 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); | |
497 return; | |
498 } | |
499 const PictureBuffer& pb = it->second; | |
500 factories_->ConsumeMailboxToTexture(mailbox, pb.texture_id()); | |
501 | |
482 vda_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 502 vda_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
483 &VideoDecodeAccelerator::ReusePictureBuffer, weak_vda_, | 503 &VideoDecodeAccelerator::ReusePictureBuffer, weak_vda_, |
484 picture_buffer_id)); | 504 picture_buffer_id)); |
485 } | 505 } |
486 | 506 |
487 GpuVideoDecoder::SHMBuffer* GpuVideoDecoder::GetSHM(size_t min_size) { | 507 GpuVideoDecoder::SHMBuffer* GpuVideoDecoder::GetSHM(size_t min_size) { |
488 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); | 508 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); |
489 if (available_shm_segments_.empty() || | 509 if (available_shm_segments_.empty() || |
490 available_shm_segments_.back()->size < min_size) { | 510 available_shm_segments_.back()->size < min_size) { |
491 size_t size_to_allocate = std::max(min_size, kSharedMemorySegmentBytes); | 511 size_t size_to_allocate = std::max(min_size, kSharedMemorySegmentBytes); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
613 | 633 |
614 error_occured_ = true; | 634 error_occured_ = true; |
615 | 635 |
616 if (!pending_read_cb_.is_null()) { | 636 if (!pending_read_cb_.is_null()) { |
617 base::ResetAndReturn(&pending_read_cb_).Run(kDecodeError, NULL); | 637 base::ResetAndReturn(&pending_read_cb_).Run(kDecodeError, NULL); |
618 return; | 638 return; |
619 } | 639 } |
620 } | 640 } |
621 | 641 |
622 } // namespace media | 642 } // namespace media |
OLD | NEW |