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

import android.util.Pair;
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 la implements ja {

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public static final double[] f13551o = {23.976023976023978d, 24.0d, 25.0d, 29.97002997002997d, 30.0d, 50.0d, 59.94005994005994d, 60.0d};

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

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

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final boolean[] f13555d = new boolean[4];

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

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

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

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

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

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

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

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

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

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

    @Nullable
    private final kb zzd;

    @Nullable
    private final p01 zzf;

    @Nullable
    private final wa zzg;

    public la(@Nullable kb kbVar, String str) {
        p01 p01Var;
        this.zzd = kbVar;
        this.f13554c = str;
        ka kaVar = new ka();
        kaVar.f13192d = new byte[128];
        this.f13556e = kaVar;
        if (kbVar != null) {
            this.zzg = new wa(178);
            p01Var = new p01();
        } else {
            p01Var = null;
            this.zzg = null;
        }
        this.zzf = p01Var;
        this.f13561j = -9223372036854775807L;
        this.f13563l = -9223372036854775807L;
    }

    @Override // com.google.android.gms.internal.ads.ja
    public final void a(q2 q2Var, x2.o0 o0Var) {
        o0Var.d();
        o0Var.e();
        this.f13552a = o0Var.f34561e;
        o0Var.e();
        this.f13553b = q2Var.e(o0Var.f34560d, 2);
        kb kbVar = this.zzd;
        if (kbVar != null) {
            kbVar.a(q2Var, o0Var);
        }
    }

    /* 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
    public final void b(boolean z10) {
        u3 u3Var = this.f13553b;
        u3Var.getClass();
        if (z10) {
            boolean z11 = this.f13564m;
            long j10 = this.f13557f - this.f13562k;
            u3Var.zze(this.f13563l, z11 ? 1 : 0, (int) j10, 0, null);
        }
    }

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

    /* JADX WARN: Removed duplicated region for block: B:44:0x0117  */
    /* JADX WARN: Removed duplicated region for block: B:65:0x018e  */
    /* 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) {
        ka kaVar;
        int i10;
        int i11;
        int i12;
        p01 p01Var2;
        int i13;
        boolean z10;
        boolean z11;
        int i14;
        int i15;
        int i16;
        float f10;
        int i17;
        p01 p01Var3 = p01Var;
        this.f13553b.getClass();
        int i18 = p01Var3.f15226b;
        int i19 = p01Var3.f15227c;
        byte[] bArr = p01Var3.f15225a;
        this.f13557f += (long) p01Var.y();
        this.f13553b.a(p01Var3, p01Var.y());
        while (true) {
            int iG = qo1.g(bArr, i18, i19, this.f13555d);
            kaVar = this.f13556e;
            if (iG == i19) {
                break;
            }
            int i20 = iG + 3;
            int i21 = p01Var3.f15225a[i20] & 255;
            int i22 = iG - i18;
            if (this.f13559h) {
                i10 = i19;
                i11 = i20;
                i12 = i18;
            } else {
                if (i22 > 0) {
                    kaVar.a(bArr, i18, iG);
                }
                int i23 = i22 < 0 ? -i22 : 0;
                if (kaVar.f13189a) {
                    int i24 = kaVar.f13190b - i23;
                    kaVar.f13190b = i24;
                    if (kaVar.f13191c == 0 && i21 == 181) {
                        kaVar.f13191c = i24;
                        i10 = i19;
                        i11 = i20;
                        i12 = i18;
                    } else {
                        kaVar.f13189a = false;
                        String str = this.f13552a;
                        str.getClass();
                        byte[] bArrCopyOf = Arrays.copyOf(kaVar.f13192d, kaVar.f13190b);
                        int i25 = bArrCopyOf[4] & 255;
                        byte b10 = bArrCopyOf[5];
                        int i26 = bArrCopyOf[6] & 255;
                        i11 = i20;
                        i10 = i19;
                        int i27 = (i25 << 4) | ((b10 & 255) >> 4);
                        int i28 = (bArrCopyOf[7] & 240) >> 4;
                        int i29 = ((b10 & 15) << 8) | i26;
                        if (i28 == 2) {
                            i15 = i29 * 4;
                            i16 = i27 * 3;
                        } else if (i28 == 3) {
                            i15 = i29 * 16;
                            i16 = i27 * 9;
                        } else if (i28 != 4) {
                            f10 = 1.0f;
                            sm2 sm2Var = new sm2();
                            sm2Var.zza(str);
                            sm2Var.zzl(this.f13554c);
                            sm2Var.zzm(MimeTypes.VIDEO_MPEG2);
                            sm2Var.f16487j = i27;
                            sm2Var.f16488k = i29;
                            sm2Var.f16493p = f10;
                            sm2Var.zzp(Collections.singletonList(bArrCopyOf));
                            zn2 zn2Var = new zn2(sm2Var);
                            i17 = (bArrCopyOf[7] & 15) - 1;
                            long j10 = 0;
                            if (i17 >= 0 || i17 >= 8) {
                                i12 = i18;
                            } else {
                                double d10 = f13551o[i17];
                                byte b11 = bArrCopyOf[kaVar.f13191c + 9];
                                int i30 = (b11 & 96) >> 5;
                                int i31 = b11 & 31;
                                if (i30 != i31) {
                                    double d11 = ((double) i30) + 1.0d;
                                    i12 = i18;
                                    d10 *= d11 / ((double) (i31 + 1));
                                } else {
                                    i12 = i18;
                                }
                                j10 = (long) (1000000.0d / d10);
                            }
                            Pair pairCreate = Pair.create(zn2Var, Long.valueOf(j10));
                            this.f13553b.d((zn2) pairCreate.first);
                            this.f13560i = ((Long) pairCreate.second).longValue();
                            this.f13559h = true;
                        } else {
                            i15 = i29 * 121;
                            i16 = i27 * 100;
                        }
                        f10 = i15 / i16;
                        sm2 sm2Var2 = new sm2();
                        sm2Var2.zza(str);
                        sm2Var2.zzl(this.f13554c);
                        sm2Var2.zzm(MimeTypes.VIDEO_MPEG2);
                        sm2Var2.f16487j = i27;
                        sm2Var2.f16488k = i29;
                        sm2Var2.f16493p = f10;
                        sm2Var2.zzp(Collections.singletonList(bArrCopyOf));
                        zn2 zn2Var2 = new zn2(sm2Var2);
                        i17 = (bArrCopyOf[7] & 15) - 1;
                        long j102 = 0;
                        if (i17 >= 0) {
                            i12 = i18;
                            Pair pairCreate2 = Pair.create(zn2Var2, Long.valueOf(j102));
                            this.f13553b.d((zn2) pairCreate2.first);
                            this.f13560i = ((Long) pairCreate2.second).longValue();
                            this.f13559h = true;
                        }
                    }
                } else {
                    i10 = i19;
                    i11 = i20;
                    i12 = i18;
                    if (i21 == 179) {
                        kaVar.f13189a = true;
                    }
                }
                kaVar.a(ka.f13188e, 0, 3);
            }
            wa waVar = this.zzg;
            if (waVar == null) {
                p01Var2 = p01Var;
                i13 = i21;
            } else {
                if (i22 > 0) {
                    waVar.c(i12, iG, bArr);
                    i14 = 0;
                } else {
                    i14 = -i22;
                }
                if (waVar.d(i14)) {
                    int iA = qo1.a(waVar.f17970e, waVar.f17969d);
                    p01 p01Var4 = this.zzf;
                    String str2 = bb1.f9474a;
                    p01Var4.w(iA, waVar.f17969d);
                    this.zzd.b(this.f13563l, p01Var4);
                }
                if (i21 == 178) {
                    p01Var2 = p01Var;
                    if (p01Var2.f15225a[iG + 2] == 1) {
                        waVar.b(178);
                    }
                    i13 = 178;
                }
            }
            if (i13 == 0 || i13 == 179) {
                int i32 = i10 - iG;
                if (this.f13565n && this.f13559h) {
                    long j11 = this.f13563l;
                    if (j11 != -9223372036854775807L) {
                        this.f13553b.zze(j11, this.f13564m ? 1 : 0, ((int) (this.f13557f - this.f13562k)) - i32, i32, null);
                    }
                }
                if (!this.f13558g || this.f13565n) {
                    this.f13562k = this.f13557f - ((long) i32);
                    long j12 = this.f13561j;
                    if (j12 == -9223372036854775807L) {
                        long j13 = this.f13563l;
                        j12 = j13 != -9223372036854775807L ? j13 + this.f13560i : -9223372036854775807L;
                    }
                    this.f13563l = j12;
                    z10 = false;
                    this.f13564m = false;
                    this.f13561j = -9223372036854775807L;
                    z11 = true;
                    this.f13558g = true;
                } else {
                    z10 = false;
                    z11 = true;
                }
                this.f13565n = i13 == 0 ? z11 : z10;
            } else if (i13 == 184) {
                this.f13564m = true;
            }
            p01Var3 = p01Var2;
            i18 = i11;
            i19 = i10;
        }
        if (!this.f13559h) {
            kaVar.a(bArr, i18, i19);
        }
        wa waVar2 = this.zzg;
        if (waVar2 != null) {
            waVar2.c(i18, i19, bArr);
        }
    }

    @Override // com.google.android.gms.internal.ads.ja
    public final void zza() {
        qo1.h(this.f13555d);
        ka kaVar = this.f13556e;
        kaVar.f13189a = false;
        kaVar.f13190b = 0;
        kaVar.f13191c = 0;
        wa waVar = this.zzg;
        if (waVar != null) {
            waVar.a();
        }
        this.f13557f = 0L;
        this.f13558g = false;
        this.f13561j = -9223372036854775807L;
        this.f13563l = -9223372036854775807L;
    }
}
