diff --git a/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/avi/AudioFormat.java b/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/avi/AudioFormat.java index 6bb5a5e81a..0a8b03ce1f 100644 --- a/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/avi/AudioFormat.java +++ b/library/extractor/src/main/java/com/google/android/exoplayer2/extractor/avi/AudioFormat.java @@ -6,8 +6,8 @@ import java.nio.ByteBuffer; public class AudioFormat { public static final short WAVE_FORMAT_PCM = 1; + static final short WAVE_FORMAT_AAC = 0xff; private static final short WAVE_FORMAT_MPEGLAYER3 = 0x55; - private static final short WAVE_FORMAT_AAC = 0xff; private static final short WAVE_FORMAT_DVM = 0x2000; //AC3 private static final short WAVE_FORMAT_DTS2 = 0x2001; //DTS private static final SparseArray FORMAT_MAP = new SparseArray<>(); @@ -40,9 +40,10 @@ public class AudioFormat { return byteBuffer.getInt(4); } // 8 - nAvgBytesPerSec(uint) - public int getBlockAlign() { - return byteBuffer.getShort(12); - } + // 12 - nBlockAlign +// public int getBlockAlign() { +// return byteBuffer.getShort(12); +// } public short getBitsPerSample() { return byteBuffer.getShort(14); } diff --git a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/AudioFormatTest.java b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/AudioFormatTest.java new file mode 100644 index 0000000000..63cfd5c108 --- /dev/null +++ b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/AudioFormatTest.java @@ -0,0 +1,25 @@ +package com.google.android.exoplayer2.extractor.avi; + +import androidx.test.ext.junit.runners.AndroidJUnit4; +import com.google.android.exoplayer2.util.MimeTypes; +import java.io.IOException; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; + +@RunWith(AndroidJUnit4.class) +public class AudioFormatTest { + final byte[] CODEC_PRIVATE = {0x11, (byte) 0x90}; + + @Test + public void getters_givenAacStreamFormat() throws IOException { + final StreamFormatBox streamFormatBox = DataHelper.getAudioStreamFormat(); + final AudioFormat audioFormat = streamFormatBox.getAudioFormat(); + Assert.assertEquals(MimeTypes.AUDIO_AAC, audioFormat.getMimeType()); + Assert.assertEquals(2, audioFormat.getChannels()); + Assert.assertEquals(AudioFormat.WAVE_FORMAT_AAC, audioFormat.getFormatTag()); + Assert.assertEquals(48000, audioFormat.getSamplesPerSecond()); + Assert.assertEquals(0, audioFormat.getBitsPerSample()); //Not meaningful for AAC + Assert.assertArrayEquals(CODEC_PRIVATE, audioFormat.getCodecData()); + } +} diff --git a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/DataHelper.java b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/DataHelper.java index b60472bcb6..4762a40e1b 100644 --- a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/DataHelper.java +++ b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/DataHelper.java @@ -29,4 +29,18 @@ public class DataHelper { byteBuffer.order(ByteOrder.LITTLE_ENDIAN); return new StreamHeaderBox(StreamHeaderBox.STRH, buffer.length, byteBuffer); } + + public static StreamFormatBox getAudioStreamFormat() throws IOException { + final byte[] buffer = getBytes("aac_stream_format.dump"); + final ByteBuffer byteBuffer = ByteBuffer.wrap(buffer); + byteBuffer.order(ByteOrder.LITTLE_ENDIAN); + return new StreamFormatBox(StreamFormatBox.STRF, buffer.length, byteBuffer); + } + + public static StreamFormatBox getVideoStreamFormat() throws IOException { + final byte[] buffer = getBytes("h264_stream_format.dump"); + final ByteBuffer byteBuffer = ByteBuffer.wrap(buffer); + byteBuffer.order(ByteOrder.LITTLE_ENDIAN); + return new StreamFormatBox(StreamFormatBox.STRF, buffer.length, byteBuffer); + } } diff --git a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/UnboundedIntArrayTest.java b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/UnboundedIntArrayTest.java new file mode 100644 index 0000000000..2f0f9078e4 --- /dev/null +++ b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/UnboundedIntArrayTest.java @@ -0,0 +1,54 @@ +package com.google.android.exoplayer2.extractor.avi; + +import org.junit.Assert; +import org.junit.Test; + +public class UnboundedIntArrayTest { + @Test + public void add_givenInt() { + final UnboundedIntArray unboundedIntArray = new UnboundedIntArray(); + unboundedIntArray.add(4); + Assert.assertEquals(1, unboundedIntArray.getSize()); + Assert.assertEquals(unboundedIntArray.array[0], 4); + } + + @Test + public void indexOf_givenOrderSet() { + final UnboundedIntArray unboundedIntArray = new UnboundedIntArray(); + unboundedIntArray.add(2); + unboundedIntArray.add(4); + unboundedIntArray.add(5); + unboundedIntArray.add(8); + Assert.assertEquals(2, unboundedIntArray.indexOf(5)); + Assert.assertTrue(unboundedIntArray.indexOf(6) < 0); + } + + @Test + public void grow_givenSizeOfOne() { + final UnboundedIntArray unboundedIntArray = new UnboundedIntArray(1); + unboundedIntArray.add(0); + Assert.assertEquals(1, unboundedIntArray.getSize()); + unboundedIntArray.add(1); + Assert.assertTrue(unboundedIntArray.getSize() > 1); + } + + @Test + public void pack_givenSizeOfOne() { + final UnboundedIntArray unboundedIntArray = new UnboundedIntArray(8); + unboundedIntArray.add(1); + unboundedIntArray.add(2); + Assert.assertEquals(8, unboundedIntArray.array.length); + unboundedIntArray.pack(); + Assert.assertEquals(2, unboundedIntArray.array.length); + } + + @Test + public void illegalArgument_givenNegativeSize() { + try { + new UnboundedIntArray(-1); + Assert.fail(); + } catch (IllegalArgumentException e) { + //Intentionally blank + } + } +} diff --git a/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/VideoFormatTest.java b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/VideoFormatTest.java new file mode 100644 index 0000000000..7f4d6d5d08 --- /dev/null +++ b/library/extractor/src/test/java/com/google/android/exoplayer2/extractor/avi/VideoFormatTest.java @@ -0,0 +1,15 @@ +package com.google.android.exoplayer2.extractor.avi; + +import java.io.IOException; +import org.junit.Assert; +import org.junit.Test; + +public class VideoFormatTest { + @Test + public void getters_givenVideoStreamFormat() throws IOException { + final StreamFormatBox streamFormatBox = DataHelper.getVideoStreamFormat(); + final VideoFormat videoFormat = streamFormatBox.getVideoFormat(); + Assert.assertEquals(712, videoFormat.getWidth()); + Assert.assertEquals(464, videoFormat.getHeight()); + } +} diff --git a/testdata/src/test/assets/extractordumps/avi/aac_stream_format.dump b/testdata/src/test/assets/extractordumps/avi/aac_stream_format.dump new file mode 100644 index 0000000000..6d7d7e37a9 Binary files /dev/null and b/testdata/src/test/assets/extractordumps/avi/aac_stream_format.dump differ diff --git a/testdata/src/test/assets/extractordumps/avi/h264_stream_format.dump b/testdata/src/test/assets/extractordumps/avi/h264_stream_format.dump new file mode 100644 index 0000000000..b1a99e6525 Binary files /dev/null and b/testdata/src/test/assets/extractordumps/avi/h264_stream_format.dump differ