AvcChunkPeeker tests

This commit is contained in:
Dustin 2022-01-31 10:52:12 -07:00
parent d006f3f473
commit 5f76e0fa04
5 changed files with 111 additions and 1 deletions

View File

@ -34,7 +34,7 @@ public class AvcChunkPeeker extends NalChunkPeeker {
picCountClock = new PicCountClock(clock.durationUs, clock.length);
}
public LinearClock getClock() {
public PicCountClock getClock() {
return picCountClock;
}
@ -131,4 +131,9 @@ public class AvcChunkPeeker extends NalChunkPeeker {
compact();
}
}
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
public NalUnitUtil.SpsData getSpsData() {
return spsData;
}
}

View File

@ -1,5 +1,7 @@
package com.google.android.exoplayer2.extractor.avi;
import androidx.annotation.VisibleForTesting;
/**
* Properly calculates the frame time for H264 frames using PicCount
*/
@ -60,4 +62,14 @@ public class PicCountClock extends LinearClock {
public long getUs() {
return getUs(picIndex);
}
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
int getMaxPicCount() {
return maxPicCount;
}
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
int getLastPicCount() {
return lastPicCount;
}
}

View File

@ -0,0 +1,65 @@
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.testutil.FakeExtractorInput;
import com.google.android.exoplayer2.testutil.FakeTrackOutput;
import com.google.android.exoplayer2.testutil.TestUtil;
import com.google.android.exoplayer2.util.MimeTypes;
import java.io.IOException;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class AvcChunkPeekerTest {
private static final Format.Builder FORMAT_BUILDER_AVC = new Format.Builder().
setSampleMimeType(MimeTypes.VIDEO_H264).
setWidth(1280).setHeight(720).setFrameRate(24000f/1001f);
private static final byte[] P_SLICE = {00,00,00,01,0x41,(byte)0x9A,0x13,0x36,0x21,0x3A,0x5F,
(byte)0xFE,(byte)0x9E,0x10,00,00};
private FakeTrackOutput fakeTrackOutput;
private AvcChunkPeeker avcChunkPeeker;
@Before
public void before() {
fakeTrackOutput = new FakeTrackOutput(false);
avcChunkPeeker = new AvcChunkPeeker(FORMAT_BUILDER_AVC, fakeTrackOutput,
new LinearClock(10_000_000L, 24 * 10));
}
private void peekStreamHeader() throws IOException {
final Context context = ApplicationProvider.getApplicationContext();
final byte[] bytes =
TestUtil.getByteArray(context,"extractordumps/avi/avc_sei_sps_pps_ird.dump");
final FakeExtractorInput input = new FakeExtractorInput.Builder().setData(bytes).build();
avcChunkPeeker.peek(input, bytes.length);
}
@Test
public void peek_givenStreamHeader() throws IOException {
peekStreamHeader();
final PicCountClock picCountClock = avcChunkPeeker.getClock();
Assert.assertEquals(64, picCountClock.getMaxPicCount());
Assert.assertEquals(0, avcChunkPeeker.getSpsData().picOrderCountType);
Assert.assertEquals(1.18f, fakeTrackOutput.lastFormat.pixelWidthHeightRatio, 0.01f);
}
@Test
public void peek_givenStreamHeaderAndPSlice() throws IOException {
peekStreamHeader();
final PicCountClock picCountClock = avcChunkPeeker.getClock();
final FakeExtractorInput input = new FakeExtractorInput.Builder().setData(P_SLICE).build();
avcChunkPeeker.peek(input, P_SLICE.length);
Assert.assertEquals(12, picCountClock.getLastPicCount());
}
}

View File

@ -0,0 +1,15 @@
package com.google.android.exoplayer2.extractor.avi;
import org.junit.Assert;
import org.junit.Test;
public class AviTrackTest {
@Test
public void setClock_givenLinearClock() {
final LinearClock linearClock = new LinearClock(1_000_000L, 30);
final AviTrack aviTrack = DataHelper.getVideoAviTrack(1);
aviTrack.setClock(linearClock);
Assert.assertSame(linearClock, aviTrack.getClock());
}
}

View File

@ -30,6 +30,19 @@ public class BitBuffer {
work |= (value & 0xffffffffL);
}
public void pushExpGolomb(final int i) {
if (i == 0) {
push(true);
}
int v = i + 1;
int zeroBits = 0;
while ((v >>>=1) > 1) {
zeroBits++;
}
final int bits = zeroBits * 2 + 1;
push(bits, i + 1);
}
public byte[] getBytes() {
//Byte align
grow(8 - bits % 8);