Remove usage of deprecated methdods from Mp4Muxer tests

PiperOrigin-RevId: 615392633
This commit is contained in:
sheenachhabra 2024-03-13 06:27:41 -07:00 committed by Copybara-Service
parent dfe9fba17d
commit 644d9a3461
2 changed files with 44 additions and 21 deletions

View File

@ -86,7 +86,7 @@ public class Mp4MuxerEndToEndTest {
try { try {
mp4Muxer = new Mp4Muxer.Builder(checkNotNull(outputStream)).build(); mp4Muxer = new Mp4Muxer.Builder(checkNotNull(outputStream)).build();
mp4Muxer.setTimestampData( mp4Muxer.addMetadata(
new Mp4TimestampData( new Mp4TimestampData(
/* creationTimestampSeconds= */ 100_000_000L, /* creationTimestampSeconds= */ 100_000_000L,
/* modificationTimestampSeconds= */ 500_000_000L)); /* modificationTimestampSeconds= */ 500_000_000L));
@ -110,7 +110,7 @@ public class Mp4MuxerEndToEndTest {
// ensure some data has been written after taking all the inputs but before closing the muxer. // ensure some data has been written after taking all the inputs but before closing the muxer.
assumeTrue(checkNotNull(inputFile).equals(H265_HDR10_MP4)); assumeTrue(checkNotNull(inputFile).equals(H265_HDR10_MP4));
Mp4Muxer mp4Muxer = new Mp4Muxer.Builder(checkNotNull(outputStream)).build(); Mp4Muxer mp4Muxer = new Mp4Muxer.Builder(checkNotNull(outputStream)).build();
mp4Muxer.setTimestampData( mp4Muxer.addMetadata(
new Mp4TimestampData( new Mp4TimestampData(
/* creationTimestampSeconds= */ 100_000_000L, /* creationTimestampSeconds= */ 100_000_000L,
/* modificationTimestampSeconds= */ 500_000_000L)); /* modificationTimestampSeconds= */ 500_000_000L));
@ -139,7 +139,7 @@ public class Mp4MuxerEndToEndTest {
try { try {
mp4Muxer = mp4Muxer =
new Mp4Muxer.Builder(checkNotNull(outputStream)).setFragmentedMp4Enabled(true).build(); new Mp4Muxer.Builder(checkNotNull(outputStream)).setFragmentedMp4Enabled(true).build();
mp4Muxer.setTimestampData( mp4Muxer.addMetadata(
new Mp4TimestampData( new Mp4TimestampData(
/* creationTimestampSeconds= */ 100_000_000L, /* creationTimestampSeconds= */ 100_000_000L,
/* modificationTimestampSeconds= */ 500_000_000L)); /* modificationTimestampSeconds= */ 500_000_000L));
@ -170,7 +170,7 @@ public class Mp4MuxerEndToEndTest {
try { try {
mp4Muxer = mp4Muxer =
new Mp4Muxer.Builder(checkNotNull(outputStream)).setFragmentedMp4Enabled(true).build(); new Mp4Muxer.Builder(checkNotNull(outputStream)).setFragmentedMp4Enabled(true).build();
mp4Muxer.setTimestampData( mp4Muxer.addMetadata(
new Mp4TimestampData( new Mp4TimestampData(
/* creationTimestampSeconds= */ 100_000_000L, /* creationTimestampSeconds= */ 100_000_000L,
/* modificationTimestampSeconds= */ 500_000_000L)); /* modificationTimestampSeconds= */ 500_000_000L));

View File

@ -15,15 +15,23 @@
*/ */
package androidx.media3.muxer; package androidx.media3.muxer;
import static androidx.media3.container.MdtaMetadataEntry.KEY_ANDROID_CAPTURE_FPS;
import static androidx.media3.container.MdtaMetadataEntry.TYPE_INDICATOR_FLOAT32;
import static androidx.media3.container.MdtaMetadataEntry.TYPE_INDICATOR_STRING;
import static androidx.media3.muxer.MuxerTestUtil.FAKE_VIDEO_FORMAT; import static androidx.media3.muxer.MuxerTestUtil.FAKE_VIDEO_FORMAT;
import static androidx.media3.muxer.MuxerTestUtil.XMP_SAMPLE_DATA; import static androidx.media3.muxer.MuxerTestUtil.XMP_SAMPLE_DATA;
import android.content.Context; import android.content.Context;
import android.media.MediaCodec.BufferInfo; import android.media.MediaCodec.BufferInfo;
import android.util.Pair; import android.util.Pair;
import androidx.media3.common.util.Util;
import androidx.media3.container.MdtaMetadataEntry;
import androidx.media3.container.Mp4LocationData;
import androidx.media3.container.Mp4OrientationData; import androidx.media3.container.Mp4OrientationData;
import androidx.media3.container.Mp4TimestampData; import androidx.media3.container.Mp4TimestampData;
import androidx.media3.container.XmpData;
import androidx.media3.extractor.mp4.Mp4Extractor; import androidx.media3.extractor.mp4.Mp4Extractor;
import androidx.media3.extractor.text.DefaultSubtitleParserFactory;
import androidx.media3.muxer.Mp4Muxer.TrackToken; import androidx.media3.muxer.Mp4Muxer.TrackToken;
import androidx.media3.test.utils.DumpFileAsserts; import androidx.media3.test.utils.DumpFileAsserts;
import androidx.media3.test.utils.DumpableMp4Box; import androidx.media3.test.utils.DumpableMp4Box;
@ -64,7 +72,8 @@ public class Mp4MuxerMetadataTest {
} }
FakeExtractorOutput fakeExtractorOutput = FakeExtractorOutput fakeExtractorOutput =
TestUtil.extractAllSamplesFromFilePath(new Mp4Extractor(), outputFilePath); TestUtil.extractAllSamplesFromFilePath(
new Mp4Extractor(new DefaultSubtitleParserFactory()), outputFilePath);
// No rotationDegrees field in output dump. // No rotationDegrees field in output dump.
DumpFileAsserts.assertOutput( DumpFileAsserts.assertOutput(
context, context,
@ -91,7 +100,8 @@ public class Mp4MuxerMetadataTest {
} }
FakeExtractorOutput fakeExtractorOutput = FakeExtractorOutput fakeExtractorOutput =
TestUtil.extractAllSamplesFromFilePath(new Mp4Extractor(), outputFilePath); TestUtil.extractAllSamplesFromFilePath(
new Mp4Extractor(new DefaultSubtitleParserFactory()), outputFilePath);
// rotationDegrees = 90 in the output dump. // rotationDegrees = 90 in the output dump.
DumpFileAsserts.assertOutput( DumpFileAsserts.assertOutput(
context, context,
@ -118,7 +128,8 @@ public class Mp4MuxerMetadataTest {
} }
FakeExtractorOutput fakeExtractorOutput = FakeExtractorOutput fakeExtractorOutput =
TestUtil.extractAllSamplesFromFilePath(new Mp4Extractor(), outputFilePath); TestUtil.extractAllSamplesFromFilePath(
new Mp4Extractor(new DefaultSubtitleParserFactory()), outputFilePath);
// rotationDegrees = 180 in the output dump. // rotationDegrees = 180 in the output dump.
DumpFileAsserts.assertOutput( DumpFileAsserts.assertOutput(
context, context,
@ -145,7 +156,8 @@ public class Mp4MuxerMetadataTest {
} }
FakeExtractorOutput fakeExtractorOutput = FakeExtractorOutput fakeExtractorOutput =
TestUtil.extractAllSamplesFromFilePath(new Mp4Extractor(), outputFilePath); TestUtil.extractAllSamplesFromFilePath(
new Mp4Extractor(new DefaultSubtitleParserFactory()), outputFilePath);
// rotationDegrees = 270 in the output dump. // rotationDegrees = 270 in the output dump.
DumpFileAsserts.assertOutput( DumpFileAsserts.assertOutput(
context, context,
@ -165,13 +177,14 @@ public class Mp4MuxerMetadataTest {
/* modificationTimestampSeconds= */ 5_000_000L)); /* modificationTimestampSeconds= */ 5_000_000L));
TrackToken token = muxer.addTrack(/* sortKey= */ 0, FAKE_VIDEO_FORMAT); TrackToken token = muxer.addTrack(/* sortKey= */ 0, FAKE_VIDEO_FORMAT);
muxer.writeSampleData(token, sampleAndSampleInfo.first, sampleAndSampleInfo.second); muxer.writeSampleData(token, sampleAndSampleInfo.first, sampleAndSampleInfo.second);
muxer.setLocation(33.0f, -120f); muxer.addMetadata(new Mp4LocationData(/* latitude= */ 33.0f, /* longitude= */ -120f));
} finally { } finally {
muxer.close(); muxer.close();
} }
FakeExtractorOutput fakeExtractorOutput = FakeExtractorOutput fakeExtractorOutput =
TestUtil.extractAllSamplesFromFilePath(new Mp4Extractor(), outputFilePath); TestUtil.extractAllSamplesFromFilePath(
new Mp4Extractor(new DefaultSubtitleParserFactory()), outputFilePath);
// Xyz data in track metadata dump. // Xyz data in track metadata dump.
DumpFileAsserts.assertOutput( DumpFileAsserts.assertOutput(
context, context,
@ -196,7 +209,8 @@ public class Mp4MuxerMetadataTest {
} }
FakeExtractorOutput fakeExtractorOutput = FakeExtractorOutput fakeExtractorOutput =
TestUtil.extractAllSamplesFromFilePath(new Mp4Extractor(), outputFilePath); TestUtil.extractAllSamplesFromFilePath(
new Mp4Extractor(new DefaultSubtitleParserFactory()), outputFilePath);
// No xyz data in track metadata dump. // No xyz data in track metadata dump.
DumpFileAsserts.assertOutput( DumpFileAsserts.assertOutput(
context, context,
@ -214,7 +228,10 @@ public class Mp4MuxerMetadataTest {
new Mp4TimestampData( new Mp4TimestampData(
/* creationTimestampSeconds= */ 1_000_000L, /* creationTimestampSeconds= */ 1_000_000L,
/* modificationTimestampSeconds= */ 5_000_000L)); /* modificationTimestampSeconds= */ 5_000_000L));
muxer.setCaptureFps(120.0f); float captureFps = 120.0f;
muxer.addMetadata(
new MdtaMetadataEntry(
KEY_ANDROID_CAPTURE_FPS, Util.toByteArray(captureFps), TYPE_INDICATOR_FLOAT32));
TrackToken token = muxer.addTrack(/* sortKey= */ 0, FAKE_VIDEO_FORMAT); TrackToken token = muxer.addTrack(/* sortKey= */ 0, FAKE_VIDEO_FORMAT);
muxer.writeSampleData(token, sampleAndSampleInfo.first, sampleAndSampleInfo.second); muxer.writeSampleData(token, sampleAndSampleInfo.first, sampleAndSampleInfo.second);
} finally { } finally {
@ -222,7 +239,8 @@ public class Mp4MuxerMetadataTest {
} }
FakeExtractorOutput fakeExtractorOutput = FakeExtractorOutput fakeExtractorOutput =
TestUtil.extractAllSamplesFromFilePath(new Mp4Extractor(), outputFilePath); TestUtil.extractAllSamplesFromFilePath(
new Mp4Extractor(new DefaultSubtitleParserFactory()), outputFilePath);
// android.capture.fps data in the track metadata dump. // android.capture.fps data in the track metadata dump.
DumpFileAsserts.assertOutput( DumpFileAsserts.assertOutput(
context, context,
@ -240,7 +258,9 @@ public class Mp4MuxerMetadataTest {
new Mp4TimestampData( new Mp4TimestampData(
/* creationTimestampSeconds= */ 1_000_000L, /* creationTimestampSeconds= */ 1_000_000L,
/* modificationTimestampSeconds= */ 5_000_000L)); /* modificationTimestampSeconds= */ 5_000_000L));
muxer.addMetadata("SomeStringKey", "Some Random String"); muxer.addMetadata(
new MdtaMetadataEntry(
"SomeStringKey", Util.getUtf8Bytes("Some Random String"), TYPE_INDICATOR_STRING));
TrackToken token = muxer.addTrack(/* sortKey= */ 0, FAKE_VIDEO_FORMAT); TrackToken token = muxer.addTrack(/* sortKey= */ 0, FAKE_VIDEO_FORMAT);
muxer.writeSampleData(token, sampleAndSampleInfo.first, sampleAndSampleInfo.second); muxer.writeSampleData(token, sampleAndSampleInfo.first, sampleAndSampleInfo.second);
} finally { } finally {
@ -248,7 +268,8 @@ public class Mp4MuxerMetadataTest {
} }
FakeExtractorOutput fakeExtractorOutput = FakeExtractorOutput fakeExtractorOutput =
TestUtil.extractAllSamplesFromFilePath(new Mp4Extractor(), outputFilePath); TestUtil.extractAllSamplesFromFilePath(
new Mp4Extractor(new DefaultSubtitleParserFactory()), outputFilePath);
// Added string metadata should be present in the track metadata dump. // Added string metadata should be present in the track metadata dump.
DumpFileAsserts.assertOutput( DumpFileAsserts.assertOutput(
context, context,
@ -266,7 +287,10 @@ public class Mp4MuxerMetadataTest {
new Mp4TimestampData( new Mp4TimestampData(
/* creationTimestampSeconds= */ 1_000_000L, /* creationTimestampSeconds= */ 1_000_000L,
/* modificationTimestampSeconds= */ 5_000_000L)); /* modificationTimestampSeconds= */ 5_000_000L));
muxer.addMetadata("SomeStringKey", 10.0f); float floatValue = 10.0f;
muxer.addMetadata(
new MdtaMetadataEntry(
"SomeStringKey", Util.toByteArray(floatValue), TYPE_INDICATOR_FLOAT32));
TrackToken token = muxer.addTrack(/* sortKey= */ 0, FAKE_VIDEO_FORMAT); TrackToken token = muxer.addTrack(/* sortKey= */ 0, FAKE_VIDEO_FORMAT);
muxer.writeSampleData(token, sampleAndSampleInfo.first, sampleAndSampleInfo.second); muxer.writeSampleData(token, sampleAndSampleInfo.first, sampleAndSampleInfo.second);
} finally { } finally {
@ -274,7 +298,8 @@ public class Mp4MuxerMetadataTest {
} }
FakeExtractorOutput fakeExtractorOutput = FakeExtractorOutput fakeExtractorOutput =
TestUtil.extractAllSamplesFromFilePath(new Mp4Extractor(), outputFilePath); TestUtil.extractAllSamplesFromFilePath(
new Mp4Extractor(new DefaultSubtitleParserFactory()), outputFilePath);
// Added float metadata should be present in the track metadata dump. // Added float metadata should be present in the track metadata dump.
DumpFileAsserts.assertOutput( DumpFileAsserts.assertOutput(
context, context,
@ -288,15 +313,13 @@ public class Mp4MuxerMetadataTest {
Mp4Muxer muxer = new Mp4Muxer.Builder(new FileOutputStream(outputFilePath)).build(); Mp4Muxer muxer = new Mp4Muxer.Builder(new FileOutputStream(outputFilePath)).build();
try { try {
muxer.setTimestampData( muxer.addMetadata(
new Mp4TimestampData( new Mp4TimestampData(
/* creationTimestampSeconds= */ 1_000_000L, /* creationTimestampSeconds= */ 1_000_000L,
/* modificationTimestampSeconds= */ 5_000_000L)); /* modificationTimestampSeconds= */ 5_000_000L));
Context context = ApplicationProvider.getApplicationContext(); Context context = ApplicationProvider.getApplicationContext();
byte[] xmpBytes = TestUtil.getByteArray(context, XMP_SAMPLE_DATA); byte[] xmpBytes = TestUtil.getByteArray(context, XMP_SAMPLE_DATA);
ByteBuffer xmp = ByteBuffer.wrap(xmpBytes); muxer.addMetadata(new XmpData(xmpBytes));
muxer.addXmp(xmp);
xmp.rewind();
TrackToken token = muxer.addTrack(0, FAKE_VIDEO_FORMAT); TrackToken token = muxer.addTrack(0, FAKE_VIDEO_FORMAT);
muxer.writeSampleData(token, sampleAndSampleInfo.first, sampleAndSampleInfo.second); muxer.writeSampleData(token, sampleAndSampleInfo.first, sampleAndSampleInfo.second);
} finally { } finally {