package A0;

import java.nio.ByteBuffer;
import u0.AbstractC1589z;
import u0.C1579o;

/* JADX INFO: loaded from: classes.dex */
public class h extends a {

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public C1579o f16s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public final d f17t = new d();

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public ByteBuffer f18u;

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

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public long f20w;

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

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public final int f22y;

    static {
        AbstractC1589z.a("media3.decoder");
    }

    public h(int i) {
        this.f22y = i;
    }

    public void e() {
        this.f6r = 0;
        ByteBuffer byteBuffer = this.f18u;
        if (byteBuffer != null) {
            byteBuffer.clear();
        }
        ByteBuffer byteBuffer2 = this.f21x;
        if (byteBuffer2 != null) {
            byteBuffer2.clear();
        }
        this.f19v = false;
    }

    public final ByteBuffer g(int i) {
        int i5 = this.f22y;
        if (i5 == 1) {
            return ByteBuffer.allocate(i);
        }
        if (i5 == 2) {
            return ByteBuffer.allocateDirect(i);
        }
        ByteBuffer byteBuffer = this.f18u;
        throw new g("Buffer too small (" + (byteBuffer == null ? 0 : byteBuffer.capacity()) + " < " + i + ")");
    }

    public final void h(int i) {
        ByteBuffer byteBuffer = this.f18u;
        if (byteBuffer == null) {
            this.f18u = g(i);
            return;
        }
        int iCapacity = byteBuffer.capacity();
        int iPosition = byteBuffer.position();
        int i5 = i + iPosition;
        if (iCapacity >= i5) {
            this.f18u = byteBuffer;
            return;
        }
        ByteBuffer byteBufferG = g(i5);
        byteBufferG.order(byteBuffer.order());
        if (iPosition > 0) {
            byteBuffer.flip();
            byteBufferG.put(byteBuffer);
        }
        this.f18u = byteBufferG;
    }

    public final void j() {
        ByteBuffer byteBuffer = this.f18u;
        if (byteBuffer != null) {
            byteBuffer.flip();
        }
        ByteBuffer byteBuffer2 = this.f21x;
        if (byteBuffer2 != null) {
            byteBuffer2.flip();
        }
    }
}
