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

import androidx.annotation.Nullable;
import java.math.RoundingMode;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

/* JADX INFO: loaded from: classes2.dex */
public final class fb0 implements i80 {

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

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public float f11155c;

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

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

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public s60 f11158f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public s60 f11159g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public s60 f11160h;

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

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

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

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

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

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

    @Nullable
    private pa0 zzj;

    @Override // com.google.android.gms.internal.ads.i80
    public final long a(long j10) {
        if (this.f11165m < 1024) {
            return (long) (j10 / ((double) this.f11155c));
        }
        long j11 = this.f11164l;
        pa0 pa0Var = this.zzj;
        pa0Var.getClass();
        long jZza = j11 - ((long) (pa0Var.f15337i.zza() * (pa0Var.f15338j * pa0Var.f15330b)));
        int i10 = this.f11160h.f16307a;
        int i11 = this.f11159g.f16307a;
        return i10 == i11 ? bb1.r(j10, this.f11165m, jZza, RoundingMode.DOWN) : bb1.r(j10, this.f11165m * ((long) i11), jZza * ((long) i10), RoundingMode.DOWN);
    }

    @Override // com.google.android.gms.internal.ads.i80
    public final void b(ByteBuffer byteBuffer) {
        if (byteBuffer.hasRemaining()) {
            pa0 pa0Var = this.zzj;
            pa0Var.getClass();
            this.f11164l += (long) byteBuffer.remaining();
            int iRemaining = byteBuffer.remaining();
            s90 s90Var = pa0Var.f15337i;
            int iZza = iRemaining / (s90Var.zza() * pa0Var.f15330b);
            s90Var.zzj(iZza);
            s90Var.g(iRemaining, byteBuffer);
            pa0Var.f15338j += iZza;
            pa0Var.b();
        }
    }

    @Override // com.google.android.gms.internal.ads.i80
    public final s60 c(s60 s60Var) throws zzcn {
        int i10 = s60Var.f16309c;
        if (i10 != 2 && i10 != 4) {
            throw new zzcn("Unhandled input format:", s60Var);
        }
        int i11 = this.f11154b;
        if (i11 == -1) {
            i11 = s60Var.f16307a;
        }
        this.f11157e = s60Var;
        s60 s60Var2 = new s60(i11, s60Var.f16308b, i10);
        this.f11158f = s60Var2;
        this.f11161i = true;
        return s60Var2;
    }

    public final long d(long j10) {
        if (this.f11165m < 1024) {
            return (long) (((double) this.f11155c) * j10);
        }
        long j11 = this.f11164l;
        pa0 pa0Var = this.zzj;
        pa0Var.getClass();
        long jZza = j11 - ((long) (pa0Var.f15337i.zza() * (pa0Var.f15338j * pa0Var.f15330b)));
        int i10 = this.f11160h.f16307a;
        int i11 = this.f11159g.f16307a;
        return i10 == i11 ? bb1.r(j10, jZza, this.f11165m, RoundingMode.DOWN) : bb1.r(j10, jZza * ((long) i10), this.f11165m * ((long) i11), RoundingMode.DOWN);
    }

    @Override // com.google.android.gms.internal.ads.i80
    public final boolean zzc() {
        if (this.f11158f.f16307a != -1) {
            return Math.abs(this.f11155c + (-1.0f)) >= 1.0E-4f || Math.abs(this.f11156d + (-1.0f)) >= 1.0E-4f || this.f11158f.f16307a != this.f11157e.f16307a;
        }
        return false;
    }

    @Override // com.google.android.gms.internal.ads.i80
    public final void zze() {
        pa0 pa0Var = this.zzj;
        if (pa0Var != null) {
            int i10 = pa0Var.f15338j;
            int i11 = pa0Var.f15343o;
            int i12 = pa0Var.f15339k;
            float f10 = pa0Var.f15331c;
            float f11 = pa0Var.f15332d;
            int i13 = i12 + ((int) ((((((((double) (i10 - i11)) / ((double) (f10 / f11))) + ((double) i11)) + pa0Var.f15345q) + ((double) pa0Var.f15340l)) / ((double) (pa0Var.f15333e * f11))) + 0.5d));
            pa0Var.f15345q = 0.0d;
            int i14 = pa0Var.f15336h;
            int i15 = i14 + i14;
            s90 s90Var = pa0Var.f15337i;
            s90Var.zzj(i10 + i15);
            s90Var.h(i10 * pa0Var.f15330b, i15);
            pa0Var.f15338j += i15;
            pa0Var.b();
            if (pa0Var.f15339k > i13) {
                pa0Var.f15339k = Math.max(i13, 0);
            }
            pa0Var.f15338j = 0;
            pa0Var.f15343o = 0;
            pa0Var.f15340l = 0;
        }
        this.f11166n = true;
    }

    @Override // com.google.android.gms.internal.ads.i80
    public final ByteBuffer zzf() {
        pa0 pa0Var = this.zzj;
        if (pa0Var != null) {
            ih1.b1(pa0Var.f15339k >= 0);
            int i10 = pa0Var.f15339k;
            int i11 = pa0Var.f15330b;
            s90 s90Var = pa0Var.f15337i;
            int iZza = s90Var.zza() * i10 * i11;
            if (iZza > 0) {
                if (this.f11162j.capacity() < iZza) {
                    this.f11162j = ByteBuffer.allocateDirect(iZza).order(ByteOrder.nativeOrder());
                } else {
                    this.f11162j.clear();
                }
                ByteBuffer byteBuffer = this.f11162j;
                ih1.b1(pa0Var.f15339k >= 0);
                int iMin = Math.min(byteBuffer.remaining() / (s90Var.zza() * i11), pa0Var.f15339k);
                s90Var.j(iMin, byteBuffer);
                pa0Var.f15339k -= iMin;
                System.arraycopy(s90Var.zzq(), iMin * i11, s90Var.zzq(), 0, pa0Var.f15339k * i11);
                this.f11162j.flip();
                this.f11165m += (long) iZza;
                this.f11163k = this.f11162j;
            }
        }
        ByteBuffer byteBuffer2 = this.f11163k;
        this.f11163k = i80.f12407a;
        return byteBuffer2;
    }

    @Override // com.google.android.gms.internal.ads.i80
    public final boolean zzg() {
        if (!this.f11166n) {
            return false;
        }
        pa0 pa0Var = this.zzj;
        if (pa0Var == null) {
            return true;
        }
        ih1.b1(pa0Var.f15339k >= 0);
        return pa0Var.f15337i.zza() * (pa0Var.f15339k * pa0Var.f15330b) == 0;
    }

    @Override // com.google.android.gms.internal.ads.i80
    public final void zzi() {
        if (zzc()) {
            s60 s60Var = this.f11157e;
            this.f11159g = s60Var;
            s60 s60Var2 = this.f11158f;
            this.f11160h = s60Var2;
            if (this.f11161i) {
                this.zzj = new pa0(s60Var.f16307a, s60Var.f16308b, this.f11155c, this.f11156d, s60Var2.f16307a, s60Var.f16309c == 4);
            } else {
                pa0 pa0Var = this.zzj;
                if (pa0Var != null) {
                    pa0Var.f15338j = 0;
                    pa0Var.f15339k = 0;
                    pa0Var.f15340l = 0;
                    pa0Var.f15341m = 0;
                    pa0Var.f15342n = 0;
                    pa0Var.f15343o = 0;
                    pa0Var.f15344p = 0;
                    pa0Var.f15345q = 0.0d;
                    pa0Var.f15337i.zzg();
                }
            }
        }
        this.f11163k = i80.f12407a;
        this.f11164l = 0L;
        this.f11165m = 0L;
        this.f11166n = false;
    }

    @Override // com.google.android.gms.internal.ads.i80
    public final void zzj() {
        this.f11155c = 1.0f;
        this.f11156d = 1.0f;
        s60 s60Var = s60.f16306e;
        this.f11157e = s60Var;
        this.f11158f = s60Var;
        this.f11159g = s60Var;
        this.f11160h = s60Var;
        ByteBuffer byteBuffer = i80.f12407a;
        this.f11162j = byteBuffer;
        this.f11163k = byteBuffer;
        this.f11154b = -1;
        this.f11161i = false;
        this.zzj = null;
        this.f11164l = 0L;
        this.f11165m = 0L;
        this.f11166n = false;
    }
}
