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

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

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

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final String f16065b = MimeTypes.VIDEO_MP2T;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final androidx.media3.extractor.b1 f16067d;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    @Nullable
    private final String zza;

    @Nullable
    private String zzw;

    public ra(@Nullable String str, int i10, String str2) {
        this.zza = str;
        this.f16064a = i10;
        p01 p01Var = new p01(1024);
        this.f16066c = p01Var;
        byte[] bArr = p01Var.f15225a;
        this.f16067d = new androidx.media3.extractor.b1(bArr, bArr.length);
        this.f16075l = -9223372036854775807L;
    }

    @Override // com.google.android.gms.internal.ads.ja
    public final void a(q2 q2Var, x2.o0 o0Var) {
        o0Var.d();
        o0Var.e();
        this.f16068e = q2Var.e(o0Var.f34560d, 1);
        o0Var.e();
        this.f16069f = o0Var.f34561e;
    }

    @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.f16075l = j10;
    }

    @Override // com.google.android.gms.internal.ads.ja
    public final void d(p01 p01Var) throws zzat {
        int iP;
        int i10;
        int iP2;
        boolean zO;
        int i11;
        this.f16068e.getClass();
        while (p01Var.y() > 0) {
            int i12 = this.f16071h;
            if (i12 != 0) {
                if (i12 != 1) {
                    androidx.media3.extractor.b1 b1Var = this.f16067d;
                    p01 p01Var2 = this.f16066c;
                    if (i12 != 2) {
                        int iMin = Math.min(p01Var.y(), this.f16073j - this.f16072i);
                        p01Var.F(this.f16072i, iMin, (byte[]) b1Var.f3327b);
                        int i13 = this.f16072i + iMin;
                        this.f16072i = i13;
                        if (i13 == this.f16073j) {
                            b1Var.l(0);
                            if (b1Var.o()) {
                                if (this.f16076m) {
                                }
                                this.f16071h = 0;
                            } else {
                                this.f16076m = true;
                                int iP3 = b1Var.p(1);
                                if (iP3 == 1) {
                                    iP2 = b1Var.p(1);
                                    i10 = 1;
                                } else {
                                    i10 = iP3;
                                    iP2 = 0;
                                }
                                this.f16077n = iP2;
                                if (iP2 != 0) {
                                    throw zzat.zzb(null, null);
                                }
                                if (i10 == 1) {
                                    b1Var.p((b1Var.p(2) + 1) * 8);
                                    i10 = 1;
                                }
                                if (!b1Var.o()) {
                                    throw zzat.zzb(null, null);
                                }
                                this.f16078o = b1Var.p(6);
                                int iP4 = b1Var.p(4);
                                int iP5 = b1Var.p(3);
                                if (iP4 != 0 || iP5 != 0) {
                                    throw zzat.zzb(null, null);
                                }
                                if (i10 == 0) {
                                    int iJ = b1Var.j();
                                    int iH = b1Var.h();
                                    l2.h hVarQ = ni.q(b1Var, true);
                                    this.zzw = (String) hVarQ.f29998d;
                                    this.f16082s = hVarQ.f29996b;
                                    this.f16084u = hVarQ.f29997c;
                                    int iH2 = iH - b1Var.h();
                                    b1Var.l(iJ);
                                    byte[] bArr = new byte[(iH2 + 7) / 8];
                                    b1Var.r(bArr, iH2);
                                    sm2 sm2Var = new sm2();
                                    sm2Var.zza(this.f16069f);
                                    sm2Var.zzl(this.f16065b);
                                    sm2Var.zzm(MimeTypes.AUDIO_AAC);
                                    sm2Var.zzj(this.zzw);
                                    sm2Var.f16496s = this.f16084u;
                                    sm2Var.f16497t = this.f16082s;
                                    sm2Var.zzp(Collections.singletonList(bArr));
                                    sm2Var.zze(this.zza);
                                    sm2Var.f16480c = this.f16064a;
                                    zn2 zn2Var = new zn2(sm2Var);
                                    if (!zn2Var.equals(this.f16070g)) {
                                        this.f16070g = zn2Var;
                                        this.f16083t = 1024000000 / ((long) zn2Var.f19349v);
                                        this.f16068e.d(zn2Var);
                                    }
                                } else {
                                    int iH3 = b1Var.h();
                                    l2.h hVarQ2 = ni.q(b1Var, true);
                                    this.zzw = (String) hVarQ2.f29998d;
                                    this.f16082s = hVarQ2.f29996b;
                                    this.f16084u = hVarQ2.f29997c;
                                    b1Var.n(b1Var.p((b1Var.p(2) + 1) * 8) - (iH3 - b1Var.h()));
                                }
                                int iP6 = b1Var.p(3);
                                this.f16079p = iP6;
                                if (iP6 == 0) {
                                    b1Var.n(8);
                                } else if (iP6 == 1) {
                                    b1Var.n(9);
                                } else if (iP6 == 3 || iP6 == 4 || iP6 == 5) {
                                    b1Var.n(6);
                                } else {
                                    if (iP6 != 6 && iP6 != 7) {
                                        throw new IllegalStateException();
                                    }
                                    b1Var.n(1);
                                }
                                boolean zO2 = b1Var.o();
                                this.f16080q = zO2;
                                this.f16081r = 0L;
                                if (zO2) {
                                    if (i10 != 1) {
                                        do {
                                            zO = b1Var.o();
                                            this.f16081r = (this.f16081r << 8) + ((long) b1Var.p(8));
                                        } while (zO);
                                    } else {
                                        this.f16081r = b1Var.p((b1Var.p(2) + 1) * 8);
                                    }
                                }
                                if (b1Var.o()) {
                                    b1Var.n(8);
                                }
                            }
                            if (this.f16077n != 0) {
                                throw zzat.zzb(null, null);
                            }
                            if (this.f16078o != 0) {
                                throw zzat.zzb(null, null);
                            }
                            if (this.f16079p != 0) {
                                throw zzat.zzb(null, null);
                            }
                            int i14 = 0;
                            do {
                                iP = b1Var.p(8);
                                i14 += iP;
                            } while (iP == 255);
                            int iJ2 = b1Var.j();
                            if ((iJ2 & 7) == 0) {
                                p01Var2.C(iJ2 >> 3);
                            } else {
                                b1Var.r(p01Var2.f15225a, i14 * 8);
                                p01Var2.C(0);
                            }
                            this.f16068e.a(p01Var2, i14);
                            ih1.b1(this.f16075l != -9223372036854775807L);
                            this.f16068e.zze(this.f16075l, 1, i14, 0, null);
                            this.f16075l += this.f16083t;
                            if (this.f16080q) {
                                b1Var.n((int) this.f16081r);
                            }
                            this.f16071h = 0;
                        } else {
                            continue;
                        }
                    } else {
                        int I = ((this.f16074k & (-225)) << 8) | p01Var.I();
                        this.f16073j = I;
                        if (I > p01Var2.f15225a.length) {
                            p01Var2.v(I);
                            byte[] bArr2 = p01Var2.f15225a;
                            int length = bArr2.length;
                            b1Var.f3327b = bArr2;
                            i11 = 0;
                            b1Var.f3328c = 0;
                            b1Var.f3329d = 0;
                            b1Var.f3330e = length;
                        } else {
                            i11 = 0;
                        }
                        this.f16072i = i11;
                        this.f16071h = 3;
                    }
                } else {
                    int I2 = p01Var.I();
                    if ((I2 & 224) == 224) {
                        this.f16074k = I2;
                        this.f16071h = 2;
                    } else if (I2 != 86) {
                        this.f16071h = 0;
                    }
                }
            } else if (p01Var.I() == 86) {
                this.f16071h = 1;
            }
        }
    }

    @Override // com.google.android.gms.internal.ads.ja
    public final void zza() {
        this.f16071h = 0;
        this.f16075l = -9223372036854775807L;
        this.f16076m = false;
    }
}
