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

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

Issue 2147843002: Drop idle MediaCodec instances after a few seconds within AVDA. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Reduce to 1 second. Make const. Created 4 years, 5 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
« no previous file with comments | « media/gpu/android_video_decode_accelerator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "media/gpu/android_video_decode_accelerator.h" 5 #include "media/gpu/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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 return base::TimeDelta::FromSeconds(1); 102 return base::TimeDelta::FromSeconds(1);
103 } 103 }
104 104
105 // Time between when we notice an error, and when we actually notify somebody. 105 // Time between when we notice an error, and when we actually notify somebody.
106 // This is to prevent codec errors caused by SurfaceView fullscreen transitions 106 // This is to prevent codec errors caused by SurfaceView fullscreen transitions
107 // from breaking the pipeline, if we're about to be reset anyway. 107 // from breaking the pipeline, if we're about to be reset anyway.
108 static inline const base::TimeDelta ErrorPostingDelay() { 108 static inline const base::TimeDelta ErrorPostingDelay() {
109 return base::TimeDelta::FromSeconds(2); 109 return base::TimeDelta::FromSeconds(2);
110 } 110 }
111 111
112 // Time allowed to elapse between codec configuration completion and the first
113 // Decode() callback. Unless a site is intentionally stalling after providing
114 // initialization information, this timeout should never be hit.
115 constexpr base::TimeDelta kNoDecodeIdleTimeout =
116 base::TimeDelta::FromSeconds(1);
117
112 // For RecordFormatChangedMetric. 118 // For RecordFormatChangedMetric.
113 enum FormatChangedValue { 119 enum FormatChangedValue {
114 CodecInitialized = false, 120 CodecInitialized = false,
115 MissingFormatChanged = true 121 MissingFormatChanged = true
116 }; 122 };
117 123
118 // Maximum number of concurrent, incomplete codec creations that we'll allow 124 // Maximum number of concurrent, incomplete codec creations that we'll allow
119 // before turning off autodection of codec type. 125 // before turning off autodection of codec type.
120 enum { kMaxConcurrentCodecAutodetections = 4 }; 126 enum { kMaxConcurrentCodecAutodetections = 4 };
121 127
(...skipping 834 matching lines...) Expand 10 before | Expand all | Expand 10 after
956 NotifyPictureReady(picture); 962 NotifyPictureReady(picture);
957 963
958 // Connect the PictureBuffer to the decoded frame, via whatever mechanism the 964 // Connect the PictureBuffer to the decoded frame, via whatever mechanism the
959 // strategy likes. 965 // strategy likes.
960 strategy_->UseCodecBufferForPictureBuffer(codec_buffer_index, i->second); 966 strategy_->UseCodecBufferForPictureBuffer(codec_buffer_index, i->second);
961 } 967 }
962 968
963 void AndroidVideoDecodeAccelerator::Decode( 969 void AndroidVideoDecodeAccelerator::Decode(
964 const BitstreamBuffer& bitstream_buffer) { 970 const BitstreamBuffer& bitstream_buffer) {
965 DCHECK(thread_checker_.CalledOnValidThread()); 971 DCHECK(thread_checker_.CalledOnValidThread());
972 no_decode_timeout_.Stop();
966 973
967 // If we previously deferred a codec restart, take care of it now. This can 974 // If we previously deferred a codec restart, take care of it now. This can
968 // happen on older devices where configuration changes require a codec reset. 975 // happen on older devices where configuration changes require a codec reset.
969 if (codec_needs_reset_) { 976 if (codec_needs_reset_) {
970 DCHECK_EQ(drain_type_, DRAIN_TYPE_NONE); 977 DCHECK_EQ(drain_type_, DRAIN_TYPE_NONE);
971 ResetCodecState(); 978 ResetCodecState();
972 } 979 }
973 980
974 if (bitstream_buffer.id() >= 0 && bitstream_buffer.size() > 0) { 981 if (bitstream_buffer.id() >= 0 && bitstream_buffer.size() > 0) {
975 DecodeBuffer(bitstream_buffer); 982 DecodeBuffer(bitstream_buffer);
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
1195 1202
1196 DCHECK(!media_codec_); 1203 DCHECK(!media_codec_);
1197 media_codec_ = std::move(media_codec); 1204 media_codec_ = std::move(media_codec);
1198 strategy_->CodecChanged(media_codec_.get()); 1205 strategy_->CodecChanged(media_codec_.get());
1199 if (!media_codec_) { 1206 if (!media_codec_) {
1200 POST_ERROR(PLATFORM_FAILURE, "Failed to create MediaCodec."); 1207 POST_ERROR(PLATFORM_FAILURE, "Failed to create MediaCodec.");
1201 return; 1208 return;
1202 } 1209 }
1203 1210
1204 state_ = NO_ERROR; 1211 state_ = NO_ERROR;
1205 1212 no_decode_timeout_.Start(FROM_HERE, kNoDecodeIdleTimeout, this,
1213 &AndroidVideoDecodeAccelerator::CloseIdleCodec);
1206 ManageTimer(true); 1214 ManageTimer(true);
1207 } 1215 }
1208 1216
1209 void AndroidVideoDecodeAccelerator::StartCodecDrain(DrainType drain_type) { 1217 void AndroidVideoDecodeAccelerator::StartCodecDrain(DrainType drain_type) {
1210 DVLOG(2) << __FUNCTION__ << " drain_type:" << drain_type; 1218 DVLOG(2) << __FUNCTION__ << " drain_type:" << drain_type;
1211 DCHECK(thread_checker_.CalledOnValidThread()); 1219 DCHECK(thread_checker_.CalledOnValidThread());
1212 1220
1213 // We assume that DRAIN_FOR_FLUSH and DRAIN_FOR_RESET cannot come while 1221 // We assume that DRAIN_FOR_FLUSH and DRAIN_FOR_RESET cannot come while
1214 // another drain request is present, but DRAIN_FOR_DESTROY can. 1222 // another drain request is present, but DRAIN_FOR_DESTROY can.
1215 DCHECK_NE(drain_type, DRAIN_TYPE_NONE); 1223 DCHECK_NE(drain_type, DRAIN_TYPE_NONE);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1304 // state because of a codec error, then it would be okay. Otherwise, it's 1312 // state because of a codec error, then it would be okay. Otherwise, it's
1305 // less obvious that we are exiting the error state. Since deferred errors 1313 // less obvious that we are exiting the error state. Since deferred errors
1306 // are only intended for fullscreen transitions right now, we take the more 1314 // are only intended for fullscreen transitions right now, we take the more
1307 // conservative approach and let the errors post. 1315 // conservative approach and let the errors post.
1308 // TODO(liberato): revisit this once we sort out the error state a bit more. 1316 // TODO(liberato): revisit this once we sort out the error state a bit more.
1309 1317
1310 // When the codec is not in error state we can flush() for JB-MR2 and beyond. 1318 // When the codec is not in error state we can flush() for JB-MR2 and beyond.
1311 // Prior to JB-MR2, flush() had several bugs (b/8125974, b/8347958) so we must 1319 // Prior to JB-MR2, flush() had several bugs (b/8125974, b/8347958) so we must
1312 // delete the MediaCodec and create a new one. The full reconfigure is much 1320 // delete the MediaCodec and create a new one. The full reconfigure is much
1313 // slower and may cause visible freezing if done mid-stream. 1321 // slower and may cause visible freezing if done mid-stream.
1314 if (!did_codec_error_happen && 1322 if (!did_codec_error_happen && media_codec_ &&
1315 base::android::BuildInfo::GetInstance()->sdk_int() >= 18) { 1323 base::android::BuildInfo::GetInstance()->sdk_int() >= 18) {
1316 DVLOG(3) << __FUNCTION__ << " Flushing MediaCodec."; 1324 DVLOG(3) << __FUNCTION__ << " Flushing MediaCodec.";
1317 media_codec_->Flush(); 1325 media_codec_->Flush();
1318 // Since we just flushed all the output buffers, make sure that nothing is 1326 // Since we just flushed all the output buffers, make sure that nothing is
1319 // using them. 1327 // using them.
1320 strategy_->CodecChanged(media_codec_.get()); 1328 strategy_->CodecChanged(media_codec_.get());
1321 } else { 1329 } else {
1322 DVLOG(3) << __FUNCTION__ 1330 DVLOG(3) << __FUNCTION__
1323 << " Deleting the MediaCodec and creating a new one."; 1331 << " Deleting the MediaCodec and creating a new one.";
1324 g_avda_timer.Pointer()->StopTimer(this); 1332 g_avda_timer.Pointer()->StopTimer(this);
(...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after
1664 if (should_be_running) 1672 if (should_be_running)
1665 g_avda_timer.Pointer()->StartTimer(this); 1673 g_avda_timer.Pointer()->StartTimer(this);
1666 else 1674 else
1667 g_avda_timer.Pointer()->StopTimer(this); 1675 g_avda_timer.Pointer()->StopTimer(this);
1668 } 1676 }
1669 1677
1670 void AndroidVideoDecodeAccelerator::ReleaseMediaCodec() { 1678 void AndroidVideoDecodeAccelerator::ReleaseMediaCodec() {
1671 if (!media_codec_) 1679 if (!media_codec_)
1672 return; 1680 return;
1673 1681
1682 no_decode_timeout_.Stop();
1683
1674 // If codec construction is broken, then we can't release this codec if it's 1684 // If codec construction is broken, then we can't release this codec if it's
1675 // backed by hardware, else it may hang too. Post it to the construction 1685 // backed by hardware, else it may hang too. Post it to the construction
1676 // thread, and it'll get freed if things start working. If things are 1686 // thread, and it'll get freed if things start working. If things are
1677 // already working, then it'll be freed soon. 1687 // already working, then it'll be freed soon.
1678 // 1688 //
1679 // We require software codecs when |allow_autodetection_| is false, so use 1689 // We require software codecs when |allow_autodetection_| is false, so use
1680 // the stored value as a proxy for whether the MediaCodec is software backed 1690 // the stored value as a proxy for whether the MediaCodec is software backed
1681 // or not. 1691 // or not.
1682 if (!codec_config_->allow_autodetection_) { 1692 if (!codec_config_->allow_autodetection_) {
1683 media_codec_.reset(); 1693 media_codec_.reset();
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
1779 } 1789 }
1780 1790
1781 bool AndroidVideoDecodeAccelerator::IsMediaCodecSoftwareDecodingForbidden() 1791 bool AndroidVideoDecodeAccelerator::IsMediaCodecSoftwareDecodingForbidden()
1782 const { 1792 const {
1783 // Prevent MediaCodec from using its internal software decoders when we have 1793 // Prevent MediaCodec from using its internal software decoders when we have
1784 // more secure and up to date versions in the renderer process. 1794 // more secure and up to date versions in the renderer process.
1785 return !config_.is_encrypted && (codec_config_->codec_ == media::kCodecVP8 || 1795 return !config_.is_encrypted && (codec_config_->codec_ == media::kCodecVP8 ||
1786 codec_config_->codec_ == media::kCodecVP9); 1796 codec_config_->codec_ == media::kCodecVP9);
1787 } 1797 }
1788 1798
1799 void AndroidVideoDecodeAccelerator::CloseIdleCodec() {
1800 if (!media_codec_)
1801 return;
1802
1803 ReleaseMediaCodec();
1804 codec_needs_reset_ = true;
watk 2016/07/13 22:38:25 Do we need to call strategy_->CodecChanged(nullptr
liberato (no reviews please) 2016/07/14 15:33:57 i don't think that we do, since no decode has been
1805 }
1806
1789 } // namespace media 1807 } // namespace media
OLDNEW
« no previous file with comments | « media/gpu/android_video_decode_accelerator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698