From 711d24a12fae8e337b578df09041444bcf1b0a70 Mon Sep 17 00:00:00 2001 From: tonihei Date: Tue, 20 Feb 2024 06:13:45 -0800 Subject: [PATCH] Clarify purpose of omitting zero duration clipped audio samples When applying edit lists, we need to output the last partial samples to have all the necessary data needed for rendering. The only case where we can omit the sample is for zero duration audio data that has no additional information. The current comment and variable name doesn't make this very clear and this change improves the naming and the comment. PiperOrigin-RevId: 608579746 --- .../java/androidx/media3/extractor/mp4/AtomParsers.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libraries/extractor/src/main/java/androidx/media3/extractor/mp4/AtomParsers.java b/libraries/extractor/src/main/java/androidx/media3/extractor/mp4/AtomParsers.java index 44b034a84c..54daa6b5c0 100644 --- a/libraries/extractor/src/main/java/androidx/media3/extractor/mp4/AtomParsers.java +++ b/libraries/extractor/src/main/java/androidx/media3/extractor/mp4/AtomParsers.java @@ -677,8 +677,11 @@ import java.util.Objects; track, offsets, sizes, maximumSize, timestamps, flags, durationUs); } - // Omit any sample at the end point of an edit for audio tracks. - boolean omitClippedSample = track.type == C.TRACK_TYPE_AUDIO; + // When applying edit lists, we need to include any partial clipped samples at the end to ensure + // the final output is rendered correctly (see https://github.com/google/ExoPlayer/issues/2408). + // For audio only, we can omit any sample that starts at exactly the end point of an edit as + // there is no partial audio in this case. + boolean omitZeroDurationClippedSample = track.type == C.TRACK_TYPE_AUDIO; // Count the number of samples after applying edits. int editedSampleCount = 0; @@ -707,7 +710,7 @@ import java.util.Objects; Util.binarySearchCeil( timestamps, editMediaTime + editDuration, - /* inclusive= */ omitClippedSample, + /* inclusive= */ omitZeroDurationClippedSample, /* stayInBounds= */ false); while (startIndices[i] < endIndices[i] && (flags[startIndices[i]] & C.BUFFER_FLAG_KEY_FRAME) == 0) {