| 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 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 723 // again. | 723 // again. |
| 724 while (!pending_decodes_.empty()) | 724 while (!pending_decodes_.empty()) |
| 725 pending_decodes_.pop(); | 725 pending_decodes_.pop(); |
| 726 decoder_.reset(); | 726 decoder_.reset(); |
| 727 // This instance is deleted once we exit this scope. | 727 // This instance is deleted once we exit this scope. |
| 728 } | 728 } |
| 729 | 729 |
| 730 void VideoDecoderShim::DecoderImpl::OnInitDone(bool success) { | 730 void VideoDecoderShim::DecoderImpl::OnInitDone(bool success) { |
| 731 int32_t result = success ? PP_OK : PP_ERROR_NOTSUPPORTED; | 731 int32_t result = success ? PP_OK : PP_ERROR_NOTSUPPORTED; |
| 732 | 732 |
| 733 // Calculate how many textures the shim should create. | |
| 734 uint32_t shim_texture_pool_size = media::limits::kMaxVideoFrames + 1; | |
| 735 main_task_runner_->PostTask( | 733 main_task_runner_->PostTask( |
| 736 FROM_HERE, base::Bind(&VideoDecoderShim::OnInitializeComplete, shim_, | 734 FROM_HERE, base::Bind(&VideoDecoderShim::OnInitializeComplete, shim_, |
| 737 result, shim_texture_pool_size)); | 735 result)); |
| 738 } | 736 } |
| 739 | 737 |
| 740 void VideoDecoderShim::DecoderImpl::DoDecode() { | 738 void VideoDecoderShim::DecoderImpl::DoDecode() { |
| 741 if (pending_decodes_.empty() || awaiting_decoder_) | 739 if (pending_decodes_.empty() || awaiting_decoder_) |
| 742 return; | 740 return; |
| 743 | 741 |
| 744 awaiting_decoder_ = true; | 742 awaiting_decoder_ = true; |
| 745 const PendingDecode& decode = pending_decodes_.front(); | 743 const PendingDecode& decode = pending_decodes_.front(); |
| 746 decode_id_ = decode.decode_id; | 744 decode_id_ = decode.decode_id; |
| 747 decoder_->Decode(decode.buffer, | 745 decoder_->Decode(decode.buffer, |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 792 main_task_runner_->PostTask( | 790 main_task_runner_->PostTask( |
| 793 FROM_HERE, base::Bind(&VideoDecoderShim::OnOutputComplete, shim_, | 791 FROM_HERE, base::Bind(&VideoDecoderShim::OnOutputComplete, shim_, |
| 794 base::Passed(&pending_frame))); | 792 base::Passed(&pending_frame))); |
| 795 } | 793 } |
| 796 | 794 |
| 797 void VideoDecoderShim::DecoderImpl::OnResetComplete() { | 795 void VideoDecoderShim::DecoderImpl::OnResetComplete() { |
| 798 main_task_runner_->PostTask( | 796 main_task_runner_->PostTask( |
| 799 FROM_HERE, base::Bind(&VideoDecoderShim::OnResetComplete, shim_)); | 797 FROM_HERE, base::Bind(&VideoDecoderShim::OnResetComplete, shim_)); |
| 800 } | 798 } |
| 801 | 799 |
| 802 VideoDecoderShim::VideoDecoderShim(PepperVideoDecoderHost* host) | 800 VideoDecoderShim::VideoDecoderShim( |
| 801 PepperVideoDecoderHost* host, uint32_t texture_pool_size) |
| 803 : state_(UNINITIALIZED), | 802 : state_(UNINITIALIZED), |
| 804 host_(host), | 803 host_(host), |
| 805 media_task_runner_( | 804 media_task_runner_( |
| 806 RenderThreadImpl::current()->GetMediaThreadTaskRunner()), | 805 RenderThreadImpl::current()->GetMediaThreadTaskRunner()), |
| 807 context_provider_( | 806 context_provider_( |
| 808 RenderThreadImpl::current()->SharedMainThreadContextProvider()), | 807 RenderThreadImpl::current()->SharedMainThreadContextProvider()), |
| 809 texture_pool_size_(0), | 808 texture_pool_size_(texture_pool_size), |
| 810 num_pending_decodes_(0), | 809 num_pending_decodes_(0), |
| 811 yuv_converter_(new YUVConverter(context_provider_)), | 810 yuv_converter_(new YUVConverter(context_provider_)), |
| 812 weak_ptr_factory_(this) { | 811 weak_ptr_factory_(this) { |
| 813 DCHECK(host_); | 812 DCHECK(host_); |
| 814 DCHECK(media_task_runner_.get()); | 813 DCHECK(media_task_runner_.get()); |
| 815 DCHECK(context_provider_.get()); | 814 DCHECK(context_provider_.get()); |
| 816 decoder_impl_.reset(new DecoderImpl(weak_ptr_factory_.GetWeakPtr())); | 815 decoder_impl_.reset(new DecoderImpl(weak_ptr_factory_.GetWeakPtr())); |
| 817 } | 816 } |
| 818 | 817 |
| 819 VideoDecoderShim::~VideoDecoderShim() { | 818 VideoDecoderShim::~VideoDecoderShim() { |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 941 media_task_runner_->PostTask( | 940 media_task_runner_->PostTask( |
| 942 FROM_HERE, | 941 FROM_HERE, |
| 943 base::Bind(&VideoDecoderShim::DecoderImpl::Reset, | 942 base::Bind(&VideoDecoderShim::DecoderImpl::Reset, |
| 944 base::Unretained(decoder_impl_.get()))); | 943 base::Unretained(decoder_impl_.get()))); |
| 945 } | 944 } |
| 946 | 945 |
| 947 void VideoDecoderShim::Destroy() { | 946 void VideoDecoderShim::Destroy() { |
| 948 delete this; | 947 delete this; |
| 949 } | 948 } |
| 950 | 949 |
| 951 void VideoDecoderShim::OnInitializeComplete(int32_t result, | 950 void VideoDecoderShim::OnInitializeComplete(int32_t result) { |
| 952 uint32_t texture_pool_size) { | |
| 953 DCHECK(RenderThreadImpl::current()); | 951 DCHECK(RenderThreadImpl::current()); |
| 954 DCHECK(host_); | 952 DCHECK(host_); |
| 955 | 953 |
| 956 if (result == PP_OK) { | 954 if (result == PP_OK) { |
| 957 state_ = DECODING; | 955 state_ = DECODING; |
| 958 texture_pool_size_ = texture_pool_size; | |
| 959 } | 956 } |
| 960 | 957 |
| 961 host_->OnInitializeComplete(result); | 958 host_->OnInitializeComplete(result); |
| 962 } | 959 } |
| 963 | 960 |
| 964 void VideoDecoderShim::OnDecodeComplete(int32_t result, uint32_t decode_id) { | 961 void VideoDecoderShim::OnDecodeComplete(int32_t result, uint32_t decode_id) { |
| 965 DCHECK(RenderThreadImpl::current()); | 962 DCHECK(RenderThreadImpl::current()); |
| 966 DCHECK(host_); | 963 DCHECK(host_); |
| 967 | 964 |
| 968 if (result == PP_ERROR_RESOURCE_FAILED) { | 965 if (result == PP_ERROR_RESOURCE_FAILED) { |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1086 void VideoDecoderShim::DeleteTexture(uint32_t texture_id) { | 1083 void VideoDecoderShim::DeleteTexture(uint32_t texture_id) { |
| 1087 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); | 1084 gpu::gles2::GLES2Interface* gles2 = context_provider_->ContextGL(); |
| 1088 gles2->DeleteTextures(1, &texture_id); | 1085 gles2->DeleteTextures(1, &texture_id); |
| 1089 } | 1086 } |
| 1090 | 1087 |
| 1091 void VideoDecoderShim::FlushCommandBuffer() { | 1088 void VideoDecoderShim::FlushCommandBuffer() { |
| 1092 context_provider_->ContextGL()->Flush(); | 1089 context_provider_->ContextGL()->Flush(); |
| 1093 } | 1090 } |
| 1094 | 1091 |
| 1095 } // namespace content | 1092 } // namespace content |
| OLD | NEW |