Tests for AudioFormat, VideoFormat and UnboundedIntArray

This commit is contained in:
Dustin 2022-01-22 22:10:12 -07:00
parent c4cf876ddb
commit 3daa74dceb
7 changed files with 113 additions and 4 deletions

View file

@ -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<String> 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);
}

View file

@ -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());
}
}

View file

@ -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);
}
}

View file

@ -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
}
}
}

View file

@ -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());
}
}

Binary file not shown.

Binary file not shown.