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

import java.nio.ByteBuffer;

/* JADX INFO: loaded from: classes2.dex */
public final class xm2 extends y80 {

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

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

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

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

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public byte[] f18480m;

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

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

    @Override // com.google.android.gms.internal.ads.i80
    public final long a(long j10) {
        return Math.max(0L, j10 - bb1.q(this.f18748b.f16307a, this.f18477j + this.f18476i));
    }

    @Override // com.google.android.gms.internal.ads.i80
    public final void b(ByteBuffer byteBuffer) {
        int iPosition = byteBuffer.position();
        int iLimit = byteBuffer.limit();
        int i10 = iLimit - iPosition;
        if (i10 == 0) {
            return;
        }
        int iMin = Math.min(i10, this.f18479l);
        this.f18482o += (long) (iMin / this.f18748b.f16310d);
        this.f18479l -= iMin;
        byteBuffer.position(iPosition + iMin);
        if (this.f18479l <= 0) {
            int i11 = i10 - iMin;
            int length = (this.f18481n + i11) - this.f18480m.length;
            ByteBuffer byteBufferD = d(length);
            int i12 = this.f18481n;
            String str = bb1.f9474a;
            int iMax = Math.max(0, Math.min(length, i12));
            byteBufferD.put(this.f18480m, 0, iMax);
            int iMax2 = Math.max(0, Math.min(length - iMax, i11));
            byteBuffer.limit(byteBuffer.position() + iMax2);
            byteBufferD.put(byteBuffer);
            byteBuffer.limit(iLimit);
            int i13 = i11 - iMax2;
            int i14 = this.f18481n - iMax;
            this.f18481n = i14;
            byte[] bArr = this.f18480m;
            System.arraycopy(bArr, iMax, bArr, 0, i14);
            byteBuffer.get(this.f18480m, this.f18481n, i13);
            this.f18481n += i13;
            byteBufferD.flip();
        }
    }

    @Override // com.google.android.gms.internal.ads.y80
    public final s60 e(s60 s60Var) throws zzcn {
        if (!bb1.a(s60Var.f16309c)) {
            throw new zzcn("Unhandled input format:", s60Var);
        }
        this.f18478k = true;
        return (this.f18476i == 0 && this.f18477j == 0) ? s60.f16306e : s60Var;
    }

    @Override // com.google.android.gms.internal.ads.y80
    public final void f() {
        if (this.f18478k) {
            int i10 = this.f18481n;
            if (i10 > 0) {
                this.f18482o += (long) (i10 / this.f18748b.f16310d);
            }
            this.f18481n = 0;
        }
    }

    @Override // com.google.android.gms.internal.ads.y80
    public final void g() {
        if (this.f18478k) {
            this.f18478k = false;
            int i10 = this.f18477j;
            int i11 = this.f18748b.f16310d;
            this.f18480m = new byte[i10 * i11];
            this.f18479l = this.f18476i * i11;
        }
        this.f18481n = 0;
    }

    @Override // com.google.android.gms.internal.ads.y80
    public final void h() {
        this.f18480m = bb1.f9475b;
    }

    @Override // com.google.android.gms.internal.ads.y80, com.google.android.gms.internal.ads.i80
    public final ByteBuffer zzf() {
        int i10;
        if (super.zzg() && (i10 = this.f18481n) > 0) {
            d(i10).put(this.f18480m, 0, this.f18481n).flip();
            this.f18481n = 0;
        }
        return super.zzf();
    }

    @Override // com.google.android.gms.internal.ads.y80, com.google.android.gms.internal.ads.i80
    public final boolean zzg() {
        return super.zzg() && this.f18481n == 0;
    }
}
