package defpackage;

import android.text.TextUtils;
import androidx.media3.common.ParserException;
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;

/* renamed from: ᵮᵯː, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C4230 implements InterfaceC2689 {

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public static final Pattern f15847 = Pattern.compile("LOCAL:([^,]+)");

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public static final Pattern f15848 = Pattern.compile("MPEGTS:(-?\\d+)");

    /* renamed from: ˇʼʤˎ, reason: contains not printable characters */
    public final boolean f15849;

    /* renamed from: ˏˋٴ, reason: contains not printable characters */
    public InterfaceC1982 f15851;

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final String f15853;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final C1240 f15854;

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public int f15855;

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final InterfaceC1889 f15856;

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final C3493 f15852 = new C3493();

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public byte[] f15850 = new byte[1024];

    public C4230(String str, C1240 c1240, InterfaceC1889 interfaceC1889, boolean z) {
        this.f15853 = str;
        this.f15854 = c1240;
        this.f15856 = interfaceC1889;
        this.f15849 = z;
    }

    @Override // defpackage.InterfaceC2689
    /* renamed from: ˇʼʤˎ */
    public final boolean mo1572(InterfaceC1383 interfaceC1383) {
        C1938 c1938 = (C1938) interfaceC1383;
        c1938.mo4251(this.f15850, 0, 6, false);
        byte[] bArr = this.f15850;
        C3493 c3493 = this.f15852;
        c3493.m7975(6, bArr);
        if (AbstractC1310.m4031(c3493)) {
            return true;
        }
        c1938.mo4251(this.f15850, 6, 3, false);
        c3493.m7975(9, this.f15850);
        return AbstractC1310.m4031(c3493);
    }

    @Override // defpackage.InterfaceC2689
    /* renamed from: ˎˏʜʾ */
    public final void mo1573(InterfaceC1982 interfaceC1982) {
        if (this.f15849) {
            interfaceC1982 = new C4699(interfaceC1982, this.f15856);
        }
        this.f15851 = interfaceC1982;
        interfaceC1982.mo4987(new C3300(-9223372036854775807L));
    }

    @Override // defpackage.InterfaceC2689
    /* renamed from: ˏˋٴ */
    public final List mo1574() {
        C4421 c4421 = AbstractC2692.f10429;
        return C4471.f16684;
    }

    @Override // defpackage.InterfaceC2689
    /* renamed from: ˏᵙ */
    public final InterfaceC2689 mo1575() {
        return this;
    }

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public final void m9180() throws ParserException, NumberFormatException {
        String strM7963;
        C3493 c3493 = new C3493(this.f15850);
        AbstractC1310.m4033(c3493);
        String strM79632 = c3493.m7963(StandardCharsets.UTF_8);
        long jM8115 = 0;
        long jM4030 = 0;
        while (true) {
            Matcher matcher = null;
            if (TextUtils.isEmpty(strM79632)) {
                while (true) {
                    String strM79633 = c3493.m7963(StandardCharsets.UTF_8);
                    if (strM79633 == null) {
                        break;
                    }
                    if (AbstractC1310.f5400.matcher(strM79633).matches()) {
                        do {
                            strM7963 = c3493.m7963(StandardCharsets.UTF_8);
                            if (strM7963 != null) {
                            }
                        } while (!strM7963.isEmpty());
                    } else {
                        Matcher matcher2 = AbstractC3671.f13679.matcher(strM79633);
                        if (matcher2.matches()) {
                            matcher = matcher2;
                            break;
                        }
                    }
                }
                if (matcher == null) {
                    m9181(0L);
                    return;
                }
                String strGroup = matcher.group(1);
                strGroup.getClass();
                long jM40302 = AbstractC1310.m4030(strGroup);
                String str = AbstractC3558.f13329;
                long jM3776 = this.f15854.m3776(AbstractC3558.m8115((jM8115 + jM40302) - jM4030, 90000L, 1000000L, RoundingMode.DOWN) % 8589934592L);
                InterfaceC2154 interfaceC2154M9181 = m9181(jM3776 - jM40302);
                byte[] bArr = this.f15850;
                int i = this.f15855;
                C3493 c34932 = this.f15852;
                c34932.m7975(i, bArr);
                interfaceC2154M9181.mo4406(this.f15855, c34932);
                interfaceC2154M9181.mo4410(jM3776, 1, this.f15855, 0, null);
                return;
            }
            if (strM79632.startsWith("X-TIMESTAMP-MAP")) {
                Matcher matcher3 = f15847.matcher(strM79632);
                if (!matcher3.find()) {
                    throw ParserException.m356("X-TIMESTAMP-MAP doesn't contain local timestamp: ".concat(strM79632), null);
                }
                Matcher matcher4 = f15848.matcher(strM79632);
                if (!matcher4.find()) {
                    throw ParserException.m356("X-TIMESTAMP-MAP doesn't contain media timestamp: ".concat(strM79632), null);
                }
                String strGroup2 = matcher3.group(1);
                strGroup2.getClass();
                jM4030 = AbstractC1310.m4030(strGroup2);
                String strGroup3 = matcher4.group(1);
                strGroup3.getClass();
                long j = Long.parseLong(strGroup3);
                String str2 = AbstractC3558.f13329;
                jM8115 = AbstractC3558.m8115(j, 1000000L, 90000L, RoundingMode.DOWN);
            }
            strM79632 = c3493.m7963(StandardCharsets.UTF_8);
        }
    }

    @Override // defpackage.InterfaceC2689
    /* renamed from: ᵥᵯˎ */
    public final void mo1576() {
    }

    @Override // defpackage.InterfaceC2689
    /* renamed from: ᵴᵳ */
    public final void mo1577(long j, long j2) {
        throw new IllegalStateException();
    }

    /* renamed from: ᵹᵝᵶ, reason: contains not printable characters */
    public final InterfaceC2154 m9181(long j) {
        InterfaceC2154 interfaceC2154Mo4996 = this.f15851.mo4996(0, 3);
        C2153 c2153 = new C2153();
        c2153.f8516 = AbstractC2924.m7101("text/vtt");
        c2153.f8527 = this.f15853;
        c2153.f8505 = j;
        AbstractC4737.m10004(c2153, interfaceC2154Mo4996);
        this.f15851.mo4985();
        return interfaceC2154Mo4996;
    }

    @Override // defpackage.InterfaceC2689
    /* renamed from: ᵻᵢﹳᵰ */
    public final int mo1578(InterfaceC1383 interfaceC1383, C4184 c4184) throws NumberFormatException {
        this.f15851.getClass();
        int length = (int) interfaceC1383.getLength();
        int i = this.f15855;
        byte[] bArr = this.f15850;
        if (i == bArr.length) {
            this.f15850 = Arrays.copyOf(bArr, ((length != -1 ? length : bArr.length) * 3) / 2);
        }
        byte[] bArr2 = this.f15850;
        int i2 = this.f15855;
        int i3 = interfaceC1383.read(bArr2, i2, bArr2.length - i2);
        if (i3 != -1) {
            int i4 = this.f15855 + i3;
            this.f15855 = i4;
            if (length == -1 || i4 != length) {
                return 0;
            }
        }
        try {
            m9180();
        } catch (ParserException unused) {
        }
        return -1;
    }
}
