package F0;

import B0.C0016c;
import C3.G;
import C3.W;
import T0.F;
import android.text.TextUtils;
import d3.C;
import java.io.EOFException;
import java.io.InterruptedIOException;
import java.math.RoundingMode;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import u0.C1578n;
import u0.E;
import x0.v;
import z1.AbstractC1788h;
import z1.AbstractC1789i;

/* JADX INFO: loaded from: classes.dex */
public final class u implements T0.m {
    public static final Pattern i = Pattern.compile("LOCAL:([^,]+)");

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public static final Pattern f2423j = Pattern.compile("MPEGTS:(-?\\d+)");

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final x0.t f2425b;

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

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

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

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

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public byte[] f2430g = new byte[1024];

    public u(String str, x0.t tVar, C c3, boolean z8) {
        this.f2424a = str;
        this.f2425b = tVar;
        this.f2427d = c3;
        this.f2428e = z8;
    }

    public final F b(long j8) {
        F fJ = this.f2429f.j(0, 3);
        C1578n c1578n = new C1578n();
        c1578n.f17320m = E.m("text/vtt");
        c1578n.f17312d = this.f2424a;
        c1578n.f17325r = j8;
        I1.a.w(c1578n, fJ);
        this.f2429f.h();
        return fJ;
    }

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

    @Override // T0.m
    public final int e(T0.n nVar, L4.h hVar) throws u0.F, EOFException, InterruptedIOException {
        String strH;
        this.f2429f.getClass();
        int i5 = (int) ((T0.j) nVar).f6427s;
        int i8 = this.f2431h;
        byte[] bArr = this.f2430g;
        if (i8 == bArr.length) {
            this.f2430g = Arrays.copyOf(bArr, ((i5 != -1 ? i5 : bArr.length) * 3) / 2);
        }
        byte[] bArr2 = this.f2430g;
        int i9 = this.f2431h;
        int iP = ((T0.j) nVar).p(bArr2, i9, bArr2.length - i9);
        if (iP != -1) {
            int i10 = this.f2431h + iP;
            this.f2431h = i10;
            if (i5 == -1 || i10 != i5) {
                return 0;
            }
        }
        x0.o oVar = new x0.o(this.f2430g);
        AbstractC1789i.d(oVar);
        String strH2 = oVar.h(StandardCharsets.UTF_8);
        long jS = 0;
        long jC = 0;
        while (true) {
            Matcher matcher = null;
            if (TextUtils.isEmpty(strH2)) {
                while (true) {
                    String strH3 = oVar.h(StandardCharsets.UTF_8);
                    if (strH3 == null) {
                        break;
                    }
                    if (AbstractC1789i.f19230a.matcher(strH3).matches()) {
                        do {
                            strH = oVar.h(StandardCharsets.UTF_8);
                            if (strH != null) {
                            }
                        } while (!strH.isEmpty());
                    } else {
                        Matcher matcher2 = AbstractC1788h.f19226a.matcher(strH3);
                        if (matcher2.matches()) {
                            matcher = matcher2;
                            break;
                        }
                    }
                }
                if (matcher == null) {
                    b(0L);
                    return -1;
                }
                String strGroup = matcher.group(1);
                strGroup.getClass();
                long jC2 = AbstractC1789i.c(strGroup);
                int i11 = v.f18553a;
                long jB = this.f2425b.b(v.S((jS + jC2) - jC, 90000L, 1000000L, RoundingMode.DOWN) % 8589934592L);
                F fB = b(jB - jC2);
                byte[] bArr3 = this.f2430g;
                int i12 = this.f2431h;
                x0.o oVar2 = this.f2426c;
                oVar2.D(i12, bArr3);
                fB.c(this.f2431h, oVar2);
                fB.a(jB, 1, this.f2431h, 0, null);
                return -1;
            }
            if (strH2.startsWith("X-TIMESTAMP-MAP")) {
                Matcher matcher3 = i.matcher(strH2);
                if (!matcher3.find()) {
                    throw u0.F.a(null, "X-TIMESTAMP-MAP doesn't contain local timestamp: ".concat(strH2));
                }
                Matcher matcher4 = f2423j.matcher(strH2);
                if (!matcher4.find()) {
                    throw u0.F.a(null, "X-TIMESTAMP-MAP doesn't contain media timestamp: ".concat(strH2));
                }
                String strGroup2 = matcher3.group(1);
                strGroup2.getClass();
                jC = AbstractC1789i.c(strGroup2);
                String strGroup3 = matcher4.group(1);
                strGroup3.getClass();
                long j8 = Long.parseLong(strGroup3);
                int i13 = v.f18553a;
                jS = v.S(j8, 1000000L, 90000L, RoundingMode.DOWN);
            }
            strH2 = oVar.h(StandardCharsets.UTF_8);
        }
    }

    @Override // T0.m
    public final boolean f(T0.n nVar) {
        T0.j jVar = (T0.j) nVar;
        jVar.f(this.f2430g, 0, 6, false);
        byte[] bArr = this.f2430g;
        x0.o oVar = this.f2426c;
        oVar.D(6, bArr);
        if (AbstractC1789i.a(oVar)) {
            return true;
        }
        jVar.f(this.f2430g, 6, 3, false);
        oVar.D(9, this.f2430g);
        return AbstractC1789i.a(oVar);
    }

    @Override // T0.m
    public final void i(long j8, long j9) {
        throw new IllegalStateException();
    }

    @Override // T0.m
    public final void l(T0.o oVar) {
        if (this.f2428e) {
            oVar = new C0016c(oVar, this.f2427d);
        }
        this.f2429f = oVar;
        oVar.v(new T0.q(-9223372036854775807L));
    }

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

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