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

import androidx.annotation.Nullable;
import androidx.media3.common.MimeTypes;
import java.util.Arrays;
import java.util.Collections;

/* JADX INFO: loaded from: classes2.dex */
public final class ga implements ja {

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public static final byte[] f11641w = {73, 68, 51};

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

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public String f11647f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public u3 f11648g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public u3 f11649h;

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

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

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

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

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

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

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

    @Nullable
    private final String zze;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final androidx.media3.extractor.b1 f11643b = new androidx.media3.extractor.b1(new byte[7], 7);

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final p01 f11644c = new p01(Arrays.copyOf(f11641w, 10));

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public int f11655n = -1;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public int f11656o = -1;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public long f11659r = -9223372036854775807L;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public long f11661t = -9223372036854775807L;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public int f11650i = 0;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public int f11651j = 0;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public int f11652k = 256;

    public ga(boolean z10, @Nullable String str, int i10, String str2) {
        this.f11642a = z10;
        this.zze = str;
        this.f11645d = i10;
        this.f11646e = str2;
    }

    @Override // com.google.android.gms.internal.ads.ja
    public final void a(q2 q2Var, x2.o0 o0Var) {
        o0Var.d();
        o0Var.e();
        this.f11647f = o0Var.f34561e;
        o0Var.e();
        u3 u3VarE = q2Var.e(o0Var.f34560d, 1);
        this.f11648g = u3VarE;
        this.f11662u = u3VarE;
        if (!this.f11642a) {
            this.f11649h = new m2();
            return;
        }
        o0Var.d();
        o0Var.e();
        u3 u3VarE2 = q2Var.e(o0Var.f34560d, 5);
        this.f11649h = u3VarE2;
        sm2 sm2Var = new sm2();
        o0Var.e();
        sm2Var.zza(o0Var.f34561e);
        sm2Var.zzl(this.f11646e);
        sm2Var.zzm(MimeTypes.APPLICATION_ID3);
        u3VarE2.d(new zn2(sm2Var));
    }

    @Override // com.google.android.gms.internal.ads.ja
    public final void b(boolean z10) {
    }

    @Override // com.google.android.gms.internal.ads.ja
    public final void c(int i10, long j10) {
        this.f11661t = j10;
    }

    /* JADX WARN: Code restructure failed: missing block: B:105:0x02a2, code lost:
    
        r20.f11657p = (r6 & 8) >> 3;
     */
    /* JADX WARN: Code restructure failed: missing block: B:106:0x02ac, code lost:
    
        if (1 == (!(r6 & 1))) goto L108;
     */
    /* JADX WARN: Code restructure failed: missing block: B:107:0x02ae, code lost:
    
        r2 = false;
     */
    /* JADX WARN: Code restructure failed: missing block: B:108:0x02b0, code lost:
    
        r2 = true;
     */
    /* JADX WARN: Code restructure failed: missing block: B:109:0x02b1, code lost:
    
        r20.f11653l = r2;
     */
    /* JADX WARN: Code restructure failed: missing block: B:110:0x02b5, code lost:
    
        if (r20.f11654m != false) goto L112;
     */
    /* JADX WARN: Code restructure failed: missing block: B:111:0x02b7, code lost:
    
        r20.f11650i = 1;
        r20.f11651j = 0;
     */
    /* JADX WARN: Code restructure failed: missing block: B:112:0x02bd, code lost:
    
        r20.f11650i = 3;
        r20.f11651j = 0;
     */
    /* JADX WARN: Code restructure failed: missing block: B:113:0x02c3, code lost:
    
        r21.C(r5);
     */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:117:0x02d3  */
    /* JADX WARN: Removed duplicated region for block: B:175:0x0318 A[SYNTHETIC] */
    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$PrimitiveArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    @Override // com.google.android.gms.internal.ads.ja
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void d(p01 p01Var) throws zzat {
        byte b10;
        int i10;
        int i11;
        char c6;
        char c10;
        char c11;
        int i12;
        int i13;
        int i14;
        int i15;
        int i16;
        this.f11648g.getClass();
        String str = bb1.f9474a;
        while (p01Var.y() > 0) {
            int i17 = this.f11650i;
            byte b11 = -1;
            int i18 = 4;
            int i19 = 1;
            int i20 = 0;
            p01 p01Var2 = this.f11644c;
            androidx.media3.extractor.b1 b1Var = this.f11643b;
            if (i17 == 0) {
                byte[] bArr = p01Var.f15225a;
                int i21 = p01Var.f15226b;
                int i22 = p01Var.f15227c;
                while (true) {
                    if (i21 >= i22) {
                        p01Var.C(i21);
                        break;
                    }
                    int i23 = i21 + 1;
                    byte b12 = bArr[i21];
                    int i24 = b12 & 255;
                    if (this.f11652k != 512 || (((((byte) i24) & 255 ? 1 : 0) | 65280 ? 1 : 0) & 65526) != 65520) {
                        b10 = b11;
                    } else {
                        if (this.f11654m) {
                            break;
                        }
                        int i25 = i21 - 1;
                        p01Var.C(i21);
                        byte[] bArr2 = (byte[]) b1Var.f3327b;
                        if (p01Var.y() < i19) {
                            i10 = i19;
                        } else {
                            p01Var.F(i20, i19, bArr2);
                            b1Var.l(i18);
                            int iP = b1Var.p(i19);
                            int i26 = this.f11655n;
                            if (i26 == -1 || iP == i26) {
                                if (this.f11656o != -1) {
                                    byte[] bArr3 = (byte[]) b1Var.f3327b;
                                    if (p01Var.y() < i19) {
                                        break;
                                    }
                                    p01Var.F(i20, i19, bArr3);
                                    b1Var.l(2);
                                    i14 = 4;
                                    if (b1Var.p(4) == this.f11656o) {
                                        p01Var.C(i23);
                                    } else {
                                        i10 = 1;
                                    }
                                } else {
                                    i14 = 4;
                                }
                                byte[] bArr4 = (byte[]) b1Var.f3327b;
                                if (p01Var.y() < i14) {
                                    break;
                                }
                                p01Var.F(i20, i14, bArr4);
                                b1Var.l(14);
                                int iP2 = b1Var.p(13);
                                if (iP2 >= 7) {
                                    byte[] bArr5 = p01Var.f15225a;
                                    int i27 = p01Var.f15227c;
                                    int i28 = i25 + iP2;
                                    if (i28 >= i27) {
                                        break;
                                    }
                                    byte b13 = bArr5[i28];
                                    b10 = -1;
                                    if (b13 != -1) {
                                        if (b13 == 73 && ((i15 = i28 + 1) == i27 || (bArr5[i15] == 68 && ((i16 = i28 + 2) == i27 || bArr5[i16] == 51)))) {
                                            break;
                                        }
                                    } else {
                                        int i29 = i28 + 1;
                                        if (i29 == i27) {
                                            break;
                                        }
                                        byte b14 = bArr5[i29];
                                        if ((((b14 & 255 ? 1 : 0) | 65280 ? 1 : 0) & 65526) == 65520 && ((b14 & 8) >> 3) == iP) {
                                            break;
                                        }
                                    }
                                } else {
                                    b10 = -1;
                                }
                                i10 = 1;
                                int i30 = this.f11652k;
                                i11 = i30 | i24;
                                if (i11 == 329) {
                                    c6 = 2;
                                    c10 = 256;
                                    c11 = 3;
                                    i12 = 0;
                                    i13 = 768;
                                } else if (i11 == 511) {
                                    c6 = 2;
                                    c10 = 256;
                                    c11 = 3;
                                    i12 = 0;
                                    i13 = 512;
                                } else if (i11 == 836) {
                                    c6 = 2;
                                    c10 = 256;
                                    c11 = 3;
                                    i12 = 0;
                                    i13 = 1024;
                                } else {
                                    if (i11 == 1075) {
                                        this.f11650i = 2;
                                        this.f11651j = 3;
                                        this.f11660s = 0;
                                        p01Var2.C(0);
                                        p01Var.C(i23);
                                        break;
                                    }
                                    c10 = 256;
                                    if (i30 != 256) {
                                        this.f11652k = 256;
                                        i19 = i10;
                                        b11 = b10;
                                        i18 = 4;
                                        i20 = 0;
                                    } else {
                                        c6 = 2;
                                        c11 = 3;
                                        i12 = 0;
                                        i21 = i23;
                                        i18 = 4;
                                        int i31 = i12;
                                        i19 = i10;
                                        b11 = b10;
                                        i20 = i31;
                                    }
                                }
                                this.f11652k = i13;
                                i21 = i23;
                                i18 = 4;
                                int i312 = i12;
                                i19 = i10;
                                b11 = b10;
                                i20 = i312;
                            } else {
                                b10 = -1;
                            }
                        }
                        b10 = -1;
                        int i302 = this.f11652k;
                        i11 = i302 | i24;
                        if (i11 == 329) {
                        }
                        this.f11652k = i13;
                        i21 = i23;
                        i18 = 4;
                        int i3122 = i12;
                        i19 = i10;
                        b11 = b10;
                        i20 = i3122;
                    }
                    i10 = i19;
                    int i3022 = this.f11652k;
                    i11 = i3022 | i24;
                    if (i11 == 329) {
                    }
                    this.f11652k = i13;
                    i21 = i23;
                    i18 = 4;
                    int i31222 = i12;
                    i19 = i10;
                    b11 = b10;
                    i20 = i31222;
                }
            } else if (i17 != 1) {
                if (i17 == 2) {
                    byte[] bArr6 = p01Var2.f15225a;
                    int iMin = Math.min(p01Var.y(), 10 - this.f11651j);
                    p01Var.F(this.f11651j, iMin, bArr6);
                    int i32 = this.f11651j + iMin;
                    this.f11651j = i32;
                    if (i32 == 10) {
                        this.f11649h.a(p01Var2, 10);
                        p01Var2.C(6);
                        u3 u3Var = this.f11649h;
                        int iG = p01Var2.g() + 10;
                        this.f11650i = 4;
                        this.f11651j = 10;
                        this.f11662u = u3Var;
                        this.f11663v = 0L;
                        this.f11660s = iG;
                    }
                } else if (i17 != 3) {
                    int iMin2 = Math.min(p01Var.y(), this.f11660s - this.f11651j);
                    this.f11662u.a(p01Var, iMin2);
                    int i33 = this.f11651j + iMin2;
                    this.f11651j = i33;
                    if (i33 == this.f11660s) {
                        ih1.b1(this.f11661t != -9223372036854775807L);
                        this.f11662u.zze(this.f11661t, 1, this.f11660s, 0, null);
                        this.f11661t += this.f11663v;
                        this.f11650i = 0;
                        this.f11651j = 0;
                        this.f11652k = 256;
                    }
                } else {
                    int i34 = true != this.f11653l ? 5 : 7;
                    byte[] bArr7 = (byte[]) b1Var.f3327b;
                    int iMin3 = Math.min(p01Var.y(), i34 - this.f11651j);
                    p01Var.F(this.f11651j, iMin3, bArr7);
                    int i35 = this.f11651j + iMin3;
                    this.f11651j = i35;
                    if (i35 == i34) {
                        b1Var.l(0);
                        if (this.f11658q) {
                            b1Var.n(10);
                        } else {
                            int iP3 = b1Var.p(2) + 1;
                            if (iP3 != 2) {
                                StringBuilder sb = new StringBuilder(String.valueOf(iP3).length() + 50);
                                sb.append("Detected audio object type: ");
                                sb.append(iP3);
                                sb.append(", but assuming AAC LC.");
                                vt0.c(sb.toString());
                            }
                            b1Var.n(5);
                            int iP4 = b1Var.p(3);
                            int i36 = this.f11656o;
                            byte[] bArr8 = {(byte) (((i36 >> 1) & 7) | 16), (byte) (((iP4 << 3) & 120) | ((i36 << 7) & 128))};
                            l2.h hVarQ = ni.q(new androidx.media3.extractor.b1(bArr8, 2), false);
                            sm2 sm2Var = new sm2();
                            sm2Var.zza(this.f11647f);
                            sm2Var.zzl(this.f11646e);
                            sm2Var.zzm(MimeTypes.AUDIO_AAC);
                            sm2Var.zzj((String) hVarQ.f29998d);
                            sm2Var.f16496s = hVarQ.f29997c;
                            sm2Var.f16497t = hVarQ.f29996b;
                            sm2Var.zzp(Collections.singletonList(bArr8));
                            sm2Var.zze(this.zze);
                            sm2Var.f16480c = this.f11645d;
                            zn2 zn2Var = new zn2(sm2Var);
                            this.f11659r = 1024000000 / ((long) zn2Var.f19349v);
                            this.f11648g.d(zn2Var);
                            this.f11658q = true;
                        }
                        b1Var.n(4);
                        int iP5 = b1Var.p(13);
                        int i37 = iP5 - 7;
                        if (this.f11653l) {
                            i37 = iP5 - 9;
                        }
                        u3 u3Var2 = this.f11648g;
                        long j10 = this.f11659r;
                        this.f11650i = 4;
                        this.f11651j = 0;
                        this.f11662u = u3Var2;
                        this.f11663v = j10;
                        this.f11660s = i37;
                    }
                }
            } else if (p01Var.y() != 0) {
                ((byte[]) b1Var.f3327b)[0] = p01Var.f15225a[p01Var.f15226b];
                b1Var.l(2);
                int iP6 = b1Var.p(4);
                int i38 = this.f11656o;
                if (i38 == -1 || iP6 == i38) {
                    if (!this.f11654m) {
                        this.f11654m = true;
                        this.f11655n = this.f11657p;
                        this.f11656o = iP6;
                    }
                    this.f11650i = 3;
                    this.f11651j = 0;
                } else {
                    this.f11654m = false;
                    this.f11650i = 0;
                    this.f11651j = 0;
                    this.f11652k = 256;
                }
            }
        }
    }

    @Override // com.google.android.gms.internal.ads.ja
    public final void zza() {
        this.f11661t = -9223372036854775807L;
        this.f11654m = false;
        this.f11650i = 0;
        this.f11651j = 0;
        this.f11652k = 256;
    }
}
