Group NAL type constants in NalUnitUtil

To be shared with AviExtractor in a later CL.

PiperOrigin-RevId: 436430385
This commit is contained in:
aquilescanta 2022-03-22 10:32:35 +00:00 committed by Ian Baker
parent 57953d8947
commit 5b4abc31f3
2 changed files with 26 additions and 20 deletions

View file

@ -31,6 +31,21 @@ public final class NalUnitUtil {
private static final String TAG = "NalUnitUtil";
/** Coded slice of a non-IDR picture. */
public static final int NAL_UNIT_TYPE_NON_IDR = 1;
/** Coded slice data partition A. */
public static final int NAL_UNIT_TYPE_PARTITION_A = 2;
/** Coded slice of an IDR picture. */
public static final int NAL_UNIT_TYPE_IDR = 5;
/** Supplemental enhancement information. */
public static final int NAL_UNIT_TYPE_SEI = 6;
/** Sequence parameter set. */
public static final int NAL_UNIT_TYPE_SPS = 7;
/** Picture parameter set. */
public static final int NAL_UNIT_TYPE_PPS = 8;
/** Access unit delimiter. */
public static final int NAL_UNIT_TYPE_AUD = 9;
/** Holds data parsed from a H.264 sequence parameter set NAL unit. */
public static final class SpsData {

View file

@ -44,10 +44,6 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
@UnstableApi
public final class H264Reader implements ElementaryStreamReader {
private static final int NAL_UNIT_TYPE_SEI = 6; // Supplemental enhancement information
private static final int NAL_UNIT_TYPE_SPS = 7; // Sequence parameter set
private static final int NAL_UNIT_TYPE_PPS = 8; // Picture parameter set
private final SeiReader seiReader;
private final boolean allowNonIdrKeyframes;
private final boolean detectAccessUnits;
@ -85,9 +81,9 @@ public final class H264Reader implements ElementaryStreamReader {
this.allowNonIdrKeyframes = allowNonIdrKeyframes;
this.detectAccessUnits = detectAccessUnits;
prefixFlags = new boolean[3];
sps = new NalUnitTargetBuffer(NAL_UNIT_TYPE_SPS, 128);
pps = new NalUnitTargetBuffer(NAL_UNIT_TYPE_PPS, 128);
sei = new NalUnitTargetBuffer(NAL_UNIT_TYPE_SEI, 128);
sps = new NalUnitTargetBuffer(NalUnitUtil.NAL_UNIT_TYPE_SPS, 128);
pps = new NalUnitTargetBuffer(NalUnitUtil.NAL_UNIT_TYPE_PPS, 128);
sei = new NalUnitTargetBuffer(NalUnitUtil.NAL_UNIT_TYPE_SEI, 128);
pesTimeUs = C.TIME_UNSET;
seiWrapper = new ParsableByteArray();
}
@ -266,11 +262,6 @@ public final class H264Reader implements ElementaryStreamReader {
private static final int DEFAULT_BUFFER_SIZE = 128;
private static final int NAL_UNIT_TYPE_NON_IDR = 1; // Coded slice of a non-IDR picture
private static final int NAL_UNIT_TYPE_PARTITION_A = 2; // Coded slice data partition A
private static final int NAL_UNIT_TYPE_IDR = 5; // Coded slice of an IDR picture
private static final int NAL_UNIT_TYPE_AUD = 9; // Access unit delimiter
private final TrackOutput output;
private final boolean allowNonIdrKeyframes;
private final boolean detectAccessUnits;
@ -331,11 +322,11 @@ public final class H264Reader implements ElementaryStreamReader {
nalUnitType = type;
nalUnitTimeUs = pesTimeUs;
nalUnitStartPosition = position;
if ((allowNonIdrKeyframes && nalUnitType == NAL_UNIT_TYPE_NON_IDR)
if ((allowNonIdrKeyframes && nalUnitType == NalUnitUtil.NAL_UNIT_TYPE_NON_IDR)
|| (detectAccessUnits
&& (nalUnitType == NAL_UNIT_TYPE_IDR
|| nalUnitType == NAL_UNIT_TYPE_NON_IDR
|| nalUnitType == NAL_UNIT_TYPE_PARTITION_A))) {
&& (nalUnitType == NalUnitUtil.NAL_UNIT_TYPE_IDR
|| nalUnitType == NalUnitUtil.NAL_UNIT_TYPE_NON_IDR
|| nalUnitType == NalUnitUtil.NAL_UNIT_TYPE_PARTITION_A))) {
// Store the previous header and prepare to populate the new one.
SliceHeaderData newSliceHeader = previousSliceHeader;
previousSliceHeader = sliceHeader;
@ -425,7 +416,7 @@ public final class H264Reader implements ElementaryStreamReader {
bottomFieldFlagPresent = true;
}
}
boolean idrPicFlag = nalUnitType == NAL_UNIT_TYPE_IDR;
boolean idrPicFlag = nalUnitType == NalUnitUtil.NAL_UNIT_TYPE_IDR;
int idrPicId = 0;
if (idrPicFlag) {
if (!bitArray.canReadExpGolombCodedNum()) {
@ -480,7 +471,7 @@ public final class H264Reader implements ElementaryStreamReader {
public boolean endNalUnit(
long position, int offset, boolean hasOutputFormat, boolean randomAccessIndicator) {
if (nalUnitType == NAL_UNIT_TYPE_AUD
if (nalUnitType == NalUnitUtil.NAL_UNIT_TYPE_AUD
|| (detectAccessUnits && sliceHeader.isFirstVclNalUnitOfPicture(previousSliceHeader))) {
// If the NAL unit ending is the start of a new sample, output the previous one.
if (hasOutputFormat && readingSample) {
@ -495,8 +486,8 @@ public final class H264Reader implements ElementaryStreamReader {
boolean treatIFrameAsKeyframe =
allowNonIdrKeyframes ? sliceHeader.isISlice() : randomAccessIndicator;
sampleIsKeyframe |=
nalUnitType == NAL_UNIT_TYPE_IDR
|| (treatIFrameAsKeyframe && nalUnitType == NAL_UNIT_TYPE_NON_IDR);
nalUnitType == NalUnitUtil.NAL_UNIT_TYPE_IDR
|| (treatIFrameAsKeyframe && nalUnitType == NalUnitUtil.NAL_UNIT_TYPE_NON_IDR);
return sampleIsKeyframe;
}