package defpackage;

import androidx.media3.common.ParserException;
import java.util.Arrays;
import java.util.List;

/* renamed from: ᵾˋᵦʠ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C5407 implements InterfaceC2689 {

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

    /* renamed from: ˌᵜᵹᵩ, reason: contains not printable characters */
    public C3442 f20251;

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

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

    /* renamed from: ᵪʩ, reason: contains not printable characters */
    public long f20257;

    /* renamed from: ᵯٴᵦ, reason: contains not printable characters */
    public int f20258;

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

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public int f20261;

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

    /* renamed from: ᵥᵯˎ, reason: contains not printable characters */
    public final byte[] f20256 = new byte[42];

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public final C3493 f20259 = new C3493(0, new byte[32768]);

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public final boolean f20254 = false;

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

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public int f20252 = 0;

    @Override // defpackage.InterfaceC2689
    /* renamed from: ˇʼʤˎ */
    public final boolean mo1572(InterfaceC1383 interfaceC1383) {
        C3034 c3034M7451 = new C3115(0).m7451(interfaceC1383, C0415.f2316, 0);
        if (c3034M7451 != null) {
            int length = c3034M7451.f11675.length;
        }
        C3493 c3493 = new C3493(4);
        ((C1938) interfaceC1383).mo4251(c3493.f13082, 0, 4, false);
        return c3493.m7954() == 1716281667;
    }

    @Override // defpackage.InterfaceC2689
    /* renamed from: ˎˏʜʾ */
    public final void mo1573(InterfaceC1982 interfaceC1982) {
        this.f20250 = interfaceC1982;
        this.f20253 = interfaceC1982.mo4996(0, 1);
        interfaceC1982.mo4985();
    }

    @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) {
        if (j == 0) {
            this.f20252 = 0;
        } else {
            C3442 c3442 = this.f20251;
            if (c3442 != null) {
                c3442.m7819(j2);
            }
        }
        this.f20257 = j2 != 0 ? -1L : 0L;
        this.f20258 = 0;
        this.f20259.m7939(0);
    }

    @Override // defpackage.InterfaceC2689
    /* renamed from: ᵻᵢﹳᵰ */
    public final int mo1578(InterfaceC1383 interfaceC1383, C4184 c4184) throws ParserException {
        C4900 c4900;
        int i;
        InterfaceC5013 c3300;
        long j;
        long j2;
        boolean z;
        long jM7949;
        long j3;
        int i2 = this.f20252;
        C3034 c3034 = null;
        if (i2 == 0) {
            interfaceC1383.mo4245();
            long jMo4244 = interfaceC1383.mo4244();
            C3034 c3034M7451 = new C3115(0).m7451(interfaceC1383, !this.f20254 ? null : C0415.f2316, 0);
            if (c3034M7451 != null && c3034M7451.f11675.length != 0) {
                c3034 = c3034M7451;
            }
            interfaceC1383.mo4248((int) (interfaceC1383.mo4244() - jMo4244));
            this.f20262 = c3034;
            this.f20252 = 1;
            return 0;
        }
        byte[] bArr = this.f20256;
        if (i2 == 1) {
            interfaceC1383.mo4249(bArr, 0, bArr.length);
            interfaceC1383.mo4245();
            this.f20252 = 2;
            return 0;
        }
        int i3 = 4;
        int i4 = 3;
        if (i2 == 2) {
            C3493 c3493 = new C3493(4);
            interfaceC1383.readFully(c3493.f13082, 0, 4);
            if (c3493.m7954() != 1716281667) {
                throw ParserException.m356("Failed to read FLAC stream marker.", null);
            }
            this.f20252 = 3;
            return 0;
        }
        int i5 = 6;
        if (i2 == 3) {
            int i6 = 0;
            C4900 c49002 = this.f20255;
            boolean z2 = false;
            while (!z2) {
                interfaceC1383.mo4245();
                byte[] bArr2 = new byte[i3];
                C4089 c4089 = new C4089(i3, bArr2);
                int i7 = i6;
                interfaceC1383.mo4249(bArr2, i7, i3);
                boolean zM8964 = c4089.m8964();
                int iM8966 = c4089.m8966(i);
                int iM89662 = c4089.m8966(24) + i3;
                if (iM8966 == 0) {
                    byte[] bArr3 = new byte[38];
                    interfaceC1383.readFully(bArr3, i7, 38);
                    c49002 = new C4900(i3, bArr3);
                } else {
                    if (c49002 == null) {
                        ᵨᴵᵺ.ᵻᵢﹳᵰ();
                        return 0;
                    }
                    C3034 c30342 = c49002.f18237;
                    if (iM8966 == i4) {
                        C3493 c34932 = new C3493(iM89662);
                        interfaceC1383.readFully(c34932.f13082, i7, iM89662);
                        c49002 = new C4900(c49002.f18242, c49002.f18243, c49002.f18240, c49002.f18247, c49002.f18236, c49002.f18238, c49002.f18246, c49002.f18244, ˀʾˀᵛ.ˀᵗᵝᵭ(c34932), c49002.f18237);
                    } else {
                        if (iM8966 == i3) {
                            C3493 c34933 = new C3493(iM89662);
                            interfaceC1383.readFully(c34933.f13082, 0, iM89662);
                            c34933.m7946(i3);
                            C3034 c3034M7374 = ᵺᵣᵬ.ᵤᵙᵷ(Arrays.asList((String[]) ᵺᵣᵬ.ᵡⁱᵥ(c34933, false, false).f19645));
                            if (c30342 != null) {
                                c3034M7374 = c30342.m7374(c3034M7374);
                            }
                            c4900 = new C4900(c49002.f18242, c49002.f18243, c49002.f18240, c49002.f18247, c49002.f18236, c49002.f18238, c49002.f18246, c49002.f18244, c49002.f18245, c3034M7374);
                        } else if (iM8966 == i5) {
                            C3493 c34934 = new C3493(iM89662);
                            interfaceC1383.readFully(c34934.f13082, 0, iM89662);
                            c34934.m7946(4);
                            C3034 c30343 = new C3034(AbstractC2692.m6702(C0530.m2321(c34934)));
                            if (c30342 != null) {
                                c30343 = c30342.m7374(c30343);
                            }
                            c4900 = new C4900(c49002.f18242, c49002.f18243, c49002.f18240, c49002.f18247, c49002.f18236, c49002.f18238, c49002.f18246, c49002.f18244, c49002.f18245, c30343);
                        } else {
                            interfaceC1383.mo4248(iM89662);
                        }
                        c49002 = c4900;
                    }
                }
                String str = AbstractC3558.f13329;
                this.f20255 = c49002;
                z2 = zM8964;
                i3 = 4;
                i4 = 3;
                i = 7;
                i5 = 6;
                i6 = 0;
            }
            this.f20255.getClass();
            this.f20260 = Math.max(this.f20255.f18240, 6);
            C3446 c3446M10347 = this.f20255.m10347(bArr, this.f20262);
            InterfaceC2154 interfaceC2154 = this.f20253;
            C2153 c2153M7829 = c3446M10347.m7829();
            c2153M7829.f8518 = AbstractC2924.m7101("audio/flac");
            AbstractC4737.m10004(c2153M7829, interfaceC2154);
            this.f20253.mo4412(this.f20255.m10348());
            this.f20252 = 4;
            return 0;
        }
        long j4 = 0;
        if (i2 == 4) {
            interfaceC1383.mo4245();
            C3493 c34935 = new C3493(2);
            interfaceC1383.mo4249(c34935.f13082, 0, 2);
            int iM7972 = c34935.m7972();
            if ((iM7972 >> 2) != 16382) {
                interfaceC1383.mo4245();
                throw ParserException.m356("First frame does not start with sync code.", null);
            }
            interfaceC1383.mo4245();
            this.f20261 = iM7972;
            InterfaceC1982 interfaceC1982 = this.f20250;
            String str2 = AbstractC3558.f13329;
            long position = interfaceC1383.getPosition();
            long length = interfaceC1383.getLength();
            this.f20255.getClass();
            C4900 c49003 = this.f20255;
            C2720 c2720 = c49003.f18245;
            if (c2720 != null && ((long[]) c2720.f10548).length > 0) {
                c3300 = new C3300(c49003, position, 1);
                i = 0;
            } else if (length == -1 || c49003.f18244 <= 0) {
                i = 0;
                c3300 = new C3300(c49003.m10348());
            } else {
                int i8 = this.f20261;
                int i9 = c49003.f18240;
                ʾᵛ r9 = new ʾᵛ(27, c49003);
                C4782 c4782 = new C4782(c49003, i8);
                long jM10348 = c49003.m10348();
                long j5 = c49003.f18244;
                int i10 = c49003.f18247;
                if (i10 > 0) {
                    i = 0;
                    j = ((i10 + i9) / 2) + 1;
                } else {
                    i = 0;
                    int i11 = c49003.f18242;
                    j = 64 + (((((i11 != c49003.f18243 || i11 <= 0) ? 4096L : i11) * c49003.f18238) * c49003.f18246) / 8);
                }
                C3442 c3442 = new C3442(r9, c4782, jM10348, j5, position, length, j, Math.max(6, i9));
                this.f20251 = c3442;
                c3300 = c3442.f12877;
            }
            interfaceC1982.mo4987(c3300);
            this.f20252 = 5;
            return i;
        }
        if (i2 != 5) {
            ᵨᴵᵺ.ˌʾˀ();
            return 0;
        }
        this.f20253.getClass();
        this.f20255.getClass();
        C3442 c34422 = this.f20251;
        if (c34422 != null && c34422.f12876 != null) {
            return c34422.m7818(interfaceC1383, c4184);
        }
        if (this.f20257 == -1) {
            C4900 c49004 = this.f20255;
            interfaceC1383.mo4245();
            interfaceC1383.mo4250(1);
            byte[] bArr4 = new byte[1];
            interfaceC1383.mo4249(bArr4, 0, 1);
            boolean z3 = (bArr4[0] & 1) == 1;
            interfaceC1383.mo4250(2);
            i = z3 ? 7 : 6;
            C3493 c34936 = new C3493(i);
            byte[] bArr5 = c34936.f13082;
            int i12 = 0;
            while (i12 < i) {
                int iMo4247 = interfaceC1383.mo4247(bArr5, i12, i - i12);
                if (iMo4247 == -1) {
                    break;
                }
                i12 += iMo4247;
            }
            c34936.m7950(i12);
            interfaceC1383.mo4245();
            try {
                jM7949 = c34936.m7949();
                if (!z3) {
                    jM7949 *= c49004.f18243;
                }
                j3 = c49004.f18244;
            } catch (NumberFormatException unused) {
            }
            if (j3 == 0 || jM7949 <= j3) {
                j4 = jM7949;
            } else {
                z = false;
            }
            if (!z) {
                throw ParserException.m356(null, null);
            }
            this.f20257 = j4;
        } else {
            C3493 c34937 = this.f20259;
            int i13 = c34937.f13081;
            if (i13 < 32768) {
                int i14 = interfaceC1383.read(c34937.f13082, i13, 32768 - i13);
                z = i14 == -1;
                if (!z) {
                    c34937.m7950(i13 + i14);
                } else if (c34937.m7959() == 0) {
                    long j6 = this.f20257 * 1000000;
                    C4900 c49005 = this.f20255;
                    String str3 = AbstractC3558.f13329;
                    this.f20253.mo4410(j6 / c49005.f18236, 1, this.f20258, 0, null);
                    return -1;
                }
            } else {
                z = false;
            }
            int i15 = c34937.f13083;
            int i16 = this.f20258;
            int i17 = this.f20260;
            if (i16 < i17) {
                c34937.m7946(Math.min(i17 - i16, c34937.m7959()));
            }
            this.f20255.getClass();
            int i18 = c34937.f13083;
            while (true) {
                int i19 = c34937.f13081 - 16;
                C4184 c41842 = this.f20263;
                if (i18 <= i19) {
                    c34937.m7955(i18);
                    if (ˋˌ.ˏˋٴ(c34937, this.f20255, this.f20261, c41842)) {
                        c34937.m7955(i18);
                        j2 = c41842.f15658;
                        break;
                    }
                    i18++;
                } else {
                    if (z) {
                        while (true) {
                            int i20 = c34937.f13081;
                            if (i18 > i20 - this.f20260) {
                                c34937.m7955(i20);
                                break;
                            }
                            c34937.m7955(i18);
                            try {
                                z = ˋˌ.ˏˋٴ(c34937, this.f20255, this.f20261, c41842);
                            } catch (IndexOutOfBoundsException unused2) {
                                z = false;
                            }
                            if (c34937.f13083 > c34937.f13081) {
                                z = false;
                            }
                            if (z) {
                                c34937.m7955(i18);
                                j2 = c41842.f15658;
                                break;
                            }
                            i18++;
                        }
                    } else {
                        c34937.m7955(i18);
                    }
                    j2 = -1;
                }
            }
            int i21 = c34937.f13083 - i15;
            c34937.m7955(i15);
            this.f20253.mo4406(i21, c34937);
            int i22 = this.f20258 + i21;
            this.f20258 = i22;
            if (j2 != -1) {
                long j7 = this.f20257 * 1000000;
                C4900 c49006 = this.f20255;
                String str4 = AbstractC3558.f13329;
                this.f20253.mo4410(j7 / c49006.f18236, 1, i22, 0, null);
                this.f20258 = 0;
                this.f20257 = j2;
            }
            int length2 = c34937.f13082.length - c34937.f13081;
            if (c34937.m7959() < 16 && length2 < 16) {
                int iM7959 = c34937.m7959();
                byte[] bArr6 = c34937.f13082;
                System.arraycopy(bArr6, c34937.f13083, bArr6, 0, iM7959);
                c34937.m7955(0);
                c34937.m7950(iM7959);
            }
        }
        return 0;
    }
}
