Commit df9e51de by Dustin

More AviExtractor tests

parent 432ff5ea
...@@ -12,8 +12,8 @@ public class Box { ...@@ -12,8 +12,8 @@ public class Box {
this.size = size; this.size = size;
} }
public long getSize() { public int getSize() {
return size & AviExtractor.UINT_MASK; return size;
} }
public int getType() { public int getType() {
......
...@@ -2,10 +2,15 @@ package com.google.android.exoplayer2.extractor.avi; ...@@ -2,10 +2,15 @@ package com.google.android.exoplayer2.extractor.avi;
import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.ext.junit.runners.AndroidJUnit4;
import com.google.android.exoplayer2.C; import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.extractor.Extractor;
import com.google.android.exoplayer2.extractor.ExtractorInput;
import com.google.android.exoplayer2.extractor.PositionHolder;
import com.google.android.exoplayer2.testutil.FakeExtractorInput;
import com.google.android.exoplayer2.testutil.FakeExtractorOutput; import com.google.android.exoplayer2.testutil.FakeExtractorOutput;
import com.google.android.exoplayer2.testutil.FakeTrackOutput; import com.google.android.exoplayer2.testutil.FakeTrackOutput;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.Collections; import java.util.Collections;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
...@@ -55,4 +60,41 @@ public class AviExtractorRoboTest { ...@@ -55,4 +60,41 @@ public class AviExtractorRoboTest {
Assert.assertNull(aviExtractor.parseStream(streamList, 0)); Assert.assertNull(aviExtractor.parseStream(streamList, 0));
} }
@Test
public void readTracks_givenVideoTrack() throws IOException {
final AviExtractor aviExtractor = new AviExtractor();
aviExtractor.setAviHeader(DataHelper.createAviHeaderBox());
final FakeExtractorOutput fakeExtractorOutput = new FakeExtractorOutput();
aviExtractor.init(fakeExtractorOutput);
final ByteBuffer byteBuffer = DataHelper.getRiffHeader(0xdc, 0xc8);
final ByteBuffer aviHeader = DataHelper.createAviHeader();
byteBuffer.putInt(aviHeader.capacity());
byteBuffer.put(aviHeader);
byteBuffer.putInt(ListBox.LIST);
byteBuffer.putInt(byteBuffer.remaining() - 4);
byteBuffer.putInt(AviExtractor.STRL);
final StreamHeaderBox streamHeaderBox = DataHelper.getVidsStreamHeader();
byteBuffer.putInt(StreamHeaderBox.STRH);
byteBuffer.putInt(streamHeaderBox.getSize());
byteBuffer.put(streamHeaderBox.getByteBuffer());
final StreamFormatBox streamFormatBox = DataHelper.getVideoStreamFormat();
byteBuffer.putInt(StreamFormatBox.STRF);
byteBuffer.putInt(streamFormatBox.getSize());
byteBuffer.put(streamFormatBox.getByteBuffer());
aviExtractor.state = AviExtractor.STATE_READ_TRACKS;
final ExtractorInput input = new FakeExtractorInput.Builder().setData(byteBuffer.array()).
build();
final PositionHolder positionHolder = new PositionHolder();
aviExtractor.read(input, positionHolder);
Assert.assertEquals(AviExtractor.STATE_FIND_MOVI, aviExtractor.state);
final AviTrack aviTrack = aviExtractor.getVideoTrack();
Assert.assertEquals(aviTrack.getClock().durationUs, streamHeaderBox.getDurationUs());
}
} }
...@@ -180,12 +180,26 @@ public class AviExtractorTest { ...@@ -180,12 +180,26 @@ public class AviExtractorTest {
final AviTrack videoTrack = DataHelper.getVideoAviTrack(secs); final AviTrack videoTrack = DataHelper.getVideoAviTrack(secs);
final AviTrack audioTrack = DataHelper.getAudioAviTrack(secs); final AviTrack audioTrack = DataHelper.getAudioAviTrack(secs);
aviExtractor.setAviTracks(new AviTrack[]{videoTrack, audioTrack}); aviExtractor.setAviTracks(new AviTrack[]{videoTrack, audioTrack});
aviExtractor.setAviHeader(DataHelper.createAviHeaderBox());
aviExtractor.state = AviExtractor.STATE_READ_IDX1;
aviExtractor.setMovi(DataHelper.MOVI_OFFSET, 128*1024);
final ByteBuffer idx1Box = AviExtractor.allocate(idx1.capacity() + 8);
idx1Box.putInt(AviExtractor.IDX1);
idx1Box.putInt(idx1.capacity());
idx1.clear();
idx1Box.put(idx1);
final FakeExtractorInput fakeExtractorInput = new FakeExtractorInput.Builder() final FakeExtractorInput fakeExtractorInput = new FakeExtractorInput.Builder()
.setData(idx1.array()).build(); .setData(idx1Box.array()).build();
aviExtractor.readIdx1(fakeExtractorInput, (int) fakeExtractorInput.getLength()); //aviExtractor.readIdx1(fakeExtractorInput, (int) fakeExtractorInput.getLength());
final PositionHolder positionHolder = new PositionHolder();
aviExtractor.read(fakeExtractorInput, positionHolder);
final AviSeekMap aviSeekMap = aviExtractor.aviSeekMap; final AviSeekMap aviSeekMap = aviExtractor.aviSeekMap;
assertIdx1(aviSeekMap, videoTrack, keyFrames, keyFrameRate); assertIdx1(aviSeekMap, videoTrack, keyFrames, keyFrameRate);
Assert.assertEquals(AviExtractor.STATE_READ_SAMPLES, aviExtractor.state);
Assert.assertEquals(DataHelper.MOVI_OFFSET + 4, positionHolder.position);
} }
@Test @Test
...@@ -353,7 +367,7 @@ public class AviExtractorTest { ...@@ -353,7 +367,7 @@ public class AviExtractorTest {
Assert.assertEquals(64 * 1024 + 8, positionHolder.position); Assert.assertEquals(64 * 1024 + 8, positionHolder.position);
} }
private AviExtractor setupReadSamples() { private AviExtractor setupVideoAviExtractor() {
final AviExtractor aviExtractor = new AviExtractor(); final AviExtractor aviExtractor = new AviExtractor();
aviExtractor.setAviHeader(DataHelper.createAviHeaderBox()); aviExtractor.setAviHeader(DataHelper.createAviHeaderBox());
final FakeExtractorOutput fakeExtractorOutput = new FakeExtractorOutput(); final FakeExtractorOutput fakeExtractorOutput = new FakeExtractorOutput();
...@@ -371,7 +385,7 @@ public class AviExtractorTest { ...@@ -371,7 +385,7 @@ public class AviExtractorTest {
@Test @Test
public void readSamples_givenAtEndOfInput() throws IOException { public void readSamples_givenAtEndOfInput() throws IOException {
AviExtractor aviExtractor = setupReadSamples(); AviExtractor aviExtractor = setupVideoAviExtractor();
aviExtractor.setMovi(0, 0); aviExtractor.setMovi(0, 0);
final AviTrack aviTrack = aviExtractor.getVideoTrack(); final AviTrack aviTrack = aviExtractor.getVideoTrack();
final ByteBuffer byteBuffer = AviExtractor.allocate(32); final ByteBuffer byteBuffer = AviExtractor.allocate(32);
...@@ -384,7 +398,7 @@ public class AviExtractorTest { ...@@ -384,7 +398,7 @@ public class AviExtractorTest {
@Test @Test
public void readSamples_completeChunk() throws IOException { public void readSamples_completeChunk() throws IOException {
AviExtractor aviExtractor = setupReadSamples(); AviExtractor aviExtractor = setupVideoAviExtractor();
final AviTrack aviTrack = aviExtractor.getVideoTrack(); final AviTrack aviTrack = aviExtractor.getVideoTrack();
final ByteBuffer byteBuffer = AviExtractor.allocate(32); final ByteBuffer byteBuffer = AviExtractor.allocate(32);
byteBuffer.putInt(aviTrack.chunkId); byteBuffer.putInt(aviTrack.chunkId);
...@@ -400,7 +414,7 @@ public class AviExtractorTest { ...@@ -400,7 +414,7 @@ public class AviExtractorTest {
@Test @Test
public void readSamples_fragmentedChunk() throws IOException { public void readSamples_fragmentedChunk() throws IOException {
AviExtractor aviExtractor = setupReadSamples(); AviExtractor aviExtractor = setupVideoAviExtractor();
final AviTrack aviTrack = aviExtractor.getVideoTrack(); final AviTrack aviTrack = aviExtractor.getVideoTrack();
final int size = 24 + 16; final int size = 24 + 16;
final ByteBuffer byteBuffer = AviExtractor.allocate(32); final ByteBuffer byteBuffer = AviExtractor.allocate(32);
...@@ -421,7 +435,7 @@ public class AviExtractorTest { ...@@ -421,7 +435,7 @@ public class AviExtractorTest {
@Test @Test
public void seek_givenPosition0() throws IOException { public void seek_givenPosition0() throws IOException {
final AviExtractor aviExtractor = setupReadSamples(); final AviExtractor aviExtractor = setupVideoAviExtractor();
final AviTrack aviTrack = aviExtractor.getVideoTrack(); final AviTrack aviTrack = aviExtractor.getVideoTrack();
aviExtractor.setChunkHandler(aviTrack); aviExtractor.setChunkHandler(aviTrack);
aviTrack.getClock().setIndex(10); aviTrack.getClock().setIndex(10);
...@@ -440,8 +454,8 @@ public class AviExtractorTest { ...@@ -440,8 +454,8 @@ public class AviExtractorTest {
} }
@Test @Test
public void seek_givenKeyFrame() throws IOException { public void seek_givenKeyFrame() {
final AviExtractor aviExtractor = setupReadSamples(); final AviExtractor aviExtractor = setupVideoAviExtractor();
final AviSeekMap aviSeekMap = DataHelper.getAviSeekMap(); final AviSeekMap aviSeekMap = DataHelper.getAviSeekMap();
aviExtractor.aviSeekMap = aviSeekMap; aviExtractor.aviSeekMap = aviSeekMap;
final AviTrack aviTrack = aviExtractor.getVideoTrack(); final AviTrack aviTrack = aviExtractor.getVideoTrack();
...@@ -449,4 +463,5 @@ public class AviExtractorTest { ...@@ -449,4 +463,5 @@ public class AviExtractorTest {
aviExtractor.seek(position, 0L); aviExtractor.seek(position, 0L);
Assert.assertEquals(aviSeekMap.seekIndexes[aviTrack.id][1], aviTrack.getClock().getIndex()); Assert.assertEquals(aviSeekMap.seekIndexes[aviTrack.id][1], aviTrack.getClock().getIndex());
} }
} }
\ No newline at end of file
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