From a7788e0d600b62d1f8833dd5e001acdffb7f1549 Mon Sep 17 00:00:00 2001 From: sheenachhabra Date: Tue, 3 Sep 2024 08:12:58 -0700 Subject: [PATCH] Rename last sample duration behaviour enums This is to improve readability. PiperOrigin-RevId: 670563611 --- .../java/androidx/media3/muxer/Boxes.java | 7 +++--- .../media3/muxer/FragmentedMp4Writer.java | 5 ++-- .../java/androidx/media3/muxer/Mp4Muxer.java | 16 ++++++------ .../java/androidx/media3/muxer/BoxesTest.java | 25 ++++++++++--------- .../media3/muxer/Mp4MuxerEndToEndTest.java | 5 ++-- .../media3/transformer/InAppMuxer.java | 3 ++- 6 files changed, 32 insertions(+), 29 deletions(-) diff --git a/libraries/muxer/src/main/java/androidx/media3/muxer/Boxes.java b/libraries/muxer/src/main/java/androidx/media3/muxer/Boxes.java index 57d16bde18..0480bca848 100644 --- a/libraries/muxer/src/main/java/androidx/media3/muxer/Boxes.java +++ b/libraries/muxer/src/main/java/androidx/media3/muxer/Boxes.java @@ -1241,16 +1241,15 @@ import org.checkerframework.checker.nullness.qual.PolyNull; @Mp4Muxer.LastSampleDurationBehavior int lastSampleDurationBehavior, int lastSampleDurationVuFromEndOfStream) { switch (lastSampleDurationBehavior) { - case Mp4Muxer.LAST_SAMPLE_DURATION_BEHAVIOR_DUPLICATE_PREV_DURATION: + case Mp4Muxer.LAST_SAMPLE_DURATION_BEHAVIOR_DUPLICATE_PREVIOUS: // For a track having less than 3 samples, duplicating the last frame duration will // significantly increase the overall track duration, so avoid that. return sampleDurationsExceptLast.size() < 2 ? 0 : Iterables.getLast(sampleDurationsExceptLast); - case Mp4Muxer.LAST_SAMPLE_DURATION_BEHAVIOR_INSERT_SHORT_SAMPLE: - // Keep the last sample duration as short as possible. + case Mp4Muxer.LAST_SAMPLE_DURATION_BEHAVIOR_SET_TO_ZERO: return 0; - case Mp4Muxer.LAST_SAMPLE_DURATION_BEHAVIOR_USING_END_OF_STREAM_FLAG: + case Mp4Muxer.LAST_SAMPLE_DURATION_BEHAVIOR_SET_FROM_END_OF_STREAM_BUFFER: return lastSampleDurationVuFromEndOfStream; default: throw new IllegalArgumentException( diff --git a/libraries/muxer/src/main/java/androidx/media3/muxer/FragmentedMp4Writer.java b/libraries/muxer/src/main/java/androidx/media3/muxer/FragmentedMp4Writer.java index 9792ba82db..e2d35f338e 100644 --- a/libraries/muxer/src/main/java/androidx/media3/muxer/FragmentedMp4Writer.java +++ b/libraries/muxer/src/main/java/androidx/media3/muxer/FragmentedMp4Writer.java @@ -23,6 +23,7 @@ import static androidx.media3.muxer.Boxes.BOX_HEADER_SIZE; import static androidx.media3.muxer.Boxes.MFHD_BOX_CONTENT_SIZE; import static androidx.media3.muxer.Boxes.TFHD_BOX_CONTENT_SIZE; import static androidx.media3.muxer.Boxes.getTrunBoxContentSize; +import static androidx.media3.muxer.Mp4Muxer.LAST_SAMPLE_DURATION_BEHAVIOR_DUPLICATE_PREVIOUS; import static androidx.media3.muxer.MuxerUtil.UNSIGNED_INT_MAX_VALUE; import static java.lang.Math.max; import static java.lang.Math.min; @@ -100,7 +101,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; this.annexBToAvccConverter = annexBToAvccConverter; this.fragmentDurationUs = fragmentDurationMs * 1_000; this.sampleCopyEnabled = sampleCopyEnabled; - lastSampleDurationBehavior = Mp4Muxer.LAST_SAMPLE_DURATION_BEHAVIOR_DUPLICATE_PREV_DURATION; + lastSampleDurationBehavior = LAST_SAMPLE_DURATION_BEHAVIOR_DUPLICATE_PREVIOUS; tracks = new ArrayList<>(); minInputPresentationTimeUs = Long.MAX_VALUE; currentFragmentSequenceNumber = 1; @@ -333,7 +334,7 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull; ? minInputPresentationTimeUs : pendingSamplesBufferInfo.get(0).presentationTimeUs, track.videoUnitTimebase(), - Mp4Muxer.LAST_SAMPLE_DURATION_BEHAVIOR_DUPLICATE_PREV_DURATION, + LAST_SAMPLE_DURATION_BEHAVIOR_DUPLICATE_PREVIOUS, track.endOfStreamTimestampUs); List sampleCompositionTimeOffsets = diff --git a/libraries/muxer/src/main/java/androidx/media3/muxer/Mp4Muxer.java b/libraries/muxer/src/main/java/androidx/media3/muxer/Mp4Muxer.java index eeb4e969cb..d41d642c0c 100644 --- a/libraries/muxer/src/main/java/androidx/media3/muxer/Mp4Muxer.java +++ b/libraries/muxer/src/main/java/androidx/media3/muxer/Mp4Muxer.java @@ -146,20 +146,20 @@ public final class Mp4Muxer implements Muxer { @Retention(RetentionPolicy.SOURCE) @Target(TYPE_USE) @IntDef({ - LAST_SAMPLE_DURATION_BEHAVIOR_INSERT_SHORT_SAMPLE, - LAST_SAMPLE_DURATION_BEHAVIOR_DUPLICATE_PREV_DURATION, - LAST_SAMPLE_DURATION_BEHAVIOR_USING_END_OF_STREAM_FLAG + LAST_SAMPLE_DURATION_BEHAVIOR_SET_TO_ZERO, + LAST_SAMPLE_DURATION_BEHAVIOR_DUPLICATE_PREVIOUS, + LAST_SAMPLE_DURATION_BEHAVIOR_SET_FROM_END_OF_STREAM_BUFFER }) public @interface LastSampleDurationBehavior {} /** The duration of the last sample is set to 0. */ - public static final int LAST_SAMPLE_DURATION_BEHAVIOR_INSERT_SHORT_SAMPLE = 0; + public static final int LAST_SAMPLE_DURATION_BEHAVIOR_SET_TO_ZERO = 0; /** * Use the difference between the last timestamp and the one before that as the duration of the * last sample. */ - public static final int LAST_SAMPLE_DURATION_BEHAVIOR_DUPLICATE_PREV_DURATION = 1; + public static final int LAST_SAMPLE_DURATION_BEHAVIOR_DUPLICATE_PREVIOUS = 1; /** * Use the {@link MediaCodec#BUFFER_FLAG_END_OF_STREAM end of stream sample} to set the duration @@ -176,7 +176,7 @@ public final class Mp4Muxer implements Muxer { *

If no explicit {@link MediaCodec#BUFFER_FLAG_END_OF_STREAM} sample is passed, then the * duration of the last sample will be set to 0. */ - public static final int LAST_SAMPLE_DURATION_BEHAVIOR_USING_END_OF_STREAM_FLAG = 2; + public static final int LAST_SAMPLE_DURATION_BEHAVIOR_SET_FROM_END_OF_STREAM_BUFFER = 2; /** The specific MP4 file format. */ @Documented @@ -216,7 +216,7 @@ public final class Mp4Muxer implements Muxer { */ public Builder(FileOutputStream outputStream) { this.outputStream = outputStream; - lastSampleDurationBehavior = LAST_SAMPLE_DURATION_BEHAVIOR_INSERT_SHORT_SAMPLE; + lastSampleDurationBehavior = LAST_SAMPLE_DURATION_BEHAVIOR_SET_TO_ZERO; sampleCopyEnabled = true; attemptStreamableOutputEnabled = true; outputFileFormat = FILE_FORMAT_DEFAULT; @@ -225,7 +225,7 @@ public final class Mp4Muxer implements Muxer { /** * Sets the {@link LastSampleDurationBehavior}. * - *

The default value is {@link #LAST_SAMPLE_DURATION_BEHAVIOR_INSERT_SHORT_SAMPLE}. + *

The default value is {@link #LAST_SAMPLE_DURATION_BEHAVIOR_SET_TO_ZERO}. */ @CanIgnoreReturnValue public Mp4Muxer.Builder setLastSampleDurationBehavior( diff --git a/libraries/muxer/src/test/java/androidx/media3/muxer/BoxesTest.java b/libraries/muxer/src/test/java/androidx/media3/muxer/BoxesTest.java index d906aba2e8..e98f16b6cb 100644 --- a/libraries/muxer/src/test/java/androidx/media3/muxer/BoxesTest.java +++ b/libraries/muxer/src/test/java/androidx/media3/muxer/BoxesTest.java @@ -15,8 +15,9 @@ */ package androidx.media3.muxer; -import static androidx.media3.muxer.Mp4Muxer.LAST_SAMPLE_DURATION_BEHAVIOR_DUPLICATE_PREV_DURATION; -import static androidx.media3.muxer.Mp4Muxer.LAST_SAMPLE_DURATION_BEHAVIOR_INSERT_SHORT_SAMPLE; +import static androidx.media3.muxer.Mp4Muxer.LAST_SAMPLE_DURATION_BEHAVIOR_DUPLICATE_PREVIOUS; +import static androidx.media3.muxer.Mp4Muxer.LAST_SAMPLE_DURATION_BEHAVIOR_SET_FROM_END_OF_STREAM_BUFFER; +import static androidx.media3.muxer.Mp4Muxer.LAST_SAMPLE_DURATION_BEHAVIOR_SET_TO_ZERO; import static androidx.media3.muxer.MuxerTestUtil.FAKE_AUDIO_FORMAT; import static androidx.media3.muxer.MuxerTestUtil.FAKE_CSD_0; import static androidx.media3.muxer.MuxerTestUtil.FAKE_VIDEO_FORMAT; @@ -477,7 +478,7 @@ public class BoxesTest { sampleBufferInfos, /* firstSamplePresentationTimeUs= */ 0L, VU_TIMEBASE, - LAST_SAMPLE_DURATION_BEHAVIOR_INSERT_SHORT_SAMPLE, + LAST_SAMPLE_DURATION_BEHAVIOR_SET_TO_ZERO, C.TIME_UNSET); assertThat(durationsVu).containsExactly(0); @@ -494,7 +495,7 @@ public class BoxesTest { sampleBufferInfos, /* firstSamplePresentationTimeUs= */ 0L, VU_TIMEBASE, - LAST_SAMPLE_DURATION_BEHAVIOR_INSERT_SHORT_SAMPLE, + LAST_SAMPLE_DURATION_BEHAVIOR_SET_TO_ZERO, C.TIME_UNSET); assertThat(durationsVu).containsExactly(0); @@ -511,7 +512,7 @@ public class BoxesTest { sampleBufferInfos, /* firstSamplePresentationTimeUs= */ 0L, VU_TIMEBASE, - LAST_SAMPLE_DURATION_BEHAVIOR_INSERT_SHORT_SAMPLE, + LAST_SAMPLE_DURATION_BEHAVIOR_SET_TO_ZERO, C.TIME_UNSET); assertThat(durationsVu).containsExactly(3_000, 5_000, 0); @@ -528,7 +529,7 @@ public class BoxesTest { sampleBufferInfos, /* firstSamplePresentationTimeUs= */ 0L, VU_TIMEBASE, - LAST_SAMPLE_DURATION_BEHAVIOR_DUPLICATE_PREV_DURATION, + LAST_SAMPLE_DURATION_BEHAVIOR_DUPLICATE_PREVIOUS, C.TIME_UNSET); assertThat(durationsVu).containsExactly(3_000, 5_000, 5_000); @@ -545,7 +546,7 @@ public class BoxesTest { sampleBufferInfos, /* firstSamplePresentationTimeUs= */ 0L, VU_TIMEBASE, - LAST_SAMPLE_DURATION_BEHAVIOR_INSERT_SHORT_SAMPLE, + LAST_SAMPLE_DURATION_BEHAVIOR_SET_TO_ZERO, C.TIME_UNSET); assertThat(durationsVu).containsExactly(100, 100, 800, 100, 0); @@ -562,7 +563,7 @@ public class BoxesTest { sampleBufferInfos, /* firstSamplePresentationTimeUs= */ 0L, VU_TIMEBASE, - Mp4Muxer.LAST_SAMPLE_DURATION_BEHAVIOR_USING_END_OF_STREAM_FLAG, + LAST_SAMPLE_DURATION_BEHAVIOR_SET_FROM_END_OF_STREAM_BUFFER, /* endOfStreamTimestampUs= */ 10_000); assertThat(durationsVu).containsExactly(100, 100, 100, 100, 600); @@ -617,7 +618,7 @@ public class BoxesTest { sampleBufferInfos, /* firstSamplePresentationTimeUs= */ 0L, VU_TIMEBASE, - LAST_SAMPLE_DURATION_BEHAVIOR_INSERT_SHORT_SAMPLE, + LAST_SAMPLE_DURATION_BEHAVIOR_SET_TO_ZERO, C.TIME_UNSET); ByteBuffer cttsBox = Boxes.ctts(sampleBufferInfos, durationsVu, VU_TIMEBASE); @@ -635,7 +636,7 @@ public class BoxesTest { sampleBufferInfos, /* firstSamplePresentationTimeUs= */ 0L, VU_TIMEBASE, - LAST_SAMPLE_DURATION_BEHAVIOR_INSERT_SHORT_SAMPLE, + LAST_SAMPLE_DURATION_BEHAVIOR_SET_TO_ZERO, C.TIME_UNSET); ByteBuffer cttsBox = Boxes.ctts(sampleBufferInfos, durationsVu, VU_TIMEBASE); @@ -655,7 +656,7 @@ public class BoxesTest { sampleBufferInfos, /* firstSamplePresentationTimeUs= */ 0L, VU_TIMEBASE, - LAST_SAMPLE_DURATION_BEHAVIOR_INSERT_SHORT_SAMPLE, + LAST_SAMPLE_DURATION_BEHAVIOR_SET_TO_ZERO, C.TIME_UNSET); ByteBuffer cttsBox = Boxes.ctts(sampleBufferInfos, durationsVu, VU_TIMEBASE); @@ -676,7 +677,7 @@ public class BoxesTest { sampleBufferInfos, /* firstSamplePresentationTimeUs= */ 23698215060L, VU_TIMEBASE, - LAST_SAMPLE_DURATION_BEHAVIOR_INSERT_SHORT_SAMPLE, + LAST_SAMPLE_DURATION_BEHAVIOR_SET_TO_ZERO, C.TIME_UNSET); ByteBuffer cttsBox = Boxes.ctts(sampleBufferInfos, durationsVu, VU_TIMEBASE); diff --git a/libraries/muxer/src/test/java/androidx/media3/muxer/Mp4MuxerEndToEndTest.java b/libraries/muxer/src/test/java/androidx/media3/muxer/Mp4MuxerEndToEndTest.java index 8df830ab2d..cdc5c8b342 100644 --- a/libraries/muxer/src/test/java/androidx/media3/muxer/Mp4MuxerEndToEndTest.java +++ b/libraries/muxer/src/test/java/androidx/media3/muxer/Mp4MuxerEndToEndTest.java @@ -15,6 +15,7 @@ */ package androidx.media3.muxer; +import static androidx.media3.muxer.Mp4Muxer.LAST_SAMPLE_DURATION_BEHAVIOR_SET_FROM_END_OF_STREAM_BUFFER; import static androidx.media3.muxer.MuxerTestUtil.FAKE_VIDEO_FORMAT; import static androidx.media3.muxer.MuxerTestUtil.XMP_SAMPLE_DATA; import static androidx.media3.muxer.MuxerTestUtil.getFakeSampleAndSampleInfo; @@ -682,7 +683,7 @@ public class Mp4MuxerEndToEndTest { Mp4Muxer mp4Muxer = new Mp4Muxer.Builder(new FileOutputStream(outputFilePath)) .setLastSampleDurationBehavior( - Mp4Muxer.LAST_SAMPLE_DURATION_BEHAVIOR_USING_END_OF_STREAM_FLAG) + LAST_SAMPLE_DURATION_BEHAVIOR_SET_FROM_END_OF_STREAM_BUFFER) .build(); mp4Muxer.addMetadataEntry( new Mp4TimestampData( @@ -730,7 +731,7 @@ public class Mp4MuxerEndToEndTest { Mp4Muxer mp4Muxer = new Mp4Muxer.Builder(new FileOutputStream(outputFilePath)) .setLastSampleDurationBehavior( - Mp4Muxer.LAST_SAMPLE_DURATION_BEHAVIOR_USING_END_OF_STREAM_FLAG) + LAST_SAMPLE_DURATION_BEHAVIOR_SET_FROM_END_OF_STREAM_BUFFER) .build(); mp4Muxer.addMetadataEntry( new Mp4TimestampData( diff --git a/libraries/transformer/src/main/java/androidx/media3/transformer/InAppMuxer.java b/libraries/transformer/src/main/java/androidx/media3/transformer/InAppMuxer.java index 6c81224d3d..8f1e7f70f1 100644 --- a/libraries/transformer/src/main/java/androidx/media3/transformer/InAppMuxer.java +++ b/libraries/transformer/src/main/java/androidx/media3/transformer/InAppMuxer.java @@ -16,6 +16,7 @@ package androidx.media3.transformer; import static androidx.media3.common.util.Assertions.checkNotNull; +import static androidx.media3.muxer.Mp4Muxer.LAST_SAMPLE_DURATION_BEHAVIOR_SET_FROM_END_OF_STREAM_BUFFER; import android.media.MediaCodec; import android.media.MediaCodec.BufferInfo; @@ -185,7 +186,7 @@ public final class InAppMuxer implements Muxer { Mp4Muxer.Builder builder = new Mp4Muxer.Builder(outputStream); if (videoDurationUs != C.TIME_UNSET) { builder.setLastSampleDurationBehavior( - Mp4Muxer.LAST_SAMPLE_DURATION_BEHAVIOR_USING_END_OF_STREAM_FLAG); + LAST_SAMPLE_DURATION_BEHAVIOR_SET_FROM_END_OF_STREAM_BUFFER); } muxer = builder.build(); }