OLD | NEW |
---|---|
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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/common/gpu/media/android_video_decode_accelerator.h" | 5 #include "content/common/gpu/media/android_video_decode_accelerator.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/android/build_info.h" | 9 #include "base/android/build_info.h" |
10 #include "base/auto_reset.h" | 10 #include "base/auto_reset.h" |
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
611 const bool allow_overlay = strategy_->ArePicturesOverlayable(); | 611 const bool allow_overlay = strategy_->ArePicturesOverlayable(); |
612 base::MessageLoop::current()->PostTask( | 612 base::MessageLoop::current()->PostTask( |
613 FROM_HERE, base::Bind(&AndroidVideoDecodeAccelerator::NotifyPictureReady, | 613 FROM_HERE, base::Bind(&AndroidVideoDecodeAccelerator::NotifyPictureReady, |
614 weak_this_factory_.GetWeakPtr(), | 614 weak_this_factory_.GetWeakPtr(), |
615 media::Picture(picture_buffer_id, bitstream_id, | 615 media::Picture(picture_buffer_id, bitstream_id, |
616 gfx::Rect(size_), allow_overlay))); | 616 gfx::Rect(size_), allow_overlay))); |
617 } | 617 } |
618 | 618 |
619 void AndroidVideoDecodeAccelerator::Decode( | 619 void AndroidVideoDecodeAccelerator::Decode( |
620 const media::BitstreamBuffer& bitstream_buffer) { | 620 const media::BitstreamBuffer& bitstream_buffer) { |
621 // We use id = -1 as a special bitstream_buffer internally, which indicating | |
Pawel Osciak
2016/02/19 07:48:44
This feels like an opportunity to remove the check
Owen Lin
2016/02/23 09:06:38
Done.
| |
622 // flush the decoder. The client should not passing any id < 0 when call | |
623 // Decode(). | |
624 if (bitstream_buffer.id() < 0) { | |
625 POST_ERROR(INVALID_ARGUMENT, | |
626 "Invalid bistream_buffer, id: " << bitstream_buffer.id()); | |
627 if (base::SharedMemory::IsHandleValid(bitstream_buffer.handle())) | |
628 base::SharedMemory::CloseHandle(bitstream_buffer.handle()); | |
629 return; | |
630 } | |
631 DecodeInternal(bitstream_buffer); | |
632 } | |
633 | |
634 void AndroidVideoDecodeAccelerator::DecodeInternal( | |
635 const media::BitstreamBuffer& bitstream_buffer) { | |
621 DCHECK(thread_checker_.CalledOnValidThread()); | 636 DCHECK(thread_checker_.CalledOnValidThread()); |
622 if (bitstream_buffer.id() != -1 && bitstream_buffer.size() == 0) { | 637 if (bitstream_buffer.id() != -1 && bitstream_buffer.size() == 0) { |
623 base::MessageLoop::current()->PostTask( | 638 base::MessageLoop::current()->PostTask( |
624 FROM_HERE, | 639 FROM_HERE, |
625 base::Bind(&AndroidVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer, | 640 base::Bind(&AndroidVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer, |
626 weak_this_factory_.GetWeakPtr(), bitstream_buffer.id())); | 641 weak_this_factory_.GetWeakPtr(), bitstream_buffer.id())); |
Pawel Osciak
2016/02/19 07:48:44
We need to CloseHandle here as well, but please se
| |
627 return; | 642 return; |
628 } | 643 } |
629 | 644 |
630 pending_bitstream_buffers_.push( | 645 pending_bitstream_buffers_.push( |
631 std::make_pair(bitstream_buffer, base::Time::Now())); | 646 std::make_pair(bitstream_buffer, base::Time::Now())); |
632 TRACE_COUNTER1("media", "AVDA::PendingBitstreamBufferCount", | 647 TRACE_COUNTER1("media", "AVDA::PendingBitstreamBufferCount", |
633 pending_bitstream_buffers_.size()); | 648 pending_bitstream_buffers_.size()); |
634 | 649 |
635 DoIOTask(); | 650 DoIOTask(); |
636 } | 651 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
697 } | 712 } |
698 | 713 |
699 strategy_->ReuseOnePictureBuffer(i->second); | 714 strategy_->ReuseOnePictureBuffer(i->second); |
700 | 715 |
701 DoIOTask(); | 716 DoIOTask(); |
702 } | 717 } |
703 | 718 |
704 void AndroidVideoDecodeAccelerator::Flush() { | 719 void AndroidVideoDecodeAccelerator::Flush() { |
705 DCHECK(thread_checker_.CalledOnValidThread()); | 720 DCHECK(thread_checker_.CalledOnValidThread()); |
706 | 721 |
707 Decode(media::BitstreamBuffer(-1, base::SharedMemoryHandle(), 0)); | 722 DecodeInternal(media::BitstreamBuffer(-1, base::SharedMemoryHandle(), 0)); |
708 } | 723 } |
709 | 724 |
710 bool AndroidVideoDecodeAccelerator::ConfigureMediaCodec() { | 725 bool AndroidVideoDecodeAccelerator::ConfigureMediaCodec() { |
711 DCHECK(thread_checker_.CalledOnValidThread()); | 726 DCHECK(thread_checker_.CalledOnValidThread()); |
712 TRACE_EVENT0("media", "AVDA::ConfigureMediaCodec"); | 727 TRACE_EVENT0("media", "AVDA::ConfigureMediaCodec"); |
713 | 728 |
714 jobject media_crypto = media_crypto_ ? media_crypto_->obj() : nullptr; | 729 jobject media_crypto = media_crypto_ ? media_crypto_->obj() : nullptr; |
715 | 730 |
716 // |needs_protected_surface_| implies encrypted stream. | 731 // |needs_protected_surface_| implies encrypted stream. |
717 DCHECK(!needs_protected_surface_ || media_crypto); | 732 DCHECK(!needs_protected_surface_ || media_crypto); |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
807 TRACE_EVENT0("media", "AVDA::Reset"); | 822 TRACE_EVENT0("media", "AVDA::Reset"); |
808 | 823 |
809 while (!pending_bitstream_buffers_.empty()) { | 824 while (!pending_bitstream_buffers_.empty()) { |
810 int32_t bitstream_buffer_id = pending_bitstream_buffers_.front().first.id(); | 825 int32_t bitstream_buffer_id = pending_bitstream_buffers_.front().first.id(); |
811 pending_bitstream_buffers_.pop(); | 826 pending_bitstream_buffers_.pop(); |
812 | 827 |
813 if (bitstream_buffer_id != -1) { | 828 if (bitstream_buffer_id != -1) { |
814 base::MessageLoop::current()->PostTask( | 829 base::MessageLoop::current()->PostTask( |
815 FROM_HERE, | 830 FROM_HERE, |
816 base::Bind(&AndroidVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer, | 831 base::Bind(&AndroidVideoDecodeAccelerator::NotifyEndOfBitstreamBuffer, |
817 weak_this_factory_.GetWeakPtr(), bitstream_buffer_id)); | 832 weak_this_factory_.GetWeakPtr(), bitstream_buffer_id)); |
Pawel Osciak
2016/02/19 07:48:44
Here we should also be closing the handle? Perhaps
Owen Lin
2016/02/23 09:06:38
Sounds good. But let me prepare the change after t
| |
818 } | 833 } |
819 } | 834 } |
820 TRACE_COUNTER1("media", "AVDA::PendingBitstreamBufferCount", 0); | 835 TRACE_COUNTER1("media", "AVDA::PendingBitstreamBufferCount", 0); |
821 bitstreams_notified_in_advance_.clear(); | 836 bitstreams_notified_in_advance_.clear(); |
822 | 837 |
823 // Any error that is waiting to post can be ignored. | 838 // Any error that is waiting to post can be ignored. |
824 error_sequence_token_++; | 839 error_sequence_token_++; |
825 | 840 |
826 ResetCodecState(); | 841 ResetCodecState(); |
827 | 842 |
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1014 | 1029 |
1015 if (UseDeferredRenderingStrategy()) { | 1030 if (UseDeferredRenderingStrategy()) { |
1016 capabilities.flags = media::VideoDecodeAccelerator::Capabilities:: | 1031 capabilities.flags = media::VideoDecodeAccelerator::Capabilities:: |
1017 NEEDS_ALL_PICTURE_BUFFERS_TO_DECODE; | 1032 NEEDS_ALL_PICTURE_BUFFERS_TO_DECODE; |
1018 } | 1033 } |
1019 | 1034 |
1020 return capabilities; | 1035 return capabilities; |
1021 } | 1036 } |
1022 | 1037 |
1023 } // namespace content | 1038 } // namespace content |
OLD | NEW |