Rabbit-R1/switch port/java/sources/androidx/media3/container/NalUnitUtil.java

691 lines
30 KiB
Java
Raw Normal View History

2024-05-21 16:08:36 -05:00
package androidx.media3.container;
import androidx.media3.common.ColorInfo;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.Log;
import com.google.common.base.Ascii;
import java.nio.ByteBuffer;
import java.util.Arrays;
/* loaded from: classes2.dex */
public final class NalUnitUtil {
public static final int EXTENDED_SAR = 255;
private static final int H264_NAL_UNIT_TYPE_SEI = 6;
private static final int H264_NAL_UNIT_TYPE_SPS = 7;
private static final int H265_NAL_UNIT_TYPE_PREFIX_SEI = 39;
public static final int NAL_UNIT_TYPE_AUD = 9;
public static final int NAL_UNIT_TYPE_IDR = 5;
public static final int NAL_UNIT_TYPE_NON_IDR = 1;
public static final int NAL_UNIT_TYPE_PARTITION_A = 2;
public static final int NAL_UNIT_TYPE_PPS = 8;
public static final int NAL_UNIT_TYPE_SEI = 6;
public static final int NAL_UNIT_TYPE_SPS = 7;
private static final String TAG = "NalUnitUtil";
public static final byte[] NAL_START_CODE = {0, 0, 0, 1};
public static final float[] ASPECT_RATIO_IDC_VALUES = {1.0f, 1.0f, 1.0909091f, 0.90909094f, 1.4545455f, 1.2121212f, 2.1818182f, 1.8181819f, 2.909091f, 2.4242425f, 1.6363636f, 1.3636364f, 1.939394f, 1.6161616f, 1.3333334f, 1.5f, 2.0f};
private static final Object scratchEscapePositionsLock = new Object();
private static int[] scratchEscapePositions = new int[10];
/* loaded from: classes2.dex */
public static final class SpsData {
public final int colorRange;
public final int colorSpace;
public final int colorTransfer;
public final int constraintsFlagsAndReservedZero2Bits;
public final boolean deltaPicOrderAlwaysZeroFlag;
public final boolean frameMbsOnlyFlag;
public final int frameNumLength;
public final int height;
public final int levelIdc;
public final int maxNumRefFrames;
public final int picOrderCntLsbLength;
public final int picOrderCountType;
public final float pixelWidthHeightRatio;
public final int profileIdc;
public final boolean separateColorPlaneFlag;
public final int seqParameterSetId;
public final int width;
public SpsData(int i, int i2, int i3, int i4, int i5, int i6, int i7, float f, boolean z, boolean z2, int i8, int i9, int i10, boolean z3, int i11, int i12, int i13) {
this.profileIdc = i;
this.constraintsFlagsAndReservedZero2Bits = i2;
this.levelIdc = i3;
this.seqParameterSetId = i4;
this.maxNumRefFrames = i5;
this.width = i6;
this.height = i7;
this.pixelWidthHeightRatio = f;
this.separateColorPlaneFlag = z;
this.frameMbsOnlyFlag = z2;
this.frameNumLength = i8;
this.picOrderCountType = i9;
this.picOrderCntLsbLength = i10;
this.deltaPicOrderAlwaysZeroFlag = z3;
this.colorSpace = i11;
this.colorRange = i12;
this.colorTransfer = i13;
}
}
/* loaded from: classes2.dex */
public static final class H265SpsData {
public final int bitDepthChromaMinus8;
public final int bitDepthLumaMinus8;
public final int chromaFormatIdc;
public final int colorRange;
public final int colorSpace;
public final int colorTransfer;
public final int[] constraintBytes;
public final int generalLevelIdc;
public final int generalProfileCompatibilityFlags;
public final int generalProfileIdc;
public final int generalProfileSpace;
public final boolean generalTierFlag;
public final int height;
public final float pixelWidthHeightRatio;
public final int seqParameterSetId;
public final int width;
public H265SpsData(int i, boolean z, int i2, int i3, int i4, int i5, int i6, int[] iArr, int i7, int i8, int i9, int i10, float f, int i11, int i12, int i13) {
this.generalProfileSpace = i;
this.generalTierFlag = z;
this.generalProfileIdc = i2;
this.generalProfileCompatibilityFlags = i3;
this.chromaFormatIdc = i4;
this.bitDepthLumaMinus8 = i5;
this.bitDepthChromaMinus8 = i6;
this.constraintBytes = iArr;
this.generalLevelIdc = i7;
this.seqParameterSetId = i8;
this.width = i9;
this.height = i10;
this.pixelWidthHeightRatio = f;
this.colorSpace = i11;
this.colorRange = i12;
this.colorTransfer = i13;
}
}
/* loaded from: classes2.dex */
public static final class PpsData {
public final boolean bottomFieldPicOrderInFramePresentFlag;
public final int picParameterSetId;
public final int seqParameterSetId;
public PpsData(int i, int i2, boolean z) {
this.picParameterSetId = i;
this.seqParameterSetId = i2;
this.bottomFieldPicOrderInFramePresentFlag = z;
}
}
public static int unescapeStream(byte[] bArr, int i) {
int i2;
synchronized (scratchEscapePositionsLock) {
int i3 = 0;
int i4 = 0;
while (i3 < i) {
try {
i3 = findNextUnescapeIndex(bArr, i3, i);
if (i3 < i) {
int[] iArr = scratchEscapePositions;
if (iArr.length <= i4) {
scratchEscapePositions = Arrays.copyOf(iArr, iArr.length * 2);
}
scratchEscapePositions[i4] = i3;
i3 += 3;
i4++;
}
} catch (Throwable th) {
throw th;
}
}
i2 = i - i4;
int i5 = 0;
int i6 = 0;
for (int i7 = 0; i7 < i4; i7++) {
int i8 = scratchEscapePositions[i7] - i6;
System.arraycopy(bArr, i6, bArr, i5, i8);
int i9 = i5 + i8;
int i10 = i9 + 1;
bArr[i9] = 0;
i5 = i9 + 2;
bArr[i10] = 0;
i6 += i8 + 3;
}
System.arraycopy(bArr, i6, bArr, i5, i2 - i5);
}
return i2;
}
public static void discardToSps(ByteBuffer byteBuffer) {
int position = byteBuffer.position();
int i = 0;
int i2 = 0;
while (true) {
int i3 = i + 1;
if (i3 < position) {
int i4 = byteBuffer.get(i) & 255;
if (i2 == 3) {
if (i4 == 1 && (byteBuffer.get(i3) & Ascii.US) == 7) {
ByteBuffer duplicate = byteBuffer.duplicate();
duplicate.position(i - 3);
duplicate.limit(position);
byteBuffer.position(0);
byteBuffer.put(duplicate);
return;
}
} else if (i4 == 0) {
i2++;
}
if (i4 != 0) {
i2 = 0;
}
i = i3;
} else {
byteBuffer.clear();
return;
}
}
}
public static boolean isNalUnitSei(String str, byte b) {
if ("video/avc".equals(str) && (b & Ascii.US) == 6) {
return true;
}
return "video/hevc".equals(str) && ((b & 126) >> 1) == 39;
}
public static int getNalUnitType(byte[] bArr, int i) {
return bArr[i + 3] & Ascii.US;
}
public static int getH265NalUnitType(byte[] bArr, int i) {
return (bArr[i + 3] & 126) >> 1;
}
public static SpsData parseSpsNalUnit(byte[] bArr, int i, int i2) {
return parseSpsNalUnitPayload(bArr, i + 1, i2);
}
public static SpsData parseSpsNalUnitPayload(byte[] bArr, int i, int i2) {
int readUnsignedExpGolombCodedInt;
boolean readBit;
int i3;
boolean z;
boolean z2;
int i4;
int i5;
int i6;
int i7;
int i8;
int i9;
ParsableNalUnitBitArray parsableNalUnitBitArray = new ParsableNalUnitBitArray(bArr, i, i2);
int readBits = parsableNalUnitBitArray.readBits(8);
int readBits2 = parsableNalUnitBitArray.readBits(8);
int readBits3 = parsableNalUnitBitArray.readBits(8);
int readUnsignedExpGolombCodedInt2 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
if (readBits == 100 || readBits == 110 || readBits == 122 || readBits == 244 || readBits == 44 || readBits == 83 || readBits == 86 || readBits == 118 || readBits == 128 || readBits == 138) {
readUnsignedExpGolombCodedInt = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
readBit = readUnsignedExpGolombCodedInt == 3 ? parsableNalUnitBitArray.readBit() : false;
parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
parsableNalUnitBitArray.skipBit();
if (parsableNalUnitBitArray.readBit()) {
int i10 = readUnsignedExpGolombCodedInt != 3 ? 8 : 12;
int i11 = 0;
while (i11 < i10) {
if (parsableNalUnitBitArray.readBit()) {
skipScalingList(parsableNalUnitBitArray, i11 < 6 ? 16 : 64);
}
i11++;
}
}
} else {
readUnsignedExpGolombCodedInt = 1;
readBit = false;
}
int readUnsignedExpGolombCodedInt3 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt() + 4;
int readUnsignedExpGolombCodedInt4 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
if (readUnsignedExpGolombCodedInt4 == 0) {
i3 = readUnsignedExpGolombCodedInt;
z = readBit;
i4 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt() + 4;
z2 = false;
} else {
if (readUnsignedExpGolombCodedInt4 == 1) {
boolean readBit2 = parsableNalUnitBitArray.readBit();
parsableNalUnitBitArray.readSignedExpGolombCodedInt();
parsableNalUnitBitArray.readSignedExpGolombCodedInt();
z = readBit;
long readUnsignedExpGolombCodedInt5 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
i3 = readUnsignedExpGolombCodedInt;
for (int i12 = 0; i12 < readUnsignedExpGolombCodedInt5; i12++) {
parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
}
z2 = readBit2;
} else {
i3 = readUnsignedExpGolombCodedInt;
z = readBit;
z2 = false;
}
i4 = 0;
}
int readUnsignedExpGolombCodedInt6 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
parsableNalUnitBitArray.skipBit();
int readUnsignedExpGolombCodedInt7 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt() + 1;
int readUnsignedExpGolombCodedInt8 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt() + 1;
boolean readBit3 = parsableNalUnitBitArray.readBit();
int i13 = (2 - (readBit3 ? 1 : 0)) * readUnsignedExpGolombCodedInt8;
if (!readBit3) {
parsableNalUnitBitArray.skipBit();
}
parsableNalUnitBitArray.skipBit();
int i14 = readUnsignedExpGolombCodedInt7 * 16;
int i15 = i13 * 16;
if (parsableNalUnitBitArray.readBit()) {
int readUnsignedExpGolombCodedInt9 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
int readUnsignedExpGolombCodedInt10 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
int readUnsignedExpGolombCodedInt11 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
int readUnsignedExpGolombCodedInt12 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
if (i3 == 0) {
i9 = 2 - (readBit3 ? 1 : 0);
i8 = 1;
} else {
int i16 = i3;
i8 = i16 == 3 ? 1 : 2;
i9 = (i16 == 1 ? 2 : 1) * (2 - (readBit3 ? 1 : 0));
}
i14 -= (readUnsignedExpGolombCodedInt9 + readUnsignedExpGolombCodedInt10) * i8;
i15 -= (readUnsignedExpGolombCodedInt11 + readUnsignedExpGolombCodedInt12) * i9;
}
int i17 = i14;
float f = 1.0f;
if (parsableNalUnitBitArray.readBit()) {
if (parsableNalUnitBitArray.readBit()) {
int readBits4 = parsableNalUnitBitArray.readBits(8);
if (readBits4 == 255) {
int readBits5 = parsableNalUnitBitArray.readBits(16);
int readBits6 = parsableNalUnitBitArray.readBits(16);
if (readBits5 != 0 && readBits6 != 0) {
f = readBits5 / readBits6;
}
} else {
float[] fArr = ASPECT_RATIO_IDC_VALUES;
if (readBits4 < fArr.length) {
f = fArr[readBits4];
} else {
Log.w(TAG, "Unexpected aspect_ratio_idc value: " + readBits4);
}
}
}
if (parsableNalUnitBitArray.readBit()) {
parsableNalUnitBitArray.skipBit();
}
if (parsableNalUnitBitArray.readBit()) {
parsableNalUnitBitArray.skipBits(3);
int i18 = parsableNalUnitBitArray.readBit() ? 1 : 2;
if (parsableNalUnitBitArray.readBit()) {
int readBits7 = parsableNalUnitBitArray.readBits(8);
int readBits8 = parsableNalUnitBitArray.readBits(8);
parsableNalUnitBitArray.skipBits(8);
i5 = ColorInfo.isoColorPrimariesToColorSpace(readBits7);
i7 = ColorInfo.isoTransferCharacteristicsToColorTransfer(readBits8);
i6 = i18;
return new SpsData(readBits, readBits2, readBits3, readUnsignedExpGolombCodedInt2, readUnsignedExpGolombCodedInt6, i17, i15, f, z, readBit3, readUnsignedExpGolombCodedInt3, readUnsignedExpGolombCodedInt4, i4, z2, i5, i6, i7);
}
i6 = i18;
i5 = -1;
i7 = -1;
return new SpsData(readBits, readBits2, readBits3, readUnsignedExpGolombCodedInt2, readUnsignedExpGolombCodedInt6, i17, i15, f, z, readBit3, readUnsignedExpGolombCodedInt3, readUnsignedExpGolombCodedInt4, i4, z2, i5, i6, i7);
}
}
i5 = -1;
i6 = -1;
i7 = -1;
return new SpsData(readBits, readBits2, readBits3, readUnsignedExpGolombCodedInt2, readUnsignedExpGolombCodedInt6, i17, i15, f, z, readBit3, readUnsignedExpGolombCodedInt3, readUnsignedExpGolombCodedInt4, i4, z2, i5, i6, i7);
}
public static H265SpsData parseH265SpsNalUnit(byte[] bArr, int i, int i2) {
return parseH265SpsNalUnitPayload(bArr, i + 2, i2);
}
public static H265SpsData parseH265SpsNalUnitPayload(byte[] bArr, int i, int i2) {
int i3;
int i4;
int i5;
int i6;
ParsableNalUnitBitArray parsableNalUnitBitArray = new ParsableNalUnitBitArray(bArr, i, i2);
parsableNalUnitBitArray.skipBits(4);
int readBits = parsableNalUnitBitArray.readBits(3);
parsableNalUnitBitArray.skipBit();
int readBits2 = parsableNalUnitBitArray.readBits(2);
boolean readBit = parsableNalUnitBitArray.readBit();
int readBits3 = parsableNalUnitBitArray.readBits(5);
int i7 = 0;
for (int i8 = 0; i8 < 32; i8++) {
if (parsableNalUnitBitArray.readBit()) {
i7 |= 1 << i8;
}
}
int[] iArr = new int[6];
for (int i9 = 0; i9 < 6; i9++) {
iArr[i9] = parsableNalUnitBitArray.readBits(8);
}
int readBits4 = parsableNalUnitBitArray.readBits(8);
int i10 = 0;
for (int i11 = 0; i11 < readBits; i11++) {
if (parsableNalUnitBitArray.readBit()) {
i10 += 89;
}
if (parsableNalUnitBitArray.readBit()) {
i10 += 8;
}
}
parsableNalUnitBitArray.skipBits(i10);
if (readBits > 0) {
parsableNalUnitBitArray.skipBits((8 - readBits) * 2);
}
int readUnsignedExpGolombCodedInt = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
int readUnsignedExpGolombCodedInt2 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
if (readUnsignedExpGolombCodedInt2 == 3) {
parsableNalUnitBitArray.skipBit();
}
int readUnsignedExpGolombCodedInt3 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
int readUnsignedExpGolombCodedInt4 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
if (parsableNalUnitBitArray.readBit()) {
int readUnsignedExpGolombCodedInt5 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
int readUnsignedExpGolombCodedInt6 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
int readUnsignedExpGolombCodedInt7 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
int readUnsignedExpGolombCodedInt8 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
readUnsignedExpGolombCodedInt3 -= ((readUnsignedExpGolombCodedInt2 == 1 || readUnsignedExpGolombCodedInt2 == 2) ? 2 : 1) * (readUnsignedExpGolombCodedInt5 + readUnsignedExpGolombCodedInt6);
readUnsignedExpGolombCodedInt4 -= (readUnsignedExpGolombCodedInt2 == 1 ? 2 : 1) * (readUnsignedExpGolombCodedInt7 + readUnsignedExpGolombCodedInt8);
}
int i12 = readUnsignedExpGolombCodedInt4;
int i13 = readUnsignedExpGolombCodedInt3;
int i14 = i12;
int readUnsignedExpGolombCodedInt9 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
int readUnsignedExpGolombCodedInt10 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
int readUnsignedExpGolombCodedInt11 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
for (int i15 = parsableNalUnitBitArray.readBit() ? 0 : readBits; i15 <= readBits; i15++) {
parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
}
parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
if (parsableNalUnitBitArray.readBit() && parsableNalUnitBitArray.readBit()) {
skipH265ScalingList(parsableNalUnitBitArray);
}
parsableNalUnitBitArray.skipBits(2);
if (parsableNalUnitBitArray.readBit()) {
parsableNalUnitBitArray.skipBits(8);
parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
parsableNalUnitBitArray.skipBit();
}
skipShortTermReferencePictureSets(parsableNalUnitBitArray);
if (parsableNalUnitBitArray.readBit()) {
int readUnsignedExpGolombCodedInt12 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
for (int i16 = 0; i16 < readUnsignedExpGolombCodedInt12; i16++) {
parsableNalUnitBitArray.skipBits(readUnsignedExpGolombCodedInt11 + 5);
}
}
parsableNalUnitBitArray.skipBits(2);
int i17 = -1;
float f = 1.0f;
if (parsableNalUnitBitArray.readBit()) {
if (parsableNalUnitBitArray.readBit()) {
int readBits5 = parsableNalUnitBitArray.readBits(8);
if (readBits5 == 255) {
int readBits6 = parsableNalUnitBitArray.readBits(16);
int readBits7 = parsableNalUnitBitArray.readBits(16);
if (readBits6 != 0 && readBits7 != 0) {
f = readBits6 / readBits7;
}
} else {
float[] fArr = ASPECT_RATIO_IDC_VALUES;
if (readBits5 < fArr.length) {
f = fArr[readBits5];
} else {
Log.w(TAG, "Unexpected aspect_ratio_idc value: " + readBits5);
}
}
}
if (parsableNalUnitBitArray.readBit()) {
parsableNalUnitBitArray.skipBit();
}
if (parsableNalUnitBitArray.readBit()) {
parsableNalUnitBitArray.skipBits(3);
i4 = parsableNalUnitBitArray.readBit() ? 1 : 2;
if (parsableNalUnitBitArray.readBit()) {
int readBits8 = parsableNalUnitBitArray.readBits(8);
int readBits9 = parsableNalUnitBitArray.readBits(8);
parsableNalUnitBitArray.skipBits(8);
i17 = ColorInfo.isoColorPrimariesToColorSpace(readBits8);
i6 = ColorInfo.isoTransferCharacteristicsToColorTransfer(readBits9);
} else {
i6 = -1;
}
} else {
i6 = -1;
i4 = -1;
}
if (parsableNalUnitBitArray.readBit()) {
parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
}
parsableNalUnitBitArray.skipBit();
if (parsableNalUnitBitArray.readBit()) {
i14 *= 2;
}
i5 = i6;
i3 = i17;
} else {
i3 = -1;
i4 = -1;
i5 = -1;
}
return new H265SpsData(readBits2, readBit, readBits3, i7, readUnsignedExpGolombCodedInt2, readUnsignedExpGolombCodedInt9, readUnsignedExpGolombCodedInt10, iArr, readBits4, readUnsignedExpGolombCodedInt, i13, i14, f, i3, i4, i5);
}
public static PpsData parsePpsNalUnit(byte[] bArr, int i, int i2) {
return parsePpsNalUnitPayload(bArr, i + 1, i2);
}
public static PpsData parsePpsNalUnitPayload(byte[] bArr, int i, int i2) {
ParsableNalUnitBitArray parsableNalUnitBitArray = new ParsableNalUnitBitArray(bArr, i, i2);
int readUnsignedExpGolombCodedInt = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
int readUnsignedExpGolombCodedInt2 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
parsableNalUnitBitArray.skipBit();
return new PpsData(readUnsignedExpGolombCodedInt, readUnsignedExpGolombCodedInt2, parsableNalUnitBitArray.readBit());
}
public static int findNalUnit(byte[] bArr, int i, int i2, boolean[] zArr) {
int i3 = i2 - i;
Assertions.checkState(i3 >= 0);
if (i3 == 0) {
return i2;
}
if (zArr[0]) {
clearPrefixFlags(zArr);
return i - 3;
}
if (i3 > 1 && zArr[1] && bArr[i] == 1) {
clearPrefixFlags(zArr);
return i - 2;
}
if (i3 > 2 && zArr[2] && bArr[i] == 0 && bArr[i + 1] == 1) {
clearPrefixFlags(zArr);
return i - 1;
}
int i4 = i2 - 1;
int i5 = i + 2;
while (i5 < i4) {
byte b = bArr[i5];
if ((b & 254) == 0) {
int i6 = i5 - 2;
if (bArr[i6] == 0 && bArr[i5 - 1] == 0 && b == 1) {
clearPrefixFlags(zArr);
return i6;
}
i5 -= 2;
}
i5 += 3;
}
zArr[0] = i3 <= 2 ? !(i3 != 2 ? !(zArr[1] && bArr[i4] == 1) : !(zArr[2] && bArr[i2 + (-2)] == 0 && bArr[i4] == 1)) : bArr[i2 + (-3)] == 0 && bArr[i2 + (-2)] == 0 && bArr[i4] == 1;
zArr[1] = i3 <= 1 ? zArr[2] && bArr[i4] == 0 : bArr[i2 + (-2)] == 0 && bArr[i4] == 0;
zArr[2] = bArr[i4] == 0;
return i2;
}
public static void clearPrefixFlags(boolean[] zArr) {
zArr[0] = false;
zArr[1] = false;
zArr[2] = false;
}
private static int findNextUnescapeIndex(byte[] bArr, int i, int i2) {
while (i < i2 - 2) {
if (bArr[i] == 0 && bArr[i + 1] == 0 && bArr[i + 2] == 3) {
return i;
}
i++;
}
return i2;
}
private static void skipScalingList(ParsableNalUnitBitArray parsableNalUnitBitArray, int i) {
int i2 = 8;
int i3 = 8;
for (int i4 = 0; i4 < i; i4++) {
if (i2 != 0) {
i2 = ((parsableNalUnitBitArray.readSignedExpGolombCodedInt() + i3) + 256) % 256;
}
if (i2 != 0) {
i3 = i2;
}
}
}
private static void skipH265ScalingList(ParsableNalUnitBitArray parsableNalUnitBitArray) {
for (int i = 0; i < 4; i++) {
int i2 = 0;
while (i2 < 6) {
int i3 = 1;
if (!parsableNalUnitBitArray.readBit()) {
parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
} else {
int min = Math.min(64, 1 << ((i << 1) + 4));
if (i > 1) {
parsableNalUnitBitArray.readSignedExpGolombCodedInt();
}
for (int i4 = 0; i4 < min; i4++) {
parsableNalUnitBitArray.readSignedExpGolombCodedInt();
}
}
if (i == 3) {
i3 = 3;
}
i2 += i3;
}
}
}
private static void skipShortTermReferencePictureSets(ParsableNalUnitBitArray parsableNalUnitBitArray) {
int readUnsignedExpGolombCodedInt = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
int[] iArr = new int[0];
int[] iArr2 = new int[0];
int i = -1;
int i2 = -1;
for (int i3 = 0; i3 < readUnsignedExpGolombCodedInt; i3++) {
if (i3 != 0 && parsableNalUnitBitArray.readBit()) {
int i4 = i + i2;
int readUnsignedExpGolombCodedInt2 = (1 - ((parsableNalUnitBitArray.readBit() ? 1 : 0) * 2)) * (parsableNalUnitBitArray.readUnsignedExpGolombCodedInt() + 1);
int i5 = i4 + 1;
boolean[] zArr = new boolean[i5];
for (int i6 = 0; i6 <= i4; i6++) {
if (!parsableNalUnitBitArray.readBit()) {
zArr[i6] = parsableNalUnitBitArray.readBit();
} else {
zArr[i6] = true;
}
}
int[] iArr3 = new int[i5];
int[] iArr4 = new int[i5];
int i7 = 0;
for (int i8 = i2 - 1; i8 >= 0; i8--) {
int i9 = iArr2[i8] + readUnsignedExpGolombCodedInt2;
if (i9 < 0 && zArr[i + i8]) {
iArr3[i7] = i9;
i7++;
}
}
if (readUnsignedExpGolombCodedInt2 < 0 && zArr[i4]) {
iArr3[i7] = readUnsignedExpGolombCodedInt2;
i7++;
}
for (int i10 = 0; i10 < i; i10++) {
int i11 = iArr[i10] + readUnsignedExpGolombCodedInt2;
if (i11 < 0 && zArr[i10]) {
iArr3[i7] = i11;
i7++;
}
}
int[] copyOf = Arrays.copyOf(iArr3, i7);
int i12 = 0;
for (int i13 = i - 1; i13 >= 0; i13--) {
int i14 = iArr[i13] + readUnsignedExpGolombCodedInt2;
if (i14 > 0 && zArr[i13]) {
iArr4[i12] = i14;
i12++;
}
}
if (readUnsignedExpGolombCodedInt2 > 0 && zArr[i4]) {
iArr4[i12] = readUnsignedExpGolombCodedInt2;
i12++;
}
for (int i15 = 0; i15 < i2; i15++) {
int i16 = iArr2[i15] + readUnsignedExpGolombCodedInt2;
if (i16 > 0 && zArr[i + i15]) {
iArr4[i12] = i16;
i12++;
}
}
iArr2 = Arrays.copyOf(iArr4, i12);
iArr = copyOf;
i = i7;
i2 = i12;
} else {
int readUnsignedExpGolombCodedInt3 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
int readUnsignedExpGolombCodedInt4 = parsableNalUnitBitArray.readUnsignedExpGolombCodedInt();
int[] iArr5 = new int[readUnsignedExpGolombCodedInt3];
int i17 = 0;
while (i17 < readUnsignedExpGolombCodedInt3) {
iArr5[i17] = (i17 > 0 ? iArr5[i17 - 1] : 0) - (parsableNalUnitBitArray.readUnsignedExpGolombCodedInt() + 1);
parsableNalUnitBitArray.skipBit();
i17++;
}
int[] iArr6 = new int[readUnsignedExpGolombCodedInt4];
int i18 = 0;
while (i18 < readUnsignedExpGolombCodedInt4) {
iArr6[i18] = (i18 > 0 ? iArr6[i18 - 1] : 0) + parsableNalUnitBitArray.readUnsignedExpGolombCodedInt() + 1;
parsableNalUnitBitArray.skipBit();
i18++;
}
i = readUnsignedExpGolombCodedInt3;
iArr = iArr5;
i2 = readUnsignedExpGolombCodedInt4;
iArr2 = iArr6;
}
}
}
private NalUnitUtil() {
}
}