diff --git a/libraries/muxer/src/androidTest/java/androidx/media3/muxer/Mp4MuxerEndToEndNonParameterizedAndroidTest.java b/libraries/muxer/src/androidTest/java/androidx/media3/muxer/Mp4MuxerEndToEndNonParameterizedAndroidTest.java new file mode 100644 index 0000000000..66dd862383 --- /dev/null +++ b/libraries/muxer/src/androidTest/java/androidx/media3/muxer/Mp4MuxerEndToEndNonParameterizedAndroidTest.java @@ -0,0 +1,82 @@ +/* + * Copyright 2023 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package androidx.media3.muxer; + +import static androidx.media3.common.util.Assertions.checkNotNull; +import static androidx.media3.muxer.AndroidMuxerTestUtil.feedInputDataToMuxer; + +import android.content.Context; +import androidx.media3.container.Mp4TimestampData; +import androidx.media3.extractor.mp4.Mp4Extractor; +import androidx.media3.test.utils.DumpFileAsserts; +import androidx.media3.test.utils.FakeExtractorOutput; +import androidx.media3.test.utils.TestUtil; +import androidx.test.core.app.ApplicationProvider; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import java.io.FileOutputStream; +import java.io.IOException; +import org.checkerframework.checker.nullness.qual.MonotonicNonNull; +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.junit.runner.RunWith; + +/** End to end instrumentation tests for {@link Mp4Muxer}. */ +@RunWith(AndroidJUnit4.class) +public class Mp4MuxerEndToEndNonParameterizedAndroidTest { + private static final String H265_HDR10_MP4 = "hdr10-720p.mp4"; + + @Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder(); + + private final Context context = ApplicationProvider.getApplicationContext(); + private @MonotonicNonNull String outputPath; + private @MonotonicNonNull FileOutputStream outputStream; + + @Before + public void setUp() throws Exception { + outputPath = temporaryFolder.newFile("muxeroutput.mp4").getPath(); + outputStream = new FileOutputStream(outputPath); + } + + @After + public void tearDown() throws IOException { + checkNotNull(outputStream).close(); + } + + @Test + public void createMp4File_muxerNotClosed_createsPartiallyWrittenValidFile() throws Exception { + Mp4Muxer mp4Muxer = new Mp4Muxer.Builder(checkNotNull(outputStream)).build(); + mp4Muxer.addMetadataEntry( + new Mp4TimestampData( + /* creationTimestampSeconds= */ 100_000_000L, + /* modificationTimestampSeconds= */ 500_000_000L)); + feedInputDataToMuxer(context, mp4Muxer, H265_HDR10_MP4); + + // Muxer not closed. + + // Audio sample written = 192 out of 195. + // Video sample written = 94 out of 127. + // Output is still a valid MP4 file. + FakeExtractorOutput fakeExtractorOutput = + TestUtil.extractAllSamplesFromFilePath(new Mp4Extractor(), checkNotNull(outputPath)); + DumpFileAsserts.assertOutput( + context, + fakeExtractorOutput, + AndroidMuxerTestUtil.getExpectedDumpFilePath("partial_" + H265_HDR10_MP4)); + } +} diff --git a/libraries/muxer/src/androidTest/java/androidx/media3/muxer/Mp4MuxerEndToEndAndroidTest.java b/libraries/muxer/src/androidTest/java/androidx/media3/muxer/Mp4MuxerEndToEndParameterizedAndroidTest.java similarity index 73% rename from libraries/muxer/src/androidTest/java/androidx/media3/muxer/Mp4MuxerEndToEndAndroidTest.java rename to libraries/muxer/src/androidTest/java/androidx/media3/muxer/Mp4MuxerEndToEndParameterizedAndroidTest.java index c13938b514..cdea32d3ed 100644 --- a/libraries/muxer/src/androidTest/java/androidx/media3/muxer/Mp4MuxerEndToEndAndroidTest.java +++ b/libraries/muxer/src/androidTest/java/androidx/media3/muxer/Mp4MuxerEndToEndParameterizedAndroidTest.java @@ -17,7 +17,6 @@ package androidx.media3.muxer; import static androidx.media3.common.util.Assertions.checkNotNull; import static androidx.media3.muxer.AndroidMuxerTestUtil.feedInputDataToMuxer; -import static org.junit.Assume.assumeTrue; import android.content.Context; import androidx.annotation.Nullable; @@ -41,9 +40,9 @@ import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameter; import org.junit.runners.Parameterized.Parameters; -/** End to end instrumentation tests for {@link Mp4Muxer}. */ +/** End to end parameterized instrumentation tests for {@link Mp4Muxer}. */ @RunWith(Parameterized.class) -public class Mp4MuxerEndToEndAndroidTest { +public class Mp4MuxerEndToEndParameterizedAndroidTest { private static final String H264_MP4 = "sample_no_bframes.mp4"; private static final String H264_WITH_NON_REFERENCE_B_FRAMES_MP4 = "bbb_800x640_768kbps_30fps_avc_non_reference_3b.mp4"; @@ -104,30 +103,4 @@ public class Mp4MuxerEndToEndAndroidTest { DumpFileAsserts.assertOutput( context, fakeExtractorOutput, AndroidMuxerTestUtil.getExpectedDumpFilePath(inputFile)); } - - @Test - public void createMp4File_muxerNotClosed_createsPartiallyWrittenValidFile() throws Exception { - // Skip for all parameter values except when the input is a large file. The muxer writes samples - // in batches (and flushes data only when it's closed), so a large input file is needed to - // ensure some data has been written after taking all the inputs but before closing the muxer. - assumeTrue(checkNotNull(inputFile).equals(H265_HDR10_MP4)); - Mp4Muxer mp4Muxer = new Mp4Muxer.Builder(checkNotNull(outputStream)).build(); - mp4Muxer.addMetadataEntry( - new Mp4TimestampData( - /* creationTimestampSeconds= */ 100_000_000L, - /* modificationTimestampSeconds= */ 500_000_000L)); - feedInputDataToMuxer(context, mp4Muxer, inputFile); - - // Muxer not closed. - - // Audio sample written = 192 out of 195. - // Video sample written = 94 out of 127. - // Output is still a valid MP4 file. - FakeExtractorOutput fakeExtractorOutput = - TestUtil.extractAllSamplesFromFilePath(new Mp4Extractor(), checkNotNull(outputPath)); - DumpFileAsserts.assertOutput( - context, - fakeExtractorOutput, - AndroidMuxerTestUtil.getExpectedDumpFilePath("partial_" + inputFile)); - } }