package com.google.android.gms.internal.ads;

import androidx.annotation.Nullable;
import java.nio.ByteBuffer;

/* JADX INFO: loaded from: classes2.dex */
public class fe2 extends q1.f {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final mc2 f11188c = new mc2();

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

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

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

    @Nullable
    public zn2 zza;

    @Nullable
    public ByteBuffer zzc;

    @Nullable
    public ByteBuffer zzf;

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

    public fe2(int i10) {
        this.f11191f = i10;
    }

    public void h() {
        this.f32097b = 0;
        ByteBuffer byteBuffer = this.zzc;
        if (byteBuffer != null) {
            byteBuffer.clear();
        }
        ByteBuffer byteBuffer2 = this.zzf;
        if (byteBuffer2 != null) {
            byteBuffer2.clear();
        }
        this.f11189d = false;
    }

    public final void i(int i10) {
        ByteBuffer byteBuffer = this.zzc;
        if (byteBuffer == null) {
            this.zzc = l(i10);
            return;
        }
        int iCapacity = byteBuffer.capacity();
        int iPosition = byteBuffer.position();
        int i11 = i10 + iPosition;
        if (iCapacity >= i11) {
            this.zzc = byteBuffer;
            return;
        }
        ByteBuffer byteBufferL = l(i11);
        byteBufferL.order(byteBuffer.order());
        if (iPosition > 0) {
            byteBuffer.flip();
            byteBufferL.put(byteBuffer);
        }
        this.zzc = byteBufferL;
    }

    public final boolean j() {
        return g(1073741824);
    }

    public final void k() {
        ByteBuffer byteBuffer = this.zzc;
        if (byteBuffer != null) {
            byteBuffer.flip();
        }
        ByteBuffer byteBuffer2 = this.zzf;
        if (byteBuffer2 != null) {
            byteBuffer2.flip();
        }
    }

    public final ByteBuffer l(int i10) {
        int i11 = this.f11191f;
        if (i11 == 1) {
            return ByteBuffer.allocate(i10);
        }
        if (i11 == 2) {
            return ByteBuffer.allocateDirect(i10);
        }
        ByteBuffer byteBuffer = this.zzc;
        int iCapacity = byteBuffer == null ? 0 : byteBuffer.capacity();
        StringBuilder sb = new StringBuilder(String.valueOf(iCapacity).length() + 21 + String.valueOf(i10).length() + 1);
        com.google.android.gms.measurement.internal.u1.y(sb, "Buffer too small (", iCapacity, " < ", i10);
        sb.append(")");
        throw new zzig(sb.toString());
    }
}
