Commit 99e699a3 by Dustin

Clean up tests

parent bec8b44b
package com.google.android.exoplayer2.extractor.avi; package com.google.android.exoplayer2.extractor.avi;
import androidx.annotation.VisibleForTesting;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.HashMap; import java.util.HashMap;
...@@ -55,4 +56,20 @@ public class VideoFormat { ...@@ -55,4 +56,20 @@ public class VideoFormat {
public String getMimeType() { public String getMimeType() {
return STREAM_MAP.get(getCompression()); return STREAM_MAP.get(getCompression());
} }
@VisibleForTesting
public void setWidth(final int width) {
byteBuffer.putInt(4, width);
}
@VisibleForTesting
public void setHeight(final int height) {
byteBuffer.putInt(8, height);
}
@VisibleForTesting
public void setCompression(final int compression) {
byteBuffer.putInt(16, compression);
}
} }
...@@ -20,14 +20,14 @@ import org.junit.runner.RunWith; ...@@ -20,14 +20,14 @@ import org.junit.runner.RunWith;
public class AviExtractorRoboTest { public class AviExtractorRoboTest {
@Test @Test
public void parseStream_givenH264StreamList() throws IOException { public void parseStream_givenXvidStreamList() throws IOException {
final AviExtractor aviExtractor = new AviExtractor(); final AviExtractor aviExtractor = new AviExtractor();
final FakeExtractorOutput fakeExtractorOutput = new FakeExtractorOutput(); final FakeExtractorOutput fakeExtractorOutput = new FakeExtractorOutput();
aviExtractor.init(fakeExtractorOutput); aviExtractor.init(fakeExtractorOutput);
final ListBox streamList = DataHelper.getVideoStreamList(); final ListBox streamList = DataHelper.getVideoStreamList();
aviExtractor.parseStream(streamList, 0); aviExtractor.parseStream(streamList, 0);
FakeTrackOutput trackOutput = fakeExtractorOutput.track(0, C.TRACK_TYPE_VIDEO); FakeTrackOutput trackOutput = fakeExtractorOutput.track(0, C.TRACK_TYPE_VIDEO);
Assert.assertEquals(MimeTypes.VIDEO_H264, trackOutput.lastFormat.sampleMimeType); Assert.assertEquals(MimeTypes.VIDEO_MP4V, trackOutput.lastFormat.sampleMimeType);
} }
@Test @Test
......
package com.google.android.exoplayer2.extractor.avi; package com.google.android.exoplayer2.extractor.avi;
import android.content.Context;
import androidx.test.core.app.ApplicationProvider;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.testutil.FakeExtractorInput;
import com.google.android.exoplayer2.testutil.FakeTrackOutput; import com.google.android.exoplayer2.testutil.FakeTrackOutput;
import java.io.File; import com.google.android.exoplayer2.testutil.TestUtil;
import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
...@@ -19,22 +19,6 @@ public class DataHelper { ...@@ -19,22 +19,6 @@ public class DataHelper {
static final int AUDIO_SIZE = 256; static final int AUDIO_SIZE = 256;
static final int AUDIO_ID = 1; static final int AUDIO_ID = 1;
static final int MOVI_OFFSET = 4096; static final int MOVI_OFFSET = 4096;
private static final long AUDIO_US = VIDEO_US / AUDIO_PER_VIDEO;
//Base path "\ExoPlayer\library\extractor\."
private static final File RELATIVE_PATH = new File("../../testdata/src/test/assets/extractordumps/avi/");
public static FakeExtractorInput getInput(final String fileName) throws IOException {
return new FakeExtractorInput.Builder().setData(getBytes(fileName)).build();
}
public static byte[] getBytes(final String fileName) throws IOException {
final File file = new File(RELATIVE_PATH, fileName);
try (FileInputStream in = new FileInputStream(file)) {
final byte[] buffer = new byte[in.available()];
in.read(buffer);
return buffer;
}
}
public static StreamHeaderBox getStreamHeader(int type, int scale, int rate, int length) { public static StreamHeaderBox getStreamHeader(int type, int scale, int rate, int length) {
final ByteBuffer byteBuffer = AviExtractor.allocate(0x40); final ByteBuffer byteBuffer = AviExtractor.allocate(0x40);
...@@ -55,20 +39,23 @@ public class DataHelper { ...@@ -55,20 +39,23 @@ public class DataHelper {
} }
public static StreamFormatBox getAacStreamFormat() throws IOException { public static StreamFormatBox getAacStreamFormat() throws IOException {
final byte[] buffer = getBytes("aac_stream_format.dump"); final Context context = ApplicationProvider.getApplicationContext();
final byte[] buffer = TestUtil.getByteArray(context,"extractordumps/avi/aac_stream_format.dump");
final ByteBuffer byteBuffer = ByteBuffer.wrap(buffer); final ByteBuffer byteBuffer = ByteBuffer.wrap(buffer);
byteBuffer.order(ByteOrder.LITTLE_ENDIAN); byteBuffer.order(ByteOrder.LITTLE_ENDIAN);
return new StreamFormatBox(StreamFormatBox.STRF, buffer.length, byteBuffer); return new StreamFormatBox(StreamFormatBox.STRF, buffer.length, byteBuffer);
} }
public static StreamFormatBox getVideoStreamFormat() throws IOException { public static StreamFormatBox getVideoStreamFormat() {
final byte[] buffer = getBytes("h264_stream_format.dump"); final ByteBuffer byteBuffer = AviExtractor.allocate(40);
final ByteBuffer byteBuffer = ByteBuffer.wrap(buffer); final VideoFormat videoFormat = new VideoFormat(byteBuffer);
byteBuffer.order(ByteOrder.LITTLE_ENDIAN); videoFormat.setWidth(720);
return new StreamFormatBox(StreamFormatBox.STRF, buffer.length, byteBuffer); videoFormat.setHeight(480);
videoFormat.setCompression(VideoFormat.XVID);
return new StreamFormatBox(StreamFormatBox.STRF, byteBuffer.capacity(), byteBuffer);
} }
public static ListBox getVideoStreamList() throws IOException { public static ListBox getVideoStreamList() {
final StreamHeaderBox streamHeaderBox = getVidsStreamHeader(); final StreamHeaderBox streamHeaderBox = getVidsStreamHeader();
final StreamFormatBox streamFormatBox = getVideoStreamFormat(); final StreamFormatBox streamFormatBox = getVideoStreamFormat();
final ArrayList<Box> list = new ArrayList<>(2); final ArrayList<Box> list = new ArrayList<>(2);
...@@ -162,8 +149,6 @@ public class DataHelper { ...@@ -162,8 +149,6 @@ public class DataHelper {
/** /**
* Get the RIFF header up to AVI Header * Get the RIFF header up to AVI Header
* @param bufferSize
* @return
*/ */
public static ByteBuffer getRiffHeader(int bufferSize, int headerListSize) { public static ByteBuffer getRiffHeader(int bufferSize, int headerListSize) {
ByteBuffer byteBuffer = AviExtractor.allocate(bufferSize); ByteBuffer byteBuffer = AviExtractor.allocate(bufferSize);
......
package com.google.android.exoplayer2.extractor.avi; package com.google.android.exoplayer2.extractor.avi;
import android.content.Context;
import androidx.test.core.app.ApplicationProvider;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.Format; import com.google.android.exoplayer2.Format;
import com.google.android.exoplayer2.testutil.FakeExtractorInput; import com.google.android.exoplayer2.testutil.FakeExtractorInput;
import com.google.android.exoplayer2.testutil.FakeTrackOutput; import com.google.android.exoplayer2.testutil.FakeTrackOutput;
import com.google.android.exoplayer2.testutil.TestUtil;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class Mp4vChunkPeekerTest { public class Mp4vChunkPeekerTest {
private ByteBuffer makeSequence() { private ByteBuffer makeSequence() {
...@@ -30,8 +36,10 @@ public class Mp4vChunkPeekerTest { ...@@ -30,8 +36,10 @@ public class Mp4vChunkPeekerTest {
public void peek_givenAspectRatio() throws IOException { public void peek_givenAspectRatio() throws IOException {
final FakeTrackOutput fakeTrackOutput = new FakeTrackOutput(false); final FakeTrackOutput fakeTrackOutput = new FakeTrackOutput(false);
final Format.Builder formatBuilder = new Format.Builder(); final Format.Builder formatBuilder = new Format.Builder();
final Context context = ApplicationProvider.getApplicationContext();
final byte[] bytes = TestUtil.getByteArray(context, "extractordumps/avi/mp4v_sequence.dump");
final FakeExtractorInput input = new FakeExtractorInput.Builder().setData(bytes).build();
final Mp4vChunkPeeker mp4vChunkPeeker = new Mp4vChunkPeeker(formatBuilder, fakeTrackOutput); final Mp4vChunkPeeker mp4vChunkPeeker = new Mp4vChunkPeeker(formatBuilder, fakeTrackOutput);
final FakeExtractorInput input = DataHelper.getInput("mp4v_sequence.dump");
mp4vChunkPeeker.peek(input, (int) input.getLength()); mp4vChunkPeeker.peek(input, (int) input.getLength());
Assert.assertEquals(1.2121212, mp4vChunkPeeker.pixelWidthHeightRatio, 0.01); Assert.assertEquals(1.2121212, mp4vChunkPeeker.pixelWidthHeightRatio, 0.01);
......
package com.google.android.exoplayer2.extractor.avi; package com.google.android.exoplayer2.extractor.avi;
import com.google.android.exoplayer2.util.MimeTypes;
import java.io.IOException; import java.io.IOException;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
...@@ -9,7 +10,8 @@ public class VideoFormatTest { ...@@ -9,7 +10,8 @@ public class VideoFormatTest {
public void getters_givenVideoStreamFormat() throws IOException { public void getters_givenVideoStreamFormat() throws IOException {
final StreamFormatBox streamFormatBox = DataHelper.getVideoStreamFormat(); final StreamFormatBox streamFormatBox = DataHelper.getVideoStreamFormat();
final VideoFormat videoFormat = streamFormatBox.getVideoFormat(); final VideoFormat videoFormat = streamFormatBox.getVideoFormat();
Assert.assertEquals(712, videoFormat.getWidth()); Assert.assertEquals(720, videoFormat.getWidth());
Assert.assertEquals(464, videoFormat.getHeight()); Assert.assertEquals(480, videoFormat.getHeight());
Assert.assertEquals(MimeTypes.VIDEO_MP4V, videoFormat.getMimeType());
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment