Chromium Code Reviews| Index: media/gpu/android_video_decode_accelerator.cc |
| diff --git a/media/gpu/android_video_decode_accelerator.cc b/media/gpu/android_video_decode_accelerator.cc |
| index 50fe2ebca4ece288bff98a1135b8baa2d94a0966..e21bc1d2cf5d65aa73e23f874acb3c4e43b39f7e 100644 |
| --- a/media/gpu/android_video_decode_accelerator.cc |
| +++ b/media/gpu/android_video_decode_accelerator.cc |
| @@ -383,6 +383,7 @@ AndroidVideoDecodeAccelerator::AndroidVideoDecodeAccelerator( |
| error_sequence_token_(0), |
| defer_errors_(false), |
| deferred_initialization_pending_(false), |
| + codec_needs_reset_(false), |
| weak_this_factory_(this) {} |
| AndroidVideoDecodeAccelerator::~AndroidVideoDecodeAccelerator() { |
| @@ -900,6 +901,11 @@ void AndroidVideoDecodeAccelerator::Decode( |
| const media::BitstreamBuffer& bitstream_buffer) { |
| DCHECK(thread_checker_.CalledOnValidThread()); |
| + // If we previously deferred a codec restart, take care of it now. This can |
| + // happen on older devices where configuration changes require a codec reset. |
| + if (codec_needs_reset_) |
| + ResetCodecState(base::Closure()); |
|
Tima Vaisburd
2016/05/21 06:40:31
Did you mean ConfigureMediaCodecAsynchronously() ?
DaleCurtis
2016/05/24 00:35:29
ResetCodecState() does all the necessary things: C
|
| + |
| if (bitstream_buffer.id() >= 0 && bitstream_buffer.size() > 0) { |
| DecodeBuffer(bitstream_buffer); |
| return; |
| @@ -1179,6 +1185,25 @@ void AndroidVideoDecodeAccelerator::ResetCodecState( |
| const bool did_codec_error_happen = state_ == ERROR; |
| state_ = NO_ERROR; |
| + // When codec is not in error state we can quickly reset (internally calls |
| + // flush()) for JB-MR2 and beyond. Prior to JB-MR2, flush() had several bugs |
| + // (b/8125974, b/8347958) so we must delete the MediaCodec and create a new |
| + // one. The full reconfigure is much slower and may cause visible freezing if |
| + // done mid-stream. |
| + const bool codec_requires_reset_for_config_changes = |
|
chcunningham
2016/05/21 00:25:33
It used to be that
api >= 18 -> quick flush
api <
DaleCurtis
2016/05/24 00:35:29
Actually, this needs to always reset since once we
|
| + base::android::BuildInfo::GetInstance()->sdk_int() < 18; |
| + |
| + // Don't reset the codec if there's no error and we're only flushing. On older |
| + // JellyBean devices we'll defer the reset until we get another Decode() call |
| + // so that we don't prematurely nuke the last few frames of video. |
| + codec_needs_reset_ = false; |
| + if (drain_type_ == DRAIN_FOR_FLUSH && !did_codec_error_happen) { |
| + codec_needs_reset_ = codec_requires_reset_for_config_changes; |
| + if (!done_cb.is_null()) |
| + done_cb.Run(); |
| + return; |
| + } |
| + |
| // We might increment error_sequence_token here to cancel any delayed errors, |
| // but right now it's unclear that it's safe to do so. If we are in an error |
| // state because of a codec error, then it would be okay. Otherwise, it's |
| @@ -1186,14 +1211,7 @@ void AndroidVideoDecodeAccelerator::ResetCodecState( |
| // are only intended for fullscreen transitions right now, we take the more |
| // conservative approach and let the errors post. |
| // TODO(liberato): revisit this once we sort out the error state a bit more. |
| - |
| - // When codec is not in error state we can quickly reset (internally calls |
| - // flush()) for JB-MR2 and beyond. Prior to JB-MR2, flush() had several bugs |
| - // (b/8125974, b/8347958) so we must delete the MediaCodec and create a new |
| - // one. The full reconfigure is much slower and may cause visible freezing if |
| - // done mid-stream. |
| - if (!did_codec_error_happen && |
| - base::android::BuildInfo::GetInstance()->sdk_int() >= 18) { |
| + if (!did_codec_error_happen && !codec_requires_reset_for_config_changes) { |
| DVLOG(3) << __FUNCTION__ << " Doing fast MediaCodec reset (flush)."; |
| media_codec_->Reset(); |
| // Since we just flushed all the output buffers, make sure that nothing is |