mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Beef up readIdx1 tests
This commit is contained in:
parent
9bd93ad98e
commit
d006f3f473
3 changed files with 44 additions and 1 deletions
|
|
@ -629,6 +629,11 @@ public class AviExtractor implements Extractor {
|
||||||
chunkHandler = aviTrack;
|
chunkHandler = aviTrack;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||||
|
long getMoviOffset() {
|
||||||
|
return moviOffset;
|
||||||
|
}
|
||||||
|
|
||||||
private static void w(String message) {
|
private static void w(String message) {
|
||||||
try {
|
try {
|
||||||
Log.w(TAG, message);
|
Log.w(TAG, message);
|
||||||
|
|
|
||||||
|
|
@ -265,6 +265,29 @@ public class AviExtractorTest {
|
||||||
Assert.assertSame(AviTrack.ALL_KEY_FRAMES, videoTrack.keyFrames);
|
Assert.assertSame(AviTrack.ALL_KEY_FRAMES, videoTrack.keyFrames);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void readIdx1_givenBufferToShort() throws IOException {
|
||||||
|
final AviExtractor aviExtractor = setupVideoAviExtractor();
|
||||||
|
final FakeExtractorInput fakeExtractorInput = new FakeExtractorInput.Builder().
|
||||||
|
setData(new byte[12]).build();
|
||||||
|
|
||||||
|
aviExtractor.readIdx1(fakeExtractorInput, 12);
|
||||||
|
final FakeExtractorOutput fakeExtractorOutput = (FakeExtractorOutput) aviExtractor.output;
|
||||||
|
Assert.assertTrue(fakeExtractorOutput.seekMap instanceof SeekMap.Unseekable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void readIdx1_givenBadOffset() throws IOException {
|
||||||
|
final AviExtractor aviExtractor = setupVideoAviExtractor();
|
||||||
|
final int secs = 4;
|
||||||
|
final ByteBuffer idx1 = DataHelper.getIndex(secs, 1, (int)aviExtractor.getMoviOffset() + 4);
|
||||||
|
|
||||||
|
final FakeExtractorInput fakeExtractorInput = new FakeExtractorInput.Builder().
|
||||||
|
setData(idx1.array()).build();
|
||||||
|
aviExtractor.readIdx1(fakeExtractorInput, (int) fakeExtractorInput.getLength());
|
||||||
|
Assert.assertEquals(0, aviExtractor.aviSeekMap.seekOffset);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void alignPositionHolder_givenOddPosition() {
|
public void alignPositionHolder_givenOddPosition() {
|
||||||
final FakeExtractorInput fakeExtractorInput = new FakeExtractorInput.Builder().
|
final FakeExtractorInput fakeExtractorInput = new FakeExtractorInput.Builder().
|
||||||
|
|
@ -471,4 +494,12 @@ public class AviExtractorTest {
|
||||||
aviExtractor.setAviTracks(new AviTrack[]{null, aviTrack});
|
aviExtractor.setAviTracks(new AviTrack[]{null, aviTrack});
|
||||||
Assert.assertSame(aviTrack, aviExtractor.getAviTrack(aviTrack.chunkId));
|
Assert.assertSame(aviTrack, aviExtractor.getAviTrack(aviTrack.chunkId));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void release() {
|
||||||
|
//Shameless way to get 100% method coverage
|
||||||
|
final AviExtractor aviExtractor = new AviExtractor();
|
||||||
|
aviExtractor.release();
|
||||||
|
//Nothing to assert on a method that does nothing
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -129,10 +129,17 @@ public class DataHelper {
|
||||||
* @param keyFrameRate Key frame rate 1= every frame, 2=every other, ...
|
* @param keyFrameRate Key frame rate 1= every frame, 2=every other, ...
|
||||||
*/
|
*/
|
||||||
public static ByteBuffer getIndex(final int secs, final int keyFrameRate) {
|
public static ByteBuffer getIndex(final int secs, final int keyFrameRate) {
|
||||||
|
return getIndex(secs, keyFrameRate, 4);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param secs Number of seconds
|
||||||
|
* @param keyFrameRate Key frame rate 1= every frame, 2=every other, ...
|
||||||
|
*/
|
||||||
|
public static ByteBuffer getIndex(final int secs, final int keyFrameRate, int offset) {
|
||||||
final int videoFrames = secs * FPS;
|
final int videoFrames = secs * FPS;
|
||||||
final int videoChunkId = AviTrack.getVideoChunkId(0);
|
final int videoChunkId = AviTrack.getVideoChunkId(0);
|
||||||
final int audioChunkId = AviTrack.getAudioChunkId(1);
|
final int audioChunkId = AviTrack.getAudioChunkId(1);
|
||||||
int offset = 4;
|
|
||||||
final ByteBuffer byteBuffer = AviExtractor.allocate((videoFrames + videoFrames*AUDIO_PER_VIDEO) * 16);
|
final ByteBuffer byteBuffer = AviExtractor.allocate((videoFrames + videoFrames*AUDIO_PER_VIDEO) * 16);
|
||||||
|
|
||||||
for (int v=0;v<videoFrames;v++) {
|
for (int v=0;v<videoFrames;v++) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue