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

import android.util.Log;
import com.google.android.exoplayer2.ParserException;
import java.util.ArrayList;
import java.util.Arrays;
import p000.p001.p002.p003.p004.C0567;
import p138.p139.p143.p144.C2803;
import p138.p176.p177.p190.C3431;
import p138.p176.p177.p190.p198.C3577;
import p138.p176.p177.p190.p198.C3578;
import p138.p176.p177.p190.p198.C3579;
import p138.p176.p177.p190.p198.C3580;
import p138.p176.p177.p190.p198.p205.AbstractC3644;
import p138.p176.p177.p190.p239.C4140;

/* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ೲ.ޛ.ކ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
public final class C3648 extends AbstractC3644 {

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

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

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

    /* JADX INFO: renamed from: ގ, reason: contains not printable characters */
    public C3580 f11047;

    /* JADX INFO: renamed from: ޏ, reason: contains not printable characters */
    public C3578 f11048;

    /* JADX INFO: renamed from: ދ.ހ.֏.ؠ.ೲ.ޛ.ކ$֏, reason: contains not printable characters */
    public static final class C3649 {

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

        /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
        public final byte[] f11050;

        /* JADX INFO: renamed from: ހ, reason: contains not printable characters */
        public final C3579[] f11051;

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

        public C3649(C3580 c3580, C3578 c3578, byte[] bArr, C3579[] c3579Arr, int i) {
            this.f11049 = c3580;
            this.f11050 = bArr;
            this.f11051 = c3579Arr;
            this.f11052 = i;
        }
    }

    @Override // p138.p176.p177.p190.p198.p205.AbstractC3644
    /* JADX INFO: renamed from: ֏ */
    public long mo5986(C4140 c4140) {
        byte[] bArr = c4140.f13227;
        if ((bArr[0] & 1) == 1) {
            return -1L;
        }
        byte b = bArr[0];
        C3649 c3649 = this.f11044;
        int i = !c3649.f11051[(b >> 1) & (255 >>> (8 - c3649.f11052))].f10608 ? c3649.f11049.f10612 : c3649.f11049.f10613;
        long j = this.f11046 ? (this.f11045 + i) / 4 : 0;
        c4140.m6691(c4140.f13229 + 4);
        byte[] bArr2 = c4140.f13227;
        int i2 = c4140.f13229;
        bArr2[i2 - 4] = (byte) (j & 255);
        bArr2[i2 - 3] = (byte) ((j >>> 8) & 255);
        bArr2[i2 - 2] = (byte) ((j >>> 16) & 255);
        bArr2[i2 - 1] = (byte) ((j >>> 24) & 255);
        this.f11046 = true;
        this.f11045 = i;
        return j;
    }

    @Override // p138.p176.p177.p190.p198.p205.AbstractC3644
    /* JADX INFO: renamed from: ֏ */
    public void mo5987(boolean z) {
        super.mo5987(z);
        if (z) {
            this.f11044 = null;
            this.f11047 = null;
            this.f11048 = null;
        }
        this.f11045 = 0;
        this.f11046 = false;
    }

    @Override // p138.p176.p177.p190.p198.p205.AbstractC3644
    /* JADX INFO: renamed from: ֏ */
    public boolean mo5988(C4140 c4140, long j, AbstractC3644.C3646 c3646) throws ParserException {
        C3649 c3649;
        if (this.f11044 != null) {
            return false;
        }
        if (this.f11047 == null) {
            C0567.m1900(1, c4140, false);
            long jM6696 = c4140.m6696();
            int iM6702 = c4140.m6702();
            long jM66962 = c4140.m6696();
            int iM6692 = c4140.m6692();
            int iM66922 = c4140.m6692();
            int iM66923 = c4140.m6692();
            int iM67022 = c4140.m6702();
            this.f11047 = new C3580(jM6696, iM6702, jM66962, iM6692, iM66922, iM66923, (int) Math.pow(2.0d, iM67022 & 15), (int) Math.pow(2.0d, (iM67022 & 240) >> 4), (c4140.m6702() & 1) > 0, Arrays.copyOf(c4140.f13227, c4140.f13229));
        } else if (this.f11048 == null) {
            this.f11048 = C0567.m1869(c4140, true, true);
        } else {
            int i = c4140.f13229;
            byte[] bArr = new byte[i];
            int i2 = 0;
            System.arraycopy(c4140.f13227, 0, bArr, 0, i);
            int i3 = this.f11047.f10609;
            int i4 = 5;
            C0567.m1900(5, c4140, false);
            int iM67023 = c4140.m6702() + 1;
            C3577 c3577 = new C3577(c4140.f13227);
            c3577.m5907(c4140.f13228 * 8);
            int i5 = 0;
            while (i5 < iM67023) {
                if (c3577.m5905(24) != 5653314) {
                    StringBuilder sbM4889 = C2803.m4889("expected code book to start with [0x56, 0x43, 0x42] at ");
                    sbM4889.append((c3577.f10605 * 8) + c3577.f10606);
                    throw new ParserException(sbM4889.toString());
                }
                int iM5905 = c3577.m5905(16);
                int iM59052 = c3577.m5905(24);
                long[] jArr = new long[iM59052];
                if (c3577.m5906()) {
                    int iM59053 = c3577.m5905(5) + 1;
                    int i6 = 0;
                    while (i6 < iM59052) {
                        int iM59054 = c3577.m5905(C0567.m1841(iM59052 - i6));
                        for (int i7 = 0; i7 < iM59054 && i6 < iM59052; i7++) {
                            jArr[i6] = iM59053;
                            i6++;
                        }
                        iM59053++;
                    }
                } else {
                    boolean zM5906 = c3577.m5906();
                    while (i2 < iM59052) {
                        if (!zM5906) {
                            jArr[i2] = c3577.m5905(5) + 1;
                        } else if (c3577.m5906()) {
                            jArr[i2] = c3577.m5905(5) + 1;
                        } else {
                            jArr[i2] = 0;
                        }
                        i2++;
                    }
                }
                int iM59055 = c3577.m5905(4);
                if (iM59055 > 2) {
                    throw new ParserException(C2803.m4871("lookup type greater than 2 not decodable: ", iM59055));
                }
                if (iM59055 == 1 || iM59055 == 2) {
                    c3577.m5907(32);
                    c3577.m5907(32);
                    int iM59056 = c3577.m5905(4) + 1;
                    c3577.m5907(1);
                    c3577.m5907((int) (((long) iM59056) * (iM59055 == 1 ? iM5905 != 0 ? (long) Math.floor(Math.pow(iM59052, 1.0d / ((double) iM5905))) : 0L : ((long) iM59052) * ((long) iM5905))));
                }
                i5++;
                i2 = 0;
            }
            int i8 = 6;
            int iM59057 = c3577.m5905(6) + 1;
            for (int i9 = 0; i9 < iM59057; i9++) {
                if (c3577.m5905(16) != 0) {
                    throw new ParserException("placeholder of time domain transforms not zeroed out");
                }
            }
            int i10 = 1;
            int iM59058 = c3577.m5905(6) + 1;
            int i11 = 0;
            while (true) {
                int i12 = 3;
                if (i11 < iM59058) {
                    int iM59059 = c3577.m5905(16);
                    if (iM59059 == 0) {
                        int i13 = 8;
                        c3577.m5907(8);
                        c3577.m5907(16);
                        c3577.m5907(16);
                        c3577.m5907(6);
                        c3577.m5907(8);
                        int iM590510 = c3577.m5905(4) + 1;
                        int i14 = 0;
                        while (i14 < iM590510) {
                            c3577.m5907(i13);
                            i14++;
                            i13 = 8;
                        }
                    } else {
                        if (iM59059 != i10) {
                            throw new ParserException(C2803.m4871("floor type greater than 1 not decodable: ", iM59059));
                        }
                        int iM590511 = c3577.m5905(i4);
                        int[] iArr = new int[iM590511];
                        int i15 = -1;
                        for (int i16 = 0; i16 < iM590511; i16++) {
                            iArr[i16] = c3577.m5905(4);
                            if (iArr[i16] > i15) {
                                i15 = iArr[i16];
                            }
                        }
                        int i17 = i15 + 1;
                        int[] iArr2 = new int[i17];
                        int i18 = 0;
                        while (i18 < i17) {
                            iArr2[i18] = c3577.m5905(i12) + 1;
                            int iM590512 = c3577.m5905(2);
                            int i19 = 8;
                            if (iM590512 > 0) {
                                c3577.m5907(8);
                            }
                            int i20 = 0;
                            for (int i21 = 1; i20 < (i21 << iM590512); i21 = 1) {
                                c3577.m5907(i19);
                                i20++;
                                i19 = 8;
                            }
                            i18++;
                            i12 = 3;
                        }
                        c3577.m5907(2);
                        int iM590513 = c3577.m5905(4);
                        int i22 = 0;
                        int i23 = 0;
                        for (int i24 = 0; i24 < iM590511; i24++) {
                            i22 += iArr2[iArr[i24]];
                            while (i23 < i22) {
                                c3577.m5907(iM590513);
                                i23++;
                            }
                        }
                    }
                    i11++;
                    i4 = 5;
                    i10 = 1;
                    i8 = 6;
                } else {
                    int iM590514 = c3577.m5905(i8);
                    int i25 = 1;
                    int i26 = iM590514 + 1;
                    int i27 = 0;
                    while (i27 < i26) {
                        if (c3577.m5905(16) > 2) {
                            throw new ParserException("residueType greater than 2 is not decodable");
                        }
                        c3577.m5907(24);
                        c3577.m5907(24);
                        c3577.m5907(24);
                        int iM590515 = c3577.m5905(6) + i25;
                        int i28 = 8;
                        c3577.m5907(8);
                        int[] iArr3 = new int[iM590515];
                        for (int i29 = 0; i29 < iM590515; i29++) {
                            iArr3[i29] = ((c3577.m5906() ? c3577.m5905(5) : 0) * 8) + c3577.m5905(3);
                        }
                        int i30 = 0;
                        while (i30 < iM590515) {
                            int i31 = 0;
                            while (i31 < i28) {
                                if ((iArr3[i30] & (1 << i31)) != 0) {
                                    c3577.m5907(i28);
                                }
                                i31++;
                                i28 = 8;
                            }
                            i30++;
                            i28 = 8;
                        }
                        i27++;
                        i25 = 1;
                    }
                    int iM590516 = c3577.m5905(6) + 1;
                    for (int i32 = 0; i32 < iM590516; i32++) {
                        int iM590517 = c3577.m5905(16);
                        if (iM590517 != 0) {
                            Log.e("VorbisUtil", "mapping type other than 0 not supported: " + iM590517);
                        } else {
                            int iM590518 = c3577.m5906() ? c3577.m5905(4) + 1 : 1;
                            if (c3577.m5906()) {
                                int iM590519 = c3577.m5905(8) + 1;
                                for (int i33 = 0; i33 < iM590519; i33++) {
                                    int i34 = i3 - 1;
                                    c3577.m5907(C0567.m1841(i34));
                                    c3577.m5907(C0567.m1841(i34));
                                }
                            }
                            if (c3577.m5905(2) != 0) {
                                throw new ParserException("to reserved bits must be zero after mapping coupling steps");
                            }
                            if (iM590518 > 1) {
                                for (int i35 = 0; i35 < i3; i35++) {
                                    c3577.m5907(4);
                                }
                            }
                            for (int i36 = 0; i36 < iM590518; i36++) {
                                c3577.m5907(8);
                                c3577.m5907(8);
                                c3577.m5907(8);
                            }
                        }
                    }
                    int iM590520 = c3577.m5905(6) + 1;
                    C3579[] c3579Arr = new C3579[iM590520];
                    for (int i37 = 0; i37 < iM590520; i37++) {
                        c3579Arr[i37] = new C3579(c3577.m5906(), c3577.m5905(16), c3577.m5905(16), c3577.m5905(8));
                    }
                    if (!c3577.m5906()) {
                        throw new ParserException("framing bit after modes not set as expected");
                    }
                    c3649 = new C3649(this.f11047, this.f11048, bArr, c3579Arr, C0567.m1841(iM590520 - 1));
                }
            }
        }
        c3649 = null;
        this.f11044 = c3649;
        if (c3649 == null) {
            return true;
        }
        ArrayList arrayList = new ArrayList();
        arrayList.add(this.f11044.f11049.f10614);
        arrayList.add(this.f11044.f11050);
        C3580 c3580 = this.f11044.f11049;
        c3646.f11042 = C3431.m5585(null, "audio/vorbis", null, c3580.f10611, -1, c3580.f10609, (int) c3580.f10610, arrayList, null, 0, null);
        return true;
    }

    @Override // p138.p176.p177.p190.p198.p205.AbstractC3644
    /* JADX INFO: renamed from: ؠ */
    public void mo5996(long j) {
        this.f11035 = j;
        this.f11046 = j != 0;
        C3580 c3580 = this.f11047;
        this.f11045 = c3580 != null ? c3580.f10612 : 0;
    }
}
