BoxesTest: Add default format builders

Move the common initialization code for format builder into separate methods to reduce code duplication.

PiperOrigin-RevId: 655118764
This commit is contained in:
Googler 2024-07-23 04:51:50 -07:00 committed by Copybara-Service
parent 225d336713
commit 3c5c81fc3e
11 changed files with 30 additions and 145 deletions

View File

@ -19,7 +19,6 @@ import static androidx.media3.muxer.Mp4Muxer.LAST_FRAME_DURATION_BEHAVIOR_DUPLIC
import static androidx.media3.muxer.Mp4Muxer.LAST_FRAME_DURATION_BEHAVIOR_INSERT_SHORT_FRAME; import static androidx.media3.muxer.Mp4Muxer.LAST_FRAME_DURATION_BEHAVIOR_INSERT_SHORT_FRAME;
import static androidx.media3.muxer.MuxerTestUtil.FAKE_AUDIO_FORMAT; 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_CSD_0;
import static androidx.media3.muxer.MuxerTestUtil.FAKE_CSD_1;
import static androidx.media3.muxer.MuxerTestUtil.FAKE_VIDEO_FORMAT; import static androidx.media3.muxer.MuxerTestUtil.FAKE_VIDEO_FORMAT;
import static androidx.media3.muxer.MuxerTestUtil.getExpectedDumpFilePath; import static androidx.media3.muxer.MuxerTestUtil.getExpectedDumpFilePath;
import static com.google.common.truth.Truth.assertThat; import static com.google.common.truth.Truth.assertThat;
@ -235,16 +234,10 @@ public class BoxesTest {
@Test @Test
public void createAudioSampleEntryBox_forMp4a_matchesExpected() throws Exception { public void createAudioSampleEntryBox_forMp4a_matchesExpected() throws Exception {
Format format = Format format =
new Format.Builder() FAKE_AUDIO_FORMAT
.setPeakBitrate(128000) .buildUpon()
.setSampleRate(48000)
.setId(3)
.setSampleMimeType("audio/mp4a-latm") .setSampleMimeType("audio/mp4a-latm")
.setChannelCount(2) .setInitializationData(ImmutableList.of(FAKE_CSD_0))
.setAverageBitrate(128000)
.setLanguage("```")
.setMaxInputSize(502)
.setInitializationData(ImmutableList.of(BaseEncoding.base16().decode("1190")))
.build(); .build();
ByteBuffer audioSampleEntryBox = Boxes.audioSampleEntry(format); ByteBuffer audioSampleEntryBox = Boxes.audioSampleEntry(format);
@ -256,17 +249,7 @@ public class BoxesTest {
@Test @Test
public void createAudioSampleEntryBox_forSamr_matchesExpected() throws Exception { public void createAudioSampleEntryBox_forSamr_matchesExpected() throws Exception {
Format format = Format format = FAKE_AUDIO_FORMAT.buildUpon().setSampleMimeType(MimeTypes.AUDIO_AMR_NB).build();
new Format.Builder()
.setPeakBitrate(128000)
.setSampleRate(48000)
.setId(3)
.setSampleMimeType(MimeTypes.AUDIO_AMR_NB)
.setChannelCount(2)
.setAverageBitrate(128000)
.setLanguage("```")
.setMaxInputSize(502)
.build();
ByteBuffer audioSampleEntryBox = Boxes.audioSampleEntry(format); ByteBuffer audioSampleEntryBox = Boxes.audioSampleEntry(format);
@ -277,17 +260,7 @@ public class BoxesTest {
@Test @Test
public void createAudioSampleEntryBox_forSawb_matchesExpected() throws Exception { public void createAudioSampleEntryBox_forSawb_matchesExpected() throws Exception {
Format format = Format format = FAKE_AUDIO_FORMAT.buildUpon().setSampleMimeType("audio/amr-wb").build();
new Format.Builder()
.setPeakBitrate(128000)
.setSampleRate(48000)
.setId(3)
.setSampleMimeType("audio/amr-wb")
.setChannelCount(2)
.setAverageBitrate(128000)
.setLanguage("```")
.setMaxInputSize(502)
.build();
ByteBuffer audioSampleEntryBox = Boxes.audioSampleEntry(format); ByteBuffer audioSampleEntryBox = Boxes.audioSampleEntry(format);
@ -299,15 +272,9 @@ public class BoxesTest {
@Test @Test
public void createAudioSampleEntryBox_forOpus_matchesExpected() throws Exception { public void createAudioSampleEntryBox_forOpus_matchesExpected() throws Exception {
Format format = Format format =
new Format.Builder() FAKE_AUDIO_FORMAT
.setPeakBitrate(128000) .buildUpon()
.setSampleRate(48000)
.setId(3)
.setSampleMimeType(MimeTypes.AUDIO_OPUS) .setSampleMimeType(MimeTypes.AUDIO_OPUS)
.setChannelCount(6)
.setAverageBitrate(128000)
.setLanguage("```")
.setMaxInputSize(502)
.setInitializationData( .setInitializationData(
ImmutableList.of( ImmutableList.of(
BaseEncoding.base16() BaseEncoding.base16()
@ -324,18 +291,7 @@ public class BoxesTest {
@Test @Test
public void createAudioSampleEntryBox_withUnknownAudioFormat_throws() { public void createAudioSampleEntryBox_withUnknownAudioFormat_throws() {
// The audio format contains an unknown MIME type. // The audio format contains an unknown MIME type.
Format format = Format format = FAKE_AUDIO_FORMAT.buildUpon().setSampleMimeType("audio/mp4a-unknown").build();
new Format.Builder()
.setPeakBitrate(128000)
.setSampleRate(48000)
.setId(3)
.setSampleMimeType("audio/mp4a-unknown")
.setChannelCount(2)
.setAverageBitrate(128000)
.setLanguage("```")
.setMaxInputSize(502)
.setInitializationData(ImmutableList.of(BaseEncoding.base16().decode("1190")))
.build();
assertThrows(IllegalArgumentException.class, () -> Boxes.audioSampleEntry(format)); assertThrows(IllegalArgumentException.class, () -> Boxes.audioSampleEntry(format));
} }
@ -343,14 +299,9 @@ public class BoxesTest {
@Test @Test
public void createVideoSampleEntryBox_forH265_matchesExpected() throws Exception { public void createVideoSampleEntryBox_forH265_matchesExpected() throws Exception {
Format format = Format format =
new Format.Builder() FAKE_VIDEO_FORMAT
.setId(1) .buildUpon()
.setSampleMimeType("video/hevc") .setSampleMimeType("video/hevc")
.setWidth(48)
.setLanguage("und")
.setMaxInputSize(114)
.setFrameRate(25)
.setHeight(32)
.setInitializationData( .setInitializationData(
ImmutableList.of( ImmutableList.of(
BaseEncoding.base16() BaseEncoding.base16()
@ -368,16 +319,9 @@ public class BoxesTest {
@Test @Test
public void createVideoSampleEntryBox_forH265_hdr10_matchesExpected() throws Exception { public void createVideoSampleEntryBox_forH265_hdr10_matchesExpected() throws Exception {
Format format = Format format =
new Format.Builder() FAKE_VIDEO_FORMAT
.setPeakBitrate(9200) .buildUpon()
.setId(1)
.setSampleMimeType("video/hevc") .setSampleMimeType("video/hevc")
.setAverageBitrate(9200)
.setLanguage("und")
.setWidth(256)
.setMaxInputSize(66)
.setFrameRate(25)
.setHeight(256)
.setColorInfo( .setColorInfo(
new ColorInfo.Builder() new ColorInfo.Builder()
.setColorSpace(C.COLOR_SPACE_BT2020) .setColorSpace(C.COLOR_SPACE_BT2020)
@ -402,16 +346,7 @@ public class BoxesTest {
@Test @Test
public void createVideoSampleEntryBox_forH263_matchesExpected() throws Exception { public void createVideoSampleEntryBox_forH263_matchesExpected() throws Exception {
Format format = Format format = FAKE_VIDEO_FORMAT.buildUpon().setSampleMimeType(MimeTypes.VIDEO_H263).build();
new Format.Builder()
.setId(1)
.setSampleMimeType(MimeTypes.VIDEO_H263)
.setLanguage("und")
.setWidth(10)
.setMaxInputSize(39)
.setFrameRate(25)
.setHeight(12)
.build();
ByteBuffer videoSampleEntryBox = Boxes.videoSampleEntry(format); ByteBuffer videoSampleEntryBox = Boxes.videoSampleEntry(format);
@ -422,17 +357,7 @@ public class BoxesTest {
@Test @Test
public void createVideoSampleEntryBox_forH264_matchesExpected() throws Exception { public void createVideoSampleEntryBox_forH264_matchesExpected() throws Exception {
Format format = Format format = FAKE_VIDEO_FORMAT.buildUpon().setSampleMimeType("video/avc").build();
new Format.Builder()
.setId(1)
.setSampleMimeType("video/avc")
.setLanguage("und")
.setWidth(10)
.setMaxInputSize(39)
.setFrameRate(25)
.setHeight(12)
.setInitializationData(ImmutableList.of(FAKE_CSD_0, FAKE_CSD_1))
.build();
ByteBuffer videoSampleEntryBox = Boxes.videoSampleEntry(format); ByteBuffer videoSampleEntryBox = Boxes.videoSampleEntry(format);
@ -443,18 +368,7 @@ public class BoxesTest {
@Test @Test
public void createVideoSampleEntryBox_forAv1_matchesExpected() throws IOException { public void createVideoSampleEntryBox_forAv1_matchesExpected() throws IOException {
Format format = Format format = FAKE_VIDEO_FORMAT.buildUpon().setSampleMimeType("video/av01").build();
new Format.Builder()
.setId(1)
.setSampleMimeType("video/av01")
.setLanguage("und")
.setWidth(10)
.setMaxInputSize(49)
.setFrameRate(25)
.setHeight(12)
.setInitializationData(
ImmutableList.of(BaseEncoding.base16().decode("812000000A09200000019CDBFFF304")))
.build();
ByteBuffer videoSampleEntryBox = Boxes.videoSampleEntry(format); ByteBuffer videoSampleEntryBox = Boxes.videoSampleEntry(format);
@ -465,23 +379,7 @@ public class BoxesTest {
@Test @Test
public void createVideoSampleEntryBox_forMPEG4_matchesExpected() throws IOException { public void createVideoSampleEntryBox_forMPEG4_matchesExpected() throws IOException {
Format format = Format format = FAKE_VIDEO_FORMAT.buildUpon().setSampleMimeType(MimeTypes.VIDEO_MP4V).build();
new Format.Builder()
.setId(1)
.setSampleMimeType(MimeTypes.VIDEO_MP4V)
.setAverageBitrate(9200)
.setPeakBitrate(9200)
.setLanguage("und")
.setWidth(10)
.setMaxInputSize(49)
.setFrameRate(25)
.setHeight(12)
.setInitializationData(
ImmutableList.of(
BaseEncoding.base16()
.decode(
"000001B001000001B58913000001000000012000C48D88007D0584121443000001B24C61766335382E35342E313030")))
.build();
ByteBuffer videoSampleEntryBox = Boxes.videoSampleEntry(format); ByteBuffer videoSampleEntryBox = Boxes.videoSampleEntry(format);
@ -496,20 +394,7 @@ public class BoxesTest {
public void createVideoSampleEntryBox_withUnknownVideoFormat_throws() { public void createVideoSampleEntryBox_withUnknownVideoFormat_throws() {
// The video format contains an unknown MIME type. // The video format contains an unknown MIME type.
Format format = Format format =
new Format.Builder() FAKE_VIDEO_FORMAT.buildUpon().setSampleMimeType("video/someweirdvideoformat").build();
.setId(1)
.setSampleMimeType("video/someweirdvideoformat")
.setWidth(48)
.setLanguage("und")
.setMaxInputSize(114)
.setFrameRate(25)
.setHeight(32)
.setInitializationData(
ImmutableList.of(
BaseEncoding.base16()
.decode(
"0000000140010C01FFFF0408000003009FC800000300001E959809000000014201010408000003009FC800000300001EC1882165959AE4CAE68080000003008000000C84000000014401C173D089")))
.build();
assertThrows(IllegalArgumentException.class, () -> Boxes.videoSampleEntry(format)); assertThrows(IllegalArgumentException.class, () -> Boxes.videoSampleEntry(format));
} }

View File

@ -1,2 +1,2 @@
mp4a (75 bytes): mp4a (101 bytes):
Data = length 67, hash FEDA4F43 Data = length 93, hash E5A8331A

View File

@ -1,2 +1,2 @@
Opus (63 bytes): Opus (63 bytes):
Data = length 55, hash CF9222D3 Data = length 55, hash 439827B8

View File

@ -1,2 +1,2 @@
samr (53 bytes): samr (53 bytes):
Data = length 45, hash 7F055BB3 Data = length 45, hash B1E06854

View File

@ -1,2 +1,2 @@
sawb (53 bytes): sawb (53 bytes):
Data = length 45, hash 7F064471 Data = length 45, hash B1E15112

View File

@ -1,2 +1,2 @@
av01 (125 bytes): av01 (138 bytes):
Data = length 117, hash F51B373 Data = length 130, hash 4FE8371B

View File

@ -1,2 +1,2 @@
s263 (117 bytes): s263 (117 bytes):
Data = length 109, hash B820D1F5 Data = length 109, hash EABCBA75

View File

@ -1,2 +1,2 @@
avc1 (150 bytes): avc1 (150 bytes):
Data = length 142, hash 9A2FF5A9 Data = length 142, hash C0931D29

View File

@ -1,2 +1,2 @@
hvc1 (214 bytes): hvc1 (214 bytes):
Data = length 206, hash C7111A0E Data = length 206, hash 80613554

View File

@ -1,2 +1,2 @@
hvc1 (240 bytes): hvc1 (240 bytes):
Data = length 232, hash 3E864AF8 Data = length 232, hash 9DAB9F90

View File

@ -1,2 +1,2 @@
mp4v (186 bytes): mp4v (167 bytes):
Data = length 178, hash DE771E7E Data = length 159, hash 78156FFF