mirror of
https://github.com/samsonjs/media.git
synced 2026-04-04 11:05:47 +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;
|
||||
}
|
||||
|
||||
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||
long getMoviOffset() {
|
||||
return moviOffset;
|
||||
}
|
||||
|
||||
private static void w(String message) {
|
||||
try {
|
||||
Log.w(TAG, message);
|
||||
|
|
|
|||
|
|
@ -265,6 +265,29 @@ public class AviExtractorTest {
|
|||
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
|
||||
public void alignPositionHolder_givenOddPosition() {
|
||||
final FakeExtractorInput fakeExtractorInput = new FakeExtractorInput.Builder().
|
||||
|
|
@ -471,4 +494,12 @@ public class AviExtractorTest {
|
|||
aviExtractor.setAviTracks(new AviTrack[]{null, aviTrack});
|
||||
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, ...
|
||||
*/
|
||||
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 videoChunkId = AviTrack.getVideoChunkId(0);
|
||||
final int audioChunkId = AviTrack.getAudioChunkId(1);
|
||||
int offset = 4;
|
||||
final ByteBuffer byteBuffer = AviExtractor.allocate((videoFrames + videoFrames*AUDIO_PER_VIDEO) * 16);
|
||||
|
||||
for (int v=0;v<videoFrames;v++) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue