Spermatid v6.1.8版本的 MD5 值为:a375ce51a42d528ba6e2583c10478296
以下内容为反编译后的 MatroskaExtractor.java 源代码,内容仅作参考
package com.mbridge.msdk.playercommon.exoplayer2.extractor.mkv;
import android.util.Log;
import android.util.Pair;
import android.util.SparseArray;
import androidx.exifinterface.media.ExifInterface;
import com.mbridge.msdk.playercommon.exoplayer2.C;
import com.mbridge.msdk.playercommon.exoplayer2.Format;
import com.mbridge.msdk.playercommon.exoplayer2.ParserException;
import com.mbridge.msdk.playercommon.exoplayer2.audio.Ac3Util;
import com.mbridge.msdk.playercommon.exoplayer2.drm.DrmInitData;
import com.mbridge.msdk.playercommon.exoplayer2.extractor.ChunkIndex;
import com.mbridge.msdk.playercommon.exoplayer2.extractor.Extractor;
import com.mbridge.msdk.playercommon.exoplayer2.extractor.ExtractorInput;
import com.mbridge.msdk.playercommon.exoplayer2.extractor.ExtractorOutput;
import com.mbridge.msdk.playercommon.exoplayer2.extractor.ExtractorsFactory;
import com.mbridge.msdk.playercommon.exoplayer2.extractor.PositionHolder;
import com.mbridge.msdk.playercommon.exoplayer2.extractor.SeekMap;
import com.mbridge.msdk.playercommon.exoplayer2.extractor.TrackOutput;
import com.mbridge.msdk.playercommon.exoplayer2.util.Assertions;
import com.mbridge.msdk.playercommon.exoplayer2.util.LongArray;
import com.mbridge.msdk.playercommon.exoplayer2.util.MimeTypes;
import com.mbridge.msdk.playercommon.exoplayer2.util.NalUnitUtil;
import com.mbridge.msdk.playercommon.exoplayer2.util.ParsableByteArray;
import com.mbridge.msdk.playercommon.exoplayer2.util.Util;
import com.mbridge.msdk.playercommon.exoplayer2.video.AvcConfig;
import com.mbridge.msdk.playercommon.exoplayer2.video.ColorInfo;
import com.mbridge.msdk.playercommon.exoplayer2.video.HevcConfig;
import com.sigmob.sdk.archives.tar.e;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.UUID;
public final class MatroskaExtractor implements Extractor {
private static final int BLOCK_STATE_DATA = 2;
private static final int BLOCK_STATE_HEADER = 1;
private static final int BLOCK_STATE_START = 0;
private static final String CODEC_ID_AAC = "A_AAC";
private static final String CODEC_ID_AC3 = "A_AC3";
private static final String CODEC_ID_ACM = "A_MS/ACM";
private static final String CODEC_ID_ASS = "S_TEXT/ASS";
private static final String CODEC_ID_DTS = "A_DTS";
private static final String CODEC_ID_DTS_EXPRESS = "A_DTS/EXPRESS";
private static final String CODEC_ID_DTS_LOSSLESS = "A_DTS/LOSSLESS";
private static final String CODEC_ID_DVBSUB = "S_DVBSUB";
private static final String CODEC_ID_E_AC3 = "A_EAC3";
private static final String CODEC_ID_FLAC = "A_FLAC";
private static final String CODEC_ID_FOURCC = "V_MS/VFW/FOURCC";
private static final String CODEC_ID_H264 = "V_MPEG4/ISO/AVC";
private static final String CODEC_ID_H265 = "V_MPEGH/ISO/HEVC";
private static final String CODEC_ID_MP2 = "A_MPEG/L2";
private static final String CODEC_ID_MP3 = "A_MPEG/L3";
private static final String CODEC_ID_MPEG2 = "V_MPEG2";
private static final String CODEC_ID_MPEG4_AP = "V_MPEG4/ISO/AP";
private static final String CODEC_ID_MPEG4_ASP = "V_MPEG4/ISO/ASP";
private static final String CODEC_ID_MPEG4_SP = "V_MPEG4/ISO/SP";
private static final String CODEC_ID_OPUS = "A_OPUS";
private static final String CODEC_ID_PCM_INT_LIT = "A_PCM/INT/LIT";
private static final String CODEC_ID_PGS = "S_HDMV/PGS";
private static final String CODEC_ID_SUBRIP = "S_TEXT/UTF8";
private static final String CODEC_ID_THEORA = "V_THEORA";
private static final String CODEC_ID_TRUEHD = "A_TRUEHD";
private static final String CODEC_ID_VOBSUB = "S_VOBSUB";
private static final String CODEC_ID_VORBIS = "A_VORBIS";
private static final String CODEC_ID_VP8 = "V_VP8";
private static final String CODEC_ID_VP9 = "V_VP9";
private static final String DOC_TYPE_MATROSKA = "matroska";
private static final String DOC_TYPE_WEBM = "webm";
private static final int ENCRYPTION_IV_SIZE = 8;
public static final int FLAG_DISABLE_SEEK_FOR_CUES = 1;
private static final int FOURCC_COMPRESSION_DIVX = 1482049860;
private static final int FOURCC_COMPRESSION_VC1 = 826496599;
private static final int ID_AUDIO = 225;
private static final int ID_AUDIO_BIT_DEPTH = 25188;
private static final int ID_BLOCK = 161;
private static final int ID_BLOCK_DURATION = 155;
private static final int ID_BLOCK_GROUP = 160;
private static final int ID_CHANNELS = 159;
private static final int ID_CLUSTER = 524531317;
private static final int ID_CODEC_DELAY = 22186;
private static final int ID_CODEC_ID = 134;
private static final int ID_CODEC_PRIVATE = 25506;
private static final int ID_COLOUR = 21936;
private static final int ID_COLOUR_PRIMARIES = 21947;
private static final int ID_COLOUR_RANGE = 21945;
private static final int ID_COLOUR_TRANSFER = 21946;
private static final int ID_CONTENT_COMPRESSION = 20532;
private static final int ID_CONTENT_COMPRESSION_ALGORITHM = 16980;
private static final int ID_CONTENT_COMPRESSION_SETTINGS = 16981;
private static final int ID_CONTENT_ENCODING = 25152;
private static final int ID_CONTENT_ENCODINGS = 28032;
private static final int ID_CONTENT_ENCODING_ORDER = 20529;
private static final int ID_CONTENT_ENCODING_SCOPE = 20530;
private static final int ID_CONTENT_ENCRYPTION = 20533;
private static final int ID_CONTENT_ENCRYPTION_AES_SETTINGS = 18407;
private static final int ID_CONTENT_ENCRYPTION_AES_SETTINGS_CIPHER_MODE = 18408;
private static final int ID_CONTENT_ENCRYPTION_ALGORITHM = 18401;
private static final int ID_CONTENT_ENCRYPTION_KEY_ID = 18402;
private static final int ID_CUES = 475249515;
private static final int ID_CUE_CLUSTER_POSITION = 241;
private static final int ID_CUE_POINT = 187;
private static final int ID_CUE_TIME = 179;
private static final int ID_CUE_TRACK_POSITIONS = 183;
private static final int ID_DEFAULT_DURATION = 2352003;
private static final int ID_DISPLAY_HEIGHT = 21690;
private static final int ID_DISPLAY_UNIT = 21682;
private static final int ID_DISPLAY_WIDTH = 21680;
private static final int ID_DOC_TYPE = 17026;
private static final int ID_DOC_TYPE_READ_VERSION = 17029;
private static final int ID_DURATION = 17545;
private static final int ID_EBML = 440786851;
private static final int ID_EBML_READ_VERSION = 17143;
private static final int ID_FLAG_DEFAULT = 136;
private static final int ID_FLAG_FORCED = 21930;
private static final int ID_INFO = 357149030;
private static final int ID_LANGUAGE = 2274716;
private static final int ID_LUMNINANCE_MAX = 21977;
private static final int ID_LUMNINANCE_MIN = 21978;
private static final int ID_MASTERING_METADATA = 21968;
private static final int ID_MAX_CLL = 21948;
private static final int ID_MAX_FALL = 21949;
private static final int ID_PIXEL_HEIGHT = 186;
private static final int ID_PIXEL_WIDTH = 176;
private static final int ID_PRIMARY_B_CHROMATICITY_X = 21973;
private static final int ID_PRIMARY_B_CHROMATICITY_Y = 21974;
private static final int ID_PRIMARY_G_CHROMATICITY_X = 21971;
private static final int ID_PRIMARY_G_CHROMATICITY_Y = 21972;
private static final int ID_PRIMARY_R_CHROMATICITY_X = 21969;
private static final int ID_PRIMARY_R_CHROMATICITY_Y = 21970;
private static final int ID_PROJECTION = 30320;
private static final int ID_PROJECTION_PRIVATE = 30322;
private static final int ID_REFERENCE_BLOCK = 251;
private static final int ID_SAMPLING_FREQUENCY = 181;
private static final int ID_SEEK = 19899;
private static final int ID_SEEK_HEAD = 290298740;
private static final int ID_SEEK_ID = 21419;
private static final int ID_SEEK_POSITION = 21420;
private static final int ID_SEEK_PRE_ROLL = 22203;
private static final int ID_SEGMENT = 408125543;
private static final int ID_SEGMENT_INFO = 357149030;
private static final int ID_SIMPLE_BLOCK = 163;
private static final int ID_STEREO_MODE = 21432;
private static final int ID_TIMECODE_SCALE = 2807729;
private static final int ID_TIME_CODE = 231;
private static final int ID_TRACKS = 374648427;
private static final int ID_TRACK_ENTRY = 174;
private static final int ID_TRACK_NUMBER = 215;
private static final int ID_TRACK_TYPE = 131;
private static final int ID_VIDEO = 224;
private static final int ID_WHITE_POINT_CHROMATICITY_X = 21975;
private static final int ID_WHITE_POINT_CHROMATICITY_Y = 21976;
private static final int LACING_EBML = 3;
private static final int LACING_FIXED_SIZE = 2;
private static final int LACING_NONE = 0;
private static final int LACING_XIPH = 1;
private static final int OPUS_MAX_INPUT_SIZE = 5760;
private static final int SSA_PREFIX_END_TIMECODE_OFFSET = 21;
private static final String SSA_TIMECODE_FORMAT = "%01d:%02d:%02d:%02d";
private static final long SSA_TIMECODE_LAST_VALUE_SCALING_FACTOR = 10000;
private static final int SUBRIP_PREFIX_END_TIMECODE_OFFSET = 19;
private static final String SUBRIP_TIMECODE_FORMAT = "%02d:%02d:%02d,%03d";
private static final long SUBRIP_TIMECODE_LAST_VALUE_SCALING_FACTOR = 1000;
private static final String TAG = "MatroskaExtractor";
private static final int TRACK_TYPE_AUDIO = 2;
private static final int UNSET_ENTRY_ID = -1;
private static final int VORBIS_MAX_INPUT_SIZE = 8192;
private static final int WAVE_FORMAT_EXTENSIBLE = 65534;
private static final int WAVE_FORMAT_PCM = 1;
private static final int WAVE_FORMAT_SIZE = 18;
private long blockDurationUs;
private int blockFlags;
private int blockLacingSampleCount;
private int blockLacingSampleIndex;
private int[] blockLacingSampleSizes;
private int blockState;
private long blockTimeUs;
private int blockTrackNumber;
private int blockTrackNumberLength;
private long clusterTimecodeUs;
private LongArray cueClusterPositions;
private LongArray cueTimesUs;
private long cuesContentPosition;
private Track currentTrack;
private long durationTimecode;
private long durationUs;
private final ParsableByteArray encryptionInitializationVector;
private final ParsableByteArray encryptionSubsampleData;
private ByteBuffer encryptionSubsampleDataBuffer;
private ExtractorOutput extractorOutput;
private final ParsableByteArray nalLength;
private final ParsableByteArray nalStartCode;
private final EbmlReader reader;
private int sampleBytesRead;
private int sampleBytesWritten;
private int sampleCurrentNalBytesRemaining;
private boolean sampleEncodingHandled;
private boolean sampleInitializationVectorRead;
private int samplePartitionCount;
private boolean samplePartitionCountRead;
private boolean sampleRead;
private boolean sampleSeenReferenceBlock;
private byte sampleSignalByte;
private boolean sampleSignalByteRead;
private final ParsableByteArray sampleStrippedBytes;
private final ParsableByteArray scratch;
private int seekEntryId;
private final ParsableByteArray seekEntryIdBytes;
private long seekEntryPosition;
private boolean seekForCues;
private final boolean seekForCuesEnabled;
private long seekPositionAfterBuildingCues;
private boolean seenClusterPositionForCurrentCuePoint;
private long segmentContentPosition;
private long segmentContentSize;
private boolean sentSeekMap;
private final ParsableByteArray subtitleSample;
private long timecodeScale;
private final SparseArray<Track> tracks;
private final VarintReader varintReader;
private final ParsableByteArray vorbisNumPageSamples;
public static final ExtractorsFactory FACTORY = new ExtractorsFactory() {
@Override
public final Extractor[] createExtractors() {
return new Extractor[]{new MatroskaExtractor()};
}
};
private static final byte[] SUBRIP_PREFIX = {e.I, 10, e.H, e.H, 58, e.H, e.H, 58, e.H, e.H, 44, e.H, e.H, e.H, 32, 45, 45, 62, 32, e.H, e.H, 58, e.H, e.H, 58, e.H, e.H, 44, e.H, e.H, e.H, 10};
private static final byte[] SUBRIP_TIMECODE_EMPTY = {32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32};
private static final byte[] SSA_DIALOGUE_FORMAT = Util.getUtf8Bytes("Format: Start, End, ReadOrder, Layer, Style, Name, MarginL, MarginR, MarginV, Effect, Text");
private static final byte[] SSA_PREFIX = {68, 105, 97, 108, 111, e.T, 117, 101, 58, 32, e.H, 58, e.H, e.H, 58, e.H, e.H, 58, e.H, e.H, 44, e.H, 58, e.H, e.H, 58, e.H, e.H, 58, e.H, e.H, 44};
private static final byte[] SSA_TIMECODE_EMPTY = {32, 32, 32, 32, 32, 32, 32, 32, 32, 32};
private static final UUID WAVE_SUBFORMAT_PCM = new UUID(72057594037932032L, -9223371306706625679L);
public @interface Flags {
}
public final class InnerEbmlReaderOutput implements EbmlReaderOutput {
private InnerEbmlReaderOutput() {
}
@Override
public final void binaryElement(int i10, int i11, ExtractorInput extractorInput) throws IOException, InterruptedException {
MatroskaExtractor.this.binaryElement(i10, i11, extractorInput);
}
@Override
public final void endMasterElement(int i10) throws ParserException {
MatroskaExtractor.this.endMasterElement(i10);
}
@Override
public final void floatElement(int i10, double d10) throws ParserException {
MatroskaExtractor.this.floatElement(i10, d10);
}
@Override
public final int getElementType(int i10) {
switch (i10) {
case 131:
case 136:
case 155:
case MatroskaExtractor.ID_CHANNELS:
case MatroskaExtractor.ID_PIXEL_WIDTH:
case MatroskaExtractor.ID_CUE_TIME:
case MatroskaExtractor.ID_PIXEL_HEIGHT:
case MatroskaExtractor.ID_TRACK_NUMBER:
case MatroskaExtractor.ID_TIME_CODE:
case MatroskaExtractor.ID_CUE_CLUSTER_POSITION:
case MatroskaExtractor.ID_REFERENCE_BLOCK:
case MatroskaExtractor.ID_CONTENT_COMPRESSION_ALGORITHM:
case MatroskaExtractor.ID_DOC_TYPE_READ_VERSION:
case MatroskaExtractor.ID_EBML_READ_VERSION:
case MatroskaExtractor.ID_CONTENT_ENCRYPTION_ALGORITHM:
case MatroskaExtractor.ID_CONTENT_ENCRYPTION_AES_SETTINGS_CIPHER_MODE:
case MatroskaExtractor.ID_CONTENT_ENCODING_ORDER:
case MatroskaExtractor.ID_CONTENT_ENCODING_SCOPE:
case MatroskaExtractor.ID_SEEK_POSITION:
case MatroskaExtractor.ID_STEREO_MODE:
case MatroskaExtractor.ID_DISPLAY_WIDTH:
case MatroskaExtractor.ID_DISPLAY_UNIT:
case MatroskaExtractor.ID_DISPLAY_HEIGHT:
case MatroskaExtractor.ID_FLAG_FORCED:
case MatroskaExtractor.ID_COLOUR_RANGE:
case MatroskaExtractor.ID_COLOUR_TRANSFER:
case MatroskaExtractor.ID_COLOUR_PRIMARIES:
case MatroskaExtractor.ID_MAX_CLL:
case MatroskaExtractor.ID_MAX_FALL:
case MatroskaExtractor.ID_CODEC_DELAY:
case MatroskaExtractor.ID_SEEK_PRE_ROLL:
case MatroskaExtractor.ID_AUDIO_BIT_DEPTH:
case MatroskaExtractor.ID_DEFAULT_DURATION:
case MatroskaExtractor.ID_TIMECODE_SCALE:
return 2;
case 134:
case MatroskaExtractor.ID_DOC_TYPE:
case MatroskaExtractor.ID_LANGUAGE:
return 3;
case MatroskaExtractor.ID_BLOCK_GROUP:
case MatroskaExtractor.ID_TRACK_ENTRY:
case MatroskaExtractor.ID_CUE_TRACK_POSITIONS:
case MatroskaExtractor.ID_CUE_POINT:
case 224:
case 225:
case MatroskaExtractor.ID_CONTENT_ENCRYPTION_AES_SETTINGS:
case MatroskaExtractor.ID_SEEK:
case MatroskaExtractor.ID_CONTENT_COMPRESSION:
case MatroskaExtractor.ID_CONTENT_ENCRYPTION:
case MatroskaExtractor.ID_COLOUR:
case MatroskaExtractor.ID_MASTERING_METADATA:
case MatroskaExtractor.ID_CONTENT_ENCODING:
case MatroskaExtractor.ID_CONTENT_ENCODINGS:
case MatroskaExtractor.ID_PROJECTION:
case MatroskaExtractor.ID_SEEK_HEAD:
case 357149030:
case MatroskaExtractor.ID_TRACKS:
case MatroskaExtractor.ID_SEGMENT:
case MatroskaExtractor.ID_EBML:
case MatroskaExtractor.ID_CUES:
case MatroskaExtractor.ID_CLUSTER:
return 1;
case 161:
case MatroskaExtractor.ID_SIMPLE_BLOCK:
case MatroskaExtractor.ID_CONTENT_COMPRESSION_SETTINGS:
case MatroskaExtractor.ID_CONTENT_ENCRYPTION_KEY_ID:
case MatroskaExtractor.ID_SEEK_ID:
case MatroskaExtractor.ID_CODEC_PRIVATE:
case MatroskaExtractor.ID_PROJECTION_PRIVATE:
return 4;
case MatroskaExtractor.ID_SAMPLING_FREQUENCY:
case MatroskaExtractor.ID_DURATION:
case MatroskaExtractor.ID_PRIMARY_R_CHROMATICITY_X:
case MatroskaExtractor.ID_PRIMARY_R_CHROMATICITY_Y:
case MatroskaExtractor.ID_PRIMARY_G_CHROMATICITY_X:
case MatroskaExtractor.ID_PRIMARY_G_CHROMATICITY_Y:
case MatroskaExtractor.ID_PRIMARY_B_CHROMATICITY_X:
case MatroskaExtractor.ID_PRIMARY_B_CHROMATICITY_Y:
case MatroskaExtractor.ID_WHITE_POINT_CHROMATICITY_X:
case MatroskaExtractor.ID_WHITE_POINT_CHROMATICITY_Y:
case MatroskaExtractor.ID_LUMNINANCE_MAX:
case MatroskaExtractor.ID_LUMNINANCE_MIN:
return 5;
default:
return 0;
}
}
@Override
public final void integerElement(int i10, long j10) throws ParserException {
MatroskaExtractor.this.integerElement(i10, j10);
}
@Override
public final boolean isLevel1Element(int i10) {
return i10 == 357149030 || i10 == MatroskaExtractor.ID_CLUSTER || i10 == MatroskaExtractor.ID_CUES || i10 == MatroskaExtractor.ID_TRACKS;
}
@Override
public final void startMasterElement(int i10, long j10, long j11) throws ParserException {
MatroskaExtractor.this.startMasterElement(i10, j10, j11);
}
@Override
public final void stringElement(int i10, String str) throws ParserException {
MatroskaExtractor.this.stringElement(i10, str);
}
}
public static final class Track {
private static final int DEFAULT_MAX_CLL = 1000;
private static final int DEFAULT_MAX_FALL = 200;
private static final int DISPLAY_UNIT_PIXELS = 0;
private static final int MAX_CHROMATICITY = 50000;
public int audioBitDepth;
public int channelCount;
public long codecDelayNs;
public String codecId;
public byte[] codecPrivate;
public int colorRange;
public int colorSpace;
public int colorTransfer;
public TrackOutput.CryptoData cryptoData;
public int defaultSampleDurationNs;
public int displayHeight;
public int displayUnit;
public int displayWidth;
public DrmInitData drmInitData;
public boolean flagDefault;
public boolean flagForced;
public boolean hasColorInfo;
public boolean hasContentEncryption;
public int height;
private String language;
public int maxContentLuminance;
public int maxFrameAverageLuminance;
public float maxMasteringLuminance;
public float minMasteringLuminance;
public int nalUnitLengthFieldLength;
public int number;
public TrackOutput output;
public float primaryBChromaticityX;
public float primaryBChromaticityY;
public float primaryGChromaticityX;
public float primaryGChromaticityY;
public float primaryRChromaticityX;
public float primaryRChromaticityY;
public byte[] projectionData;
public int sampleRate;
public byte[] sampleStrippedBytes;
public long seekPreRollNs;
public int stereoMode;
public TrueHdSampleRechunker trueHdSampleRechunker;
public int type;
public float whitePointChromaticityX;
public float whitePointChromaticityY;
public int width;
private Track() {
this.width = -1;
this.height = -1;
this.displayWidth = -1;
this.displayHeight = -1;
this.displayUnit = 0;
this.projectionData = null;
this.stereoMode = -1;
this.hasColorInfo = false;
this.colorSpace = -1;
this.colorTransfer = -1;
this.colorRange = -1;
this.maxContentLuminance = 1000;
this.maxFrameAverageLuminance = 200;
this.primaryRChromaticityX = -1.0f;
this.primaryRChromaticityY = -1.0f;
this.primaryGChromaticityX = -1.0f;
this.primaryGChromaticityY = -1.0f;
this.primaryBChromaticityX = -1.0f;
this.primaryBChromaticityY = -1.0f;
this.whitePointChromaticityX = -1.0f;
this.whitePointChromaticityY = -1.0f;
this.maxMasteringLuminance = -1.0f;
this.minMasteringLuminance = -1.0f;
this.channelCount = 1;
this.audioBitDepth = -1;
this.sampleRate = 8000;
this.codecDelayNs = 0L;
this.seekPreRollNs = 0L;
this.flagDefault = true;
this.language = "eng";
}
private byte[] getHdrStaticInfo() {
if (this.primaryRChromaticityX == -1.0f || this.primaryRChromaticityY == -1.0f || this.primaryGChromaticityX == -1.0f || this.primaryGChromaticityY == -1.0f || this.primaryBChromaticityX == -1.0f || this.primaryBChromaticityY == -1.0f || this.whitePointChromaticityX == -1.0f || this.whitePointChromaticityY == -1.0f || this.maxMasteringLuminance == -1.0f || this.minMasteringLuminance == -1.0f) {
return null;
}
byte[] bArr = new byte[25];
ByteBuffer wrap = ByteBuffer.wrap(bArr);
wrap.put((byte) 0);
wrap.putShort((short) ((this.primaryRChromaticityX * 50000.0f) + 0.5f));
wrap.putShort((short) ((this.primaryRChromaticityY * 50000.0f) + 0.5f));
wrap.putShort((short) ((this.primaryGChromaticityX * 50000.0f) + 0.5f));
wrap.putShort((short) ((this.primaryGChromaticityY * 50000.0f) + 0.5f));
wrap.putShort((short) ((this.primaryBChromaticityX * 50000.0f) + 0.5f));
wrap.putShort((short) ((this.primaryBChromaticityY * 50000.0f) + 0.5f));
wrap.putShort((short) ((this.whitePointChromaticityX * 50000.0f) + 0.5f));
wrap.putShort((short) ((this.whitePointChromaticityY * 50000.0f) + 0.5f));
wrap.putShort((short) (this.maxMasteringLuminance + 0.5f));
wrap.putShort((short) (this.minMasteringLuminance + 0.5f));
wrap.putShort((short) this.maxContentLuminance);
wrap.putShort((short) this.maxFrameAverageLuminance);
return bArr;
}
private static Pair<String, List<byte[]>> parseFourCcPrivate(ParsableByteArray parsableByteArray) throws ParserException {
try {
parsableByteArray.skipBytes(16);
long readLittleEndianUnsignedInt = parsableByteArray.readLittleEndianUnsignedInt();
if (readLittleEndianUnsignedInt == 1482049860) {
return new Pair<>(MimeTypes.VIDEO_H263, null);
}
if (readLittleEndianUnsignedInt == 826496599) {
byte[] bArr = parsableByteArray.data;
for (int position = parsableByteArray.getPosition() + 20; position < bArr.length - 4; position++) {
if (bArr[position] == 0 && bArr[position + 1] == 0 && bArr[position + 2] == 1 && bArr[position + 3] == 15) {
return new Pair<>(MimeTypes.VIDEO_VC1, Collections.singletonList(Arrays.copyOfRange(bArr, position, bArr.length)));
}
}
throw new ParserException("Failed to find FourCC VC1 initialization data");
}
Log.w(MatroskaExtractor.TAG, "Unknown FourCC. Setting mimeType to video/x-unknown");
return new Pair<>(MimeTypes.VIDEO_UNKNOWN, null);
} catch (ArrayIndexOutOfBoundsException unused) {
throw new ParserException("Error parsing FourCC private data");
}
}
private static boolean parseMsAcmCodecPrivate(ParsableByteArray parsableByteArray) throws ParserException {
try {
int readLittleEndianUnsignedShort = parsableByteArray.readLittleEndianUnsignedShort();
if (readLittleEndianUnsignedShort == 1) {
return true;
}
if (readLittleEndianUnsignedShort != MatroskaExtractor.WAVE_FORMAT_EXTENSIBLE) {
return false;
}
parsableByteArray.setPosition(24);
if (parsableByteArray.readLong() == MatroskaExtractor.WAVE_SUBFORMAT_PCM.getMostSignificantBits()) {
if (parsableByteArray.readLong() == MatroskaExtractor.WAVE_SUBFORMAT_PCM.getLeastSignificantBits()) {
return true;
}
}
return false;
} catch (ArrayIndexOutOfBoundsException unused) {
throw new ParserException("Error parsing MS/ACM codec private");
}
}
private static List<byte[]> parseVorbisCodecPrivate(byte[] bArr) throws ParserException {
try {
if (bArr[0] == 2) {
int i10 = 1;
int i11 = 0;
while (bArr[i10] == -1) {
i11 += 255;
i10++;
}
int i12 = i10 + 1;
int i13 = i11 + bArr[i10];
int i14 = 0;
while (bArr[i12] == -1) {
i14 += 255;
i12++;
}
int i15 = i12 + 1;
int i16 = i14 + bArr[i12];
if (bArr[i15] == 1) {
byte[] bArr2 = new byte[i13];
System.arraycopy(bArr, i15, bArr2, 0, i13);
int i17 = i15 + i13;
if (bArr[i17] == 3) {
int i18 = i17 + i16;
if (bArr[i18] == 5) {
byte[] bArr3 = new byte[bArr.length - i18];
System.arraycopy(bArr, i18, bArr3, 0, bArr.length - i18);
ArrayList arrayList = new ArrayList(2);
arrayList.add(bArr2);
arrayList.add(bArr3);
return arrayList;
}
throw new ParserException("Error parsing vorbis codec private");
}
throw new ParserException("Error parsing vorbis codec private");
}
throw new ParserException("Error parsing vorbis codec private");
}
throw new ParserException("Error parsing vorbis codec private");
} catch (ArrayIndexOutOfBoundsException unused) {
throw new ParserException("Error parsing vorbis codec private");
}
}
public final void initializeOutput(ExtractorOutput extractorOutput, int i10) throws ParserException {
char c10;
List<byte[]> singletonList;
String str;
int pcmEncoding;
String str2;
int i11;
int i12;
String str3;
List<byte[]> list;
Format createImageSampleFormat;
int i13;
int i14;
String str4 = this.codecId;
str4.hashCode();
int i15 = 1;
switch (str4.hashCode()) {
case -2095576542:
if (str4.equals(MatroskaExtractor.CODEC_ID_MPEG4_AP)) {
c10 = 0;
break;
}
c10 = 65535;
break;
case -2095575984:
if (str4.equals(MatroskaExtractor.CODEC_ID_MPEG4_SP)) {
c10 = 1;
break;
}
c10 = 65535;
break;
case -1985379776:
if (str4.equals(MatroskaExtractor.CODEC_ID_ACM)) {
c10 = 2;
break;
}
c10 = 65535;
break;
case -1784763192:
if (str4.equals(MatroskaExtractor.CODEC_ID_TRUEHD)) {
c10 = 3;
break;
}
c10 = 65535;
break;
case -1730367663:
if (str4.equals(MatroskaExtractor.CODEC_ID_VORBIS)) {
c10 = 4;
break;
}
c10 = 65535;
break;
case -1482641358:
if (str4.equals(MatroskaExtractor.CODEC_ID_MP2)) {
c10 = 5;
break;
}
c10 = 65535;
break;
case -1482641357:
if (str4.equals(MatroskaExtractor.CODEC_ID_MP3)) {
c10 = 6;
break;
}
c10 = 65535;
break;
case -1373388978:
if (str4.equals(MatroskaExtractor.CODEC_ID_FOURCC)) {
c10 = 7;
break;
}
c10 = 65535;
break;
case -933872740:
if (str4.equals(MatroskaExtractor.CODEC_ID_DVBSUB)) {
c10 = '\b';
break;
}
c10 = 65535;
break;
case -538363189:
if (str4.equals(MatroskaExtractor.CODEC_ID_MPEG4_ASP)) {
c10 = '\t';
break;
}
c10 = 65535;
break;
case -538363109:
if (str4.equals(MatroskaExtractor.CODEC_ID_H264)) {
c10 = '\n';
break;
}
c10 = 65535;
break;
case -425012669:
if (str4.equals(MatroskaExtractor.CODEC_ID_VOBSUB)) {
c10 = 11;
break;
}
c10 = 65535;
break;
case -356037306:
if (str4.equals(MatroskaExtractor.CODEC_ID_DTS_LOSSLESS)) {
c10 = '\f';
break;
}
c10 = 65535;
break;
case 62923557:
if (str4.equals(MatroskaExtractor.CODEC_ID_AAC)) {
c10 = '\r';
break;
}
c10 = 65535;
break;
case 62923603:
if (str4.equals(MatroskaExtractor.CODEC_ID_AC3)) {
c10 = 14;
break;
}
c10 = 65535;
break;
case 62927045:
if (str4.equals(MatroskaExtractor.CODEC_ID_DTS)) {
c10 = 15;
break;
}
c10 = 65535;
break;
case 82338133:
if (str4.equals(MatroskaExtractor.CODEC_ID_VP8)) {
c10 = 16;
break;
}
c10 = 65535;
break;
case 82338134:
if (str4.equals(MatroskaExtractor.CODEC_ID_VP9)) {
c10 = 17;
break;
}
c10 = 65535;
break;
case 99146302:
if (str4.equals(MatroskaExtractor.CODEC_ID_PGS)) {
c10 = 18;
break;
}
c10 = 65535;
break;
case 444813526:
if (str4.equals(MatroskaExtractor.CODEC_ID_THEORA)) {
c10 = 19;
break;
}
c10 = 65535;
break;
case 542569478:
if (str4.equals(MatroskaExtractor.CODEC_ID_DTS_EXPRESS)) {
c10 = 20;
break;
}
c10 = 65535;
break;
case 725957860:
if (str4.equals(MatroskaExtractor.CODEC_ID_PCM_INT_LIT)) {
c10 = 21;
break;
}
c10 = 65535;
break;
case 738597099:
if (str4.equals(MatroskaExtractor.CODEC_ID_ASS)) {
c10 = 22;
break;
}
c10 = 65535;
break;
case 855502857:
if (str4.equals(MatroskaExtractor.CODEC_ID_H265)) {
c10 = 23;
break;
}
c10 = 65535;
break;
case 1422270023:
if (str4.equals(MatroskaExtractor.CODEC_ID_SUBRIP)) {
c10 = 24;
break;
}
c10 = 65535;
break;
case 1809237540:
if (str4.equals(MatroskaExtractor.CODEC_ID_MPEG2)) {
c10 = 25;
break;
}
c10 = 65535;
break;
case 1950749482:
if (str4.equals(MatroskaExtractor.CODEC_ID_E_AC3)) {
c10 = 26;
break;
}
c10 = 65535;
break;
case 1950789798:
if (str4.equals(MatroskaExtractor.CODEC_ID_FLAC)) {
c10 = 27;
break;
}
c10 = 65535;
break;
case 1951062397:
if (str4.equals(MatroskaExtractor.CODEC_ID_OPUS)) {
c10 = 28;
break;
}
c10 = 65535;
break;
default:
c10 = 65535;
break;
}
String str5 = MimeTypes.AUDIO_UNKNOWN;
switch (c10) {
case 0:
case 1:
case '\t':
byte[] bArr = this.codecPrivate;
singletonList = bArr == null ? null : Collections.singletonList(bArr);
str = MimeTypes.VIDEO_MP4V;
str5 = str;
i11 = -1;
i12 = -1;
int i16 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
createImageSampleFormat = Format.createAudioSampleFormat(Integer.toString(i10), str5, null, -1, i12, this.channelCount, this.sampleRate, i11, singletonList, this.drmInitData, i16, this.language);
} else if (MimeTypes.isVideo(str5)) {
if (this.displayUnit == 0) {
int i17 = this.displayWidth;
i13 = -1;
if (i17 == -1) {
i17 = this.width;
}
this.displayWidth = i17;
int i18 = this.displayHeight;
if (i18 == -1) {
i18 = this.height;
}
this.displayHeight = i18;
} else {
i13 = -1;
}
createImageSampleFormat = Format.createVideoSampleFormat(Integer.toString(i10), str5, null, -1, i12, this.width, this.height, -1.0f, singletonList, -1, (this.displayWidth == i13 || (i14 = this.displayHeight) == i13) ? -1.0f : (this.height * r4) / (this.width * i14), this.projectionData, this.stereoMode, this.hasColorInfo ? new ColorInfo(this.colorSpace, this.colorRange, this.colorTransfer, getHdrStaticInfo()) : null, this.drmInitData);
i15 = 2;
} else {
if (MimeTypes.APPLICATION_SUBRIP.equals(str5)) {
createImageSampleFormat = Format.createTextSampleFormat(Integer.toString(i10), str5, i16, this.language, this.drmInitData);
} else if (MimeTypes.TEXT_SSA.equals(str5)) {
ArrayList arrayList = new ArrayList(2);
arrayList.add(MatroskaExtractor.SSA_DIALOGUE_FORMAT);
arrayList.add(this.codecPrivate);
createImageSampleFormat = Format.createTextSampleFormat(Integer.toString(i10), str5, null, -1, i16, this.language, -1, this.drmInitData, Long.MAX_VALUE, arrayList);
} else {
if (!MimeTypes.APPLICATION_VOBSUB.equals(str5) && !MimeTypes.APPLICATION_PGS.equals(str5) && !MimeTypes.APPLICATION_DVBSUBS.equals(str5)) {
throw new ParserException("Unexpected MIME type.");
}
createImageSampleFormat = Format.createImageSampleFormat(Integer.toString(i10), str5, null, -1, i16, singletonList, this.language, this.drmInitData);
}
i15 = 3;
}
TrackOutput track = extractorOutput.track(this.number, i15);
this.output = track;
track.format(createImageSampleFormat);
return;
case 2:
if (parseMsAcmCodecPrivate(new ParsableByteArray(this.codecPrivate))) {
pcmEncoding = Util.getPcmEncoding(this.audioBitDepth);
if (pcmEncoding == 0) {
Log.w(MatroskaExtractor.TAG, "Unsupported PCM bit depth: " + this.audioBitDepth + ". Setting mimeType to " + MimeTypes.AUDIO_UNKNOWN);
}
i11 = pcmEncoding;
str5 = MimeTypes.AUDIO_RAW;
singletonList = null;
i12 = -1;
int i162 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track2 = extractorOutput.track(this.number, i15);
this.output = track2;
track2.format(createImageSampleFormat);
return;
}
Log.w(MatroskaExtractor.TAG, "Non-PCM MS/ACM is unsupported. Setting mimeType to " + MimeTypes.AUDIO_UNKNOWN);
singletonList = null;
i11 = -1;
i12 = -1;
int i1622 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track22 = extractorOutput.track(this.number, i15);
this.output = track22;
track22.format(createImageSampleFormat);
return;
case 3:
this.trueHdSampleRechunker = new TrueHdSampleRechunker();
str2 = MimeTypes.AUDIO_TRUEHD;
str5 = str2;
singletonList = null;
i11 = -1;
i12 = -1;
int i16222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track222 = extractorOutput.track(this.number, i15);
this.output = track222;
track222.format(createImageSampleFormat);
return;
case 4:
singletonList = parseVorbisCodecPrivate(this.codecPrivate);
str5 = MimeTypes.AUDIO_VORBIS;
i11 = -1;
i12 = 8192;
int i162222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track2222 = extractorOutput.track(this.number, i15);
this.output = track2222;
track2222.format(createImageSampleFormat);
return;
case 5:
str3 = MimeTypes.AUDIO_MPEG_L2;
str5 = str3;
singletonList = null;
i11 = -1;
i12 = 4096;
int i1622222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track22222 = extractorOutput.track(this.number, i15);
this.output = track22222;
track22222.format(createImageSampleFormat);
return;
case 6:
str3 = MimeTypes.AUDIO_MPEG;
str5 = str3;
singletonList = null;
i11 = -1;
i12 = 4096;
int i16222222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track222222 = extractorOutput.track(this.number, i15);
this.output = track222222;
track222222.format(createImageSampleFormat);
return;
case 7:
Pair<String, List<byte[]>> parseFourCcPrivate = parseFourCcPrivate(new ParsableByteArray(this.codecPrivate));
str = (String) parseFourCcPrivate.first;
singletonList = (List) parseFourCcPrivate.second;
str5 = str;
i11 = -1;
i12 = -1;
int i162222222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track2222222 = extractorOutput.track(this.number, i15);
this.output = track2222222;
track2222222.format(createImageSampleFormat);
return;
case '\b':
byte[] bArr2 = this.codecPrivate;
singletonList = Collections.singletonList(new byte[]{bArr2[0], bArr2[1], bArr2[2], bArr2[3]});
str5 = MimeTypes.APPLICATION_DVBSUBS;
i11 = -1;
i12 = -1;
int i1622222222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track22222222 = extractorOutput.track(this.number, i15);
this.output = track22222222;
track22222222.format(createImageSampleFormat);
return;
case '\n':
AvcConfig parse = AvcConfig.parse(new ParsableByteArray(this.codecPrivate));
list = parse.initializationData;
this.nalUnitLengthFieldLength = parse.nalUnitLengthFieldLength;
str = MimeTypes.VIDEO_H264;
singletonList = list;
str5 = str;
i11 = -1;
i12 = -1;
int i16222222222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track222222222 = extractorOutput.track(this.number, i15);
this.output = track222222222;
track222222222.format(createImageSampleFormat);
return;
case 11:
singletonList = Collections.singletonList(this.codecPrivate);
str5 = MimeTypes.APPLICATION_VOBSUB;
i11 = -1;
i12 = -1;
int i162222222222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track2222222222 = extractorOutput.track(this.number, i15);
this.output = track2222222222;
track2222222222.format(createImageSampleFormat);
return;
case '\f':
str2 = MimeTypes.AUDIO_DTS_HD;
str5 = str2;
singletonList = null;
i11 = -1;
i12 = -1;
int i1622222222222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track22222222222 = extractorOutput.track(this.number, i15);
this.output = track22222222222;
track22222222222.format(createImageSampleFormat);
return;
case '\r':
singletonList = Collections.singletonList(this.codecPrivate);
str = MimeTypes.AUDIO_AAC;
str5 = str;
i11 = -1;
i12 = -1;
int i16222222222222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track222222222222 = extractorOutput.track(this.number, i15);
this.output = track222222222222;
track222222222222.format(createImageSampleFormat);
return;
case 14:
str2 = MimeTypes.AUDIO_AC3;
str5 = str2;
singletonList = null;
i11 = -1;
i12 = -1;
int i162222222222222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track2222222222222 = extractorOutput.track(this.number, i15);
this.output = track2222222222222;
track2222222222222.format(createImageSampleFormat);
return;
case 15:
case 20:
str2 = MimeTypes.AUDIO_DTS;
str5 = str2;
singletonList = null;
i11 = -1;
i12 = -1;
int i1622222222222222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track22222222222222 = extractorOutput.track(this.number, i15);
this.output = track22222222222222;
track22222222222222.format(createImageSampleFormat);
return;
case 16:
str2 = MimeTypes.VIDEO_VP8;
str5 = str2;
singletonList = null;
i11 = -1;
i12 = -1;
int i16222222222222222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track222222222222222 = extractorOutput.track(this.number, i15);
this.output = track222222222222222;
track222222222222222.format(createImageSampleFormat);
return;
case 17:
str2 = MimeTypes.VIDEO_VP9;
str5 = str2;
singletonList = null;
i11 = -1;
i12 = -1;
int i162222222222222222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track2222222222222222 = extractorOutput.track(this.number, i15);
this.output = track2222222222222222;
track2222222222222222.format(createImageSampleFormat);
return;
case 18:
str5 = MimeTypes.APPLICATION_PGS;
singletonList = null;
i11 = -1;
i12 = -1;
int i1622222222222222222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track22222222222222222 = extractorOutput.track(this.number, i15);
this.output = track22222222222222222;
track22222222222222222.format(createImageSampleFormat);
return;
case 19:
str2 = MimeTypes.VIDEO_UNKNOWN;
str5 = str2;
singletonList = null;
i11 = -1;
i12 = -1;
int i16222222222222222222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track222222222222222222 = extractorOutput.track(this.number, i15);
this.output = track222222222222222222;
track222222222222222222.format(createImageSampleFormat);
return;
case 21:
pcmEncoding = Util.getPcmEncoding(this.audioBitDepth);
if (pcmEncoding == 0) {
Log.w(MatroskaExtractor.TAG, "Unsupported PCM bit depth: " + this.audioBitDepth + ". Setting mimeType to " + MimeTypes.AUDIO_UNKNOWN);
singletonList = null;
i11 = -1;
i12 = -1;
int i162222222222222222222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track2222222222222222222 = extractorOutput.track(this.number, i15);
this.output = track2222222222222222222;
track2222222222222222222.format(createImageSampleFormat);
return;
}
i11 = pcmEncoding;
str5 = MimeTypes.AUDIO_RAW;
singletonList = null;
i12 = -1;
int i1622222222222222222222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track22222222222222222222 = extractorOutput.track(this.number, i15);
this.output = track22222222222222222222;
track22222222222222222222.format(createImageSampleFormat);
return;
case 22:
str5 = MimeTypes.TEXT_SSA;
singletonList = null;
i11 = -1;
i12 = -1;
int i16222222222222222222222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track222222222222222222222 = extractorOutput.track(this.number, i15);
this.output = track222222222222222222222;
track222222222222222222222.format(createImageSampleFormat);
return;
case 23:
HevcConfig parse2 = HevcConfig.parse(new ParsableByteArray(this.codecPrivate));
list = parse2.initializationData;
this.nalUnitLengthFieldLength = parse2.nalUnitLengthFieldLength;
str = MimeTypes.VIDEO_H265;
singletonList = list;
str5 = str;
i11 = -1;
i12 = -1;
int i162222222222222222222222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track2222222222222222222222 = extractorOutput.track(this.number, i15);
this.output = track2222222222222222222222;
track2222222222222222222222.format(createImageSampleFormat);
return;
case 24:
str5 = MimeTypes.APPLICATION_SUBRIP;
singletonList = null;
i11 = -1;
i12 = -1;
int i1622222222222222222222222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track22222222222222222222222 = extractorOutput.track(this.number, i15);
this.output = track22222222222222222222222;
track22222222222222222222222.format(createImageSampleFormat);
return;
case 25:
str2 = MimeTypes.VIDEO_MPEG2;
str5 = str2;
singletonList = null;
i11 = -1;
i12 = -1;
int i16222222222222222222222222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track222222222222222222222222 = extractorOutput.track(this.number, i15);
this.output = track222222222222222222222222;
track222222222222222222222222.format(createImageSampleFormat);
return;
case 26:
str2 = MimeTypes.AUDIO_E_AC3;
str5 = str2;
singletonList = null;
i11 = -1;
i12 = -1;
int i162222222222222222222222222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track2222222222222222222222222 = extractorOutput.track(this.number, i15);
this.output = track2222222222222222222222222;
track2222222222222222222222222.format(createImageSampleFormat);
return;
case 27:
singletonList = Collections.singletonList(this.codecPrivate);
str = MimeTypes.AUDIO_FLAC;
str5 = str;
i11 = -1;
i12 = -1;
int i1622222222222222222222222222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track22222222222222222222222222 = extractorOutput.track(this.number, i15);
this.output = track22222222222222222222222222;
track22222222222222222222222222.format(createImageSampleFormat);
return;
case 28:
singletonList = new ArrayList<>(3);
singletonList.add(this.codecPrivate);
singletonList.add(ByteBuffer.allocate(8).order(ByteOrder.nativeOrder()).putLong(this.codecDelayNs).array());
singletonList.add(ByteBuffer.allocate(8).order(ByteOrder.nativeOrder()).putLong(this.seekPreRollNs).array());
str5 = MimeTypes.AUDIO_OPUS;
i11 = -1;
i12 = MatroskaExtractor.OPUS_MAX_INPUT_SIZE;
int i16222222222222222222222222222 = (this.flagDefault ? 1 : 0) | 0 | (this.flagForced ? 2 : 0);
if (!MimeTypes.isAudio(str5)) {
}
TrackOutput track222222222222222222222222222 = extractorOutput.track(this.number, i15);
this.output = track222222222222222222222222222;
track222222222222222222222222222.format(createImageSampleFormat);
return;
default:
throw new ParserException("Unrecognized codec identifier.");
}
}
public final void outputPendingSampleMetadata() {
TrueHdSampleRechunker trueHdSampleRechunker = this.trueHdSampleRechunker;
if (trueHdSampleRechunker != null) {
trueHdSampleRechunker.outputPendingSampleMetadata(this);
}
}
public final void reset() {
TrueHdSampleRechunker trueHdSampleRechunker = this.trueHdSampleRechunker;
if (trueHdSampleRechunker != null) {
trueHdSampleRechunker.reset();
}
}
}
public static final class TrueHdSampleRechunker {
private int blockFlags;
private int chunkSize;
private boolean foundSyncframe;
private int sampleCount;
private final byte[] syncframePrefix = new byte[10];
private long timeUs;
public final void outputPendingSampleMetadata(Track track) {
if (!this.foundSyncframe || this.sampleCount <= 0) {
return;
}
track.output.sampleMetadata(this.timeUs, this.blockFlags, this.chunkSize, 0, track.cryptoData);
this.sampleCount = 0;
}
public final void reset() {
this.foundSyncframe = false;
}
public final void sampleMetadata(Track track, long j10) {
if (this.foundSyncframe) {
int i10 = this.sampleCount;
int i11 = i10 + 1;
this.sampleCount = i11;
if (i10 == 0) {
this.timeUs = j10;
}
if (i11 < 16) {
return;
}
track.output.sampleMetadata(this.timeUs, this.blockFlags, this.chunkSize, 0, track.cryptoData);
this.sampleCount = 0;
}
}
public final void startSample(ExtractorInput extractorInput, int i10, int i11) throws IOException, InterruptedException {
if (!this.foundSyncframe) {
extractorInput.peekFully(this.syncframePrefix, 0, 10);
extractorInput.resetPeekPosition();
if (Ac3Util.parseTrueHdSyncframeAudioSampleCount(this.syncframePrefix) == -1) {
return;
}
this.foundSyncframe = true;
this.sampleCount = 0;
}
if (this.sampleCount == 0) {
this.blockFlags = i10;
this.chunkSize = 0;
}
this.chunkSize += i11;
}
}
public MatroskaExtractor() {
this(0);
}
private SeekMap buildSeekMap() {
LongArray longArray;
LongArray longArray2;
if (this.segmentContentPosition != -1 && this.durationUs != C.TIME_UNSET && (longArray = this.cueTimesUs) != null && longArray.size() != 0 && (longArray2 = this.cueClusterPositions) != null && longArray2.size() == this.cueTimesUs.size()) {
int size = this.cueTimesUs.size();
int[] iArr = new int[size];
long[] jArr = new long[size];
long[] jArr2 = new long[size];
long[] jArr3 = new long[size];
int i10 = 0;
for (int i11 = 0; i11 < size; i11++) {
jArr3[i11] = this.cueTimesUs.get(i11);
jArr[i11] = this.segmentContentPosition + this.cueClusterPositions.get(i11);
}
while (true) {
int i12 = size - 1;
if (i10 < i12) {
int i13 = i10 + 1;
iArr[i10] = (int) (jArr[i13] - jArr[i10]);
jArr2[i10] = jArr3[i13] - jArr3[i10];
i10 = i13;
} else {
iArr[i12] = (int) ((this.segmentContentPosition + this.segmentContentSize) - jArr[i12]);
jArr2[i12] = this.durationUs - jArr3[i12];
this.cueTimesUs = null;
this.cueClusterPositions = null;
return new ChunkIndex(iArr, jArr, jArr2, jArr3);
}
}
} else {
this.cueTimesUs = null;
this.cueClusterPositions = null;
return new SeekMap.Unseekable(this.durationUs);
}
}
private void commitSampleToOutput(Track track, long j10) {
TrueHdSampleRechunker trueHdSampleRechunker = track.trueHdSampleRechunker;
if (trueHdSampleRechunker != null) {
trueHdSampleRechunker.sampleMetadata(track, j10);
} else {
if (CODEC_ID_SUBRIP.equals(track.codecId)) {
commitSubtitleSample(track, SUBRIP_TIMECODE_FORMAT, 19, 1000L, SUBRIP_TIMECODE_EMPTY);
} else if (CODEC_ID_ASS.equals(track.codecId)) {
commitSubtitleSample(track, SSA_TIMECODE_FORMAT, 21, SSA_TIMECODE_LAST_VALUE_SCALING_FACTOR, SSA_TIMECODE_EMPTY);
}
track.output.sampleMetadata(j10, this.blockFlags, this.sampleBytesWritten, 0, track.cryptoData);
}
this.sampleRead = true;
resetSample();
}
private void commitSubtitleSample(Track track, String str, int i10, long j10, byte[] bArr) {
setSampleDuration(this.subtitleSample.data, this.blockDurationUs, str, i10, j10, bArr);
TrackOutput trackOutput = track.output;
ParsableByteArray parsableByteArray = this.subtitleSample;
trackOutput.sampleData(parsableByteArray, parsableByteArray.limit());
this.sampleBytesWritten += this.subtitleSample.limit();
}
private static int[] ensureArrayCapacity(int[] iArr, int i10) {
if (iArr == null) {
return new int[i10];
}
return iArr.length >= i10 ? iArr : new int[Math.max(iArr.length * 2, i10)];
}
private static boolean isCodecSupported(String str) {
return CODEC_ID_VP8.equals(str) || CODEC_ID_VP9.equals(str) || CODEC_ID_MPEG2.equals(str) || CODEC_ID_MPEG4_SP.equals(str) || CODEC_ID_MPEG4_ASP.equals(str) || CODEC_ID_MPEG4_AP.equals(str) || CODEC_ID_H264.equals(str) || CODEC_ID_H265.equals(str) || CODEC_ID_FOURCC.equals(str) || CODEC_ID_THEORA.equals(str) || CODEC_ID_OPUS.equals(str) || CODEC_ID_VORBIS.equals(str) || CODEC_ID_AAC.equals(str) || CODEC_ID_MP2.equals(str) || CODEC_ID_MP3.equals(str) || CODEC_ID_AC3.equals(str) || CODEC_ID_E_AC3.equals(str) || CODEC_ID_TRUEHD.equals(str) || CODEC_ID_DTS.equals(str) || CODEC_ID_DTS_EXPRESS.equals(str) || CODEC_ID_DTS_LOSSLESS.equals(str) || CODEC_ID_FLAC.equals(str) || CODEC_ID_ACM.equals(str) || CODEC_ID_PCM_INT_LIT.equals(str) || CODEC_ID_SUBRIP.equals(str) || CODEC_ID_ASS.equals(str) || CODEC_ID_VOBSUB.equals(str) || CODEC_ID_PGS.equals(str) || CODEC_ID_DVBSUB.equals(str);
}
private boolean maybeSeekForCues(PositionHolder positionHolder, long j10) {
if (this.seekForCues) {
this.seekPositionAfterBuildingCues = j10;
positionHolder.position = this.cuesContentPosition;
this.seekForCues = false;
return true;
}
if (this.sentSeekMap) {
long j11 = this.seekPositionAfterBuildingCues;
if (j11 != -1) {
positionHolder.position = j11;
this.seekPositionAfterBuildingCues = -1L;
return true;
}
}
return false;
}
private void readScratch(ExtractorInput extractorInput, int i10) throws IOException, InterruptedException {
if (this.scratch.limit() >= i10) {
return;
}
if (this.scratch.capacity() < i10) {
ParsableByteArray parsableByteArray = this.scratch;
byte[] bArr = parsableByteArray.data;
parsableByteArray.reset(Arrays.copyOf(bArr, Math.max(bArr.length * 2, i10)), this.scratch.limit());
}
ParsableByteArray parsableByteArray2 = this.scratch;
extractorInput.readFully(parsableByteArray2.data, parsableByteArray2.limit(), i10 - this.scratch.limit());
this.scratch.setLimit(i10);
}
private int readToOutput(ExtractorInput extractorInput, TrackOutput trackOutput, int i10) throws IOException, InterruptedException {
int sampleData;
int bytesLeft = this.sampleStrippedBytes.bytesLeft();
if (bytesLeft > 0) {
sampleData = Math.min(i10, bytesLeft);
trackOutput.sampleData(this.sampleStrippedBytes, sampleData);
} else {
sampleData = trackOutput.sampleData(extractorInput, i10, false);
}
this.sampleBytesRead += sampleData;
this.sampleBytesWritten += sampleData;
return sampleData;
}
private void readToTarget(ExtractorInput extractorInput, byte[] bArr, int i10, int i11) throws IOException, InterruptedException {
int min = Math.min(i11, this.sampleStrippedBytes.bytesLeft());
extractorInput.readFully(bArr, i10 + min, i11 - min);
if (min > 0) {
this.sampleStrippedBytes.readBytes(bArr, i10, min);
}
this.sampleBytesRead += i11;
}
private void resetSample() {
this.sampleBytesRead = 0;
this.sampleBytesWritten = 0;
this.sampleCurrentNalBytesRemaining = 0;
this.sampleEncodingHandled = false;
this.sampleSignalByteRead = false;
this.samplePartitionCountRead = false;
this.samplePartitionCount = 0;
this.sampleSignalByte = (byte) 0;
this.sampleInitializationVectorRead = false;
this.sampleStrippedBytes.reset();
}
private long scaleTimecodeToUs(long j10) throws ParserException {
long j11 = this.timecodeScale;
if (j11 != C.TIME_UNSET) {
return Util.scaleLargeTimestamp(j10, j11, 1000L);
}
throw new ParserException("Can't scale timecode prior to timecodeScale being set.");
}
private static void setSampleDuration(byte[] bArr, long j10, String str, int i10, long j11, byte[] bArr2) {
byte[] utf8Bytes;
byte[] bArr3;
if (j10 == C.TIME_UNSET) {
utf8Bytes = bArr2;
bArr3 = utf8Bytes;
} else {
long j12 = j10 - ((r2 * 3600) * 1000000);
int i11 = (int) (j12 / 60000000);
long j13 = j12 - ((i11 * 60) * 1000000);
int i12 = (int) (j13 / 1000000);
utf8Bytes = Util.getUtf8Bytes(String.format(Locale.US, str, Integer.valueOf((int) (j10 / 3600000000L)), Integer.valueOf(i11), Integer.valueOf(i12), Integer.valueOf((int) ((j13 - (i12 * 1000000)) / j11))));
bArr3 = bArr2;
}
System.arraycopy(utf8Bytes, 0, bArr, i10, bArr3.length);
}
private void writeSampleData(ExtractorInput extractorInput, Track track, int i10) throws IOException, InterruptedException {
int i11;
if (CODEC_ID_SUBRIP.equals(track.codecId)) {
writeSubtitleSampleData(extractorInput, SUBRIP_PREFIX, i10);
return;
}
if (CODEC_ID_ASS.equals(track.codecId)) {
writeSubtitleSampleData(extractorInput, SSA_PREFIX, i10);
return;
}
TrackOutput trackOutput = track.output;
if (!this.sampleEncodingHandled) {
if (track.hasContentEncryption) {
this.blockFlags &= -1073741825;
if (!this.sampleSignalByteRead) {
extractorInput.readFully(this.scratch.data, 0, 1);
this.sampleBytesRead++;
byte[] bArr = this.scratch.data;
if ((bArr[0] & 128) != 128) {
this.sampleSignalByte = bArr[0];
this.sampleSignalByteRead = true;
} else {
throw new ParserException("Extension bit is set in signal byte");
}
}
byte b10 = this.sampleSignalByte;
if ((b10 & 1) == 1) {
boolean z10 = (b10 & 2) == 2;
this.blockFlags |= 1073741824;
if (!this.sampleInitializationVectorRead) {
extractorInput.readFully(this.encryptionInitializationVector.data, 0, 8);
this.sampleBytesRead += 8;
this.sampleInitializationVectorRead = true;
ParsableByteArray parsableByteArray = this.scratch;
parsableByteArray.data[0] = (byte) ((z10 ? 128 : 0) | 8);
parsableByteArray.setPosition(0);
trackOutput.sampleData(this.scratch, 1);
this.sampleBytesWritten++;
this.encryptionInitializationVector.setPosition(0);
trackOutput.sampleData(this.encryptionInitializationVector, 8);
this.sampleBytesWritten += 8;
}
if (z10) {
if (!this.samplePartitionCountRead) {
extractorInput.readFully(this.scratch.data, 0, 1);
this.sampleBytesRead++;
this.scratch.setPosition(0);
this.samplePartitionCount = this.scratch.readUnsignedByte();
this.samplePartitionCountRead = true;
}
int i12 = this.samplePartitionCount * 4;
this.scratch.reset(i12);
extractorInput.readFully(this.scratch.data, 0, i12);
this.sampleBytesRead += i12;
short s10 = (short) ((this.samplePartitionCount / 2) + 1);
int i13 = (s10 * 6) + 2;
ByteBuffer byteBuffer = this.encryptionSubsampleDataBuffer;
if (byteBuffer == null || byteBuffer.capacity() < i13) {
this.encryptionSubsampleDataBuffer = ByteBuffer.allocate(i13);
}
this.encryptionSubsampleDataBuffer.position(0);
this.encryptionSubsampleDataBuffer.putShort(s10);
int i14 = 0;
int i15 = 0;
while (true) {
i11 = this.samplePartitionCount;
if (i14 >= i11) {
break;
}
int readUnsignedIntToInt = this.scratch.readUnsignedIntToInt();
if (i14 % 2 == 0) {
this.encryptionSubsampleDataBuffer.putShort((short) (readUnsignedIntToInt - i15));
} else {
this.encryptionSubsampleDataBuffer.putInt(readUnsignedIntToInt - i15);
}
i14++;
i15 = readUnsignedIntToInt;
}
int i16 = (i10 - this.sampleBytesRead) - i15;
if (i11 % 2 == 1) {
this.encryptionSubsampleDataBuffer.putInt(i16);
} else {
this.encryptionSubsampleDataBuffer.putShort((short) i16);
this.encryptionSubsampleDataBuffer.putInt(0);
}
this.encryptionSubsampleData.reset(this.encryptionSubsampleDataBuffer.array(), i13);
trackOutput.sampleData(this.encryptionSubsampleData, i13);
this.sampleBytesWritten += i13;
}
}
} else {
byte[] bArr2 = track.sampleStrippedBytes;
if (bArr2 != null) {
this.sampleStrippedBytes.reset(bArr2, bArr2.length);
}
}
this.sampleEncodingHandled = true;
}
int limit = i10 + this.sampleStrippedBytes.limit();
if (!CODEC_ID_H264.equals(track.codecId) && !CODEC_ID_H265.equals(track.codecId)) {
if (track.trueHdSampleRechunker != null) {
Assertions.checkState(this.sampleStrippedBytes.limit() == 0);
track.trueHdSampleRechunker.startSample(extractorInput, this.blockFlags, limit);
}
while (true) {
int i17 = this.sampleBytesRead;
if (i17 >= limit) {
break;
} else {
readToOutput(extractorInput, trackOutput, limit - i17);
}
}
} else {
byte[] bArr3 = this.nalLength.data;
bArr3[0] = 0;
bArr3[1] = 0;
bArr3[2] = 0;
int i18 = track.nalUnitLengthFieldLength;
int i19 = 4 - i18;
while (this.sampleBytesRead < limit) {
int i20 = this.sampleCurrentNalBytesRemaining;
if (i20 == 0) {
readToTarget(extractorInput, bArr3, i19, i18);
this.nalLength.setPosition(0);
this.sampleCurrentNalBytesRemaining = this.nalLength.readUnsignedIntToInt();
this.nalStartCode.setPosition(0);
trackOutput.sampleData(this.nalStartCode, 4);
this.sampleBytesWritten += 4;
} else {
this.sampleCurrentNalBytesRemaining = i20 - readToOutput(extractorInput, trackOutput, i20);
}
}
}
if (CODEC_ID_VORBIS.equals(track.codecId)) {
this.vorbisNumPageSamples.setPosition(0);
trackOutput.sampleData(this.vorbisNumPageSamples, 4);
this.sampleBytesWritten += 4;
}
}
private void writeSubtitleSampleData(ExtractorInput extractorInput, byte[] bArr, int i10) throws IOException, InterruptedException {
int length = bArr.length + i10;
if (this.subtitleSample.capacity() < length) {
this.subtitleSample.data = Arrays.copyOf(bArr, length + i10);
} else {
System.arraycopy(bArr, 0, this.subtitleSample.data, 0, bArr.length);
}
extractorInput.readFully(this.subtitleSample.data, bArr.length, i10);
this.subtitleSample.reset(length);
}
public final void binaryElement(int i10, int i11, ExtractorInput extractorInput) throws IOException, InterruptedException {
char c10;
int i12;
int i13;
int[] iArr;
int i14 = 0;
int i15 = 1;
if (i10 != 161 && i10 != ID_SIMPLE_BLOCK) {
if (i10 == ID_CONTENT_COMPRESSION_SETTINGS) {
byte[] bArr = new byte[i11];
this.currentTrack.sampleStrippedBytes = bArr;
extractorInput.readFully(bArr, 0, i11);
return;
}
if (i10 == ID_CONTENT_ENCRYPTION_KEY_ID) {
byte[] bArr2 = new byte[i11];
extractorInput.readFully(bArr2, 0, i11);
this.currentTrack.cryptoData = new TrackOutput.CryptoData(1, bArr2, 0, 0);
return;
}
if (i10 == ID_SEEK_ID) {
Arrays.fill(this.seekEntryIdBytes.data, (byte) 0);
extractorInput.readFully(this.seekEntryIdBytes.data, 4 - i11, i11);
this.seekEntryIdBytes.setPosition(0);
this.seekEntryId = (int) this.seekEntryIdBytes.readUnsignedInt();
return;
}
if (i10 == ID_CODEC_PRIVATE) {
byte[] bArr3 = new byte[i11];
this.currentTrack.codecPrivate = bArr3;
extractorInput.readFully(bArr3, 0, i11);
return;
} else if (i10 == ID_PROJECTION_PRIVATE) {
byte[] bArr4 = new byte[i11];
this.currentTrack.projectionData = bArr4;
extractorInput.readFully(bArr4, 0, i11);
return;
} else {
throw new ParserException("Unexpected id: " + i10);
}
}
if (this.blockState == 0) {
this.blockTrackNumber = (int) this.varintReader.readUnsignedVarint(extractorInput, false, true, 8);
this.blockTrackNumberLength = this.varintReader.getLastLength();
this.blockDurationUs = C.TIME_UNSET;
this.blockState = 1;
this.scratch.reset();
}
Track track = this.tracks.get(this.blockTrackNumber);
if (track == null) {
extractorInput.skipFully(i11 - this.blockTrackNumberLength);
this.blockState = 0;
return;
}
if (this.blockState == 1) {
readScratch(extractorInput, 3);
int i16 = (this.scratch.data[2] & 6) >> 1;
byte b10 = ExifInterface.MARKER;
if (i16 == 0) {
this.blockLacingSampleCount = 1;
int[] ensureArrayCapacity = ensureArrayCapacity(this.blockLacingSampleSizes, 1);
this.blockLacingSampleSizes = ensureArrayCapacity;
ensureArrayCapacity[0] = (i11 - this.blockTrackNumberLength) - 3;
} else if (i10 == ID_SIMPLE_BLOCK) {
int i17 = 4;
readScratch(extractorInput, 4);
int i18 = (this.scratch.data[3] & ExifInterface.MARKER) + 1;
this.blockLacingSampleCount = i18;
int[] ensureArrayCapacity2 = ensureArrayCapacity(this.blockLacingSampleSizes, i18);
this.blockLacingSampleSizes = ensureArrayCapacity2;
if (i16 == 2) {
int i19 = (i11 - this.blockTrackNumberLength) - 4;
int i20 = this.blockLacingSampleCount;
Arrays.fill(ensureArrayCapacity2, 0, i20, i19 / i20);
} else if (i16 == 1) {
int i21 = 0;
int i22 = 0;
while (true) {
i12 = this.blockLacingSampleCount;
if (i21 >= i12 - 1) {
break;
}
this.blockLacingSampleSizes[i21] = 0;
do {
i17++;
readScratch(extractorInput, i17);
i13 = this.scratch.data[i17 - 1] & ExifInterface.MARKER;
iArr = this.blockLacingSampleSizes;
iArr[i21] = iArr[i21] + i13;
} while (i13 == 255);
i22 += iArr[i21];
i21++;
}
this.blockLacingSampleSizes[i12 - 1] = ((i11 - this.blockTrackNumberLength) - i17) - i22;
} else {
if (i16 != 3) {
throw new ParserException("Unexpected lacing value: " + i16);
}
int i23 = 0;
int i24 = 0;
while (true) {
int i25 = this.blockLacingSampleCount;
if (i23 < i25 - 1) {
this.blockLacingSampleSizes[i23] = i14;
i17++;
readScratch(extractorInput, i17);
int i26 = i17 - 1;
if (this.scratch.data[i26] == 0) {
throw new ParserException("No valid varint length mask found");
}
long j10 = 0;
int i27 = 0;
while (true) {
if (i27 >= 8) {
break;
}
int i28 = i15 << (7 - i27);
if ((this.scratch.data[i26] & i28) != 0) {
i17 += i27;
readScratch(extractorInput, i17);
long j11 = (~i28) & this.scratch.data[i26] & b10;
int i29 = i26 + 1;
j10 = j11;
while (i29 < i17) {
long j12 = j10 << 8;
int i30 = i29 + 1;
long j13 = j12 | (this.scratch.data[i29] & b10);
b10 = ExifInterface.MARKER;
i29 = i30;
j10 = j13;
}
if (i23 > 0) {
j10 -= (1 << ((i27 * 7) + 6)) - 1;
}
} else {
i27++;
i15 = 1;
b10 = ExifInterface.MARKER;
}
}
long j14 = j10;
if (j14 < -2147483648L || j14 > 2147483647L) {
break;
}
int i31 = (int) j14;
int[] iArr2 = this.blockLacingSampleSizes;
if (i23 != 0) {
i31 += iArr2[i23 - 1];
}
iArr2[i23] = i31;
i24 += iArr2[i23];
i23++;
i14 = 0;
i15 = 1;
b10 = ExifInterface.MARKER;
} else {
c10 = 1;
this.blockLacingSampleSizes[i25 - 1] = ((i11 - this.blockTrackNumberLength) - i17) - i24;
break;
}
}
}
} else {
throw new ParserException("Lacing only supported in SimpleBlocks.");
}
c10 = 1;
byte[] bArr5 = this.scratch.data;
this.blockTimeUs = this.clusterTimecodeUs + scaleTimecodeToUs((bArr5[c10] & ExifInterface.MARKER) | (bArr5[0] << 8));
byte[] bArr6 = this.scratch.data;
this.blockFlags = ((track.type == 2 || (i10 == ID_SIMPLE_BLOCK && (bArr6[2] & 128) == 128)) ? 1 : 0) | ((bArr6[2] & 8) == 8 ? Integer.MIN_VALUE : 0);
this.blockState = 2;
this.blockLacingSampleIndex = 0;
}
if (i10 != ID_SIMPLE_BLOCK) {
writeSampleData(extractorInput, track, this.blockLacingSampleSizes[0]);
return;
}
while (true) {
int i32 = this.blockLacingSampleIndex;
if (i32 < this.blockLacingSampleCount) {
writeSampleData(extractorInput, track, this.blockLacingSampleSizes[i32]);
commitSampleToOutput(track, this.blockTimeUs + ((this.blockLacingSampleIndex * track.defaultSampleDurationNs) / 1000));
this.blockLacingSampleIndex++;
} else {
this.blockState = 0;
return;
}
}
}
public final void endMasterElement(int i10) throws ParserException {
if (i10 == ID_BLOCK_GROUP) {
if (this.blockState != 2) {
return;
}
if (!this.sampleSeenReferenceBlock) {
this.blockFlags |= 1;
}
commitSampleToOutput(this.tracks.get(this.blockTrackNumber), this.blockTimeUs);
this.blockState = 0;
return;
}
if (i10 == ID_TRACK_ENTRY) {
if (isCodecSupported(this.currentTrack.codecId)) {
Track track = this.currentTrack;
track.initializeOutput(this.extractorOutput, track.number);
SparseArray<Track> sparseArray = this.tracks;
Track track2 = this.currentTrack;
sparseArray.put(track2.number, track2);
}
this.currentTrack = null;
return;
}
if (i10 == ID_SEEK) {
int i11 = this.seekEntryId;
if (i11 != -1) {
long j10 = this.seekEntryPosition;
if (j10 != -1) {
if (i11 == ID_CUES) {
this.cuesContentPosition = j10;
return;
}
return;
}
}
throw new ParserException("Mandatory element SeekID or SeekPosition not found");
}
if (i10 == ID_CONTENT_ENCODING) {
Track track3 = this.currentTrack;
if (track3.hasContentEncryption) {
if (track3.cryptoData != null) {
track3.drmInitData = new DrmInitData(new DrmInitData.SchemeData(C.UUID_NIL, MimeTypes.VIDEO_WEBM, this.currentTrack.cryptoData.encryptionKey));
return;
}
throw new ParserException("Encrypted Track found but ContentEncKeyID was not found");
}
return;
}
if (i10 == ID_CONTENT_ENCODINGS) {
Track track4 = this.currentTrack;
if (track4.hasContentEncryption && track4.sampleStrippedBytes != null) {
throw new ParserException("Combining encryption and compression is not supported");
}
return;
}
if (i10 == 357149030) {
if (this.timecodeScale == C.TIME_UNSET) {
this.timecodeScale = 1000000L;
}
long j11 = this.durationTimecode;
if (j11 != C.TIME_UNSET) {
this.durationUs = scaleTimecodeToUs(j11);
return;
}
return;
}
if (i10 != ID_TRACKS) {
if (i10 == ID_CUES && !this.sentSeekMap) {
this.extractorOutput.seekMap(buildSeekMap());
this.sentSeekMap = true;
return;
}
return;
}
if (this.tracks.size() != 0) {
this.extractorOutput.endTracks();
return;
}
throw new ParserException("No valid tracks were found");
}
public final void floatElement(int i10, double d10) {
if (i10 == ID_SAMPLING_FREQUENCY) {
this.currentTrack.sampleRate = (int) d10;
return;
}
if (i10 != ID_DURATION) {
switch (i10) {
case ID_PRIMARY_R_CHROMATICITY_X:
this.currentTrack.primaryRChromaticityX = (float) d10;
return;
case ID_PRIMARY_R_CHROMATICITY_Y:
this.currentTrack.primaryRChromaticityY = (float) d10;
return;
case ID_PRIMARY_G_CHROMATICITY_X:
this.currentTrack.primaryGChromaticityX = (float) d10;
return;
case ID_PRIMARY_G_CHROMATICITY_Y:
this.currentTrack.primaryGChromaticityY = (float) d10;
return;
case ID_PRIMARY_B_CHROMATICITY_X:
this.currentTrack.primaryBChromaticityX = (float) d10;
return;
case ID_PRIMARY_B_CHROMATICITY_Y:
this.currentTrack.primaryBChromaticityY = (float) d10;
return;
case ID_WHITE_POINT_CHROMATICITY_X:
this.currentTrack.whitePointChromaticityX = (float) d10;
return;
case ID_WHITE_POINT_CHROMATICITY_Y:
this.currentTrack.whitePointChromaticityY = (float) d10;
return;
case ID_LUMNINANCE_MAX:
this.currentTrack.maxMasteringLuminance = (float) d10;
return;
case ID_LUMNINANCE_MIN:
this.currentTrack.minMasteringLuminance = (float) d10;
return;
default:
return;
}
}
this.durationTimecode = (long) d10;
}
@Override
public final void init(ExtractorOutput extractorOutput) {
this.extractorOutput = extractorOutput;
}
public final void integerElement(int i10, long j10) throws ParserException {
if (i10 == ID_CONTENT_ENCODING_ORDER) {
if (j10 == 0) {
return;
}
throw new ParserException("ContentEncodingOrder " + j10 + " not supported");
}
if (i10 == ID_CONTENT_ENCODING_SCOPE) {
if (j10 == 1) {
return;
}
throw new ParserException("ContentEncodingScope " + j10 + " not supported");
}
switch (i10) {
case 131:
this.currentTrack.type = (int) j10;
return;
case 136:
this.currentTrack.flagDefault = j10 == 1;
return;
case 155:
this.blockDurationUs = scaleTimecodeToUs(j10);
return;
case ID_CHANNELS:
this.currentTrack.channelCount = (int) j10;
return;
case ID_PIXEL_WIDTH:
this.currentTrack.width = (int) j10;
return;
case ID_CUE_TIME:
this.cueTimesUs.add(scaleTimecodeToUs(j10));
return;
case ID_PIXEL_HEIGHT:
this.currentTrack.height = (int) j10;
return;
case ID_TRACK_NUMBER:
this.currentTrack.number = (int) j10;
return;
case ID_TIME_CODE:
this.clusterTimecodeUs = scaleTimecodeToUs(j10);
return;
case ID_CUE_CLUSTER_POSITION:
if (this.seenClusterPositionForCurrentCuePoint) {
return;
}
this.cueClusterPositions.add(j10);
this.seenClusterPositionForCurrentCuePoint = true;
return;
case ID_REFERENCE_BLOCK:
this.sampleSeenReferenceBlock = true;
return;
case ID_CONTENT_COMPRESSION_ALGORITHM:
if (j10 == 3) {
return;
}
throw new ParserException("ContentCompAlgo " + j10 + " not supported");
case ID_DOC_TYPE_READ_VERSION:
if (j10 < 1 || j10 > 2) {
throw new ParserException("DocTypeReadVersion " + j10 + " not supported");
}
return;
case ID_EBML_READ_VERSION:
if (j10 == 1) {
return;
}
throw new ParserException("EBMLReadVersion " + j10 + " not supported");
case ID_CONTENT_ENCRYPTION_ALGORITHM:
if (j10 == 5) {
return;
}
throw new ParserException("ContentEncAlgo " + j10 + " not supported");
case ID_CONTENT_ENCRYPTION_AES_SETTINGS_CIPHER_MODE:
if (j10 == 1) {
return;
}
throw new ParserException("AESSettingsCipherMode " + j10 + " not supported");
case ID_SEEK_POSITION:
this.seekEntryPosition = j10 + this.segmentContentPosition;
return;
case ID_STEREO_MODE:
int i11 = (int) j10;
if (i11 == 0) {
this.currentTrack.stereoMode = 0;
return;
}
if (i11 == 1) {
this.currentTrack.stereoMode = 2;
return;
} else if (i11 == 3) {
this.currentTrack.stereoMode = 1;
return;
} else {
if (i11 != 15) {
return;
}
this.currentTrack.stereoMode = 3;
return;
}
case ID_DISPLAY_WIDTH:
this.currentTrack.displayWidth = (int) j10;
return;
case ID_DISPLAY_UNIT:
this.currentTrack.displayUnit = (int) j10;
return;
case ID_DISPLAY_HEIGHT:
this.currentTrack.displayHeight = (int) j10;
return;
case ID_FLAG_FORCED:
this.currentTrack.flagForced = j10 == 1;
return;
case ID_CODEC_DELAY:
this.currentTrack.codecDelayNs = j10;
return;
case ID_SEEK_PRE_ROLL:
this.currentTrack.seekPreRollNs = j10;
return;
case ID_AUDIO_BIT_DEPTH:
this.currentTrack.audioBitDepth = (int) j10;
return;
case ID_DEFAULT_DURATION:
this.currentTrack.defaultSampleDurationNs = (int) j10;
return;
case ID_TIMECODE_SCALE:
this.timecodeScale = j10;
return;
default:
switch (i10) {
case ID_COLOUR_RANGE:
int i12 = (int) j10;
if (i12 == 1) {
this.currentTrack.colorRange = 2;
return;
} else {
if (i12 != 2) {
return;
}
this.currentTrack.colorRange = 1;
return;
}
case ID_COLOUR_TRANSFER:
int i13 = (int) j10;
if (i13 != 1) {
if (i13 == 16) {
this.currentTrack.colorTransfer = 6;
return;
} else if (i13 == 18) {
this.currentTrack.colorTransfer = 7;
return;
} else if (i13 != 6 && i13 != 7) {
return;
}
}
this.currentTrack.colorTransfer = 3;
return;
case ID_COLOUR_PRIMARIES:
Track track = this.currentTrack;
track.hasColorInfo = true;
int i14 = (int) j10;
if (i14 == 1) {
track.colorSpace = 1;
return;
}
if (i14 == 9) {
track.colorSpace = 6;
return;
} else {
if (i14 == 4 || i14 == 5 || i14 == 6 || i14 == 7) {
track.colorSpace = 2;
return;
}
return;
}
case ID_MAX_CLL:
this.currentTrack.maxContentLuminance = (int) j10;
return;
case ID_MAX_FALL:
this.currentTrack.maxFrameAverageLuminance = (int) j10;
return;
default:
return;
}
}
}
@Override
public final int read(ExtractorInput extractorInput, PositionHolder positionHolder) throws IOException, InterruptedException {
this.sampleRead = false;
boolean z10 = true;
while (z10 && !this.sampleRead) {
z10 = this.reader.read(extractorInput);
if (z10 && maybeSeekForCues(positionHolder, extractorInput.getPosition())) {
return 1;
}
}
if (z10) {
return 0;
}
for (int i10 = 0; i10 < this.tracks.size(); i10++) {
this.tracks.valueAt(i10).outputPendingSampleMetadata();
}
return -1;
}
@Override
public final void release() {
}
@Override
public final void seek(long j10, long j11) {
this.clusterTimecodeUs = C.TIME_UNSET;
this.blockState = 0;
this.reader.reset();
this.varintReader.reset();
resetSample();
for (int i10 = 0; i10 < this.tracks.size(); i10++) {
this.tracks.valueAt(i10).reset();
}
}
@Override
public final boolean sniff(ExtractorInput extractorInput) throws IOException, InterruptedException {
return new Sniffer().sniff(extractorInput);
}
public final void startMasterElement(int i10, long j10, long j11) throws ParserException {
if (i10 == ID_BLOCK_GROUP) {
this.sampleSeenReferenceBlock = false;
return;
}
if (i10 == ID_TRACK_ENTRY) {
this.currentTrack = new Track();
return;
}
if (i10 == ID_CUE_POINT) {
this.seenClusterPositionForCurrentCuePoint = false;
return;
}
if (i10 == ID_SEEK) {
this.seekEntryId = -1;
this.seekEntryPosition = -1L;
return;
}
if (i10 == ID_CONTENT_ENCRYPTION) {
this.currentTrack.hasContentEncryption = true;
return;
}
if (i10 == ID_MASTERING_METADATA) {
this.currentTrack.hasColorInfo = true;
return;
}
if (i10 == ID_SEGMENT) {
long j12 = this.segmentContentPosition;
if (j12 != -1 && j12 != j10) {
throw new ParserException("Multiple Segment elements not supported");
}
this.segmentContentPosition = j10;
this.segmentContentSize = j11;
return;
}
if (i10 != ID_CUES) {
if (i10 == ID_CLUSTER && !this.sentSeekMap) {
if (this.seekForCuesEnabled && this.cuesContentPosition != -1) {
this.seekForCues = true;
return;
} else {
this.extractorOutput.seekMap(new SeekMap.Unseekable(this.durationUs));
this.sentSeekMap = true;
return;
}
}
return;
}
this.cueTimesUs = new LongArray();
this.cueClusterPositions = new LongArray();
}
public final void stringElement(int i10, String str) throws ParserException {
if (i10 == 134) {
this.currentTrack.codecId = str;
return;
}
if (i10 != ID_DOC_TYPE) {
if (i10 != ID_LANGUAGE) {
return;
}
this.currentTrack.language = str;
} else {
if (DOC_TYPE_WEBM.equals(str) || DOC_TYPE_MATROSKA.equals(str)) {
return;
}
throw new ParserException("DocType " + str + " not supported");
}
}
public MatroskaExtractor(int i10) {
this(new DefaultEbmlReader(), i10);
}
public MatroskaExtractor(EbmlReader ebmlReader, int i10) {
this.segmentContentPosition = -1L;
this.timecodeScale = C.TIME_UNSET;
this.durationTimecode = C.TIME_UNSET;
this.durationUs = C.TIME_UNSET;
this.cuesContentPosition = -1L;
this.seekPositionAfterBuildingCues = -1L;
this.clusterTimecodeUs = C.TIME_UNSET;
this.reader = ebmlReader;
ebmlReader.init(new InnerEbmlReaderOutput());
this.seekForCuesEnabled = (i10 & 1) == 0;
this.varintReader = new VarintReader();
this.tracks = new SparseArray<>();
this.scratch = new ParsableByteArray(4);
this.vorbisNumPageSamples = new ParsableByteArray(ByteBuffer.allocate(4).putInt(-1).array());
this.seekEntryIdBytes = new ParsableByteArray(4);
this.nalStartCode = new ParsableByteArray(NalUnitUtil.NAL_START_CODE);
this.nalLength = new ParsableByteArray(4);
this.sampleStrippedBytes = new ParsableByteArray();
this.subtitleSample = new ParsableByteArray();
this.encryptionInitializationVector = new ParsableByteArray(8);
this.encryptionSubsampleData = new ParsableByteArray();
}
}