package defpackage;

import androidx.media3.common.audio.AudioProcessor$UnhandledAudioFormatException;
import java.math.RoundingMode;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

/* renamed from: ᵭᵝʡʦ, reason: contains not printable characters */
/* loaded from: classes3.dex */
public final class C4131 implements InterfaceC0240 {

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

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

    /* renamed from: ˎˏʜʾ, reason: contains not printable characters */
    public C2263 f15433;

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

    /* renamed from: ˏᵙ, reason: contains not printable characters */
    public float f15435;

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

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

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

    /* renamed from: ᵳٴᵶ, reason: contains not printable characters */
    public boolean f15439;

    /* renamed from: ᵴᵳ, reason: contains not printable characters */
    public int f15440;

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

    /* renamed from: ᵸˑ, reason: contains not printable characters */
    public ByteBuffer f15442;

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

    /* renamed from: ᵻᵢﹳᵰ, reason: contains not printable characters */
    public float f15444;

    @Override // defpackage.InterfaceC0240
    public final void reset() {
        this.f15435 = 1.0f;
        this.f15444 = 1.0f;
        C2263 c2263 = C2263.f8838;
        this.f15431 = c2263;
        this.f15434 = c2263;
        this.f15433 = c2263;
        this.f15443 = c2263;
        ByteBuffer byteBuffer = InterfaceC0240.f1780;
        this.f15442 = byteBuffer;
        this.f15432 = byteBuffer;
        this.f15440 = -1;
        this.f15436 = false;
        this.f15441 = null;
        this.f15438 = 0L;
        this.f15437 = 0L;
        this.f15439 = false;
    }

    @Override // defpackage.InterfaceC0240
    /* renamed from: ˇʼʤˎ */
    public final void mo1538(C3046 c3046) {
        if (mo1541()) {
            C2263 c2263 = this.f15431;
            this.f15433 = c2263;
            C2263 c22632 = this.f15434;
            this.f15443 = c22632;
            if (this.f15436) {
                this.f15441 = new C3725(c2263.f8840, c2263.f8841, this.f15435, this.f15444, c22632.f8840, c2263.f8839 == 4);
            } else {
                C3725 c3725 = this.f15441;
                if (c3725 != null) {
                    c3725.f13915 = 0;
                    c3725.f13916 = 0;
                    c3725.f13904 = 0;
                    c3725.f13912 = 0;
                    c3725.f13911 = 0;
                    c3725.f13913 = 0;
                    c3725.f13903 = 0;
                    c3725.f13909 = 0.0d;
                    c3725.f13908.flush();
                }
            }
        }
        this.f15432 = InterfaceC0240.f1780;
        this.f15438 = 0L;
        this.f15437 = 0L;
        this.f15439 = false;
    }

    @Override // defpackage.InterfaceC0240
    /* renamed from: ˎˏʜʾ */
    public final C2263 mo1539(C2263 c2263) throws AudioProcessor$UnhandledAudioFormatException {
        int i = c2263.f8839;
        if (i != 2 && i != 4) {
            throw new AudioProcessor$UnhandledAudioFormatException(c2263);
        }
        int i2 = this.f15440;
        if (i2 == -1) {
            i2 = c2263.f8840;
        }
        this.f15431 = c2263;
        C2263 c22632 = new C2263(i2, c2263.f8841, i);
        this.f15434 = c22632;
        this.f15436 = true;
        return c22632;
    }

    @Override // defpackage.InterfaceC0240
    /* renamed from: ˏˋٴ */
    public final void mo1540(ByteBuffer byteBuffer) {
        if (byteBuffer.hasRemaining()) {
            C3725 c3725 = this.f15441;
            c3725.getClass();
            this.f15438 += byteBuffer.remaining();
            int iRemaining = byteBuffer.remaining();
            int i = c3725.f13914;
            InterfaceC4771 interfaceC4771 = c3725.f13908;
            int iMo5900 = iRemaining / (interfaceC4771.mo5900() * i);
            interfaceC4771.mo5889(iMo5900);
            interfaceC4771.mo5897(iRemaining, byteBuffer);
            c3725.f13915 += iMo5900;
            c3725.m8360();
        }
    }

    @Override // defpackage.InterfaceC0240
    /* renamed from: ˏᵙ */
    public final boolean mo1541() {
        if (this.f15434.f8840 != -1) {
            return Math.abs(this.f15435 - 1.0f) >= 1.0E-4f || Math.abs(this.f15444 - 1.0f) >= 1.0E-4f || this.f15434.f8840 != this.f15431.f8840;
        }
        return false;
    }

    @Override // defpackage.InterfaceC0240
    /* renamed from: ᵝᵵᵺ */
    public final long mo1542(long j) {
        if (this.f15437 < 1024) {
            return (long) (j / this.f15435);
        }
        long j2 = this.f15438;
        this.f15441.getClass();
        long jMo5900 = j2 - (r2.f13908.mo5900() * (r2.f13915 * r2.f13914));
        int i = this.f15443.f8840;
        int i2 = this.f15433.f8840;
        long j3 = this.f15437;
        return i == i2 ? AbstractC3558.m8115(j, j3, jMo5900, RoundingMode.DOWN) : AbstractC3558.m8115(j, j3 * i2, jMo5900 * i, RoundingMode.DOWN);
    }

    @Override // defpackage.InterfaceC0240
    /* renamed from: ᵴᵳ */
    public final boolean mo1543() {
        if (this.f15439) {
            C3725 c3725 = this.f15441;
            if (c3725 != null) {
                ᵛᵾˏ.ᵿʗᵝʽ(c3725.f13916 >= 0);
                if (c3725.f13908.mo5900() * c3725.f13916 * c3725.f13914 == 0) {
                }
            }
            return true;
        }
        return false;
    }

    @Override // defpackage.InterfaceC0240
    /* renamed from: ᵹᵝᵶ */
    public final void mo1544() {
        C3725 c3725 = this.f15441;
        if (c3725 != null) {
            int i = c3725.f13915;
            float f = c3725.f13907;
            float f2 = c3725.f13918;
            double d = f / f2;
            int i2 = c3725.f13916 + ((int) (((((((i - r6) / d) + c3725.f13913) + c3725.f13909) + c3725.f13904) / (c3725.f13902 * f2)) + 0.5d));
            c3725.f13909 = 0.0d;
            InterfaceC4771 interfaceC4771 = c3725.f13908;
            int i3 = c3725.f13917 * 2;
            interfaceC4771.mo5889(i3 + i);
            interfaceC4771.mo5893(i * c3725.f13914, i3);
            c3725.f13915 = i3 + c3725.f13915;
            c3725.m8360();
            if (c3725.f13916 > i2) {
                c3725.f13916 = Math.max(i2, 0);
            }
            c3725.f13915 = 0;
            c3725.f13913 = 0;
            c3725.f13904 = 0;
        }
        this.f15439 = true;
    }

    @Override // defpackage.InterfaceC0240
    /* renamed from: ᵻᵢﹳᵰ */
    public final ByteBuffer mo1545() {
        C3725 c3725 = this.f15441;
        if (c3725 != null) {
            InterfaceC4771 interfaceC4771 = c3725.f13908;
            int i = c3725.f13914;
            ᵛᵾˏ.ᵿʗᵝʽ(c3725.f13916 >= 0);
            int iMo5900 = interfaceC4771.mo5900() * c3725.f13916 * i;
            if (iMo5900 > 0) {
                if (this.f15442.capacity() < iMo5900) {
                    this.f15442 = ByteBuffer.allocateDirect(iMo5900).order(ByteOrder.nativeOrder());
                } else {
                    this.f15442.clear();
                }
                ByteBuffer byteBuffer = this.f15442;
                ᵛᵾˏ.ᵿʗᵝʽ(c3725.f13916 >= 0);
                int iMin = Math.min(byteBuffer.remaining() / (interfaceC4771.mo5900() * i), c3725.f13916);
                interfaceC4771.mo5901(iMin, byteBuffer);
                c3725.f13916 -= iMin;
                System.arraycopy(interfaceC4771.mo5905(), iMin * i, interfaceC4771.mo5905(), 0, c3725.f13916 * i);
                this.f15442.flip();
                this.f15437 += iMo5900;
                this.f15432 = this.f15442;
            }
        }
        ByteBuffer byteBuffer2 = this.f15432;
        this.f15432 = InterfaceC0240.f1780;
        return byteBuffer2;
    }
}
