OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 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/video_decoder_shim.h" | 5 #include "content/renderer/pepper/video_decoder_shim.h" |
6 | 6 |
7 #include <GLES2/gl2.h> | 7 #include <GLES2/gl2.h> |
8 #include <GLES2/gl2ext.h> | 8 #include <GLES2/gl2ext.h> |
9 #include <GLES2/gl2extchromium.h> | 9 #include <GLES2/gl2extchromium.h> |
10 #include <utility> | 10 #include <utility> |
(...skipping 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
643 ~DecoderImpl(); | 643 ~DecoderImpl(); |
644 | 644 |
645 void Initialize(media::VideoDecoderConfig config); | 645 void Initialize(media::VideoDecoderConfig config); |
646 void Decode(uint32_t decode_id, scoped_refptr<media::DecoderBuffer> buffer); | 646 void Decode(uint32_t decode_id, scoped_refptr<media::DecoderBuffer> buffer); |
647 void Reset(); | 647 void Reset(); |
648 void Stop(); | 648 void Stop(); |
649 | 649 |
650 private: | 650 private: |
651 void OnInitDone(bool success); | 651 void OnInitDone(bool success); |
652 void DoDecode(); | 652 void DoDecode(); |
653 void OnDecodeComplete(media::VideoDecoder::Status status); | 653 void OnDecodeComplete(media::DecodeStatus status); |
654 void OnOutputComplete(const scoped_refptr<media::VideoFrame>& frame); | 654 void OnOutputComplete(const scoped_refptr<media::VideoFrame>& frame); |
655 void OnResetComplete(); | 655 void OnResetComplete(); |
656 | 656 |
657 // WeakPtr is bound to main_message_loop_. Use only in shim callbacks. | 657 // WeakPtr is bound to main_message_loop_. Use only in shim callbacks. |
658 base::WeakPtr<VideoDecoderShim> shim_; | 658 base::WeakPtr<VideoDecoderShim> shim_; |
659 scoped_ptr<media::VideoDecoder> decoder_; | 659 scoped_ptr<media::VideoDecoder> decoder_; |
660 bool initialized_ = false; | 660 bool initialized_ = false; |
661 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 661 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
662 // Queue of decodes waiting for the decoder. | 662 // Queue of decodes waiting for the decoder. |
663 typedef std::queue<PendingDecode> PendingDecodeQueue; | 663 typedef std::queue<PendingDecode> PendingDecodeQueue; |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 DoDecode(); | 725 DoDecode(); |
726 } | 726 } |
727 | 727 |
728 void VideoDecoderShim::DecoderImpl::Reset() { | 728 void VideoDecoderShim::DecoderImpl::Reset() { |
729 DCHECK(decoder_); | 729 DCHECK(decoder_); |
730 // Abort all pending decodes. | 730 // Abort all pending decodes. |
731 while (!pending_decodes_.empty()) { | 731 while (!pending_decodes_.empty()) { |
732 const PendingDecode& decode = pending_decodes_.front(); | 732 const PendingDecode& decode = pending_decodes_.front(); |
733 scoped_ptr<PendingFrame> pending_frame(new PendingFrame(decode.decode_id)); | 733 scoped_ptr<PendingFrame> pending_frame(new PendingFrame(decode.decode_id)); |
734 main_task_runner_->PostTask( | 734 main_task_runner_->PostTask( |
735 FROM_HERE, base::Bind(&VideoDecoderShim::OnDecodeComplete, shim_, | 735 FROM_HERE, base::Bind(&VideoDecoderShim::OnDecodeComplete, shim_, PP_OK, |
736 media::VideoDecoder::kAborted, decode.decode_id)); | 736 decode.decode_id)); |
737 pending_decodes_.pop(); | 737 pending_decodes_.pop(); |
738 } | 738 } |
739 // Don't need to call Reset() if the |decoder_| hasn't been initialized. | 739 // Don't need to call Reset() if the |decoder_| hasn't been initialized. |
740 if (!initialized_) { | 740 if (!initialized_) { |
741 OnResetComplete(); | 741 OnResetComplete(); |
742 return; | 742 return; |
743 } | 743 } |
744 | 744 |
745 decoder_->Reset(base::Bind(&VideoDecoderShim::DecoderImpl::OnResetComplete, | 745 decoder_->Reset(base::Bind(&VideoDecoderShim::DecoderImpl::OnResetComplete, |
746 weak_ptr_factory_.GetWeakPtr())); | 746 weak_ptr_factory_.GetWeakPtr())); |
(...skipping 27 matching lines...) Expand all Loading... |
774 awaiting_decoder_ = true; | 774 awaiting_decoder_ = true; |
775 const PendingDecode& decode = pending_decodes_.front(); | 775 const PendingDecode& decode = pending_decodes_.front(); |
776 decode_id_ = decode.decode_id; | 776 decode_id_ = decode.decode_id; |
777 decoder_->Decode(decode.buffer, | 777 decoder_->Decode(decode.buffer, |
778 base::Bind(&VideoDecoderShim::DecoderImpl::OnDecodeComplete, | 778 base::Bind(&VideoDecoderShim::DecoderImpl::OnDecodeComplete, |
779 weak_ptr_factory_.GetWeakPtr())); | 779 weak_ptr_factory_.GetWeakPtr())); |
780 pending_decodes_.pop(); | 780 pending_decodes_.pop(); |
781 } | 781 } |
782 | 782 |
783 void VideoDecoderShim::DecoderImpl::OnDecodeComplete( | 783 void VideoDecoderShim::DecoderImpl::OnDecodeComplete( |
784 media::VideoDecoder::Status status) { | 784 media::DecodeStatus status) { |
785 DCHECK(awaiting_decoder_); | 785 DCHECK(awaiting_decoder_); |
786 awaiting_decoder_ = false; | 786 awaiting_decoder_ = false; |
787 | 787 |
788 int32_t result; | 788 int32_t result; |
789 switch (status) { | 789 switch (status) { |
790 case media::VideoDecoder::kOk: | 790 case media::DecodeStatus::OK: |
791 case media::VideoDecoder::kAborted: | 791 case media::DecodeStatus::ABORTED: |
792 result = PP_OK; | 792 result = PP_OK; |
793 break; | 793 break; |
794 case media::VideoDecoder::kDecodeError: | 794 case media::DecodeStatus::DECODE_ERROR: |
795 result = PP_ERROR_RESOURCE_FAILED; | 795 result = PP_ERROR_RESOURCE_FAILED; |
796 break; | 796 break; |
797 default: | |
798 NOTREACHED(); | |
799 result = PP_ERROR_FAILED; | |
800 break; | |
801 } | 797 } |
802 | 798 |
803 main_task_runner_->PostTask( | 799 main_task_runner_->PostTask( |
804 FROM_HERE, base::Bind(&VideoDecoderShim::OnDecodeComplete, shim_, result, | 800 FROM_HERE, base::Bind(&VideoDecoderShim::OnDecodeComplete, shim_, result, |
805 decode_id_)); | 801 decode_id_)); |
806 | 802 |
807 DoDecode(); | 803 DoDecode(); |
808 } | 804 } |
809 | 805 |
810 void VideoDecoderShim::DecoderImpl::OnOutputComplete( | 806 void VideoDecoderShim::DecoderImpl::OnOutputComplete( |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1120 void VideoDecoderShim::DeleteTexture(uint32_t texture_id) { | 1116 void VideoDecoderShim::DeleteTexture(uint32_t texture_id) { |
1121 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); | 1117 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); |
1122 gles2->DeleteTextures(1, &texture_id); | 1118 gles2->DeleteTextures(1, &texture_id); |
1123 } | 1119 } |
1124 | 1120 |
1125 void VideoDecoderShim::FlushCommandBuffer() { | 1121 void VideoDecoderShim::FlushCommandBuffer() { |
1126 context_provider_->ContextGL()->Flush(); | 1122 context_provider_->ContextGL()->Flush(); |
1127 } | 1123 } |
1128 | 1124 |
1129 } // namespace content | 1125 } // namespace content |
OLD | NEW |