package defpackage;

import android.util.SparseArray;
import java.io.EOFException;
import java.io.InterruptedIOException;
import java.util.List;

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

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

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public boolean f16117;

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

    /* renamed from: ᵝᵵᵺ, reason: contains not printable characters */
    public C3442 f16120;

    /* renamed from: ᵶᵷᵕ, reason: contains not printable characters */
    public InterfaceC1982 f16123;

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public boolean f16124;

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

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final C1240 f16121 = new C1240(0);

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

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final SparseArray f16122 = new SparseArray();

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public final C0837 f16126 = new C0837();

    @Override // defpackage.InterfaceC2689
    /* renamed from: ˇʼʤˎ */
    public final boolean mo1572(InterfaceC1383 interfaceC1383) throws EOFException, InterruptedIOException {
        byte[] bArr = new byte[14];
        C1938 c1938 = (C1938) interfaceC1383;
        c1938.mo4251(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) {
            c1938.m5455(bArr[13] & 7, false);
            c1938.mo4251(bArr, 0, 3, false);
            if (1 == (((bArr[0] & 255) << 16) | ((bArr[1] & 255) << 8) | (bArr[2] & 255))) {
                return true;
            }
        }
        return false;
    }

    @Override // defpackage.InterfaceC2689
    /* renamed from: ˎˏʜʾ */
    public final void mo1573(InterfaceC1982 interfaceC1982) {
        this.f16123 = interfaceC1982;
    }

    @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;
    }

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

    @Override // defpackage.InterfaceC2689
    /* renamed from: ᵴᵳ */
    public final void mo1577(long j, long j2) {
        C1240 c1240 = this.f16121;
        boolean z = c1240.m3771() == -9223372036854775807L;
        if (!z) {
            long jM3778 = c1240.m3778();
            z = (jM3778 == -9223372036854775807L || jM3778 == 0 || jM3778 == j2) ? false : true;
        }
        if (z) {
            c1240.m3772(j2);
        }
        C3442 c3442 = this.f16120;
        if (c3442 != null) {
            c3442.m7819(j2);
        }
        int i = 0;
        while (true) {
            SparseArray sparseArray = this.f16122;
            if (i >= sparseArray.size()) {
                return;
            }
            C0801 c0801 = (C0801) sparseArray.valueAt(i);
            c0801.f3721 = false;
            c0801.f3723.mo1773();
            i++;
        }
    }

    @Override // defpackage.InterfaceC2689
    /* renamed from: ᵻᵢﹳᵰ */
    public final int mo1578(InterfaceC1383 interfaceC1383, C4184 c4184) {
        char c;
        int i;
        int i2;
        InterfaceC4315 c0509;
        long j;
        this.f16123.getClass();
        long length = interfaceC1383.getLength();
        int i3 = (length > (-1L) ? 1 : (length == (-1L) ? 0 : -1));
        long j2 = -9223372036854775807L;
        C0837 c0837 = this.f16126;
        if (i3 != 0) {
            c = 3;
            if (!c0837.f3861) {
                C1240 c1240 = c0837.f3862;
                C3493 c3493 = c0837.f3863;
                if (!c0837.f3858) {
                    long length2 = interfaceC1383.getLength();
                    int iMin = (int) Math.min(20000L, length2);
                    long j3 = length2 - iMin;
                    if (interfaceC1383.getPosition() != j3) {
                        c4184.f15658 = j3;
                        return 1;
                    }
                    c3493.m7939(iMin);
                    interfaceC1383.mo4245();
                    interfaceC1383.mo4249(c3493.f13082, 0, iMin);
                    int i4 = c3493.f13083;
                    int i5 = c3493.f13081 - 4;
                    while (true) {
                        if (i5 < i4) {
                            break;
                        }
                        if (C0837.m2961(i5, c3493.f13082) == 442) {
                            c3493.m7955(i5 + 4);
                            long jM2960 = C0837.m2960(c3493);
                            if (jM2960 != -9223372036854775807L) {
                                j2 = jM2960;
                                break;
                            }
                        }
                        i5--;
                    }
                    c0837.f3859 = j2;
                    c0837.f3858 = true;
                    return 0;
                }
                if (c0837.f3859 == -9223372036854775807L) {
                    c0837.m2962(interfaceC1383);
                    return 0;
                }
                if (c0837.f3865) {
                    long j4 = c0837.f3860;
                    if (j4 == -9223372036854775807L) {
                        c0837.m2962(interfaceC1383);
                        return 0;
                    }
                    c0837.f3864 = c1240.m3774(c0837.f3859) - c1240.m3776(j4);
                    c0837.m2962(interfaceC1383);
                    return 0;
                }
                int iMin2 = (int) Math.min(20000L, interfaceC1383.getLength());
                if (interfaceC1383.getPosition() != 0) {
                    c4184.f15658 = 0L;
                    return 1;
                }
                c3493.m7939(iMin2);
                interfaceC1383.mo4245();
                interfaceC1383.mo4249(c3493.f13082, 0, iMin2);
                int i6 = c3493.f13083;
                int i7 = c3493.f13081;
                while (true) {
                    if (i6 >= i7 - 3) {
                        j = -9223372036854775807L;
                        break;
                    }
                    if (C0837.m2961(i6, c3493.f13082) == 442) {
                        c3493.m7955(i6 + 4);
                        long jM29602 = C0837.m2960(c3493);
                        if (jM29602 != -9223372036854775807L) {
                            j = jM29602;
                            break;
                        }
                    }
                    i6++;
                }
                c0837.f3860 = j;
                c0837.f3865 = true;
                return 0;
            }
        } else {
            c = 3;
        }
        if (this.f16124) {
            i = i3;
            i2 = 4;
        } else {
            this.f16124 = true;
            long j5 = c0837.f3864;
            if (j5 != -9223372036854775807L) {
                i = i3;
                i2 = 4;
                C3442 c3442 = new C3442(new ʾᵠᵦ(), new ᵶˉᵹʣ(c0837.f3862), j5, j5 + 1, 0L, length, 188L, 1000);
                this.f16120 = c3442;
                this.f16123.mo4987(c3442.f12877);
            } else {
                i = i3;
                i2 = 4;
                this.f16123.mo4987(new C3300(j5));
            }
        }
        C3442 c34422 = this.f16120;
        if (c34422 != null && c34422.f12876 != null) {
            return c34422.m7818(interfaceC1383, c4184);
        }
        interfaceC1383.mo4245();
        long jMo4244 = i != 0 ? length - interfaceC1383.mo4244() : -1L;
        if (jMo4244 != -1 && jMo4244 < 4) {
            return -1;
        }
        C3493 c34932 = this.f16119;
        if (!interfaceC1383.mo4251(c34932.f13082, 0, i2, true)) {
            return -1;
        }
        c34932.m7955(0);
        int iM7965 = c34932.m7965();
        if (iM7965 == 441) {
            return -1;
        }
        if (iM7965 == 442) {
            interfaceC1383.mo4249(c34932.f13082, 0, 10);
            c34932.m7955(9);
            interfaceC1383.mo4248((c34932.m7956() & 7) + 14);
            return 0;
        }
        if (iM7965 == 443) {
            interfaceC1383.mo4249(c34932.f13082, 0, 2);
            c34932.m7955(0);
            interfaceC1383.mo4248(c34932.m7972() + 6);
            return 0;
        }
        if (((iM7965 & (-256)) >> 8) != 1) {
            interfaceC1383.mo4248(1);
            return 0;
        }
        int i8 = iM7965 & 255;
        SparseArray sparseArray = this.f16122;
        C0801 c0801 = (C0801) sparseArray.get(i8);
        if (!this.f16116) {
            if (c0801 == null) {
                if (i8 == 189) {
                    c0509 = new C3926("video/mp2p");
                    this.f16118 = true;
                    this.f16125 = interfaceC1383.getPosition();
                } else if ((iM7965 & 224) == 192) {
                    c0509 = new C0999(0, null, "video/mp2p");
                    this.f16118 = true;
                    this.f16125 = interfaceC1383.getPosition();
                } else if ((iM7965 & 240) == 224) {
                    c0509 = new C0509(null, "video/mp2p");
                    this.f16117 = true;
                    this.f16125 = interfaceC1383.getPosition();
                } else {
                    c0509 = null;
                }
                if (c0509 != null) {
                    c0509.mo1772(this.f16123, new C4996(i8, 256));
                    c0801 = new C0801(c0509, this.f16121);
                    sparseArray.put(i8, c0801);
                }
            }
            if (interfaceC1383.getPosition() > ((this.f16118 && this.f16117) ? this.f16125 + 8192 : 1048576L)) {
                this.f16116 = true;
                this.f16123.mo4985();
            }
        }
        interfaceC1383.mo4249(c34932.f13082, 0, 2);
        c34932.m7955(0);
        int iM7972 = c34932.m7972() + 6;
        if (c0801 == null) {
            interfaceC1383.mo4248(iM7972);
            return 0;
        }
        c34932.m7939(iM7972);
        interfaceC1383.readFully(c34932.f13082, 0, iM7972);
        c34932.m7955(6);
        InterfaceC4315 interfaceC4315 = c0801.f3723;
        C4089 c4089 = c0801.f3722;
        c34932.m7970(c4089.f15282, 0, 3);
        c4089.m8957(0);
        c4089.m8956(8);
        c0801.f3725 = c4089.m8964();
        c0801.f3719 = c4089.m8964();
        c4089.m8956(6);
        c34932.m7970(c4089.f15282, 0, c4089.m8966(8));
        c4089.m8957(0);
        C1240 c12402 = c0801.f3724;
        c0801.f3720 = 0L;
        if (c0801.f3725) {
            c4089.m8956(4);
            c4089.m8956(1);
            c4089.m8956(1);
            long jM8966 = (c4089.m8966(3) << 30) | (c4089.m8966(15) << 15) | c4089.m8966(15);
            c4089.m8956(1);
            if (!c0801.f3721 && c0801.f3719) {
                c4089.m8956(4);
                c4089.m8956(1);
                c4089.m8956(1);
                c4089.m8956(1);
                c12402.m3776((c4089.m8966(3) << 30) | (c4089.m8966(15) << 15) | c4089.m8966(15));
                c0801.f3721 = true;
            }
            c0801.f3720 = c12402.m3776(jM8966);
        }
        interfaceC4315.mo1771(c0801.f3720, 4);
        interfaceC4315.mo1774(c34932);
        interfaceC4315.mo1775(false);
        c34932.m7950(c34932.f13082.length);
        return 0;
    }
}
