package b0;

import androidx.media3.decoder.midi.MidiDecoder;
import com.cvte.vman.instance.InvokeCmd;
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: loaded from: classes.dex */
public abstract class h {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    private static final int[] f2990a = {1, 2, 2, 2, 2, 3, 3, 4, 4, 5, 6, 6, 6, 7, 8, 8};

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    private static final int[] f2991b = {-1, 8000, 16000, TvPvrManager.PVR_PLAYBACK_SPEED_FF_32X, -1, -1, 11025, 22050, MidiDecoder.DEFAULT_SAMPLE_RATE, -1, -1, PlayerImpl.TVPLAYER_CI_EVENT_START, 24000, 48000, -1, -1};

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private static final int[] f2992c = {64, 112, 128, TvLanguage.GORONTALO, TvLanguage.INTERLINGUA, 256, TvLanguage.LULESAMI, TvLanguage.KLINGON, 512, 640, 768, 896, 1024, 1152, 1280, 1536, 1920, 2048, 2304, 2560, 2688, 2816, InvokeCmd.CMD_DEVICE_GET_USBSW_SIDE, 2944, 3072, 3840, 4096, InvokeCmd.CMD_RS232_CTRL_START, InvokeCmd.CMD_PTZ_CTRL_START};

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private static final s f2993d = new s();

    private enum a {
        rawBigEndian,
        rawLittleEndian,
        _14BitsBigEndian,
        _14BitsLittleEndian
    }

    public static int a(byte[] bArr) {
        return (((bArr[7] & 240) >> 4) | ((bArr[5] & 2) << 12) | ((bArr[6] & 255) << 4)) + 1;
    }

    public static int b(byte[] bArr) {
        int i2;
        int i3;
        s sVar = f2993d;
        sVar.i(bArr);
        sVar.l(42);
        if (sVar.e(1) == 0) {
            i2 = 8;
            i3 = 16;
        } else {
            i2 = 12;
            i3 = 20;
        }
        sVar.e(i2);
        return sVar.e(i3) + 1;
    }

    public static int c(ByteBuffer byteBuffer) {
        int i2;
        int i3;
        int iPosition = byteBuffer.position();
        a aVar = a.rawBigEndian;
        while (true) {
            i2 = iPosition + 4;
            if (i2 < byteBuffer.limit()) {
                if (byteBuffer.get(iPosition) != 127 || (byteBuffer.get(iPosition + 1) & 255) != 254 || (byteBuffer.get(iPosition + 2) & 255) != 128 || byteBuffer.get(iPosition + 3) != 1) {
                    if ((byteBuffer.get(iPosition) & 255) != 255 || byteBuffer.get(iPosition + 1) != 31 || byteBuffer.get(iPosition + 2) != 0 || (byteBuffer.get(iPosition + 3) & 255) != 232) {
                        if ((byteBuffer.get(iPosition) & 255) == 254 && byteBuffer.get(iPosition + 1) == 127 && byteBuffer.get(iPosition + 2) == 1 && (byteBuffer.get(iPosition + 3) & 255) == 128) {
                            aVar = a.rawLittleEndian;
                            break;
                        }
                        iPosition++;
                    } else {
                        aVar = a._14BitsLittleEndian;
                        break;
                    }
                } else {
                    aVar = a.rawBigEndian;
                    break;
                }
            } else {
                break;
            }
        }
        int i4 = 0;
        if (aVar == a._14BitsLittleEndian) {
            int[] iArr = new int[2];
            iArr[0] = 0;
            iArr[1] = 0;
            int i5 = 32;
            while (iPosition < byteBuffer.limit()) {
                int i6 = iPosition + 1;
                int i7 = byteBuffer.get(iPosition) & 255;
                iPosition += 2;
                int i8 = (((byteBuffer.get(i6) & 255) << 8) | i7) & 16383;
                if (i5 < 14) {
                    int i9 = 14 - i5;
                    iArr[i4] = (iArr[i4] << i5) | (i8 >>> i9);
                    i4++;
                    if (i4 >= 2) {
                        break;
                    }
                    iArr[i4] = (16383 >> i5) & i8;
                    i5 = 32 - i9;
                } else {
                    iArr[i4] = i8 | (iArr[i4] << 14);
                    i5 -= 14;
                }
            }
            i3 = (iArr[1] & 33292288) >> 18;
        } else {
            int i10 = iPosition + 5;
            if (i10 >= byteBuffer.limit()) {
                return 0;
            }
            if (aVar == a.rawLittleEndian) {
                i3 = ((byteBuffer.get(i2) & 252) >> 2) | ((byteBuffer.get(i10) & 1) << 6);
            } else {
                i3 = ((byteBuffer.get(i10) & 252) >> 2) | ((byteBuffer.get(i2) & 1) << 6);
            }
        }
        return (i3 + 1) * 32;
    }

    public static int d(byte[] bArr) {
        return ((((bArr[5] & 252) >> 2) | ((bArr[4] & 1) << 6)) + 1) * 32;
    }

    public static int e(ByteBuffer byteBuffer, int i2) {
        int iPosition = byteBuffer.position();
        int i3 = (byteBuffer.get(iPosition + 5) & SDKKeyboardCode.FUNCTION_KEY_BOARD_3) == 0 ? iPosition + 8 : iPosition + 9;
        if ((byteBuffer.get(i3) & SDKKeyboardCode.FUNCTION_KEY_BOARD_M) <= 0) {
            return 0;
        }
        int i4 = (byteBuffer.get(i3) & SDKKeyboardCode.FUNCTION_KEY_BOARD_I) >> 2;
        int i5 = (((byteBuffer.get(i3 + 1) & SDKKeyboardCode.FUNCTION_KEY_BOARD_VOLUME_DOWN) >> 7) | ((byteBuffer.get(i3) & 3) << 1)) + 1;
        if (i4 == 0) {
            return ((i5 * 512) * i2) / TvPvrManager.PVR_PLAYBACK_SPEED_FF_32X;
        }
        if (i4 == 1) {
            return ((i5 * 512) * i2) / MidiDecoder.DEFAULT_SAMPLE_RATE;
        }
        if (i4 != 2) {
            return 0;
        }
        return ((i5 * 512) * i2) / 48000;
    }

    public static n.x f(byte[] bArr, String str, long j2, String str2) {
        s sVar = f2993d;
        sVar.i(bArr);
        sVar.l(60);
        int i2 = f2990a[sVar.e(6)];
        int i3 = f2991b[sVar.e(4)];
        int iE = sVar.e(5);
        int[] iArr = f2992c;
        int i4 = iE >= iArr.length ? -1 : (iArr[iE] * 1000) / 2;
        sVar.l(10);
        return n.x.h(str, "audio/vnd.dts", i4, -1, j2, i2 + (sVar.e(2) > 0 ? 1 : 0), i3, null, str2);
    }

    public static n.x g(byte[] bArr, String str, long j2, String str2) {
        return n.x.h(str, "audio/vnd.dts", -1, -1, j2, 8, 48000, null, str2);
    }
}
