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

import com.google.android.exoplayer2.ParserException;
import java.io.EOFException;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import p000.p001.p002.p003.p004.C0567;
import p138.p176.p177.p190.p198.C3558;
import p138.p176.p177.p190.p198.C3564;
import p138.p176.p177.p190.p198.C3566;
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.InterfaceC3571;
import p138.p176.p177.p190.p198.InterfaceC3575;
import p138.p176.p177.p190.p210.C3710;
import p138.p176.p177.p190.p210.p212.C3724;
import p138.p176.p177.p190.p239.C4128;
import p138.p176.p177.p190.p239.C4139;
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 C3586 implements InterfaceC3561 {

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

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

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

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

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

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

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

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

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

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final byte[] f10639 = new byte[42];

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final C4140 f10640 = new C4140(new byte[32768], 0);

    /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
    public final boolean f10641 = false;

    /* JADX INFO: renamed from: ށ, reason: contains not printable characters */
    public final C3564.C3565 f10642 = new C3564.C3565();

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public int f10645 = 0;

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r4v0 */
    /* JADX WARN: Type inference failed for: r4v10, types: [boolean, int] */
    /* JADX WARN: Type inference failed for: r4v14 */
    @Override // p138.p176.p177.p190.p198.InterfaceC3561
    /* JADX INFO: renamed from: ֏ */
    public int mo5886(C3558 c3558, C3570 c3570) throws InterruptedException, ParserException, EOFException {
        boolean z;
        C4128 c4128;
        InterfaceC3571 c3573;
        long j;
        boolean zM5895;
        int i = this.f10645;
        ?? r4 = 0;
        if (i == 0) {
            boolean z2 = !this.f10641;
            c3558.f10565 = 0;
            long jM5872 = c3558.m5872();
            C3710 c3710M1872 = C0567.m1872(c3558, z2);
            c3558.m5878((int) (c3558.m5872() - jM5872));
            this.f10646 = c3710M1872;
            this.f10645 = 1;
            return 0;
        }
        if (i == 1) {
            byte[] bArr = this.f10639;
            c3558.m5875(bArr, 0, bArr.length, false);
            c3558.f10565 = 0;
            this.f10645 = 2;
            return 0;
        }
        int i2 = 24;
        int i3 = 4;
        int i4 = 3;
        if (i == 2) {
            byte[] bArr2 = new byte[4];
            c3558.m5877(bArr2, 0, 4, false);
            if ((((((long) bArr2[0]) & 255) << 24) | ((((long) bArr2[1]) & 255) << 16) | ((((long) bArr2[2]) & 255) << 8) | (((long) bArr2[3]) & 255)) != 1716281667) {
                throw new ParserException("Failed to read FLAC stream marker.");
            }
            this.f10645 = 3;
            return 0;
        }
        if (i == 3) {
            C4128 c4128M6642 = this.f10647;
            boolean z3 = false;
            while (!z3) {
                c3558.f10565 = r4;
                C4139 c4139 = new C4139(new byte[i3]);
                c3558.m5875(c4139.f13223, r4, i3, r4);
                boolean zM6677 = c4139.m6677();
                int iM6667 = c4139.m6667(i);
                int iM66672 = c4139.m6667(i2) + i3;
                if (iM6667 == 0) {
                    byte[] bArr3 = new byte[38];
                    c3558.m5877(bArr3, r4, 38, r4);
                    c4128M6642 = new C4128(bArr3, i3);
                } else {
                    if (c4128M6642 == null) {
                        throw new IllegalArgumentException();
                    }
                    if (iM6667 == i4) {
                        C4140 c4140 = new C4140(iM66672);
                        c3558.m5877(c4140.f13227, r4, iM66672, r4);
                        c4128M6642 = c4128M6642.m6642(C0567.m1930(c4140));
                    } else {
                        if (iM6667 == i3) {
                            C4140 c41402 = new C4140(iM66672);
                            c3558.m5877(c41402.f13227, r4, iM66672, r4);
                            c41402.m6695(i3);
                            c4128 = new C4128(c4128M6642.f13180, c4128M6642.f13181, c4128M6642.f13182, c4128M6642.f13183, c4128M6642.f13184, c4128M6642.f13186, c4128M6642.f13187, c4128M6642.f13189, c4128M6642.f13190, c4128M6642.m6641(C4128.m6636((List<String>) Arrays.asList(C0567.m1869(c41402, (boolean) r4, (boolean) r4).f10607), (List<C3724>) Collections.emptyList())));
                            z = zM6677;
                        } else if (iM6667 == 6) {
                            C4140 c41403 = new C4140(iM66672);
                            c3558.m5877(c41403.f13227, r4, iM66672, r4);
                            c41403.m6695(4);
                            int iM6688 = c41403.m6688();
                            String strM6681 = c41403.m6681(c41403.m6688(), Charset.forName("US-ASCII"));
                            String strM6687 = c41403.m6687(c41403.m6688());
                            int iM66882 = c41403.m6688();
                            int iM66883 = c41403.m6688();
                            int iM66884 = c41403.m6688();
                            int iM66885 = c41403.m6688();
                            int iM66886 = c41403.m6688();
                            byte[] bArr4 = new byte[iM66886];
                            System.arraycopy(c41403.f13227, c41403.f13228, bArr4, r4, iM66886);
                            c41403.f13228 += iM66886;
                            z = zM6677;
                            c4128 = new C4128(c4128M6642.f13180, c4128M6642.f13181, c4128M6642.f13182, c4128M6642.f13183, c4128M6642.f13184, c4128M6642.f13186, c4128M6642.f13187, c4128M6642.f13189, c4128M6642.f13190, c4128M6642.m6641(C4128.m6636((List<String>) Collections.emptyList(), (List<C3724>) Collections.singletonList(new C3724(iM6688, strM6681, strM6687, iM66882, iM66883, iM66884, iM66885, bArr4)))));
                        } else {
                            z = zM6677;
                            c3558.m5878(iM66672);
                            C4150.m6755(c4128M6642);
                            this.f10647 = c4128M6642;
                            z3 = z;
                            r4 = 0;
                            i2 = 24;
                            i3 = 4;
                            i4 = 3;
                            i = 7;
                        }
                        c4128M6642 = c4128;
                        C4150.m6755(c4128M6642);
                        this.f10647 = c4128M6642;
                        z3 = z;
                        r4 = 0;
                        i2 = 24;
                        i3 = 4;
                        i4 = 3;
                        i = 7;
                    }
                }
                z = zM6677;
                C4150.m6755(c4128M6642);
                this.f10647 = c4128M6642;
                z3 = z;
                r4 = 0;
                i2 = 24;
                i3 = 4;
                i4 = 3;
                i = 7;
            }
            C0567.m1856(this.f10647);
            this.f10648 = Math.max(this.f10647.f13182, 6);
            InterfaceC3575 interfaceC3575 = this.f10644;
            C4150.m6755(interfaceC3575);
            interfaceC3575.mo5884(this.f10647.m6640(this.f10639, this.f10646));
            this.f10645 = 4;
            return 0;
        }
        long j2 = 0;
        if (i == 4) {
            c3558.f10565 = 0;
            byte[] bArr5 = new byte[2];
            c3558.m5875(bArr5, 0, 2, false);
            int i5 = (bArr5[1] & 255) | ((bArr5[0] & 255) << 8);
            if ((i5 >> 2) != 16382) {
                c3558.f10565 = 0;
                throw new ParserException("First frame does not start with sync code.");
            }
            c3558.f10565 = 0;
            this.f10649 = i5;
            InterfaceC3562 interfaceC3562 = this.f10643;
            C4150.m6755(interfaceC3562);
            long j3 = c3558.f10563;
            long j4 = c3558.f10562;
            C0567.m1856(this.f10647);
            C4128 c41282 = this.f10647;
            if (c41282.f13190 != null) {
                c3573 = new C3566(c41282, j3);
            } else if (j4 == -1 || c41282.f13189 <= 0) {
                c3573 = new InterfaceC3571.C3573(this.f10647.m6638(), 0L);
            } else {
                C3583 c3583 = new C3583(c41282, this.f10649, j3, j4);
                this.f10650 = c3583;
                c3573 = c3583.f10525;
            }
            interfaceC3562.mo5893(c3573);
            this.f10645 = 5;
            return 0;
        }
        if (i != 5) {
            throw new IllegalStateException();
        }
        C0567.m1856(this.f10644);
        C0567.m1856(this.f10647);
        C3583 c35832 = this.f10650;
        if (c35832 != null && c35832.m5855()) {
            return this.f10650.m5852(c3558, c3570);
        }
        if (this.f10652 == -1) {
            C4128 c41283 = this.f10647;
            c3558.f10565 = 0;
            c3558.m5874(1, false);
            byte[] bArr6 = new byte[1];
            c3558.m5875(bArr6, 0, 1, false);
            boolean z4 = (bArr6[0] & 1) == 1;
            c3558.m5874(2, false);
            i = z4 ? 7 : 6;
            C4140 c41404 = new C4140(i);
            c41404.m6691(C0567.m1846(c3558, c41404.f13227, 0, i));
            c3558.f10565 = 0;
            try {
                long jM6708 = c41404.m6708();
                if (!z4) {
                    jM6708 *= (long) c41283.f13181;
                }
                j2 = jM6708;
            } catch (NumberFormatException unused) {
                z = false;
            }
            if (!z) {
                throw new ParserException();
            }
            this.f10652 = j2;
            return 0;
        }
        C4140 c41405 = this.f10640;
        int i6 = c41405.f13229;
        if (i6 < 32768) {
            int iM5870 = c3558.m5870(c41405.f13227, i6, 32768 - i6);
            z = iM5870 == -1;
            if (!z) {
                this.f10640.m6691(i6 + iM5870);
            } else if (this.f10640.m6679() == 0) {
                m5911();
                return -1;
            }
        } else {
            z = false;
        }
        C4140 c41406 = this.f10640;
        int i7 = c41406.f13228;
        int i8 = this.f10651;
        int i9 = this.f10648;
        if (i8 < i9) {
            c41406.m6695(Math.min(i9 - i8, c41406.m6679()));
        }
        C4140 c41407 = this.f10640;
        C0567.m1856(this.f10647);
        int i10 = c41407.f13228;
        while (true) {
            if (i10 <= c41407.f13229 - 16) {
                c41407.m6693(i10);
                if (C3564.m5895(c41407, this.f10647, this.f10649, this.f10642)) {
                    c41407.m6693(i10);
                    j = this.f10642.f10570;
                    break;
                }
                i10++;
            } else {
                if (z) {
                    while (true) {
                        int i11 = c41407.f13229;
                        if (i10 > i11 - this.f10648) {
                            c41407.m6693(i11);
                            break;
                        }
                        c41407.m6693(i10);
                        try {
                            zM5895 = C3564.m5895(c41407, this.f10647, this.f10649, this.f10642);
                        } catch (IndexOutOfBoundsException unused2) {
                            zM5895 = false;
                        }
                        if (c41407.f13228 > c41407.f13229) {
                            zM5895 = false;
                        }
                        if (zM5895) {
                            c41407.m6693(i10);
                            j = this.f10642.f10570;
                            break;
                        }
                        i10++;
                    }
                } else {
                    c41407.m6693(i10);
                }
                j = -1;
            }
        }
        C4140 c41408 = this.f10640;
        int i12 = c41408.f13228 - i7;
        c41408.m6693(i7);
        this.f10644.mo5885(this.f10640, i12);
        this.f10651 += i12;
        if (j != -1) {
            m5911();
            this.f10651 = 0;
            this.f10652 = j;
        }
        if (this.f10640.m6679() >= 16) {
            return 0;
        }
        C4140 c41409 = this.f10640;
        byte[] bArr7 = c41409.f13227;
        System.arraycopy(bArr7, c41409.f13228, bArr7, 0, c41409.m6679());
        C4140 c414010 = this.f10640;
        c414010.m6689(c414010.m6679());
        return 0;
    }

    @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) {
        if (j == 0) {
            this.f10645 = 0;
        } else {
            C3583 c3583 = this.f10650;
            if (c3583 != null) {
                c3583.m5853(j2);
            }
        }
        this.f10652 = j2 != 0 ? -1L : 0L;
        this.f10651 = 0;
        this.f10640.m6709();
    }

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

    @Override // p138.p176.p177.p190.p198.InterfaceC3561
    /* JADX INFO: renamed from: ֏ */
    public boolean mo5890(C3558 c3558) throws InterruptedException, EOFException {
        C0567.m1872(c3558, false);
        byte[] bArr = new byte[4];
        c3558.m5875(bArr, 0, 4, false);
        return (((((((long) bArr[0]) & 255) << 24) | ((((long) bArr[1]) & 255) << 16)) | ((((long) bArr[2]) & 255) << 8)) | (255 & ((long) bArr[3]))) == 1716281667;
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final void m5911() {
        long j = this.f10652 * 1000000;
        C4128 c4128 = this.f10647;
        C4150.m6755(c4128);
        this.f10644.mo5883(j / ((long) c4128.f13184), 1, this.f10651, 0, null);
    }
}
