package A1;

import C3.W;
import android.util.SparseArray;
import d3.R0;
import java.io.EOFException;
import java.io.InterruptedIOException;
import java.util.List;
import x0.AbstractC1709a;

/* JADX INFO: loaded from: classes.dex */
public final class D implements T0.m {

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

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

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

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

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public T0.o f54j;

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final x0.t f46a = new x0.t(0);

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final x0.o f48c = new x0.o(4096);

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final B f49d = new B(0);

    @Override // T0.m
    public final T0.m c() {
        return this;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r13v0 */
    /* JADX WARN: Type inference failed for: r13v1, types: [x0.o] */
    /* JADX WARN: Type inference failed for: r13v2 */
    /* JADX WARN: Type inference failed for: r13v3 */
    /* JADX WARN: Type inference failed for: r13v4 */
    /* JADX WARN: Type inference failed for: r13v5 */
    /* JADX WARN: Type inference failed for: r1v2, types: [T0.j] */
    /* JADX WARN: Type inference failed for: r1v4, types: [T0.H] */
    /* JADX WARN: Type inference failed for: r2v11 */
    /* JADX WARN: Type inference failed for: r2v12 */
    /* JADX WARN: Type inference failed for: r2v4 */
    /* JADX WARN: Type inference failed for: r2v5, types: [boolean, int] */
    /* JADX WARN: Type inference failed for: r3v3, types: [x0.o] */
    /* JADX WARN: Type inference failed for: r3v4, types: [A1.i] */
    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$UnknownArg
    	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 // T0.m
    public final int e(T0.n nVar, L4.h hVar) throws EOFException, InterruptedIOException {
        int i;
        ?? r22;
        ?? r13;
        ?? r132;
        InterfaceC0008i c0010k;
        AbstractC1709a.k(this.f54j);
        long j8 = ((T0.j) nVar).f6427s;
        int i5 = (j8 > (-1L) ? 1 : (j8 == (-1L) ? 0 : -1));
        long j9 = -9223372036854775807L;
        B b8 = this.f49d;
        if (i5 != 0 && !b8.f34d) {
            boolean z8 = b8.f36f;
            x0.o oVar = b8.f33c;
            if (!z8) {
                T0.j jVar = (T0.j) nVar;
                long j10 = jVar.f6427s;
                int iMin = (int) Math.min(20000L, j10);
                long j11 = j10 - ((long) iMin);
                if (jVar.f6428t != j11) {
                    hVar.f4006a = j11;
                    return 1;
                }
                oVar.C(iMin);
                jVar.f6430v = 0;
                jVar.f(oVar.f18539a, 0, iMin, false);
                int i8 = oVar.f18540b;
                int i9 = oVar.f18541c - 4;
                while (true) {
                    if (i9 < i8) {
                        break;
                    }
                    if (B.b(i9, oVar.f18539a) == 442) {
                        oVar.F(i9 + 4);
                        long jC = B.c(oVar);
                        if (jC != -9223372036854775807L) {
                            j9 = jC;
                            break;
                        }
                    }
                    i9--;
                }
                b8.f38h = j9;
                b8.f36f = true;
                return 0;
            }
            if (b8.f38h == -9223372036854775807L) {
                b8.a((T0.j) nVar);
                return 0;
            }
            if (b8.f35e) {
                long j12 = b8.f37g;
                if (j12 == -9223372036854775807L) {
                    b8.a((T0.j) nVar);
                    return 0;
                }
                x0.t tVar = b8.f32b;
                b8.i = tVar.c(b8.f38h) - tVar.b(j12);
                b8.a((T0.j) nVar);
                return 0;
            }
            T0.j jVar2 = (T0.j) nVar;
            int iMin2 = (int) Math.min(20000L, jVar2.f6427s);
            long j13 = 0;
            if (jVar2.f6428t != j13) {
                hVar.f4006a = j13;
                return 1;
            }
            oVar.C(iMin2);
            jVar2.f6430v = 0;
            jVar2.f(oVar.f18539a, 0, iMin2, false);
            int i10 = oVar.f18540b;
            int i11 = oVar.f18541c;
            while (true) {
                if (i10 >= i11 - 3) {
                    break;
                }
                if (B.b(i10, oVar.f18539a) == 442) {
                    oVar.F(i10 + 4);
                    long jC2 = B.c(oVar);
                    if (jC2 != -9223372036854775807L) {
                        j9 = jC2;
                        break;
                    }
                }
                i10++;
            }
            b8.f37g = j9;
            b8.f35e = true;
            return 0;
        }
        if (this.f55k) {
            i = i5;
            r22 = 0;
        } else {
            this.f55k = true;
            long j14 = b8.i;
            if (j14 != -9223372036854775807L) {
                i = i5;
                r22 = 0;
                A a3 = new A(new x3.e(13), new R0(b8.f32b), j14, j14 + 1, 0L, j8, 188L, 1000);
                this.i = a3;
                this.f54j.v(a3.f27a);
            } else {
                i = i5;
                r22 = 0;
                this.f54j.v(new T0.q(j14));
            }
        }
        A a8 = this.i;
        if (a8 != null && a8.f29c != null) {
            return a8.b((T0.j) nVar, hVar);
        }
        ?? r12 = (T0.j) nVar;
        r12.f6430v = r22;
        long jI = i != 0 ? j8 - r12.i() : -1L;
        if (jI != -1 && jI < 4) {
            return -1;
        }
        ?? r32 = this.f48c;
        if (!r12.f(r32.f18539a, r22, 4, true)) {
            return -1;
        }
        r32.F(r22);
        int iG = r32.g();
        if (iG == 441) {
            return -1;
        }
        if (iG == 442) {
            r12.f(r32.f18539a, r22, 10, r22);
            r32.F(9);
            r12.b((r32.t() & 7) + 14);
            return r22;
        }
        if (iG == 443) {
            r12.f(r32.f18539a, r22, 2, r22);
            r32.F(r22);
            r12.b(r32.z() + 6);
            return r22;
        }
        if (((iG & (-256)) >> 8) != 1) {
            r12.b(1);
            return r22;
        }
        int i12 = iG & 255;
        SparseArray sparseArray = this.f47b;
        C c3 = (C) sparseArray.get(i12);
        if (!this.f50e) {
            if (c3 == null) {
                if (i12 == 189) {
                    c0010k = new C0001b("video/mp2p");
                    this.f51f = true;
                    this.f53h = r12.f6428t;
                } else if ((iG & 224) == 192) {
                    c0010k = new u(r22, null, "video/mp2p");
                    this.f51f = true;
                    this.f53h = r12.f6428t;
                } else if ((iG & 240) == 224) {
                    c0010k = new C0010k(null, "video/mp2p");
                    this.f52g = true;
                    this.f53h = r12.f6428t;
                } else {
                    c0010k = null;
                }
                if (c0010k != null) {
                    c0010k.g(this.f54j, new M(i12, 256));
                    c3 = new C(c0010k, this.f46a);
                    sparseArray.put(i12, c3);
                }
            }
            if (r12.f6428t > ((this.f51f && this.f52g) ? this.f53h + 8192 : 1048576L)) {
                this.f50e = true;
                this.f54j.h();
            }
        }
        r12.f(r32.f18539a, r22, 2, r22);
        r32.F(r22);
        int iZ = r32.z() + 6;
        if (c3 == null) {
            r12.b(iZ);
            return r22;
        }
        r32.C(iZ);
        r12.c(r32.f18539a, r22, iZ, r22);
        r32.F(6);
        ?? r14 = c3.f41c;
        r32.e(r14.f6361d, r22, 3);
        r14.q(r22);
        r14.t(8);
        c3.f42d = r14.h();
        c3.f43e = r14.h();
        r14.t(6);
        r32.e(r14.f6361d, r22, r14.i(8));
        r14.q(r22);
        c3.f45g = 0L;
        if (c3.f42d) {
            r14.t(4);
            long jI2 = ((long) r14.i(3)) << 30;
            r14.t(1);
            long jI3 = jI2 | ((long) (r14.i(15) << 15));
            r14.t(1);
            long jI4 = jI3 | ((long) r14.i(15));
            r14.t(1);
            boolean z9 = c3.f44f;
            x0.t tVar2 = c3.f40b;
            if (z9 || !c3.f43e) {
                r132 = r32;
            } else {
                r14.t(4);
                long jI5 = ((long) r14.i(3)) << 30;
                r14.t(1);
                r132 = r32;
                long jI6 = ((long) (r14.i(15) << 15)) | jI5;
                r14.t(1);
                long jI7 = jI6 | ((long) r14.i(15));
                r14.t(1);
                tVar2.b(jI7);
                c3.f44f = true;
            }
            c3.f45g = tVar2.b(jI4);
            r13 = r132;
        } else {
            r13 = r32;
        }
        long j15 = c3.f45g;
        ?? r33 = c3.f39a;
        r33.h(j15, 4);
        r33.e(r13);
        r33.f(false);
        r13.E(r13.f18539a.length);
        return 0;
    }

    @Override // T0.m
    public final boolean f(T0.n nVar) throws EOFException, InterruptedIOException {
        byte[] bArr = new byte[14];
        T0.j jVar = (T0.j) nVar;
        jVar.f(bArr, 0, 14, false);
        if (442 == (((bArr[0] & 255) << 24) | ((bArr[1] & 255) << 16) | ((bArr[2] & 255) << 8) | (bArr[3] & 255)) && (bArr[4] & 196) == 68 && (bArr[6] & 4) == 4 && (bArr[8] & 4) == 4 && (bArr[9] & 1) == 1 && (bArr[12] & 3) == 3) {
            jVar.h(bArr[13] & 7, false);
            jVar.f(bArr, 0, 3, false);
            if (1 == (((bArr[0] & 255) << 16) | ((bArr[1] & 255) << 8) | (bArr[2] & 255))) {
                return true;
            }
        }
        return false;
    }

    @Override // T0.m
    public final void i(long j8, long j9) {
        x0.t tVar = this.f46a;
        boolean z8 = tVar.e() == -9223372036854775807L;
        if (!z8) {
            long jD = tVar.d();
            z8 = (jD == -9223372036854775807L || jD == 0 || jD == j9) ? false : true;
        }
        if (z8) {
            tVar.g(j9);
        }
        A a3 = this.i;
        if (a3 != null) {
            a3.d(j9);
        }
        int i = 0;
        while (true) {
            SparseArray sparseArray = this.f47b;
            if (i >= sparseArray.size()) {
                return;
            }
            C c3 = (C) sparseArray.valueAt(i);
            c3.f44f = false;
            c3.f39a.a();
            i++;
        }
    }

    @Override // T0.m
    public final void l(T0.o oVar) {
        this.f54j = oVar;
    }

    @Override // T0.m
    public final List m() {
        C3.E e8 = C3.G.f1197r;
        return W.f1225u;
    }

    @Override // T0.m
    public final void a() {
    }
}
