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

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

Issue 1918623002: Use the MediaCodec flush workaround in more cases (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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 <memory> 9 #include <memory>
10 10
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 get_gles2_decoder_cb_(get_gles2_decoder_cb), 310 get_gles2_decoder_cb_(get_gles2_decoder_cb),
311 is_encrypted_(false), 311 is_encrypted_(false),
312 state_(NO_ERROR), 312 state_(NO_ERROR),
313 picturebuffers_requested_(false), 313 picturebuffers_requested_(false),
314 media_drm_bridge_cdm_context_(nullptr), 314 media_drm_bridge_cdm_context_(nullptr),
315 cdm_registration_id_(0), 315 cdm_registration_id_(0),
316 pending_input_buf_index_(-1), 316 pending_input_buf_index_(-1),
317 error_sequence_token_(0), 317 error_sequence_token_(0),
318 defer_errors_(false), 318 defer_errors_(false),
319 deferred_initialization_pending_(false), 319 deferred_initialization_pending_(false),
320 codec_needs_flush_workaround_(false),
320 weak_this_factory_(this) {} 321 weak_this_factory_(this) {}
321 322
322 AndroidVideoDecodeAccelerator::~AndroidVideoDecodeAccelerator() { 323 AndroidVideoDecodeAccelerator::~AndroidVideoDecodeAccelerator() {
323 DCHECK(thread_checker_.CalledOnValidThread()); 324 DCHECK(thread_checker_.CalledOnValidThread());
324 g_avda_timer.Pointer()->StopTimer(this); 325 g_avda_timer.Pointer()->StopTimer(this);
325 g_avda_timer.Pointer()->StopThread(this); 326 g_avda_timer.Pointer()->StopThread(this);
326 327
327 #if defined(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS) 328 #if defined(ENABLE_MOJO_MEDIA_IN_GPU_PROCESS)
328 if (!media_drm_bridge_cdm_context_) 329 if (!media_drm_bridge_cdm_context_)
329 return; 330 return;
(...skipping 685 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 if (deferred_initialization_pending_) { 1016 if (deferred_initialization_pending_) {
1016 NotifyInitializationComplete(!!media_codec_); 1017 NotifyInitializationComplete(!!media_codec_);
1017 deferred_initialization_pending_ = false; 1018 deferred_initialization_pending_ = false;
1018 } 1019 }
1019 1020
1020 if (!media_codec_) { 1021 if (!media_codec_) {
1021 POST_ERROR(PLATFORM_FAILURE, "Failed to create MediaCodec."); 1022 POST_ERROR(PLATFORM_FAILURE, "Failed to create MediaCodec.");
1022 return; 1023 return;
1023 } 1024 }
1024 1025
1026 codec_needs_flush_workaround_ =
1027 media::MediaCodecUtil::CodecNeedsFlushWorkaround(media_codec_.get());
1028
1025 state_ = NO_ERROR; 1029 state_ = NO_ERROR;
1026 1030
1027 ManageTimer(true); 1031 ManageTimer(true);
1028 } 1032 }
1029 1033
1030 void AndroidVideoDecodeAccelerator::ResetCodecState() { 1034 void AndroidVideoDecodeAccelerator::ResetCodecState() {
1031 DCHECK(thread_checker_.CalledOnValidThread()); 1035 DCHECK(thread_checker_.CalledOnValidThread());
1032 1036
1033 // If there is already a reset in flight, then that counts. This can really 1037 // If there is already a reset in flight, then that counts. This can really
1034 // only happen if somebody calls Reset. 1038 // only happen if somebody calls Reset.
(...skipping 15 matching lines...) Expand all
1050 state_ = NO_ERROR; 1054 state_ = NO_ERROR;
1051 1055
1052 // We might increment error_sequence_token here to cancel any delayed errors, 1056 // We might increment error_sequence_token here to cancel any delayed errors,
1053 // but right now it's unclear that it's safe to do so. If we are in an error 1057 // but right now it's unclear that it's safe to do so. If we are in an error
1054 // state because of a codec error, then it would be okay. Otherwise, it's 1058 // state because of a codec error, then it would be okay. Otherwise, it's
1055 // less obvious that we are exiting the error state. Since deferred errors 1059 // less obvious that we are exiting the error state. Since deferred errors
1056 // are only intended for fullscreen transitions right now, we take the more 1060 // are only intended for fullscreen transitions right now, we take the more
1057 // conservative approach and let the errors post. 1061 // conservative approach and let the errors post.
1058 // TODO(liberato): revisit this once we sort out the error state a bit more. 1062 // TODO(liberato): revisit this once we sort out the error state a bit more.
1059 1063
1060 // When codec is not in error state we can quickly reset (internally calls 1064 if (state_ == NO_ERROR && !codec_needs_flush_workaround_) {
1061 // flush()) for JB-MR2 and beyond. Prior to JB-MR2, flush() had several bugs
1062 // (b/8125974, b/8347958) so we must delete the MediaCodec and create a new
1063 // one. The full reconfigure is much slower and may cause visible freezing if
1064 // done mid-stream.
1065 if (state_ == NO_ERROR &&
1066 base::android::BuildInfo::GetInstance()->sdk_int() >= 18) {
1067 DVLOG(3) << __FUNCTION__ << " Doing fast MediaCodec reset (flush)."; 1065 DVLOG(3) << __FUNCTION__ << " Doing fast MediaCodec reset (flush).";
1068 media_codec_->Reset(); 1066 media_codec_->Reset();
1069 // Since we just flushed all the output buffers, make sure that nothing is 1067 // Since we just flushed all the output buffers, make sure that nothing is
1070 // using them. 1068 // using them.
1071 strategy_->CodecChanged(media_codec_.get()); 1069 strategy_->CodecChanged(media_codec_.get());
1072 } else { 1070 } else {
1073 DVLOG(3) << __FUNCTION__ 1071 DVLOG(3) << __FUNCTION__
1074 << " Deleting the MediaCodec and creating a new one."; 1072 << " Deleting the MediaCodec and creating a new one.";
1075 g_avda_timer.Pointer()->StopTimer(this); 1073 g_avda_timer.Pointer()->StopTimer(this);
1076 // Changing the codec will also notify the strategy to forget about any
1077 // output buffers it has currently.
1078 state_ = NO_ERROR; 1074 state_ = NO_ERROR;
1079 ConfigureMediaCodecAsynchronously(); 1075 ConfigureMediaCodecAsynchronously();
1080 } 1076 }
1081 } 1077 }
1082 1078
1083 void AndroidVideoDecodeAccelerator::Reset() { 1079 void AndroidVideoDecodeAccelerator::Reset() {
1084 DCHECK(thread_checker_.CalledOnValidThread()); 1080 DCHECK(thread_checker_.CalledOnValidThread());
1085 TRACE_EVENT0("media", "AVDA::Reset"); 1081 TRACE_EVENT0("media", "AVDA::Reset");
1086 1082
1087 while (!pending_bitstream_buffers_.empty()) { 1083 while (!pending_bitstream_buffers_.empty()) {
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after
1354 if (media::MediaCodecUtil::IsSurfaceViewOutputSupported()) { 1350 if (media::MediaCodecUtil::IsSurfaceViewOutputSupported()) {
1355 capabilities.flags |= media::VideoDecodeAccelerator::Capabilities:: 1351 capabilities.flags |= media::VideoDecodeAccelerator::Capabilities::
1356 SUPPORTS_EXTERNAL_OUTPUT_SURFACE; 1352 SUPPORTS_EXTERNAL_OUTPUT_SURFACE;
1357 } 1353 }
1358 } 1354 }
1359 1355
1360 return capabilities; 1356 return capabilities;
1361 } 1357 }
1362 1358
1363 } // namespace content 1359 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698