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

Side by Side Diff: media/gpu/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: Add TargetApi annotation 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/base/android/sdk_media_codec_bridge.cc ('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 1257 matching lines...) Expand 10 before | Expand all | Expand 10 after
1268 // If there is already a reset in flight, then that counts. This can really 1268 // If there is already a reset in flight, then that counts. This can really
1269 // only happen if somebody calls Reset. 1269 // only happen if somebody calls Reset.
1270 // If the surface is destroyed there's nothing to do. 1270 // If the surface is destroyed there's nothing to do.
1271 if (state_ == WAITING_FOR_CODEC || state_ == SURFACE_DESTROYED) 1271 if (state_ == WAITING_FOR_CODEC || state_ == SURFACE_DESTROYED)
1272 return; 1272 return;
1273 1273
1274 bitstream_buffers_in_decoder_.clear(); 1274 bitstream_buffers_in_decoder_.clear();
1275 1275
1276 if (pending_input_buf_index_ != -1) { 1276 if (pending_input_buf_index_ != -1) {
1277 // The data for that index exists in the input buffer, but corresponding 1277 // The data for that index exists in the input buffer, but corresponding
1278 // shm block been deleted. Check that it is safe to flush the coec, i.e. 1278 // shm block been deleted. Check that it is safe to flush the codec, i.e.
1279 // |pending_bitstream_records_| is empty. 1279 // |pending_bitstream_records_| is empty.
1280 // TODO(timav): keep shm block for that buffer and remove this restriction. 1280 // TODO(timav): keep shm block for that buffer and remove this restriction.
1281 DCHECK(pending_bitstream_records_.empty()); 1281 DCHECK(pending_bitstream_records_.empty());
1282 pending_input_buf_index_ = -1; 1282 pending_input_buf_index_ = -1;
1283 } 1283 }
1284 1284
1285 const bool did_codec_error_happen = state_ == ERROR; 1285 const bool did_codec_error_happen = state_ == ERROR;
1286 state_ = NO_ERROR; 1286 state_ = NO_ERROR;
1287 1287
1288 // Don't reset the codec here if there's no error and we're only flushing; 1288 // Don't reset the codec here if there's no error and we're only flushing;
1289 // instead defer until the next decode call; this prevents us from unbacking 1289 // instead defer until the next decode call; this prevents us from unbacking
1290 // frames that might be out for display at end of stream. 1290 // frames that might be out for display at end of stream.
1291 codec_needs_reset_ = false; 1291 codec_needs_reset_ = false;
1292 if (drain_type_ == DRAIN_FOR_FLUSH && !did_codec_error_happen) { 1292 if (drain_type_ == DRAIN_FOR_FLUSH && !did_codec_error_happen) {
1293 codec_needs_reset_ = true; 1293 codec_needs_reset_ = true;
1294 return; 1294 return;
1295 } 1295 }
1296 1296
1297 // We might increment error_sequence_token here to cancel any delayed errors, 1297 // We might increment error_sequence_token here to cancel any delayed errors,
1298 // but right now it's unclear that it's safe to do so. If we are in an error 1298 // but right now it's unclear that it's safe to do so. If we are in an error
1299 // state because of a codec error, then it would be okay. Otherwise, it's 1299 // state because of a codec error, then it would be okay. Otherwise, it's
1300 // less obvious that we are exiting the error state. Since deferred errors 1300 // less obvious that we are exiting the error state. Since deferred errors
1301 // are only intended for fullscreen transitions right now, we take the more 1301 // are only intended for fullscreen transitions right now, we take the more
1302 // conservative approach and let the errors post. 1302 // conservative approach and let the errors post.
1303 // TODO(liberato): revisit this once we sort out the error state a bit more. 1303 // TODO(liberato): revisit this once we sort out the error state a bit more.
1304 1304
1305 // When the codec is not in error state we can flush() for JB-MR2 and beyond. 1305 // Flush the codec if possible, or create a new one if not.
1306 // Prior to JB-MR2, flush() had several bugs (b/8125974, b/8347958) so we must
1307 // delete the MediaCodec and create a new one. The full reconfigure is much
1308 // slower and may cause visible freezing if done mid-stream.
1309 if (!did_codec_error_happen && 1306 if (!did_codec_error_happen &&
1310 base::android::BuildInfo::GetInstance()->sdk_int() >= 18) { 1307 !media::MediaCodecUtil::CodecNeedsFlushWorkaround(media_codec_.get())) {
1311 DVLOG(3) << __FUNCTION__ << " Flushing MediaCodec."; 1308 DVLOG(3) << __FUNCTION__ << " Flushing MediaCodec.";
1312 media_codec_->Flush(); 1309 media_codec_->Flush();
1313 // Since we just flushed all the output buffers, make sure that nothing is 1310 // Since we just flushed all the output buffers, make sure that nothing is
1314 // using them. 1311 // using them.
1315 strategy_->CodecChanged(media_codec_.get()); 1312 strategy_->CodecChanged(media_codec_.get());
1316 } else { 1313 } else {
1317 DVLOG(3) << __FUNCTION__ 1314 DVLOG(3) << __FUNCTION__
1318 << " Deleting the MediaCodec and creating a new one."; 1315 << " Deleting the MediaCodec and creating a new one.";
1319 g_avda_timer.Pointer()->StopTimer(this); 1316 g_avda_timer.Pointer()->StopTimer(this);
1320 ConfigureMediaCodecAsynchronously(); 1317 ConfigureMediaCodecAsynchronously();
(...skipping 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
1775 1772
1776 bool AndroidVideoDecodeAccelerator::IsMediaCodecSoftwareDecodingForbidden() 1773 bool AndroidVideoDecodeAccelerator::IsMediaCodecSoftwareDecodingForbidden()
1777 const { 1774 const {
1778 // Prevent MediaCodec from using its internal software decoders when we have 1775 // Prevent MediaCodec from using its internal software decoders when we have
1779 // more secure and up to date versions in the renderer process. 1776 // more secure and up to date versions in the renderer process.
1780 return !config_.is_encrypted && (codec_config_->codec_ == media::kCodecVP8 || 1777 return !config_.is_encrypted && (codec_config_->codec_ == media::kCodecVP8 ||
1781 codec_config_->codec_ == media::kCodecVP9); 1778 codec_config_->codec_ == media::kCodecVP9);
1782 } 1779 }
1783 1780
1784 } // namespace media 1781 } // namespace media
OLDNEW
« no previous file with comments | « media/base/android/sdk_media_codec_bridge.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698