package com.google.android.gms.internal.ads;

import android.util.SparseArray;
import androidx.annotation.Nullable;
import androidx.media3.common.MimeTypes;
import java.io.EOFException;
import java.io.InterruptedIOException;
import java.math.RoundingMode;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;

/* JADX INFO: loaded from: classes2.dex */
public final class g6 implements o2 {

    /* JADX INFO: renamed from: j0, reason: collision with root package name */
    public static final byte[] f11494j0 = {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: k0, reason: collision with root package name */
    public static final byte[] f11495k0;

    /* JADX INFO: renamed from: l0, reason: collision with root package name */
    public static final byte[] f11496l0;

    /* JADX INFO: renamed from: m0, reason: collision with root package name */
    public static final byte[] f11497m0;

    /* JADX INFO: renamed from: n0, reason: collision with root package name */
    public static final UUID f11498n0;

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

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

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

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

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: f0, reason: collision with root package name */
    public byte f11511f0;

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

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

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

    /* JADX INFO: renamed from: h0, reason: collision with root package name */
    public q2 f11515h0;

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

    /* JADX INFO: renamed from: i0, reason: collision with root package name */
    public final b6 f11517i0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    @Nullable
    private f6 zzE;

    static {
        String str = bb1.f9474a;
        f11495k0 = "Format: Start, End, ReadOrder, Layer, Style, Name, MarginL, MarginR, MarginV, Effect, Text".getBytes(StandardCharsets.UTF_8);
        f11496l0 = new byte[]{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};
        f11497m0 = new byte[]{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};
        f11498n0 = new UUID(72057594037932032L, -9223371306706625679L);
        HashMap map = new HashMap();
        com.google.android.gms.measurement.internal.u1.t(0, map, "htc_video_rotA-000", 90, "htc_video_rotA-090");
        com.google.android.gms.measurement.internal.u1.t(180, map, "htc_video_rotA-180", 270, "htc_video_rotA-270");
        f11499o0 = Collections.unmodifiableMap(map);
    }

    public g6() {
        this(new b6(), 2, i8.f12406t);
    }

    public static byte[] s(long j10, long j11, String str) {
        ih1.x(j10 != -9223372036854775807L);
        Locale locale = Locale.US;
        int i10 = (int) (j10 / 3600000000L);
        Integer numValueOf = Integer.valueOf(i10);
        long j12 = j10 - (((long) i10) * 3600000000L);
        int i11 = (int) (j12 / 60000000);
        Integer numValueOf2 = Integer.valueOf(i11);
        long j13 = j12 - (((long) i11) * 60000000);
        int i12 = (int) (j13 / 1000000);
        String str2 = String.format(locale, str, numValueOf, numValueOf2, Integer.valueOf(i12), Integer.valueOf((int) ((j13 - (((long) i12) * 1000000)) / j11)));
        String str3 = bb1.f9474a;
        return str2.getBytes(StandardCharsets.UTF_8);
    }

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

    @Override // com.google.android.gms.internal.ads.o2
    public final boolean a(p2 p2Var) throws EOFException, InterruptedIOException {
        h6 h6Var = new h6();
        long jZzo = p2Var.zzo();
        long j10 = 1024;
        if (jZzo != -1 && jZzo <= 1024) {
            j10 = jZzo;
        }
        p01 p01Var = (p01) h6Var.f12038c;
        h2 h2Var = (h2) p2Var;
        h2Var.j(p01Var.f15225a, 0, 4, false);
        h6Var.f12037b = 4;
        for (long jN = p01Var.N(); jN != 440786851; jN = ((jN << 8) & (-256)) | ((long) (p01Var.f15225a[0] & 255))) {
            int i10 = (int) j10;
            int i11 = h6Var.f12037b + 1;
            h6Var.f12037b = i11;
            if (i11 == i10) {
                return false;
            }
            h2Var.j(p01Var.f15225a, 0, 1, false);
        }
        long jE = h6Var.e(p2Var);
        long j11 = h6Var.f12037b;
        if (jE == Long.MIN_VALUE) {
            return false;
        }
        long j12 = j11 + jE;
        if (jZzo != -1 && j12 >= jZzo) {
            return false;
        }
        while (true) {
            long j13 = h6Var.f12037b;
            if (j13 >= j12) {
                return j13 == j12;
            }
            if (h6Var.e(p2Var) == Long.MIN_VALUE) {
                return false;
            }
            long jE2 = h6Var.e(p2Var);
            if (jE2 < 0) {
                return false;
            }
            if (jE2 != 0) {
                int i12 = (int) jE2;
                h2Var.l(i12, false);
                h6Var.f12037b += i12;
            }
        }
    }

    @Override // com.google.android.gms.internal.ads.o2
    public final void b(q2 q2Var) {
        if (this.f11506d) {
            q2Var = new k8(q2Var, this.f11508e);
        }
        this.f11515h0 = q2Var;
    }

    /* JADX WARN: Code restructure failed: missing block: B:131:?, code lost:
    
        return 1;
     */
    /* JADX WARN: Code restructure failed: missing block: B:87:0x01cf, code lost:
    
        r4 = r25.zzn();
     */
    /* JADX WARN: Code restructure failed: missing block: B:88:0x01d5, code lost:
    
        if (r24.H == false) goto L91;
     */
    /* JADX WARN: Code restructure failed: missing block: B:89:0x01d7, code lost:
    
        r24.J = r4;
        r26.f3366a = r24.I;
        r24.H = false;
     */
    /* JADX WARN: Code restructure failed: missing block: B:90:0x01df, code lost:
    
        return 1;
     */
    /* JADX WARN: Code restructure failed: missing block: B:92:0x01e3, code lost:
    
        if (r24.f11532x == false) goto L109;
     */
    /* JADX WARN: Code restructure failed: missing block: B:93:0x01e5, code lost:
    
        r4 = r24.J;
     */
    /* JADX WARN: Code restructure failed: missing block: B:94:0x01eb, code lost:
    
        if (r4 == (-1)) goto L110;
     */
    /* JADX WARN: Code restructure failed: missing block: B:95:0x01ed, code lost:
    
        r26.f3366a = r4;
        r24.J = -1;
     */
    /* JADX WARN: Removed duplicated region for block: B:112:0x0101 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:113:0x0147 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:114:0x0151 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:115:0x0175 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:116:0x01bf A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:55:0x00f7 A[LOOP:1: B:6:0x0014->B:55:0x00f7, LOOP_END] */
    @Override // com.google.android.gms.internal.ads.o2
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int c(p2 p2Var, androidx.media3.extractor.f0 f0Var) throws zzat {
        i6 i6Var;
        int i10;
        String str;
        int i11;
        int iB;
        int i12 = 0;
        this.L = false;
        while (!this.L) {
            b6 b6Var = this.f11517i0;
            b6Var.f9406d.getClass();
            while (true) {
                ArrayDeque arrayDeque = b6Var.f9404b;
                a6 a6Var = (a6) arrayDeque.peek();
                if (a6Var == null || p2Var.zzn() < a6Var.f8498b) {
                    int i13 = b6Var.f9407e;
                    int i14 = 8;
                    i6 i6Var2 = b6Var.f9405c;
                    if (i13 != 0) {
                        i6Var = i6Var2;
                        if (i13 == 1) {
                        }
                        c6 c6Var = b6Var.f9406d;
                        i10 = b6Var.f9408f;
                        g6 g6Var = c6Var.f9744a;
                        switch (i10) {
                            case 131:
                            case 136:
                            case 155:
                            case 159:
                            case 176:
                            case 179:
                            case 186:
                            case 215:
                            case 231:
                            case 238:
                            case 240:
                            case 241:
                            case 247:
                            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:
                                long j10 = b6Var.f9409g;
                                if (j10 > 8) {
                                    StringBuilder sb = new StringBuilder(String.valueOf(j10).length() + 22);
                                    sb.append("Invalid integer size: ");
                                    sb.append(j10);
                                    throw zzat.zzb(sb.toString(), null);
                                }
                                g6Var.h(i10, b6Var.a(p2Var, (int) j10));
                                b6Var.f9407e = 0;
                                break;
                                break;
                            case 134:
                            case 17026:
                            case 21358:
                            case 2274716:
                                long j11 = b6Var.f9409g;
                                if (j11 > 2147483647L) {
                                    StringBuilder sb2 = new StringBuilder(String.valueOf(j11).length() + 21);
                                    sb2.append("String element size: ");
                                    sb2.append(j11);
                                    throw zzat.zzb(sb2.toString(), null);
                                }
                                int i15 = (int) j11;
                                if (i15 == 0) {
                                    str = "";
                                } else {
                                    byte[] bArr = new byte[i15];
                                    p2Var.c(bArr, 0, i15);
                                    while (i15 > 0) {
                                        int i16 = i15 - 1;
                                        if (bArr[i16] == 0) {
                                            i15 = i16;
                                        } else {
                                            str = new String(bArr, 0, i15);
                                        }
                                    }
                                    str = new String(bArr, 0, i15);
                                }
                                g6Var.j(i10, str);
                                b6Var.f9407e = 0;
                                break;
                                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:
                                long jZzn = p2Var.zzn();
                                arrayDeque.push(new a6(jZzn + b6Var.f9409g, i10));
                                b6Var.f9406d.f9744a.f(b6Var.f9408f, jZzn, b6Var.f9409g);
                                b6Var.f9407e = 0;
                                break;
                            case 161:
                            case 163:
                            case 165:
                            case 16877:
                            case 16981:
                            case 18402:
                            case 21419:
                            case 25506:
                            case 30322:
                                g6Var.k(i10, (int) b6Var.f9409g, p2Var);
                                b6Var.f9407e = 0;
                                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:
                                long j12 = b6Var.f9409g;
                                if (j12 != 4 && j12 != 8) {
                                    StringBuilder sb3 = new StringBuilder(String.valueOf(j12).length() + 20);
                                    sb3.append("Invalid float size: ");
                                    sb3.append(j12);
                                    throw zzat.zzb(sb3.toString(), null);
                                }
                                int i17 = (int) j12;
                                g6Var.i(i17 == 4 ? Float.intBitsToFloat((int) r7) : Double.longBitsToDouble(b6Var.a(p2Var, i17)), i10);
                                b6Var.f9407e = 0;
                                break;
                                break;
                            default:
                                p2Var.e((int) b6Var.f9409g);
                                b6Var.f9407e = 0;
                                break;
                        }
                    } else {
                        long jA = i6Var2.a(p2Var, true, false, 4);
                        if (jA == -2) {
                            p2Var.zzl();
                            while (true) {
                                byte[] bArr2 = b6Var.f9403a;
                                p2Var.h(0, 4, bArr2);
                                byte b10 = bArr2[0];
                                int i18 = 0;
                                while (true) {
                                    if (i18 < i14) {
                                        int i19 = i18 + 1;
                                        i6Var = i6Var2;
                                        if ((i6.f12384d[i18] & ((long) b10)) != 0) {
                                            i11 = i19;
                                        } else {
                                            i18 = i19;
                                            i6Var2 = i6Var;
                                            i14 = 8;
                                        }
                                    } else {
                                        i6Var = i6Var2;
                                        i11 = -1;
                                    }
                                }
                                if (i11 != -1 && i11 <= 4) {
                                    iB = (int) i6.b(bArr2, i11, false);
                                    g6 g6Var2 = b6Var.f9406d.f9744a;
                                    if (iB != 357149030 && iB != 524531317 && iB != 475249515) {
                                        if (iB == 374648427) {
                                            iB = 374648427;
                                        }
                                    }
                                }
                                p2Var.e(1);
                                i6Var2 = i6Var;
                                i14 = 8;
                            }
                            p2Var.e(i11);
                            jA = iB;
                        } else {
                            i6Var = i6Var2;
                        }
                        if (jA == -1) {
                            while (true) {
                                SparseArray sparseArray = this.f11502b;
                                if (i12 >= sparseArray.size()) {
                                    return -1;
                                }
                                f6 f6Var = (f6) sparseArray.valueAt(i12);
                                f6Var.f11045a0.getClass();
                                v3 v3Var = f6Var.V;
                                if (v3Var != null) {
                                    v3Var.zzd(f6Var.f11045a0, f6Var.f11057k);
                                }
                                i12++;
                            }
                        } else {
                            b6Var.f9408f = (int) jA;
                            b6Var.f9407e = 1;
                        }
                    }
                    b6Var.f9409g = i6Var.a(p2Var, false, true, 8);
                    b6Var.f9407e = 2;
                    c6 c6Var2 = b6Var.f9406d;
                    i10 = b6Var.f9408f;
                    g6 g6Var3 = c6Var2.f9744a;
                    switch (i10) {
                        case 131:
                        case 136:
                        case 155:
                        case 159:
                        case 176:
                        case 179:
                        case 186:
                        case 215:
                        case 231:
                        case 238:
                        case 240:
                        case 241:
                        case 247:
                        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:
                            break;
                        case 134:
                        case 17026:
                        case 21358:
                        case 2274716:
                            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:
                            break;
                        case 161:
                        case 163:
                        case 165:
                        case 16877:
                        case 16981:
                        case 18402:
                        case 21419:
                        case 25506:
                        case 30322:
                            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:
                            break;
                    }
                } else {
                    b6Var.f9406d.f9744a.g(((a6) arrayDeque.pop()).f8497a);
                }
            }
        }
        return 0;
    }

    @Override // com.google.android.gms.internal.ads.o2
    public final void d(long j10, long j11) {
        this.K = -9223372036854775807L;
        this.M = 0;
        b6 b6Var = this.f11517i0;
        b6Var.f9407e = 0;
        b6Var.f9404b.clear();
        i6 i6Var = b6Var.f9405c;
        i6Var.f12386b = 0;
        i6Var.f12387c = 0;
        i6 i6Var2 = this.f11500a;
        i6Var2.f12386b = 0;
        i6Var2.f12387c = 0;
        q();
        this.B = false;
        this.C = -9223372036854775807L;
        this.D = -1;
        this.E = -1L;
        this.F = -1L;
        if (!this.f11532x) {
            this.A.clear();
        }
        int i10 = 0;
        while (true) {
            SparseArray sparseArray = this.f11502b;
            if (i10 >= sparseArray.size()) {
                return;
            }
            v3 v3Var = ((f6) sparseArray.valueAt(i10)).V;
            if (v3Var != null) {
                v3Var.f17489b = false;
                v3Var.f17490c = 0;
            }
            i10++;
        }
    }

    public final void e() {
        if (!this.f11531w) {
            return;
        }
        int i10 = 0;
        while (true) {
            SparseArray sparseArray = this.f11502b;
            if (i10 >= sparseArray.size()) {
                q2 q2Var = this.f11515h0;
                q2Var.getClass();
                q2Var.d();
                this.f11531w = false;
                return;
            }
            if (((f6) sparseArray.valueAt(i10)).W) {
                return;
            } else {
                i10++;
            }
        }
    }

    public final void f(int i10, long j10, long j11) throws zzat {
        q2 q2Var = this.f11515h0;
        q2Var.getClass();
        if (i10 == 160) {
            this.W = false;
            this.X = 0L;
            return;
        }
        if (i10 == 174) {
            f6 f6Var = new f6();
            f6Var.f11060n = -1;
            f6Var.f11061o = -1;
            f6Var.f11062p = -1;
            f6Var.f11063q = -1;
            f6Var.f11064r = -1;
            f6Var.f11065s = 0;
            f6Var.f11066t = -1;
            f6Var.f11067u = 0.0f;
            f6Var.f11068v = 0.0f;
            f6Var.f11069w = 0.0f;
            f6Var.f11070x = null;
            f6Var.f11071y = -1;
            f6Var.f11072z = false;
            f6Var.A = -1;
            f6Var.B = -1;
            f6Var.C = -1;
            f6Var.D = 1000;
            f6Var.E = 200;
            f6Var.F = -1.0f;
            f6Var.G = -1.0f;
            f6Var.H = -1.0f;
            f6Var.I = -1.0f;
            f6Var.J = -1.0f;
            f6Var.K = -1.0f;
            f6Var.L = -1.0f;
            f6Var.M = -1.0f;
            f6Var.N = -1.0f;
            f6Var.O = -1.0f;
            f6Var.Q = 1;
            f6Var.R = -1;
            f6Var.S = 8000;
            f6Var.T = 0L;
            f6Var.U = 0L;
            f6Var.W = false;
            f6Var.Y = true;
            f6Var.Z = "eng";
            this.zzE = f6Var;
            f6Var.f11044a = this.f11530v;
            return;
        }
        if (i10 == 183) {
            if (this.f11532x) {
                return;
            }
            m(i10);
            this.D = -1;
            this.E = -1L;
            this.F = -1L;
            return;
        }
        if (i10 == 187) {
            if (this.f11532x) {
                return;
            }
            m(i10);
            this.C = -9223372036854775807L;
            return;
        }
        if (i10 == 19899) {
            this.f11533y = -1;
            this.f11534z = -1L;
            return;
        }
        if (i10 == 20533) {
            l(i10);
            this.zzE.f11055i = true;
            return;
        }
        if (i10 == 21968) {
            l(i10);
            this.zzE.f11072z = true;
            return;
        }
        if (i10 == 408125543) {
            long j12 = this.f11526r;
            if (j12 != -1 && j12 != j10) {
                throw zzat.zzb("Multiple Segment elements not supported", null);
            }
            this.f11526r = j10;
            this.f11525q = j11;
            return;
        }
        if (i10 == 475249515) {
            if (this.f11532x) {
                return;
            }
            this.B = true;
        } else if (i10 == 524531317 && !this.f11532x) {
            if (this.f11504c && this.I != -1) {
                this.H = true;
            } else {
                q2Var.k(new w2(this.f11529u, 0L));
                this.f11532x = true;
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:74:0x01a0  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void g(int i10) throws zzat {
        int i11;
        int i12;
        int i13;
        List list;
        int i14;
        SparseArray sparseArray;
        SparseArray sparseArray2;
        f6 f6Var;
        List list2;
        long j10;
        SparseArray sparseArray3;
        List list3;
        int i15;
        long j11;
        long j12;
        long j13;
        g6 g6Var = this;
        g6Var.f11515h0.getClass();
        SparseArray sparseArray4 = g6Var.f11502b;
        int i16 = 2;
        if (i10 == 160) {
            if (g6Var.M == 2) {
                f6 f6Var2 = (f6) sparseArray4.get(g6Var.S);
                f6Var2.f11045a0.getClass();
                if (g6Var.X > 0 && "A_OPUS".equals(f6Var2.f11048c)) {
                    byte[] bArrArray = ByteBuffer.allocate(8).order(ByteOrder.LITTLE_ENDIAN).putLong(g6Var.X).array();
                    g6Var.f11523o.w(bArrArray.length, bArrArray);
                }
                int i17 = 0;
                for (int i18 = 0; i18 < g6Var.Q; i18++) {
                    i17 += g6Var.R[i18];
                }
                int i19 = 0;
                while (i19 < g6Var.Q) {
                    long j14 = g6Var.N + ((long) ((f6Var2.f11052f * i19) / 1000));
                    int i20 = g6Var.U;
                    if (i19 == 0) {
                        if (!g6Var.W) {
                            i20 |= 1;
                        }
                        i11 = i20;
                        i12 = 0;
                    } else {
                        i11 = i20;
                        i12 = i19;
                    }
                    int i21 = g6Var.R[i12];
                    int i22 = i17 - i21;
                    n(f6Var2, j14, i11, i21, i22);
                    i19 = i12 + 1;
                    i17 = i22;
                }
                g6Var.M = 0;
                return;
            }
            return;
        }
        if (i10 == 174) {
            f6 f6Var3 = g6Var.zzE;
            f6Var3.getClass();
            String str = f6Var3.f11048c;
            if (str == null) {
                throw zzat.zzb("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":
                    f6Var3.a(f6Var3.f11050d);
                    f6Var3.f11045a0 = g6Var.f11515h0.e(f6Var3.f11050d, f6Var3.f11051e);
                    sparseArray4.put(f6Var3.f11050d, f6Var3);
                    break;
            }
            g6Var.zzE = null;
            return;
        }
        SparseArray sparseArray5 = g6Var.A;
        if (i10 == 183) {
            if (g6Var.f11532x) {
                return;
            }
            m(i10);
            if (g6Var.C == -9223372036854775807L || (i13 = g6Var.D) == -1 || g6Var.E == -1) {
                return;
            }
            List arrayList = (List) sparseArray5.get(i13);
            if (arrayList == null) {
                arrayList = new ArrayList();
                sparseArray5.put(g6Var.D, arrayList);
            }
            arrayList.add(new d6(g6Var.C, g6Var.f11526r + g6Var.E, g6Var.F));
            return;
        }
        if (i10 == 19899) {
            int i23 = g6Var.f11533y;
            if (i23 != -1) {
                long j15 = g6Var.f11534z;
                if (j15 != -1) {
                    if (i23 == 475249515) {
                        g6Var.I = j15;
                        return;
                    }
                    return;
                }
            }
            throw zzat.zzb("Mandatory element SeekID or SeekPosition not found", null);
        }
        if (i10 == 25152) {
            l(i10);
            f6 f6Var4 = g6Var.zzE;
            if (f6Var4.f11055i) {
                t3 t3Var = f6Var4.f11057k;
                if (t3Var == null) {
                    throw zzat.zzb("Encrypted Track found but ContentEncKeyID was not found", null);
                }
                f6Var4.f11059m = new uk2(null, new bk2(jj1.f12904a, null, MimeTypes.VIDEO_WEBM, t3Var.f16693b));
                return;
            }
            return;
        }
        if (i10 == 28032) {
            l(i10);
            f6 f6Var5 = g6Var.zzE;
            if (f6Var5.f11055i && f6Var5.f11056j != null) {
                throw zzat.zzb("Combining encryption and compression is not supported", null);
            }
            return;
        }
        if (i10 == 357149030) {
            if (g6Var.f11527s == -9223372036854775807L) {
                g6Var.f11527s = 1000000L;
            }
            long j16 = g6Var.f11528t;
            if (j16 != -9223372036854775807L) {
                g6Var.f11529u = g6Var.t(j16);
                return;
            }
            return;
        }
        if (i10 == 374648427) {
            SparseArray sparseArray6 = sparseArray4;
            if (sparseArray6.size() == 0) {
                throw zzat.zzb("No valid tracks were found", null);
            }
            boolean z10 = !this.f11504c || this.I == -1;
            int i24 = 0;
            int i25 = -1;
            int i26 = -1;
            int i27 = -1;
            int i28 = -1;
            while (i24 < sparseArray6.size()) {
                SparseArray sparseArray7 = sparseArray6;
                f6 f6Var6 = (f6) sparseArray7.valueAt(i24);
                int i29 = f6Var6.f11051e;
                if (i29 == 2) {
                    if (f6Var6.Y) {
                        i25 = f6Var6.f11050d;
                    }
                    if (i26 == -1) {
                        i26 = f6Var6.f11050d;
                    }
                } else if (i29 == 1) {
                    if (f6Var6.Y) {
                        i27 = f6Var6.f11050d;
                    }
                    if (i28 == -1) {
                        i28 = f6Var6.f11050d;
                    }
                }
                if (z10) {
                    f6Var6.f11045a0.getClass();
                    if (!f6Var6.W) {
                        u3 u3Var = f6Var6.f11045a0;
                        zn2 zn2Var = f6Var6.f11047b0;
                        zn2Var.getClass();
                        u3Var.d(zn2Var);
                    }
                }
                i24++;
                sparseArray6 = sparseArray7;
            }
            SparseArray sparseArray8 = sparseArray6;
            if (i25 != -1) {
                this.G = i25;
            } else if (i26 != -1) {
                this.G = i26;
            } else if (i27 != -1) {
                this.G = i27;
            } else if (i28 != -1) {
                this.G = i28;
            } else {
                this.G = sparseArray8.size() > 0 ? ((f6) sparseArray8.valueAt(0)).f11050d : -1;
            }
            if (z10) {
                e();
                return;
            }
            return;
        }
        if (i10 == 475249515 && !g6Var.f11532x) {
            int i30 = 0;
            while (true) {
                if (i30 >= sparseArray5.size()) {
                    break;
                }
                if (((List) sparseArray5.valueAt(i30)).isEmpty()) {
                    i30++;
                } else {
                    if (g6Var.f11529u == -9223372036854775807L) {
                        break;
                    }
                    for (int i31 = 0; i31 < sparseArray5.size(); i31++) {
                        Collections.sort((List) sparseArray5.valueAt(i31));
                    }
                    g6Var.f11515h0.k(new e6(sparseArray5, g6Var.f11529u, g6Var.G, g6Var.f11526r, g6Var.f11525q));
                }
            }
            g6Var.f11515h0.k(new w2(g6Var.f11529u, 0L));
            g6Var.f11532x = true;
            g6Var.B = false;
            int i32 = 0;
            while (i32 < sparseArray4.size()) {
                f6 f6Var7 = (f6) sparseArray4.valueAt(i32);
                long j17 = g6Var.f11529u;
                long j18 = g6Var.f11526r;
                long j19 = g6Var.f11525q;
                if (f6Var7.f11051e != i16 || (list = (List) sparseArray5.get(f6Var7.f11050d)) == null || list.isEmpty()) {
                    i14 = i32;
                    sparseArray = sparseArray4;
                    sparseArray2 = sparseArray5;
                } else {
                    if (list.isEmpty()) {
                        i14 = i32;
                        sparseArray = sparseArray4;
                        sparseArray2 = sparseArray5;
                        f6Var = f6Var7;
                    } else {
                        int iMin = Math.min(list.size(), 20);
                        double d10 = 0.0d;
                        int i33 = 0;
                        int i34 = -1;
                        while (true) {
                            if (i33 >= iMin) {
                                i14 = i32;
                                sparseArray = sparseArray4;
                                sparseArray2 = sparseArray5;
                                f6Var = f6Var7;
                                list2 = list;
                                break;
                            }
                            d6 d6Var = (d6) list.get(i33);
                            int i35 = iMin;
                            SparseArray sparseArray9 = sparseArray5;
                            if (d6Var.f10210a > 10000000) {
                                i14 = i32;
                                sparseArray = sparseArray4;
                                f6Var = f6Var7;
                                list2 = list;
                                sparseArray2 = sparseArray9;
                                break;
                            }
                            int i36 = i33 + 1;
                            int size = list.size() - 1;
                            int i37 = i32;
                            SparseArray sparseArray10 = sparseArray4;
                            long j20 = d6Var.f10210a;
                            f6 f6Var8 = f6Var7;
                            long j21 = j17;
                            long j22 = d6Var.f10212c;
                            long j23 = d6Var.f10211b;
                            if (i33 < size) {
                                d6 d6Var2 = (d6) list.get(i36);
                                sparseArray3 = sparseArray9;
                                list3 = list;
                                i15 = i33;
                                j11 = d6Var2.f10211b + d6Var2.f10212c;
                                j12 = j23 + j22;
                                j13 = d6Var2.f10210a - j20;
                            } else {
                                sparseArray3 = sparseArray9;
                                list3 = list;
                                i15 = i33;
                                j11 = j18 + j19;
                                j12 = j23 + j22;
                                j13 = j21 - j20;
                            }
                            long j24 = j11 - j12;
                            if (j13 > 0) {
                                double d11 = j24 / j13;
                                if (d11 > d10) {
                                    d10 = d11;
                                    i34 = i15;
                                }
                            }
                            i33 = i36;
                            sparseArray4 = sparseArray10;
                            i32 = i37;
                            f6Var7 = f6Var8;
                            j17 = j21;
                            sparseArray5 = sparseArray3;
                            list = list3;
                            iMin = i35;
                        }
                        int i38 = i34;
                        if (i38 != -1) {
                            j10 = ((d6) list2.get(i38)).f10210a;
                        }
                        f6Var7 = f6Var;
                        if (j10 != -9223372036854775807L) {
                            zn2 zn2Var2 = f6Var7.f11047b0;
                            zn2Var2.getClass();
                            ta taVar = zn2Var2.zzl;
                            z4 z4Var = new z4(j10);
                            ta taVar2 = taVar == null ? new ta(z4Var) : taVar.b(z4Var);
                            zn2 zn2Var3 = f6Var7.f11047b0;
                            zn2Var3.getClass();
                            sm2 sm2Var = new sm2(zn2Var3);
                            sm2Var.zzk(taVar2);
                            f6Var7.f11047b0 = new zn2(sm2Var);
                        }
                    }
                    j10 = -9223372036854775807L;
                    f6Var7 = f6Var;
                    if (j10 != -9223372036854775807L) {
                    }
                }
                if (!f6Var7.W) {
                    f6Var7.f11045a0.getClass();
                    u3 u3Var2 = f6Var7.f11045a0;
                    zn2 zn2Var4 = f6Var7.f11047b0;
                    zn2Var4.getClass();
                    u3Var2.d(zn2Var4);
                }
                i32 = i14 + 1;
                sparseArray4 = sparseArray;
                sparseArray5 = sparseArray2;
                i16 = 2;
                g6Var = this;
            }
            e();
        }
    }

    public final void h(int i10, long j10) throws zzat {
        boolean z10;
        if (i10 == 240) {
            if (this.f11532x) {
                return;
            }
            m(i10);
            if (this.F == -1) {
                this.F = j10;
                return;
            }
            return;
        }
        if (i10 == 241) {
            if (this.f11532x) {
                return;
            }
            m(i10);
            if (this.E == -1) {
                this.E = j10;
                return;
            }
            return;
        }
        if (i10 == 20529) {
            if (j10 == 0) {
                return;
            }
            StringBuilder sb = new StringBuilder(String.valueOf(j10).length() + 35);
            sb.append("ContentEncodingOrder ");
            sb.append(j10);
            sb.append(" not supported");
            throw zzat.zzb(sb.toString(), null);
        }
        if (i10 == 20530) {
            if (j10 == 1) {
                return;
            }
            StringBuilder sb2 = new StringBuilder(String.valueOf(j10).length() + 35);
            sb2.append("ContentEncodingScope ");
            sb2.append(j10);
            sb2.append(" not supported");
            throw zzat.zzb(sb2.toString(), null);
        }
        switch (i10) {
            case 131:
                int i11 = (int) j10;
                if (i11 == 1) {
                    l(i10);
                    this.zzE.f11051e = 2;
                    return;
                }
                if (i11 == 2) {
                    l(i10);
                    this.zzE.f11051e = 1;
                    return;
                } else if (i11 == 17) {
                    l(i10);
                    this.zzE.f11051e = 3;
                    return;
                } else if (i11 != 33) {
                    l(i10);
                    this.zzE.f11051e = -1;
                    return;
                } else {
                    l(i10);
                    this.zzE.f11051e = 5;
                    return;
                }
            case 136:
                z10 = j10 == 1;
                l(i10);
                this.zzE.Y = z10;
                return;
            case 155:
                this.O = t(j10);
                return;
            case 159:
                l(i10);
                this.zzE.Q = (int) j10;
                return;
            case 176:
                l(i10);
                this.zzE.f11060n = (int) j10;
                return;
            case 179:
                if (this.f11532x) {
                    return;
                }
                m(i10);
                this.C = t(j10);
                return;
            case 186:
                l(i10);
                this.zzE.f11061o = (int) j10;
                return;
            case 215:
                l(i10);
                this.zzE.f11050d = (int) j10;
                return;
            case 231:
                this.K = t(j10);
                return;
            case 238:
                this.V = (int) j10;
                return;
            case 247:
                if (this.f11532x) {
                    return;
                }
                m(i10);
                this.D = (int) j10;
                return;
            case 251:
                this.W = true;
                return;
            case 16871:
                l(i10);
                this.zzE.f11054h = (int) j10;
                return;
            case 16980:
                if (j10 == 3) {
                    return;
                }
                StringBuilder sb3 = new StringBuilder(String.valueOf(j10).length() + 30);
                sb3.append("ContentCompAlgo ");
                sb3.append(j10);
                sb3.append(" not supported");
                throw zzat.zzb(sb3.toString(), null);
            case 17029:
                if (j10 < 1 || j10 > 2) {
                    StringBuilder sb4 = new StringBuilder(String.valueOf(j10).length() + 33);
                    sb4.append("DocTypeReadVersion ");
                    sb4.append(j10);
                    sb4.append(" not supported");
                    throw zzat.zzb(sb4.toString(), null);
                }
                return;
            case 17143:
                if (j10 == 1) {
                    return;
                }
                StringBuilder sb5 = new StringBuilder(String.valueOf(j10).length() + 30);
                sb5.append("EBMLReadVersion ");
                sb5.append(j10);
                sb5.append(" not supported");
                throw zzat.zzb(sb5.toString(), null);
            case 18401:
                if (j10 == 5) {
                    return;
                }
                StringBuilder sb6 = new StringBuilder(String.valueOf(j10).length() + 29);
                sb6.append("ContentEncAlgo ");
                sb6.append(j10);
                sb6.append(" not supported");
                throw zzat.zzb(sb6.toString(), null);
            case 18408:
                if (j10 == 1) {
                    return;
                }
                StringBuilder sb7 = new StringBuilder(String.valueOf(j10).length() + 36);
                sb7.append("AESSettingsCipherMode ");
                sb7.append(j10);
                sb7.append(" not supported");
                throw zzat.zzb(sb7.toString(), null);
            case 21420:
                this.f11534z = j10 + this.f11526r;
                return;
            case 21432:
                int i12 = (int) j10;
                l(i10);
                if (i12 == 0) {
                    this.zzE.f11071y = 0;
                    return;
                }
                if (i12 == 1) {
                    this.zzE.f11071y = 2;
                    return;
                } else if (i12 == 3) {
                    this.zzE.f11071y = 1;
                    return;
                } else {
                    if (i12 != 15) {
                        return;
                    }
                    this.zzE.f11071y = 3;
                    return;
                }
            case 21680:
                l(i10);
                this.zzE.f11063q = (int) j10;
                return;
            case 21682:
                l(i10);
                this.zzE.f11065s = (int) j10;
                return;
            case 21690:
                l(i10);
                this.zzE.f11064r = (int) j10;
                return;
            case 21930:
                z10 = j10 == 1;
                l(i10);
                this.zzE.X = z10;
                return;
            case 21938:
                l(i10);
                f6 f6Var = this.zzE;
                f6Var.f11072z = true;
                f6Var.f11062p = (int) j10;
                return;
            case 21998:
                l(i10);
                this.zzE.f11053g = (int) j10;
                return;
            case 22186:
                l(i10);
                this.zzE.T = j10;
                return;
            case 22203:
                l(i10);
                this.zzE.U = j10;
                return;
            case 25188:
                l(i10);
                this.zzE.R = (int) j10;
                return;
            case 30114:
                this.X = j10;
                return;
            case 30321:
                int i13 = (int) j10;
                l(i10);
                if (i13 == 0) {
                    this.zzE.f11066t = 0;
                    return;
                }
                if (i13 == 1) {
                    this.zzE.f11066t = 1;
                    return;
                } else if (i13 == 2) {
                    this.zzE.f11066t = 2;
                    return;
                } else {
                    if (i13 != 3) {
                        return;
                    }
                    this.zzE.f11066t = 3;
                    return;
                }
            case 2352003:
                l(i10);
                this.zzE.f11052f = (int) j10;
                return;
            case 2807729:
                this.f11527s = j10;
                return;
            default:
                switch (i10) {
                    case 21945:
                        int i14 = (int) j10;
                        l(i10);
                        if (i14 == 1) {
                            this.zzE.C = 2;
                            return;
                        } else {
                            if (i14 != 2) {
                                return;
                            }
                            this.zzE.C = 1;
                            return;
                        }
                    case 21946:
                        l(i10);
                        int iB = ea2.b((int) j10);
                        if (iB != -1) {
                            this.zzE.B = iB;
                            return;
                        }
                        return;
                    case 21947:
                        l(i10);
                        this.zzE.f11072z = true;
                        int iA = ea2.a((int) j10);
                        if (iA != -1) {
                            this.zzE.A = iA;
                            return;
                        }
                        return;
                    case 21948:
                        l(i10);
                        this.zzE.D = (int) j10;
                        return;
                    case 21949:
                        l(i10);
                        this.zzE.E = (int) j10;
                        return;
                    default:
                        return;
                }
        }
    }

    public final void i(double d10, int i10) throws zzat {
        if (i10 == 181) {
            l(i10);
            this.zzE.S = (int) d10;
            return;
        }
        if (i10 == 17545) {
            this.f11528t = (long) d10;
            return;
        }
        switch (i10) {
            case 21969:
                l(i10);
                this.zzE.F = (float) d10;
                break;
            case 21970:
                l(i10);
                this.zzE.G = (float) d10;
                break;
            case 21971:
                l(i10);
                this.zzE.H = (float) d10;
                break;
            case 21972:
                l(i10);
                this.zzE.I = (float) d10;
                break;
            case 21973:
                l(i10);
                this.zzE.J = (float) d10;
                break;
            case 21974:
                l(i10);
                this.zzE.K = (float) d10;
                break;
            case 21975:
                l(i10);
                this.zzE.L = (float) d10;
                break;
            case 21976:
                l(i10);
                this.zzE.M = (float) d10;
                break;
            case 21977:
                l(i10);
                this.zzE.N = (float) d10;
                break;
            case 21978:
                l(i10);
                this.zzE.O = (float) d10;
                break;
            default:
                switch (i10) {
                    case 30323:
                        l(i10);
                        this.zzE.f11067u = (float) d10;
                        break;
                    case 30324:
                        l(i10);
                        this.zzE.f11068v = (float) d10;
                        break;
                    case 30325:
                        l(i10);
                        this.zzE.f11069w = (float) d10;
                        break;
                }
                break;
        }
    }

    public final void j(int i10, String str) throws zzat {
        if (i10 == 134) {
            l(i10);
            this.zzE.f11048c = str;
            return;
        }
        if (i10 != 17026) {
            if (i10 == 21358) {
                l(i10);
                this.zzE.f11046b = str;
                return;
            } else {
                if (i10 != 2274716) {
                    return;
                }
                l(i10);
                this.zzE.Z = str;
                return;
            }
        }
        if ("webm".equals(str) || "matroska".equals(str)) {
            this.f11530v = str.equals("webm");
            return;
        }
        StringBuilder sb = new StringBuilder(str.length() + 22);
        sb.append("DocType ");
        sb.append(str);
        sb.append(" not supported");
        throw zzat.zzb(sb.toString(), null);
    }

    public final void k(int i10, int i11, p2 p2Var) throws zzat {
        f6 f6Var;
        int i12;
        f6 f6Var2;
        long j10;
        int i13;
        int i14;
        int i15;
        int i16;
        int i17;
        int i18 = i10;
        SparseArray sparseArray = this.f11502b;
        int i19 = 1;
        Throwable th = null;
        int i20 = 0;
        if (i18 != 161 && i18 != 163) {
            if (i18 == 165) {
                if (this.M != 2) {
                    return;
                }
                f6 f6Var3 = (f6) sparseArray.get(this.S);
                if (this.V != 4 || !"V_VP9".equals(f6Var3.f11048c)) {
                    p2Var.e(i11);
                    return;
                }
                p01 p01Var = this.f11523o;
                p01Var.v(i11);
                p2Var.c(p01Var.f15225a, 0, i11);
                return;
            }
            if (i18 == 16877) {
                l(i10);
                f6 f6Var4 = this.zzE;
                int i21 = f6Var4.f11054h;
                if (i21 != 1685485123 && i21 != 1685480259) {
                    p2Var.e(i11);
                    return;
                }
                byte[] bArr = new byte[i11];
                f6Var4.P = bArr;
                p2Var.c(bArr, 0, i11);
                return;
            }
            if (i18 == 16981) {
                l(i10);
                byte[] bArr2 = new byte[i11];
                this.zzE.f11056j = bArr2;
                p2Var.c(bArr2, 0, i11);
                return;
            }
            if (i18 == 18402) {
                byte[] bArr3 = new byte[i11];
                p2Var.c(bArr3, 0, i11);
                l(i10);
                this.zzE.f11057k = new t3(1, 0, 0, bArr3);
                return;
            }
            if (i18 == 21419) {
                p01 p01Var2 = this.f11518j;
                Arrays.fill(p01Var2.f15225a, (byte) 0);
                p2Var.c(p01Var2.f15225a, 4 - i11, i11);
                p01Var2.C(0);
                this.f11533y = (int) p01Var2.N();
                return;
            }
            if (i18 == 25506) {
                l(i10);
                byte[] bArr4 = new byte[i11];
                this.zzE.f11058l = bArr4;
                p2Var.c(bArr4, 0, i11);
                return;
            }
            if (i18 != 30322) {
                StringBuilder sb = new StringBuilder(String.valueOf(i10).length() + 15);
                sb.append("Unexpected id: ");
                sb.append(i18);
                throw zzat.zzb(sb.toString(), null);
            }
            l(i10);
            byte[] bArr5 = new byte[i11];
            this.zzE.f11070x = bArr5;
            p2Var.c(bArr5, 0, i11);
            return;
        }
        int i22 = this.M;
        p01 p01Var3 = this.f11514h;
        int i23 = 8;
        if (i22 == 0) {
            i6 i6Var = this.f11500a;
            this.S = (int) i6Var.a(p2Var, false, true, 8);
            this.T = i6Var.f12387c;
            this.O = -9223372036854775807L;
            this.M = 1;
            p01Var3.v(0);
        }
        f6 f6Var5 = (f6) sparseArray.get(this.S);
        if (f6Var5 == null) {
            p2Var.e(i11 - this.T);
            this.M = 0;
            return;
        }
        f6Var5.f11045a0.getClass();
        if (this.M == 1) {
            o(p2Var, 3);
            int i24 = (p01Var3.f15225a[2] & 6) >> 1;
            if (i24 == 0) {
                this.Q = 1;
                int[] iArrZzA = zzA(this.R, 1);
                this.R = iArrZzA;
                iArrZzA[0] = (i11 - this.T) - 3;
            } else {
                o(p2Var, 4);
                int i25 = (p01Var3.f15225a[3] & 255) + 1;
                this.Q = i25;
                int[] iArrZzA2 = zzA(this.R, i25);
                this.R = iArrZzA2;
                if (i24 == 2) {
                    int i26 = (i11 - this.T) - 4;
                    int i27 = this.Q;
                    Arrays.fill(iArrZzA2, 0, i27, i26 / i27);
                } else {
                    if (i24 != 1) {
                        if (i24 != 3) {
                            throw zzat.zzb("Unexpected lacing value: 2", null);
                        }
                        int i28 = 0;
                        int i29 = 0;
                        int i30 = 4;
                        while (true) {
                            int i31 = this.Q - 1;
                            if (i28 >= i31) {
                                f6Var = f6Var5;
                                this.R[i31] = ((i11 - this.T) - i30) - i29;
                                break;
                            }
                            this.R[i28] = i20;
                            int i32 = i30 + 1;
                            o(p2Var, i32);
                            if (p01Var3.f15225a[i30] == 0) {
                                throw zzat.zzb("No valid varint length mask found", th);
                            }
                            int i33 = i20;
                            while (true) {
                                if (i33 >= i23) {
                                    f6Var2 = f6Var5;
                                    j10 = 0;
                                    i30 = i32;
                                    break;
                                }
                                int i34 = i19 << (7 - i33);
                                if ((p01Var3.f15225a[i30] & i34) != 0) {
                                    int i35 = i32 + i33;
                                    o(p2Var, i35);
                                    int i36 = p01Var3.f15225a[i30] & 255 & (~i34);
                                    f6Var2 = f6Var5;
                                    j10 = i36;
                                    while (i32 < i35) {
                                        j10 = (j10 << 8) | ((long) (p01Var3.f15225a[i32] & 255));
                                        i32++;
                                        i33 = i33;
                                    }
                                    int i37 = i33;
                                    if (i28 > 0) {
                                        j10 -= (1 << ((i37 * 7) + 6)) - 1;
                                    }
                                    i30 = i35;
                                } else {
                                    i33++;
                                    i19 = 1;
                                    i23 = 8;
                                }
                            }
                            if (j10 < -2147483648L || j10 > 2147483647L) {
                                break;
                            }
                            int[] iArr = this.R;
                            int i38 = (int) j10;
                            if (i28 != 0) {
                                i38 += iArr[i28 - 1];
                            }
                            iArr[i28] = i38;
                            i29 += i38;
                            i28++;
                            f6Var5 = f6Var2;
                            th = null;
                            i19 = 1;
                            i20 = 0;
                            i23 = 8;
                        }
                        throw zzat.zzb("EBML lacing sample size out of range.", null);
                    }
                    int i39 = 0;
                    int i40 = 0;
                    int i41 = 4;
                    while (true) {
                        i13 = this.Q - 1;
                        if (i39 >= i13) {
                            break;
                        }
                        this.R[i39] = 0;
                        while (true) {
                            i14 = i41 + 1;
                            o(p2Var, i14);
                            int i42 = p01Var3.f15225a[i41] & 255;
                            int[] iArr2 = this.R;
                            i15 = iArr2[i39] + i42;
                            iArr2[i39] = i15;
                            if (i42 != 255) {
                                break;
                            } else {
                                i41 = i14;
                            }
                        }
                        i40 += i15;
                        i39++;
                        i41 = i14;
                    }
                    this.R[i13] = ((i11 - this.T) - i41) - i40;
                }
            }
            f6Var = f6Var5;
            byte[] bArr6 = p01Var3.f15225a;
            int i43 = bArr6[0] << 8;
            int i44 = bArr6[1] & 255;
            this.N = t(i44 | i43) + this.K;
            if (f6Var.f11051e != 1) {
                if (i18 == 163) {
                    i16 = 2;
                    if ((p01Var3.f15225a[2] & 128) == 128) {
                        i18 = 163;
                    } else {
                        i18 = 163;
                    }
                } else {
                    i16 = 2;
                }
                i17 = 0;
                this.U = i17;
                this.M = i16;
                this.P = 0;
                i12 = 163;
            } else {
                i16 = 2;
            }
            i17 = 1;
            this.U = i17;
            this.M = i16;
            this.P = 0;
            i12 = 163;
        } else {
            f6Var = f6Var5;
            i12 = 163;
        }
        if (i18 == i12) {
            while (true) {
                int i45 = this.P;
                if (i45 >= this.Q) {
                    this.M = 0;
                    return;
                }
                n(f6Var, ((long) ((this.P * f6Var.f11052f) / 1000)) + this.N, this.U, p(p2Var, f6Var, this.R[i45], false), 0);
                this.P++;
            }
        } else {
            while (true) {
                int i46 = this.P;
                if (i46 >= this.Q) {
                    return;
                }
                int[] iArr3 = this.R;
                iArr3[i46] = p(p2Var, f6Var, iArr3[i46], true);
                this.P++;
            }
        }
    }

    public final void l(int i10) throws zzat {
        if (this.zzE != null) {
            return;
        }
        StringBuilder sb = new StringBuilder(String.valueOf(i10).length() + 32);
        sb.append("Element ");
        sb.append(i10);
        sb.append(" must be in a TrackEntry");
        throw zzat.zzb(sb.toString(), null);
    }

    public final void m(int i10) throws zzat {
        if (this.B) {
            return;
        }
        StringBuilder sb = new StringBuilder(String.valueOf(i10).length() + 26);
        sb.append("Element ");
        sb.append(i10);
        sb.append(" must be in a Cues");
        throw zzat.zzb(sb.toString(), null);
    }

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARN: Failed to restore switch over string. Please report as a decompilation issue */
    /* JADX WARN: Removed duplicated region for block: B:35:0x008b  */
    /* JADX WARN: Removed duplicated region for block: B:56:0x00e0  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void n(f6 f6Var, long j10, int i10, int i11, int i12) {
        byte b10;
        byte[] bArrS;
        int i13;
        int i14;
        v3 v3Var = f6Var.V;
        if (v3Var != null) {
            v3Var.zzc(f6Var.f11045a0, j10, i10, i11, i12, f6Var.f11057k);
        } else {
            String str = f6Var.f11048c;
            if ("S_TEXT/UTF8".equals(str) || "S_TEXT/ASS".equals(str) || "S_TEXT/SSA".equals(str) || "S_TEXT/WEBVTT".equals(str)) {
                if (this.Q > 1) {
                    vt0.c("Skipping subtitle sample in laced block.");
                } else {
                    long j11 = this.O;
                    if (j11 == -9223372036854775807L) {
                        vt0.c("Skipping subtitle sample with no duration.");
                    } else {
                        p01 p01Var = this.f11520l;
                        byte[] bArr = p01Var.f15225a;
                        switch (str.hashCode()) {
                            case 738597099:
                                b10 = !str.equals("S_TEXT/ASS") ? (byte) -1 : (byte) 1;
                                break;
                            case 738614379:
                                if (str.equals("S_TEXT/SSA")) {
                                    b10 = 2;
                                    break;
                                }
                                break;
                            case 1045209816:
                                if (str.equals("S_TEXT/WEBVTT")) {
                                    b10 = 3;
                                    break;
                                }
                                break;
                            case 1422270023:
                                if (str.equals("S_TEXT/UTF8")) {
                                    b10 = 0;
                                    break;
                                }
                                break;
                        }
                        if (b10 == 0) {
                            bArrS = s(j11, 1000L, "%02d:%02d:%02d,%03d");
                            i13 = 19;
                        } else if (b10 == 1 || b10 == 2) {
                            bArrS = s(j11, 10000L, "%01d:%02d:%02d:%02d");
                            i13 = 21;
                        } else {
                            if (b10 != 3) {
                                throw new IllegalArgumentException();
                            }
                            bArrS = s(j11, 1000L, "%02d:%02d:%02d.%03d");
                            i13 = 25;
                        }
                        System.arraycopy(bArrS, 0, bArr, i13, bArrS.length);
                        int i15 = p01Var.f15226b;
                        while (true) {
                            if (i15 < p01Var.f15227c) {
                                if (p01Var.f15225a[i15] == 0) {
                                    p01Var.A(i15);
                                } else {
                                    i15++;
                                }
                            }
                        }
                        f6Var.f11045a0.a(p01Var, p01Var.f15227c);
                        i14 = i11 + p01Var.f15227c;
                        if ((i10 & 268435456) != 0) {
                            int i16 = this.Q;
                            p01 p01Var2 = this.f11523o;
                            if (i16 > 1) {
                                p01Var2.v(0);
                            } else {
                                int i17 = p01Var2.f15227c;
                                f6Var.f11045a0.b(p01Var2, i17, 2);
                                i14 += i17;
                            }
                        }
                        f6Var.f11045a0.zze(j10, i10, i14, i12, f6Var.f11057k);
                    }
                }
                i14 = i11;
                if ((i10 & 268435456) != 0) {
                }
                f6Var.f11045a0.zze(j10, i10, i14, i12, f6Var.f11057k);
            } else {
                i14 = i11;
                if ((i10 & 268435456) != 0) {
                }
                f6Var.f11045a0.zze(j10, i10, i14, i12, f6Var.f11057k);
            }
        }
        this.L = true;
    }

    public final void o(p2 p2Var, int i10) {
        p01 p01Var = this.f11514h;
        if (p01Var.f15227c >= i10) {
            return;
        }
        byte[] bArr = p01Var.f15225a;
        if (bArr.length < i10) {
            int length = bArr.length;
            p01Var.x(Math.max(length + length, i10));
        }
        byte[] bArr2 = p01Var.f15225a;
        int i11 = p01Var.f15227c;
        p2Var.c(bArr2, i11, i10 - i11);
        p01Var.A(i10);
    }

    public final int p(p2 p2Var, f6 f6Var, int i10, boolean z10) throws zzat {
        int iE;
        int iE2;
        int i11;
        String str = f6Var.f11048c;
        if ("S_TEXT/UTF8".equals(str)) {
            r(p2Var, f11494j0, i10);
            int i12 = this.Z;
            q();
            return i12;
        }
        if ("S_TEXT/ASS".equals(str) || "S_TEXT/SSA".equals(str)) {
            r(p2Var, f11496l0, i10);
            int i13 = this.Z;
            q();
            return i13;
        }
        if ("S_TEXT/WEBVTT".equals(str)) {
            r(p2Var, f11497m0, i10);
            int i14 = this.Z;
            q();
            return i14;
        }
        if (f6Var.W) {
            f6Var.f11047b0.getClass();
            p01 p01Var = new p01(i10);
            if (p2Var.j(p01Var.f15225a, 0, i10, true)) {
                p2Var.zzl();
                if (n2.a(p01Var.H()) == 1 && p01Var.y() >= 10) {
                    byte[] bArr = new byte[10];
                    p01Var.F(0, 10, bArr);
                    p01Var.C(0);
                    int iB = n2.b(bArr);
                    if (p01Var.y() >= iB + 4) {
                        p01Var.E(iB);
                        if (n2.a(p01Var.b()) == 2) {
                            zn2 zn2Var = f6Var.f11047b0;
                            zn2Var.getClass();
                            sm2 sm2Var = new sm2(zn2Var);
                            sm2Var.zzm(MimeTypes.AUDIO_DTS_HD);
                            f6Var.f11047b0 = new zn2(sm2Var);
                        }
                    }
                }
            }
            f6Var.f11045a0.d(f6Var.f11047b0);
            f6Var.W = false;
            e();
        }
        u3 u3Var = f6Var.f11045a0;
        boolean z11 = this.f11503b0;
        p01 p01Var2 = this.f11519k;
        if (!z11) {
            boolean z12 = f6Var.f11055i;
            p01 p01Var3 = this.f11514h;
            if (z12) {
                this.U &= -1073741825;
                if (!this.f11505c0) {
                    p2Var.c(p01Var3.f15225a, 0, 1);
                    this.Y++;
                    byte b10 = p01Var3.f15225a[0];
                    if ((b10 & 128) == 128) {
                        throw zzat.zzb("Extension bit is set in signal byte", null);
                    }
                    this.f11511f0 = b10;
                    this.f11505c0 = true;
                }
                byte b11 = this.f11511f0;
                if ((b11 & 1) == 1) {
                    int i15 = b11 & 2;
                    this.U |= 1073741824;
                    if (!this.f11513g0) {
                        p01 p01Var4 = this.f11521m;
                        p2Var.c(p01Var4.f15225a, 0, 8);
                        this.Y += 8;
                        this.f11513g0 = true;
                        p01Var3.f15225a[0] = (byte) ((i15 != 2 ? 0 : 128) | 8);
                        p01Var3.C(0);
                        u3Var.b(p01Var3, 1, 1);
                        this.Z++;
                        p01Var4.C(0);
                        u3Var.b(p01Var4, 8, 1);
                        this.Z += 8;
                    }
                    if (i15 == 2) {
                        if (!this.f11507d0) {
                            p2Var.c(p01Var3.f15225a, 0, 1);
                            this.Y++;
                            p01Var3.C(0);
                            this.f11509e0 = p01Var3.I();
                            this.f11507d0 = true;
                        }
                        int i16 = this.f11509e0 * 4;
                        p01Var3.v(i16);
                        p2Var.c(p01Var3.f15225a, 0, i16);
                        this.Y += i16;
                        int i17 = (this.f11509e0 >> 1) + 1;
                        int i18 = (i17 * 6) + 2;
                        ByteBuffer byteBuffer = this.f11524p;
                        if (byteBuffer == null || byteBuffer.capacity() < i18) {
                            this.f11524p = ByteBuffer.allocate(i18);
                        }
                        this.f11524p.position(0);
                        this.f11524p.putShort((short) i17);
                        int i19 = 0;
                        int i20 = 0;
                        while (true) {
                            i11 = this.f11509e0;
                            if (i19 >= i11) {
                                break;
                            }
                            int iH = p01Var3.h();
                            int i21 = iH - i20;
                            if (i19 % 2 == 0) {
                                this.f11524p.putShort((short) i21);
                            } else {
                                this.f11524p.putInt(i21);
                            }
                            i19++;
                            i20 = iH;
                        }
                        int i22 = (i10 - this.Y) - i20;
                        if ((i11 & 1) == 1) {
                            this.f11524p.putInt(i22);
                        } else {
                            this.f11524p.putShort((short) i22);
                            this.f11524p.putInt(0);
                        }
                        byte[] bArrArray = this.f11524p.array();
                        p01 p01Var5 = this.f11522n;
                        p01Var5.w(i18, bArrArray);
                        u3Var.b(p01Var5, i18, 1);
                        this.Z += i18;
                    }
                }
            } else {
                byte[] bArr2 = f6Var.f11056j;
                if (bArr2 != null) {
                    p01Var2.w(bArr2.length, bArr2);
                }
            }
            if (!"A_OPUS".equals(f6Var.f11048c) ? f6Var.f11053g > 0 : z10) {
                this.U |= 268435456;
                this.f11523o.v(0);
                int i23 = (p01Var2.f15227c + i10) - this.Y;
                p01Var3.v(4);
                byte[] bArr3 = p01Var3.f15225a;
                bArr3[0] = (byte) ((i23 >> 24) & 255);
                bArr3[1] = (byte) ((i23 >> 16) & 255);
                bArr3[2] = (byte) ((i23 >> 8) & 255);
                bArr3[3] = (byte) (i23 & 255);
                u3Var.b(p01Var3, 4, 2);
                this.Z += 4;
            }
            this.f11503b0 = true;
        }
        int i24 = i10 + p01Var2.f15227c;
        String str2 = f6Var.f11048c;
        if (!"V_MPEG4/ISO/AVC".equals(str2) && !"V_MPEGH/ISO/HEVC".equals(str2)) {
            if (f6Var.V != null) {
                ih1.b1(p01Var2.f15227c == 0);
                f6Var.V.a(p2Var);
            }
            while (true) {
                int i25 = this.Y;
                if (i25 >= i24) {
                    break;
                }
                int i26 = i24 - i25;
                int iY = p01Var2.y();
                if (iY > 0) {
                    iE2 = Math.min(i26, iY);
                    u3Var.a(p01Var2, iE2);
                } else {
                    iE2 = u3Var.e(p2Var, i26, false);
                }
                this.Y += iE2;
                this.Z += iE2;
            }
        } else {
            p01 p01Var6 = this.f11512g;
            byte[] bArr4 = p01Var6.f15225a;
            bArr4[0] = 0;
            bArr4[1] = 0;
            bArr4[2] = 0;
            int i27 = f6Var.f11049c0;
            int i28 = 4 - i27;
            while (this.Y < i24) {
                int i29 = this.f11501a0;
                if (i29 == 0) {
                    int iMin = Math.min(i27, p01Var2.y());
                    p2Var.c(bArr4, i28 + iMin, i27 - iMin);
                    if (iMin > 0) {
                        p01Var2.F(i28, iMin, bArr4);
                    }
                    this.Y += i27;
                    p01Var6.C(0);
                    this.f11501a0 = p01Var6.h();
                    p01 p01Var7 = this.f11510f;
                    p01Var7.C(0);
                    u3Var.a(p01Var7, 4);
                    this.Z += 4;
                } else {
                    int iY2 = p01Var2.y();
                    if (iY2 > 0) {
                        iE = Math.min(i29, iY2);
                        u3Var.a(p01Var2, iE);
                    } else {
                        iE = u3Var.e(p2Var, i29, false);
                    }
                    this.Y += iE;
                    this.Z += iE;
                    this.f11501a0 -= iE;
                }
            }
        }
        if ("A_VORBIS".equals(f6Var.f11048c)) {
            p01 p01Var8 = this.f11516i;
            p01Var8.C(0);
            u3Var.a(p01Var8, 4);
            this.Z += 4;
        }
        int i30 = this.Z;
        q();
        return i30;
    }

    public final void q() {
        this.Y = 0;
        this.Z = 0;
        this.f11501a0 = 0;
        this.f11503b0 = false;
        this.f11505c0 = false;
        this.f11507d0 = false;
        this.f11509e0 = 0;
        this.f11511f0 = (byte) 0;
        this.f11513g0 = false;
        this.f11519k.v(0);
    }

    public final void r(p2 p2Var, byte[] bArr, int i10) {
        int length = bArr.length;
        int i11 = length + i10;
        p01 p01Var = this.f11520l;
        byte[] bArr2 = p01Var.f15225a;
        if (bArr2.length < i11) {
            byte[] bArrCopyOf = Arrays.copyOf(bArr, i11 + i10);
            p01Var.w(bArrCopyOf.length, bArrCopyOf);
        } else {
            System.arraycopy(bArr, 0, bArr2, 0, length);
        }
        p2Var.c(p01Var.f15225a, length, i10);
        p01Var.C(0);
        p01Var.A(i11);
    }

    public final long t(long j10) throws zzat {
        long j11 = this.f11527s;
        if (j11 != -9223372036854775807L) {
            return bb1.r(j10, j11, 1000L, RoundingMode.DOWN);
        }
        throw zzat.zzb("Can't scale timecode prior to timecodeScale being set.", null);
    }

    @Override // com.google.android.gms.internal.ads.o2
    public final void zzf() {
    }

    public g6(b6 b6Var, int i10, va2 va2Var) {
        this.f11526r = -1L;
        this.f11527s = -9223372036854775807L;
        this.f11528t = -9223372036854775807L;
        this.f11529u = -9223372036854775807L;
        this.C = -9223372036854775807L;
        this.D = -1;
        this.E = -1L;
        this.F = -1L;
        this.G = -1;
        this.I = -1L;
        this.J = -1L;
        this.K = -9223372036854775807L;
        this.f11517i0 = b6Var;
        b6Var.f9406d = new c6(this);
        this.f11508e = va2Var;
        this.A = new SparseArray();
        this.f11504c = 1 == ((i10 & 1) ^ 1);
        this.f11506d = (i10 & 2) == 0;
        this.f11500a = new i6();
        this.f11502b = new SparseArray();
        this.f11514h = new p01(4);
        this.f11516i = new p01(ByteBuffer.allocate(4).putInt(-1).array());
        this.f11518j = new p01(4);
        this.f11510f = new p01(qo1.f15833a);
        this.f11512g = new p01(4);
        this.f11519k = new p01();
        this.f11520l = new p01();
        this.f11521m = new p01(8);
        this.f11522n = new p01();
        this.f11523o = new p01();
        this.R = new int[1];
        this.f11531w = true;
    }
}
