Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(733)

Side by Side Diff: content/common/gpu/media/android_video_decode_accelerator.cc

Issue 1745903002: Introduce GpuVideoDecodeAcceleratorFactory. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 // Repeating timer responsible for draining pending IO to the codecs. 222 // Repeating timer responsible for draining pending IO to the codecs.
223 base::RepeatingTimer io_timer_; 223 base::RepeatingTimer io_timer_;
224 224
225 DISALLOW_COPY_AND_ASSIGN(AVDATimerManager); 225 DISALLOW_COPY_AND_ASSIGN(AVDATimerManager);
226 }; 226 };
227 227
228 static base::LazyInstance<AVDATimerManager>::Leaky g_avda_timer = 228 static base::LazyInstance<AVDATimerManager>::Leaky g_avda_timer =
229 LAZY_INSTANCE_INITIALIZER; 229 LAZY_INSTANCE_INITIALIZER;
230 230
231 AndroidVideoDecodeAccelerator::AndroidVideoDecodeAccelerator( 231 AndroidVideoDecodeAccelerator::AndroidVideoDecodeAccelerator(
232 const base::WeakPtr<gpu::gles2::GLES2Decoder> decoder, 232 const gpu_vda_helpers::GetGLES2DecoderCb& get_gles2_decoder_cb,
233 const base::Callback<bool(void)>& make_context_current) 233 const gpu_vda_helpers::MakeGLContextCurrentCb& make_context_current_cb)
234 : client_(NULL), 234 : client_(NULL),
235 make_context_current_(make_context_current), 235 make_context_current_cb_(make_context_current_cb),
236 get_gles2_decoder_cb_(get_gles2_decoder_cb),
236 codec_(media::kCodecH264), 237 codec_(media::kCodecH264),
237 is_encrypted_(false), 238 is_encrypted_(false),
238 needs_protected_surface_(false), 239 needs_protected_surface_(false),
239 state_(NO_ERROR), 240 state_(NO_ERROR),
240 picturebuffers_requested_(false), 241 picturebuffers_requested_(false),
241 gl_decoder_(decoder),
242 cdm_registration_id_(0), 242 cdm_registration_id_(0),
243 pending_input_buf_index_(-1), 243 pending_input_buf_index_(-1),
244 error_sequence_token_(0), 244 error_sequence_token_(0),
245 defer_errors_(false), 245 defer_errors_(false),
246 weak_this_factory_(this) { 246 weak_this_factory_(this) {
247 if (UseDeferredRenderingStrategy()) { 247 if (UseDeferredRenderingStrategy()) {
248 // TODO(liberato, watk): Figure out what we want to do about zero copy for 248 // TODO(liberato, watk): Figure out what we want to do about zero copy for
249 // fullscreen external SurfaceView in WebView. http://crbug.com/582170. 249 // fullscreen external SurfaceView in WebView. http://crbug.com/582170.
250 DCHECK(!gl_decoder_->GetContextGroup()->mailbox_manager()->UsesSync()); 250 auto gles_decoder = get_gles2_decoder_cb_.Run();
kcwu 2016/03/01 10:25:06 However about moving those callbacks invoking to I
Pawel Osciak 2016/03/02 07:17:11 Done.
251 DCHECK(gles_decoder);
252 DCHECK(!gles_decoder->GetContextGroup()->mailbox_manager()->UsesSync());
251 DVLOG(1) << __FUNCTION__ << ", using deferred rendering strategy."; 253 DVLOG(1) << __FUNCTION__ << ", using deferred rendering strategy.";
252 strategy_.reset(new AndroidDeferredRenderingBackingStrategy(this)); 254 strategy_.reset(new AndroidDeferredRenderingBackingStrategy(this));
253 } else { 255 } else {
254 DVLOG(1) << __FUNCTION__ << ", using copy back strategy."; 256 DVLOG(1) << __FUNCTION__ << ", using copy back strategy.";
255 strategy_.reset(new AndroidCopyingBackingStrategy(this)); 257 strategy_.reset(new AndroidCopyingBackingStrategy(this));
256 } 258 }
257 } 259 }
258 260
259 AndroidVideoDecodeAccelerator::~AndroidVideoDecodeAccelerator() { 261 AndroidVideoDecodeAccelerator::~AndroidVideoDecodeAccelerator() {
260 DCHECK(thread_checker_.CalledOnValidThread()); 262 DCHECK(thread_checker_.CalledOnValidThread());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
297 !is_encrypted_) { 299 !is_encrypted_) {
298 if (media::VideoCodecBridge::IsKnownUnaccelerated( 300 if (media::VideoCodecBridge::IsKnownUnaccelerated(
299 codec_, media::MEDIA_CODEC_DECODER)) { 301 codec_, media::MEDIA_CODEC_DECODER)) {
300 DVLOG(1) << "Initialization failed: " 302 DVLOG(1) << "Initialization failed: "
301 << (codec_ == media::kCodecVP8 ? "vp8" : "vp9") 303 << (codec_ == media::kCodecVP8 ? "vp8" : "vp9")
302 << " is not hardware accelerated"; 304 << " is not hardware accelerated";
303 return false; 305 return false;
304 } 306 }
305 } 307 }
306 308
307 if (!make_context_current_.Run()) { 309 if (!make_context_current_cb_.Run()) {
308 LOG(ERROR) << "Failed to make this decoder's GL context current."; 310 LOG(ERROR) << "Failed to make this decoder's GL context current.";
309 return false; 311 return false;
310 } 312 }
311 313
312 if (!gl_decoder_) { 314 if (!GetGlDecoder()) {
313 LOG(ERROR) << "Failed to get gles2 decoder instance."; 315 LOG(ERROR) << "Failed to get gles2 decoder instance.";
314 return false; 316 return false;
315 } 317 }
316 318
317 surface_ = strategy_->Initialize(config.surface_id); 319 surface_ = strategy_->Initialize(config.surface_id);
318 if (surface_.IsEmpty()) { 320 if (surface_.IsEmpty()) {
319 LOG(ERROR) << "Failed to initialize the backing strategy. The returned " 321 LOG(ERROR) << "Failed to initialize the backing strategy. The returned "
320 "Java surface is empty."; 322 "Java surface is empty.";
321 return false; 323 return false;
322 } 324 }
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
669 } 671 }
670 672
671 void AndroidVideoDecodeAccelerator::SendDecodedFrameToClient( 673 void AndroidVideoDecodeAccelerator::SendDecodedFrameToClient(
672 int32_t codec_buffer_index, 674 int32_t codec_buffer_index,
673 int32_t bitstream_id) { 675 int32_t bitstream_id) {
674 DCHECK(thread_checker_.CalledOnValidThread()); 676 DCHECK(thread_checker_.CalledOnValidThread());
675 DCHECK_NE(bitstream_id, -1); 677 DCHECK_NE(bitstream_id, -1);
676 DCHECK(!free_picture_ids_.empty()); 678 DCHECK(!free_picture_ids_.empty());
677 TRACE_EVENT0("media", "AVDA::SendDecodedFrameToClient"); 679 TRACE_EVENT0("media", "AVDA::SendDecodedFrameToClient");
678 680
679 if (!make_context_current_.Run()) { 681 if (!make_context_current_cb_.Run()) {
680 POST_ERROR(PLATFORM_FAILURE, "Failed to make the GL context current."); 682 POST_ERROR(PLATFORM_FAILURE, "Failed to make the GL context current.");
681 return; 683 return;
682 } 684 }
683 685
684 int32_t picture_buffer_id = free_picture_ids_.front(); 686 int32_t picture_buffer_id = free_picture_ids_.front();
685 free_picture_ids_.pop(); 687 free_picture_ids_.pop();
686 TRACE_COUNTER1("media", "AVDA::FreePictureIds", free_picture_ids_.size()); 688 TRACE_COUNTER1("media", "AVDA::FreePictureIds", free_picture_ids_.size());
687 689
688 OutputBufferMap::const_iterator i = 690 OutputBufferMap::const_iterator i =
689 output_picture_buffers_.find(picture_buffer_id); 691 output_picture_buffers_.find(picture_buffer_id);
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 ResetCodecState(); 931 ResetCodecState();
930 932
931 base::MessageLoop::current()->PostTask( 933 base::MessageLoop::current()->PostTask(
932 FROM_HERE, base::Bind(&AndroidVideoDecodeAccelerator::NotifyResetDone, 934 FROM_HERE, base::Bind(&AndroidVideoDecodeAccelerator::NotifyResetDone,
933 weak_this_factory_.GetWeakPtr())); 935 weak_this_factory_.GetWeakPtr()));
934 } 936 }
935 937
936 void AndroidVideoDecodeAccelerator::Destroy() { 938 void AndroidVideoDecodeAccelerator::Destroy() {
937 DCHECK(thread_checker_.CalledOnValidThread()); 939 DCHECK(thread_checker_.CalledOnValidThread());
938 940
939 bool have_context = make_context_current_.Run(); 941 bool have_context = make_context_current_cb_.Run();
940 if (!have_context) 942 if (!have_context)
941 LOG(WARNING) << "Failed make GL context current for Destroy, continuing."; 943 LOG(WARNING) << "Failed make GL context current for Destroy, continuing.";
942 944
943 strategy_->Cleanup(have_context, output_picture_buffers_); 945 strategy_->Cleanup(have_context, output_picture_buffers_);
944 946
945 // If we have an OnFrameAvailable handler, tell it that we're going away. 947 // If we have an OnFrameAvailable handler, tell it that we're going away.
946 if (on_frame_available_handler_) { 948 if (on_frame_available_handler_) {
947 on_frame_available_handler_->ClearOwner(); 949 on_frame_available_handler_->ClearOwner();
948 on_frame_available_handler_ = nullptr; 950 on_frame_available_handler_ = nullptr;
949 } 951 }
950 952
951 weak_this_factory_.InvalidateWeakPtrs(); 953 weak_this_factory_.InvalidateWeakPtrs();
952 if (media_codec_) { 954 if (media_codec_) {
953 g_avda_timer.Pointer()->StopTimer(this); 955 g_avda_timer.Pointer()->StopTimer(this);
954 media_codec_.reset(); 956 media_codec_.reset();
955 } 957 }
956 delete this; 958 delete this;
957 } 959 }
958 960
959 bool AndroidVideoDecodeAccelerator::CanDecodeOnIOThread() { 961 bool AndroidVideoDecodeAccelerator::TryInitializeDecodeOnSeparateThread(
962 const base::WeakPtr<Client>& decode_client,
963 const scoped_refptr<base::SingleThreadTaskRunner>& decode_task_runner) {
960 return false; 964 return false;
961 } 965 }
962 966
963 const gfx::Size& AndroidVideoDecodeAccelerator::GetSize() const { 967 const gfx::Size& AndroidVideoDecodeAccelerator::GetSize() const {
964 return size_; 968 return size_;
965 } 969 }
966 970
967 const base::ThreadChecker& AndroidVideoDecodeAccelerator::ThreadChecker() 971 const base::ThreadChecker& AndroidVideoDecodeAccelerator::ThreadChecker()
968 const { 972 const {
969 return thread_checker_; 973 return thread_checker_;
970 } 974 }
971 975
972 base::WeakPtr<gpu::gles2::GLES2Decoder> 976 base::WeakPtr<gpu::gles2::GLES2Decoder>
973 AndroidVideoDecodeAccelerator::GetGlDecoder() const { 977 AndroidVideoDecodeAccelerator::GetGlDecoder() const {
974 return gl_decoder_; 978 return get_gles2_decoder_cb_.Run();
975 } 979 }
976 980
977 void AndroidVideoDecodeAccelerator::OnFrameAvailable() { 981 void AndroidVideoDecodeAccelerator::OnFrameAvailable() {
978 // Remember: this may be on any thread. 982 // Remember: this may be on any thread.
979 DCHECK(strategy_); 983 DCHECK(strategy_);
980 strategy_->OnFrameAvailable(); 984 strategy_->OnFrameAvailable();
981 } 985 }
982 986
983 void AndroidVideoDecodeAccelerator::PostError( 987 void AndroidVideoDecodeAccelerator::PostError(
984 const ::tracked_objects::Location& from_here, 988 const ::tracked_objects::Location& from_here,
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 capabilities.flags = media::VideoDecodeAccelerator::Capabilities:: 1125 capabilities.flags = media::VideoDecodeAccelerator::Capabilities::
1122 NEEDS_ALL_PICTURE_BUFFERS_TO_DECODE | 1126 NEEDS_ALL_PICTURE_BUFFERS_TO_DECODE |
1123 media::VideoDecodeAccelerator::Capabilities:: 1127 media::VideoDecodeAccelerator::Capabilities::
1124 SUPPORTS_EXTERNAL_OUTPUT_SURFACE; 1128 SUPPORTS_EXTERNAL_OUTPUT_SURFACE;
1125 } 1129 }
1126 1130
1127 return capabilities; 1131 return capabilities;
1128 } 1132 }
1129 1133
1130 } // namespace content 1134 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698