mirror of
https://github.com/androidx/media.git
synced 2025-05-07 07:30:22 +08:00
AvcChunkPeeker tests
This commit is contained in:
parent
d006f3f473
commit
5f76e0fa04
@ -34,7 +34,7 @@ public class AvcChunkPeeker extends NalChunkPeeker {
|
|||||||
picCountClock = new PicCountClock(clock.durationUs, clock.length);
|
picCountClock = new PicCountClock(clock.durationUs, clock.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LinearClock getClock() {
|
public PicCountClock getClock() {
|
||||||
return picCountClock;
|
return picCountClock;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -131,4 +131,9 @@ public class AvcChunkPeeker extends NalChunkPeeker {
|
|||||||
compact();
|
compact();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||||
|
public NalUnitUtil.SpsData getSpsData() {
|
||||||
|
return spsData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package com.google.android.exoplayer2.extractor.avi;
|
package com.google.android.exoplayer2.extractor.avi;
|
||||||
|
|
||||||
|
import androidx.annotation.VisibleForTesting;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Properly calculates the frame time for H264 frames using PicCount
|
* Properly calculates the frame time for H264 frames using PicCount
|
||||||
*/
|
*/
|
||||||
@ -60,4 +62,14 @@ public class PicCountClock extends LinearClock {
|
|||||||
public long getUs() {
|
public long getUs() {
|
||||||
return getUs(picIndex);
|
return getUs(picIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||||
|
int getMaxPicCount() {
|
||||||
|
return maxPicCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting(otherwise = VisibleForTesting.NONE)
|
||||||
|
int getLastPicCount() {
|
||||||
|
return lastPicCount;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
@ -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());
|
||||||
|
}
|
||||||
|
}
|
@ -30,6 +30,19 @@ public class BitBuffer {
|
|||||||
work |= (value & 0xffffffffL);
|
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() {
|
public byte[] getBytes() {
|
||||||
//Byte align
|
//Byte align
|
||||||
grow(8 - bits % 8);
|
grow(8 - bits % 8);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user