package p138.p176.p177.p190.p192;

import com.google.android.exoplayer2.audio.AudioProcessor;
import java.nio.ByteBuffer;
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 C3498 extends AbstractC3489 {

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

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

    /* JADX INFO: renamed from: ވ, reason: contains not printable characters */
    public byte[] f10367;

    /* JADX INFO: renamed from: މ, reason: contains not printable characters */
    public byte[] f10368;

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

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

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

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

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

    public C3498() {
        byte[] bArr = C4150.f13264;
        this.f10367 = bArr;
        this.f10368 = bArr;
    }

    @Override // com.google.android.exoplayer2.audio.AudioProcessor
    /* JADX INFO: renamed from: ֏ */
    public void mo1059(ByteBuffer byteBuffer) {
        int iPosition;
        while (byteBuffer.hasRemaining() && !this.f10340.hasRemaining()) {
            int i = this.f10369;
            if (i == 0) {
                int iLimit = byteBuffer.limit();
                byteBuffer.limit(Math.min(iLimit, byteBuffer.position() + this.f10367.length));
                int iLimit2 = byteBuffer.limit() - 1;
                while (true) {
                    if (iLimit2 < byteBuffer.position()) {
                        iPosition = byteBuffer.position();
                        break;
                    } else {
                        if (Math.abs((int) byteBuffer.get(iLimit2)) > 4) {
                            int i2 = this.f10365;
                            iPosition = ((iLimit2 / i2) * i2) + i2;
                            break;
                        }
                        iLimit2 -= 2;
                    }
                }
                if (iPosition == byteBuffer.position()) {
                    this.f10369 = 1;
                } else {
                    byteBuffer.limit(iPosition);
                    int iRemaining = byteBuffer.remaining();
                    m5775(iRemaining).put(byteBuffer).flip();
                    if (iRemaining > 0) {
                        this.f10372 = true;
                    }
                }
                byteBuffer.limit(iLimit);
            } else if (i == 1) {
                int iLimit3 = byteBuffer.limit();
                int iM5786 = m5786(byteBuffer);
                int iPosition2 = iM5786 - byteBuffer.position();
                byte[] bArr = this.f10367;
                int length = bArr.length;
                int i3 = this.f10370;
                int i4 = length - i3;
                if (iM5786 >= iLimit3 || iPosition2 >= i4) {
                    int iMin = Math.min(iPosition2, i4);
                    byteBuffer.limit(byteBuffer.position() + iMin);
                    byteBuffer.get(this.f10367, this.f10370, iMin);
                    int i5 = this.f10370 + iMin;
                    this.f10370 = i5;
                    byte[] bArr2 = this.f10367;
                    if (i5 == bArr2.length) {
                        if (this.f10372) {
                            m5785(bArr2, this.f10371);
                            this.f10373 += (long) ((this.f10370 - (this.f10371 * 2)) / this.f10365);
                        } else {
                            this.f10373 += (long) ((i5 - this.f10371) / this.f10365);
                        }
                        m5784(byteBuffer, this.f10367, this.f10370);
                        this.f10370 = 0;
                        this.f10369 = 2;
                    }
                    byteBuffer.limit(iLimit3);
                } else {
                    m5785(bArr, i3);
                    this.f10370 = 0;
                    this.f10369 = 0;
                }
            } else {
                if (i != 2) {
                    throw new IllegalStateException();
                }
                int iLimit4 = byteBuffer.limit();
                int iM57862 = m5786(byteBuffer);
                byteBuffer.limit(iM57862);
                this.f10373 += (long) (byteBuffer.remaining() / this.f10365);
                m5784(byteBuffer, this.f10368, this.f10371);
                if (iM57862 < iLimit4) {
                    m5785(this.f10368, this.f10371);
                    this.f10369 = 0;
                    byteBuffer.limit(iLimit4);
                }
            }
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m5784(ByteBuffer byteBuffer, byte[] bArr, int i) {
        int iMin = Math.min(byteBuffer.remaining(), this.f10371);
        int i2 = this.f10371 - iMin;
        System.arraycopy(bArr, i - i2, this.f10368, 0, i2);
        byteBuffer.position(byteBuffer.limit() - iMin);
        byteBuffer.get(this.f10368, i2, iMin);
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final void m5785(byte[] bArr, int i) {
        m5775(i).put(bArr, 0, i).flip();
        if (i > 0) {
            this.f10372 = true;
        }
    }

    /* JADX INFO: renamed from: ؠ, reason: contains not printable characters */
    public final int m5786(ByteBuffer byteBuffer) {
        for (int iPosition = byteBuffer.position() + 1; iPosition < byteBuffer.limit(); iPosition += 2) {
            if (Math.abs((int) byteBuffer.get(iPosition)) > 4) {
                int i = this.f10365;
                return (iPosition / i) * i;
            }
        }
        return byteBuffer.limit();
    }

    @Override // p138.p176.p177.p190.p192.AbstractC3489
    /* JADX INFO: renamed from: ؠ */
    public AudioProcessor.C0268 mo5776(AudioProcessor.C0268 c0268) throws AudioProcessor.UnhandledAudioFormatException {
        if (c0268.f1540 == 2) {
            return this.f10366 ? c0268 : AudioProcessor.C0268.f1537;
        }
        throw new AudioProcessor.UnhandledAudioFormatException(c0268);
    }

    @Override // p138.p176.p177.p190.p192.AbstractC3489, com.google.android.exoplayer2.audio.AudioProcessor
    /* JADX INFO: renamed from: ހ */
    public boolean mo1061() {
        return this.f10366;
    }

    @Override // p138.p176.p177.p190.p192.AbstractC3489
    /* JADX INFO: renamed from: ރ */
    public void mo5777() {
        if (this.f10366) {
            AudioProcessor.C0268 c0268 = this.f10335;
            int i = c0268.f1541;
            this.f10365 = i;
            int i2 = ((int) ((((long) c0268.f1538) * 150000) / 1000000)) * i;
            if (this.f10367.length != i2) {
                this.f10367 = new byte[i2];
            }
            int i3 = ((int) ((((long) this.f10335.f1538) * 20000) / 1000000)) * this.f10365;
            this.f10371 = i3;
            if (this.f10368.length != i3) {
                this.f10368 = new byte[i3];
            }
        }
        this.f10369 = 0;
        this.f10373 = 0L;
        this.f10370 = 0;
        this.f10372 = false;
    }

    @Override // p138.p176.p177.p190.p192.AbstractC3489
    /* JADX INFO: renamed from: ބ */
    public void mo5778() {
        int i = this.f10370;
        if (i > 0) {
            m5785(this.f10367, i);
        }
        if (this.f10372) {
            return;
        }
        this.f10373 += (long) (this.f10371 / this.f10365);
    }

    @Override // p138.p176.p177.p190.p192.AbstractC3489
    /* JADX INFO: renamed from: ޅ */
    public void mo5779() {
        this.f10366 = false;
        this.f10371 = 0;
        byte[] bArr = C4150.f13264;
        this.f10367 = bArr;
        this.f10368 = bArr;
    }
}
