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

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

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

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

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

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public x2.s f15646d;

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

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final wa f15649g = new wa(32);

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final wa f15650h = new wa(33);

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public final wa f15651i = new wa(34);

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final wa f15652j = new wa(39);

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final wa f15653k = new wa(40);

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

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

    public qa(eb ebVar) {
        this.f15643a = ebVar;
    }

    @Override // com.google.android.gms.internal.ads.ja
    public final void a(q2 q2Var, x2.o0 o0Var) {
        o0Var.d();
        o0Var.e();
        this.f15644b = o0Var.f34561e;
        o0Var.e();
        u3 u3VarE = q2Var.e(o0Var.f34560d, 2);
        this.f15645c = u3VarE;
        this.f15646d = new x2.s(u3VarE);
        this.f15643a.b(q2Var, o0Var);
    }

    @Override // com.google.android.gms.internal.ads.ja
    public final void b(boolean z10) {
        this.f15645c.getClass();
        String str = bb1.f9474a;
        if (z10) {
            ((dq1) this.f15643a.f10744e).c(0);
            g(0, 0, this.f15654l, this.f15655m);
            e(0, 48, this.f15654l, this.f15655m);
        }
    }

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

    /* JADX WARN: Removed duplicated region for block: B:14:0x0047  */
    @Override // com.google.android.gms.internal.ads.ja
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void d(p01 p01Var) {
        int i10;
        int i11;
        this.f15645c.getClass();
        String str = bb1.f9474a;
        while (p01Var.y() > 0) {
            int i12 = p01Var.f15226b;
            int i13 = p01Var.f15227c;
            byte[] bArr = p01Var.f15225a;
            this.f15654l += (long) p01Var.y();
            this.f15645c.a(p01Var, p01Var.y());
            while (i12 < i13) {
                int iG = qo1.g(bArr, i12, i13, this.f15648f);
                if (iG == i13) {
                    f(i12, i13, bArr);
                    return;
                }
                int i14 = bArr[iG + 3] & 126;
                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) {
                    f(i12, i10, bArr);
                }
                int i17 = i13 - i10;
                long j10 = this.f15654l - ((long) i17);
                g(i17, i16 < 0 ? -i16 : 0, j10, this.f15655m);
                e(i17, i14 >> 1, j10, this.f15655m);
                i12 = i10 + i11;
            }
        }
    }

    public final void e(int i10, int i11, long j10, long j11) {
        x2.s sVar = this.f15646d;
        boolean z10 = this.f15647e;
        sVar.f34619f = false;
        sVar.f34620g = false;
        sVar.f34617d = j11;
        sVar.f34616c = 0;
        sVar.f34614a = j10;
        if (i11 >= 32 && i11 != 40) {
            if (sVar.f34621h && !sVar.f34622i) {
                if (z10) {
                    sVar.b(i10);
                }
                sVar.f34621h = false;
            }
            if (i11 <= 35 || i11 == 39) {
                sVar.f34620g = !sVar.f34622i;
                sVar.f34622i = true;
            }
        }
        boolean z11 = i11 >= 16 && i11 <= 21;
        sVar.f34615b = z11;
        sVar.f34618e = z11 || i11 <= 9;
        if (!this.f15647e) {
            this.f15649g.b(i11);
            this.f15650h.b(i11);
            this.f15651i.b(i11);
        }
        this.f15652j.b(i11);
        this.f15653k.b(i11);
    }

    public final void f(int i10, int i11, byte[] bArr) {
        x2.s sVar = this.f15646d;
        if (sVar.f34618e) {
            int i12 = sVar.f34616c;
            int i13 = (i10 + 2) - i12;
            if (i13 < i11) {
                sVar.f34619f = (bArr[i13] & 128) != 0;
                sVar.f34618e = false;
            } else {
                sVar.f34616c = (i11 - i10) + i12;
            }
        }
        if (!this.f15647e) {
            this.f15649g.c(i10, i11, bArr);
            this.f15650h.c(i10, i11, bArr);
            this.f15651i.c(i10, i11, bArr);
        }
        this.f15652j.c(i10, i11, bArr);
        this.f15653k.c(i10, i11, bArr);
    }

    public final void g(int i10, int i11, long j10, long j11) {
        x2.s sVar = this.f15646d;
        boolean z10 = this.f15647e;
        if (sVar.f34622i && sVar.f34619f) {
            sVar.f34625l = sVar.f34615b;
            sVar.f34622i = false;
        } else if (sVar.f34620g || sVar.f34619f) {
            if (z10 && sVar.f34621h) {
                sVar.b(i10 + ((int) (j10 - sVar.f34614a)));
            }
            sVar.f34623j = sVar.f34614a;
            sVar.f34624k = sVar.f34617d;
            sVar.f34625l = sVar.f34615b;
            sVar.f34621h = true;
        }
        boolean z11 = this.f15647e;
        eb ebVar = this.f15643a;
        if (!z11) {
            wa waVar = this.f15649g;
            waVar.d(i11);
            wa waVar2 = this.f15650h;
            waVar2.d(i11);
            wa waVar3 = this.f15651i;
            waVar3.d(i11);
            if (waVar.f17968c && waVar2.f17968c && waVar3.f17968c) {
                String str = this.f15644b;
                int i12 = waVar.f17970e;
                byte[] bArr = new byte[waVar2.f17970e + i12 + waVar3.f17970e];
                System.arraycopy(waVar.f17969d, 0, bArr, 0, i12);
                System.arraycopy(waVar2.f17969d, 0, bArr, waVar.f17970e, waVar2.f17970e);
                System.arraycopy(waVar3.f17969d, 0, bArr, waVar.f17970e + waVar2.f17970e, waVar3.f17970e);
                String strA = null;
                mm1 mm1VarZzg = qo1.zzg(waVar2.f17969d, 3, waVar2.f17970e, null);
                yj1 yj1Var = mm1VarZzg.zzb;
                if (yj1Var != null) {
                    int i13 = yj1Var.f18857f;
                    int[] iArr = yj1Var.f18856e;
                    int i14 = yj1Var.f18855d;
                    strA = km0.a(yj1Var.f18852a, yj1Var.f18853b, yj1Var.f18854c, i14, iArr, i13);
                }
                sm2 sm2Var = new sm2();
                sm2Var.zza(str);
                sm2Var.zzl(MimeTypes.VIDEO_MP2T);
                sm2Var.zzm(MimeTypes.VIDEO_H265);
                sm2Var.zzj(strA);
                sm2Var.f16487j = mm1VarZzg.f14283d;
                sm2Var.f16488k = mm1VarZzg.f14284e;
                sm2Var.f16489l = mm1VarZzg.f14285f;
                sm2Var.f16490m = mm1VarZzg.f14286g;
                fv1 fv1Var = new fv1();
                fv1Var.f11401a = mm1VarZzg.f14289j;
                fv1Var.f11402b = mm1VarZzg.f14290k;
                fv1Var.f11403c = mm1VarZzg.f14291l;
                fv1Var.f11404d = mm1VarZzg.f14281b + 8;
                fv1Var.f11405e = mm1VarZzg.f14282c + 8;
                sm2Var.zzC(fv1Var.a());
                sm2Var.f16493p = mm1VarZzg.f14287h;
                sm2Var.f16484g = mm1VarZzg.f14288i;
                sm2Var.f16495r = mm1VarZzg.f14280a + 1;
                sm2Var.zzp(Collections.singletonList(bArr));
                zn2 zn2Var = new zn2(sm2Var);
                this.f15645c.d(zn2Var);
                int i15 = zn2Var.f19335h;
                ih1.b1(i15 != -1);
                ebVar.j(i15);
                this.f15647e = true;
            }
        }
        wa waVar4 = this.f15652j;
        boolean zD = waVar4.d(i11);
        p01 p01Var = this.f15656n;
        if (zD) {
            p01Var.w(qo1.a(waVar4.f17970e, waVar4.f17969d), waVar4.f17969d);
            p01Var.E(5);
            ((dq1) ebVar.f10744e).b(j11, p01Var);
        }
        wa waVar5 = this.f15653k;
        if (waVar5.d(i11)) {
            p01Var.w(qo1.a(waVar5.f17970e, waVar5.f17969d), waVar5.f17969d);
            p01Var.E(5);
            ((dq1) ebVar.f10744e).b(j11, p01Var);
        }
    }

    @Override // com.google.android.gms.internal.ads.ja
    public final void zza() {
        this.f15654l = 0L;
        this.f15655m = -9223372036854775807L;
        qo1.h(this.f15648f);
        this.f15649g.a();
        this.f15650h.a();
        this.f15651i.a();
        this.f15652j.a();
        this.f15653k.a();
        ((dq1) this.f15643a.f10744e).c(0);
        x2.s sVar = this.f15646d;
        if (sVar != null) {
            sVar.f34618e = false;
            sVar.f34619f = false;
            sVar.f34620g = false;
            sVar.f34621h = false;
            sVar.f34622i = false;
        }
    }
}
