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

import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.List;

/* JADX INFO: loaded from: classes2.dex */
public final class um2 {

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final byte[] f17330d = {79, 103, 103, 83, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 28, -43, -59, -9, 1, 19, 79, 112, 117, 115, 72, 101, 97, 100, 1, 2, 56, 1, -128, -69, 0, 0, 0, 0, 0};

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final byte[] f17331e = {79, 103, 103, 83, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 11, -103, 87, 83, 1, 16, 79, 112, 117, 115, 84, 97, 103, 115, 0, 0, 0, 0, 0, 0, 0, 0};

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

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

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

    public static final void b(ByteBuffer byteBuffer, long j10, int i10, int i11, boolean z10) {
        byteBuffer.put((byte) 79);
        byteBuffer.put((byte) 103);
        byteBuffer.put((byte) 103);
        byteBuffer.put((byte) 83);
        byteBuffer.put((byte) 0);
        byteBuffer.put(true != z10 ? (byte) 0 : (byte) 2);
        byteBuffer.putLong(j10);
        byteBuffer.putInt(0);
        byteBuffer.putInt(i10);
        byteBuffer.putInt(0);
        byteBuffer.put(ih1.c(i11));
    }

    public final void a(fe2 fe2Var, List list) {
        int length;
        ByteBuffer byteBuffer = fe2Var.zzc;
        byteBuffer.getClass();
        if (byteBuffer.limit() - fe2Var.zzc.position() == 0) {
            return;
        }
        byte[] bArr = null;
        int i10 = 0;
        if (this.f17333b == 2 && (list.size() == 1 || list.size() == 3)) {
            bArr = (byte[]) list.get(0);
        }
        ByteBuffer byteBuffer2 = fe2Var.zzc;
        int iPosition = byteBuffer2.position();
        int iLimit = byteBuffer2.limit();
        int i11 = iLimit - iPosition;
        int i12 = (i11 + 255) / 255;
        int i13 = i12 + 27 + i11;
        if (this.f17333b == 2) {
            length = bArr != null ? bArr.length + 28 : 47;
            i13 += length + 44;
        } else {
            length = 0;
        }
        if (this.f17332a.capacity() < i13) {
            this.f17332a = ByteBuffer.allocate(i13).order(ByteOrder.LITTLE_ENDIAN);
        } else {
            this.f17332a.clear();
        }
        ByteBuffer byteBuffer3 = this.f17332a;
        if (this.f17333b == 2) {
            if (bArr != null) {
                b(byteBuffer3, 0L, 0, 1, true);
                int length2 = bArr.length;
                byteBuffer3.put(ih1.c(length2));
                byteBuffer3.put(bArr);
                int i14 = length2 + 28;
                i10 = 0;
                byteBuffer3.putInt(22, bb1.f(byteBuffer3.arrayOffset(), i14, 0, byteBuffer3.array()));
                byteBuffer3.position(i14);
            } else {
                byteBuffer3.put(f17330d);
            }
            byteBuffer3.put(f17331e);
        }
        int iP = this.f17334c + ((int) ((za2.P(byteBuffer2.get(i10), byteBuffer2.limit() > 1 ? byteBuffer2.get(1) : (byte) 0) * 48000) / 1000000));
        this.f17334c = iP;
        b(byteBuffer3, iP, this.f17333b, i12, false);
        for (int i15 = 0; i15 < i12; i15++) {
            if (i11 >= 255) {
                byteBuffer3.put((byte) -1);
                i11 -= 255;
            } else {
                byteBuffer3.put((byte) i11);
                i11 = 0;
            }
        }
        while (iPosition < iLimit) {
            byteBuffer3.put(byteBuffer2.get(iPosition));
            iPosition++;
        }
        byteBuffer2.position(byteBuffer2.limit());
        byteBuffer3.flip();
        if (this.f17333b == 2) {
            byteBuffer3.putInt(length + 66, bb1.f(byteBuffer3.arrayOffset() + length + 44, byteBuffer3.limit() - byteBuffer3.position(), 0, byteBuffer3.array()));
        } else {
            byteBuffer3.putInt(22, bb1.f(byteBuffer3.arrayOffset(), byteBuffer3.limit() - byteBuffer3.position(), 0, byteBuffer3.array()));
        }
        this.f17333b++;
        this.f17332a = byteBuffer3;
        fe2Var.h();
        fe2Var.i(this.f17332a.remaining());
        fe2Var.zzc.put(this.f17332a);
        fe2Var.k();
    }
}
