package q1;

import C3.E;
import C3.G;
import C3.W;
import T0.F;
import T0.w;
import java.io.EOFException;
import java.io.InterruptedIOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import u0.C1579o;
import x0.AbstractC1709a;
import x0.o;
import x0.v;

/* JADX INFO: renamed from: q1.i, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1452i implements T0.m {

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

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

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

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public byte[] f16214e = v.f18555c;

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final C1579o f16211b = null;

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

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public int f16217h = 0;
    public long[] i = v.f18556d;

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

    public C1452i(InterfaceC1456m interfaceC1456m) {
        this.f16210a = interfaceC1456m;
    }

    @Override // T0.m
    public final void a() {
        if (this.f16217h == 5) {
            return;
        }
        this.f16210a.reset();
        this.f16217h = 5;
    }

    public final void b(C1451h c1451h) {
        AbstractC1709a.k(this.f16215f);
        byte[] bArr = c1451h.f16209r;
        int length = bArr.length;
        o oVar = this.f16213d;
        oVar.getClass();
        oVar.D(bArr.length, bArr);
        this.f16215f.c(length, oVar);
        this.f16215f.a(c1451h.f16208q, 1, length, 0, null);
    }

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

    /* JADX WARN: Removed duplicated region for block: B:69:0x0080 A[EXC_TOP_SPLITTER, PHI: r15
      0x0080: PHI (r15v3 long) = (r15v4 long), (r15v5 long) binds: [B:32:0x007e, B:29:0x007a] A[DONT_GENERATE, DONT_INLINE], SYNTHETIC] */
    @Override // T0.m
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final int e(T0.n nVar, L4.h hVar) throws u0.F, EOFException, InterruptedIOException {
        long j8;
        int i = this.f16217h;
        AbstractC1709a.j((i == 0 || i == 5) ? false : true);
        if (this.f16217h == 1) {
            int iH = ((T0.j) nVar).f6427s != -1 ? W3.b.h(((T0.j) nVar).f6427s) : 1024;
            if (iH > this.f16214e.length) {
                this.f16214e = new byte[iH];
            }
            this.f16216g = 0;
            this.f16217h = 2;
        }
        int i5 = this.f16217h;
        ArrayList arrayList = this.f16212c;
        if (i5 == 2) {
            byte[] bArr = this.f16214e;
            if (bArr.length == this.f16216g) {
                this.f16214e = Arrays.copyOf(bArr, bArr.length + 1024);
            }
            byte[] bArr2 = this.f16214e;
            int i8 = this.f16216g;
            T0.j jVar = (T0.j) nVar;
            int iP = jVar.p(bArr2, i8, bArr2.length - i8);
            if (iP != -1) {
                this.f16216g += iP;
            }
            long j9 = jVar.f6427s;
            if (j9 != -1) {
                j8 = -1;
                if (this.f16216g == j9) {
                    try {
                        long j10 = this.f16218j;
                        this.f16210a.a(this.f16214e, 0, this.f16216g, j10 != -9223372036854775807L ? new C1455l(j10, true) : C1455l.f16221c, new C1450g(0, this));
                        Collections.sort(arrayList);
                        this.i = new long[arrayList.size()];
                        for (int i9 = 0; i9 < arrayList.size(); i9++) {
                            this.i[i9] = ((C1451h) arrayList.get(i9)).f16208q;
                        }
                        this.f16214e = v.f18555c;
                        this.f16217h = 4;
                    } catch (RuntimeException e8) {
                        throw u0.F.a(e8, "SubtitleParser failed.");
                    }
                }
            } else {
                j8 = -1;
            }
            if (iP == -1) {
            }
        } else {
            j8 = -1;
        }
        if (this.f16217h == 3) {
            if (((T0.j) nVar).s(((T0.j) nVar).f6427s != j8 ? W3.b.h(((T0.j) nVar).f6427s) : 1024) == -1) {
                long j11 = this.f16218j;
                for (int iE = j11 == -9223372036854775807L ? 0 : v.e(this.i, j11, true); iE < arrayList.size(); iE++) {
                    b((C1451h) arrayList.get(iE));
                }
                this.f16217h = 4;
            }
        }
        return this.f16217h == 4 ? -1 : 0;
    }

    @Override // T0.m
    public final boolean f(T0.n nVar) {
        return true;
    }

    @Override // T0.m
    public final void i(long j8, long j9) {
        int i = this.f16217h;
        AbstractC1709a.j((i == 0 || i == 5) ? false : true);
        this.f16218j = j9;
        if (this.f16217h == 2) {
            this.f16217h = 1;
        }
        if (this.f16217h == 4) {
            this.f16217h = 3;
        }
    }

    @Override // T0.m
    public final void l(T0.o oVar) {
        AbstractC1709a.j(this.f16217h == 0);
        F fJ = oVar.j(0, 3);
        this.f16215f = fJ;
        C1579o c1579o = this.f16211b;
        if (c1579o != null) {
            fJ.e(c1579o);
            oVar.h();
            oVar.v(new w(-9223372036854775807L, new long[]{0}, new long[]{0}));
        }
        this.f16217h = 1;
    }

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