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

import androidx.media3.common.MimeTypes;
import java.util.ArrayList;
import java.util.Arrays;

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final boolean[] f15321f = new boolean[3];

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final wa f15317b = new wa(7);

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final wa f15318c = new wa(8);

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final wa f15319d = new wa(6);

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

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public final p01 f15328m = new p01();

    public pa(eb ebVar) {
        this.f15316a = ebVar;
    }

    @Override // com.google.android.gms.internal.ads.ja
    public final void a(q2 q2Var, x2.o0 o0Var) {
        o0Var.d();
        o0Var.e();
        this.f15322g = o0Var.f34561e;
        o0Var.e();
        u3 u3VarE = q2Var.e(o0Var.f34560d, 2);
        this.f15323h = u3VarE;
        this.f15324i = new oa(u3VarE);
        this.f15316a.b(q2Var, o0Var);
    }

    @Override // com.google.android.gms.internal.ads.ja
    public final void b(boolean z10) {
        this.f15323h.getClass();
        String str = bb1.f9474a;
        if (z10) {
            ((dq1) this.f15316a.f10744e).c(0);
            f(0, 0, this.f15320e, this.f15326k);
            e(9, this.f15320e, this.f15326k);
            f(0, 0, this.f15320e, this.f15326k);
        }
    }

    @Override // com.google.android.gms.internal.ads.ja
    public final void c(int i10, long j10) {
        this.f15326k = j10;
        int i11 = i10 & 2;
        this.f15327l = (i11 != 0) | this.f15327l;
    }

    /* JADX WARN: Removed duplicated region for block: B:10:0x0044  */
    @Override // com.google.android.gms.internal.ads.ja
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void d(p01 p01Var) {
        wa waVar;
        wa waVar2;
        wa waVar3;
        int i10;
        int i11;
        this.f15323h.getClass();
        String str = bb1.f9474a;
        int i12 = p01Var.f15226b;
        int i13 = p01Var.f15227c;
        byte[] bArr = p01Var.f15225a;
        this.f15320e += (long) p01Var.y();
        this.f15323h.a(p01Var, p01Var.y());
        while (true) {
            int iG = qo1.g(bArr, i12, i13, this.f15321f);
            waVar = this.f15319d;
            waVar2 = this.f15318c;
            waVar3 = this.f15317b;
            if (iG == i13) {
                break;
            }
            int i14 = bArr[iG + 3] & 31;
            if (iG > 0) {
                int i15 = iG - 1;
                if (bArr[i15] == 0) {
                    i11 = 4;
                    i10 = i15;
                } else {
                    i10 = iG;
                    i11 = 3;
                }
            }
            int i16 = i10 - i12;
            if (i16 > 0) {
                if (!this.f15325j) {
                    waVar3.c(i12, i10, bArr);
                    waVar2.c(i12, i10, bArr);
                }
                waVar.c(i12, i10, bArr);
            }
            int i17 = i13 - i10;
            long j10 = this.f15320e - ((long) i17);
            f(i17, i16 < 0 ? -i16 : 0, j10, this.f15326k);
            e(i14, j10, this.f15326k);
            i12 = i10 + i11;
        }
        if (!this.f15325j) {
            waVar3.c(i12, i13, bArr);
            waVar2.c(i12, i13, bArr);
        }
        waVar.c(i12, i13, bArr);
    }

    public final void e(int i10, long j10, long j11) {
        if (!this.f15325j) {
            this.f15317b.b(i10);
            this.f15318c.b(i10);
        }
        this.f15319d.b(i10);
        oa oaVar = this.f15324i;
        boolean z10 = this.f15327l;
        oaVar.f14969d = i10;
        oaVar.f14971f = j11;
        oaVar.f14970e = j10;
        oaVar.f14976k = z10;
    }

    /* 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)
     */
    public final void f(int i10, int i11, long j10, long j11) {
        boolean z10 = this.f15325j;
        boolean z11 = true;
        eb ebVar = this.f15316a;
        if (!z10) {
            wa waVar = this.f15317b;
            waVar.d(i11);
            wa waVar2 = this.f15318c;
            waVar2.d(i11);
            if (this.f15325j) {
                if (waVar.f17968c) {
                    mo1 mo1VarE = qo1.e(4, waVar.f17970e, waVar.f17969d);
                    ebVar.j(mo1VarE.f14321m);
                    this.f15324i.f14967b.append(mo1VarE.f14312d, mo1VarE);
                    waVar.a();
                } else if (waVar2.f17968c) {
                    byte[] bArr = waVar2.f17969d;
                    int i12 = waVar2.f17970e;
                    byte[] bArr2 = qo1.f15833a;
                    ap1 ap1Var = new ap1(bArr, 4, i12);
                    int i13 = ap1Var.i();
                    ap1Var.i();
                    ap1Var.a();
                    ap1Var.e();
                    l8.k kVar = new l8.k(i13, (Object) null);
                    this.f15324i.f14968c.append(kVar.f30185b, kVar);
                    waVar2.a();
                }
            } else if (waVar.f17968c && waVar2.f17968c) {
                ArrayList arrayList = new ArrayList();
                arrayList.add(Arrays.copyOf(waVar.f17969d, waVar.f17970e));
                arrayList.add(Arrays.copyOf(waVar2.f17969d, waVar2.f17970e));
                mo1 mo1VarE2 = qo1.e(4, waVar.f17970e, waVar.f17969d);
                ap1 ap1Var2 = new ap1(waVar2.f17969d, 4, waVar2.f17970e);
                int i14 = ap1Var2.i();
                ap1Var2.i();
                ap1Var2.a();
                ap1Var2.e();
                l8.k kVar2 = new l8.k(i14, (Object) null);
                byte[] bArr3 = km0.f13311a;
                String str = String.format("avc1.%02X%02X%02X", Integer.valueOf(mo1VarE2.f14309a), Integer.valueOf(mo1VarE2.f14310b), Integer.valueOf(mo1VarE2.f14311c));
                u3 u3Var = this.f15323h;
                sm2 sm2Var = new sm2();
                sm2Var.zza(this.f15322g);
                sm2Var.zzl(MimeTypes.VIDEO_MP2T);
                sm2Var.zzm(MimeTypes.VIDEO_H264);
                sm2Var.zzj(str);
                sm2Var.f16487j = mo1VarE2.f14313e;
                sm2Var.f16488k = mo1VarE2.f14314f;
                fv1 fv1Var = new fv1();
                fv1Var.f11401a = mo1VarE2.f14318j;
                fv1Var.f11402b = mo1VarE2.f14319k;
                fv1Var.f11403c = mo1VarE2.f14320l;
                fv1Var.f11404d = mo1VarE2.f14316h + 8;
                fv1Var.f11405e = mo1VarE2.f14317i + 8;
                sm2Var.zzC(fv1Var.a());
                sm2Var.f16493p = mo1VarE2.f14315g;
                sm2Var.zzp(arrayList);
                int i15 = mo1VarE2.f14321m;
                sm2Var.f16484g = i15;
                u3Var.d(new zn2(sm2Var));
                this.f15325j = true;
                ebVar.j(i15);
                this.f15324i.f14967b.append(mo1VarE2.f14312d, mo1VarE2);
                this.f15324i.f14968c.append(kVar2.f30185b, kVar2);
                waVar.a();
                waVar2.a();
            }
        }
        wa waVar3 = this.f15319d;
        if (waVar3.d(i11)) {
            int iA = qo1.a(waVar3.f17970e, waVar3.f17969d);
            byte[] bArr4 = waVar3.f17969d;
            p01 p01Var = this.f15328m;
            p01Var.w(iA, bArr4);
            p01Var.C(4);
            ((dq1) ebVar.f10744e).b(j11, p01Var);
        }
        oa oaVar = this.f15324i;
        boolean z12 = this.f15325j;
        if (oaVar.f14969d == 9) {
            if (z12 && oaVar.f14972g) {
                long j12 = oaVar.f14970e;
                int i16 = i10 + ((int) (j10 - j12));
                long j13 = oaVar.f14974i;
                if (j13 != -9223372036854775807L) {
                    long j14 = oaVar.f14973h;
                    if (j12 != j14) {
                        oaVar.f14966a.zze(j13, oaVar.f14975j ? 1 : 0, (int) (j12 - j14), i16, null);
                    }
                }
            }
            oaVar.f14973h = oaVar.f14970e;
            oaVar.f14974i = oaVar.f14971f;
            oaVar.f14975j = false;
            oaVar.f14972g = true;
        }
        boolean z13 = oaVar.f14976k;
        boolean z14 = oaVar.f14975j;
        int i17 = oaVar.f14969d;
        if (i17 != 5 && (!z13 || i17 != 1)) {
            z11 = false;
        }
        boolean z15 = z14 | z11;
        oaVar.f14975j = z15;
        oaVar.f14969d = 24;
        if (z15) {
            this.f15327l = false;
        }
    }

    @Override // com.google.android.gms.internal.ads.ja
    public final void zza() {
        this.f15320e = 0L;
        this.f15327l = false;
        this.f15326k = -9223372036854775807L;
        qo1.h(this.f15321f);
        this.f15317b.a();
        this.f15318c.a();
        this.f15319d.a();
        ((dq1) this.f15316a.f10744e).c(0);
        oa oaVar = this.f15324i;
        if (oaVar != null) {
            oaVar.f14972g = false;
        }
    }
}
