| 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 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 488 void GpuVideoDecoder::NotifyInitializeDone() { | 488 void GpuVideoDecoder::NotifyInitializeDone() { |
| 489 NOTREACHED() << "GpuVideoDecodeAcceleratorHost::Initialize is synchronous!"; | 489 NOTREACHED() << "GpuVideoDecodeAcceleratorHost::Initialize is synchronous!"; |
| 490 } | 490 } |
| 491 | 491 |
| 492 void GpuVideoDecoder::ProvidePictureBuffers(uint32 count, | 492 void GpuVideoDecoder::ProvidePictureBuffers(uint32 count, |
| 493 const gfx::Size& size, | 493 const gfx::Size& size, |
| 494 uint32 texture_target) { | 494 uint32 texture_target) { |
| 495 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); | 495 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); |
| 496 | 496 |
| 497 std::vector<uint32> texture_ids; | 497 std::vector<uint32> texture_ids; |
| 498 std::vector<gpu::Mailbox> texture_mailboxes; |
| 498 decoder_texture_target_ = texture_target; | 499 decoder_texture_target_ = texture_target; |
| 499 if (!factories_->CreateTextures( | 500 if (!factories_->CreateTextures(count, |
| 500 count, size, &texture_ids, decoder_texture_target_)) { | 501 size, |
| 502 &texture_ids, |
| 503 &texture_mailboxes, |
| 504 decoder_texture_target_)) { |
| 501 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); | 505 NotifyError(VideoDecodeAccelerator::PLATFORM_FAILURE); |
| 502 return; | 506 return; |
| 503 } | 507 } |
| 504 DCHECK_EQ(count, texture_ids.size()); | 508 DCHECK_EQ(count, texture_ids.size()); |
| 505 | 509 |
| 506 if (!vda_) | 510 if (!vda_) |
| 507 return; | 511 return; |
| 508 | 512 |
| 509 std::vector<PictureBuffer> picture_buffers; | 513 std::vector<PictureBuffer> picture_buffers; |
| 510 for (size_t i = 0; i < texture_ids.size(); ++i) { | 514 for (size_t i = 0; i < texture_ids.size(); ++i) { |
| 511 picture_buffers.push_back(PictureBuffer( | 515 picture_buffers.push_back(PictureBuffer( |
| 512 next_picture_buffer_id_++, size, texture_ids[i])); | 516 next_picture_buffer_id_++, size, texture_ids[i], texture_mailboxes[i])); |
| 513 bool inserted = assigned_picture_buffers_.insert(std::make_pair( | 517 bool inserted = assigned_picture_buffers_.insert(std::make_pair( |
| 514 picture_buffers.back().id(), picture_buffers.back())).second; | 518 picture_buffers.back().id(), picture_buffers.back())).second; |
| 515 DCHECK(inserted); | 519 DCHECK(inserted); |
| 516 } | 520 } |
| 517 | 521 |
| 518 available_pictures_ += count; | 522 available_pictures_ += count; |
| 519 | 523 |
| 520 vda_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 524 vda_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
| 521 &VideoDecodeAccelerator::AssignPictureBuffers, weak_vda_, | 525 &VideoDecodeAccelerator::AssignPictureBuffers, weak_vda_, |
| 522 picture_buffers)); | 526 picture_buffers)); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 563 } | 567 } |
| 564 const PictureBuffer& pb = it->second; | 568 const PictureBuffer& pb = it->second; |
| 565 | 569 |
| 566 // Update frame's timestamp. | 570 // Update frame's timestamp. |
| 567 base::TimeDelta timestamp; | 571 base::TimeDelta timestamp; |
| 568 gfx::Rect visible_rect; | 572 gfx::Rect visible_rect; |
| 569 gfx::Size natural_size; | 573 gfx::Size natural_size; |
| 570 GetBufferData(picture.bitstream_buffer_id(), ×tamp, &visible_rect, | 574 GetBufferData(picture.bitstream_buffer_id(), ×tamp, &visible_rect, |
| 571 &natural_size); | 575 &natural_size); |
| 572 DCHECK(decoder_texture_target_); | 576 DCHECK(decoder_texture_target_); |
| 577 |
| 578 uint32 sync_point = factories_->ProduceTextureToMailbox( |
| 579 pb.texture_mailbox(), |
| 580 pb.texture_id(), |
| 581 decoder_texture_target_); |
| 582 |
| 573 scoped_refptr<VideoFrame> frame( | 583 scoped_refptr<VideoFrame> frame( |
| 574 VideoFrame::WrapNativeTexture( | 584 VideoFrame::WrapNativeTexture( |
| 575 pb.texture_id(), decoder_texture_target_, pb.size(), visible_rect, | 585 pb.texture_mailbox(), sync_point, |
| 586 decoder_texture_target_, |
| 587 pb.size(), visible_rect, |
| 576 natural_size, timestamp, | 588 natural_size, timestamp, |
| 577 base::Bind(&Factories::ReadPixels, factories_, pb.texture_id(), | 589 base::Bind(&Factories::ReadPixels, factories_, pb.texture_id(), |
| 578 decoder_texture_target_, | 590 decoder_texture_target_, |
| 579 gfx::Size(visible_rect.width(), visible_rect.height())), | 591 gfx::Size(visible_rect.width(), visible_rect.height())), |
| 580 BindToCurrentLoop(base::Bind( | 592 BindToCurrentLoop(base::Bind( |
| 581 &GpuVideoDecoder::ReusePictureBuffer, weak_this_, | 593 &GpuVideoDecoder::ReusePictureBuffer, weak_this_, |
| 582 picture.picture_buffer_id())))); | 594 picture.picture_buffer_id())), |
| 595 base::Closure())); |
| 583 CHECK_GT(available_pictures_, 0); | 596 CHECK_GT(available_pictures_, 0); |
| 584 --available_pictures_; | 597 --available_pictures_; |
| 585 bool inserted = | 598 bool inserted = |
| 586 picture_buffers_at_display_.insert(picture.picture_buffer_id()).second; | 599 picture_buffers_at_display_.insert(picture.picture_buffer_id()).second; |
| 587 DCHECK(inserted); | 600 DCHECK(inserted); |
| 588 | 601 |
| 589 EnqueueFrameAndTriggerFrameDelivery(frame); | 602 EnqueueFrameAndTriggerFrameDelivery(frame); |
| 590 } | 603 } |
| 591 | 604 |
| 592 void GpuVideoDecoder::EnqueueFrameAndTriggerFrameDelivery( | 605 void GpuVideoDecoder::EnqueueFrameAndTriggerFrameDelivery( |
| (...skipping 10 matching lines...) Expand all Loading... |
| 603 else | 616 else |
| 604 DCHECK(!ready_video_frames_.empty()); | 617 DCHECK(!ready_video_frames_.empty()); |
| 605 | 618 |
| 606 if (pending_read_cb_.is_null()) | 619 if (pending_read_cb_.is_null()) |
| 607 return; | 620 return; |
| 608 | 621 |
| 609 base::ResetAndReturn(&pending_read_cb_).Run(kOk, ready_video_frames_.front()); | 622 base::ResetAndReturn(&pending_read_cb_).Run(kOk, ready_video_frames_.front()); |
| 610 ready_video_frames_.pop_front(); | 623 ready_video_frames_.pop_front(); |
| 611 } | 624 } |
| 612 | 625 |
| 613 void GpuVideoDecoder::ReusePictureBuffer(int64 picture_buffer_id) { | 626 void GpuVideoDecoder::ReusePictureBuffer(int64 picture_buffer_id, |
| 627 uint32 sync_point) { |
| 614 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); | 628 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); |
| 615 | 629 |
| 616 if (!vda_) | 630 if (!vda_) |
| 617 return; | 631 return; |
| 618 | 632 |
| 619 CHECK(!picture_buffers_at_display_.empty()); | 633 CHECK(!picture_buffers_at_display_.empty()); |
| 620 | 634 |
| 621 size_t num_erased = picture_buffers_at_display_.erase(picture_buffer_id); | 635 size_t num_erased = picture_buffers_at_display_.erase(picture_buffer_id); |
| 622 DCHECK(num_erased); | 636 DCHECK(num_erased); |
| 623 | 637 |
| 624 std::map<int32, PictureBuffer>::iterator it = | 638 std::map<int32, PictureBuffer>::iterator it = |
| 625 assigned_picture_buffers_.find(picture_buffer_id); | 639 assigned_picture_buffers_.find(picture_buffer_id); |
| 626 | 640 |
| 627 if (it == assigned_picture_buffers_.end()) { | 641 if (it == assigned_picture_buffers_.end()) { |
| 628 // This picture was dismissed while in display, so we postponed deletion. | 642 // This picture was dismissed while in display, so we postponed deletion. |
| 629 it = dismissed_picture_buffers_.find(picture_buffer_id); | 643 it = dismissed_picture_buffers_.find(picture_buffer_id); |
| 630 DCHECK(it != dismissed_picture_buffers_.end()); | 644 DCHECK(it != dismissed_picture_buffers_.end()); |
| 631 factories_->DeleteTexture(it->second.texture_id()); | 645 factories_->DeleteTexture(it->second.texture_id()); |
| 632 dismissed_picture_buffers_.erase(it); | 646 dismissed_picture_buffers_.erase(it); |
| 633 return; | 647 return; |
| 634 } | 648 } |
| 635 | 649 |
| 650 const PictureBuffer& pb = it->second; |
| 651 factories_->ConsumeMailboxToTexture(pb.texture_mailbox(), |
| 652 pb.texture_id(), |
| 653 decoder_texture_target_, |
| 654 sync_point); |
| 655 |
| 636 ++available_pictures_; | 656 ++available_pictures_; |
| 637 | 657 |
| 658 |
| 638 vda_loop_proxy_->PostTask(FROM_HERE, base::Bind( | 659 vda_loop_proxy_->PostTask(FROM_HERE, base::Bind( |
| 639 &VideoDecodeAccelerator::ReusePictureBuffer, weak_vda_, | 660 &VideoDecodeAccelerator::ReusePictureBuffer, weak_vda_, |
| 640 picture_buffer_id)); | 661 picture_buffer_id)); |
| 641 } | 662 } |
| 642 | 663 |
| 643 GpuVideoDecoder::SHMBuffer* GpuVideoDecoder::GetSHM(size_t min_size) { | 664 GpuVideoDecoder::SHMBuffer* GpuVideoDecoder::GetSHM(size_t min_size) { |
| 644 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); | 665 DCHECK(gvd_loop_proxy_->BelongsToCurrentThread()); |
| 645 if (available_shm_segments_.empty() || | 666 if (available_shm_segments_.empty() || |
| 646 available_shm_segments_.back()->size < min_size) { | 667 available_shm_segments_.back()->size < min_size) { |
| 647 size_t size_to_allocate = std::max(min_size, kSharedMemorySegmentBytes); | 668 size_t size_to_allocate = std::max(min_size, kSharedMemorySegmentBytes); |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 752 | 773 |
| 753 state_ = kError; | 774 state_ = kError; |
| 754 | 775 |
| 755 if (!pending_read_cb_.is_null()) { | 776 if (!pending_read_cb_.is_null()) { |
| 756 base::ResetAndReturn(&pending_read_cb_).Run(kDecodeError, NULL); | 777 base::ResetAndReturn(&pending_read_cb_).Run(kDecodeError, NULL); |
| 757 return; | 778 return; |
| 758 } | 779 } |
| 759 } | 780 } |
| 760 | 781 |
| 761 } // namespace media | 782 } // namespace media |
| OLD | NEW |