package o1;

import A1.I;
import B0.t0;
import C3.G;
import T0.AbstractC0302b;
import T0.H;
import T0.x;
import e0.C0853a;
import java.util.ArrayList;
import java.util.Arrays;
import u0.C1578n;
import u0.C1579o;
import u0.D;
import u0.E;
import u0.F;
import x0.AbstractC1709a;
import x0.o;

/* JADX INFO: renamed from: o1.j, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C1334j extends AbstractC1333i {

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public I f15625n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public int f15626o;

    /* JADX INFO: renamed from: p, reason: collision with root package name */
    public boolean f15627p;

    /* JADX INFO: renamed from: q, reason: collision with root package name */
    public x f15628q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public P.g f15629r;

    @Override // o1.AbstractC1333i
    public final void a(long j8) {
        this.f15619g = j8;
        this.f15627p = j8 != 0;
        x xVar = this.f15628q;
        this.f15626o = xVar != null ? xVar.f6479e : 0;
    }

    @Override // o1.AbstractC1333i
    public final long b(o oVar) {
        byte b8 = oVar.f18539a[0];
        if ((b8 & 1) == 1) {
            return -1L;
        }
        I i = this.f15625n;
        AbstractC1709a.k(i);
        boolean z8 = ((t0[]) i.f73v)[(b8 >> 1) & (255 >>> (8 - i.f69r))].f916b;
        x xVar = (x) i.f70s;
        int i5 = !z8 ? xVar.f6479e : xVar.f6480f;
        long j8 = this.f15627p ? (this.f15626o + i5) / 4 : 0;
        byte[] bArr = oVar.f18539a;
        int length = bArr.length;
        int i8 = oVar.f18541c + 4;
        if (length < i8) {
            byte[] bArrCopyOf = Arrays.copyOf(bArr, i8);
            oVar.D(bArrCopyOf.length, bArrCopyOf);
        } else {
            oVar.E(i8);
        }
        byte[] bArr2 = oVar.f18539a;
        int i9 = oVar.f18541c;
        bArr2[i9 - 4] = (byte) (j8 & 255);
        bArr2[i9 - 3] = (byte) ((j8 >>> 8) & 255);
        bArr2[i9 - 2] = (byte) ((j8 >>> 16) & 255);
        bArr2[i9 - 1] = (byte) ((j8 >>> 24) & 255);
        this.f15627p = true;
        this.f15626o = i5;
        return j8;
    }

    @Override // o1.AbstractC1333i
    public final boolean c(o oVar, long j8, C0853a c0853a) throws F {
        I i;
        x xVar;
        int i5;
        x xVar2;
        long jFloor;
        if (this.f15625n != null) {
            ((C1579o) c0853a.f12397r).getClass();
            return false;
        }
        x xVar3 = this.f15628q;
        int i8 = 1;
        int i9 = 4;
        if (xVar3 == null) {
            AbstractC0302b.w(1, oVar, false);
            oVar.l();
            int iT = oVar.t();
            int iL = oVar.l();
            int i10 = oVar.i();
            if (i10 <= 0) {
                i10 = -1;
            }
            int i11 = oVar.i();
            int i12 = i11 > 0 ? i11 : -1;
            oVar.i();
            int iT2 = oVar.t();
            int iPow = (int) Math.pow(2.0d, iT2 & 15);
            int iPow2 = (int) Math.pow(2.0d, (iT2 & 240) >> 4);
            oVar.t();
            byte[] bArrCopyOf = Arrays.copyOf(oVar.f18539a, oVar.f18541c);
            x xVar4 = new x();
            xVar4.f6475a = iT;
            xVar4.f6476b = iL;
            xVar4.f6477c = i10;
            xVar4.f6478d = i12;
            xVar4.f6479e = iPow;
            xVar4.f6480f = iPow2;
            xVar4.f6481g = bArrCopyOf;
            this.f15628q = xVar4;
        } else {
            P.g gVar = this.f15629r;
            if (gVar == null) {
                this.f15629r = AbstractC0302b.u(oVar, true, true);
            } else {
                int i13 = oVar.f18541c;
                byte[] bArr = new byte[i13];
                System.arraycopy(oVar.f18539a, 0, bArr, 0, i13);
                int i14 = 5;
                AbstractC0302b.w(5, oVar, false);
                int iT3 = oVar.t() + 1;
                H h8 = new H(oVar.f18539a);
                int i15 = 8;
                h8.t(oVar.f18540b * 8);
                int i16 = 0;
                while (true) {
                    int i17 = 2;
                    int i18 = 16;
                    if (i16 < iT3) {
                        int i19 = i15;
                        if (h8.i(24) != 5653314) {
                            throw F.a(null, "expected code book to start with [0x56, 0x43, 0x42] at " + ((h8.f6360c * 8) + h8.f6362e));
                        }
                        int i20 = h8.i(16);
                        int i21 = h8.i(24);
                        if (h8.h()) {
                            h8.t(i14);
                            for (int i22 = 0; i22 < i21; i22 += h8.i(AbstractC0302b.l(i21 - i22))) {
                            }
                        } else {
                            boolean zH = h8.h();
                            for (int i23 = 0; i23 < i21; i23++) {
                                if (!zH) {
                                    h8.t(i14);
                                } else if (h8.h()) {
                                    h8.t(i14);
                                }
                            }
                        }
                        int i24 = h8.i(i9);
                        if (i24 > 2) {
                            throw F.a(null, "lookup type greater than 2 not decodable: " + i24);
                        }
                        if (i24 == 1 || i24 == 2) {
                            h8.t(32);
                            h8.t(32);
                            int i25 = h8.i(i9) + 1;
                            h8.t(1);
                            if (i24 != 1) {
                                xVar2 = xVar3;
                                jFloor = ((long) i21) * ((long) i20);
                            } else if (i20 != 0) {
                                xVar2 = xVar3;
                                jFloor = (long) Math.floor(Math.pow(i21, 1.0d / ((double) i20)));
                            } else {
                                xVar2 = xVar3;
                                jFloor = 0;
                            }
                            h8.t((int) (jFloor * ((long) i25)));
                        } else {
                            xVar2 = xVar3;
                        }
                        i16++;
                        i15 = i19;
                        xVar3 = xVar2;
                        i9 = 4;
                        i14 = 5;
                    } else {
                        x xVar5 = xVar3;
                        int i26 = i15;
                        int i27 = 6;
                        int i28 = h8.i(6) + 1;
                        for (int i29 = 0; i29 < i28; i29++) {
                            if (h8.i(16) != 0) {
                                throw F.a(null, "placeholder of time domain transforms not zeroed out");
                            }
                        }
                        int i30 = h8.i(6) + 1;
                        int i31 = 0;
                        while (true) {
                            int i32 = 3;
                            if (i31 < i30) {
                                int i33 = h8.i(i18);
                                if (i33 == 0) {
                                    int i34 = i26;
                                    i5 = i8;
                                    h8.t(i34);
                                    h8.t(16);
                                    h8.t(16);
                                    h8.t(6);
                                    h8.t(i34);
                                    int i35 = h8.i(4) + 1;
                                    int i36 = 0;
                                    while (i36 < i35) {
                                        h8.t(i34);
                                        i36++;
                                        i34 = 8;
                                    }
                                } else {
                                    if (i33 != i8) {
                                        throw F.a(null, "floor type greater than 1 not decodable: " + i33);
                                    }
                                    int i37 = h8.i(5);
                                    int[] iArr = new int[i37];
                                    i5 = i8;
                                    int i38 = -1;
                                    for (int i39 = 0; i39 < i37; i39++) {
                                        int i40 = h8.i(4);
                                        iArr[i39] = i40;
                                        if (i40 > i38) {
                                            i38 = i40;
                                        }
                                    }
                                    int i41 = i38 + 1;
                                    int[] iArr2 = new int[i41];
                                    int i42 = 0;
                                    while (i42 < i41) {
                                        iArr2[i42] = h8.i(i32) + 1;
                                        int i43 = h8.i(i17);
                                        int i44 = i26;
                                        if (i43 > 0) {
                                            h8.t(i44);
                                        }
                                        int i45 = 0;
                                        while (i45 < (i5 << i43)) {
                                            h8.t(i44);
                                            i45++;
                                            i44 = 8;
                                        }
                                        i42++;
                                        i26 = 8;
                                        i32 = 3;
                                        i17 = 2;
                                    }
                                    h8.t(i17);
                                    int i46 = h8.i(4);
                                    int i47 = 0;
                                    int i48 = 0;
                                    for (int i49 = 0; i49 < i37; i49++) {
                                        i47 += iArr2[iArr[i49]];
                                        while (i48 < i47) {
                                            h8.t(i46);
                                            i48++;
                                        }
                                    }
                                }
                                i31++;
                                i8 = i5;
                                i26 = 8;
                                i27 = 6;
                                i18 = 16;
                                i17 = 2;
                            } else {
                                int i50 = i8;
                                int i51 = h8.i(i27) + 1;
                                int i52 = 0;
                                while (i52 < i51) {
                                    if (h8.i(16) > 2) {
                                        throw F.a(null, "residueType greater than 2 is not decodable");
                                    }
                                    h8.t(24);
                                    h8.t(24);
                                    h8.t(24);
                                    int i53 = h8.i(i27) + 1;
                                    int i54 = 8;
                                    h8.t(8);
                                    int[] iArr3 = new int[i53];
                                    for (int i55 = 0; i55 < i53; i55++) {
                                        iArr3[i55] = ((h8.h() ? h8.i(5) : 0) * 8) + h8.i(3);
                                    }
                                    int i56 = 0;
                                    while (i56 < i53) {
                                        int i57 = 0;
                                        while (i57 < i54) {
                                            if ((iArr3[i56] & (i50 << i57)) != 0) {
                                                h8.t(i54);
                                            }
                                            i57++;
                                            i54 = 8;
                                        }
                                        i56++;
                                        i54 = 8;
                                    }
                                    i52++;
                                    i27 = 6;
                                }
                                int i58 = h8.i(i27) + 1;
                                int i59 = 0;
                                while (i59 < i58) {
                                    int i60 = h8.i(16);
                                    if (i60 != 0) {
                                        AbstractC1709a.o("VorbisUtil", "mapping type other than 0 not supported: " + i60);
                                        xVar = xVar5;
                                    } else {
                                        int i61 = h8.h() ? h8.i(4) + 1 : i50;
                                        boolean zH2 = h8.h();
                                        xVar = xVar5;
                                        int i62 = xVar.f6475a;
                                        if (zH2) {
                                            int i63 = h8.i(8) + 1;
                                            for (int i64 = 0; i64 < i63; i64++) {
                                                int i65 = i62 - 1;
                                                h8.t(AbstractC0302b.l(i65));
                                                h8.t(AbstractC0302b.l(i65));
                                            }
                                        }
                                        if (h8.i(2) != 0) {
                                            throw F.a(null, "to reserved bits must be zero after mapping coupling steps");
                                        }
                                        if (i61 > i50) {
                                            for (int i66 = 0; i66 < i62; i66++) {
                                                h8.t(4);
                                            }
                                        }
                                        for (int i67 = 0; i67 < i61; i67++) {
                                            h8.t(8);
                                            h8.t(8);
                                            h8.t(8);
                                        }
                                    }
                                    i59++;
                                    xVar5 = xVar;
                                    i50 = 1;
                                }
                                x xVar6 = xVar5;
                                int i68 = h8.i(6);
                                int i69 = i68 + 1;
                                t0[] t0VarArr = new t0[i69];
                                for (int i70 = 0; i70 < i69; i70++) {
                                    boolean zH3 = h8.h();
                                    h8.i(16);
                                    h8.i(16);
                                    h8.i(8);
                                    t0VarArr[i70] = new t0(2, zH3);
                                }
                                if (!h8.h()) {
                                    throw F.a(null, "framing bit after modes not set as expected");
                                }
                                i = new I(xVar6, gVar, bArr, t0VarArr, AbstractC0302b.l(i68));
                            }
                        }
                    }
                }
            }
        }
        i = null;
        this.f15625n = i;
        if (i == null) {
            return true;
        }
        ArrayList arrayList = new ArrayList();
        x xVar7 = (x) i.f70s;
        arrayList.add((byte[]) xVar7.f6481g);
        arrayList.add((byte[]) i.f72u);
        D dR = AbstractC0302b.r(G.l((String[]) ((P.g) i.f71t).f5246r));
        C1578n c1578n = new C1578n();
        c1578n.f17319l = E.m("audio/ogg");
        c1578n.f17320m = E.m("audio/vorbis");
        c1578n.f17316h = xVar7.f6478d;
        c1578n.i = xVar7.f6477c;
        c1578n.f17301C = xVar7.f6475a;
        c1578n.D = xVar7.f6476b;
        c1578n.f17323p = arrayList;
        c1578n.f17318k = dR;
        c0853a.f12397r = new C1579o(c1578n);
        return true;
    }

    @Override // o1.AbstractC1333i
    public final void d(boolean z8) {
        super.d(z8);
        if (z8) {
            this.f15625n = null;
            this.f15628q = null;
            this.f15629r = null;
        }
        this.f15626o = 0;
        this.f15627p = false;
    }
}
