mirror of
https://github.com/samsonjs/media.git
synced 2026-04-27 15:07:40 +00:00
Group NAL type constants in NalUnitUtil
To be shared with AviExtractor in a later CL. PiperOrigin-RevId: 436430385
This commit is contained in:
parent
57953d8947
commit
5b4abc31f3
2 changed files with 26 additions and 20 deletions
|
|
@ -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;
|
||||||
@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 {
|
||||||
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 {
|
||||||
|
|
||||||
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 {
|
||||||
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 {
|
||||||
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 {
|
||||||
|
|
||||||
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 {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue