From fb982c2d548508dafc062916ea80e50b31068d3a Mon Sep 17 00:00:00 2001 From: tonihei Date: Wed, 1 May 2024 06:40:09 -0700 Subject: [PATCH] Don't enforce SimpleDecoder skipping for samples before start time We currently enforce the skipping if the sample has a timestamp less than the start time. While this may be the default desired behavior for most implementations, it prevents an implementation from outputting a sample with such a timestamp. This change updates the logic to pre-fill the shouldBeSkipped flag based on the input timestamp, and only check this flag on the output buffer. None of the implementations in our library change timestamps of samples, so this is equivalent to the previous code. PiperOrigin-RevId: 629708873 --- .../main/java/androidx/media3/decoder/SimpleDecoder.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libraries/decoder/src/main/java/androidx/media3/decoder/SimpleDecoder.java b/libraries/decoder/src/main/java/androidx/media3/decoder/SimpleDecoder.java index cec438b8dd..c728d0945e 100644 --- a/libraries/decoder/src/main/java/androidx/media3/decoder/SimpleDecoder.java +++ b/libraries/decoder/src/main/java/androidx/media3/decoder/SimpleDecoder.java @@ -262,6 +262,9 @@ public abstract class SimpleDecoder< if (inputBuffer.isFirstSample()) { outputBuffer.addFlag(C.BUFFER_FLAG_FIRST_SAMPLE); } + if (!isAtLeastOutputStartTimeUs(inputBuffer.timeUs)) { + outputBuffer.shouldBeSkipped = true; + } @Nullable E exception; try { exception = decode(inputBuffer, outputBuffer, resetDecoder); @@ -286,8 +289,7 @@ public abstract class SimpleDecoder< synchronized (lock) { if (flushed) { outputBuffer.release(); - } else if ((!outputBuffer.isEndOfStream() && !isAtLeastOutputStartTimeUs(outputBuffer.timeUs)) - || outputBuffer.shouldBeSkipped) { + } else if (outputBuffer.shouldBeSkipped) { skippedOutputBufferCount++; outputBuffer.release(); } else {