| 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 | 10 |
| (...skipping 615 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 626 public: | 626 public: |
| 627 explicit DecoderImpl(const base::WeakPtr<VideoDecoderShim>& proxy); | 627 explicit DecoderImpl(const base::WeakPtr<VideoDecoderShim>& proxy); |
| 628 ~DecoderImpl(); | 628 ~DecoderImpl(); |
| 629 | 629 |
| 630 void Initialize(media::VideoDecoderConfig config); | 630 void Initialize(media::VideoDecoderConfig config); |
| 631 void Decode(uint32_t decode_id, scoped_refptr<media::DecoderBuffer> buffer); | 631 void Decode(uint32_t decode_id, scoped_refptr<media::DecoderBuffer> buffer); |
| 632 void Reset(); | 632 void Reset(); |
| 633 void Stop(); | 633 void Stop(); |
| 634 | 634 |
| 635 private: | 635 private: |
| 636 void OnInitDone(bool success); | 636 void OnPipelineStatus(media::PipelineStatus status); |
| 637 void DoDecode(); | 637 void DoDecode(); |
| 638 void OnDecodeComplete(media::VideoDecoder::Status status); | 638 void OnDecodeComplete(media::VideoDecoder::Status status); |
| 639 void OnOutputComplete(const scoped_refptr<media::VideoFrame>& frame); | 639 void OnOutputComplete(const scoped_refptr<media::VideoFrame>& frame); |
| 640 void OnResetComplete(); | 640 void OnResetComplete(); |
| 641 | 641 |
| 642 // WeakPtr is bound to main_message_loop_. Use only in shim callbacks. | 642 // WeakPtr is bound to main_message_loop_. Use only in shim callbacks. |
| 643 base::WeakPtr<VideoDecoderShim> shim_; | 643 base::WeakPtr<VideoDecoderShim> shim_; |
| 644 scoped_ptr<media::VideoDecoder> decoder_; | 644 scoped_ptr<media::VideoDecoder> decoder_; |
| 645 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; | 645 scoped_refptr<base::SingleThreadTaskRunner> main_task_runner_; |
| 646 // Queue of decodes waiting for the decoder. | 646 // Queue of decodes waiting for the decoder. |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 685 ffmpeg_video_decoder->set_decode_nalus(true); | 685 ffmpeg_video_decoder->set_decode_nalus(true); |
| 686 decoder_ = ffmpeg_video_decoder.Pass(); | 686 decoder_ = ffmpeg_video_decoder.Pass(); |
| 687 } | 687 } |
| 688 | 688 |
| 689 // VpxVideoDecoder and FFmpegVideoDecoder support only one pending Decode() | 689 // VpxVideoDecoder and FFmpegVideoDecoder support only one pending Decode() |
| 690 // request. | 690 // request. |
| 691 DCHECK_EQ(decoder_->GetMaxDecodeRequests(), 1); | 691 DCHECK_EQ(decoder_->GetMaxDecodeRequests(), 1); |
| 692 | 692 |
| 693 decoder_->Initialize( | 693 decoder_->Initialize( |
| 694 config, true /* low_delay */, | 694 config, true /* low_delay */, |
| 695 base::Bind(&VideoDecoderShim::DecoderImpl::OnInitDone, | 695 base::Bind(&VideoDecoderShim::DecoderImpl::OnPipelineStatus, |
| 696 weak_ptr_factory_.GetWeakPtr()), | 696 weak_ptr_factory_.GetWeakPtr()), |
| 697 base::Bind(&VideoDecoderShim::DecoderImpl::OnOutputComplete, | 697 base::Bind(&VideoDecoderShim::DecoderImpl::OnOutputComplete, |
| 698 weak_ptr_factory_.GetWeakPtr())); | 698 weak_ptr_factory_.GetWeakPtr())); |
| 699 } | 699 } |
| 700 | 700 |
| 701 void VideoDecoderShim::DecoderImpl::Decode( | 701 void VideoDecoderShim::DecoderImpl::Decode( |
| 702 uint32_t decode_id, | 702 uint32_t decode_id, |
| 703 scoped_refptr<media::DecoderBuffer> buffer) { | 703 scoped_refptr<media::DecoderBuffer> buffer) { |
| 704 DCHECK(decoder_); | 704 DCHECK(decoder_); |
| 705 pending_decodes_.push(PendingDecode(decode_id, buffer)); | 705 pending_decodes_.push(PendingDecode(decode_id, buffer)); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 724 void VideoDecoderShim::DecoderImpl::Stop() { | 724 void VideoDecoderShim::DecoderImpl::Stop() { |
| 725 DCHECK(decoder_); | 725 DCHECK(decoder_); |
| 726 // Clear pending decodes now. We don't want OnDecodeComplete to call DoDecode | 726 // Clear pending decodes now. We don't want OnDecodeComplete to call DoDecode |
| 727 // again. | 727 // again. |
| 728 while (!pending_decodes_.empty()) | 728 while (!pending_decodes_.empty()) |
| 729 pending_decodes_.pop(); | 729 pending_decodes_.pop(); |
| 730 decoder_.reset(); | 730 decoder_.reset(); |
| 731 // This instance is deleted once we exit this scope. | 731 // This instance is deleted once we exit this scope. |
| 732 } | 732 } |
| 733 | 733 |
| 734 void VideoDecoderShim::DecoderImpl::OnInitDone(bool success) { | 734 void VideoDecoderShim::DecoderImpl::OnPipelineStatus( |
| 735 int32_t result = success ? PP_OK : PP_ERROR_NOTSUPPORTED; | 735 media::PipelineStatus status) { |
| 736 int32_t result; |
| 737 switch (status) { |
| 738 case media::PIPELINE_OK: |
| 739 result = PP_OK; |
| 740 break; |
| 741 case media::DECODER_ERROR_NOT_SUPPORTED: |
| 742 result = PP_ERROR_NOTSUPPORTED; |
| 743 break; |
| 744 default: |
| 745 result = PP_ERROR_FAILED; |
| 746 break; |
| 747 } |
| 736 | 748 |
| 737 // Calculate how many textures the shim should create. | 749 // Calculate how many textures the shim should create. |
| 738 uint32_t shim_texture_pool_size = media::limits::kMaxVideoFrames + 1; | 750 uint32_t shim_texture_pool_size = media::limits::kMaxVideoFrames + 1; |
| 739 main_task_runner_->PostTask( | 751 main_task_runner_->PostTask( |
| 740 FROM_HERE, base::Bind(&VideoDecoderShim::OnInitializeComplete, shim_, | 752 FROM_HERE, base::Bind(&VideoDecoderShim::OnInitializeComplete, shim_, |
| 741 result, shim_texture_pool_size)); | 753 result, shim_texture_pool_size)); |
| 742 } | 754 } |
| 743 | 755 |
| 744 void VideoDecoderShim::DecoderImpl::DoDecode() { | 756 void VideoDecoderShim::DecoderImpl::DoDecode() { |
| 745 if (pending_decodes_.empty() || awaiting_decoder_) | 757 if (pending_decodes_.empty() || awaiting_decoder_) |
| (...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1094 void VideoDecoderShim::DeleteTexture(uint32_t texture_id) { | 1106 void VideoDecoderShim::DeleteTexture(uint32_t texture_id) { |
| 1095 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); | 1107 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); |
| 1096 gles2->DeleteTextures(1, &texture_id); | 1108 gles2->DeleteTextures(1, &texture_id); |
| 1097 } | 1109 } |
| 1098 | 1110 |
| 1099 void VideoDecoderShim::FlushCommandBuffer() { | 1111 void VideoDecoderShim::FlushCommandBuffer() { |
| 1100 context_provider_->ContextGL()->Flush(); | 1112 context_provider_->ContextGL()->Flush(); |
| 1101 } | 1113 } |
| 1102 | 1114 |
| 1103 } // namespace content | 1115 } // namespace content |
| OLD | NEW |