package A1;

import android.util.Pair;
import d3.R0;
import java.util.Arrays;
import java.util.Collections;
import u0.C1578n;
import u0.C1579o;
import x0.AbstractC1709a;

/* JADX INFO: renamed from: A1.k, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0010k implements InterfaceC0008i {

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public static final double[] f185r = {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 f186a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public T0.F f187b;

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

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final x0.o f190e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final x f191f;

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final C0009j f193h;
    public long i;

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

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

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

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

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

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

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

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

    public C0010k(R0 r02, String str) {
        this.f188c = r02;
        this.f189d = str;
        C0009j c0009j = new C0009j();
        c0009j.f184d = new byte[128];
        this.f193h = c0009j;
        if (r02 != null) {
            this.f191f = new x(178);
            this.f190e = new x0.o();
        } else {
            this.f191f = null;
            this.f190e = null;
        }
        this.f197m = -9223372036854775807L;
        this.f199o = -9223372036854775807L;
    }

    @Override // A1.InterfaceC0008i
    public final void a() {
        y0.o.b(this.f192g);
        C0009j c0009j = this.f193h;
        c0009j.f181a = false;
        c0009j.f182b = 0;
        c0009j.f183c = 0;
        x xVar = this.f191f;
        if (xVar != null) {
            xVar.g();
        }
        this.i = 0L;
        this.f194j = false;
        this.f197m = -9223372036854775807L;
        this.f199o = -9223372036854775807L;
    }

    /* JADX WARN: Removed duplicated region for block: B:65:0x01a3  */
    /* 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 // A1.InterfaceC0008i
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final void e(x0.o oVar) {
        C0009j c0009j;
        x xVar;
        char c3;
        boolean z8;
        boolean z9;
        boolean z10;
        int i;
        float f3;
        long j8;
        float f7;
        int i5;
        char c8 = 3;
        AbstractC1709a.k(this.f187b);
        int i8 = oVar.f18540b;
        int i9 = oVar.f18541c;
        byte[] bArr = oVar.f18539a;
        this.i += (long) oVar.a();
        this.f187b.c(oVar.a(), oVar);
        while (true) {
            int iC = y0.o.c(bArr, i8, i9, this.f192g);
            c0009j = this.f193h;
            xVar = this.f191f;
            if (iC == i9) {
                break;
            }
            int i10 = iC + 3;
            int i11 = oVar.f18539a[i10] & 255;
            int i12 = iC - i8;
            if (this.f195k) {
                c3 = c8;
            } else {
                if (i12 > 0) {
                    c0009j.a(bArr, i8, iC);
                }
                int i13 = i12 < 0 ? -i12 : 0;
                if (c0009j.f181a) {
                    int i14 = c0009j.f182b - i13;
                    c0009j.f182b = i14;
                    if (c0009j.f183c == 0 && i11 == 181) {
                        c0009j.f183c = i14;
                    } else {
                        c0009j.f181a = false;
                        String str = this.f186a;
                        str.getClass();
                        byte[] bArrCopyOf = Arrays.copyOf(c0009j.f184d, c0009j.f182b);
                        int i15 = bArrCopyOf[4] & 255;
                        byte b8 = bArrCopyOf[5];
                        int i16 = (i15 << 4) | ((b8 & 255) >> 4);
                        int i17 = ((b8 & 15) << 8) | (bArrCopyOf[6] & 255);
                        int i18 = (bArrCopyOf[7] & 240) >> 4;
                        if (i18 != 2) {
                            if (i18 == 3) {
                                f7 = i17 * 16;
                                i5 = i16 * 9;
                            } else if (i18 != 4) {
                                f3 = 1.0f;
                            } else {
                                f7 = i17 * 121;
                                i5 = i16 * 100;
                            }
                            f3 = f7 / i5;
                        } else {
                            f3 = (i17 * 4) / (i16 * 3);
                        }
                        C1578n c1578n = new C1578n();
                        c1578n.f17309a = str;
                        c1578n.f17319l = u0.E.m(this.f189d);
                        c1578n.f17320m = u0.E.m("video/mpeg2");
                        c1578n.f17327t = i16;
                        c1578n.f17328u = i17;
                        c1578n.f17331x = f3;
                        c1578n.f17323p = Collections.singletonList(bArrCopyOf);
                        C1579o c1579o = new C1579o(c1578n);
                        int i19 = (bArrCopyOf[7] & 15) - 1;
                        if (i19 < 0 || i19 >= 8) {
                            j8 = 0;
                        } else {
                            double d8 = f185r[i19];
                            byte b9 = bArrCopyOf[c0009j.f183c + 9];
                            int i20 = (b9 & 96) >> 5;
                            int i21 = b9 & 31;
                            if (i20 != i21) {
                                d8 = ((((double) i20) + 1.0d) / ((double) (i21 + 1))) * d8;
                            }
                            j8 = (long) (1000000.0d / d8);
                        }
                        Pair pairCreate = Pair.create(c1579o, Long.valueOf(j8));
                        this.f187b.e((C1579o) pairCreate.first);
                        this.f196l = ((Long) pairCreate.second).longValue();
                        this.f195k = true;
                        c3 = 3;
                    }
                } else if (i11 == 179) {
                    c0009j.f181a = true;
                }
                c3 = 3;
                c0009j.a(C0009j.f180e, 0, 3);
            }
            if (xVar == null) {
                z8 = true;
            } else {
                if (i12 > 0) {
                    xVar.a(bArr, i8, iC);
                    i = 0;
                } else {
                    i = -i12;
                }
                if (xVar.e(i)) {
                    int iN = y0.o.n(xVar.f360e, (byte[]) xVar.f361f);
                    int i22 = x0.v.f18553a;
                    byte[] bArr2 = (byte[]) xVar.f361f;
                    x0.o oVar2 = this.f190e;
                    oVar2.D(iN, bArr2);
                    this.f188c.I(this.f199o, oVar2);
                }
                if (i11 == 178) {
                    z8 = true;
                    if (oVar.f18539a[iC + 2] == 1) {
                        xVar.h(i11);
                    }
                }
            }
            if (i11 == 0 || i11 == 179) {
                int i23 = i9 - iC;
                if (this.f201q && this.f195k) {
                    long j9 = this.f199o;
                    if (j9 != -9223372036854775807L) {
                        this.f187b.a(j9, this.f200p ? 1 : 0, ((int) (this.i - this.f198n)) - i23, i23, null);
                    }
                }
                if (!this.f194j || this.f201q) {
                    this.f198n = this.i - ((long) i23);
                    long j10 = this.f197m;
                    if (j10 == -9223372036854775807L) {
                        long j11 = this.f199o;
                        j10 = j11 != -9223372036854775807L ? j11 + this.f196l : -9223372036854775807L;
                    }
                    this.f199o = j10;
                    z9 = false;
                    this.f200p = false;
                    this.f197m = -9223372036854775807L;
                    z10 = true;
                    this.f194j = true;
                } else {
                    z10 = true;
                    z9 = false;
                }
                if (i11 == 0) {
                    z9 = z10;
                }
                this.f201q = z9;
            } else if (i11 == 184) {
                this.f200p = z8;
            }
            c8 = c3;
            i8 = i10;
        }
        if (!this.f195k) {
            c0009j.a(bArr, i8, i9);
        }
        if (xVar != null) {
            xVar.a(bArr, i8, i9);
        }
    }

    /* 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 // A1.InterfaceC0008i
    public final void f(boolean z8) {
        AbstractC1709a.k(this.f187b);
        if (z8) {
            boolean z9 = this.f200p;
            this.f187b.a(this.f199o, z9 ? 1 : 0, (int) (this.i - this.f198n), 0, null);
        }
    }

    @Override // A1.InterfaceC0008i
    public final void g(T0.o oVar, M m8) {
        m8.a();
        m8.b();
        this.f186a = m8.f103e;
        m8.b();
        this.f187b = oVar.j(m8.f102d, 2);
        R0 r02 = this.f188c;
        if (r02 != null) {
            r02.K(oVar, m8);
        }
    }

    @Override // A1.InterfaceC0008i
    public final void h(long j8, int i) {
        this.f197m = j8;
    }
}
