package p138.p176.p177.p190.p198.p203;

import android.util.Log;
import com.google.android.exoplayer2.ParserException;
import java.io.EOFException;
import java.util.List;
import p138.p176.p177.p190.C3431;
import p138.p176.p177.p190.p194.C3526;
import p138.p176.p177.p190.p198.C3558;
import p138.p176.p177.p190.p198.C3567;
import p138.p176.p177.p190.p198.C3568;
import p138.p176.p177.p190.p198.C3569;
import p138.p176.p177.p190.p198.C3570;
import p138.p176.p177.p190.p198.InterfaceC3561;
import p138.p176.p177.p190.p198.InterfaceC3562;
import p138.p176.p177.p190.p198.InterfaceC3575;
import p138.p176.p177.p190.p198.p203.InterfaceC3607;
import p138.p176.p177.p190.p210.C3710;
import p138.p176.p177.p190.p210.p214.C3746;
import p138.p176.p177.p190.p210.p214.C3752;
import p138.p176.p177.p190.p239.C4140;
import p138.p176.p177.p190.p239.C4150;

/* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ೲ.ޙ.ށ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C3606 implements InterfaceC3561 {

    /* JADX INFO: renamed from: ގ, reason: contains not printable characters */
    public static final C3746.InterfaceC3747 f10813 = new C3746.InterfaceC3747() { // from class: ދ.ހ.֏.ؠ.ೲ.ޙ.֏
        @Override // p138.p176.p177.p190.p210.p214.C3746.InterfaceC3747
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final boolean mo5933(int i, int i2, int i3, int i4, int i5) {
            return C3606.m5937(i, i2, i3, i4, i5);
        }
    };

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final int f10814;

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final long f10815;

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final C4140 f10816;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final C3569 f10817;

    /* JADX INFO: renamed from: ނ, reason: contains not printable characters */
    public final C3567 f10818;

    /* JADX INFO: renamed from: ރ, reason: contains not printable characters */
    public final C3568 f10819;

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public InterfaceC3562 f10820;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public InterfaceC3575 f10821;

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public int f10822;

    /* JADX INFO: renamed from: އ, reason: contains not printable characters */
    public C3710 f10823;

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public InterfaceC3607 f10824;

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public boolean f10825;

    /* JADX INFO: renamed from: ފ, reason: contains not printable characters */
    public long f10826;

    /* JADX INFO: renamed from: ދ, reason: contains not printable characters */
    public long f10827;

    /* JADX INFO: renamed from: ތ, reason: contains not printable characters */
    public long f10828;

    /* JADX INFO: renamed from: ލ, reason: contains not printable characters */
    public int f10829;

    public C3606() {
        this(0, -9223372036854775807L);
    }

    public C3606(int i, long j) {
        this.f10814 = i;
        this.f10815 = j;
        this.f10816 = new C4140(10);
        this.f10817 = new C3569();
        this.f10818 = new C3567();
        this.f10826 = -9223372036854775807L;
        this.f10819 = new C3568();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static /* synthetic */ boolean m5937(int i, int i2, int i3, int i4, int i5) {
        return (i2 == 67 && i3 == 79 && i4 == 77 && (i5 == 77 || i == 2)) || (i2 == 77 && i3 == 76 && i4 == 76 && (i5 == 84 || i == 2));
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public static boolean m5938(int i, long j) {
        return ((long) (i & (-128000))) == (j & (-128000));
    }

    /* JADX WARN: Removed duplicated region for block: B:118:0x02a9  */
    /* JADX WARN: Removed duplicated region for block: B:119:0x02b1  */
    /* JADX WARN: Removed duplicated region for block: B:132:0x02ff  */
    /* JADX WARN: Removed duplicated region for block: B:133:0x0302  */
    /* JADX WARN: Removed duplicated region for block: B:22:0x005b  */
    /* JADX WARN: Removed duplicated region for block: B:27:0x006e  */
    @Override // p138.p176.p177.p190.p198.InterfaceC3561
    /* JADX INFO: renamed from: ֏ */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public int mo5886(C3558 c3558, C3570 c3570) throws InterruptedException, ParserException, EOFException {
        C3606 c3606;
        C3558 c35582;
        int i;
        int i2;
        InterfaceC3607 interfaceC3607M5940;
        int iM6705;
        C3605 c3605;
        int iM6702;
        if (this.f10822 == 0) {
            try {
                m5939(c3558, false);
            } catch (EOFException unused) {
                return -1;
            }
        }
        if (this.f10824 == null) {
            C4140 c4140 = new C4140(this.f10817.f10586);
            c3558.m5875(c4140.f13227, 0, this.f10817.f10586, false);
            C3569 c3569 = this.f10817;
            int i3 = c3569.f10584 & 1;
            int i4 = 21;
            int i5 = c3569.f10588;
            if (i3 != 0) {
                if (i5 != 1) {
                    i4 = 36;
                }
            } else if (i5 == 1) {
                i4 = 13;
            }
            if (c4140.f13229 >= i4 + 4) {
                c4140.m6693(i4);
                int iM6688 = c4140.m6688();
                if (iM6688 != 1483304551 && iM6688 != 1231971951) {
                    if (c4140.f13229 >= 40) {
                        c4140.m6693(36);
                        iM6688 = c4140.m6688() == 1447187017 ? 1447187017 : 0;
                    }
                }
                if (iM6688 == 1483304551 || iM6688 == 1231971951) {
                    c3606 = this;
                    c35582 = c3558;
                    long j = c35582.f10562;
                    long j2 = c35582.f10563;
                    C3569 c35692 = c3606.f10817;
                    int i6 = c35692.f10590;
                    int i7 = c35692.f10587;
                    int iM66882 = c4140.m6688();
                    if ((iM66882 & 1) != 1 || (iM6705 = c4140.m6705()) == 0) {
                        i = iM6688;
                        i2 = i4;
                        interfaceC3607M5940 = null;
                    } else {
                        i = iM6688;
                        long jM6797 = C4150.m6797(iM6705, ((long) i6) * 1000000, i7);
                        if ((iM66882 & 6) != 6) {
                            interfaceC3607M5940 = new C3610(j2, c35692.f10586, jM6797, -1L, null);
                            i2 = i4;
                        } else {
                            long jM6705 = c4140.m6705();
                            long[] jArr = new long[100];
                            int i8 = 0;
                            for (int i9 = 100; i8 < i9; i9 = 100) {
                                jArr[i8] = c4140.m6702();
                                i8++;
                                i4 = i4;
                            }
                            i2 = i4;
                            if (j != -1) {
                                long j3 = j2 + jM6705;
                                if (j != j3) {
                                    Log.w("XingSeeker", "XING data size mismatch: " + j + ", " + j3);
                                }
                            }
                            interfaceC3607M5940 = new C3610(j2, c35692.f10586, jM6797, jM6705, jArr);
                        }
                    }
                    if (interfaceC3607M5940 != null) {
                        C3567 c3567 = c3606.f10818;
                        if (!((c3567.f10574 == -1 || c3567.f10575 == -1) ? false : true)) {
                            c35582.f10565 = 0;
                            c35582.m5874(i2 + 141, false);
                            c35582.m5875(c3606.f10816.f13227, 0, 3, false);
                            c3606.f10816.m6693(0);
                            C3567 c35672 = c3606.f10818;
                            int iM6704 = c3606.f10816.m6704();
                            if (c35672 == null) {
                                throw null;
                            }
                            int i10 = iM6704 >> 12;
                            int i11 = iM6704 & 4095;
                            if (i10 > 0 || i11 > 0) {
                                c35672.f10574 = i10;
                                c35672.f10575 = i11;
                            }
                        }
                    }
                    c35582.m5878(c3606.f10817.f10586);
                    if (interfaceC3607M5940 != null && !interfaceC3607M5940.mo5858() && i == 1231971951) {
                        interfaceC3607M5940 = m5940(c3558);
                    }
                } else if (iM6688 == 1447187017) {
                    long j4 = c3558.f10562;
                    long j5 = c3558.f10563;
                    C3569 c35693 = this.f10817;
                    c4140.m6695(10);
                    int iM66883 = c4140.m6688();
                    if (iM66883 <= 0) {
                        c3606 = this;
                        interfaceC3607M5940 = null;
                        c35582 = c3558;
                        c35582.m5878(c3606.f10817.f10586);
                    } else {
                        int i12 = c35693.f10587;
                        long jM67972 = C4150.m6797(iM66883, ((long) (i12 >= 32000 ? 1152 : 576)) * 1000000, i12);
                        int iM6707 = c4140.m6707();
                        int iM67072 = c4140.m6707();
                        int iM67073 = c4140.m6707();
                        c4140.m6695(2);
                        long j6 = ((long) c35693.f10586) + j5;
                        long[] jArr2 = new long[iM6707];
                        long[] jArr3 = new long[iM6707];
                        for (int i13 = 0; i13 < iM6707; i13++) {
                            long j7 = j5;
                            jArr2[i13] = (((long) i13) * jM67972) / ((long) iM6707);
                            jArr3[i13] = Math.max(j7, j6);
                            if (iM67073 == 1) {
                                iM6702 = c4140.m6702();
                            } else if (iM67073 == 2) {
                                iM6702 = c4140.m6707();
                            } else if (iM67073 == 3) {
                                iM6702 = c4140.m6704();
                            } else {
                                if (iM67073 != 4) {
                                    c3606 = this;
                                    interfaceC3607M5940 = null;
                                    break;
                                }
                                iM6702 = c4140.m6705();
                            }
                            j5 = j7 + ((long) (iM6702 * iM67072));
                        }
                        if (j4 != -1 && j4 != j5) {
                            Log.w("VbriSeeker", "VBRI data size mismatch: " + j4 + ", " + j5);
                        }
                        interfaceC3607M5940 = new C3609(jArr2, jArr3, jM67972, j5);
                        c3606 = this;
                        c35582 = c3558;
                        c35582.m5878(c3606.f10817.f10586);
                    }
                } else {
                    c3606 = this;
                    c35582 = c3558;
                    c35582.f10565 = 0;
                    interfaceC3607M5940 = null;
                }
                C3710 c3710 = c3606.f10823;
                long j8 = c35582.f10563;
                if (c3710 != null) {
                    int length = c3710.f11440.length;
                    for (int i14 = 0; i14 < length; i14++) {
                        C3710.InterfaceC3712 interfaceC3712 = c3710.f11440[i14];
                        if (interfaceC3712 instanceof C3752) {
                            C3752 c3752 = (C3752) interfaceC3712;
                            int length2 = c3752.f11522.length;
                            int i15 = length2 + 1;
                            long[] jArr4 = new long[i15];
                            long[] jArr5 = new long[i15];
                            jArr4[0] = j8;
                            jArr5[0] = 0;
                            long j9 = 0;
                            for (int i16 = 1; i16 <= length2; i16++) {
                                int i17 = i16 - 1;
                                j8 += (long) (c3752.f11520 + c3752.f11522[i17]);
                                j9 += (long) (c3752.f11521 + c3752.f11523[i17]);
                                jArr4[i16] = j8;
                                jArr5[i16] = j9;
                            }
                            c3605 = new C3605(jArr4, jArr5);
                            if (c3606.f10825) {
                                c3606.f10824 = new InterfaceC3607.C3608();
                            } else {
                                if (c3605 != null) {
                                    c3606.f10824 = c3605;
                                } else if (interfaceC3607M5940 != null) {
                                    c3606.f10824 = interfaceC3607M5940;
                                }
                                InterfaceC3607 interfaceC3607 = c3606.f10824;
                                if (interfaceC3607 == null || (!interfaceC3607.mo5858() && (c3606.f10814 & 1) != 0)) {
                                    c3606.f10824 = m5940(c3558);
                                }
                            }
                            c3606.f10820.mo5893(c3606.f10824);
                            InterfaceC3575 interfaceC3575 = c3606.f10821;
                            C3569 c35694 = c3606.f10817;
                            String str = c35694.f10585;
                            int i18 = c35694.f10588;
                            int i19 = c35694.f10587;
                            C3567 c35673 = c3606.f10818;
                            interfaceC3575.mo5884(C3431.m5583((String) null, str, (String) null, -1, 4096, i18, i19, -1, c35673.f10574, c35673.f10575, (List<byte[]>) null, (C3526) null, 0, (String) null, (c3606.f10814 & 2) != 0 ? null : c3606.f10823));
                            c3606.f10828 = c35582.f10563;
                        }
                    }
                    c3605 = null;
                    if (c3606.f10825) {
                    }
                    c3606.f10820.mo5893(c3606.f10824);
                    InterfaceC3575 interfaceC35752 = c3606.f10821;
                    C3569 c356942 = c3606.f10817;
                    String str2 = c356942.f10585;
                    int i182 = c356942.f10588;
                    int i192 = c356942.f10587;
                    C3567 c356732 = c3606.f10818;
                    interfaceC35752.mo5884(C3431.m5583((String) null, str2, (String) null, -1, 4096, i182, i192, -1, c356732.f10574, c356732.f10575, (List<byte[]>) null, (C3526) null, 0, (String) null, (c3606.f10814 & 2) != 0 ? null : c3606.f10823));
                    c3606.f10828 = c35582.f10563;
                } else {
                    c3605 = null;
                    if (c3606.f10825) {
                    }
                    c3606.f10820.mo5893(c3606.f10824);
                    InterfaceC3575 interfaceC357522 = c3606.f10821;
                    C3569 c3569422 = c3606.f10817;
                    String str22 = c3569422.f10585;
                    int i1822 = c3569422.f10588;
                    int i1922 = c3569422.f10587;
                    C3567 c3567322 = c3606.f10818;
                    interfaceC357522.mo5884(C3431.m5583((String) null, str22, (String) null, -1, 4096, i1822, i1922, -1, c3567322.f10574, c3567322.f10575, (List<byte[]>) null, (C3526) null, 0, (String) null, (c3606.f10814 & 2) != 0 ? null : c3606.f10823));
                    c3606.f10828 = c35582.f10563;
                }
            }
        } else {
            c3606 = this;
            c35582 = c3558;
            long j10 = c3606.f10828;
            if (j10 != 0) {
                long j11 = c35582.f10563;
                if (j11 < j10) {
                    c35582.m5878((int) (j10 - j11));
                }
            }
        }
        if (c3606.f10829 == 0) {
            c35582.f10565 = 0;
            if (!m5941(c3558)) {
                c3606.f10816.m6693(0);
                int iM66884 = c3606.f10816.m6688();
                if (!m5938(iM66884, c3606.f10822) || C3569.m5901(iM66884) == -1) {
                    c35582.m5878(1);
                    c3606.f10822 = 0;
                    return 0;
                }
                C3569.m5903(iM66884, c3606.f10817);
                if (c3606.f10826 == -9223372036854775807L) {
                    c3606.f10826 = c3606.f10824.mo5934(c35582.f10563);
                    if (c3606.f10815 != -9223372036854775807L) {
                        c3606.f10826 = (c3606.f10815 - c3606.f10824.mo5934(0L)) + c3606.f10826;
                    }
                }
                c3606.f10829 = c3606.f10817.f10586;
            }
            return -1;
        }
        int iMo5882 = c3606.f10821.mo5882(c35582, c3606.f10829, true);
        if (iMo5882 != -1) {
            int i20 = c3606.f10829 - iMo5882;
            c3606.f10829 = i20;
            if (i20 <= 0) {
                long j12 = c3606.f10826;
                long j13 = c3606.f10827 * 1000000;
                C3569 c35695 = c3606.f10817;
                c3606.f10821.mo5883((j13 / ((long) c35695.f10587)) + j12, 1, c35695.f10586, 0, null);
                c3606.f10827 += (long) c3606.f10817.f10590;
                c3606.f10829 = 0;
            }
            return 0;
        }
        return -1;
    }

    @Override // p138.p176.p177.p190.p198.InterfaceC3561
    /* JADX INFO: renamed from: ֏ */
    public void mo5887() {
    }

    @Override // p138.p176.p177.p190.p198.InterfaceC3561
    /* JADX INFO: renamed from: ֏ */
    public void mo5888(long j, long j2) {
        this.f10822 = 0;
        this.f10826 = -9223372036854775807L;
        this.f10827 = 0L;
        this.f10829 = 0;
    }

    @Override // p138.p176.p177.p190.p198.InterfaceC3561
    /* JADX INFO: renamed from: ֏ */
    public void mo5889(InterfaceC3562 interfaceC3562) {
        this.f10820 = interfaceC3562;
        this.f10821 = interfaceC3562.mo5891(0, 1);
        this.f10820.mo5892();
    }

    @Override // p138.p176.p177.p190.p198.InterfaceC3561
    /* JADX INFO: renamed from: ֏ */
    public boolean mo5890(C3558 c3558) {
        return m5939(c3558, true);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final boolean m5939(C3558 c3558, boolean z) throws InterruptedException, ParserException, EOFException {
        int i;
        int iM5872;
        int iM5901;
        int i2 = z ? 16384 : 131072;
        c3558.f10565 = 0;
        if (c3558.f10563 == 0) {
            C3710 c3710M5900 = this.f10819.m5900(c3558, (this.f10814 & 2) == 0 ? null : f10813);
            this.f10823 = c3710M5900;
            if (c3710M5900 != null) {
                this.f10818.m5899(c3710M5900);
            }
            iM5872 = (int) c3558.m5872();
            if (!z) {
                c3558.m5878(iM5872);
            }
            i = 0;
        } else {
            i = 0;
            iM5872 = 0;
        }
        int i3 = 0;
        int i4 = 0;
        while (true) {
            if (!m5941(c3558)) {
                this.f10816.m6693(0);
                int iM6688 = this.f10816.m6688();
                if ((i == 0 || m5938(iM6688, i)) && (iM5901 = C3569.m5901(iM6688)) != -1) {
                    i3++;
                    if (i3 != 1) {
                        if (i3 == 4) {
                            break;
                        }
                    } else {
                        C3569.m5903(iM6688, this.f10817);
                        i = iM6688;
                    }
                    c3558.m5874(iM5901 - 4, false);
                } else {
                    int i5 = i4 + 1;
                    if (i4 == i2) {
                        if (z) {
                            return false;
                        }
                        throw new ParserException("Searched too many bytes.");
                    }
                    if (z) {
                        c3558.f10565 = 0;
                        c3558.m5874(iM5872 + i5, false);
                    } else {
                        c3558.m5878(1);
                    }
                    i4 = i5;
                    i = 0;
                    i3 = 0;
                }
            } else if (i3 <= 0) {
                throw new EOFException();
            }
        }
        if (z) {
            c3558.m5878(iM5872 + i4);
        } else {
            c3558.f10565 = 0;
        }
        this.f10822 = i;
        return true;
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final InterfaceC3607 m5940(C3558 c3558) {
        c3558.m5875(this.f10816.f13227, 0, 4, false);
        this.f10816.m6693(0);
        C3569.m5903(this.f10816.m6688(), this.f10817);
        return new C3604(c3558.f10562, c3558.f10563, this.f10817);
    }

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final boolean m5941(C3558 c3558) {
        InterfaceC3607 interfaceC3607 = this.f10824;
        if (interfaceC3607 != null) {
            long jMo5935 = interfaceC3607.mo5935();
            if (jMo5935 != -1 && c3558.m5872() > jMo5935 - 4) {
                return true;
            }
        }
        try {
            return !c3558.m5875(this.f10816.f13227, 0, 4, true);
        } catch (EOFException unused) {
            return true;
        }
    }
}
