Commit 5b4abc31 by aquilescanta Committed by Ian Baker

Group NAL type constants in NalUnitUtil

To be shared with AviExtractor in a later CL.

PiperOrigin-RevId: 436430385
parent 57953d89
...@@ -31,6 +31,21 @@ public final class NalUnitUtil { ...@@ -31,6 +31,21 @@ public final class NalUnitUtil {
private static final String TAG = "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. */ /** Holds data parsed from a H.264 sequence parameter set NAL unit. */
public static final class SpsData { public static final class SpsData {
......
...@@ -44,10 +44,6 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -44,10 +44,6 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
@UnstableApi @UnstableApi
public final class H264Reader implements ElementaryStreamReader { 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 SeiReader seiReader;
private final boolean allowNonIdrKeyframes; private final boolean allowNonIdrKeyframes;
private final boolean detectAccessUnits; private final boolean detectAccessUnits;
...@@ -85,9 +81,9 @@ public final class H264Reader implements ElementaryStreamReader { ...@@ -85,9 +81,9 @@ public final class H264Reader implements ElementaryStreamReader {
this.allowNonIdrKeyframes = allowNonIdrKeyframes; this.allowNonIdrKeyframes = allowNonIdrKeyframes;
this.detectAccessUnits = detectAccessUnits; this.detectAccessUnits = detectAccessUnits;
prefixFlags = new boolean[3]; prefixFlags = new boolean[3];
sps = new NalUnitTargetBuffer(NAL_UNIT_TYPE_SPS, 128); sps = new NalUnitTargetBuffer(NalUnitUtil.NAL_UNIT_TYPE_SPS, 128);
pps = new NalUnitTargetBuffer(NAL_UNIT_TYPE_PPS, 128); pps = new NalUnitTargetBuffer(NalUnitUtil.NAL_UNIT_TYPE_PPS, 128);
sei = new NalUnitTargetBuffer(NAL_UNIT_TYPE_SEI, 128); sei = new NalUnitTargetBuffer(NalUnitUtil.NAL_UNIT_TYPE_SEI, 128);
pesTimeUs = C.TIME_UNSET; pesTimeUs = C.TIME_UNSET;
seiWrapper = new ParsableByteArray(); seiWrapper = new ParsableByteArray();
} }
...@@ -266,11 +262,6 @@ public final class H264Reader implements ElementaryStreamReader { ...@@ -266,11 +262,6 @@ public final class H264Reader implements ElementaryStreamReader {
private static final int DEFAULT_BUFFER_SIZE = 128; 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 TrackOutput output;
private final boolean allowNonIdrKeyframes; private final boolean allowNonIdrKeyframes;
private final boolean detectAccessUnits; private final boolean detectAccessUnits;
...@@ -331,11 +322,11 @@ public final class H264Reader implements ElementaryStreamReader { ...@@ -331,11 +322,11 @@ public final class H264Reader implements ElementaryStreamReader {
nalUnitType = type; nalUnitType = type;
nalUnitTimeUs = pesTimeUs; nalUnitTimeUs = pesTimeUs;
nalUnitStartPosition = position; nalUnitStartPosition = position;
if ((allowNonIdrKeyframes && nalUnitType == NAL_UNIT_TYPE_NON_IDR) if ((allowNonIdrKeyframes && nalUnitType == NalUnitUtil.NAL_UNIT_TYPE_NON_IDR)
|| (detectAccessUnits || (detectAccessUnits
&& (nalUnitType == NAL_UNIT_TYPE_IDR && (nalUnitType == NalUnitUtil.NAL_UNIT_TYPE_IDR
|| nalUnitType == NAL_UNIT_TYPE_NON_IDR || nalUnitType == NalUnitUtil.NAL_UNIT_TYPE_NON_IDR
|| nalUnitType == NAL_UNIT_TYPE_PARTITION_A))) { || nalUnitType == NalUnitUtil.NAL_UNIT_TYPE_PARTITION_A))) {
// Store the previous header and prepare to populate the new one. // Store the previous header and prepare to populate the new one.
SliceHeaderData newSliceHeader = previousSliceHeader; SliceHeaderData newSliceHeader = previousSliceHeader;
previousSliceHeader = sliceHeader; previousSliceHeader = sliceHeader;
...@@ -425,7 +416,7 @@ public final class H264Reader implements ElementaryStreamReader { ...@@ -425,7 +416,7 @@ public final class H264Reader implements ElementaryStreamReader {
bottomFieldFlagPresent = true; bottomFieldFlagPresent = true;
} }
} }
boolean idrPicFlag = nalUnitType == NAL_UNIT_TYPE_IDR; boolean idrPicFlag = nalUnitType == NalUnitUtil.NAL_UNIT_TYPE_IDR;
int idrPicId = 0; int idrPicId = 0;
if (idrPicFlag) { if (idrPicFlag) {
if (!bitArray.canReadExpGolombCodedNum()) { if (!bitArray.canReadExpGolombCodedNum()) {
...@@ -480,7 +471,7 @@ public final class H264Reader implements ElementaryStreamReader { ...@@ -480,7 +471,7 @@ public final class H264Reader implements ElementaryStreamReader {
public boolean endNalUnit( public boolean endNalUnit(
long position, int offset, boolean hasOutputFormat, boolean randomAccessIndicator) { 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))) { || (detectAccessUnits && sliceHeader.isFirstVclNalUnitOfPicture(previousSliceHeader))) {
// If the NAL unit ending is the start of a new sample, output the previous one. // If the NAL unit ending is the start of a new sample, output the previous one.
if (hasOutputFormat && readingSample) { if (hasOutputFormat && readingSample) {
...@@ -495,8 +486,8 @@ public final class H264Reader implements ElementaryStreamReader { ...@@ -495,8 +486,8 @@ public final class H264Reader implements ElementaryStreamReader {
boolean treatIFrameAsKeyframe = boolean treatIFrameAsKeyframe =
allowNonIdrKeyframes ? sliceHeader.isISlice() : randomAccessIndicator; allowNonIdrKeyframes ? sliceHeader.isISlice() : randomAccessIndicator;
sampleIsKeyframe |= sampleIsKeyframe |=
nalUnitType == NAL_UNIT_TYPE_IDR nalUnitType == NalUnitUtil.NAL_UNIT_TYPE_IDR
|| (treatIFrameAsKeyframe && nalUnitType == NAL_UNIT_TYPE_NON_IDR); || (treatIFrameAsKeyframe && nalUnitType == NalUnitUtil.NAL_UNIT_TYPE_NON_IDR);
return sampleIsKeyframe; return sampleIsKeyframe;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment