From 77798e4fef374a5ffc4ecf1b9f2306548546b37b Mon Sep 17 00:00:00 2001 From: kimvde Date: Thu, 4 Feb 2021 18:06:02 +0000 Subject: [PATCH] Avoid skipping the first decoder output buffers after speed change #minor-release PiperOrigin-RevId: 355652144 --- .../transformer/TransformerAudioRenderer.java | 9 ++-- .../mp4/sample_sef_slow_motion.mp4.dump | 41 +++++++++++++++++-- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerAudioRenderer.java b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerAudioRenderer.java index 627120acb4a..c0fc23bb78b 100644 --- a/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerAudioRenderer.java +++ b/library/transformer/src/main/java/com/google/android/exoplayer2/transformer/TransformerAudioRenderer.java @@ -227,12 +227,11 @@ private boolean drainDecoderToFeedSonic() { MediaCodecAdapterWrapper decoder = checkNotNull(this.decoder); if (drainingSonicForSpeedChange) { - if (!sonicAudioProcessor.isEnded()) { - // Sonic needs draining, but has not fully drained yet. - return false; + if (sonicAudioProcessor.isEnded() && !sonicOutputBuffer.hasRemaining()) { + flushSonicAndSetSpeed(currentSpeed); + drainingSonicForSpeedChange = false; } - flushSonicAndSetSpeed(currentSpeed); - drainingSonicForSpeedChange = false; + return false; } // Sonic invalidates any previous output buffer when more input is queued, so we don't queue if diff --git a/testdata/src/test/assets/transformerdumps/mp4/sample_sef_slow_motion.mp4.dump b/testdata/src/test/assets/transformerdumps/mp4/sample_sef_slow_motion.mp4.dump index 672582b7038..89f996e5308 100644 --- a/testdata/src/test/assets/transformerdumps/mp4/sample_sef_slow_motion.mp4.dump +++ b/testdata/src/test/assets/transformerdumps/mp4/sample_sef_slow_motion.mp4.dump @@ -123,14 +123,44 @@ sample: presentationTimeUs = 36499 sample: trackIndex = 0 - dataHashCode = -2124187794 + dataHashCode = 250093960 isKeyFrame = true presentationTimeUs = 44415 sample: trackIndex = 0 - dataHashCode = 1016665126 + dataHashCode = 1895536226 isKeyFrame = true - presentationTimeUs = 63081 + presentationTimeUs = 59998 +sample: + trackIndex = 0 + dataHashCode = 1723596464 + isKeyFrame = true + presentationTimeUs = 81748 +sample: + trackIndex = 0 + dataHashCode = -978803114 + isKeyFrame = true + presentationTimeUs = 101414 +sample: + trackIndex = 0 + dataHashCode = 387377078 + isKeyFrame = true + presentationTimeUs = 121080 +sample: + trackIndex = 0 + dataHashCode = -132658698 + isKeyFrame = true + presentationTimeUs = 140746 +sample: + trackIndex = 0 + dataHashCode = 1495036471 + isKeyFrame = true + presentationTimeUs = 159496 +sample: + trackIndex = 0 + dataHashCode = 304440590 + isKeyFrame = true + presentationTimeUs = 178162 sample: trackIndex = 1 dataHashCode = 2139021989 @@ -151,6 +181,11 @@ sample: dataHashCode = -1893277090 isKeyFrame = false presentationTimeUs = 734083 +sample: + trackIndex = 0 + dataHashCode = -752661703 + isKeyFrame = true + presentationTimeUs = 196412 sample: trackIndex = 1 dataHashCode = -1554795381