package j2;

import android.util.SparseArray;
import androidx.annotation.Nullable;
import androidx.media3.common.C;
import androidx.media3.common.ColorInfo;
import androidx.media3.common.DataReader;
import androidx.media3.common.DrmInitData;
import androidx.media3.common.MimeTypes;
import androidx.media3.common.ParserException;
import androidx.media3.common.util.Assertions;
import androidx.media3.common.util.Log;
import androidx.media3.common.util.LongArray;
import androidx.media3.common.util.ParsableByteArray;
import androidx.media3.common.util.Util;
import androidx.media3.extractor.a1;
import androidx.media3.extractor.b0;
import androidx.media3.extractor.i0;
import androidx.media3.extractor.o;
import androidx.media3.extractor.r0;
import androidx.media3.extractor.t0;
import androidx.media3.extractor.y;
import androidx.media3.extractor.y0;
import androidx.media3.extractor.z;
import androidx.media3.extractor.z0;
import com.google.android.gms.measurement.internal.u1;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import n2.n;
import n2.q;
import q1.v;
import xyz.stream.utils.j0;

/* JADX INFO: loaded from: classes.dex */
public final class d implements y {

    /* JADX INFO: renamed from: c0, reason: collision with root package name */
    public static final byte[] f28582c0 = {49, 10, 48, 48, 58, 48, 48, 58, 48, 48, 44, 48, 48, 48, 32, 45, 45, 62, 32, 48, 48, 58, 48, 48, 58, 48, 48, 44, 48, 48, 48, 10};

    /* JADX INFO: renamed from: d0, reason: collision with root package name */
    public static final byte[] f28583d0 = Util.getUtf8Bytes("Format: Start, End, ReadOrder, Layer, Style, Name, MarginL, MarginR, MarginV, Effect, Text");

    /* JADX INFO: renamed from: e0, reason: collision with root package name */
    public static final byte[] f28584e0 = {68, 105, 97, 108, 111, 103, 117, 101, 58, 32, 48, 58, 48, 48, 58, 48, 48, 58, 48, 48, 44, 48, 58, 48, 48, 58, 48, 48, 58, 48, 48, 44};

    /* JADX INFO: renamed from: f0, reason: collision with root package name */
    public static final byte[] f28585f0 = {87, 69, 66, 86, 84, 84, 10, 10, 48, 48, 58, 48, 48, 58, 48, 48, 46, 48, 48, 48, 32, 45, 45, 62, 32, 48, 48, 58, 48, 48, 58, 48, 48, 46, 48, 48, 48, 10};

    /* JADX INFO: renamed from: g0, reason: collision with root package name */
    public static final UUID f28586g0 = new UUID(72057594037932032L, -9223371306706625679L);

    /* JADX INFO: renamed from: h0, reason: collision with root package name */
    public static final Map f28587h0;
    public boolean A;
    public long B;
    public long C;
    public long D;
    public boolean E;
    public boolean F;
    public int G;
    public long H;
    public long I;
    public int J;
    public int K;
    public int[] L;
    public int M;
    public int N;
    public int O;
    public int P;
    public boolean Q;
    public long R;
    public int S;
    public int T;
    public int U;
    public boolean V;
    public boolean W;
    public boolean X;
    public int Y;
    public byte Z;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final b f28588a;

    /* JADX INFO: renamed from: a0, reason: collision with root package name */
    public boolean f28589a0;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final f f28590b;

    /* JADX INFO: renamed from: b0, reason: collision with root package name */
    public b0 f28591b0;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final SparseArray f28592c;

    @Nullable
    private LongArray cueClusterPositions;

    @Nullable
    private LongArray cueTimesUs;

    @Nullable
    private c currentTrack;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final boolean f28593d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final boolean f28594e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final n f28595f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final ParsableByteArray f28596g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final ParsableByteArray f28597h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final ParsableByteArray f28598i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final ParsableByteArray f28599j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final ParsableByteArray f28600k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public final ParsableByteArray f28601l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final ParsableByteArray f28602m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public final ParsableByteArray f28603n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public final ParsableByteArray f28604o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public final ParsableByteArray f28605p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public ByteBuffer f28606q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public long f28607r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public long f28608s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public long f28609t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public long f28610u;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public long f28611v;

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public boolean f28612w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public boolean f28613x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public int f28614y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public long f28615z;

    static {
        HashMap map = new HashMap();
        u1.t(0, map, "htc_video_rotA-000", 90, "htc_video_rotA-090");
        u1.t(180, map, "htc_video_rotA-180", 270, "htc_video_rotA-270");
        f28587h0 = Collections.unmodifiableMap(map);
    }

    public d(int i10, n nVar) {
        b bVar = new b();
        this.f28608s = -1L;
        this.f28609t = -9223372036854775807L;
        this.f28610u = -9223372036854775807L;
        this.f28611v = -9223372036854775807L;
        this.B = -1L;
        this.C = -1L;
        this.D = -9223372036854775807L;
        this.f28588a = bVar;
        bVar.f28551d = new j0(this);
        this.f28595f = nVar;
        this.f28593d = (i10 & 1) == 0;
        this.f28594e = (i10 & 2) == 0;
        this.f28590b = new f();
        this.f28592c = new SparseArray();
        this.f28598i = new ParsableByteArray(4);
        this.f28599j = new ParsableByteArray(ByteBuffer.allocate(4).putInt(-1).array());
        this.f28600k = new ParsableByteArray(4);
        this.f28596g = new ParsableByteArray(v.f32164a);
        this.f28597h = new ParsableByteArray(4);
        this.f28601l = new ParsableByteArray();
        this.f28602m = new ParsableByteArray();
        this.f28603n = new ParsableByteArray(8);
        this.f28604o = new ParsableByteArray();
        this.f28605p = new ParsableByteArray();
        this.L = new int[1];
    }

    private t0 buildSeekMap(@Nullable LongArray longArray, @Nullable LongArray longArray2) {
        int i10;
        if (this.f28608s == -1 || this.f28611v == -9223372036854775807L || longArray == null || longArray.size() == 0 || longArray2 == null || longArray2.size() != longArray.size()) {
            return new i0(this.f28611v);
        }
        int size = longArray.size();
        int[] iArrCopyOf = new int[size];
        long[] jArrCopyOf = new long[size];
        long[] jArrCopyOf2 = new long[size];
        long[] jArrCopyOf3 = new long[size];
        int i11 = 0;
        for (int i12 = 0; i12 < size; i12++) {
            jArrCopyOf3[i12] = longArray.get(i12);
            jArrCopyOf[i12] = longArray2.get(i12) + this.f28608s;
        }
        while (true) {
            i10 = size - 1;
            if (i11 >= i10) {
                break;
            }
            int i13 = i11 + 1;
            iArrCopyOf[i11] = (int) (jArrCopyOf[i13] - jArrCopyOf[i11]);
            jArrCopyOf2[i11] = jArrCopyOf3[i13] - jArrCopyOf3[i11];
            i11 = i13;
        }
        int i14 = i10;
        while (i14 > 0 && jArrCopyOf3[i14] > this.f28611v) {
            i14--;
        }
        iArrCopyOf[i14] = (int) ((this.f28608s + this.f28607r) - jArrCopyOf[i14]);
        jArrCopyOf2[i14] = this.f28611v - jArrCopyOf3[i14];
        if (i14 < i10) {
            Log.w("MatroskaExtractor", "Discarding trailing cue points with timestamps greater than total duration");
            int i15 = i14 + 1;
            iArrCopyOf = Arrays.copyOf(iArrCopyOf, i15);
            jArrCopyOf = Arrays.copyOf(jArrCopyOf, i15);
            jArrCopyOf2 = Arrays.copyOf(jArrCopyOf2, i15);
            jArrCopyOf3 = Arrays.copyOf(jArrCopyOf3, i15);
        }
        return new o(iArrCopyOf, jArrCopyOf, jArrCopyOf2, jArrCopyOf3);
    }

    private static int[] ensureArrayCapacity(@Nullable int[] iArr, int i10) {
        return iArr == null ? new int[i10] : iArr.length >= i10 ? iArr : new int[Math.max(iArr.length * 2, i10)];
    }

    public static byte[] g(long j10, long j11, String str) {
        Assertions.checkArgument(j10 != -9223372036854775807L);
        int i10 = (int) (j10 / 3600000000L);
        long j12 = j10 - (((long) i10) * 3600000000L);
        int i11 = (int) (j12 / 60000000);
        long j13 = j12 - (((long) i11) * 60000000);
        int i12 = (int) (j13 / 1000000);
        return Util.getUtf8Bytes(String.format(Locale.US, str, Integer.valueOf(i10), Integer.valueOf(i11), Integer.valueOf(i12), Integer.valueOf((int) ((j13 - (((long) i12) * 1000000)) / j11))));
    }

    public final void a(int i10) throws ParserException {
        if (this.cueTimesUs == null || this.cueClusterPositions == null) {
            throw ParserException.createForMalformedContainer("Element " + i10 + " must be in a Cues", null);
        }
    }

    public final void b(int i10) throws ParserException {
        if (this.currentTrack != null) {
            return;
        }
        throw ParserException.createForMalformedContainer("Element " + i10 + " must be in a TrackEntry", null);
    }

    public final void c(int i10, int i11, z zVar) throws ParserException {
        int i12;
        long j10;
        int i13;
        int i14;
        int i15;
        SparseArray sparseArray = this.f28592c;
        int i16 = 4;
        int i17 = 1;
        int i18 = 0;
        if (i10 != 161 && i10 != 163) {
            if (i10 == 165) {
                if (this.G != 2) {
                    return;
                }
                c cVar = (c) sparseArray.get(this.M);
                if (this.P != 4 || !"V_VP9".equals(cVar.f28558c)) {
                    zVar.k(i11);
                    return;
                }
                ParsableByteArray parsableByteArray = this.f28605p;
                parsableByteArray.reset(i11);
                zVar.readFully(parsableByteArray.getData(), 0, i11);
                return;
            }
            if (i10 == 16877) {
                b(i10);
                c cVar2 = this.currentTrack;
                int i19 = cVar2.f28563h;
                if (i19 != 1685485123 && i19 != 1685480259) {
                    zVar.k(i11);
                    return;
                }
                byte[] bArr = new byte[i11];
                cVar2.P = bArr;
                zVar.readFully(bArr, 0, i11);
                return;
            }
            if (i10 == 16981) {
                b(i10);
                byte[] bArr2 = new byte[i11];
                this.currentTrack.f28565j = bArr2;
                zVar.readFully(bArr2, 0, i11);
                return;
            }
            if (i10 == 18402) {
                byte[] bArr3 = new byte[i11];
                zVar.readFully(bArr3, 0, i11);
                b(i10);
                this.currentTrack.f28566k = new y0(1, 0, 0, bArr3);
                return;
            }
            if (i10 == 21419) {
                ParsableByteArray parsableByteArray2 = this.f28600k;
                Arrays.fill(parsableByteArray2.getData(), (byte) 0);
                zVar.readFully(parsableByteArray2.getData(), 4 - i11, i11);
                parsableByteArray2.setPosition(0);
                this.f28614y = (int) parsableByteArray2.readUnsignedInt();
                return;
            }
            if (i10 == 25506) {
                b(i10);
                byte[] bArr4 = new byte[i11];
                this.currentTrack.f28567l = bArr4;
                zVar.readFully(bArr4, 0, i11);
                return;
            }
            if (i10 != 30322) {
                throw ParserException.createForMalformedContainer("Unexpected id: " + i10, null);
            }
            b(i10);
            byte[] bArr5 = new byte[i11];
            this.currentTrack.f28579x = bArr5;
            zVar.readFully(bArr5, 0, i11);
            return;
        }
        int i20 = this.G;
        int i21 = 8;
        ParsableByteArray parsableByteArray3 = this.f28598i;
        if (i20 == 0) {
            f fVar = this.f28590b;
            this.M = (int) fVar.c(zVar, false, true, 8);
            this.N = fVar.f28621c;
            this.I = -9223372036854775807L;
            this.G = 1;
            parsableByteArray3.reset(0);
        }
        c cVar3 = (c) sparseArray.get(this.M);
        if (cVar3 == null) {
            zVar.k(i11 - this.N);
            this.G = 0;
            return;
        }
        Assertions.checkNotNull(cVar3.Z);
        if (this.G == 1) {
            i(zVar, 3);
            int i22 = (parsableByteArray3.getData()[2] & 6) >> 1;
            if (i22 == 0) {
                this.K = 1;
                int[] iArrEnsureArrayCapacity = ensureArrayCapacity(this.L, 1);
                this.L = iArrEnsureArrayCapacity;
                iArrEnsureArrayCapacity[0] = (i11 - this.N) - 3;
            } else {
                i(zVar, 4);
                int i23 = (parsableByteArray3.getData()[3] & 255) + 1;
                this.K = i23;
                int[] iArrEnsureArrayCapacity2 = ensureArrayCapacity(this.L, i23);
                this.L = iArrEnsureArrayCapacity2;
                if (i22 == 2) {
                    int i24 = (i11 - this.N) - 4;
                    int i25 = this.K;
                    Arrays.fill(iArrEnsureArrayCapacity2, 0, i25, i24 / i25);
                } else {
                    if (i22 != 1) {
                        if (i22 != 3) {
                            throw ParserException.createForMalformedContainer("Unexpected lacing value: " + i22, null);
                        }
                        int i26 = 0;
                        int i27 = 0;
                        while (true) {
                            int i28 = this.K - i17;
                            if (i26 >= i28) {
                                this.L[i28] = ((i11 - this.N) - i16) - i27;
                                break;
                            }
                            this.L[i26] = i18;
                            int i29 = i16 + 1;
                            i(zVar, i29);
                            if (parsableByteArray3.getData()[i16] == 0) {
                                throw ParserException.createForMalformedContainer("No valid varint length mask found", null);
                            }
                            int i30 = i18;
                            while (true) {
                                if (i30 >= i21) {
                                    j10 = 0;
                                    i16 = i29;
                                    break;
                                }
                                int i31 = i17 << (7 - i30);
                                if ((parsableByteArray3.getData()[i16] & i31) != 0) {
                                    int i32 = i29 + i30;
                                    i(zVar, i32);
                                    j10 = parsableByteArray3.getData()[i16] & 255 & (~i31);
                                    while (i29 < i32) {
                                        j10 = (j10 << 8) | ((long) (parsableByteArray3.getData()[i29] & 255));
                                        i29++;
                                        i32 = i32;
                                    }
                                    int i33 = i32;
                                    if (i26 > 0) {
                                        j10 -= (1 << ((i30 * 7) + 6)) - 1;
                                    }
                                    i16 = i33;
                                } else {
                                    i30++;
                                    i17 = 1;
                                    i21 = 8;
                                }
                            }
                            if (j10 < -2147483648L || j10 > 2147483647L) {
                                break;
                            }
                            int i34 = (int) j10;
                            int[] iArr = this.L;
                            if (i26 != 0) {
                                i34 += iArr[i26 - 1];
                            }
                            iArr[i26] = i34;
                            i27 += i34;
                            i26++;
                            i17 = 1;
                            i18 = 0;
                            i21 = 8;
                        }
                        throw ParserException.createForMalformedContainer("EBML lacing sample size out of range.", null);
                    }
                    int i35 = 0;
                    int i36 = 0;
                    while (true) {
                        i13 = this.K - 1;
                        if (i35 >= i13) {
                            break;
                        }
                        this.L[i35] = 0;
                        while (true) {
                            i14 = i16 + 1;
                            i(zVar, i14);
                            int i37 = parsableByteArray3.getData()[i16] & 255;
                            int[] iArr2 = this.L;
                            i15 = iArr2[i35] + i37;
                            iArr2[i35] = i15;
                            if (i37 != 255) {
                                break;
                            } else {
                                i16 = i14;
                            }
                        }
                        i36 += i15;
                        i35++;
                        i16 = i14;
                    }
                    this.L[i13] = ((i11 - this.N) - i16) - i36;
                }
            }
            this.H = k((parsableByteArray3.getData()[0] << 8) | (parsableByteArray3.getData()[1] & 255)) + this.D;
            this.O = (cVar3.f28560e == 2 || (i10 == 163 && (parsableByteArray3.getData()[2] & 128) == 128)) ? 1 : 0;
            this.G = 2;
            this.J = 0;
            i12 = 163;
        } else {
            i12 = 163;
        }
        if (i10 == i12) {
            while (true) {
                int i38 = this.J;
                if (i38 >= this.K) {
                    this.G = 0;
                    return;
                } else {
                    d(cVar3, ((long) ((this.J * cVar3.f28561f) / 1000)) + this.H, this.O, n(zVar, cVar3, this.L[i38], false), 0);
                    this.J++;
                }
            }
        } else {
            while (true) {
                int i39 = this.J;
                if (i39 >= this.K) {
                    return;
                }
                int[] iArr3 = this.L;
                iArr3[i39] = n(zVar, cVar3, iArr3[i39], true);
                this.J++;
            }
        }
    }

    /* JADX WARN: Failed to restore switch over string. Please report as a decompilation issue */
    /* JADX WARN: Removed duplicated region for block: B:59:0x00ff  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void d(c cVar, long j10, int i10, int i11, int i12) {
        byte b10;
        byte[] bArrG;
        int i13;
        int iLimit;
        a1 a1Var = cVar.V;
        if (a1Var != null) {
            a1Var.sampleMetadata(cVar.Z, j10, i10, i11, i12, cVar.f28566k);
        } else if ("S_TEXT/UTF8".equals(cVar.f28558c) || "S_TEXT/ASS".equals(cVar.f28558c) || "S_TEXT/SSA".equals(cVar.f28558c) || "S_TEXT/WEBVTT".equals(cVar.f28558c)) {
            if (this.K > 1) {
                Log.w("MatroskaExtractor", "Skipping subtitle sample in laced block.");
            } else {
                long j11 = this.I;
                if (j11 == -9223372036854775807L) {
                    Log.w("MatroskaExtractor", "Skipping subtitle sample with no duration.");
                } else {
                    String str = cVar.f28558c;
                    ParsableByteArray parsableByteArray = this.f28602m;
                    byte[] data = parsableByteArray.getData();
                    str.getClass();
                    switch (str.hashCode()) {
                        case 738597099:
                            b10 = !str.equals("S_TEXT/ASS") ? (byte) -1 : (byte) 0;
                            break;
                        case 738614379:
                            b10 = !str.equals("S_TEXT/SSA") ? (byte) -1 : (byte) 1;
                            break;
                        case 1045209816:
                            b10 = !str.equals("S_TEXT/WEBVTT") ? (byte) -1 : (byte) 2;
                            break;
                        case 1422270023:
                            b10 = !str.equals("S_TEXT/UTF8") ? (byte) -1 : (byte) 3;
                            break;
                        default:
                            b10 = -1;
                            break;
                    }
                    if (b10 == 0 || b10 == 1) {
                        bArrG = g(j11, 10000L, "%01d:%02d:%02d:%02d");
                        i13 = 21;
                    } else if (b10 == 2) {
                        bArrG = g(j11, 1000L, "%02d:%02d:%02d.%03d");
                        i13 = 25;
                    } else {
                        if (b10 != 3) {
                            throw new IllegalArgumentException();
                        }
                        bArrG = g(j11, 1000L, "%02d:%02d:%02d,%03d");
                        i13 = 19;
                    }
                    System.arraycopy(bArrG, 0, data, i13, bArrG.length);
                    int position = parsableByteArray.getPosition();
                    while (true) {
                        if (position < parsableByteArray.limit()) {
                            if (parsableByteArray.getData()[position] == 0) {
                                parsableByteArray.setLimit(position);
                            } else {
                                position++;
                            }
                        }
                    }
                    cVar.Z.sampleData(parsableByteArray, parsableByteArray.limit());
                    iLimit = parsableByteArray.limit() + i11;
                    if ((i10 & 268435456) != 0) {
                        int i14 = this.K;
                        ParsableByteArray parsableByteArray2 = this.f28605p;
                        if (i14 > 1) {
                            parsableByteArray2.reset(0);
                        } else {
                            int iLimit2 = parsableByteArray2.limit();
                            cVar.Z.sampleData(parsableByteArray2, iLimit2, 2);
                            iLimit += iLimit2;
                        }
                    }
                    cVar.Z.sampleMetadata(j10, i10, iLimit, i12, cVar.f28566k);
                }
            }
            iLimit = i11;
            if ((i10 & 268435456) != 0) {
            }
            cVar.Z.sampleMetadata(j10, i10, iLimit, i12, cVar.f28566k);
        } else {
            iLimit = i11;
            if ((i10 & 268435456) != 0) {
            }
            cVar.Z.sampleMetadata(j10, i10, iLimit, i12, cVar.f28566k);
        }
        this.F = true;
    }

    public final void e(int i10) throws ParserException {
        Assertions.checkStateNotNull(this.f28591b0);
        SparseArray sparseArray = this.f28592c;
        if (i10 == 160) {
            if (this.G != 2) {
                return;
            }
            c cVar = (c) sparseArray.get(this.M);
            Assertions.checkNotNull(cVar.Z);
            if (this.R > 0 && "A_OPUS".equals(cVar.f28558c)) {
                this.f28605p.reset(ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putLong(this.R).array());
            }
            int i11 = 0;
            for (int i12 = 0; i12 < this.K; i12++) {
                i11 += this.L[i12];
            }
            for (int i13 = 0; i13 < this.K; i13++) {
                long j10 = this.H + ((long) ((cVar.f28561f * i13) / 1000));
                int i14 = this.O;
                if (i13 == 0 && !this.Q) {
                    i14 |= 1;
                }
                int i15 = this.L[i13];
                i11 -= i15;
                d(cVar, j10, i14, i15, i11);
            }
            this.G = 0;
            return;
        }
        if (i10 != 174) {
            if (i10 == 19899) {
                int i16 = this.f28614y;
                if (i16 != -1) {
                    long j11 = this.f28615z;
                    if (j11 != -1) {
                        if (i16 == 475249515) {
                            this.B = j11;
                            return;
                        }
                        return;
                    }
                }
                throw ParserException.createForMalformedContainer("Mandatory element SeekID or SeekPosition not found", null);
            }
            if (i10 == 25152) {
                b(i10);
                c cVar2 = this.currentTrack;
                if (cVar2.f28564i) {
                    if (cVar2.f28566k == null) {
                        throw ParserException.createForMalformedContainer("Encrypted Track found but ContentEncKeyID was not found", null);
                    }
                    cVar2.f28568m = new DrmInitData(new DrmInitData.SchemeData(C.UUID_NIL, MimeTypes.VIDEO_WEBM, this.currentTrack.f28566k.f3500b));
                    return;
                }
                return;
            }
            if (i10 == 28032) {
                b(i10);
                c cVar3 = this.currentTrack;
                if (cVar3.f28564i && cVar3.f28565j != null) {
                    throw ParserException.createForMalformedContainer("Combining encryption and compression is not supported", null);
                }
                return;
            }
            if (i10 == 357149030) {
                if (this.f28609t == -9223372036854775807L) {
                    this.f28609t = 1000000L;
                }
                long j12 = this.f28610u;
                if (j12 != -9223372036854775807L) {
                    this.f28611v = k(j12);
                    return;
                }
                return;
            }
            if (i10 == 374648427) {
                if (sparseArray.size() == 0) {
                    throw ParserException.createForMalformedContainer("No valid tracks were found", null);
                }
                this.f28591b0.endTracks();
                return;
            } else {
                if (i10 != 475249515) {
                    return;
                }
                if (!this.f28613x) {
                    this.f28591b0.seekMap(buildSeekMap(this.cueTimesUs, this.cueClusterPositions));
                    this.f28613x = true;
                }
                this.cueTimesUs = null;
                this.cueClusterPositions = null;
                return;
            }
        }
        c cVar4 = (c) Assertions.checkStateNotNull(this.currentTrack);
        String str = cVar4.f28558c;
        if (str == null) {
            throw ParserException.createForMalformedContainer("CodecId is missing in TrackEntry element", null);
        }
        switch (str) {
            case "V_MPEG4/ISO/AP":
            case "V_MPEG4/ISO/SP":
            case "A_MS/ACM":
            case "A_TRUEHD":
            case "A_VORBIS":
            case "A_MPEG/L2":
            case "A_MPEG/L3":
            case "V_MS/VFW/FOURCC":
            case "S_DVBSUB":
            case "V_MPEG4/ISO/ASP":
            case "V_MPEG4/ISO/AVC":
            case "S_VOBSUB":
            case "A_DTS/LOSSLESS":
            case "A_AAC":
            case "A_AC3":
            case "A_DTS":
            case "V_AV1":
            case "V_VP8":
            case "V_VP9":
            case "S_HDMV/PGS":
            case "V_THEORA":
            case "A_DTS/EXPRESS":
            case "A_PCM/FLOAT/IEEE":
            case "A_PCM/INT/BIG":
            case "A_PCM/INT/LIT":
            case "S_TEXT/ASS":
            case "S_TEXT/SSA":
            case "V_MPEGH/ISO/HEVC":
            case "S_TEXT/WEBVTT":
            case "S_TEXT/UTF8":
            case "V_MPEG2":
            case "A_EAC3":
            case "A_FLAC":
            case "A_OPUS":
                cVar4.b(this.f28591b0, cVar4.f28559d);
                sparseArray.put(cVar4.f28559d, cVar4);
                break;
        }
        this.currentTrack = null;
    }

    public final void f(double d10, int i10) throws ParserException {
        if (i10 == 181) {
            b(i10);
            this.currentTrack.S = (int) d10;
        }
        if (i10 == 17545) {
            this.f28610u = (long) d10;
            return;
        }
        switch (i10) {
            case 21969:
                b(i10);
                this.currentTrack.F = (float) d10;
                break;
            case 21970:
                b(i10);
                this.currentTrack.G = (float) d10;
                break;
            case 21971:
                b(i10);
                this.currentTrack.H = (float) d10;
                break;
            case 21972:
                b(i10);
                this.currentTrack.I = (float) d10;
                break;
            case 21973:
                b(i10);
                this.currentTrack.J = (float) d10;
                break;
            case 21974:
                b(i10);
                this.currentTrack.K = (float) d10;
                break;
            case 21975:
                b(i10);
                this.currentTrack.L = (float) d10;
                break;
            case 21976:
                b(i10);
                this.currentTrack.M = (float) d10;
                break;
            case 21977:
                b(i10);
                this.currentTrack.N = (float) d10;
                break;
            case 21978:
                b(i10);
                this.currentTrack.O = (float) d10;
                break;
            default:
                switch (i10) {
                    case 30323:
                        b(i10);
                        this.currentTrack.f28576u = (float) d10;
                        break;
                    case 30324:
                        b(i10);
                        this.currentTrack.f28577v = (float) d10;
                        break;
                    case 30325:
                        b(i10);
                        this.currentTrack.f28578w = (float) d10;
                        break;
                }
                break;
        }
    }

    public final void h(int i10, long j10) throws ParserException {
        if (i10 == 20529) {
            if (j10 == 0) {
                return;
            }
            throw ParserException.createForMalformedContainer("ContentEncodingOrder " + j10 + " not supported", null);
        }
        if (i10 == 20530) {
            if (j10 == 1) {
                return;
            }
            throw ParserException.createForMalformedContainer("ContentEncodingScope " + j10 + " not supported", null);
        }
        switch (i10) {
            case 131:
                b(i10);
                this.currentTrack.f28560e = (int) j10;
                return;
            case 136:
                b(i10);
                this.currentTrack.X = j10 == 1;
                return;
            case 155:
                this.I = k(j10);
                return;
            case 159:
                b(i10);
                this.currentTrack.Q = (int) j10;
                return;
            case 176:
                b(i10);
                this.currentTrack.f28569n = (int) j10;
                return;
            case 179:
                a(i10);
                this.cueTimesUs.add(k(j10));
                return;
            case 186:
                b(i10);
                this.currentTrack.f28570o = (int) j10;
                return;
            case 215:
                b(i10);
                this.currentTrack.f28559d = (int) j10;
                return;
            case 231:
                this.D = k(j10);
                return;
            case 238:
                this.P = (int) j10;
                return;
            case 241:
                if (this.E) {
                    return;
                }
                a(i10);
                this.cueClusterPositions.add(j10);
                this.E = true;
                return;
            case 251:
                this.Q = true;
                return;
            case 16871:
                b(i10);
                this.currentTrack.f28563h = (int) j10;
                return;
            case 16980:
                if (j10 == 3) {
                    return;
                }
                throw ParserException.createForMalformedContainer("ContentCompAlgo " + j10 + " not supported", null);
            case 17029:
                if (j10 < 1 || j10 > 2) {
                    throw ParserException.createForMalformedContainer("DocTypeReadVersion " + j10 + " not supported", null);
                }
                return;
            case 17143:
                if (j10 == 1) {
                    return;
                }
                throw ParserException.createForMalformedContainer("EBMLReadVersion " + j10 + " not supported", null);
            case 18401:
                if (j10 == 5) {
                    return;
                }
                throw ParserException.createForMalformedContainer("ContentEncAlgo " + j10 + " not supported", null);
            case 18408:
                if (j10 == 1) {
                    return;
                }
                throw ParserException.createForMalformedContainer("AESSettingsCipherMode " + j10 + " not supported", null);
            case 21420:
                this.f28615z = j10 + this.f28608s;
                return;
            case 21432:
                int i11 = (int) j10;
                b(i10);
                if (i11 == 0) {
                    this.currentTrack.f28580y = 0;
                    return;
                }
                if (i11 == 1) {
                    this.currentTrack.f28580y = 2;
                    return;
                } else if (i11 == 3) {
                    this.currentTrack.f28580y = 1;
                    return;
                } else {
                    if (i11 != 15) {
                        return;
                    }
                    this.currentTrack.f28580y = 3;
                    return;
                }
            case 21680:
                b(i10);
                this.currentTrack.f28572q = (int) j10;
                return;
            case 21682:
                b(i10);
                this.currentTrack.f28574s = (int) j10;
                return;
            case 21690:
                b(i10);
                this.currentTrack.f28573r = (int) j10;
                return;
            case 21930:
                b(i10);
                this.currentTrack.W = j10 == 1;
                return;
            case 21938:
                b(i10);
                c cVar = this.currentTrack;
                cVar.f28581z = true;
                cVar.f28571p = (int) j10;
                return;
            case 21998:
                b(i10);
                this.currentTrack.f28562g = (int) j10;
                return;
            case 22186:
                b(i10);
                this.currentTrack.T = j10;
                return;
            case 22203:
                b(i10);
                this.currentTrack.U = j10;
                return;
            case 25188:
                b(i10);
                this.currentTrack.R = (int) j10;
                return;
            case 30114:
                this.R = j10;
                return;
            case 30321:
                b(i10);
                int i12 = (int) j10;
                if (i12 == 0) {
                    this.currentTrack.f28575t = 0;
                    return;
                }
                if (i12 == 1) {
                    this.currentTrack.f28575t = 1;
                    return;
                } else if (i12 == 2) {
                    this.currentTrack.f28575t = 2;
                    return;
                } else {
                    if (i12 != 3) {
                        return;
                    }
                    this.currentTrack.f28575t = 3;
                    return;
                }
            case 2352003:
                b(i10);
                this.currentTrack.f28561f = (int) j10;
                return;
            case 2807729:
                this.f28609t = j10;
                return;
            default:
                switch (i10) {
                    case 21945:
                        b(i10);
                        int i13 = (int) j10;
                        if (i13 == 1) {
                            this.currentTrack.C = 2;
                            return;
                        } else {
                            if (i13 != 2) {
                                return;
                            }
                            this.currentTrack.C = 1;
                            return;
                        }
                    case 21946:
                        b(i10);
                        int iIsoTransferCharacteristicsToColorTransfer = ColorInfo.isoTransferCharacteristicsToColorTransfer((int) j10);
                        if (iIsoTransferCharacteristicsToColorTransfer != -1) {
                            this.currentTrack.B = iIsoTransferCharacteristicsToColorTransfer;
                            return;
                        }
                        return;
                    case 21947:
                        b(i10);
                        this.currentTrack.f28581z = true;
                        int iIsoColorPrimariesToColorSpace = ColorInfo.isoColorPrimariesToColorSpace((int) j10);
                        if (iIsoColorPrimariesToColorSpace != -1) {
                            this.currentTrack.A = iIsoColorPrimariesToColorSpace;
                            return;
                        }
                        return;
                    case 21948:
                        b(i10);
                        this.currentTrack.D = (int) j10;
                        return;
                    case 21949:
                        b(i10);
                        this.currentTrack.E = (int) j10;
                        return;
                    default:
                        return;
                }
        }
    }

    public final void i(z zVar, int i10) {
        ParsableByteArray parsableByteArray = this.f28598i;
        if (parsableByteArray.limit() >= i10) {
            return;
        }
        if (parsableByteArray.capacity() < i10) {
            parsableByteArray.ensureCapacity(Math.max(parsableByteArray.capacity() * 2, i10));
        }
        zVar.readFully(parsableByteArray.getData(), parsableByteArray.limit(), i10 - parsableByteArray.limit());
        parsableByteArray.setLimit(i10);
    }

    @Override // androidx.media3.extractor.y
    public final void init(b0 b0Var) {
        if (this.f28594e) {
            b0Var = new q(b0Var, this.f28595f);
        }
        this.f28591b0 = b0Var;
    }

    public final void j() {
        this.S = 0;
        this.T = 0;
        this.U = 0;
        this.V = false;
        this.W = false;
        this.X = false;
        this.Y = 0;
        this.Z = (byte) 0;
        this.f28589a0 = false;
        this.f28601l.reset(0);
    }

    public final long k(long j10) throws ParserException {
        long j11 = this.f28609t;
        if (j11 != -9223372036854775807L) {
            return Util.scaleLargeTimestamp(j10, j11, 1000L);
        }
        throw ParserException.createForMalformedContainer("Can't scale timecode prior to timecodeScale being set.", null);
    }

    public final void l(int i10, long j10, long j11) throws ParserException {
        Assertions.checkStateNotNull(this.f28591b0);
        if (i10 == 160) {
            this.Q = false;
            this.R = 0L;
            return;
        }
        if (i10 != 174) {
            if (i10 == 187) {
                this.E = false;
                return;
            }
            if (i10 == 19899) {
                this.f28614y = -1;
                this.f28615z = -1L;
                return;
            }
            if (i10 == 20533) {
                b(i10);
                this.currentTrack.f28564i = true;
                return;
            }
            if (i10 == 21968) {
                b(i10);
                this.currentTrack.f28581z = true;
                return;
            }
            if (i10 == 408125543) {
                long j12 = this.f28608s;
                if (j12 != -1 && j12 != j10) {
                    throw ParserException.createForMalformedContainer("Multiple Segment elements not supported", null);
                }
                this.f28608s = j10;
                this.f28607r = j11;
                return;
            }
            if (i10 == 475249515) {
                this.cueTimesUs = new LongArray();
                this.cueClusterPositions = new LongArray();
                return;
            } else {
                if (i10 == 524531317 && !this.f28613x) {
                    if (this.f28593d && this.B != -1) {
                        this.A = true;
                        return;
                    } else {
                        this.f28591b0.seekMap(new i0(this.f28611v));
                        this.f28613x = true;
                        return;
                    }
                }
                return;
            }
        }
        c cVar = new c();
        cVar.f28569n = -1;
        cVar.f28570o = -1;
        cVar.f28571p = -1;
        cVar.f28572q = -1;
        cVar.f28573r = -1;
        cVar.f28574s = 0;
        cVar.f28575t = -1;
        cVar.f28576u = 0.0f;
        cVar.f28577v = 0.0f;
        cVar.f28578w = 0.0f;
        cVar.f28579x = null;
        cVar.f28580y = -1;
        cVar.f28581z = false;
        cVar.A = -1;
        cVar.B = -1;
        cVar.C = -1;
        cVar.D = 1000;
        cVar.E = 200;
        cVar.F = -1.0f;
        cVar.G = -1.0f;
        cVar.H = -1.0f;
        cVar.I = -1.0f;
        cVar.J = -1.0f;
        cVar.K = -1.0f;
        cVar.L = -1.0f;
        cVar.M = -1.0f;
        cVar.N = -1.0f;
        cVar.O = -1.0f;
        cVar.Q = 1;
        cVar.R = -1;
        cVar.S = 8000;
        cVar.T = 0L;
        cVar.U = 0L;
        cVar.X = true;
        cVar.Y = "eng";
        this.currentTrack = cVar;
        cVar.f28555a = this.f28612w;
    }

    public final void m(int i10, String str) throws ParserException {
        if (i10 == 134) {
            b(i10);
            this.currentTrack.f28558c = str;
            return;
        }
        if (i10 == 17026) {
            if ("webm".equals(str) || "matroska".equals(str)) {
                this.f28612w = str.equals("webm");
                return;
            }
            throw ParserException.createForMalformedContainer("DocType " + str + " not supported", null);
        }
        if (i10 == 21358) {
            b(i10);
            this.currentTrack.f28557b = str;
        } else {
            if (i10 != 2274716) {
                return;
            }
            b(i10);
            this.currentTrack.Y = str;
        }
    }

    public final int n(z zVar, c cVar, int i10, boolean z10) throws ParserException {
        int iSampleData;
        int iSampleData2;
        int i11;
        if ("S_TEXT/UTF8".equals(cVar.f28558c)) {
            o(zVar, f28582c0, i10);
            int i12 = this.T;
            j();
            return i12;
        }
        if ("S_TEXT/ASS".equals(cVar.f28558c) || "S_TEXT/SSA".equals(cVar.f28558c)) {
            o(zVar, f28584e0, i10);
            int i13 = this.T;
            j();
            return i13;
        }
        if ("S_TEXT/WEBVTT".equals(cVar.f28558c)) {
            o(zVar, f28585f0, i10);
            int i14 = this.T;
            j();
            return i14;
        }
        z0 z0Var = cVar.Z;
        boolean z11 = this.V;
        ParsableByteArray parsableByteArray = this.f28601l;
        if (!z11) {
            boolean z12 = cVar.f28564i;
            ParsableByteArray parsableByteArray2 = this.f28598i;
            if (z12) {
                this.O &= -1073741825;
                if (!this.W) {
                    zVar.readFully(parsableByteArray2.getData(), 0, 1);
                    this.S++;
                    if ((parsableByteArray2.getData()[0] & 128) == 128) {
                        throw ParserException.createForMalformedContainer("Extension bit is set in signal byte", null);
                    }
                    this.Z = parsableByteArray2.getData()[0];
                    this.W = true;
                }
                byte b10 = this.Z;
                if ((b10 & 1) == 1) {
                    boolean z13 = (b10 & 2) == 2;
                    this.O |= 1073741824;
                    if (!this.f28589a0) {
                        ParsableByteArray parsableByteArray3 = this.f28603n;
                        zVar.readFully(parsableByteArray3.getData(), 0, 8);
                        this.S += 8;
                        this.f28589a0 = true;
                        parsableByteArray2.getData()[0] = (byte) ((z13 ? 128 : 0) | 8);
                        parsableByteArray2.setPosition(0);
                        z0Var.sampleData(parsableByteArray2, 1, 1);
                        this.T++;
                        parsableByteArray3.setPosition(0);
                        z0Var.sampleData(parsableByteArray3, 8, 1);
                        this.T += 8;
                    }
                    if (z13) {
                        if (!this.X) {
                            zVar.readFully(parsableByteArray2.getData(), 0, 1);
                            this.S++;
                            parsableByteArray2.setPosition(0);
                            this.Y = parsableByteArray2.readUnsignedByte();
                            this.X = true;
                        }
                        int i15 = this.Y * 4;
                        parsableByteArray2.reset(i15);
                        zVar.readFully(parsableByteArray2.getData(), 0, i15);
                        this.S += i15;
                        short s10 = (short) ((this.Y / 2) + 1);
                        int i16 = (s10 * 6) + 2;
                        ByteBuffer byteBuffer = this.f28606q;
                        if (byteBuffer == null || byteBuffer.capacity() < i16) {
                            this.f28606q = ByteBuffer.allocate(i16);
                        }
                        this.f28606q.position(0);
                        this.f28606q.putShort(s10);
                        int i17 = 0;
                        int i18 = 0;
                        while (true) {
                            i11 = this.Y;
                            if (i17 >= i11) {
                                break;
                            }
                            int unsignedIntToInt = parsableByteArray2.readUnsignedIntToInt();
                            if (i17 % 2 == 0) {
                                this.f28606q.putShort((short) (unsignedIntToInt - i18));
                            } else {
                                this.f28606q.putInt(unsignedIntToInt - i18);
                            }
                            i17++;
                            i18 = unsignedIntToInt;
                        }
                        int i19 = (i10 - this.S) - i18;
                        if (i11 % 2 == 1) {
                            this.f28606q.putInt(i19);
                        } else {
                            this.f28606q.putShort((short) i19);
                            this.f28606q.putInt(0);
                        }
                        byte[] bArrArray = this.f28606q.array();
                        ParsableByteArray parsableByteArray4 = this.f28604o;
                        parsableByteArray4.reset(bArrArray, i16);
                        z0Var.sampleData(parsableByteArray4, i16, 1);
                        this.T += i16;
                    }
                }
            } else {
                byte[] bArr = cVar.f28565j;
                if (bArr != null) {
                    parsableByteArray.reset(bArr, bArr.length);
                }
            }
            if (!"A_OPUS".equals(cVar.f28558c) ? cVar.f28562g > 0 : z10) {
                this.O |= 268435456;
                this.f28605p.reset(0);
                int iLimit = (parsableByteArray.limit() + i10) - this.S;
                parsableByteArray2.reset(4);
                parsableByteArray2.getData()[0] = (byte) ((iLimit >> 24) & 255);
                parsableByteArray2.getData()[1] = (byte) ((iLimit >> 16) & 255);
                parsableByteArray2.getData()[2] = (byte) ((iLimit >> 8) & 255);
                parsableByteArray2.getData()[3] = (byte) (iLimit & 255);
                z0Var.sampleData(parsableByteArray2, 4, 2);
                this.T += 4;
            }
            this.V = true;
        }
        int iLimit2 = parsableByteArray.limit() + i10;
        if (!"V_MPEG4/ISO/AVC".equals(cVar.f28558c) && !"V_MPEGH/ISO/HEVC".equals(cVar.f28558c)) {
            if (cVar.V != null) {
                Assertions.checkState(parsableByteArray.limit() == 0);
                cVar.V.a(zVar);
            }
            while (true) {
                int i20 = this.S;
                if (i20 >= iLimit2) {
                    break;
                }
                int i21 = iLimit2 - i20;
                int iBytesLeft = parsableByteArray.bytesLeft();
                if (iBytesLeft > 0) {
                    iSampleData2 = Math.min(i21, iBytesLeft);
                    z0Var.sampleData(parsableByteArray, iSampleData2);
                } else {
                    iSampleData2 = z0Var.sampleData((DataReader) zVar, i21, false);
                }
                this.S += iSampleData2;
                this.T += iSampleData2;
            }
        } else {
            ParsableByteArray parsableByteArray5 = this.f28597h;
            byte[] data = parsableByteArray5.getData();
            data[0] = 0;
            data[1] = 0;
            data[2] = 0;
            int i22 = cVar.f28556a0;
            int i23 = 4 - i22;
            while (this.S < iLimit2) {
                int i24 = this.U;
                if (i24 == 0) {
                    int iMin = Math.min(i22, parsableByteArray.bytesLeft());
                    zVar.readFully(data, i23 + iMin, i22 - iMin);
                    if (iMin > 0) {
                        parsableByteArray.readBytes(data, i23, iMin);
                    }
                    this.S += i22;
                    parsableByteArray5.setPosition(0);
                    this.U = parsableByteArray5.readUnsignedIntToInt();
                    ParsableByteArray parsableByteArray6 = this.f28596g;
                    parsableByteArray6.setPosition(0);
                    z0Var.sampleData(parsableByteArray6, 4);
                    this.T += 4;
                } else {
                    int iBytesLeft2 = parsableByteArray.bytesLeft();
                    if (iBytesLeft2 > 0) {
                        iSampleData = Math.min(i24, iBytesLeft2);
                        z0Var.sampleData(parsableByteArray, iSampleData);
                    } else {
                        iSampleData = z0Var.sampleData((DataReader) zVar, i24, false);
                    }
                    this.S += iSampleData;
                    this.T += iSampleData;
                    this.U -= iSampleData;
                }
            }
        }
        if ("A_VORBIS".equals(cVar.f28558c)) {
            ParsableByteArray parsableByteArray7 = this.f28599j;
            parsableByteArray7.setPosition(0);
            z0Var.sampleData(parsableByteArray7, 4);
            this.T += 4;
        }
        int i25 = this.T;
        j();
        return i25;
    }

    public final void o(z zVar, byte[] bArr, int i10) {
        int length = bArr.length + i10;
        ParsableByteArray parsableByteArray = this.f28602m;
        if (parsableByteArray.capacity() < length) {
            parsableByteArray.reset(Arrays.copyOf(bArr, length + i10));
        } else {
            System.arraycopy(bArr, 0, parsableByteArray.getData(), 0, bArr.length);
        }
        zVar.readFully(parsableByteArray.getData(), bArr.length, i10);
        parsableByteArray.setPosition(0);
        parsableByteArray.setLimit(length);
    }

    /* JADX WARN: Code restructure failed: missing block: B:121:0x000b, code lost:
    
        continue;
     */
    /* JADX WARN: Code restructure failed: missing block: B:13:0x0040, code lost:
    
        r5 = true;
     */
    /* JADX WARN: Code restructure failed: missing block: B:89:0x01da, code lost:
    
        if (r5 == false) goto L120;
     */
    /* JADX WARN: Code restructure failed: missing block: B:90:0x01dc, code lost:
    
        r6 = r20.getPosition();
     */
    /* JADX WARN: Code restructure failed: missing block: B:91:0x01e2, code lost:
    
        if (r19.A == false) goto L93;
     */
    /* JADX WARN: Code restructure failed: missing block: B:92:0x01e4, code lost:
    
        r19.C = r6;
        r21.f3463a = r19.B;
        r19.A = false;
     */
    /* JADX WARN: Code restructure failed: missing block: B:94:0x01ef, code lost:
    
        if (r19.f28613x == false) goto L121;
     */
    /* JADX WARN: Code restructure failed: missing block: B:95:0x01f1, code lost:
    
        r6 = r19.C;
     */
    /* JADX WARN: Code restructure failed: missing block: B:96:0x01f7, code lost:
    
        if (r6 == (-1)) goto L122;
     */
    /* JADX WARN: Code restructure failed: missing block: B:97:0x01f9, code lost:
    
        r21.f3463a = r6;
        r19.C = -1;
     */
    /* JADX WARN: Code restructure failed: missing block: B:98:0x01fd, code lost:
    
        return 1;
     */
    @Override // androidx.media3.extractor.y
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int read(z zVar, r0 r0Var) throws ParserException {
        int i10;
        String str;
        int iB;
        int iA;
        int i11 = 0;
        this.F = false;
        boolean z10 = true;
        while (z10 && !this.F) {
            b bVar = this.f28588a;
            Assertions.checkStateNotNull(bVar.f28551d);
            while (true) {
                ArrayDeque arrayDeque = bVar.f28549b;
                a aVar = (a) arrayDeque.peek();
                if (aVar == null || zVar.getPosition() < aVar.f28547b) {
                    int i12 = bVar.f28552e;
                    f fVar = bVar.f28550c;
                    if (i12 == 0) {
                        long jC = fVar.c(zVar, true, false, 4);
                        if (jC == -2) {
                            zVar.j();
                            while (true) {
                                byte[] bArr = bVar.f28548a;
                                zVar.a(0, 4, bArr);
                                iB = f.b(bArr[0]);
                                if (iB != -1 && iB <= 4) {
                                    iA = (int) f.a(bArr, iB, false);
                                    ((d) bVar.f28551d.f36154b).getClass();
                                    if (iA == 357149030 || iA == 524531317 || iA == 475249515 || iA == 374648427) {
                                    }
                                }
                                zVar.k(1);
                            }
                            zVar.k(iB);
                            jC = iA;
                        }
                        if (jC == -1) {
                            z10 = false;
                        } else {
                            bVar.f28553f = (int) jC;
                            bVar.f28552e = 1;
                        }
                    }
                    if (bVar.f28552e == 1) {
                        bVar.f28554g = fVar.c(zVar, false, true, 8);
                        bVar.f28552e = 2;
                    }
                    j0 j0Var = bVar.f28551d;
                    int i13 = bVar.f28553f;
                    ((d) j0Var.f36154b).getClass();
                    switch (i13) {
                        case 131:
                        case 136:
                        case 155:
                        case 159:
                        case 176:
                        case 179:
                        case 186:
                        case 215:
                        case 231:
                        case 238:
                        case 241:
                        case 251:
                        case 16871:
                        case 16980:
                        case 17029:
                        case 17143:
                        case 18401:
                        case 18408:
                        case 20529:
                        case 20530:
                        case 21420:
                        case 21432:
                        case 21680:
                        case 21682:
                        case 21690:
                        case 21930:
                        case 21938:
                        case 21945:
                        case 21946:
                        case 21947:
                        case 21948:
                        case 21949:
                        case 21998:
                        case 22186:
                        case 22203:
                        case 25188:
                        case 30114:
                        case 30321:
                        case 2352003:
                        case 2807729:
                            i10 = 2;
                            break;
                        case 134:
                        case 17026:
                        case 21358:
                        case 2274716:
                            i10 = 3;
                            break;
                        case 160:
                        case 166:
                        case 174:
                        case 183:
                        case 187:
                        case 224:
                        case 225:
                        case 16868:
                        case 18407:
                        case 19899:
                        case 20532:
                        case 20533:
                        case 21936:
                        case 21968:
                        case 25152:
                        case 28032:
                        case 30113:
                        case 30320:
                        case 290298740:
                        case 357149030:
                        case 374648427:
                        case 408125543:
                        case 440786851:
                        case 475249515:
                        case 524531317:
                            i10 = 1;
                            break;
                        case 161:
                        case 163:
                        case 165:
                        case 16877:
                        case 16981:
                        case 18402:
                        case 21419:
                        case 25506:
                        case 30322:
                            i10 = 4;
                            break;
                        case 181:
                        case 17545:
                        case 21969:
                        case 21970:
                        case 21971:
                        case 21972:
                        case 21973:
                        case 21974:
                        case 21975:
                        case 21976:
                        case 21977:
                        case 21978:
                        case 30323:
                        case 30324:
                        case 30325:
                            i10 = 5;
                            break;
                        default:
                            i10 = 0;
                            break;
                    }
                    if (i10 == 0) {
                        zVar.k((int) bVar.f28554g);
                        bVar.f28552e = 0;
                    } else if (i10 == 1) {
                        long position = zVar.getPosition();
                        arrayDeque.push(new a(bVar.f28553f, bVar.f28554g + position));
                        ((d) bVar.f28551d.f36154b).l(bVar.f28553f, position, bVar.f28554g);
                        bVar.f28552e = 0;
                    } else if (i10 == 2) {
                        long j10 = bVar.f28554g;
                        if (j10 > 8) {
                            throw ParserException.createForMalformedContainer("Invalid integer size: " + bVar.f28554g, null);
                        }
                        ((d) bVar.f28551d.f36154b).h(bVar.f28553f, bVar.a(zVar, (int) j10));
                        bVar.f28552e = 0;
                    } else if (i10 == 3) {
                        long j11 = bVar.f28554g;
                        if (j11 > 2147483647L) {
                            throw ParserException.createForMalformedContainer("String element size: " + bVar.f28554g, null);
                        }
                        j0 j0Var2 = bVar.f28551d;
                        int i14 = bVar.f28553f;
                        int i15 = (int) j11;
                        if (i15 == 0) {
                            str = "";
                        } else {
                            byte[] bArr2 = new byte[i15];
                            zVar.readFully(bArr2, 0, i15);
                            while (i15 > 0 && bArr2[i15 - 1] == 0) {
                                i15--;
                            }
                            str = new String(bArr2, 0, i15);
                        }
                        ((d) j0Var2.f36154b).m(i14, str);
                        bVar.f28552e = 0;
                    } else if (i10 == 4) {
                        ((d) bVar.f28551d.f36154b).c(bVar.f28553f, (int) bVar.f28554g, zVar);
                        bVar.f28552e = 0;
                    } else {
                        if (i10 != 5) {
                            throw ParserException.createForMalformedContainer("Invalid element type " + i10, null);
                        }
                        long j12 = bVar.f28554g;
                        if (j12 != 4 && j12 != 8) {
                            throw ParserException.createForMalformedContainer("Invalid float size: " + bVar.f28554g, null);
                        }
                        j0 j0Var3 = bVar.f28551d;
                        int i16 = (int) j12;
                        ((d) j0Var3.f36154b).f(i16 == 4 ? Float.intBitsToFloat((int) r13) : Double.longBitsToDouble(bVar.a(zVar, i16)), bVar.f28553f);
                        bVar.f28552e = 0;
                    }
                } else {
                    ((d) bVar.f28551d.f36154b).e(((a) arrayDeque.pop()).f28546a);
                }
            }
        }
        if (z10) {
            return 0;
        }
        while (true) {
            SparseArray sparseArray = this.f28592c;
            if (i11 >= sparseArray.size()) {
                return -1;
            }
            c cVar = (c) sparseArray.valueAt(i11);
            Assertions.checkNotNull(cVar.Z);
            a1 a1Var = cVar.V;
            if (a1Var != null) {
                a1Var.outputPendingSampleMetadata(cVar.Z, cVar.f28566k);
            }
            i11++;
        }
    }

    @Override // androidx.media3.extractor.y
    public final void release() {
    }

    @Override // androidx.media3.extractor.y
    public final void seek(long j10, long j11) {
        this.D = -9223372036854775807L;
        this.G = 0;
        b bVar = this.f28588a;
        bVar.f28552e = 0;
        bVar.f28549b.clear();
        f fVar = bVar.f28550c;
        fVar.f28620b = 0;
        fVar.f28621c = 0;
        f fVar2 = this.f28590b;
        fVar2.f28620b = 0;
        fVar2.f28621c = 0;
        j();
        int i10 = 0;
        while (true) {
            SparseArray sparseArray = this.f28592c;
            if (i10 >= sparseArray.size()) {
                return;
            }
            a1 a1Var = ((c) sparseArray.valueAt(i10)).V;
            if (a1Var != null) {
                a1Var.f3310b = false;
                a1Var.f3311c = 0;
            }
            i10++;
        }
    }

    @Override // androidx.media3.extractor.y
    public final boolean sniff(z zVar) {
        e eVar = new e();
        long length = zVar.getLength();
        long j10 = 1024;
        if (length != -1 && length <= 1024) {
            j10 = length;
        }
        int i10 = (int) j10;
        ParsableByteArray parsableByteArray = (ParsableByteArray) eVar.f28617b;
        zVar.a(0, 4, parsableByteArray.getData());
        eVar.f28616a = 4;
        for (long unsignedInt = parsableByteArray.readUnsignedInt(); unsignedInt != 440786851; unsignedInt = ((unsignedInt << 8) & (-256)) | ((long) (parsableByteArray.getData()[0] & 255))) {
            int i11 = eVar.f28616a + 1;
            eVar.f28616a = i11;
            if (i11 == i10) {
                return false;
            }
            zVar.a(0, 1, parsableByteArray.getData());
        }
        long jB = eVar.b(zVar);
        long j11 = eVar.f28616a;
        if (jB == Long.MIN_VALUE) {
            return false;
        }
        if (length != -1 && j11 + jB >= length) {
            return false;
        }
        while (true) {
            long j12 = eVar.f28616a;
            long j13 = j11 + jB;
            if (j12 >= j13) {
                return j12 == j13;
            }
            if (eVar.b(zVar) == Long.MIN_VALUE) {
                return false;
            }
            long jB2 = eVar.b(zVar);
            if (jB2 < 0 || jB2 > 2147483647L) {
                return false;
            }
            if (jB2 != 0) {
                int i12 = (int) jB2;
                zVar.h(i12);
                eVar.f28616a += i12;
            }
        }
    }
}
