diff --git a/README.md b/README.md index 756eb8e..89dc4be 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ In spite of these design choices, Divinus boasts numerous features that cater to | infinity6b0[^14] | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | | infinity6e[^15] | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | | infinity6c[^16] | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | -| infinity6f[^17] | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | +| mercury6[^17] | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ | _✔️ - supported, ↻ - in development, ✗ - unsupported, ⁿ/ₐ - not supported by hardware_ @@ -60,7 +60,7 @@ _* At the moment, text, RGB or bitfield bitmaps and PNG overlays are handled, mo [^14]: SSC33\[3/5/7\]\(DE\) [^15]: SSC30K\[D/Q\], SSC336\[D/Q\], SSC338\[D/G/Q\] and SSC339G [^16]: SSC377\(D/DE/QE\) or SSC378\[DE/QE\] -[^17]: SSC379G +[^17]: SSC359G ### Documentation diff --git a/src/error.c b/src/error.c index 62cdae2..8fd4f31 100644 --- a/src/error.c +++ b/src/error.c @@ -52,23 +52,23 @@ char *errstr(int error) { error |= (module << 16); break; } break; - case HAL_PLATFORM_I6F: + case HAL_PLATFORM_M6: level = (error >> 12) & 0xF; error = error & 0xFF000FFF | (level > 0 ? (4 << 13) : 0); switch (module) { - case I6F_SYS_MOD_SYS: + case M6_SYS_MOD_SYS: error |= (V4_SYS_MOD_SYS << 16); break; - case I6F_SYS_MOD_ISP: + case M6_SYS_MOD_ISP: error |= (V4_SYS_MOD_ISP << 16); break; - case I6F_SYS_MOD_VIF: + case M6_SYS_MOD_VIF: error |= (V4_SYS_MOD_VIU << 16); break; - case I6F_SYS_MOD_SCL: + case M6_SYS_MOD_SCL: error |= (V4_SYS_MOD_VPSS << 16); break; - case I6F_SYS_MOD_VENC: + case M6_SYS_MOD_VENC: error |= (V4_SYS_MOD_VENC << 16); break; - case I6F_SYS_MOD_RGN: + case M6_SYS_MOD_RGN: error |= (V4_SYS_MOD_RGN << 16); break; - case I6F_SYS_MOD_AI: + case M6_SYS_MOD_AI: error |= (V4_SYS_MOD_AI << 16); break; default: error |= (module << 16); break; diff --git a/src/hal/star/m6_aud.h b/src/hal/star/m6_aud.h new file mode 100644 index 0000000..bd9b796 --- /dev/null +++ b/src/hal/star/m6_aud.h @@ -0,0 +1,191 @@ +#pragma once + +#include "m6_common.h" + +#define M6_AUD_CHN_NUM 16 + +typedef enum { + M6_AUD_BIT_16, + M6_AUD_BIT_24, + M6_AUD_BIT_32, + M6_AUD_BIT_END +} m6_aud_bit; + +typedef enum { + M6_AUD_CLK_OFF, + M6_AUD_CLK_12_288M, + M6_AUD_CLK_16_384M, + M6_AUD_CLK_18_432M, + M6_AUD_CLK_24_576M, + M6_AUD_CLK_24M, + M6_AUD_CLK_48M +} m6_aud_clk; + +typedef enum { + M6_AUD_G726_16K, + M6_AUD_G726_24K, + M6_AUD_G726_32K, + M6_AUD_G726_40K +} m6_aud_g726t; + +typedef enum { + M6_AUD_INTF_I2S_MASTER, + M6_AUD_INTF_I2S_SLAVE, + M6_AUD_INTF_TDM_MASTER, + M6_AUD_INTF_TDM_SLAVE, + M6_AUD_INTF_END +} m6_aud_intf; + +typedef enum { + M6_AUD_SND_MONO, + M6_AUD_SND_STEREO, + M6_AUD_SND_QUEUE, + M6_AUD_SND_END +} m6_aud_snd; + +typedef enum { + M6_AUD_TYPE_G711A, + M6_AUD_TYPE_G711U, + M6_AUD_TYPE_G726, +} m6_aud_type; + +typedef struct { + int leftJustOn; + m6_aud_clk clock; + char syncRxClkOn; + unsigned int tdmSlotNum; + m6_aud_bit bit; +} m6_aud_i2s; + +typedef struct { + // Accept industry standards from 8000 to 96000Hz + int rate; + m6_aud_bit bit; + m6_aud_intf intf; + m6_aud_snd sound; + unsigned int frmNum; + unsigned int packNumPerFrm; + unsigned int codecChnNum; + unsigned int chnNum; + m6_aud_i2s i2s; +} m6_aud_cnf; + +typedef struct { + m6_aud_bit bit; + m6_aud_snd sound; + void *addr[M6_AUD_CHN_NUM]; + unsigned long long timestamp; + unsigned int sequence; + unsigned int length[M6_AUD_CHN_NUM]; + unsigned int poolId[2]; + void *pcmAddr[M6_AUD_CHN_NUM]; + unsigned int pcmLength[M6_AUD_CHN_NUM]; +} m6_aud_frm; + +typedef struct { + m6_aud_frm frame; + char isValid; +} m6_aud_efrm; + +typedef struct { + // Accept industry standards from 8000 to 96000Hz + int rate; + m6_aud_snd sound; +} m6_aud_g711; + +typedef struct { + // Accept industry standards from 8000 to 96000Hz + int rate; + m6_aud_snd sound; + m6_aud_g726t type; +} m6_aud_g726; + +typedef struct { + m6_aud_type type; + union { + m6_aud_g711 g711; + m6_aud_g726t g726; + }; +} m6_aud_para; + +typedef struct { + void *handle; + + int (*fnDisableDevice)(int device); + int (*fnEnableDevice)(int device); + int (*fnSetDeviceConfig)(int device, m6_aud_cnf *config); + + int (*fnDisableChannel)(int device, int channel); + int (*fnEnableChannel)(int device, int channel); + + int (*fnDisableEncoding)(int device, int channel); + int (*fnEnableEncoding)(int device, int channel); + int (*fnSetEncodingParam)(int device, int channel, m6_aud_para *param); + + int (*fnSetMute)(int device, int channel, char active); + int (*fnSetVolume)(int device, int channel, int dbLevel); + + int (*fnFreeFrame)(int device, int channel, m6_aud_frm *frame, m6_aud_efrm *encFrame); + int (*fnGetFrame)(int device, int channel, m6_aud_frm *frame, m6_aud_efrm *encFrame, int millis); +} m6_aud_impl; + +static int m6_aud_load(m6_aud_impl *aud_lib) { + if (!(aud_lib->handle = dlopen("libmi_ai.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("m6_aud", "Failed to load library!\nError: %s\n", dlerror()); + + if (!(aud_lib->fnDisableDevice = (int(*)(int device)) + hal_symbol_load("m6_aud", aud_lib->handle, "MI_AI_Disable"))) + return EXIT_FAILURE; + + if (!(aud_lib->fnEnableDevice = (int(*)(int device)) + hal_symbol_load("m6_aud", aud_lib->handle, "MI_AI_Enable"))) + return EXIT_FAILURE; + + if (!(aud_lib->fnSetDeviceConfig = (int(*)(int device, m6_aud_cnf *config)) + hal_symbol_load("m6_aud", aud_lib->handle, "MI_AI_SetPubAttr"))) + return EXIT_FAILURE; + + if (!(aud_lib->fnDisableChannel = (int(*)(int device, int channel)) + hal_symbol_load("m6_aud", aud_lib->handle, "MI_AI_DisableChn"))) + return EXIT_FAILURE; + + if (!(aud_lib->fnEnableChannel = (int(*)(int device, int channel)) + hal_symbol_load("m6_aud", aud_lib->handle, "MI_AI_EnableChn"))) + return EXIT_FAILURE; + + if (!(aud_lib->fnDisableEncoding = (int(*)(int device, int channel)) + hal_symbol_load("m6_aud", aud_lib->handle, "MI_AI_DisableAenc"))) + return EXIT_FAILURE; + + if (!(aud_lib->fnEnableEncoding = (int(*)(int device, int channel)) + hal_symbol_load("m6_aud", aud_lib->handle, "MI_AI_EnableAenc"))) + return EXIT_FAILURE; + + if (!(aud_lib->fnSetEncodingParam = (int(*)(int device, int channel, m6_aud_para *param)) + hal_symbol_load("m6_aud", aud_lib->handle, "MI_AI_SetAencAttr"))) + return EXIT_FAILURE; + + if (!(aud_lib->fnSetMute = (int(*)(int device, int channel, char active)) + hal_symbol_load("m6_aud", aud_lib->handle, "MI_AI_SetMute"))) + return EXIT_FAILURE; + + if (!(aud_lib->fnSetVolume = (int(*)(int device, int channel, int dbLevel)) + hal_symbol_load("m6_aud", aud_lib->handle, "MI_AI_SetVqeVolume"))) + return EXIT_FAILURE; + + if (!(aud_lib->fnFreeFrame = (int(*)(int device, int channel, m6_aud_frm *frame, m6_aud_efrm *encFrame)) + hal_symbol_load("m6_aud", aud_lib->handle, "MI_AI_ReleaseFrame"))) + return EXIT_FAILURE; + + if (!(aud_lib->fnGetFrame = (int(*)(int device, int channel, m6_aud_frm *frame, m6_aud_efrm *encFrame, int millis)) + hal_symbol_load("m6_aud", aud_lib->handle, "MI_AI_GetFrame"))) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + +static void m6_aud_unload(m6_aud_impl *aud_lib) { + if (aud_lib->handle) dlclose(aud_lib->handle); + aud_lib->handle = NULL; + memset(aud_lib, 0, sizeof(*aud_lib)); +} \ No newline at end of file diff --git a/src/hal/star/m6_common.h b/src/hal/star/m6_common.h new file mode 100644 index 0000000..ba4cf0b --- /dev/null +++ b/src/hal/star/m6_common.h @@ -0,0 +1,110 @@ +#pragma once + +#include +#include +#include + +#include "../symbols.h" +#include "../types.h" + +typedef enum { + M6_BAYER_RG, + M6_BAYER_GR, + M6_BAYER_BG, + M6_BAYER_GB, + M6_BAYER_R0, + M6_BAYER_G0, + M6_BAYER_B0, + M6_BAYER_G1, + M6_BAYER_G2, + M6_BAYER_I0, + M6_BAYER_G3, + M6_BAYER_I1, + M6_BAYER_END +} m6_common_bayer; + +typedef enum { + M6_COMPR_NONE, + M6_COMPR_SEG, + M6_COMPR_LINE, + M6_COMPR_FRAME, + M6_COMPR_8BIT, + M6_COMPR_END +} m6_common_compr; + +typedef enum { + M6_EDGE_SINGLE_UP, + M6_EDGE_SINGLE_DOWN, + M6_EDGE_DOUBLE, + M6_EDGE_END +} m6_common_edge; + +typedef enum { + M6_HDR_OFF, + M6_HDR_VC, + M6_HDR_DOL, + M6_HDR_EMBED, + M6_HDR_LI, + M6_HDR_END +} m6_common_hdr; + +typedef enum { + M6_INTF_BT656, + M6_INTF_DIGITAL_CAMERA, + M6_INTF_BT1120_STANDARD, + M6_INTF_BT1120_INTERLEAVED, + M6_INTF_MIPI, + M6_INTF_END +} m6_common_intf; + +typedef enum { + M6_PREC_8BPP, + M6_PREC_10BPP, + M6_PREC_12BPP, + M6_PREC_14BPP, + M6_PREC_16BPP, + M6_PREC_END +} m6_common_prec; + +typedef enum { + M6_PIXFMT_YUV422_YUYV, + M6_PIXFMT_ARGB8888, + M6_PIXFMT_ABGR8888, + M6_PIXFMT_BGRA8888, + M6_PIXFMT_RGB565, + M6_PIXFMT_ARGB1555, + M6_PIXFMT_ARGB4444, + M6_PIXFMT_I2, + M6_PIXFMT_I4, + M6_PIXFMT_I8, + M6_PIXFMT_YUV422SP, + M6_PIXFMT_YUV420SP, + M6_PIXFMT_YUV420SP_NV21, + M6_PIXFMT_YUV420_TILE, + M6_PIXFMT_YUV422_UYVY, + M6_PIXFMT_YUV422_YVYU, + M6_PIXFMT_YUV422_VYUY, + M6_PIXFMT_YUV422P, + M6_PIXFMT_YUV420P, + M6_PIXFMT_YUV420_FBC, + M6_PIXFMT_RGB_BAYER, + M6_PIXFMT_RGB_BAYER_END = + M6_PIXFMT_RGB_BAYER + M6_PREC_END * M6_BAYER_END - 1, + M6_PIXFMT_RGB888, + M6_PIXFMT_BGR888, + M6_PIXFMT_GRAY8, + M6_PIXFMT_RGB101010, + M6_PIXFMT_END +} m6_common_pixfmt; + +typedef struct { + unsigned short width; + unsigned short height; +} m6_common_dim; + +typedef struct { + unsigned short x; + unsigned short y; + unsigned short width; + unsigned short height; +} m6_common_rect; \ No newline at end of file diff --git a/src/hal/star/m6_hal.c b/src/hal/star/m6_hal.c new file mode 100644 index 0000000..3c686e7 --- /dev/null +++ b/src/hal/star/m6_hal.c @@ -0,0 +1,952 @@ +#ifdef __arm__ + +#include "m6_hal.h" + +m6_aud_impl m6_aud; +m6_isp_impl m6_isp; +m6_rgn_impl m6_rgn; +m6_scl_impl m6_scl; +m6_snr_impl m6_snr; +m6_sys_impl m6_sys; +m6_venc_impl m6_venc; +m6_vif_impl m6_vif; + +hal_chnstate m6_state[M6_VENC_CHN_NUM] = {0}; +int (*m6_aud_cb)(hal_audframe*); +int (*m6_vid_cb)(char, hal_vidstream*); + +m6_snr_pad _m6_snr_pad; +m6_snr_plane _m6_snr_plane; +char _m6_snr_framerate, _m6_snr_hdr, _m6_snr_index, _m6_snr_profile; + +char _m6_aud_chn = 0; +char _m6_aud_dev = 0; +char _m6_isp_chn = 0; +char _m6_isp_dev = 0; +char _m6_isp_port = 0; +char _m6_scl_chn = 0; +char _m6_scl_dev = 0; +char _m6_venc_dev[M6_VENC_CHN_NUM] = { 255 }; +char _m6_venc_port = 0; +char _m6_vif_chn = 0; +char _m6_vif_dev = 0; +char _m6_vif_grp = 0; + +void m6_hal_deinit(void) +{ + m6_vif_unload(&m6_vif); + m6_venc_unload(&m6_venc); + m6_snr_unload(&m6_snr); + m6_scl_unload(&m6_scl); + m6_rgn_unload(&m6_rgn); + m6_isp_unload(&m6_isp); + m6_aud_unload(&m6_aud); + m6_sys_unload(&m6_sys); +} + +int m6_hal_init(void) +{ + int ret; + + if (ret = m6_sys_load(&m6_sys)) + return ret; + if (ret = m6_aud_load(&m6_aud)) + return ret; + if (ret = m6_isp_load(&m6_isp)) + return ret; + if (ret = m6_rgn_load(&m6_rgn)) + return ret; + if (ret = m6_scl_load(&m6_scl)) + return ret; + if (ret = m6_snr_load(&m6_snr)) + return ret; + if (ret = m6_venc_load(&m6_venc)) + return ret; + if (ret = m6_vif_load(&m6_vif)) + return ret; + + return EXIT_SUCCESS; +} + +void m6_audio_deinit(void) +{ + m6_aud.fnDisableChannel(_m6_aud_dev, _m6_aud_chn); + + m6_aud.fnDisableDevice(_m6_aud_dev); +} + + +int m6_audio_init(int samplerate) +{ + int ret; + + { + m6_aud_cnf config; + config.rate = samplerate; + config.bit = M6_AUD_BIT_16; + config.intf = M6_AUD_INTF_I2S_SLAVE; + config.sound = M6_AUD_SND_MONO; + config.frmNum = 0; + config.packNumPerFrm = 640; + config.codecChnNum = 0; + config.chnNum = 1; + config.i2s.clock = M6_AUD_CLK_OFF; + config.i2s.leftJustOn = 0; + config.i2s.syncRxClkOn = 0; + config.i2s.tdmSlotNum = 0; + config.i2s.bit = M6_AUD_BIT_16; + if (ret = m6_aud.fnSetDeviceConfig(_m6_aud_dev, &config)) + return ret; + } + if (ret = m6_aud.fnEnableDevice(_m6_aud_dev)) + return ret; + + if (ret = m6_aud.fnEnableChannel(_m6_aud_dev, _m6_aud_chn)) + return ret; + if (ret = m6_aud.fnSetVolume(_m6_aud_dev, _m6_aud_chn, 13)) + return ret; + + { + m6_sys_bind bind = { .module = M6_SYS_MOD_AI, + .device = _m6_aud_dev, .channel = _m6_aud_chn }; + if (ret = m6_sys.fnSetOutputDepth(0, &bind, 2, 4)) + return ret; + } + + return EXIT_SUCCESS; +} + +void *m6_audio_thread(void) +{ + int ret; + + m6_aud_frm frame; + memset(&frame, 0, sizeof(frame)); + + while (keepRunning) { + if (ret = m6_aud.fnGetFrame(_m6_aud_dev, _m6_aud_chn, + &frame, NULL, 128)) { + HAL_WARNING("m6_aud", "Getting the frame failed " + "with %#x!\n", ret); + continue; + } + + if (m6_aud_cb) { + hal_audframe outFrame; + outFrame.channelCnt = 1; + outFrame.data[0] = frame.addr[0]; + outFrame.length[0] = frame.length[0]; + outFrame.seq = frame.sequence; + outFrame.timestamp = frame.timestamp; + (m6_aud_cb)(&outFrame); + } + + if (ret = m6_aud.fnFreeFrame(_m6_aud_dev, _m6_aud_chn, + &frame, NULL)) { + HAL_WARNING("m6_aud", "Releasing the frame failed" + " with %#x!\n", ret); + } + } + HAL_INFO("m6_aud", "Shutting down capture thread...\n"); +} + +int m6_channel_bind(char index, char framerate) +{ + int ret; + + if (ret = m6_scl.fnEnablePort(_m6_scl_dev, _m6_scl_chn, index)) + return ret; + + { + m6_sys_bind source = { .module = M6_SYS_MOD_SCL, + .device = _m6_scl_dev, .channel = _m6_scl_chn, .port = index }; + m6_sys_bind dest = { .module = M6_SYS_MOD_VENC, + .device = _m6_venc_dev[index] ? M6_VENC_DEV_MJPG_0 : M6_VENC_DEV_H26X_0, + .channel = index, .port = _m6_venc_port }; + if (ret = m6_sys.fnBindExt(0, &source, &dest, framerate, framerate, + _m6_venc_dev[index] >= M6_VENC_DEV_MJPG_0 ? + M6_SYS_LINK_FRAMEBASE : M6_SYS_LINK_REALTIME, 0)) + return ret; + } + + return EXIT_SUCCESS; +} + +int m6_channel_create(char index, short width, short height, char mirror, char flip, char jpeg) +{ + m6_scl_port port; + port.crop.x = 0; + port.crop.y = 0; + port.crop.width = 0; + port.crop.height = 0; + port.output.width = width; + port.output.height = height; + port.mirror = mirror; + port.flip = flip; + port.compress = M6_COMPR_NONE; + port.pixFmt = jpeg ? M6_PIXFMT_YUV422_YUYV : M6_PIXFMT_YUV420SP; + + return m6_scl.fnSetPortConfig(_m6_scl_dev, _m6_scl_chn, index, &port); +} + +int m6_channel_grayscale(char enable) +{ + return m6_isp.fnSetColorToGray(_m6_isp_dev, 0, &enable); +} + +int m6_channel_unbind(char index) +{ + int ret; + + if (ret = m6_scl.fnDisablePort(_m6_scl_dev, _m6_scl_chn, index)) + return ret; + + { + m6_sys_bind source = { .module = M6_SYS_MOD_SCL, + .device = _m6_scl_dev, .channel = _m6_scl_chn, .port = index }; + m6_sys_bind dest = { .module = M6_SYS_MOD_VENC, + .device = _m6_venc_dev[index], .channel = index, .port = _m6_venc_port }; + if (ret = m6_sys.fnUnbind(0, &source, &dest)) + return ret; + } + + return EXIT_SUCCESS; +} + +int m6_config_load(char *path) +{ + return m6_isp.fnLoadChannelConfig(_m6_isp_dev, _m6_isp_chn, path, 1234); +} + +int m6_pipeline_create(char sensor, short width, short height, char framerate) +{ + int ret; + + _m6_snr_index = sensor; + _m6_snr_profile = -1; + + { + unsigned int count; + m6_snr_res resolution; + if (ret = m6_snr.fnSetPlaneMode(_m6_snr_index, 0)) + return ret; + + if (ret = m6_snr.fnGetResolutionCount(_m6_snr_index, &count)) + return ret; + for (char i = 0; i < count; i++) { + if (ret = m6_snr.fnGetResolution(_m6_snr_index, i, &resolution)) + return ret; + + if (width > resolution.crop.width || + height > resolution.crop.height || + framerate > resolution.maxFps) + continue; + + _m6_snr_profile = i; + if (ret = m6_snr.fnSetResolution(_m6_snr_index, _m6_snr_profile)) + return ret; + _m6_snr_framerate = framerate; + if (ret = m6_snr.fnSetFramerate(_m6_snr_index, _m6_snr_framerate)) + return ret; + break; + } + if (_m6_snr_profile < 0) + return EXIT_FAILURE; + } + + if (ret = m6_snr.fnGetPadInfo(_m6_snr_index, &_m6_snr_pad)) + return ret; + if (ret = m6_snr.fnGetPlaneInfo(_m6_snr_index, 0, &_m6_snr_plane)) + return ret; + if (ret = m6_snr.fnEnable(_m6_snr_index)) + return ret; + + { + m6_vif_grp group; + group.intf = _m6_snr_pad.intf; + group.work = M6_VIF_WORK_1MULTIPLEX; + group.hdr = M6_HDR_OFF; + group.edge = group.intf == M6_INTF_BT656 ? + _m6_snr_pad.intfAttr.bt656.edge : M6_EDGE_DOUBLE; + group.interlaceOn = 0; + group.grpStitch = (1 << _m6_vif_grp); + if (ret = m6_vif.fnCreateGroup(_m6_vif_grp, &group)) + return ret; + } + + { + m6_vif_dev device; + device.pixFmt = (m6_common_pixfmt)(_m6_snr_plane.bayer > M6_BAYER_END ? + _m6_snr_plane.pixFmt : (M6_PIXFMT_RGB_BAYER + _m6_snr_plane.precision * M6_BAYER_END + _m6_snr_plane.bayer)); + device.crop = _m6_snr_plane.capt; + device.field = 0; + device.halfHScan = 0; + if (ret = m6_vif.fnSetDeviceConfig(_m6_vif_dev, &device)) + return ret; + } + if (ret = m6_vif.fnEnableDevice(_m6_vif_dev)) + return ret; + + { + m6_vif_port port; + port.capt = _m6_snr_plane.capt; + port.dest.height = _m6_snr_plane.capt.height; + port.dest.width = _m6_snr_plane.capt.width; + port.pixFmt = (m6_common_pixfmt)(_m6_snr_plane.bayer > M6_BAYER_END ? + _m6_snr_plane.pixFmt : (M6_PIXFMT_RGB_BAYER + _m6_snr_plane.precision * M6_BAYER_END + _m6_snr_plane.bayer)); + port.frate = M6_VIF_FRATE_FULL; + if (ret = m6_vif.fnSetPortConfig(_m6_vif_dev, _m6_vif_chn, &port)) + return ret; + } + if (ret = m6_vif.fnEnablePort(_m6_vif_dev, _m6_vif_chn)) + return ret; + + { + unsigned int combo = 1; + if (ret = m6_isp.fnCreateDevice(_m6_isp_dev, &combo)) + return ret; + } + + { + m6_isp_chn channel; + memset(&channel, 0, sizeof(channel)); + channel.sensorId = (1 << _m6_snr_index); + if (ret = m6_isp.fnCreateChannel(_m6_isp_dev, _m6_isp_chn, &channel)) + return ret; + } + + { + m6_isp_para param; + param.hdr = M6_HDR_OFF; + param.level3DNR = 1; + param.mirror = 0; + param.flip = 0; + param.rotate = 0; + if (ret = m6_isp.fnSetChannelParam(_m6_isp_dev, _m6_isp_chn, ¶m)) + return ret; + } + if (ret = m6_isp.fnStartChannel(_m6_isp_dev, _m6_isp_chn)) + return ret; + + { + m6_isp_port port; + memset(&port, 0, sizeof(port)); + port.pixFmt = M6_PIXFMT_YUV422_YUYV; + if (ret = m6_isp.fnSetPortConfig(_m6_isp_dev, _m6_isp_chn, _m6_isp_port, &port)) + return ret; + } + if (ret = m6_isp.fnEnablePort(_m6_isp_dev, _m6_isp_chn, _m6_isp_port)) + return ret; + + { + unsigned int binds = (1 << 0) | (1 << 1) | (1 << 2) | (1 << 3); + if (ret = m6_scl.fnCreateDevice(_m6_scl_dev, &binds)) + return ret; + } + + { + unsigned int reserved = 0; + if (ret = m6_scl.fnCreateChannel(_m6_scl_dev, _m6_scl_chn, &reserved)) + return ret; + } + { + int rotate = 0; + if (ret = m6_scl.fnAdjustChannelRotation(_m6_scl_dev, _m6_scl_chn, &rotate)) + return ret; + } + if (ret = m6_scl.fnStartChannel(_m6_scl_dev, _m6_scl_chn)) + return ret; + + { + m6_sys_bind source = { .module = M6_SYS_MOD_VIF, + .device = _m6_vif_dev, .channel = _m6_vif_chn, .port = 0 }; + m6_sys_bind dest = { .module = M6_SYS_MOD_ISP, + .device = _m6_isp_dev, .channel = _m6_isp_chn, .port = _m6_isp_port }; + if (ret = m6_sys.fnBindExt(0, &source, &dest, _m6_snr_framerate, _m6_snr_framerate, + M6_SYS_LINK_REALTIME, 0)) + return ret; + } + + { + m6_sys_bind source = { .module = M6_SYS_MOD_ISP, + .device = _m6_isp_dev, .channel = _m6_isp_chn, .port = _m6_isp_port }; + m6_sys_bind dest = { .module = M6_SYS_MOD_SCL, + .device = _m6_scl_dev, .channel = _m6_scl_chn, .port = 0 }; + return m6_sys.fnBindExt(0, &source, &dest, _m6_snr_framerate, _m6_snr_framerate, + M6_SYS_LINK_REALTIME, 0); + } + + return EXIT_SUCCESS; +} + +void m6_pipeline_destroy(void) +{ + for (char i = 0; i < 4; i++) + m6_scl.fnDisablePort(_m6_scl_dev, _m6_scl_chn, i); + + { + m6_sys_bind source = { .module = M6_SYS_MOD_ISP, + .device = _m6_isp_dev, .channel = _m6_isp_chn, .port = _m6_isp_port }; + m6_sys_bind dest = { .module = M6_SYS_MOD_SCL, + .device = _m6_scl_dev, .channel = _m6_scl_chn, .port = 0 }; + m6_sys.fnUnbind(0, &source, &dest); + } + + m6_scl.fnStopChannel(_m6_scl_dev, _m6_scl_chn); + m6_scl.fnDestroyChannel(_m6_scl_dev, _m6_scl_chn); + + m6_scl.fnDestroyDevice(_m6_scl_dev); + + m6_isp.fnStopChannel(_m6_isp_dev, _m6_isp_chn); + m6_isp.fnDestroyChannel(_m6_isp_dev, _m6_isp_chn); + + m6_isp.fnDestroyDevice(_m6_isp_dev); + + { + m6_sys_bind source = { .module = M6_SYS_MOD_VIF, + .device = _m6_vif_dev, .channel = _m6_vif_chn, .port = 0 }; + m6_sys_bind dest = { .module = M6_SYS_MOD_ISP, + .device = _m6_isp_dev, .channel = _m6_isp_chn, .port = _m6_isp_port }; + m6_sys.fnUnbind(0, &source, &dest); + } + + m6_vif.fnDisablePort(_m6_vif_dev, 0); + + m6_vif.fnDisableDevice(_m6_vif_dev); + + m6_snr.fnDisable(_m6_snr_index); +} + +int m6_region_create(char handle, hal_rect rect, short opacity) +{ + int ret; + + m6_sys_bind dest = { .module = M6_SYS_MOD_VENC, .port = _m6_venc_port }; + m6_rgn_cnf region, regionCurr; + m6_rgn_chn attrib, attribCurr; + + region.type = M6_RGN_TYPE_OSD; + region.pixFmt = M6_RGN_PIXFMT_ARGB1555; + region.size.width = rect.width; + region.size.height = rect.height; + + if (m6_rgn.fnGetRegionConfig(0, handle, ®ionCurr)) { + HAL_INFO("m6_rgn", "Creating region %d...\n", handle); + if (ret = m6_rgn.fnCreateRegion(0, handle, ®ion)) + return ret; + } else if (regionCurr.type != region.type || + regionCurr.size.height != region.size.height || + regionCurr.size.width != region.size.width) { + HAL_INFO("m6_rgn", "Parameters are different, recreating " + "region %d...\n", handle); + for (char i = 0; i < M6_VENC_CHN_NUM; i++) { + if (!m6_state[i].enable) continue; + dest.device = _m6_venc_dev[i]; + dest.channel = i; + m6_rgn.fnDetachChannel(0, handle, &dest); + } + m6_rgn.fnDestroyRegion(0, handle); + if (ret = m6_rgn.fnCreateRegion(0, handle, ®ion)) + return ret; + } + + if (m6_rgn.fnGetChannelConfig(0, handle, &dest, &attribCurr)) + HAL_INFO("m6_rgn", "Attaching region %d...\n", handle); + else if (attribCurr.point.x != rect.x || attribCurr.point.x != rect.y || + attribCurr.osd.bgFgAlpha[1] != opacity) { + HAL_INFO("m6_rgn", "Parameters are different, reattaching " + "region %d...\n", handle); + for (char i = 0; i < M6_VENC_CHN_NUM; i++) { + if (!m6_state[i].enable) continue; + dest.device = _m6_venc_dev[i]; + dest.channel = i; + m6_rgn.fnDetachChannel(0, handle, &dest); + } + } + + memset(&attrib, 0, sizeof(attrib)); + attrib.show = 1; + attrib.point.x = rect.x; + attrib.point.y = rect.y; + attrib.osd.layer = 0; + attrib.osd.constAlphaOn = 0; + attrib.osd.bgFgAlpha[0] = 0; + attrib.osd.bgFgAlpha[1] = opacity; + + for (char i = 0; i < M6_VENC_CHN_NUM; i++) { + if (!m6_state[i].enable) continue; + dest.device = _m6_venc_dev[i]; + dest.channel = i; + m6_rgn.fnAttachChannel(0, handle, &dest, &attrib); + } + + return EXIT_SUCCESS; +} + +void m6_region_deinit(void) +{ + m6_rgn.fnDeinit(0); +} + +void m6_region_destroy(char handle) +{ + m6_sys_bind dest = { .module = M6_SYS_MOD_VENC, .port = _m6_venc_port }; + + for (char i = 0; i < M6_VENC_CHN_NUM; i++) { + if (!m6_state[i].enable) continue; + dest.device = _m6_venc_dev[i]; + dest.channel = i; + m6_rgn.fnDetachChannel(0, handle, &dest); + } + m6_rgn.fnDestroyRegion(0, handle); +} + +void m6_region_init(void) +{ + m6_rgn_pal palette = {{{0, 0, 0, 0}}}; + m6_rgn.fnInit(0, &palette); +} + +int m6_region_setbitmap(int handle, hal_bitmap *bitmap) +{ + m6_rgn_bmp nativeBmp = { .data = bitmap->data, .pixFmt = M6_RGN_PIXFMT_ARGB1555, + .size.height = bitmap->dim.height, .size.width = bitmap->dim.width }; + + return m6_rgn.fnSetBitmap(0, handle, &nativeBmp); +} + +int m6_video_create(char index, hal_vidconfig *config) +{ + int ret; + m6_venc_chn channel; + m6_venc_attr_h26x *attrib; + + if (config->codec == HAL_VIDCODEC_JPG || config->codec == HAL_VIDCODEC_MJPG) { + _m6_venc_dev[index] = M6_VENC_DEV_MJPG_0; + channel.attrib.codec = M6_VENC_CODEC_MJPG; + switch (config->mode) { + case HAL_VIDMODE_CBR: + channel.rate.mode = M6_VENC_RATEMODE_MJPGCBR; + channel.rate.mjpgCbr.bitrate = config->bitrate << 10; + channel.rate.mjpgCbr.fpsNum = + config->codec == HAL_VIDCODEC_JPG ? 1 : config->framerate; + channel.rate.mjpgCbr.fpsDen = 1; + break; + case HAL_VIDMODE_QP: + channel.rate.mode = M6_VENC_RATEMODE_MJPGQP; + channel.rate.mjpgQp.fpsNum = config->framerate; + channel.rate.mjpgQp.fpsDen = + config->codec == HAL_VIDCODEC_JPG ? 1 : config->framerate; + channel.rate.mjpgQp.quality = MAX(config->minQual, config->maxQual); + break; + default: + HAL_ERROR("m6_venc", "MJPEG encoder can only support CBR or fixed QP modes!"); + } + + channel.attrib.mjpg.maxHeight = ALIGN_UP(config->height, 2); + channel.attrib.mjpg.maxWidth = ALIGN_UP(config->width, 8); + channel.attrib.mjpg.bufSize = ALIGN_UP(config->width, 8) * ALIGN_UP(config->height, 2); + channel.attrib.mjpg.byFrame = 1; + channel.attrib.mjpg.height = ALIGN_UP(config->height, 2); + channel.attrib.mjpg.width = ALIGN_UP(config->width, 8); + channel.attrib.mjpg.dcfThumbs = 0; + channel.attrib.mjpg.markPerRow = 0; + + goto attach; + } else if (config->codec == HAL_VIDCODEC_H265) { + channel.attrib.codec = M6_VENC_CODEC_H265; + attrib = &channel.attrib.h265; + switch (config->mode) { + case HAL_VIDMODE_CBR: + channel.rate.mode = M6_VENC_RATEMODE_H265CBR; + channel.rate.h265Cbr = (m6_venc_rate_h26xcbr){ .gop = config->gop, + .statTime = 1, .fpsNum = config->framerate, .fpsDen = 1, .bitrate = + (unsigned int)(config->bitrate) << 10, .avgLvl = 1 }; break; + case HAL_VIDMODE_VBR: + channel.rate.mode = M6_VENC_RATEMODE_H265VBR; + channel.rate.h265Vbr = (m6_venc_rate_h26xvbr){ .gop = config->gop, + .statTime = 1, .fpsNum = config->framerate, .fpsDen = 1, .maxBitrate = + (unsigned int)(MAX(config->bitrate, config->maxBitrate)) << 10, + .maxQual = config->maxQual, .minQual = config->minQual }; break; + case HAL_VIDMODE_QP: + channel.rate.mode = M6_VENC_RATEMODE_H265QP; + channel.rate.h265Qp = (m6_venc_rate_h26xqp){ .gop = config->gop, + .fpsNum = config->framerate, .fpsDen = 1, .interQual = config->maxQual, + .predQual = config->minQual }; break; + case HAL_VIDMODE_ABR: + HAL_ERROR("m6_venc", "H.265 encoder does not support ABR mode!"); + case HAL_VIDMODE_AVBR: + channel.rate.mode = M6_VENC_RATEMODE_H265AVBR; + channel.rate.h265Avbr = (m6_venc_rate_h26xvbr){ .gop = config->gop, + .statTime = 1, .fpsNum = config->framerate, .fpsDen = 1, .maxBitrate = + (unsigned int)(MAX(config->bitrate, config->maxBitrate)) << 10, + .maxQual = config->maxQual, .minQual = config->minQual }; break; + default: + HAL_ERROR("m6_venc", "H.265 encoder does not support this mode!"); + } + } else if (config->codec == HAL_VIDCODEC_H264) { + channel.attrib.codec = M6_VENC_CODEC_H264; + attrib = &channel.attrib.h264; + switch (config->mode) { + case HAL_VIDMODE_CBR: + channel.rate.mode = M6_VENC_RATEMODE_H264CBR; + channel.rate.h264Cbr = (m6_venc_rate_h26xcbr){ .gop = config->gop, + .statTime = 1, .fpsNum = config->framerate, .fpsDen = 1, .bitrate = + (unsigned int)(config->bitrate) << 10, .avgLvl = 1 }; break; + case HAL_VIDMODE_VBR: + channel.rate.mode = M6_VENC_RATEMODE_H264VBR; + channel.rate.h264Vbr = (m6_venc_rate_h26xvbr){ .gop = config->gop, + .statTime = 1, .fpsNum = config->framerate, .fpsDen = 1, .maxBitrate = + (unsigned int)(MAX(config->bitrate, config->maxBitrate)) << 10, + .maxQual = config->maxQual, .minQual = config->minQual }; break; + case HAL_VIDMODE_QP: + channel.rate.mode = M6_VENC_RATEMODE_H264QP; + channel.rate.h264Qp = (m6_venc_rate_h26xqp){ .gop = config->gop, + .fpsNum = config->framerate, .fpsDen = 1, .interQual = config->maxQual, + .predQual = config->minQual }; break; + case HAL_VIDMODE_ABR: + channel.rate.mode = M6_VENC_RATEMODE_H264ABR; + channel.rate.h264Abr = (m6_venc_rate_h26xabr){ .gop = config->gop, + .statTime = 1, .fpsNum = config->framerate, .fpsDen = 1, + .avgBitrate = (unsigned int)(config->bitrate) << 10, + .maxBitrate = (unsigned int)(config->maxBitrate) << 10 }; break; + case HAL_VIDMODE_AVBR: + channel.rate.mode = M6_VENC_RATEMODE_H265AVBR; + channel.rate.h265Avbr = (m6_venc_rate_h26xvbr){ .gop = config->gop, + .statTime = 1, .fpsNum = config->framerate, .fpsDen = 1, .maxBitrate = + (unsigned int)(MAX(config->bitrate, config->maxBitrate)) << 10, + .maxQual = config->maxQual, .minQual = config->minQual }; break; + default: + HAL_ERROR("m6_venc", "H.264 encoder does not support this mode!"); + } + } else HAL_ERROR("m6_venc", "This codec is not supported by the hardware!"); + _m6_venc_dev[index] = M6_VENC_DEV_H26X_0; + attrib->maxHeight = config->height; + attrib->maxWidth = config->width; + attrib->bufSize = config->height * config->width; + attrib->profile = config->profile; + attrib->byFrame = 1; + attrib->height = config->height; + attrib->width = config->width; + attrib->bFrameNum = 0; + attrib->refNum = 1; +attach: + if (ret = m6_venc.fnCreateChannel(_m6_venc_dev[index], index, &channel)) + return ret; + + if (config->codec != HAL_VIDCODEC_JPG && + (ret = m6_venc.fnStartReceiving(_m6_venc_dev[index], index))) + return ret; + + m6_state[index].payload = config->codec; + + return EXIT_SUCCESS; +} + +int m6_video_destroy(char index) +{ + int ret; + + m6_state[index].enable = 0; + m6_state[index].payload = HAL_VIDCODEC_UNSPEC; + + m6_venc.fnStopReceiving(_m6_venc_dev[index], index); + + { + m6_sys_bind source = { .module = M6_SYS_MOD_SCL, + .device = _m6_scl_dev, .channel = _m6_scl_chn, .port = index }; + m6_sys_bind dest = { .module = M6_SYS_MOD_VENC, + .device = _m6_venc_dev[index], .channel = index, .port = _m6_venc_port }; + if (ret = m6_sys.fnUnbind(0, &source, &dest)) + return ret; + } + + if (ret = m6_venc.fnDestroyChannel(_m6_venc_dev[index], index)) + return ret; + + if (ret = m6_scl.fnDisablePort(_m6_scl_dev, _m6_scl_chn, index)) + return ret; + + _m6_venc_dev[index] = 255; + + return EXIT_SUCCESS; +} + +int m6_video_destroy_all(void) +{ + int ret; + + for (char i = 0; i < M6_VENC_CHN_NUM; i++) + if (m6_state[i].enable) + if (ret = m6_video_destroy(i)) + return ret; + + return EXIT_SUCCESS; +} + +void m6_video_request_idr(char index) +{ + if (m6_state[index].payload == HAL_VIDCODEC_JPG || + m6_state[index].payload == HAL_VIDCODEC_MJPG) return; + + m6_venc.fnRequestIdr(M6_VENC_DEV_H26X_0, index, 1); +} + +int m6_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg) +{ + int ret; + + if (ret = m6_channel_bind(index, 1)) { + HAL_DANGER("m6_venc", "Binding the encoder channel " + "%d failed with %#x!\n", index, ret); + goto abort; + } + return ret; + + m6_venc_jpg param; + memset(¶m, 0, sizeof(param)); + if (ret = m6_venc.fnGetJpegParam(_m6_venc_dev[index], index, ¶m)) { + HAL_DANGER("m6_venc", "Reading the JPEG settings " + "%d failed with %#x!\n", index, ret); + goto abort; + } + return ret; + return ret; + param.quality = quality; + if (ret = m6_venc.fnSetJpegParam(_m6_venc_dev[index], index, ¶m)) { + HAL_DANGER("m6_venc", "Writing the JPEG settings " + "%d failed with %#x!\n", index, ret); + goto abort; + } + + unsigned int count = 1; + if (ret = m6_venc.fnStartReceivingEx(_m6_venc_dev[index], index, &count)) { + HAL_DANGER("m6_venc", "Requesting one frame " + "%d failed with %#x!\n", index, ret); + goto abort; + } + + int fd = m6_venc.fnGetDescriptor(_m6_venc_dev[index], index); + + struct timeval timeout = { .tv_sec = 2, .tv_usec = 0 }; + fd_set readFds; + FD_ZERO(&readFds); + FD_SET(fd, &readFds); + ret = select(fd + 1, &readFds, NULL, NULL, &timeout); + if (ret < 0) { + HAL_DANGER("m6_venc", "Select operation failed!\n"); + goto abort; + } else if (ret == 0) { + HAL_DANGER("m6_venc", "Capture stream timed out!\n"); + goto abort; + } + + if (FD_ISSET(fd, &readFds)) { + m6_venc_stat stat; + if (ret = m6_venc.fnQuery(_m6_venc_dev[index], index, &stat)) { + HAL_DANGER("m6_venc", "Querying the encoder channel " + "%d failed with %#x!\n", index, ret); + goto abort; + } + + if (!stat.curPacks) { + HAL_DANGER("m6_venc", "Current frame is empty, skipping it!\n"); + goto abort; + } + + m6_venc_strm strm; + memset(&strm, 0, sizeof(strm)); + strm.packet = (m6_venc_pack*)malloc(sizeof(m6_venc_pack) * stat.curPacks); + if (!strm.packet) { + HAL_DANGER("m6_venc", "Memory allocation on channel %d failed!\n", index); + goto abort; + } + strm.count = stat.curPacks; + + if (ret = m6_venc.fnGetStream(_m6_venc_dev[index], index, &strm, stat.curPacks)) { + HAL_DANGER("m6_venc", "Getting the stream on " + "channel %d failed with %#x!\n", index, ret); + free(strm.packet); + strm.packet = NULL; + goto abort; + } + + { + jpeg->jpegSize = 0; + for (unsigned int i = 0; i < strm.count; i++) { + m6_venc_pack *pack = &strm.packet[i]; + unsigned int packLen = pack->length - pack->offset; + unsigned char *packData = pack->data + pack->offset; + + unsigned int newLen = jpeg->jpegSize + packLen; + if (newLen > jpeg->length) { + jpeg->data = realloc(jpeg->data, newLen); + jpeg->length = newLen; + } + memcpy(jpeg->data + jpeg->jpegSize, packData, packLen); + jpeg->jpegSize += packLen; + } + } + +abort: + m6_venc.fnFreeStream(_m6_venc_dev[index], index, &strm); + } + + m6_venc.fnFreeDescriptor(_m6_venc_dev[index], index); + + m6_venc.fnStopReceiving(_m6_venc_dev[index], index); + + m6_channel_unbind(index); + + return ret; +} + +void *m6_video_thread(void) +{ + int ret, maxFd = 0; + + for (int i = 0; i < M6_VENC_CHN_NUM; i++) { + if (!m6_state[i].enable) continue; + if (!m6_state[i].mainLoop) continue; + + ret = m6_venc.fnGetDescriptor(_m6_venc_dev[i], i); + if (ret < 0) { + HAL_DANGER("m6_venc", "Getting the encoder descriptor failed with %#x!\n", ret); + return NULL; + } + m6_state[i].fileDesc = ret; + + if (maxFd <= m6_state[i].fileDesc) + maxFd = m6_state[i].fileDesc; + } + + m6_venc_stat stat; + m6_venc_strm stream; + struct timeval timeout; + fd_set readFds; + + while (keepRunning) { + FD_ZERO(&readFds); + for(int i = 0; i < M6_VENC_CHN_NUM; i++) { + if (!m6_state[i].enable) continue; + if (!m6_state[i].mainLoop) continue; + FD_SET(m6_state[i].fileDesc, &readFds); + } + + timeout.tv_sec = 2; + timeout.tv_usec = 0; + ret = select(maxFd + 1, &readFds, NULL, NULL, &timeout); + if (ret < 0) { + HAL_DANGER("m6_venc", "Select operation failed!\n"); + break; + } else if (ret == 0) { + HAL_WARNING("m6_venc", "Main stream loop timed out!\n"); + continue; + } else { + for (int i = 0; i < M6_VENC_CHN_NUM; i++) { + if (!m6_state[i].enable) continue; + if (!m6_state[i].mainLoop) continue; + if (FD_ISSET(m6_state[i].fileDesc, &readFds)) { + memset(&stream, 0, sizeof(stream)); + + if (ret = m6_venc.fnQuery(_m6_venc_dev[i], i, &stat)) { + HAL_DANGER("m6_venc", "Querying the encoder channel " + "%d failed with %#x!\n", i, ret); + break; + } + + if (!stat.curPacks) { + HAL_WARNING("m6_venc", "Current frame is empty, skipping it!\n"); + continue; + } + + stream.packet = (m6_venc_pack*)malloc( + sizeof(m6_venc_pack) * stat.curPacks); + if (!stream.packet) { + HAL_DANGER("m6_venc", "Memory allocation on channel %d failed!\n", i); + break; + } + stream.count = stat.curPacks; + + if (ret = m6_venc.fnGetStream(_m6_venc_dev[i], i, &stream, 40)) { + HAL_DANGER("m6_venc", "Getting the stream on " + "channel %d failed with %#x!\n", i, ret); + break; + } + + if (m6_vid_cb) { + hal_vidstream outStrm; + hal_vidpack outPack[stream.count]; + outStrm.count = stream.count; + outStrm.seq = stream.sequence; + for (int j = 0; j < stream.count; j++) { + m6_venc_pack *pack = &stream.packet[j]; + outPack[j].data = pack->data; + outPack[j].length = pack->length; + outPack[j].naluCnt = pack->packNum; + switch (m6_state[i].payload) { + case HAL_VIDCODEC_H264: + for (char k = 0; k < outPack[j].naluCnt; k++) { + outPack[j].nalu[k].length = + pack->packetInfo[k].length; + outPack[j].nalu[k].offset = + pack->packetInfo[k].offset; + outPack[j].nalu[k].type = + pack->packetInfo[k].packType.h264Nalu; + } + break; + case HAL_VIDCODEC_H265: + for (char k = 0; k < outPack[j].naluCnt; k++) { + outPack[j].nalu[k].length = + pack->packetInfo[k].length; + outPack[j].nalu[k].offset = + pack->packetInfo[k].offset; + outPack[j].nalu[k].type = + pack->packetInfo[k].packType.h265Nalu; + } + break; + } + outPack[j].offset = pack->offset; + outPack[j].timestamp = pack->timestamp; + } + outStrm.pack = outPack; + (*m6_vid_cb)(i, &outStrm); + } + + if (ret = m6_venc.fnFreeStream(_m6_venc_dev[i], i, &stream)) + HAL_WARNING("m6_venc", "Releasing the stream on " + "channel %d failed with %#x!\n", i, ret); + free(stream.packet); + stream.packet = NULL; + } + } + } + } + + HAL_INFO("m6_venc", "Shutting down encoding thread...\n"); +} + +void m6_system_deinit(void) +{ + m6_sys.fnExit(0); +} + +int m6_system_init(void) +{ + int ret; + + printf("App built with headers v%s\n", M6_SYS_API); + + if (ret = m6_sys.fnInit(0)) + return ret; + { + m6_sys_ver version; + if (ret = m6_sys.fnGetVersion(0, &version)) + return ret; + puts(version.version); + } + + return EXIT_SUCCESS; +} + +#endif \ No newline at end of file diff --git a/src/hal/star/m6_hal.h b/src/hal/star/m6_hal.h new file mode 100644 index 0000000..01187c6 --- /dev/null +++ b/src/hal/star/m6_hal.h @@ -0,0 +1,52 @@ +#include "m6_common.h" +#include "m6_aud.h" +#include "m6_ipu.h" +#include "m6_isp.h" +#include "m6_rgn.h" +#include "m6_scl.h" +#include "m6_snr.h" +#include "m6_sys.h" +#include "m6_venc.h" +#include "m6_vif.h" + +#include +#include + +extern char keepRunning; + +extern hal_chnstate m6_state[M6_VENC_CHN_NUM]; +extern int (*m6_aud_cb)(hal_audframe*); +extern int (*m6_vid_cb)(char, hal_vidstream*); + +void m6_hal_deinit(void); +int m6_hal_init(void); + +void m6_audio_deinit(void); +int m6_audio_init(int samplerate); +void *m6_audio_thread(void); + +int m6_channel_bind(char index, char framerate); +int m6_channel_create(char index, short width, short height, char mirror, char flip, char jpeg); +int m6_channel_grayscale(char enable); +int m6_channel_unbind(char index); + +int m6_config_load(char *path); + +int m6_pipeline_create(char sensor, short width, short height, char framerate); +void m6_pipeline_destroy(void); + +int m6_region_create(char handle, hal_rect rect, short opacity); +void m6_region_deinit(void); +void m6_region_destroy(char handle); +void m6_region_init(void); +int m6_region_setbitmap(int handle, hal_bitmap *bitmap); + +int m6_video_create(char index, hal_vidconfig *config); +int m6_video_destroy(char index); +int m6_video_destroy_all(void); +void m6_video_request_idr(char index); +int m6_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg); +void *m6_video_thread(void); + +void m6_system_deinit(void); +int m6_system_init(void); \ No newline at end of file diff --git a/src/hal/star/m6_ipu.h b/src/hal/star/m6_ipu.h new file mode 100644 index 0000000..fbecfb4 --- /dev/null +++ b/src/hal/star/m6_ipu.h @@ -0,0 +1,134 @@ +#pragma once + +#include "i6_common.h" + +#define M6_IPU_MAXIODEPTH 3 +#define M6_IPU_YUV420WALIGN 16 +#define M6_IPU_YUV420HALIGN 2 +#define M6_IPU_RGBWALIGN 16 + +typedef int (*m6_ipu_rdfn)(void *data, int offset, int size, char *ctx); + +typedef enum { + M6_IPU_FMT_U8, + M6_IPU_FMT_NV12, + M6_IPU_FMT_INT16, + M6_IPU_FMT_INT32, + M6_IPU_FMT_INT8, + M6_IPU_FMT_FP32, + M6_IPU_FMT_UNKNOWN, + M6_IPU_FMT_ARGB8888, + M6_IPU_FMT_ABGR8888 +} m6_ipu_fmt; + +typedef struct { + unsigned int subnet; + unsigned int usrDepth; + unsigned int bufDepth; +} m6_ipu_chn; + +typedef struct { + unsigned int maxDynBufSize; + unsigned int yuv420Walign; + unsigned int yuv420Halign; + unsigned int rgbWalign; +} m6_ipu_dev; + +typedef struct { + unsigned int dimension; + m6_ipu_fmt format; + unsigned int shape[8]; + char name[256]; + unsigned int innerMost; + float scalar; + long long zeroPnt; + int alignedBufSize; +} m6_ipu_tend; + +typedef struct { + unsigned int inCnt; + unsigned int outCnt; + m6_ipu_tend inDesc[61]; + m6_ipu_tend outDesc[61]; +} m6_ipu_tio; + +typedef struct { + void *data[2]; + unsigned long long phyAddr[2]; +} m6_ipu_ten; + +typedef struct { + unsigned int count; + m6_ipu_ten tensor[61]; +} m6_ipu_tenv; + +typedef struct { + void *handle; + + int (*fnCreateDevice)(m6_ipu_dev *config, m6_ipu_rdfn readFunc, char *fwPath, unsigned int fwSize); + int (*fnDestroyDevice)(void); + + int (*fnCreateChannel)(unsigned int *channel, m6_ipu_chn *config, m6_ipu_rdfn readFunc, char *netPath); + int (*fnDestroyChannel)(unsigned int channel); + + int (*fnGetIOTensorDescription)(unsigned int channel, m6_ipu_tio *desc); + int (*fnGetInputTensors)(unsigned int channel, m6_ipu_tenv *ins); + int (*fnGetOutputTensors)(unsigned int channel, m6_ipu_tenv *outs); + int (*fnSetInputTensors)(unsigned int channel, m6_ipu_tenv *ins); + int (*fnSetOutputTensors)(unsigned int channel, m6_ipu_tenv *outs); + + int (*fnInvoke)(unsigned int channel, m6_ipu_tenv *ins, m6_ipu_tenv *outs); +} m6_ipu_impl; + +static int m6_ipu_load(m6_ipu_impl *ipu_lib) { + if (!(ipu_lib->handle = dlopen("libmi_ipu.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("m6_ipu", "Failed to load library!\nError: %s\n", dlerror()); + + if (!(ipu_lib->fnCreateDevice = (int(*)(m6_ipu_dev *config, m6_ipu_rdfn readFunc, char *fwPath, unsigned int fwSize)) + hal_symbol_load("m6_ipu", ipu_lib->handle, "MI_IPU_CreateDevice"))) + return EXIT_FAILURE; + + if (!(ipu_lib->fnDestroyDevice = (int(*)(void)) + hal_symbol_load("m6_ipu", ipu_lib->handle, "MI_IPU_DestroyDevice"))) + return EXIT_FAILURE; + + if (!(ipu_lib->fnCreateChannel = (int(*)(unsigned int *channel, m6_ipu_chn *config, m6_ipu_rdfn readFunc, char *netPath)) + hal_symbol_load("m6_ipu", ipu_lib->handle, "MI_IPU_CreateCHN"))) + return EXIT_FAILURE; + + if (!(ipu_lib->fnDestroyChannel = (int(*)(unsigned int channel)) + hal_symbol_load("m6_ipu", ipu_lib->handle, "MI_IPU_DestroyCHN"))) + return EXIT_FAILURE; + + if (!(ipu_lib->fnGetIOTensorDescription = (int(*)(unsigned int channel, m6_ipu_tio *desc)) + hal_symbol_load("m6_ipu", ipu_lib->handle, "MI_IPU_GetInOutTensorDesc"))) + return EXIT_FAILURE; + + if (!(ipu_lib->fnGetInputTensors = (int(*)(unsigned int channel, m6_ipu_tenv *ins)) + hal_symbol_load("m6_ipu", ipu_lib->handle, "MI_IPU_GetInputTensors"))) + return EXIT_FAILURE; + + if (!(ipu_lib->fnGetOutputTensors = (int(*)(unsigned int channel, m6_ipu_tenv *outs)) + hal_symbol_load("m6_ipu", ipu_lib->handle, "MI_IPU_GetOutputTensors"))) + return EXIT_FAILURE; + + if (!(ipu_lib->fnSetInputTensors = (int(*)(unsigned int channel, m6_ipu_tenv *ins)) + hal_symbol_load("m6_ipu", ipu_lib->handle, "MI_IPU_PutInputTensors"))) + return EXIT_FAILURE; + + if (!(ipu_lib->fnSetOutputTensors = (int(*)(unsigned int channel, m6_ipu_tenv *outs)) + hal_symbol_load("m6_ipu", ipu_lib->handle, "MI_IPU_PutOutputTensors"))) + return EXIT_FAILURE; + + if (!(ipu_lib->fnInvoke = (int(*)(unsigned int channel, m6_ipu_tenv *ins, m6_ipu_tenv *outs)) + hal_symbol_load("m6_ipu", ipu_lib->handle, "MI_IPU_Invoke"))) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + +static void m6_ipu_unload(m6_ipu_impl *ipu_lib) { + if (ipu_lib->handle) dlclose(ipu_lib->handle); + ipu_lib->handle = NULL; + memset(ipu_lib, 0, sizeof(*ipu_lib)); +} \ No newline at end of file diff --git a/src/hal/star/m6_isp.h b/src/hal/star/m6_isp.h new file mode 100644 index 0000000..5bf02c4 --- /dev/null +++ b/src/hal/star/m6_isp.h @@ -0,0 +1,122 @@ +#pragma once + +#include "m6_common.h" + +typedef struct { + unsigned int rev; + unsigned int size; + unsigned char data[64]; +} m6_isp_iqver; + +typedef struct { + unsigned int sensorId; + m6_isp_iqver iqVer; + unsigned int sync3A; +} m6_isp_chn; + +typedef struct { + m6_common_hdr hdr; + // Accepts values from 0-7 + int level3DNR; + char mirror; + char flip; + // Represents 90-degree arcs + int rotate; +} m6_isp_para; + +typedef struct { + m6_common_rect crop; + m6_common_pixfmt pixFmt; +} m6_isp_port; + +typedef struct { + void *handle, *handleCus3a, *handleIspAlgo; + + int (*fnCreateDevice)(int device, unsigned int *combo); + int (*fnDestroyDevice)(int device); + + int (*fnCreateChannel)(int device, int channel, m6_isp_chn *config); + int (*fnDestroyChannel)(int device, int channel); + int (*fnLoadChannelConfig)(int device, int channel, char *path, unsigned int key); + int (*fnSetChannelParam)(int device, int channel, m6_isp_para *config); + int (*fnStartChannel)(int device, int channel); + int (*fnStopChannel)(int device, int channel); + + int (*fnDisablePort)(int device, int channel, int port); + int (*fnEnablePort)(int device, int channel, int port); + int (*fnSetPortConfig)(int device, int channel, int port, m6_isp_port *config); + + int (*fnSetColorToGray)(int device, int channel, char *enable); +} m6_isp_impl; + +static int m6_isp_load(m6_isp_impl *isp_lib) { + if (!(isp_lib->handleIspAlgo = dlopen("libispalgo.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("m6_isp", "Failed to load dependency library!\nError: %s\n", dlerror()); + + + if (!(isp_lib->handleCus3a = dlopen("libcus3a.so", RTLD_LAZY | RTLD_GLOBAL))) + return EXIT_FAILURE; + + if (!(isp_lib->handle = dlopen("libmi_isp.so", RTLD_LAZY | RTLD_GLOBAL))) + return EXIT_FAILURE; + + if (!(isp_lib->fnCreateDevice = (int(*)(int device, unsigned int *combo)) + hal_symbol_load("m6_isp", isp_lib->handle, "MI_ISP_CreateDevice"))) + return EXIT_FAILURE; + + if (!(isp_lib->fnDestroyDevice = (int(*)(int device)) + hal_symbol_load("m6_isp", isp_lib->handle, "MI_ISP_DestoryDevice"))) + return EXIT_FAILURE; + + if (!(isp_lib->fnCreateChannel = (int(*)(int device, int channel, m6_isp_chn *config)) + hal_symbol_load("m6_isp", isp_lib->handle, "MI_ISP_CreateChannel"))) + return EXIT_FAILURE; + + if (!(isp_lib->fnDestroyChannel = (int(*)(int device, int channel)) + hal_symbol_load("m6_isp", isp_lib->handle, "MI_ISP_DestroyChannel"))) + return EXIT_FAILURE; + + if (!(isp_lib->fnLoadChannelConfig = (int(*)(int device, int channel, char *path, unsigned int key)) + hal_symbol_load("m6_isp", isp_lib->handle, "MI_ISP_ALGO_API_CmdLoadBinFile"))) + return EXIT_FAILURE; + + if (!(isp_lib->fnSetChannelParam = (int(*)(int device, int channel, m6_isp_para *config)) + hal_symbol_load("m6_isp", isp_lib->handle, "MI_ISP_SetChnParam"))) + return EXIT_FAILURE; + + if (!(isp_lib->fnStartChannel = (int(*)(int device, int channel)) + hal_symbol_load("m6_isp", isp_lib->handle, "MI_ISP_StartChannel"))) + return EXIT_FAILURE; + + if (!(isp_lib->fnStopChannel = (int(*)(int device, int channel)) + hal_symbol_load("m6_isp", isp_lib->handle, "MI_ISP_StopChannel"))) + return EXIT_FAILURE; + + if (!(isp_lib->fnDisablePort = (int(*)(int device, int channel, int port)) + hal_symbol_load("m6_isp", isp_lib->handle, "MI_ISP_DisableOutputPort"))) + return EXIT_FAILURE; + + if (!(isp_lib->fnEnablePort = (int(*)(int device, int channel, int port)) + hal_symbol_load("m6_isp", isp_lib->handle, "MI_ISP_EnableOutputPort"))) + return EXIT_FAILURE; + + if (!(isp_lib->fnSetPortConfig = (int(*)(int device, int channel, int port, m6_isp_port *config)) + hal_symbol_load("m6_isp", isp_lib->handle, "MI_ISP_SetOutputPortParam"))) + return EXIT_FAILURE; + + if (!(isp_lib->fnSetColorToGray = (int(*)(int device, int channel, char *enable)) + hal_symbol_load("m6_isp", isp_lib->handle, "MI_ISP_IQ_SetColorToGray"))) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + +static void m6_isp_unload(m6_isp_impl *isp_lib) { + if (isp_lib->handle) dlclose(isp_lib->handle); + isp_lib->handle = NULL; + if (isp_lib->handleCus3a) dlclose(isp_lib->handleCus3a); + isp_lib->handleCus3a = NULL; + if (isp_lib->handleIspAlgo) dlclose(isp_lib->handleIspAlgo); + isp_lib->handleIspAlgo = NULL; + memset(isp_lib, 0, sizeof(*isp_lib)); +} \ No newline at end of file diff --git a/src/hal/star/m6_rgn.h b/src/hal/star/m6_rgn.h new file mode 100644 index 0000000..b7c6c44 --- /dev/null +++ b/src/hal/star/m6_rgn.h @@ -0,0 +1,159 @@ +#pragma once + +#include "m6_common.h" +#include "m6_sys.h" + +typedef enum { + M6_RGN_PIXFMT_ARGB1555, + M6_RGN_PIXFMT_ARGB4444, + M6_RGN_PIXFMT_I2, + M6_RGN_PIXFMT_I4, + M6_RGN_PIXFMT_I8, + M6_RGN_PIXFMT_RGB565, + M6_RGN_PIXFMT_ARGB888, + M6_RGN_PIXFMT_END +} m6_rgn_pixfmt; + +typedef enum { + M6_RGN_TYPE_OSD, + M6_RGN_TYPE_COVER, + M6_RGN_TYPE_END +} m6_rgn_type; + +typedef struct { + unsigned int width; + unsigned int height; +} m6_rgn_size; + +typedef struct { + m6_rgn_pixfmt pixFmt; + m6_rgn_size size; + void *data; +} m6_rgn_bmp; + +typedef struct { + m6_rgn_type type; + m6_rgn_pixfmt pixFmt; + m6_rgn_size size; +} m6_rgn_cnf; + +typedef struct { + unsigned int layer; + m6_rgn_size size; + unsigned int color; +} m6_rgn_cov; + +typedef struct { + int invColOn; + int lowThanThresh; + unsigned int lumThresh; + unsigned short divWidth; + unsigned short divHeight; +} m6_rgn_inv; + +typedef struct { + unsigned int layer; + int constAlphaOn; + union { + unsigned char bgFgAlpha[2]; + unsigned char constAlpha[2]; + }; + m6_rgn_inv invert; +} m6_rgn_osd; + +typedef struct { + unsigned int x; + unsigned int y; +} m6_rgn_pnt; + +typedef struct { + int show; + m6_rgn_pnt point; + union { + m6_rgn_cov cover; + m6_rgn_osd osd; + }; +} m6_rgn_chn; + +typedef struct { + unsigned char alpha; + unsigned char red; + unsigned char green; + unsigned char blue; +} m6_rgn_pale; + +typedef struct { + m6_rgn_pale element[256]; +} m6_rgn_pal; + +typedef struct { + void *handle; + + int (*fnDeinit)(unsigned short chip); + int (*fnInit)(unsigned short chip, m6_rgn_pal *palette); + + int (*fnCreateRegion)(unsigned short chip, unsigned int handle, m6_rgn_cnf *config); + int (*fnDestroyRegion)(unsigned short chip, unsigned int handle); + int (*fnGetRegionConfig)(unsigned short chip, unsigned int handle, m6_rgn_cnf *config); + + int (*fnAttachChannel)(unsigned short chip, unsigned int handle, m6_sys_bind *dest, m6_rgn_chn *config); + int (*fnDetachChannel)(unsigned short chip, unsigned int handle, m6_sys_bind *dest); + int (*fnGetChannelConfig)(unsigned short chip, unsigned int handle, m6_sys_bind *dest, m6_rgn_chn *config); + int (*fnSetChannelConfig)(unsigned short chip, unsigned int handle, m6_sys_bind *dest, m6_rgn_chn *config); + + int (*fnSetBitmap)(unsigned short chip, unsigned int handle, m6_rgn_bmp *bitmap); +} m6_rgn_impl; + +static int m6_rgn_load(m6_rgn_impl *rgn_lib) { + if (!(rgn_lib->handle = dlopen("libmi_rgn.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("m6_rgn", "Failed to load library!\nError: %s\n", dlerror()); + + + if (!(rgn_lib->fnDeinit = (int(*)(unsigned short chip)) + hal_symbol_load("m6_rgn", rgn_lib->handle, "MI_RGN_DeInit"))) + return EXIT_FAILURE; + + if (!(rgn_lib->fnInit = (int(*)(unsigned short chip, m6_rgn_pal *palette)) + hal_symbol_load("m6_rgn", rgn_lib->handle, "MI_RGN_Init"))) + return EXIT_FAILURE; + + if (!(rgn_lib->fnCreateRegion = (int(*)(unsigned short chip, unsigned int handle, m6_rgn_cnf *config)) + hal_symbol_load("m6_rgn", rgn_lib->handle, "MI_RGN_Create"))) + return EXIT_FAILURE; + + if (!(rgn_lib->fnGetRegionConfig = (int(*)(unsigned short chip, unsigned int handle, m6_rgn_cnf *config)) + hal_symbol_load("m6_rgn", rgn_lib->handle, "MI_RGN_GetAttr"))) + return EXIT_FAILURE; + + if (!(rgn_lib->fnDestroyRegion = (int(*)(unsigned short chip, unsigned int handle)) + hal_symbol_load("m6_rgn", rgn_lib->handle, "MI_RGN_Destroy"))) + return EXIT_FAILURE; + + if (!(rgn_lib->fnAttachChannel = (int(*)(unsigned short chip, unsigned int handle, m6_sys_bind *dest, m6_rgn_chn *config)) + hal_symbol_load("m6_rgn", rgn_lib->handle, "MI_RGN_AttachToChn"))) + return EXIT_FAILURE; + + if (!(rgn_lib->fnDetachChannel = (int(*)(unsigned short chip, unsigned int handle, m6_sys_bind *dest)) + hal_symbol_load("m6_rgn", rgn_lib->handle, "MI_RGN_DetachFromChn"))) + return EXIT_FAILURE; + + if (!(rgn_lib->fnGetChannelConfig = (int(*)(unsigned short chip, unsigned int handle, m6_sys_bind *dest, m6_rgn_chn *config)) + hal_symbol_load("m6_rgn", rgn_lib->handle, "MI_RGN_GetDisplayAttr"))) + return EXIT_FAILURE; + + if (!(rgn_lib->fnSetChannelConfig = (int(*)(unsigned short chip, unsigned int handle, m6_sys_bind *dest, m6_rgn_chn *config)) + hal_symbol_load("m6_rgn", rgn_lib->handle, "MI_RGN_SetDisplayAttr"))) + return EXIT_FAILURE; + + if (!(rgn_lib->fnSetBitmap = (int(*)(unsigned short chip, unsigned int handle, m6_rgn_bmp *bitmap)) + hal_symbol_load("m6_rgn", rgn_lib->handle, "MI_RGN_SetBitMap"))) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + +static void m6_rgn_unload(m6_rgn_impl *rgn_lib) { + if (rgn_lib->handle) dlclose(rgn_lib->handle); + rgn_lib->handle = NULL; + memset(rgn_lib, 0, sizeof(*rgn_lib)); +} \ No newline at end of file diff --git a/src/hal/star/m6_scl.h b/src/hal/star/m6_scl.h new file mode 100644 index 0000000..1cb2367 --- /dev/null +++ b/src/hal/star/m6_scl.h @@ -0,0 +1,93 @@ +#pragma once + +#include "m6_common.h" + +typedef enum { + M6_SCL_BIND_INVALID, + M6_SCL_BIND_ID0 = 0x1, + M6_SCL_BIND_ID1 = 0x2, + M6_SCL_BIND_ID2 = 0x4, + M6_SCL_BIND_ID3 = 0x8, + M6_SCL_BIND_ID4 = 0x10, + M6_SCL_BIND_ID5 = 0x20, + M6_SCL_BIND_END = 0xffff, +} m6_scl_bind; + +typedef struct { + m6_common_rect crop; + m6_common_dim output; + char mirror; + char flip; + m6_common_pixfmt pixFmt; + m6_common_compr compress; +} m6_scl_port; + +typedef struct { + void *handle; + + int (*fnCreateDevice)(int device, unsigned int *binds); + int (*fnDestroyDevice)(int device); + + int (*fnAdjustChannelRotation)(int device, int channel, int *rotate); + int (*fnCreateChannel)(int device, int channel, unsigned int *reserved); + int (*fnDestroyChannel)(int device, int channel); + int (*fnStartChannel)(int device, int channel); + int (*fnStopChannel)(int device, int channel); + + int (*fnDisablePort)(int device, int channel, int port); + int (*fnEnablePort)(int device, int channel, int port); + int (*fnSetPortConfig)(int device, int channel, int port, m6_scl_port *config); +} m6_scl_impl; + +static int m6_scl_load(m6_scl_impl *scl_lib) { + if (!(scl_lib->handle = dlopen("libmi_scl.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("m6_scl", "Failed to load library!\nError: %s\n", dlerror()); + + if (!(scl_lib->fnCreateDevice = (int(*)(int device, unsigned int *binds)) + hal_symbol_load("m6_scl", scl_lib->handle, "MI_SCL_CreateDevice"))) + return EXIT_FAILURE; + + if (!(scl_lib->fnDestroyDevice = (int(*)(int device)) + hal_symbol_load("m6_scl", scl_lib->handle, "MI_SCL_DestroyDevice"))) + return EXIT_FAILURE; + + if (!(scl_lib->fnAdjustChannelRotation = (int(*)(int device, int channel, int *rotate)) + hal_symbol_load("m6_scl", scl_lib->handle, "MI_SCL_SetChnParam"))) + return EXIT_FAILURE; + + if (!(scl_lib->fnCreateChannel = (int(*)(int device, int channel, unsigned int *reserved)) + hal_symbol_load("m6_scl", scl_lib->handle, "MI_SCL_CreateChannel"))) + return EXIT_FAILURE; + + if (!(scl_lib->fnDestroyChannel = (int(*)(int device, int channel)) + hal_symbol_load("m6_scl", scl_lib->handle, "MI_SCL_DestroyChannel"))) + return EXIT_FAILURE; + + if (!(scl_lib->fnStartChannel = (int(*)(int device, int channel)) + hal_symbol_load("m6_scl", scl_lib->handle, "MI_SCL_StartChannel"))) + return EXIT_FAILURE; + + if (!(scl_lib->fnStopChannel = (int(*)(int device, int channel)) + hal_symbol_load("m6_scl", scl_lib->handle, "MI_SCL_StopChannel"))) + return EXIT_FAILURE; + + if (!(scl_lib->fnDisablePort = (int(*)(int device, int channel, int port)) + hal_symbol_load("m6_scl", scl_lib->handle, "MI_SCL_DisableOutputPort"))) + return EXIT_FAILURE; + + if (!(scl_lib->fnEnablePort = (int(*)(int device, int channel, int port)) + hal_symbol_load("m6_scl", scl_lib->handle, "MI_SCL_EnableOutputPort"))) + return EXIT_FAILURE; + + if (!(scl_lib->fnSetPortConfig = (int(*)(int device, int channel, int port, m6_scl_port *config)) + hal_symbol_load("m6_scl", scl_lib->handle, "MI_SCL_SetOutputPortParam"))) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + +static void m6_scl_unload(m6_scl_impl *scl_lib) { + if (scl_lib->handle) dlclose(scl_lib->handle); + scl_lib->handle = NULL; + memset(scl_lib, 0, sizeof(*scl_lib)); +} \ No newline at end of file diff --git a/src/hal/star/m6_snr.h b/src/hal/star/m6_snr.h new file mode 100644 index 0000000..21ebc07 --- /dev/null +++ b/src/hal/star/m6_snr.h @@ -0,0 +1,152 @@ +#pragma once + +#include "m6_common.h" + +typedef enum { + M6_SNR_HWHDR_NONE, + M6_SNR_HWHDR_SONY_DOL, + M6_SNR_HWHDR_DCG, + M6_SNR_HWHDR_EMBED_RAW8, + M6_SNR_HWHDR_EMBED_RAW10, + M6_SNR_HWHDR_EMBED_RAW12, + M6_SNR_HWHDR_EMBED_RAW14, + M6_SNR_HWHDR_EMBED_RAW16 +} m6_snr_hwhdr; + +typedef struct { + unsigned int laneCnt; + unsigned int rgbFmtOn; + unsigned int hsyncMode; + unsigned int sampDelay; + m6_snr_hwhdr hwHdr; + unsigned int virtChn; + unsigned int packType[2]; +} m6_snr_mipi; + +typedef struct { + int vsyncInv; + int hsyncInv; + int pixclkInv; + unsigned int vsyncDelay; + unsigned int hsyncDelay; + unsigned int pixclkDelay; +} m6_snr_sync; + +typedef struct { + unsigned int multplxNum; + m6_snr_sync sync; + m6_common_edge edge; + char bitswap; +} m6_snr_bt656; + +typedef struct { + m6_snr_sync sync; +} m6_snr_par; + +typedef union { + m6_snr_par parallel; + m6_snr_mipi mipi; + m6_snr_bt656 bt656; +} m6_snr_intfattr; + +typedef struct { + unsigned int planeCnt; + m6_common_intf intf; + m6_common_hdr hdr; + m6_snr_intfattr intfAttr; + char earlyInit; +} m6_snr_pad; + +typedef struct { + unsigned int planeId; + char sensName[32]; + m6_common_rect capt; + m6_common_bayer bayer; + m6_common_prec precision; + int hdrSrc; + // Value in microseconds + unsigned int shutter; + // Value multiplied by 1024 + unsigned int sensGain; + unsigned int compGain; + m6_common_pixfmt pixFmt; +} m6_snr_plane; + +typedef struct { + m6_common_rect crop; + m6_common_dim output; + unsigned int maxFps; + unsigned int minFps; + char desc[32]; +} __attribute__((packed, aligned(4))) m6_snr_res; + +typedef struct { + void *handle; + + int (*fnDisable)(unsigned int sensor); + int (*fnEnable)(unsigned int sensor); + + int (*fnSetFramerate)(unsigned int sensor, unsigned int framerate); + + int (*fnGetPadInfo)(unsigned int sensor, m6_snr_pad *info); + int (*fnGetPlaneInfo)(unsigned int sensor, unsigned int index, m6_snr_plane *info); + int (*fnSetPlaneMode)(unsigned int sensor, unsigned char active); + + int (*fnCurrentResolution)(unsigned int sensor, unsigned char *index, m6_snr_res *resolution); + int (*fnGetResolution)(unsigned int sensor, unsigned char index, m6_snr_res *resolution); + int (*fnGetResolutionCount)(unsigned int sensor, unsigned int *count); + int (*fnSetResolution)(unsigned int sensor, unsigned char index); +} m6_snr_impl; + +static int m6_snr_load(m6_snr_impl *snr_lib) { + if (!(snr_lib->handle = dlopen("libmi_sensor.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("m6_snr", "Failed to load library!\nError: %s\n", dlerror()); + + if (!(snr_lib->fnDisable = (int(*)(unsigned int sensor)) + hal_symbol_load("m6_snr", snr_lib->handle, "MI_SNR_Disable"))) + return EXIT_FAILURE; + + if (!(snr_lib->fnEnable = (int(*)(unsigned int sensor)) + hal_symbol_load("m6_snr", snr_lib->handle, "MI_SNR_Enable"))) + return EXIT_FAILURE; + + if (!(snr_lib->fnSetFramerate = (int(*)(unsigned int sensor, unsigned int framerate)) + hal_symbol_load("m6_snr", snr_lib->handle, "MI_SNR_SetFps"))) + return EXIT_FAILURE; + + if (!(snr_lib->fnGetPadInfo = (int(*)(unsigned int sensor, m6_snr_pad *info)) + hal_symbol_load("m6_snr", snr_lib->handle, "MI_SNR_GetPadInfo"))) + return EXIT_FAILURE; + + if (!(snr_lib->fnGetPlaneInfo = (int(*)(unsigned int sensor, unsigned int index, m6_snr_plane *info)) + hal_symbol_load("m6_snr", snr_lib->handle, "MI_SNR_GetPlaneInfo"))) + return EXIT_FAILURE; + + if (!(snr_lib->fnSetPlaneMode = (int(*)(unsigned int sensor, unsigned char active)) + hal_symbol_load("m6_snr", snr_lib->handle, "MI_SNR_SetPlaneMode"))) + return EXIT_FAILURE; + + if (!(snr_lib->fnCurrentResolution = (int(*)(unsigned int sensor, unsigned char *index, m6_snr_res *resolution)) + hal_symbol_load("m6_snr", snr_lib->handle, "MI_SNR_GetCurRes"))) + return EXIT_FAILURE; + + if (!(snr_lib->fnGetResolution = (int(*)(unsigned int sensor, unsigned char index, m6_snr_res *resolution)) + hal_symbol_load("m6_snr", snr_lib->handle, "MI_SNR_GetRes"))) + return EXIT_FAILURE; + + if (!(snr_lib->fnGetResolutionCount = (int(*)(unsigned int sensor, unsigned int *count)) + hal_symbol_load("m6_snr", snr_lib->handle, "MI_SNR_QueryResCount"))) + return EXIT_FAILURE; + + if (!(snr_lib->fnSetResolution = (int(*)(unsigned int sensor, unsigned char index)) + hal_symbol_load("m6_snr", snr_lib->handle, "MI_SNR_SetRes"))) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + +static void m6_snr_unload(m6_snr_impl *snr_lib) { + if (snr_lib->handle) dlclose(snr_lib->handle); + snr_lib->handle = NULL; + memset(snr_lib, 0, sizeof(*snr_lib)); +} \ No newline at end of file diff --git a/src/hal/star/m6_sys.h b/src/hal/star/m6_sys.h new file mode 100644 index 0000000..3de3e86 --- /dev/null +++ b/src/hal/star/m6_sys.h @@ -0,0 +1,181 @@ +#pragma once + +#include "m6_common.h" + +#define M6_SYS_API "1.0" + +typedef enum { + M6_SYS_LINK_FRAMEBASE = 0x1, + M6_SYS_LINK_LOWLATENCY = 0x2, + M6_SYS_LINK_REALTIME = 0x4, + M6_SYS_LINK_AUTOSYNC = 0x8, + M6_SYS_LINK_RING = 0x10 +} m6_sys_link; + +typedef enum { + M6_SYS_MOD_IVE, + M6_SYS_MOD_VDF, + M6_SYS_MOD_VENC, + M6_SYS_MOD_RGN, + M6_SYS_MOD_AI, + M6_SYS_MOD_AO, + M6_SYS_MOD_VIF, + M6_SYS_MOD_VPE, + M6_SYS_MOD_VDEC, + M6_SYS_MOD_SYS, + M6_SYS_MOD_FB, + M6_SYS_MOD_HDMI, + M6_SYS_MOD_DIVP, + M6_SYS_MOD_GFX, + M6_SYS_MOD_VDISP, + M6_SYS_MOD_DISP, + M6_SYS_MOD_OS, + M6_SYS_MOD_IAE, + M6_SYS_MOD_MD, + M6_SYS_MOD_OD, + M6_SYS_MOD_SHADOW, + M6_SYS_MOD_WARP, + M6_SYS_MOD_UAC, + M6_SYS_MOD_LDC, + M6_SYS_MOD_SD, + M6_SYS_MOD_PANEL, + M6_SYS_MOD_CIPHER, + M6_SYS_MOD_SNR, + M6_SYS_MOD_WLAN, + M6_SYS_MOD_IPU, + M6_SYS_MOD_MIPITX, + M6_SYS_MOD_GYRO, + M6_SYS_MOD_JPD, + M6_SYS_MOD_ISP, + M6_SYS_MOD_SCL, + M6_SYS_MOD_WBC, + M6_SYS_MOD_END, +} m6_sys_mod; + +typedef enum { + M6_SYS_POOL_ENCODER_RING, + M6_SYS_POOL_CHANNEL, + M6_SYS_POOL_DEVICE, + M6_SYS_POOL_OUTPUT +} m6_sys_pooltype; + +typedef struct { + m6_sys_mod module; + unsigned int device; + unsigned int channel; + unsigned int port; +} m6_sys_bind; + +typedef struct { + m6_sys_mod module; + unsigned int device; + unsigned int channel; + unsigned char heapName[32]; + unsigned int heapSize; +} m6_sys_poolchn; + +typedef struct { + m6_sys_mod module; + unsigned int device; + unsigned int reserved; + unsigned char heapName[32]; + unsigned int heapSize; +} m6_sys_pooldev; + +typedef struct { + unsigned int ringSize; + unsigned char heapName[32]; +} m6_sys_poolenc; + +typedef struct { + m6_sys_mod module; + unsigned int device; + unsigned int channel; + unsigned int port; + unsigned char heapName[32]; + unsigned int heapSize; +} m6_sys_poolout; + +typedef struct { + m6_sys_pooltype type; + char create; + union { + m6_sys_poolchn channel; + m6_sys_pooldev device; + m6_sys_poolenc encode; + m6_sys_poolout output; + } config; +} m6_sys_pool; + +typedef struct { + unsigned char version[128]; +} m6_sys_ver; + +typedef struct { + void *handle, *handleCamOsWrapper; + + int (*fnExit)(unsigned short chip); + int (*fnGetVersion)(unsigned short chip, m6_sys_ver *version); + int (*fnInit)(unsigned short chip); + + int (*fnBind)(unsigned short chip, m6_sys_bind *source, m6_sys_bind *dest, m6_sys_link *link); + int (*fnBindExt)(unsigned short chip, m6_sys_bind *source, m6_sys_bind *dest, + unsigned int srcFps, unsigned int dstFps, m6_sys_link link, unsigned int linkParam); + int (*fnSetOutputDepth)(unsigned short chip, m6_sys_bind *bind, unsigned int usrDepth, + unsigned int bufDepth); + int (*fnUnbind)(unsigned short chip, m6_sys_bind *source, m6_sys_bind *dest); + + int (*fnConfigPool)(unsigned short chip, m6_sys_pool *config); +} m6_sys_impl; + +static int m6_sys_load(m6_sys_impl *sys_lib) { + if (!(sys_lib->handleCamOsWrapper = dlopen("libcam_os_wrapper.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("m6_sys", "Failed to load dependency library!\nError: %s\n", dlerror()); + + if (!(sys_lib->handle = dlopen("libmi_sys.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("m6_sys", "Failed to load library!\nError: %s\n", dlerror()); + + if (!(sys_lib->fnExit = (int(*)(unsigned short chip)) + hal_symbol_load("m6_sys", sys_lib->handle, "MI_SYS_Exit"))) + return EXIT_FAILURE; + + if (!(sys_lib->fnGetVersion = (int(*)(unsigned short chip, m6_sys_ver *version)) + hal_symbol_load("m6_venc", sys_lib->handle, "MI_SYS_GetVersion"))) + return EXIT_FAILURE; + + if (!(sys_lib->fnInit = (int(*)(unsigned short chip)) + hal_symbol_load("m6_venc", sys_lib->handle, "MI_SYS_Init"))) + return EXIT_FAILURE; + + if (!(sys_lib->fnBind = (int(*)(unsigned short chip, m6_sys_bind *source, m6_sys_bind *dest, m6_sys_link *link)) + hal_symbol_load("m6_venc", sys_lib->handle, "MI_SYS_BindChnPort"))) + return EXIT_FAILURE; + + if (!(sys_lib->fnBindExt = (int(*)(unsigned short chip, m6_sys_bind *source, m6_sys_bind *dest, + unsigned int srcFps, unsigned int dstFps, m6_sys_link link, unsigned int linkParam)) + hal_symbol_load("m6_venc", sys_lib->handle, "MI_SYS_BindChnPort2"))) + return EXIT_FAILURE; + + if (!(sys_lib->fnSetOutputDepth = (int(*)(unsigned short chip, m6_sys_bind *bind, + unsigned int usrDepth, unsigned int bufDepth)) + hal_symbol_load("m6_venc", sys_lib->handle, "MI_SYS_SetChnOutputPortDepth"))) + return EXIT_FAILURE; + + if (!(sys_lib->fnUnbind = (int(*)(unsigned short chip, m6_sys_bind *source, m6_sys_bind *dest)) + hal_symbol_load("m6_venc", sys_lib->handle, "MI_SYS_UnBindChnPort"))) + return EXIT_FAILURE; + + if (!(sys_lib->fnConfigPool = (int(*)(unsigned short chip, m6_sys_pool *config)) + hal_symbol_load("m6_venc", sys_lib->handle, "MI_SYS_ConfigPrivateMMAPool"))) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + +static void m6_sys_unload(m6_sys_impl *sys_lib) { + if (sys_lib->handle) dlclose(sys_lib->handle); + sys_lib->handle = NULL; + if (sys_lib->handleCamOsWrapper) dlclose(sys_lib->handleCamOsWrapper); + sys_lib->handleCamOsWrapper = NULL; + memset(sys_lib, 0, sizeof(*sys_lib)); +} \ No newline at end of file diff --git a/src/hal/star/m6_venc.h b/src/hal/star/m6_venc.h new file mode 100644 index 0000000..2cd4563 --- /dev/null +++ b/src/hal/star/m6_venc.h @@ -0,0 +1,395 @@ +#pragma once + +#include "m6_common.h" + +#define M6_VENC_CHN_NUM 12 +#define M6_VENC_DEV_H26X_0 0 +#define M6_VENC_DEV_MJPG_0 8 + +typedef enum { + M6_VENC_CODEC_H264 = 2, + M6_VENC_CODEC_H265, + M6_VENC_CODEC_MJPG, + M6_VENC_CODEC_END +} m6_venc_codec; + +typedef enum { + M6_VENC_NALU_H264_PSLICE = 1, + M6_VENC_NALU_H264_ISLICE = 5, + M6_VENC_NALU_H264_SEI, + M6_VENC_NALU_H264_SPS, + M6_VENC_NALU_H264_PPS, + M6_VENC_NALU_H264_IPSLICE, + M6_VENC_NALU_H264_PREFIX = 14, + M6_VENC_NALU_H264_END +} m6_venc_nalu_h264; + +typedef enum { + M6_VENC_NALU_H265_PSLICE = 1, + M6_VENC_NALU_H265_ISLICE = 19, + M6_VENC_NALU_H265_VPS = 32, + M6_VENC_NALU_H265_SPS, + M6_VENC_NALU_H265_PPS, + M6_VENC_NALU_H265_SEI = 39, + M6_VENC_NALU_H265_END +} m6_venc_nalu_h265; + +typedef enum { + M6_VENC_NALU_MJPG_ECS = 5, + M6_VENC_NALU_MJPG_APP, + M6_VENC_NALU_MJPG_VDO, + M6_VENC_NALU_MJPG_PIC, + M6_VENC_NALU_MJPG_END +} m6_venc_nalu_mjpg; + +typedef enum { + M6_VENC_SRC_CONF_NORMAL, + M6_VENC_SRC_CONF_RING_ONE, + M6_VENC_SRC_CONF_RING_HALF, + M6_VENC_SRC_CONF_HW_SYNC, + M6_VENC_SRC_CONF_END +} m6_venc_src_conf; + +typedef enum { + M6_VENC_RATEMODE_H264CBR = 1, + M6_VENC_RATEMODE_H264VBR, + M6_VENC_RATEMODE_H264ABR, + M6_VENC_RATEMODE_H264QP, + M6_VENC_RATEMODE_H264AVBR, + M6_VENC_RATEMODE_MJPGCBR, + M6_VENC_RATEMODE_MJPGQP, + M6_VENC_RATEMODE_H265CBR, + M6_VENC_RATEMODE_H265VBR, + M6_VENC_RATEMODE_H265QP, + M6_VENC_RATEMODE_H265AVBR, + M6_VENC_RATEMODE_END +} m6_venc_ratemode; + +typedef struct { + unsigned int maxWidth; + unsigned int maxHeight; + unsigned int bufSize; + unsigned int profile; + char byFrame; + unsigned int width; + unsigned int height; + unsigned int bFrameNum; + unsigned int refNum; +} m6_venc_attr_h26x; + +typedef struct { + unsigned int maxWidth; + unsigned int maxHeight; + unsigned int bufSize; + char byFrame; + unsigned int width; + unsigned int height; + char dcfThumbs; + unsigned int markPerRow; +} m6_venc_attr_mjpg; + +typedef struct { + m6_venc_codec codec; + union { + m6_venc_attr_h26x h264; + m6_venc_attr_mjpg mjpg; + m6_venc_attr_h26x h265; + }; +} m6_venc_attrib; + +typedef struct { + unsigned int gop; + unsigned int statTime; + unsigned int fpsNum; + unsigned int fpsDen; + unsigned int bitrate; + unsigned int avgLvl; +} m6_venc_rate_h26xcbr; + +typedef struct { + unsigned int gop; + unsigned int statTime; + unsigned int fpsNum; + unsigned int fpsDen; + unsigned int maxBitrate; + unsigned int maxQual; + unsigned int minQual; +} m6_venc_rate_h26xvbr; + +typedef struct { + unsigned int gop; + unsigned int fpsNum; + unsigned int fpsDen; + unsigned int interQual; + unsigned int predQual; +} m6_venc_rate_h26xqp; + +typedef struct { + unsigned int gop; + unsigned int statTime; + unsigned int fpsNum; + unsigned int fpsDen; + unsigned int avgBitrate; + unsigned int maxBitrate; +} m6_venc_rate_h26xabr; + +typedef struct { + unsigned int bitrate; + unsigned int fpsNum; + unsigned int fpsDen; +} m6_venc_rate_mjpgcbr; + +typedef struct { + unsigned int fpsNum; + unsigned int fpsDen; + unsigned int quality; +} m6_venc_rate_mjpgqp; + +typedef struct { + m6_venc_ratemode mode; + union { + m6_venc_rate_h26xcbr h264Cbr; + m6_venc_rate_h26xvbr h264Vbr; + m6_venc_rate_h26xqp h264Qp; + m6_venc_rate_h26xabr h264Abr; + m6_venc_rate_h26xvbr h264Avbr; + m6_venc_rate_mjpgcbr mjpgCbr; + m6_venc_rate_mjpgqp mjpgQp; + m6_venc_rate_h26xcbr h265Cbr; + m6_venc_rate_h26xvbr h265Vbr; + m6_venc_rate_h26xqp h265Qp; + m6_venc_rate_h26xvbr h265Avbr; + }; + void *extend; +} m6_venc_rate; + +typedef struct { + m6_venc_attrib attrib; + m6_venc_rate rate; +} m6_venc_chn; + +typedef struct { + unsigned int maxWidth; + unsigned int maxHeight; +} m6_venc_init; + +typedef struct { + unsigned int quality; + unsigned char qtLuma[64]; + unsigned char qtChroma[64]; + unsigned int mcuPerEcs; +} m6_venc_jpg; + +typedef union { + m6_venc_nalu_h264 h264Nalu; + m6_venc_nalu_mjpg mjpgNalu; + m6_venc_nalu_h265 h265Nalu; +} m6_venc_nalu; + +typedef struct +{ + m6_venc_nalu packType; + unsigned int offset; + unsigned int length; + unsigned int sliceId; +} m6_venc_packinfo; + +typedef struct { + unsigned long long addr; + unsigned char *data; + unsigned int length; + unsigned long long timestamp; + char endFrame; + m6_venc_nalu naluType; + unsigned int offset; + unsigned int packNum; + unsigned char frameQual; + int picOrder; + unsigned int gradient; + m6_venc_packinfo packetInfo[8]; +} m6_venc_pack; + +typedef struct { + unsigned int leftPics; + unsigned int leftBytes; + unsigned int leftFrames; + unsigned int leftMillis; + unsigned int curPacks; + unsigned int leftRecvPics; + unsigned int leftEncPics; + unsigned int fpsNum; + unsigned int fpsDen; + unsigned int bitrate; +} m6_venc_stat; + +typedef struct { + unsigned int size; + unsigned int skipMb; + unsigned int ipcmMb; + unsigned int iMb16x8; + unsigned int iMb16x16; + unsigned int iMb8x16; + unsigned int iMb8x8; + unsigned int pMb16; + unsigned int pMb8; + unsigned int pMb4; + unsigned int refSliceType; + unsigned int refType; + unsigned int updAttrCnt; + unsigned int startQual; +} m6_venc_strminfo_h264; + +typedef struct { + unsigned int size; + unsigned int iCu64x64; + unsigned int iCu32x32; + unsigned int iCu16x16; + unsigned int iCu8x8; + unsigned int pCu32x32; + unsigned int pCu16x16; + unsigned int pCu8x8; + unsigned int pCu4x4; + unsigned int refType; + unsigned int updAttrCnt; + unsigned int startQual; +} m6_venc_strminfo_h265; + +typedef struct +{ + unsigned int size; + unsigned int updAttrCnt; + unsigned int quality; +} m6_venc_strminfo_mjpg; + +typedef struct { + m6_venc_pack *packet; + unsigned int count; + unsigned int sequence; + unsigned long handle; + union + { + m6_venc_strminfo_h264 h264Info; + m6_venc_strminfo_mjpg mjpgInfo; + m6_venc_strminfo_h265 h265Info; + }; +} m6_venc_strm; + +typedef struct { + void *handle; + + int (*fnCreateDevice)(unsigned int device, m6_venc_init *config); + int (*fnDestroyDevice)(unsigned int device); + + int (*fnCreateChannel)(unsigned int device, unsigned int channel, m6_venc_chn *config); + int (*fnDestroyChannel)(unsigned int device, unsigned int channel); + int (*fnGetChannelConfig)(unsigned int device, unsigned int channel, m6_venc_chn *config); + int (*fnResetChannel)(unsigned int device, unsigned int channel); + int (*fnSetChannelConfig)(unsigned int device, unsigned int channel, m6_venc_chn *config); + + int (*fnFreeDescriptor)(unsigned int device, unsigned int channel); + int (*fnGetDescriptor)(unsigned int device, unsigned int channel); + + int (*fnGetJpegParam)(unsigned int device, unsigned int channel, m6_venc_jpg *param); + int (*fnSetJpegParam)(unsigned int device, unsigned int channel, m6_venc_jpg *param); + + int (*fnFreeStream)(unsigned int device, unsigned int channel, m6_venc_strm *stream); + int (*fnGetStream)(unsigned int device, unsigned int channel, m6_venc_strm *stream, unsigned int timeout); + + int (*fnQuery)(unsigned int device, unsigned int channel, m6_venc_stat* stats); + + int (*fnSetSourceConfig)(unsigned int device, unsigned int channel, m6_venc_src_conf *config); + + int (*fnRequestIdr)(unsigned int device, unsigned int channel, char instant); + int (*fnStartReceiving)(unsigned int device, unsigned int channel); + int (*fnStartReceivingEx)(unsigned int device, unsigned int channel, int *count); + int (*fnStopReceiving)(unsigned int device, unsigned int channel); +} m6_venc_impl; + +static int m6_venc_load(m6_venc_impl *venc_lib) { + if (!(venc_lib->handle = dlopen("libmi_venc.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("m6_venc", "Failed to load library!\nError: %s\n", dlerror()); + + if (!(venc_lib->fnCreateDevice = (int(*)(unsigned int device, m6_venc_init *config)) + hal_symbol_load("m6_venc", venc_lib->handle, "MI_VENC_CreateDev"))) + return EXIT_FAILURE; + + if (!(venc_lib->fnDestroyDevice = (int(*)(unsigned int device)) + hal_symbol_load("m6_venc", venc_lib->handle, "MI_VENC_DestroyDev"))) + return EXIT_FAILURE; + + if (!(venc_lib->fnCreateChannel = (int(*)(unsigned int device, unsigned int channel, m6_venc_chn *config)) + hal_symbol_load("m6_venc", venc_lib->handle, "MI_VENC_CreateChn"))) + return EXIT_FAILURE; + + if (!(venc_lib->fnDestroyChannel = (int(*)(unsigned int device, unsigned int channel)) + hal_symbol_load("m6_venc", venc_lib->handle, "MI_VENC_DestroyChn"))) + return EXIT_FAILURE; + + if (!(venc_lib->fnGetChannelConfig = (int(*)(unsigned int device, unsigned int channel, m6_venc_chn *config)) + hal_symbol_load("m6_venc", venc_lib->handle, "MI_VENC_GetChnAttr"))) + return EXIT_FAILURE; + + if (!(venc_lib->fnResetChannel = (int(*)(unsigned int device, unsigned int channel)) + hal_symbol_load("m6_venc", venc_lib->handle, "MI_VENC_ResetChn"))) + return EXIT_FAILURE; + + if (!(venc_lib->fnSetChannelConfig = (int(*)(unsigned int device, unsigned int channel, m6_venc_chn *config)) + hal_symbol_load("m6_venc", venc_lib->handle, "MI_VENC_SetChnAttr"))) + return EXIT_FAILURE; + + if (!(venc_lib->fnFreeDescriptor = (int(*)(unsigned int device, unsigned int channel)) + hal_symbol_load("m6_venc", venc_lib->handle, "MI_VENC_CloseFd"))) + return EXIT_FAILURE; + + if (!(venc_lib->fnGetDescriptor = (int(*)(unsigned int device, unsigned int channel)) + hal_symbol_load("m6_venc", venc_lib->handle, "MI_VENC_GetFd"))) + return EXIT_FAILURE; + + if (!(venc_lib->fnGetJpegParam = (int(*)(unsigned int device, unsigned int channel, m6_venc_jpg *param)) + hal_symbol_load("m6_venc", venc_lib->handle, "MI_VENC_GetJpegParam"))) + return EXIT_FAILURE; + + if (!(venc_lib->fnSetJpegParam = (int(*)(unsigned int device, unsigned int channel, m6_venc_jpg *param)) + hal_symbol_load("m6_venc", venc_lib->handle, "MI_VENC_SetJpegParam"))) + return EXIT_FAILURE; + + if (!(venc_lib->fnFreeStream = (int(*)(unsigned int device, unsigned int channel, m6_venc_strm *stream)) + hal_symbol_load("m6_venc", venc_lib->handle, "MI_VENC_ReleaseStream"))) + return EXIT_FAILURE; + + if (!(venc_lib->fnGetStream = (int(*)(unsigned int device, unsigned int channel, m6_venc_strm *stream, unsigned int timeout)) + hal_symbol_load("m6_venc", venc_lib->handle, "MI_VENC_GetStream"))) + return EXIT_FAILURE; + + if (!(venc_lib->fnQuery = (int(*)(unsigned int device, unsigned int channel, m6_venc_stat *stats)) + hal_symbol_load("m6_venc", venc_lib->handle, "MI_VENC_Query"))) + return EXIT_FAILURE; + + if (!(venc_lib->fnSetSourceConfig = (int(*)(unsigned int device, unsigned int channel, m6_venc_src_conf *config)) + hal_symbol_load("m6_venc", venc_lib->handle, "MI_VENC_SetInputSourceConfig"))) + return EXIT_FAILURE; + + if (!(venc_lib->fnRequestIdr = (int(*)(unsigned int device, unsigned int channel, char instant)) + hal_symbol_load("m6_venc", venc_lib->handle, "MI_VENC_RequestIdr"))) + return EXIT_FAILURE; + + if (!(venc_lib->fnStartReceiving = (int(*)(unsigned int device, unsigned int channel)) + hal_symbol_load("m6_venc", venc_lib->handle, "MI_VENC_StartRecvPic"))) + return EXIT_FAILURE; + + if (!(venc_lib->fnStartReceivingEx = (int(*)(unsigned int device, unsigned int channel, int *count)) + hal_symbol_load("m6_venc", venc_lib->handle, "MI_VENC_StartRecvPicEx"))) + return EXIT_FAILURE; + + if (!(venc_lib->fnStopReceiving = (int(*)(unsigned int device, unsigned int channel)) + hal_symbol_load("m6_venc", venc_lib->handle, "MI_VENC_StopRecvPic"))) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + +static void m6_venc_unload(m6_venc_impl *venc_lib) { + if (venc_lib->handle) dlclose(venc_lib->handle); + venc_lib->handle = NULL; + memset(venc_lib, 0, sizeof(*venc_lib)); +} \ No newline at end of file diff --git a/src/hal/star/m6_vif.h b/src/hal/star/m6_vif.h new file mode 100644 index 0000000..425b31c --- /dev/null +++ b/src/hal/star/m6_vif.h @@ -0,0 +1,114 @@ +#pragma once + +#include "m6_common.h" + +typedef enum { + M6_VIF_FRATE_FULL, + M6_VIF_FRATE_HALF, + M6_VIF_FRATE_QUART, + M6_VIF_FRATE_OCTANT, + M6_VIF_FRATE_3QUARTS, + M6_VIF_FRATE_END +} m6_vif_frate; + +typedef enum { + M6_VIF_CLK_12MHZ, + M6_VIF_CLK_18MHZ, + M6_VIF_CLK_27MHZ, + M6_VIF_CLK_36MHZ, + M6_VIF_CLK_54MHZ, + M6_VIF_CLK_108MHZ, + M6_VIF_CLK_END +} m6_vif_clk; + +typedef enum { + M6_VIF_WORK_1MULTIPLEX, + M6_VIF_WORK_2MULTIPLEX, + M6_VIF_WORK_4MULTIPLEX, + M6_VIF_WORK_END +} m6_vif_work; + +typedef struct { + m6_common_pixfmt pixFmt; + m6_common_rect crop; + // Values 0-3 correspond to No, Top, Bottom, Both + int field; + char halfHScan; +} m6_vif_dev; + +typedef struct { + m6_common_intf intf; + m6_vif_work work; + m6_common_hdr hdr; + m6_common_edge edge; + m6_vif_clk clock; + int interlaceOn; + unsigned int grpStitch; +} m6_vif_grp; + +typedef struct { + m6_common_rect capt; + m6_common_dim dest; + m6_common_pixfmt pixFmt; + m6_vif_frate frate; +} m6_vif_port; + +typedef struct { + void *handle; + + int (*fnDisableDevice)(int device); + int (*fnEnableDevice)(int device); + int (*fnSetDeviceConfig)(int device, m6_vif_dev *config); + + int (*fnCreateGroup)(int group, m6_vif_grp *config); + int (*fnDestroyGroup)(int group); + + int (*fnDisablePort)(int device, int port); + int (*fnEnablePort)(int device, int port); + int (*fnSetPortConfig)(int device, int port, m6_vif_port *config); +} m6_vif_impl; + +static int m6_vif_load(m6_vif_impl *vif_lib) { + if (!(vif_lib->handle = dlopen("libmi_vif.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("m6_vif", "Failed to load library!\nError: %s\n", dlerror()); + + if (!(vif_lib->fnDisableDevice = (int(*)(int device)) + hal_symbol_load("m6_vif", vif_lib->handle, "MI_VIF_DisableDev"))) + return EXIT_FAILURE; + + if (!(vif_lib->fnEnableDevice = (int(*)(int device)) + hal_symbol_load("m6_vif", vif_lib->handle, "MI_VIF_EnableDev"))) + return EXIT_FAILURE; + + if (!(vif_lib->fnSetDeviceConfig = (int(*)(int device, m6_vif_dev *config)) + hal_symbol_load("m6_vif", vif_lib->handle, "MI_VIF_SetDevAttr"))) + return EXIT_FAILURE; + + if (!(vif_lib->fnCreateGroup = (int(*)(int group, m6_vif_grp *config)) + hal_symbol_load("m6_vif", vif_lib->handle, "MI_VIF_CreateDevGroup"))) + return EXIT_FAILURE; + + if (!(vif_lib->fnDestroyGroup = (int(*)(int group)) + hal_symbol_load("m6_vif", vif_lib->handle, "MI_VIF_DestroyDevGroup"))) + return EXIT_FAILURE; + + if (!(vif_lib->fnDisablePort = (int(*)(int device, int port)) + hal_symbol_load("m6_vif", vif_lib->handle, "MI_VIF_DisableOutputPort"))) + return EXIT_FAILURE; + + if (!(vif_lib->fnEnablePort = (int(*)(int device, int port)) + hal_symbol_load("m6_vif", vif_lib->handle, "MI_VIF_EnableOutputPort"))) + return EXIT_FAILURE; + + if (!(vif_lib->fnSetPortConfig = (int(*)(int device, int port, m6_vif_port *config)) + hal_symbol_load("m6_vif", vif_lib->handle, "MI_VIF_SetOutputPortAttr"))) + return EXIT_FAILURE; + + return EXIT_SUCCESS; +} + +static void m6_vif_unload(m6_vif_impl *vif_lib) { + if (vif_lib->handle) dlclose(vif_lib->handle); + vif_lib->handle = NULL; + memset(vif_lib, 0, sizeof(*vif_lib)); +} \ No newline at end of file diff --git a/src/hal/support.c b/src/hal/support.c index 8123c41..6beb92c 100644 --- a/src/hal/support.c +++ b/src/hal/support.c @@ -99,13 +99,13 @@ void hal_identify(void) { vid_thread = i6c_video_thread; break; case 0xFB: - plat = HAL_PLATFORM_I6F; + plat = HAL_PLATFORM_M6; strcpy(chip, "SSC379G"); - strcpy(family, "infinity6f"); - chnCount = I6F_VENC_CHN_NUM; - chnState = (hal_chnstate*)i6f_state; - aud_thread = i6f_audio_thread; - vid_thread = i6f_video_thread; + strcpy(family, "mercury6"); + chnCount = M6_VENC_CHN_NUM; + chnState = (hal_chnstate*)m6_state; + aud_thread = m6_audio_thread; + vid_thread = m6_video_thread; break; default: plat = HAL_PLATFORM_UNK; diff --git a/src/hal/support.h b/src/hal/support.h index 413a087..4faa979 100644 --- a/src/hal/support.h +++ b/src/hal/support.h @@ -11,7 +11,7 @@ #include "star/i3_hal.h" #include "star/i6_hal.h" #include "star/i6c_hal.h" -#include "star/i6f_hal.h" +#include "star/m6_hal.h" #elif defined(__mips__) #include "inge/t31_hal.h" #elif defined(__riscv) || defined(__riscv__) diff --git a/src/hal/types.h b/src/hal/types.h index 6b35579..8bfb4b4 100644 --- a/src/hal/types.h +++ b/src/hal/types.h @@ -26,7 +26,7 @@ typedef enum { HAL_PLATFORM_I3, HAL_PLATFORM_I6, HAL_PLATFORM_I6C, - HAL_PLATFORM_I6F, + HAL_PLATFORM_M6, HAL_PLATFORM_T31, HAL_PLATFORM_V1, HAL_PLATFORM_V2, diff --git a/src/jpeg.c b/src/jpeg.c index 5684313..3b0f2e7 100644 --- a/src/jpeg.c +++ b/src/jpeg.c @@ -40,7 +40,7 @@ int jpeg_init() { #if defined(__arm__) case HAL_PLATFORM_I6: ret = i6_video_create(jpeg_index, &config); break; case HAL_PLATFORM_I6C: ret = i6c_video_create(jpeg_index, &config); break; - case HAL_PLATFORM_I6F: ret = i6f_video_create(jpeg_index, &config); break; + case HAL_PLATFORM_M6: ret = m6_video_create(jpeg_index, &config); break; case HAL_PLATFORM_V1: ret = v1_video_create(jpeg_index, &config); break; case HAL_PLATFORM_V2: ret = v2_video_create(jpeg_index, &config); break; case HAL_PLATFORM_V3: ret = v3_video_create(jpeg_index, &config); break; @@ -76,7 +76,7 @@ void jpeg_deinit() { case HAL_PLATFORM_GM: goto active; case HAL_PLATFORM_I6: i6_video_destroy(jpeg_index); break; case HAL_PLATFORM_I6C: i6c_video_destroy(jpeg_index); break; - case HAL_PLATFORM_I6F: i6f_video_destroy(jpeg_index); break; + case HAL_PLATFORM_M6: m6_video_destroy(jpeg_index); break; case HAL_PLATFORM_V1: v1_video_destroy(jpeg_index); break; case HAL_PLATFORM_V2: v2_video_destroy(jpeg_index); break; case HAL_PLATFORM_V3: v3_video_destroy(jpeg_index); break; @@ -112,7 +112,7 @@ int jpeg_get(short width, short height, char quality, char grayscale, case HAL_PLATFORM_GM: ret = gm_video_snapshot_grab(width, height, quality, jpeg); break; case HAL_PLATFORM_I6: ret = i6_video_snapshot_grab(jpeg_index, quality, jpeg); break; case HAL_PLATFORM_I6C: ret = i6c_video_snapshot_grab(jpeg_index, quality, jpeg); break; - case HAL_PLATFORM_I6F: ret = i6f_video_snapshot_grab(jpeg_index, quality, jpeg); break; + case HAL_PLATFORM_M6: ret = m6_video_snapshot_grab(jpeg_index, quality, jpeg); break; case HAL_PLATFORM_V1: ret = v1_video_snapshot_grab(jpeg_index, jpeg); break; case HAL_PLATFORM_V2: ret = v2_video_snapshot_grab(jpeg_index, jpeg); break; case HAL_PLATFORM_V3: ret = v3_video_snapshot_grab(jpeg_index, jpeg); break; diff --git a/src/media.c b/src/media.c index 110c9e8..27ccf74 100644 --- a/src/media.c +++ b/src/media.c @@ -155,7 +155,7 @@ void request_idr(void) { case HAL_PLATFORM_GM: gm_video_request_idr(index); break; case HAL_PLATFORM_I6: i6_video_request_idr(index); break; case HAL_PLATFORM_I6C: i6c_video_request_idr(index); break; - case HAL_PLATFORM_I6F: i6f_video_request_idr(index); break; + case HAL_PLATFORM_M6: m6_video_request_idr(index); break; case HAL_PLATFORM_V1: v1_video_request_idr(index); break; case HAL_PLATFORM_V2: v2_video_request_idr(index); break; case HAL_PLATFORM_V3: v3_video_request_idr(index); break; @@ -176,7 +176,7 @@ void set_grayscale(bool active) { case HAL_PLATFORM_AK: ak_channel_grayscale(active); break; case HAL_PLATFORM_I6: i6_channel_grayscale(active); break; case HAL_PLATFORM_I6C: i6c_channel_grayscale(active); break; - case HAL_PLATFORM_I6F: i6f_channel_grayscale(active); break; + case HAL_PLATFORM_M6: m6_channel_grayscale(active); break; case HAL_PLATFORM_V1: v1_channel_grayscale(active); break; case HAL_PLATFORM_V2: v2_channel_grayscale(active); break; case HAL_PLATFORM_V3: v3_channel_grayscale(active); break; @@ -213,7 +213,7 @@ int create_channel(char index, short width, short height, char framerate, char j app_config.mirror, app_config.flip, jpeg); case HAL_PLATFORM_I6C: return i6c_channel_create(index, width, height, app_config.mirror, app_config.flip, jpeg); - case HAL_PLATFORM_I6F: return i6f_channel_create(index, width, height, + case HAL_PLATFORM_M6: return m6_channel_create(index, width, height, app_config.mirror, app_config.flip, jpeg); case HAL_PLATFORM_V1: return v1_channel_create(index, width, height, app_config.mirror, app_config.flip, framerate); @@ -240,7 +240,7 @@ int bind_channel(char index, char framerate, char jpeg) { case HAL_PLATFORM_GM: return gm_channel_bind(index); case HAL_PLATFORM_I6: return i6_channel_bind(index, framerate); case HAL_PLATFORM_I6C: return i6c_channel_bind(index, framerate); - case HAL_PLATFORM_I6F: return i6f_channel_bind(index, framerate); + case HAL_PLATFORM_M6: return m6_channel_bind(index, framerate); case HAL_PLATFORM_V1: return v1_channel_bind(index); case HAL_PLATFORM_V2: return v2_channel_bind(index); case HAL_PLATFORM_V3: return v3_channel_bind(index); @@ -260,7 +260,7 @@ int unbind_channel(char index, char jpeg) { case HAL_PLATFORM_GM: return gm_channel_unbind(index); case HAL_PLATFORM_I6: return i6_channel_unbind(index); case HAL_PLATFORM_I6C: return i6c_channel_unbind(index); - case HAL_PLATFORM_I6F: return i6f_channel_unbind(index); + case HAL_PLATFORM_M6: return m6_channel_unbind(index); case HAL_PLATFORM_V1: return v1_channel_unbind(index); case HAL_PLATFORM_V2: return v2_channel_unbind(index); case HAL_PLATFORM_V3: return v3_channel_unbind(index); @@ -280,7 +280,7 @@ int disable_video(char index, char jpeg) { case HAL_PLATFORM_GM: return gm_video_destroy(index); case HAL_PLATFORM_I6: return i6_video_destroy(index); case HAL_PLATFORM_I6C: return i6c_video_destroy(index); - case HAL_PLATFORM_I6F: return i6f_video_destroy(index); + case HAL_PLATFORM_M6: return m6_video_destroy(index); case HAL_PLATFORM_V1: return v1_video_destroy(index); case HAL_PLATFORM_V2: return v2_video_destroy(index); case HAL_PLATFORM_V3: return v3_video_destroy(index); @@ -304,7 +304,7 @@ void disable_audio(void) { case HAL_PLATFORM_GM: gm_audio_deinit(); break; case HAL_PLATFORM_I6: i6_audio_deinit(); break; case HAL_PLATFORM_I6C: i6c_audio_deinit(); break; - case HAL_PLATFORM_I6F: i6f_audio_deinit(); break; + case HAL_PLATFORM_M6: m6_audio_deinit(); break; case HAL_PLATFORM_V1: v1_audio_deinit(); break; case HAL_PLATFORM_V2: v2_audio_deinit(); break; case HAL_PLATFORM_V3: v3_audio_deinit(); break; @@ -325,7 +325,7 @@ int enable_audio(void) { case HAL_PLATFORM_GM: ret = gm_audio_init(app_config.audio_srate); break; case HAL_PLATFORM_I6: ret = i6_audio_init(app_config.audio_srate); break; case HAL_PLATFORM_I6C: ret = i6c_audio_init(app_config.audio_srate); break; - case HAL_PLATFORM_I6F: ret = i6f_audio_init(app_config.audio_srate); break; + case HAL_PLATFORM_M6: ret = m6_audio_init(app_config.audio_srate); break; case HAL_PLATFORM_V1: ret = v1_audio_init(app_config.audio_srate); break; case HAL_PLATFORM_V2: ret = v2_audio_init(app_config.audio_srate); break; case HAL_PLATFORM_V3: ret = v3_audio_init(app_config.audio_srate); break; @@ -437,7 +437,7 @@ int enable_mjpeg(void) { case HAL_PLATFORM_GM: ret = gm_video_create(index, &config); break; case HAL_PLATFORM_I6: ret = i6_video_create(index, &config); break; case HAL_PLATFORM_I6C: ret = i6c_video_create(index, &config); break; - case HAL_PLATFORM_I6F: ret = i6f_video_create(index, &config); break; + case HAL_PLATFORM_M6: ret = m6_video_create(index, &config); break; case HAL_PLATFORM_V1: ret = v1_video_create(index, &config); break; case HAL_PLATFORM_V2: ret = v2_video_create(index, &config); break; case HAL_PLATFORM_V3: ret = v3_video_create(index, &config); break; @@ -510,7 +510,7 @@ int enable_mp4(void) { case HAL_PLATFORM_GM: ret = gm_video_create(index, &config); break; case HAL_PLATFORM_I6: ret = i6_video_create(index, &config); break; case HAL_PLATFORM_I6C: ret = i6c_video_create(index, &config); break; - case HAL_PLATFORM_I6F: ret = i6f_video_create(index, &config); break; + case HAL_PLATFORM_M6: ret = m6_video_create(index, &config); break; case HAL_PLATFORM_V1: ret = v1_video_create(index, &config); break; case HAL_PLATFORM_V2: ret = v2_video_create(index, &config); break; case HAL_PLATFORM_V3: ret = v3_video_create(index, &config); break; @@ -548,7 +548,7 @@ int start_sdk(void) { case HAL_PLATFORM_I3: ret = i3_hal_init(); break; case HAL_PLATFORM_I6: ret = i6_hal_init(); break; case HAL_PLATFORM_I6C: ret = i6c_hal_init(); break; - case HAL_PLATFORM_I6F: ret = i6f_hal_init(); break; + case HAL_PLATFORM_M6: ret = m6_hal_init(); break; case HAL_PLATFORM_V1: ret = v1_hal_init(); break; case HAL_PLATFORM_V2: ret = v2_hal_init(); break; case HAL_PLATFORM_V3: ret = v3_hal_init(); break; @@ -577,9 +577,9 @@ int start_sdk(void) { i6c_aud_cb = save_audio_stream; i6c_vid_cb = save_video_stream; break; - case HAL_PLATFORM_I6F: - i6f_aud_cb = save_audio_stream; - i6f_vid_cb = save_video_stream; + case HAL_PLATFORM_M6: + m6_aud_cb = save_audio_stream; + m6_vid_cb = save_video_stream; break; case HAL_PLATFORM_V1: v1_aud_cb = save_audio_stream; @@ -617,7 +617,7 @@ int start_sdk(void) { case HAL_PLATFORM_I3: ret = i3_system_init(); break; case HAL_PLATFORM_I6: ret = i6_system_init(); break; case HAL_PLATFORM_I6C: ret = i6c_system_init(); break; - case HAL_PLATFORM_I6F: ret = i6f_system_init(); break; + case HAL_PLATFORM_M6: ret = m6_system_init(); break; case HAL_PLATFORM_V1: ret = v1_system_init(app_config.sensor_config); break; case HAL_PLATFORM_V2: ret = v2_system_init(app_config.sensor_config); break; case HAL_PLATFORM_V3: ret = v3_system_init(app_config.sensor_config); break; @@ -653,7 +653,7 @@ int start_sdk(void) { height, framerate); break; case HAL_PLATFORM_I6C: ret = i6c_pipeline_create(0, width, height, framerate); break; - case HAL_PLATFORM_I6F: ret = i6f_pipeline_create(0, width, + case HAL_PLATFORM_M6: ret = m6_pipeline_create(0, width, height, framerate); break; case HAL_PLATFORM_V1: ret = v1_pipeline_create(); break; case HAL_PLATFORM_V2: ret = v2_pipeline_create(); break; @@ -727,7 +727,7 @@ int start_sdk(void) { case HAL_PLATFORM_I3: i3_config_load(app_config.sensor_config); break; case HAL_PLATFORM_I6: i6_config_load(app_config.sensor_config); break; case HAL_PLATFORM_I6C: i6c_config_load(app_config.sensor_config); break; - case HAL_PLATFORM_I6F: i6f_config_load(app_config.sensor_config); break; + case HAL_PLATFORM_M6: m6_config_load(app_config.sensor_config); break; #elif defined(__mips__) case HAL_PLATFORM_T31: t31_config_load(app_config.sensor_config); break; #endif @@ -750,7 +750,7 @@ int stop_sdk(void) { case HAL_PLATFORM_GM: gm_video_destroy_all(); break; case HAL_PLATFORM_I6: i6_video_destroy_all(); break; case HAL_PLATFORM_I6C: i6c_video_destroy_all(); break; - case HAL_PLATFORM_I6F: i6f_video_destroy_all(); break; + case HAL_PLATFORM_M6: m6_video_destroy_all(); break; case HAL_PLATFORM_V1: v1_video_destroy_all(); break; case HAL_PLATFORM_V2: v2_video_destroy_all(); break; case HAL_PLATFORM_V3: v3_video_destroy_all(); break; @@ -768,7 +768,7 @@ int stop_sdk(void) { case HAL_PLATFORM_GM: gm_pipeline_destroy(); break; case HAL_PLATFORM_I6: i6_pipeline_destroy(); break; case HAL_PLATFORM_I6C: i6c_pipeline_destroy(); break; - case HAL_PLATFORM_I6F: i6f_pipeline_destroy(); break; + case HAL_PLATFORM_M6: m6_pipeline_destroy(); break; case HAL_PLATFORM_V1: v1_pipeline_destroy(); break; case HAL_PLATFORM_V2: v2_pipeline_destroy(); break; case HAL_PLATFORM_V3: v3_pipeline_destroy(); break; @@ -793,7 +793,7 @@ int stop_sdk(void) { case HAL_PLATFORM_I3: i3_system_deinit(); break; case HAL_PLATFORM_I6: i6_system_deinit(); break; case HAL_PLATFORM_I6C: i6c_system_deinit(); break; - case HAL_PLATFORM_I6F: i6f_system_deinit(); break; + case HAL_PLATFORM_M6: m6_system_deinit(); break; case HAL_PLATFORM_V1: v1_system_deinit(); break; case HAL_PLATFORM_V2: v2_system_deinit(); break; case HAL_PLATFORM_V3: v3_system_deinit(); break; @@ -821,7 +821,7 @@ int stop_sdk(void) { case HAL_PLATFORM_I3: i3_hal_deinit(); break; case HAL_PLATFORM_I6: i6_hal_deinit(); break; case HAL_PLATFORM_I6C: i6c_hal_deinit(); break; - case HAL_PLATFORM_I6F: i6f_hal_deinit(); break; + case HAL_PLATFORM_M6: m6_hal_deinit(); break; case HAL_PLATFORM_V1: v1_hal_deinit(); break; case HAL_PLATFORM_V2: v2_hal_deinit(); break; case HAL_PLATFORM_V3: v3_hal_deinit(); break; diff --git a/src/region.c b/src/region.c index daae985..e6bde69 100644 --- a/src/region.c +++ b/src/region.c @@ -83,7 +83,7 @@ void region_fill_formatted(char* str) #if defined(__arm__) case HAL_PLATFORM_I6: case HAL_PLATFORM_I6C: - case HAL_PLATFORM_I6F: + case HAL_PLATFORM_M6: FILE* file; char line[20] = {0}; if (file = fopen("/sys/class/mstar/msys/TEMP_R", "r")) { @@ -244,7 +244,7 @@ void *region_thread(void) #if defined(__arm__) case HAL_PLATFORM_I6: i6_region_init(); break; case HAL_PLATFORM_I6C: i6c_region_init(); break; - case HAL_PLATFORM_I6F: i6f_region_init(); break; + case HAL_PLATFORM_M6: m6_region_init(); break; #endif } @@ -294,9 +294,9 @@ void *region_thread(void) i6c_region_create(id, rect, osds[id].opal); i6c_region_setbitmap(id, &bitmap); break; - case HAL_PLATFORM_I6F: - i6f_region_create(id, rect, osds[id].opal); - i6f_region_setbitmap(id, &bitmap); + case HAL_PLATFORM_M6: + m6_region_create(id, rect, osds[id].opal); + m6_region_setbitmap(id, &bitmap); break; case HAL_PLATFORM_V1: v1_region_create(id, rect, osds[id].opal); @@ -350,9 +350,9 @@ void *region_thread(void) i6c_region_create(id, rect, osds[id].opal); i6c_region_setbitmap(id, &bitmap); break; - case HAL_PLATFORM_I6F: - i6f_region_create(id, rect, osds[id].opal); - i6f_region_setbitmap(id, &bitmap); + case HAL_PLATFORM_M6: + m6_region_create(id, rect, osds[id].opal); + m6_region_setbitmap(id, &bitmap); break; case HAL_PLATFORM_V1: v1_region_create(id, rect, osds[id].opal); @@ -386,7 +386,7 @@ void *region_thread(void) case HAL_PLATFORM_GM: gm_region_destroy(id); break; case HAL_PLATFORM_I6: i6_region_destroy(id); break; case HAL_PLATFORM_I6C: i6c_region_destroy(id); break; - case HAL_PLATFORM_I6F: i6f_region_destroy(id); break; + case HAL_PLATFORM_M6: m6_region_destroy(id); break; case HAL_PLATFORM_V1: v1_region_destroy(id); break; case HAL_PLATFORM_V2: v2_region_destroy(id); break; case HAL_PLATFORM_V3: v3_region_destroy(id); break; @@ -405,7 +405,7 @@ void *region_thread(void) #if defined(__arm__) case HAL_PLATFORM_I6: i6_region_deinit(); break; case HAL_PLATFORM_I6C: i6c_region_deinit(); break; - case HAL_PLATFORM_I6F: i6f_region_deinit(); break; + case HAL_PLATFORM_M6: m6_region_deinit(); break; #endif } }