package b0;

import android.util.Log;
import androidx.media3.decoder.midi.MidiDecoder;
import com.mstar.android.tv.TvLanguage;
import com.mstar.android.tv.TvPvrManager;
import com.mstar.android.tvapi.impl.PlayerImpl;
import com.seewo.sdk.model.SDKKeyboardCode;
import java.nio.ByteBuffer;

/* JADX INFO: renamed from: b0.a, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractC0396a {
    public static final byte[] a(int i2, int i3, int i4) {
        int i5;
        switch (i2) {
            case 8000:
                i5 = 11;
                break;
            case 11025:
                i5 = 10;
                break;
            case PlayerImpl.TVPLAYER_CI_EVENT_START /* 12000 */:
                i5 = 9;
                break;
            case 16000:
                i5 = 8;
                break;
            case 22050:
                i5 = 7;
                break;
            case 24000:
                i5 = 6;
                break;
            case TvPvrManager.PVR_PLAYBACK_SPEED_FF_32X /* 32000 */:
                i5 = 5;
                break;
            case MidiDecoder.DEFAULT_SAMPLE_RATE /* 44100 */:
            default:
                i5 = 4;
                break;
            case 48000:
                i5 = 3;
                break;
            case 64000:
                i5 = 2;
                break;
            case 88200:
                i5 = 1;
                break;
            case 96000:
                i5 = 0;
                break;
        }
        if (i3 > 2) {
            i3 = 0;
        }
        int i6 = i4 + 7;
        return new byte[]{-1, -15, (byte) (((i5 << 2) & 60) | 64 | ((i3 >> 2) & 1)), (byte) (((i3 & 3) << 6) | ((i6 >> 11) & 3)), (byte) ((i6 >> 3) & 255), (byte) (((i6 << 5) & TvLanguage.INTERLINGUA) | 31), -4};
    }

    public static final void b(ByteBuffer byteBuffer, int i2, E e2) {
        int iCapacity = byteBuffer.capacity();
        int i3 = iCapacity * 8;
        int i4 = i3 / 255;
        int i5 = i3 % 255;
        int i6 = i2 / 255;
        int i7 = i2 % 255;
        int i8 = i4 + 10 + iCapacity + i6 + 1;
        byte[] bArr = new byte[i8];
        bArr[0] = 86;
        bArr[1] = -32;
        int i9 = (i8 - 3) + i2;
        bArr[1] = (byte) (((byte) ((i9 >> 8) & 31)) | (-32));
        bArr[2] = (byte) (i9 & 255);
        bArr[3] = SDKKeyboardCode.FUNCTION_KEY_BOARD_SCROLL_LOCK;
        bArr[4] = -4;
        bArr[5] = 0;
        e2.j(bArr, 6);
        e2.h(false, 3);
        if (i4 == 0) {
            e2.h(false, 2);
        } else if (i4 == 1) {
            e2.g(false);
            e2.g(true);
        } else if (i4 == 2) {
            e2.g(true);
            e2.g(false);
        } else if (i4 != 3) {
            Log.e("AacUtil", "unexpected byteNumOfascLength:" + i4);
        } else {
            e2.h(true, 2);
        }
        for (int i10 = 0; i10 <= i4; i10++) {
            if (i10 < i4) {
                e2.e((byte) -1);
            } else {
                e2.e((byte) i5);
            }
        }
        e2.i(byteBuffer.array());
        e2.h(false, 3);
        e2.e((byte) -1);
        e2.h(false, 2);
        for (int i11 = 0; i11 <= i6; i11++) {
            if (i11 < i6) {
                e2.e((byte) -1);
            } else {
                e2.e((byte) i7);
            }
        }
    }

    public static int c(int i2) {
        return (i2 == 5 || i2 == 29) ? 2048 : 1024;
    }

    public static final int d(ByteBuffer byteBuffer, int i2) {
        int iCapacity = byteBuffer.capacity();
        return ((iCapacity * 8) / 255) + 10 + iCapacity + (i2 / 255) + 1;
    }

    public static final ByteBuffer e(ByteBuffer byteBuffer) {
        Log.i("AacUtil", "parsePCEFromFrame");
        int iLimit = byteBuffer.limit() - 7;
        Log.i("AacUtil", "length:" + iLimit + ", frame.limit:" + byteBuffer.limit());
        byte[] bArr = new byte[iLimit];
        int iPosition = byteBuffer.position();
        byteBuffer.position(7);
        byteBuffer.get(bArr, 0, iLimit);
        if ((o.a() & 2) > 0) {
            String str = " ";
            for (int i2 = 0; i2 < iLimit; i2++) {
                str = (str + Integer.toHexString(bArr[i2]).toUpperCase()) + " ";
            }
            o.c("AacUtil", 2, "PCE String:", str);
            byteBuffer.position(0);
        }
        byteBuffer.position(iPosition);
        s sVar = new s(bArr, iLimit);
        if (sVar.e(3) != 5) {
            Log.e("AacUtil", "Don't have PCE in frame");
            return null;
        }
        sVar.l(4);
        sVar.l(2);
        sVar.l(4);
        int iE = sVar.e(4);
        int iE2 = sVar.e(4);
        int iE3 = sVar.e(4);
        int iE4 = sVar.e(2);
        int iE5 = sVar.e(3);
        int iE6 = sVar.e(4);
        if (1 == sVar.e(1)) {
            sVar.l(4);
        }
        if (1 == sVar.e(1)) {
            sVar.l(4);
        }
        if (1 == sVar.e(1)) {
            sVar.l(2);
            sVar.l(1);
        }
        for (int i3 = 0; i3 < iE; i3++) {
            sVar.l(1);
            sVar.l(4);
        }
        for (int i4 = 0; i4 < iE2; i4++) {
            sVar.l(1);
            sVar.l(4);
        }
        for (int i5 = 0; i5 < iE3; i5++) {
            sVar.l(1);
            sVar.l(4);
        }
        for (int i6 = 0; i6 < iE4; i6++) {
            sVar.l(4);
        }
        for (int i7 = 0; i7 < iE5; i7++) {
            sVar.l(4);
        }
        for (int i8 = 0; i8 < iE6; i8++) {
            sVar.l(1);
            sVar.l(4);
        }
        sVar.l(sVar.b() % 8);
        int iE7 = sVar.e(8);
        for (int i9 = 0; i9 < iE7; i9++) {
            sVar.l(8);
        }
        int iB = iLimit > sVar.b() / 8 ? iLimit - (sVar.b() / 8) : 0;
        ByteBuffer byteBufferAllocate = ByteBuffer.allocate(iB);
        byteBufferAllocate.put(bArr, 0, iB);
        byteBufferAllocate.position(0);
        Log.i("AacUtil", "pceLength:" + iB);
        if ((o.a() & 2) > 0) {
            String str2 = " ";
            for (int i10 = 0; i10 < iB; i10++) {
                str2 = (str2 + Integer.toHexString(byteBufferAllocate.get()).toUpperCase()) + " ";
            }
            o.c("AacUtil", 2, "PCE String:", str2);
            byteBufferAllocate.position(0);
        }
        return byteBufferAllocate;
    }
}
