diff --git a/src/hal/inge/t31_aud.h b/src/hal/inge/t31_aud.h index 232f79b..33bea90 100644 --- a/src/hal/inge/t31_aud.h +++ b/src/hal/inge/t31_aud.h @@ -59,82 +59,56 @@ typedef struct { } t31_aud_impl; static int t31_aud_load(t31_aud_impl *aud_lib) { - if (!(aud_lib->handle = dlopen("libimp.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[t31_aud] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(aud_lib->handle = dlopen("libimp.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("t31_aud", "Failed to load library!\nError: %s\n", dlerror()); if (!(aud_lib->fnDisableDevice = (int(*)(int device)) - dlsym(aud_lib->handle, "IMP_AI_Disable"))) { - fprintf(stderr, "[t31_aud] Failed to acquire symbol IMP_AI_Disable!\n"); + hal_symbol_load("t31_aud", aud_lib->handle, "IMP_AI_Disable"))) return EXIT_FAILURE; - } if (!(aud_lib->fnEnableDevice = (int(*)(int device)) - dlsym(aud_lib->handle, "IMP_AI_Enable"))) { - fprintf(stderr, "[t31_aud] Failed to acquire symbol IMP_AI_Enable!\n"); + hal_symbol_load("t31_aud", aud_lib->handle, "IMP_AI_Enable"))) return EXIT_FAILURE; - } if (!(aud_lib->fnSetDeviceConfig = (int(*)(int device, t31_aud_cnf *config)) - dlsym(aud_lib->handle, "IMP_AI_SetPubAttr"))) { - fprintf(stderr, "[t31_aud] Failed to acquire symbol IMP_AI_SetPubAttr!\n"); + hal_symbol_load("t31_aud", aud_lib->handle, "IMP_AI_SetPubAttr"))) return EXIT_FAILURE; - } if (!(aud_lib->fnDisableChannel = (int(*)(int device, int channel)) - dlsym(aud_lib->handle, "IMP_AI_DisableChn"))) { - fprintf(stderr, "[t31_aud] Failed to acquire symbol IMP_AI_DisableChn!\n"); + hal_symbol_load("t31_aud", aud_lib->handle, "IMP_AI_DisableChn"))) return EXIT_FAILURE; - } if (!(aud_lib->fnEnableChannel = (int(*)(int device, int channel)) - dlsym(aud_lib->handle, "IMP_AI_EnableChn"))) { - fprintf(stderr, "[t31_aud] Failed to acquire symbol IMP_AI_EnableChn!\n"); + hal_symbol_load("t31_aud", aud_lib->handle, "IMP_AI_EnableChn"))) return EXIT_FAILURE; - } if (!(aud_lib->fnSetChannelConfig = (int(*)(int device, int channel, t31_aud_chn *config)) - dlsym(aud_lib->handle, "IMP_AI_SetChnParam"))) { - fprintf(stderr, "[t31_aud] Failed to acquire symbol IMP_AI_SetChnParam!\n"); + hal_symbol_load("t31_aud", aud_lib->handle, "IMP_AI_SetChnParam"))) return EXIT_FAILURE; - } if (!(aud_lib->fnSetGain = (int(*)(int device, int channel, int level)) - dlsym(aud_lib->handle, "IMP_AI_SetGain"))) { - fprintf(stderr, "[t31_aud] Failed to acquire symbol IMP_AI_SetGain!\n"); + hal_symbol_load("t31_aud", aud_lib->handle, "IMP_AI_SetGain"))) return EXIT_FAILURE; - } if (!(aud_lib->fnSetMute = (int(*)(int device, int channel, int active)) - dlsym(aud_lib->handle, "IMP_AI_SetVolMute"))) { - fprintf(stderr, "[t31_aud] Failed to acquire symbol IMP_AI_SetVolMute!\n"); + hal_symbol_load("t31_aud", aud_lib->handle, "IMP_AI_SetVolMute"))) return EXIT_FAILURE; - } if (!(aud_lib->fnSetVolume = (int(*)(int device, int channel, int level)) - dlsym(aud_lib->handle, "IMP_AI_SetVol"))) { - fprintf(stderr, "[t31_aud] Failed to acquire symbol IMP_AI_SetVol!\n"); + hal_symbol_load("t31_aud", aud_lib->handle, "IMP_AI_SetVol"))) return EXIT_FAILURE; - } if (!(aud_lib->fnFreeFrame = (int(*)(int device, int channel, t31_aud_frm *frame)) - dlsym(aud_lib->handle, "IMP_AI_ReleaseFrame"))) { - fprintf(stderr, "[t31_aud] Failed to acquire symbol IMP_AI_ReleaseFrame!\n"); + hal_symbol_load("t31_aud", aud_lib->handle, "IMP_AI_ReleaseFrame"))) return EXIT_FAILURE; - } if (!(aud_lib->fnGetFrame = (int(*)(int device, int channel, t31_aud_frm *frame, int notBlocking)) - dlsym(aud_lib->handle, "IMP_AI_GetFrame"))) { - fprintf(stderr, "[t31_aud] Failed to acquire symbol IMP_AI_GetFrame!\n"); + hal_symbol_load("t31_aud", aud_lib->handle, "IMP_AI_GetFrame"))) return EXIT_FAILURE; - } if (!(aud_lib->fnPollFrame = (int(*)(int device, int channel, int timeout)) - dlsym(aud_lib->handle, "IMP_AI_PollingFrame"))) { - fprintf(stderr, "[t31_aud] Failed to acquire symbol IMP_AI_PollingFrame!\n"); + hal_symbol_load("t31_aud", aud_lib->handle, "IMP_AI_PollingFrame"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/inge/t31_common.h b/src/hal/inge/t31_common.h index 465be82..7de7557 100644 --- a/src/hal/inge/t31_common.h +++ b/src/hal/inge/t31_common.h @@ -6,16 +6,9 @@ #include #include +#include "../symbols.h" #include "../types.h" -#define T31_ERROR(x, ...) \ - do { \ - fprintf(stderr, "[t31_hal] \033[31m"); \ - fprintf(stderr, (x), ##__VA_ARGS__); \ - fprintf(stderr, "\033[0m"); \ - return EXIT_FAILURE; \ - } while (0) - typedef enum { T31_PIXFMT_YUV420P, T31_PIXFMT_YUV422_YUYV, diff --git a/src/hal/inge/t31_fs.h b/src/hal/inge/t31_fs.h index 5442ed7..eb86522 100644 --- a/src/hal/inge/t31_fs.h +++ b/src/hal/inge/t31_fs.h @@ -57,53 +57,37 @@ typedef struct { } t31_fs_impl; static int t31_fs_load(t31_fs_impl *fs_lib) { - if (!(fs_lib->handle = dlopen("libimp.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[t31_fs] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(fs_lib->handle = dlopen("libimp.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("t31_fs", "Failed to load library!\nError: %s\n", dlerror()); if (!(fs_lib->fnCreateChannel = (int(*)(int channel, t31_fs_chn *config)) - dlsym(fs_lib->handle, "IMP_FrameSource_CreateChn"))) { - fprintf(stderr, "[t31_fs] Failed to acquire symbol IMP_FrameSource_CreateChn!\n"); + hal_symbol_load("t31_fs", fs_lib->handle, "IMP_FrameSource_CreateChn"))) return EXIT_FAILURE; - } if (!(fs_lib->fnDestroyChannel = (int(*)(int channel)) - dlsym(fs_lib->handle, "IMP_FrameSource_DestroyChn"))) { - fprintf(stderr, "[t31_fs] Failed to acquire symbol IMP_FrameSource_DestroyChn!\n"); + hal_symbol_load("t31_fs", fs_lib->handle, "IMP_FrameSource_DestroyChn"))) return EXIT_FAILURE; - } if (!(fs_lib->fnDisableChannel = (int(*)(int channel)) - dlsym(fs_lib->handle, "IMP_FrameSource_DisableChn"))) { - fprintf(stderr, "[t31_fs] Failed to acquire symbol IMP_FrameSource_DisableChn!\n"); + hal_symbol_load("t31_fs", fs_lib->handle, "IMP_FrameSource_DisableChn"))) return EXIT_FAILURE; - } if (!(fs_lib->fnEnableChannel = (int(*)(int channel)) - dlsym(fs_lib->handle, "IMP_FrameSource_EnableChn"))) { - fprintf(stderr, "[t31_fs] Failed to acquire symbol IMP_FrameSource_EnableChn!\n"); + hal_symbol_load("t31_fs", fs_lib->handle, "IMP_FrameSource_EnableChn"))) return EXIT_FAILURE; - } if (!(fs_lib->fnSetChannelRotate = (int(*)(int channel, char rotateMode, int width, int height)) - dlsym(fs_lib->handle, "IMP_FrameSource_SetChnRotate"))) { - fprintf(stderr, "[t31_fs] Failed to acquire symbol IMP_FrameSource_SetChnRotate!\n"); + hal_symbol_load("t31_fs", fs_lib->handle, "IMP_FrameSource_SetChnRotate"))) return EXIT_FAILURE; - } if (!(fs_lib->fnSetChannelSource = (int(*)(int channel, int source)) - dlsym(fs_lib->handle, "IMP_FrameSource_SetSource"))) { - fprintf(stderr, "[t31_fs] Failed to acquire symbol IMP_FrameSource_SetSource!\n"); + hal_symbol_load("t31_fs", fs_lib->handle, "IMP_FrameSource_SetSource"))) return EXIT_FAILURE; - } if (!(fs_lib->fnSnapshot = (int(*)(int channel, t31_common_pixfmt pixFmt, int width, int height, void *data, t31_fs_frame *info)) - dlsym(fs_lib->handle, "IMP_FrameSource_SnapFrame"))) { - fprintf(stderr, "[t31_fs] Failed to acquire symbol IMP_FrameSource_SnapFrame!\n"); + hal_symbol_load("t31_fs", fs_lib->handle, "IMP_FrameSource_SnapFrame"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/inge/t31_hal.c b/src/hal/inge/t31_hal.c index 4eec663..37fcc1f 100644 --- a/src/hal/inge/t31_hal.c +++ b/src/hal/inge/t31_hal.c @@ -105,7 +105,7 @@ void *t31_audio_thread(void) continue; if (ret = t31_aud.fnGetFrame(_t31_aud_dev, _t31_aud_chn, &frame, 1)) { - fprintf(stderr, "[t31_aud] Getting the frame failed " + HAL_WARNING("t31_aud", "Getting the frame failed " "with %#x!\n", ret); continue; } @@ -121,11 +121,11 @@ void *t31_audio_thread(void) } if (ret = t31_aud.fnFreeFrame(_t31_aud_dev, _t31_aud_chn, &frame)) { - fprintf(stderr, "[t31_aud] Releasing the frame failed" + HAL_WARNING("t31_aud", "Releasing the frame failed" " with %#x!\n", ret); } } - fprintf(stderr, "[t31_aud] Shutting down capture thread...\n"); + HAL_INFO("t31_aud", "Shutting down capture thread...\n"); } int t31_channel_bind(char index) @@ -216,7 +216,7 @@ int t31_pipeline_create(char mirror, char flip, char antiflicker, char framerate char *sensor, sensorName[50]; FILE *sensorInfo = fopen("/proc/jz/sinfo/info", "r"); if (!fgets(sensorName, 50, sensorInfo)) - fprintf(stderr, "[t31_hal] Couldn't determine the sensor name from sinfo module!\n"); + HAL_INFO("t31_hal", "Couldn't determine the sensor name from sinfo module!\n"); else { sensor = strstr(sensorName, ":"); if (!sensor++) goto sensor_from_env; @@ -301,13 +301,13 @@ int t31_region_create(int *handle, hal_rect rect, short opacity) region.data.picture = NULL; if (t31_osd.fnGetRegionConfig(*handle, ®ionCurr)) { - fprintf(stderr, "[t31_osd] Creating region...\n", _t31_osd_grp); + HAL_INFO("t31_osd", "Creating region...\n", _t31_osd_grp); if ((ret = t31_osd.fnCreateRegion(®ion)) < 0) return ret; else *handle = ret; } else if (regionCurr.rect.p1.y - regionCurr.rect.p0.y != rect.height || regionCurr.rect.p1.x - regionCurr.rect.p0.x != rect.width) { - fprintf(stderr, "[t31_osd] Parameters are different, recreating " + HAL_INFO("t31_osd", "Parameters are different, recreating " "region...\n", _t31_osd_grp); if (ret = t31_osd.fnSetRegionConfig(*handle, ®ion)) return ret; @@ -316,7 +316,7 @@ int t31_region_create(int *handle, hal_rect rect, short opacity) } if (t31_osd.fnGetGroupConfig(*handle, _t31_osd_grp, &attribCurr)) - fprintf(stderr, "[t31_osd] Attaching region...\n", _t31_osd_grp); + HAL_INFO("t31_osd", "Attaching region...\n", _t31_osd_grp); memset(&attrib, 0, sizeof(attrib)); attrib.show = 1; @@ -358,7 +358,7 @@ int t31_video_create(char index, hal_vidconfig *config) case HAL_VIDMODE_VBR: ratemode = T31_VENC_RATEMODE_VBR; break; case HAL_VIDMODE_QP: ratemode = T31_VENC_RATEMODE_QP; break; case HAL_VIDMODE_AVBR: ratemode = T31_VENC_RATEMODE_AVBR; break; - default: T31_ERROR("Video encoder does not support this mode!"); + default: HAL_ERROR("t31_venc", "Video encoder does not support this mode!"); } switch (config->codec) { case HAL_VIDCODEC_JPG: @@ -370,7 +370,7 @@ int t31_video_create(char index, hal_vidconfig *config) case HAL_VIDPROFILE_MAIN: profile = T31_VENC_PROF_H264_MAIN; break; default: profile = T31_VENC_PROF_H264_HIGH; break; } break; - default: T31_ERROR("This codec is not supported by the hardware!"); + default: HAL_ERROR("t31_venc", "This codec is not supported by the hardware!"); } if (profile == T31_VENC_PROF_MJPG) { @@ -466,7 +466,7 @@ int t31_video_snapshot_grab(char index, hal_jpegdata *jpeg) char mjpeg = 0; if (index == -1) { - fprintf(stderr, "[t31_venc] Snapshot falling back to the MJPEG channel," + HAL_INFO("t31_venc", "Snapshot falling back to the MJPEG channel," " its resolution will be used in place\n"); for (char i = 0; i < T31_VENC_CHN_NUM; i++) { if (!t31_state[i].enable) continue; @@ -480,13 +480,13 @@ int t31_video_snapshot_grab(char index, hal_jpegdata *jpeg) if (!mjpeg) { if (ret = t31_channel_bind(index)) { - fprintf(stderr, "[t31_venc] Binding the encoder channel " + HAL_DANGER("t31_venc", "Binding the encoder channel " "%d failed with %#x!\n", index, ret); goto abort; } if (t31_venc.fnStartReceiving(index)) { - fprintf(stderr, "[t31_venc] Requesting one frame " + HAL_DANGER("t31_venc", "Requesting one frame " "%d failed with %#x!\n", index, ret); goto abort; } @@ -500,23 +500,23 @@ int t31_video_snapshot_grab(char index, hal_jpegdata *jpeg) FD_SET(fd, &readFds); ret = select(fd + 1, &readFds, NULL, NULL, &timeout); if (ret < 0) { - fprintf(stderr, "[t31_venc] Select operation failed!\n"); + HAL_DANGER("t31_venc", "Select operation failed!\n"); goto abort; } else if (ret == 0) { - fprintf(stderr, "[t31_venc] Capture stream timed out!\n"); + HAL_DANGER("t31_venc", "Capture stream timed out!\n"); goto abort; } if (FD_ISSET(fd, &readFds)) { t31_venc_stat stat; if (t31_venc.fnQuery(index, &stat)) { - fprintf(stderr, "[t31_venc] Querying the encoder channel " + HAL_DANGER("t31_venc", "Querying the encoder channel " "%d failed with %#x!\n", index, ret); goto abort; } if (!stat.curPacks) { - fprintf(stderr, "[t31_venc] Current frame is empty, skipping it!\n"); + HAL_DANGER("t31_venc", "Current frame is empty, skipping it!\n"); goto abort; } @@ -524,13 +524,13 @@ int t31_video_snapshot_grab(char index, hal_jpegdata *jpeg) memset(&strm, 0, sizeof(strm)); strm.packet = (t31_venc_pack*)malloc(sizeof(t31_venc_pack) * stat.curPacks); if (!strm.packet) { - fprintf(stderr, "[t31_venc] Memory allocation on channel %d failed!\n", index); + HAL_DANGER("t31_venc", "Memory allocation on channel %d failed!\n", index); goto abort; } strm.count = stat.curPacks; if (ret = t31_venc.fnGetStream(index, &strm, 0)) { - fprintf(stderr, "[t31_venc] Getting the stream on " + HAL_DANGER("t31_venc", "Getting the stream on " "channel %d failed with %#x!\n", index, ret); free(strm.packet); strm.packet = NULL; @@ -578,7 +578,7 @@ void *t31_video_thread(void) ret = t31_venc.fnGetDescriptor(i); if (ret < 0) { - fprintf(stderr, "[t31_venc] Getting the encoder descriptor failed with %#x!\n", ret); + HAL_DANGER("t31_venc", "Getting the encoder descriptor failed with %#x!\n", ret); return NULL; } t31_state[i].fileDesc = ret; @@ -603,10 +603,10 @@ void *t31_video_thread(void) timeout.tv_usec = 0; ret = select(maxFd + 1, &readFds, NULL, NULL, &timeout); if (ret < 0) { - fprintf(stderr, "[t31_venc] Select operation failed!\n"); + HAL_DANGER("t31_venc", "Select operation failed!\n"); break; } else if (ret == 0) { - fprintf(stderr, "[t31_venc] Main stream loop timed out!\n"); + HAL_WARNING("t31_venc", "Main stream loop timed out!\n"); continue; } else { for (int i = 0; i < T31_VENC_CHN_NUM; i++) { @@ -616,7 +616,7 @@ void *t31_video_thread(void) t31_venc_strm stream; if (ret = t31_venc.fnGetStream(i, &stream, 0)) { - fprintf(stderr, "[t31_venc] Getting the stream on " + HAL_DANGER("t31_venc", "Getting the stream on " "channel %d failed with %#x!\n", i, ret); break; } @@ -657,14 +657,14 @@ void *t31_video_thread(void) } if (ret = t31_venc.fnFreeStream(i, &stream)) { - fprintf(stderr, "[t31_venc] Releasing the stream on " + HAL_DANGER("t31_venc", "Releasing the stream on " "channel %d failed with %#x!\n", i, ret); } } } } } - fprintf(stderr, "[t31_venc] Shutting down encoding thread...\n"); + HAL_INFO("t31_venc", "Shutting down encoding thread...\n"); } void t31_system_deinit(void) diff --git a/src/hal/inge/t31_isp.h b/src/hal/inge/t31_isp.h index 3426b79..cdc37cc 100644 --- a/src/hal/inge/t31_isp.h +++ b/src/hal/inge/t31_isp.h @@ -119,82 +119,56 @@ typedef struct { } t31_isp_impl; static int t31_isp_load(t31_isp_impl *isp_lib) { - if (!(isp_lib->handle = dlopen("libimp.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[t31_isp] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(isp_lib->handle = dlopen("libimp.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("t31_isp", "Failed to load library!\nError: %s\n", dlerror()); if (!(isp_lib->fnEnableTuning = (int(*)(void)) - dlsym(isp_lib->handle, "IMP_ISP_EnableTuning"))) { - fprintf(stderr, "[t31_isp] Failed to acquire symbol IMP_ISP_EnableTuning!\n"); + hal_symbol_load("t31_isp", isp_lib->handle, "IMP_ISP_EnableTuning"))) return EXIT_FAILURE; - } if (!(isp_lib->fnExit = (int(*)(void)) - dlsym(isp_lib->handle, "IMP_ISP_Close"))) { - fprintf(stderr, "[t31_isp] Failed to acquire symbol IMP_ISP_Close!\n"); + hal_symbol_load("t31_isp", isp_lib->handle, "IMP_ISP_Close"))) return EXIT_FAILURE; - } if (!(isp_lib->fnInit = (int(*)(void)) - dlsym(isp_lib->handle, "IMP_ISP_Open"))) { - fprintf(stderr, "[t31_isp] Failed to acquire symbol IMP_ISP_Open!\n"); + hal_symbol_load("t31_isp", isp_lib->handle, "IMP_ISP_Open"))) return EXIT_FAILURE; - } if (!(isp_lib->fnLoadConfig = (int(*)(char *path)) - dlsym(isp_lib->handle, "IMP_ISP_SetDefaultBinPath"))) { - fprintf(stderr, "[t31_isp] Failed to acquire symbol IMP_ISP_SetDefaultBinPath!\n"); + hal_symbol_load("t31_isp", isp_lib->handle, "IMP_ISP_SetDefaultBinPath"))) return EXIT_FAILURE; - } if (!(isp_lib->fnSetAntiFlicker = (int(*)(t31_isp_flick mode)) - dlsym(isp_lib->handle, "IMP_ISP_Tuning_SetAntiFlickerAttr"))) { - fprintf(stderr, "[t31_isp] Failed to acquire symbol IMP_ISP_Tuning_SetAntiFlickerAttr!\n"); + hal_symbol_load("t31_isp", isp_lib->handle, "IMP_ISP_Tuning_SetAntiFlickerAttr"))) return EXIT_FAILURE; - } if (!(isp_lib->fnSetFlip = (int(*)(int mode)) - dlsym(isp_lib->handle, "IMP_ISP_Tuning_SetHVFLIP"))) { - fprintf(stderr, "[t31_isp] Failed to acquire symbol IMP_ISP_Tuning_SetHVFLIP!\n"); + hal_symbol_load("t31_isp", isp_lib->handle, "IMP_ISP_Tuning_SetHVFLIP"))) return EXIT_FAILURE; - } if (!(isp_lib->fnSetFramerate = (int(*)(unsigned int fpsNum, unsigned int fpsDen)) - dlsym(isp_lib->handle, "IMP_ISP_Tuning_SetSensorFPS"))) { - fprintf(stderr, "[t31_isp] Failed to acquire symbol IMP_ISP_Tuning_SetSensorFPS!\n"); + hal_symbol_load("t31_isp", isp_lib->handle, "IMP_ISP_Tuning_SetSensorFPS"))) return EXIT_FAILURE; - } if (!(isp_lib->fnSetRunningMode = (int(*)(int nightOn)) - dlsym(isp_lib->handle, "IMP_ISP_Tuning_SetISPRunningMode"))) { - fprintf(stderr, "[t31_isp] Failed to acquire symbol IMP_ISP_Tuning_SetISPRunningMode!\n"); + hal_symbol_load("t31_isp", isp_lib->handle, "IMP_ISP_Tuning_SetISPRunningMode"))) return EXIT_FAILURE; - } if (!(isp_lib->fnAddSensor = (int(*)(t31_isp_snr *sensor)) - dlsym(isp_lib->handle, "IMP_ISP_AddSensor"))) { - fprintf(stderr, "[t31_isp] Failed to acquire symbol IMP_ISP_AddSensor!\n"); + hal_symbol_load("t31_isp", isp_lib->handle, "IMP_ISP_AddSensor"))) return EXIT_FAILURE; - } if (!(isp_lib->fnDeleteSensor = (int(*)(t31_isp_snr *sensor)) - dlsym(isp_lib->handle, "IMP_ISP_DelSensor"))) { - fprintf(stderr, "[t31_isp] Failed to acquire symbol IMP_ISP_DelSensor!\n"); + hal_symbol_load("t31_isp", isp_lib->handle, "IMP_ISP_DelSensor"))) return EXIT_FAILURE; - } if (!(isp_lib->fnDisableSensor = (int(*)(void)) - dlsym(isp_lib->handle, "IMP_ISP_DisableSensor"))) { - fprintf(stderr, "[t31_isp] Failed to acquire symbol IMP_ISP_DisableSensor!\n"); + hal_symbol_load("t31_isp", isp_lib->handle, "IMP_ISP_DisableSensor"))) return EXIT_FAILURE; - } if (!(isp_lib->fnEnableSensor = (int(*)(void)) - dlsym(isp_lib->handle, "IMP_ISP_EnableSensor"))) { - fprintf(stderr, "[t31_isp] Failed to acquire symbol IMP_ISP_EnableSensor!\n"); + hal_symbol_load("t31_isp", isp_lib->handle, "IMP_ISP_EnableSensor"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/inge/t31_osd.h b/src/hal/inge/t31_osd.h index 8d62842..d2f651c 100644 --- a/src/hal/inge/t31_osd.h +++ b/src/hal/inge/t31_osd.h @@ -65,83 +65,56 @@ typedef struct { } t31_osd_impl; static int t31_osd_load(t31_osd_impl *osd_lib) { - if (!(osd_lib->handle = dlopen("libimp.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[t31_osd] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(osd_lib->handle = dlopen("libimp.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("t31_osd", "Failed to load library!\nError: %s\n", dlerror()); if (!(osd_lib->fnCreateRegion = (int(*)(t31_osd_rgn *config)) - dlsym(osd_lib->handle, "IMP_OSD_CreateRgn"))) { - fprintf(stderr, "[t31_osd] Failed to acquire symbol IMP_OSD_CreateRgn!\n"); + hal_symbol_load("t31_osd", osd_lib->handle, "IMP_OSD_CreateRgn"))) return EXIT_FAILURE; - } if (!(osd_lib->fnDestroyRegion = (int(*)(int handle)) - dlsym(osd_lib->handle, "IMP_OSD_DestroyRgn"))) { - fprintf(stderr, "[t31_osd] Failed to acquire symbol IMP_OSD_DestroyRgn!\n"); + hal_symbol_load("t31_osd", osd_lib->handle, "IMP_OSD_DestroyRgn"))) return EXIT_FAILURE; - } if (!(osd_lib->fnGetRegionConfig = (int(*)(int handle, t31_osd_rgn *config)) - dlsym(osd_lib->handle, "IMP_OSD_GetRgnAttr"))) { - fprintf(stderr, "[t31_osd] Failed to acquire symbol IMP_OSD_GetRgnAttr!\n"); + hal_symbol_load("t31_osd", osd_lib->handle, "IMP_OSD_GetRgnAttr"))) return EXIT_FAILURE; - } if (!(osd_lib->fnRegisterRegion = (int(*)(int handle, int group, t31_osd_grp *config)) - dlsym(osd_lib->handle, "IMP_OSD_RegisterRgn"))) { - fprintf(stderr, "[t31_osd] Failed to acquire symbol IMP_OSD_RegisterRgn!\n"); + hal_symbol_load("t31_osd", osd_lib->handle, "IMP_OSD_RegisterRgn"))) return EXIT_FAILURE; - } if (!(osd_lib->fnSetRegionConfig = (int(*)(int handle, t31_osd_rgn *config)) - dlsym(osd_lib->handle, "IMP_OSD_SetRgnAttr"))) { - fprintf(stderr, "[t31_osd] Failed to acquire symbol IMP_OSD_SetRgnAttr!\n"); + hal_symbol_load("t31_osd", osd_lib->handle, "IMP_OSD_SetRgnAttr"))) return EXIT_FAILURE; - } if (!(osd_lib->fnUnregisterRegion = (int(*)(int handle, int group)) - dlsym(osd_lib->handle, "IMP_OSD_UnRegisterRgn"))) { - fprintf(stderr, "[t31_osd] Failed to acquire symbol IMP_OSD_UnRegisterRgn!\n"); + hal_symbol_load("t31_osd", osd_lib->handle, "IMP_OSD_UnRegisterRgn"))) return EXIT_FAILURE; - } if (!(osd_lib->fnAttachToGroup = (int(*)(t31_sys_bind *source, t31_sys_bind *dest)) - dlsym(osd_lib->handle, "IMP_OSD_AttachToGroup"))) { - fprintf(stderr, "[t31_osd] Failed to acquire symbol IMP_OSD_AttachToGroup!\n"); + hal_symbol_load("t31_osd", osd_lib->handle, "IMP_OSD_AttachToGroup"))) return EXIT_FAILURE; - } if (!(osd_lib->fnCreateGroup = (int(*)(int group)) - dlsym(osd_lib->handle, "IMP_OSD_CreateGroup"))) { - fprintf(stderr, "[t31_osd] Failed to acquire symbol IMP_OSD_CreateGroup!\n"); + hal_symbol_load("t31_osd", osd_lib->handle, "IMP_OSD_CreateGroup"))) return EXIT_FAILURE; - } if (!(osd_lib->fnDestroyGroup = (int(*)(int group)) - dlsym(osd_lib->handle, "IMP_OSD_DestroyGroup"))) { - fprintf(stderr, "[t31_osd] Failed to acquire symbol IMP_OSD_DestroyGroup!\n"); + hal_symbol_load("t31_osd", osd_lib->handle, "IMP_OSD_DestroyGroup"))) return EXIT_FAILURE; - } if (!(osd_lib->fnGetGroupConfig = (int(*)(int handle, int group, t31_osd_grp *config)) - dlsym(osd_lib->handle, "IMP_OSD_GetGrpRgnAttr"))) { - fprintf(stderr, "[t31_osd] Failed to acquire symbol IMP_OSD_GetGrpRgnAttr!\n"); + hal_symbol_load("t31_osd", osd_lib->handle, "IMP_OSD_GetGrpRgnAttr"))) return EXIT_FAILURE; - } if (!(osd_lib->fnStartGroup = (int(*)(int group)) - dlsym(osd_lib->handle, "IMP_OSD_Start"))) { - fprintf(stderr, "[t31_osd] Failed to acquire symbol IMP_OSD_Start!\n"); + hal_symbol_load("t31_osd", osd_lib->handle, "IMP_OSD_Start"))) return EXIT_FAILURE; - } if (!(osd_lib->fnStopGroup = (int(*)(int group)) - dlsym(osd_lib->handle, "IMP_OSD_Stop"))) { - fprintf(stderr, "[t31_osd] Failed to acquire symbol IMP_OSD_Stop!\n"); + hal_symbol_load("t31_osd", osd_lib->handle, "IMP_OSD_Stop"))) return EXIT_FAILURE; - } - return EXIT_SUCCESS; } diff --git a/src/hal/inge/t31_sys.h b/src/hal/inge/t31_sys.h index 434ae80..72d2739 100644 --- a/src/hal/inge/t31_sys.h +++ b/src/hal/inge/t31_sys.h @@ -41,46 +41,32 @@ typedef struct { static int t31_sys_load(t31_sys_impl *sys_lib) { if (!(sys_lib->handleSysutils = dlopen("libsysutils.so", RTLD_LAZY | RTLD_GLOBAL)) || !(sys_lib->handleAlog = dlopen("libalog.so", RTLD_LAZY | RTLD_GLOBAL)) || - !(sys_lib->handle = dlopen("libimp.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[t31_sys] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + !(sys_lib->handle = dlopen("libimp.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("t31_sys", "Failed to load library!\nError: %s\n", dlerror()); if (!(sys_lib->fnExit = (int(*)(void)) - dlsym(sys_lib->handle, "IMP_System_Exit"))) { - fprintf(stderr, "[t31_sys] Failed to acquire symbol IMP_System_Exit!\n"); + hal_symbol_load("t31_sys", sys_lib->handle, "IMP_System_Exit"))) return EXIT_FAILURE; - } if (!(sys_lib->fnGetChipName = (int(*)(const char *chip)) - dlsym(sys_lib->handle, "IMP_System_GetCPUInfo"))) { - fprintf(stderr, "[t31_sys] Failed to acquire symbol IMP_System_GetCPUInfo!\n"); + hal_symbol_load("t31_sys", sys_lib->handle, "IMP_System_GetCPUInfo"))) return EXIT_FAILURE; - } if (!(sys_lib->fnGetVersion = (int(*)(t31_sys_ver *version)) - dlsym(sys_lib->handle, "IMP_System_GetVersion"))) { - fprintf(stderr, "[t31_sys] Failed to acquire symbol IMP_System_GetVersion!\n"); + hal_symbol_load("t31_sys", sys_lib->handle, "IMP_System_GetVersion"))) return EXIT_FAILURE; - } if (!(sys_lib->fnInit = (int(*)(void)) - dlsym(sys_lib->handle, "IMP_System_Init"))) { - fprintf(stderr, "[t31_sys] Failed to acquire symbol IMP_System_Init!\n"); + hal_symbol_load("t31_sys", sys_lib->handle, "IMP_System_Init"))) return EXIT_FAILURE; - } if (!(sys_lib->fnBind = (int(*)(t31_sys_bind *source, t31_sys_bind *dest)) - dlsym(sys_lib->handle, "IMP_System_Bind"))) { - fprintf(stderr, "[t31_sys] Failed to acquire symbol IMP_System_Bind!\n"); + hal_symbol_load("t31_sys", sys_lib->handle, "IMP_System_Bind"))) return EXIT_FAILURE; - } if (!(sys_lib->fnUnbind = (int(*)(t31_sys_bind *source, t31_sys_bind *dest)) - dlsym(sys_lib->handle, "IMP_System_UnBind"))) { - fprintf(stderr, "[t31_sys] Failed to acquire symbol IMP_System_UnBind!\n"); + hal_symbol_load("t31_sys", sys_lib->handle, "IMP_System_UnBind"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/inge/t31_venc.h b/src/hal/inge/t31_venc.h index 0862ea6..f215ceb 100644 --- a/src/hal/inge/t31_venc.h +++ b/src/hal/inge/t31_venc.h @@ -273,7 +273,10 @@ typedef struct { typedef struct { void *handle; - int (*fnSetDefaults)(t31_venc_chn *config, t31_venc_prof profile, t31_venc_ratemode ratemode, unsigned short width, unsigned short height, unsigned int fpsNum, unsigned int fpsDen, unsigned int gopLength, int maxSameSenceCnt, int initialQp, unsigned int tgtBitrate); + int (*fnSetDefaults)(t31_venc_chn *config, t31_venc_prof profile, + t31_venc_ratemode ratemode, unsigned short width, unsigned short height, + unsigned int fpsNum, unsigned int fpsDen, unsigned int gopLength, + int maxSameSenceCnt, int initialQp, unsigned int tgtBitrate); int (*fnCreateGroup)(int group); int (*fnDestroyGroup)(int group); @@ -296,94 +299,67 @@ typedef struct { } t31_venc_impl; static int t31_venc_load(t31_venc_impl *venc_lib) { - if (!(venc_lib->handle = dlopen("libimp.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[t31_venc] Failed to load library!\nError: %s\n", dlerror()); + if (!(venc_lib->handle = dlopen("libimp.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("t31_venc", "Failed to load library!\nError: %s\n", dlerror()); + + if (!(venc_lib->fnSetDefaults = (int(*)(t31_venc_chn *config, t31_venc_prof profile, + t31_venc_ratemode ratemode, unsigned short width, unsigned short height, + unsigned int fpsNum, unsigned int fpsDen, unsigned int gopLength, + int maxSameSenceCnt, int initialQp, unsigned int tgtBitrate)) + hal_symbol_load("t31_venc", venc_lib->handle, "IMP_Encoder_SetDefaultParam"))) return EXIT_FAILURE; - } - - if (!(venc_lib->fnSetDefaults = (int(*)(t31_venc_chn *config, t31_venc_prof profile, t31_venc_ratemode ratemode, unsigned short width, unsigned short height, unsigned int fpsNum, unsigned int fpsDen, unsigned int gopLength, int maxSameSenceCnt, int initialQp, unsigned int tgtBitrate)) - dlsym(venc_lib->handle, "IMP_Encoder_SetDefaultParam"))) { - fprintf(stderr, "[t31_venc] Failed to acquire symbol IMP_Encoder_SetDefaultParam!\n"); - return EXIT_FAILURE; - } if (!(venc_lib->fnCreateGroup = (int(*)(int group)) - dlsym(venc_lib->handle, "IMP_Encoder_CreateGroup"))) { - fprintf(stderr, "[t31_venc] Failed to acquire symbol IMP_Encoder_CreateGroup!\n"); + hal_symbol_load("t31_venc", venc_lib->handle, "IMP_Encoder_CreateGroup"))) return EXIT_FAILURE; - } if (!(venc_lib->fnDestroyGroup = (int(*)(int group)) - dlsym(venc_lib->handle, "IMP_Encoder_DestroyGroup"))) { - fprintf(stderr, "[t31_venc] Failed to acquire symbol IMP_Encoder_DestroyGroup!\n"); + hal_symbol_load("t31_venc", venc_lib->handle, "IMP_Encoder_DestroyGroup"))) return EXIT_FAILURE; - } if (!(venc_lib->fnCreateChannel = (int(*)(int channel, t31_venc_chn *config)) - dlsym(venc_lib->handle, "IMP_Encoder_CreateChn"))) { - fprintf(stderr, "[t31_venc] Failed to acquire symbol IMP_Encoder_CreateChn!\n"); + hal_symbol_load("t31_venc", venc_lib->handle, "IMP_Encoder_CreateChn"))) return EXIT_FAILURE; - } if (!(venc_lib->fnDestroyChannel = (int(*)(int channel)) - dlsym(venc_lib->handle, "IMP_Encoder_DestroyChn"))) { - fprintf(stderr, "[t31_venc] Failed to acquire symbol IMP_Encoder_DestroyChn!\n"); + hal_symbol_load("t31_venc", venc_lib->handle, "IMP_Encoder_DestroyChn"))) return EXIT_FAILURE; - } if (!(venc_lib->fnRegisterChannel = (int(*)(int group, int channel)) - dlsym(venc_lib->handle, "IMP_Encoder_RegisterChn"))) { - fprintf(stderr, "[t31_venc] Failed to acquire symbol IMP_Encoder_RegisterChn!\n"); + hal_symbol_load("t31_venc", venc_lib->handle, "IMP_Encoder_RegisterChn"))) return EXIT_FAILURE; - } if (!(venc_lib->fnUnregisterChannel = (int(*)(int channel)) - dlsym(venc_lib->handle, "IMP_Encoder_UnRegisterChn"))) { - fprintf(stderr, "[t31_venc] Failed to acquire symbol IMP_Encoder_UnRegisterChn!\n"); + hal_symbol_load("t31_venc", venc_lib->handle, "IMP_Encoder_UnRegisterChn"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetDescriptor = (int(*)(int channel)) - dlsym(venc_lib->handle, "IMP_Encoder_GetFd"))) { - fprintf(stderr, "[t31_venc] Failed to acquire symbol IMP_Encoder_GetFd!\n"); + hal_symbol_load("t31_venc", venc_lib->handle, "IMP_Encoder_GetFd"))) return EXIT_FAILURE; - } if (!(venc_lib->fnFreeStream = (int(*)(int channel, t31_venc_strm *stream)) - dlsym(venc_lib->handle, "IMP_Encoder_ReleaseStream"))) { - fprintf(stderr, "[t31_venc] Failed to acquire symbol IMP_Encoder_ReleaseStream!\n"); + hal_symbol_load("t31_venc", venc_lib->handle, "IMP_Encoder_ReleaseStream"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetStream = (int(*)(int channel, t31_venc_strm *stream, char blockingOn)) - dlsym(venc_lib->handle, "IMP_Encoder_GetStream"))) { - fprintf(stderr, "[t31_venc] Failed to acquire symbol IMP_Encoder_GetStream!\n"); + hal_symbol_load("t31_venc", venc_lib->handle, "IMP_Encoder_GetStream"))) return EXIT_FAILURE; - } if (!(venc_lib->fnQuery = (int(*)(int channel, t31_venc_stat *stats)) - dlsym(venc_lib->handle, "IMP_Encoder_Query"))) { - fprintf(stderr, "[t31_venc] Failed to acquire symbol IMP_Encoder_Query!\n"); + hal_symbol_load("t31_venc", venc_lib->handle, "IMP_Encoder_Query"))) return EXIT_FAILURE; - } if (!(venc_lib->fnRequestIdr = (int(*)(int channel)) - dlsym(venc_lib->handle, "IMP_Encoder_RequestIDR"))) { - fprintf(stderr, "[t31_venc] Failed to acquire symbol IMP_Encoder_RequestIDR!\n"); + hal_symbol_load("t31_venc", venc_lib->handle, "IMP_Encoder_RequestIDR"))) return EXIT_FAILURE; - } if (!(venc_lib->fnStartReceiving = (int(*)(int channel)) - dlsym(venc_lib->handle, "IMP_Encoder_StartRecvPic"))) { - fprintf(stderr, "[t31_venc] Failed to acquire symbol IMP_Encoder_StartRecvPic!\n"); + hal_symbol_load("t31_venc", venc_lib->handle, "IMP_Encoder_StartRecvPic"))) return EXIT_FAILURE; - } if (!(venc_lib->fnStopReceiving = (int(*)(int channel)) - dlsym(venc_lib->handle, "IMP_Encoder_StopRecvPic"))) { - fprintf(stderr, "[t31_venc] Failed to acquire symbol IMP_Encoder_StopRecvPic!\n"); + hal_symbol_load("t31_venc", venc_lib->handle, "IMP_Encoder_StopRecvPic"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/macros.h b/src/hal/macros.h new file mode 100644 index 0000000..2c95e85 --- /dev/null +++ b/src/hal/macros.h @@ -0,0 +1,29 @@ +#pragma once + +#define HAL_DANGER(mod, x, ...) \ + do { \ + fprintf(stderr, "[%s] \033[31m", (mod)); \ + fprintf(stderr, (x), ##__VA_ARGS__); \ + fprintf(stderr, "\033[0m"); \ + } while (0) + +#define HAL_ERROR(mod, x, ...) \ + do { \ + fprintf(stderr, "[%s] \033[31m", (mod)); \ + fprintf(stderr, (x), ##__VA_ARGS__); \ + fprintf(stderr, "\033[0m"); \ + return EXIT_FAILURE; \ + } while (0) + +#define HAL_INFO(mod, x, ...) \ + do { \ + fprintf(stderr, "[%s] ", (mod)); \ + fprintf(stderr, (x), ##__VA_ARGS__); \ + } while (0) + +#define HAL_WARNING(mod, x, ...) \ + do { \ + fprintf(stderr, "[%s] \033[33m", (mod)); \ + fprintf(stderr, (x), ##__VA_ARGS__); \ + fprintf(stderr, "\033[0m"); \ + } while (0) diff --git a/src/hal/plus/gm_common.h b/src/hal/plus/gm_common.h index 47650ef..fbf9d99 100644 --- a/src/hal/plus/gm_common.h +++ b/src/hal/plus/gm_common.h @@ -6,6 +6,7 @@ #include #include +#include "../symbols.h" #include "../types.h" #define GM_LIB_VER 0x41 @@ -23,14 +24,6 @@ typedef enum { #define GM_DECLARE(hal, var, type, real) \ type var = ({hal.fnDeclareStruct(&var, real, sizeof(type), GM_LIB_VER); var;}) -#define GM_ERROR(x, ...) \ - do { \ - fprintf(stderr, "[gm_hal] \033[31m"); \ - fprintf(stderr, (x), ##__VA_ARGS__); \ - fprintf(stderr, "\033[0m"); \ - return EXIT_FAILURE; \ - } while (0) - typedef struct { int width; int height; diff --git a/src/hal/plus/gm_hal.c b/src/hal/plus/gm_hal.c index 9e2d599..acc20cb 100644 --- a/src/hal/plus/gm_hal.c +++ b/src/hal/plus/gm_hal.c @@ -89,7 +89,7 @@ int gm_video_create(char index, hal_vidconfig *config) switch (config->mode) { case HAL_VIDMODE_CBR: ratemode = GM_VENC_RATEMODE_CBR; break; case HAL_VIDMODE_VBR: ratemode = GM_VENC_RATEMODE_VBR; break; - default: GM_ERROR("Video encoder does not support this mode!"); + default: HAL_ERROR("gm_venc", "Video encoder does not support this mode!"); } switch (config->codec) { @@ -132,7 +132,7 @@ int gm_video_create(char index, hal_vidconfig *config) h264chn.level = 41; gm_lib.fnSetDeviceConfig(_gm_venc_dev[index], &h264chn); break; - default: GM_ERROR("This codec is not supported by the hardware!"); + default: HAL_ERROR("gm_venc", "This codec is not supported by the hardware!"); } gm_state[index].payload = config->codec; @@ -195,7 +195,7 @@ int gm_video_snapshot_grab(short width, short height, char quality, hal_jpegdata abort: free(buffer); - GM_ERROR("Taking a snapshot failed with %#x!\n", ret); + HAL_ERROR("gm_venc", "Taking a snapshot failed with %#x!\n", ret); } void *gm_video_thread(void) @@ -214,7 +214,7 @@ void *gm_video_thread(void) while (keepRunning) { ret = gm_lib.fnPollStream(_gm_venc_fds, GM_VENC_CHN_NUM, 500); if (ret == GM_ERR_TIMEOUT) { - fprintf(stderr, "[gm_venc] Main stream loop timed out!\n"); + HAL_WARNING("gm_venc", "Main stream loop timed out!\n"); continue; } @@ -222,7 +222,7 @@ void *gm_video_thread(void) if (_gm_venc_fds[i].event.type != GM_POLL_READ) continue; if (_gm_venc_fds[i].event.bsLength > bufSize) { - fprintf(stderr, "[gm_venc] Bitstream buffer needs %d bytes " + HAL_WARNING("gm_venc", "Bitstream buffer needs %d bytes " "more, dropping the upcoming data!\n", _gm_venc_fds[i].event.bsLength - bufSize); continue; @@ -236,12 +236,12 @@ void *gm_video_thread(void) } if ((ret = gm_lib.fnReceiveStream(stream, GM_VENC_CHN_NUM)) < 0) - fprintf(stderr, "[gm_venc] Receiving the streams failed " + HAL_WARNING("gm_venc", "Receiving the streams failed " "with %#x!\n", ret); else for (char i = 0; i < GM_VENC_CHN_NUM; i++) { if (!stream[i].bind) continue; if (stream[i].ret < 0) - fprintf(stderr, "[gm_venc] Failed to the receive bitstream on " + HAL_WARNING("gm_venc", "Failed to the receive bitstream on " "channel %d with %#x!\n", i, stream[i].ret); else if (!stream[i].ret && gm_vid_cb) { gm_venc_pack *pack = &stream[i].pack; @@ -276,7 +276,7 @@ void *gm_video_thread(void) } } abort: - fprintf(stderr, "[gm_venc] Shutting down encoding thread...\n"); + HAL_INFO("gm_venc", "Shutting down encoding thread...\n"); free(bsData); } diff --git a/src/hal/plus/gm_hal.h b/src/hal/plus/gm_hal.h index 8ddd49a..b329c04 100644 --- a/src/hal/plus/gm_hal.h +++ b/src/hal/plus/gm_hal.h @@ -74,100 +74,68 @@ typedef struct { } gm_lib_impl; static int gm_lib_load(gm_lib_impl *aio_lib) { - if (!(aio_lib->handle = dlopen("libgm.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[gm_lib] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(aio_lib->handle = dlopen("libgm.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("gm_lib", "Failed to load library!\nError: %s\n", dlerror()); if (!(aio_lib->fnDeclareStruct = (void(*)(void *name, char *string, int size, int libVersion)) - dlsym(aio_lib->handle, "gm_init_attr"))) { - fprintf(stderr, "[gm_lib] Failed to acquire symbol gm_init_attr!\n"); + hal_symbol_load("gm_lib", aio_lib->handle, "gm_init_attr"))) return EXIT_FAILURE; - } if (!(aio_lib->fnExit = (int(*)(void)) - dlsym(aio_lib->handle, "gm_release"))) { - fprintf(stderr, "[gm_lib] Failed to acquire symbol gm_release!\n"); + hal_symbol_load("gm_lib", aio_lib->handle, "gm_release"))) return EXIT_FAILURE; - } if (!(aio_lib->fnInit = (int(*)(int libVersion)) - dlsym(aio_lib->handle, "gm_init_private"))) { - fprintf(stderr, "[gm_lib] Failed to acquire symbol gm_init_private!\n"); + hal_symbol_load("gm_lib", aio_lib->handle, "gm_init_private"))) return EXIT_FAILURE; - } if (!(aio_lib->fnCreateDevice = (void*(*)(gm_lib_dev type)) - dlsym(aio_lib->handle, "gm_new_obj"))) { - fprintf(stderr, "[gm_lib] Failed to acquire symbol gm_new_obj!\n"); + hal_symbol_load("gm_lib", aio_lib->handle, "gm_new_obj"))) return EXIT_FAILURE; - } if (!(aio_lib->fnDestroyDevice = (int(*)(void *device)) - dlsym(aio_lib->handle, "gm_delete_obj"))) { - fprintf(stderr, "[gm_lib] Failed to acquire symbol gm_delete_obj!\n"); + hal_symbol_load("gm_lib", aio_lib->handle, "gm_delete_obj"))) return EXIT_FAILURE; - } if (!(aio_lib->fnSetDeviceConfig = (int(*)(void *device, void *config)) - dlsym(aio_lib->handle, "gm_set_attr"))) { - fprintf(stderr, "[gm_lib] Failed to acquire symbol gm_set_attr!\n"); + hal_symbol_load("gm_lib", aio_lib->handle, "gm_set_attr"))) return EXIT_FAILURE; - } if (!(aio_lib->fnCreateGroup = (void*(*)(void)) - dlsym(aio_lib->handle, "gm_new_groupfd"))) { - fprintf(stderr, "[gm_lib] Failed to acquire symbol gm_new_groupfd!\n"); + hal_symbol_load("gm_lib", aio_lib->handle, "gm_new_groupfd"))) return EXIT_FAILURE; - } if (!(aio_lib->fnDestroyGroup = (int(*)(void *group)) - dlsym(aio_lib->handle, "gm_delete_groupfd"))) { - fprintf(stderr, "[gm_lib] Failed to acquire symbol gm_delete_groupfd!\n"); + hal_symbol_load("gm_lib", aio_lib->handle, "gm_delete_groupfd"))) return EXIT_FAILURE; - } if (!(aio_lib->fnRefreshGroup = (int(*)(void *group)) - dlsym(aio_lib->handle, "gm_apply"))) { - fprintf(stderr, "[gm_lib] Failed to acquire symbol gm_apply!\n"); + hal_symbol_load("gm_lib", aio_lib->handle, "gm_apply"))) return EXIT_FAILURE; - } if (!(aio_lib->fnBind = (void*(*)(void *group, void *source, void *dest)) - dlsym(aio_lib->handle, "gm_bind"))) { - fprintf(stderr, "[gm_lib] Failed to acquire symbol gm_bind!\n"); + hal_symbol_load("gm_lib", aio_lib->handle, "gm_bind"))) return EXIT_FAILURE; - } if (!(aio_lib->fnUnbind = (int(*)(void *group)) - dlsym(aio_lib->handle, "gm_unbind"))) { - fprintf(stderr, "[gm_lib] Failed to acquire symbol gm_unbind!\n"); + hal_symbol_load("gm_lib", aio_lib->handle, "gm_unbind"))) return EXIT_FAILURE; - } if (!(aio_lib->fnPollStream = (int(*)(gm_venc_fds *fds, int count, int millis)) - dlsym(aio_lib->handle, "gm_poll"))) { - fprintf(stderr, "[gm_lib] Failed to acquire symbol gm_poll!\n"); + hal_symbol_load("gm_lib", aio_lib->handle, "gm_poll"))) return EXIT_FAILURE; - } if (!(aio_lib->fnReceiveStream = (int(*)(gm_venc_strm *strms, int count)) - dlsym(aio_lib->handle, "gm_recv_multi_bitstreams"))) { - fprintf(stderr, "[gm_lib] Failed to acquire symbol gm_recv_multi_bitstreams!\n"); + hal_symbol_load("gm_lib", aio_lib->handle, "gm_recv_multi_bitstreams"))) return EXIT_FAILURE; - } if (!(aio_lib->fnSnapshot = (int(*)(gm_venc_snap *snapshot, int millis)) - dlsym(aio_lib->handle, "gm_request_snapshot"))) { - fprintf(stderr, "[gm_lib] Failed to acquire symbol gm_request_snapshot!\n"); + hal_symbol_load("gm_lib", aio_lib->handle, "gm_request_snapshot"))) return EXIT_FAILURE; - } if (!(aio_lib->fnRequestIdr = (int(*)(void *device)) - dlsym(aio_lib->handle, "gm_request_keyframe"))) { - fprintf(stderr, "[gm_lib] Failed to acquire symbol gm_request_keyframe!\n"); + hal_symbol_load("gm_lib", aio_lib->handle, "gm_request_keyframe"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6_aud.h b/src/hal/star/i6_aud.h index 58bba2c..10854c8 100644 --- a/src/hal/star/i6_aud.h +++ b/src/hal/star/i6_aud.h @@ -123,82 +123,56 @@ typedef struct { } i6_aud_impl; static int i6_aud_load(i6_aud_impl *aud_lib) { - if (!(aud_lib->handle = dlopen("libmi_ai.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6_aud] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(aud_lib->handle = dlopen("libmi_ai.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6_aud", "Failed to load library!\nError: %s\n", dlerror()); if (!(aud_lib->fnDisableDevice = (int(*)(int device)) - dlsym(aud_lib->handle, "MI_AI_Disable"))) { - fprintf(stderr, "[i6_aud] Failed to acquire symbol MI_AI_Disable!\n"); + hal_symbol_load("i6_aud", aud_lib->handle, "MI_AI_Disable"))) return EXIT_FAILURE; - } if (!(aud_lib->fnEnableDevice = (int(*)(int device)) - dlsym(aud_lib->handle, "MI_AI_Enable"))) { - fprintf(stderr, "[i6_aud] Failed to acquire symbol MI_AI_Enable!\n"); + hal_symbol_load("i6_aud", aud_lib->handle, "MI_AI_Enable"))) return EXIT_FAILURE; - } if (!(aud_lib->fnSetDeviceConfig = (int(*)(int device, i6_aud_cnf *config)) - dlsym(aud_lib->handle, "MI_AI_SetPubAttr"))) { - fprintf(stderr, "[i6_aud] Failed to acquire symbol MI_AI_SetPubAttr!\n"); + hal_symbol_load("i6_aud", aud_lib->handle, "MI_AI_SetPubAttr"))) return EXIT_FAILURE; - } if (!(aud_lib->fnDisableChannel = (int(*)(int device, int channel)) - dlsym(aud_lib->handle, "MI_AI_DisableChn"))) { - fprintf(stderr, "[i6_aud] Failed to acquire symbol MI_AI_DisableChn!\n"); + hal_symbol_load("i6_aud", aud_lib->handle, "MI_AI_DisableChn"))) return EXIT_FAILURE; - } if (!(aud_lib->fnEnableChannel = (int(*)(int device, int channel)) - dlsym(aud_lib->handle, "MI_AI_EnableChn"))) { - fprintf(stderr, "[i6_aud] Failed to acquire symbol MI_AI_EnableChn!\n"); + hal_symbol_load("i6_aud", aud_lib->handle, "MI_AI_EnableChn"))) return EXIT_FAILURE; - } if (!(aud_lib->fnDisableEncoding = (int(*)(int device, int channel)) - dlsym(aud_lib->handle, "MI_AI_DisableAenc"))) { - fprintf(stderr, "[i6_aud] Failed to acquire symbol MI_AI_DisableAenc!\n"); + hal_symbol_load("i6_aud", aud_lib->handle, "MI_AI_DisableAenc"))) return EXIT_FAILURE; - } if (!(aud_lib->fnEnableEncoding = (int(*)(int device, int channel)) - dlsym(aud_lib->handle, "MI_AI_EnableAenc"))) { - fprintf(stderr, "[i6_aud] Failed to acquire symbol MI_AI_EnableAenc!\n"); + hal_symbol_load("i6_aud", aud_lib->handle, "MI_AI_EnableAenc"))) return EXIT_FAILURE; - } if (!(aud_lib->fnSetEncodingParam = (int(*)(int device, int channel, i6_aud_para *param)) - dlsym(aud_lib->handle, "MI_AI_SetAencAttr"))) { - fprintf(stderr, "[i6_aud] Failed to acquire symbol MI_AI_SetAencAttr!\n"); + hal_symbol_load("i6_aud", aud_lib->handle, "MI_AI_SetAencAttr"))) return EXIT_FAILURE; - } if (!(aud_lib->fnSetMute = (int(*)(int device, int channel, char active)) - dlsym(aud_lib->handle, "MI_AI_SetMute"))) { - fprintf(stderr, "[i6_aud] Failed to acquire symbol MI_AI_SetMute!\n"); + hal_symbol_load("i6_aud", aud_lib->handle, "MI_AI_SetMute"))) return EXIT_FAILURE; - } if (!(aud_lib->fnSetVolume = (int(*)(int device, int channel, int dbLevel)) - dlsym(aud_lib->handle, "MI_AI_SetVqeVolume"))) { - fprintf(stderr, "[i6_aud] Failed to acquire symbol MI_AI_SetVqeVolume!\n"); + hal_symbol_load("i6_aud", aud_lib->handle, "MI_AI_SetVqeVolume"))) return EXIT_FAILURE; - } if (!(aud_lib->fnFreeFrame = (int(*)(int device, int channel, i6_aud_frm *frame, i6_aud_efrm *encFrame)) - dlsym(aud_lib->handle, "MI_AI_ReleaseFrame"))) { - fprintf(stderr, "[i6_aud] Failed to acquire symbol MI_AI_ReleaseFrame!\n"); + hal_symbol_load("i6_aud", aud_lib->handle, "MI_AI_ReleaseFrame"))) return EXIT_FAILURE; - } if (!(aud_lib->fnGetFrame = (int(*)(int device, int channel, i6_aud_frm *frame, i6_aud_efrm *encFrame, int millis)) - dlsym(aud_lib->handle, "MI_AI_GetFrame"))) { - fprintf(stderr, "[i6_aud] Failed to acquire symbol MI_AI_GetFrame!\n"); + hal_symbol_load("i6_aud", aud_lib->handle, "MI_AI_GetFrame"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6_common.h b/src/hal/star/i6_common.h index f0441cb..e6847ba 100644 --- a/src/hal/star/i6_common.h +++ b/src/hal/star/i6_common.h @@ -6,16 +6,9 @@ #include #include +#include "../symbols.h" #include "../types.h" -#define I6_ERROR(x, ...) \ - do { \ - fprintf(stderr, "[i6_hal] \033[31m"); \ - fprintf(stderr, (x), ##__VA_ARGS__); \ - fprintf(stderr, "\033[0m"); \ - return EXIT_FAILURE; \ - } while (0) - typedef enum { I6_BAYER_RG, I6_BAYER_GR, diff --git a/src/hal/star/i6_hal.c b/src/hal/star/i6_hal.c index ec4c0e3..664b9e6 100644 --- a/src/hal/star/i6_hal.c +++ b/src/hal/star/i6_hal.c @@ -123,7 +123,7 @@ void *i6_audio_thread(void) while (keepRunning) { if (ret = i6_aud.fnGetFrame(_i6_aud_dev, _i6_aud_chn, &frame, NULL, 128)) { - fprintf(stderr, "[i6_aud] Getting the frame failed " + HAL_WARNING("i6_aud", "Getting the frame failed " "with %#x!\n", ret); continue; } @@ -140,11 +140,11 @@ void *i6_audio_thread(void) if (ret = i6_aud.fnFreeFrame(_i6_aud_dev, _i6_aud_chn, &frame, NULL)) { - fprintf(stderr, "[i6_aud] Releasing the frame failed" + HAL_WARNING("i6_aud", "Releasing the frame failed" " with %#x!\n", ret); } } - fprintf(stderr, "[i6_aud] Shutting down capture thread...\n"); + HAL_INFO("i6_aud", "Shutting down capture thread...\n"); } int i6_channel_bind(char index, char framerate) @@ -383,12 +383,12 @@ int i6_region_create(char handle, hal_rect rect, short opacity) region.size.height = rect.height; if (i6_rgn.fnGetRegionConfig(handle, ®ionCurr)) { - fprintf(stderr, "[i6_rgn] Creating region %d...\n", handle); + HAL_INFO("i6_rgn", "Creating region %d...\n", handle); if (ret = i6_rgn.fnCreateRegion(handle, ®ion)) return ret; } else if (regionCurr.size.height != region.size.height || regionCurr.size.width != region.size.width) { - fprintf(stderr, "[i6_rgn] Parameters are different, recreating " + HAL_INFO("i6_rgn", "Parameters are different, recreating " "region %d...\n", handle); for (char i = 0; i < I6_VENC_CHN_NUM; i++) { if (!i6_state[i].enable) continue; @@ -401,10 +401,10 @@ int i6_region_create(char handle, hal_rect rect, short opacity) } if (i6_rgn.fnGetChannelConfig(handle, &channel, &attribCurr)) - fprintf(stderr, "[i6_rgn] Attaching region %d...\n", handle); + HAL_INFO("i6_rgn", "Attaching region %d...\n", handle); else if (attribCurr.point.x != rect.x || attribCurr.point.x != rect.y || attribCurr.osd.bgFgAlpha[1] != opacity) { - fprintf(stderr, "[i6_rgn] Parameters are different, reattaching " + HAL_INFO("i6_rgn", "Parameters are different, reattaching " "region %d...\n", handle); for (char i = 0; i < I6_VENC_CHN_NUM; i++) { if (!i6_state[i].enable) continue; @@ -486,7 +486,7 @@ int i6_video_create(char index, hal_vidconfig *config) channel.rate.mjpgQp.quality = MAX(config->minQual, config->maxQual); break; default: - I6_ERROR("MJPEG encoder can only support CBR or fixed QP modes!"); + HAL_ERROR("i6_venc", "MJPEG encoder can only support CBR or fixed QP modes!"); } channel.attrib.mjpg.maxHeight = ALIGN_UP(config->height, 16); @@ -520,7 +520,7 @@ int i6_video_create(char index, hal_vidconfig *config) .fpsNum = config->framerate, .fpsDen = 1, .interQual = config->maxQual, .predQual = config->minQual }; break; case HAL_VIDMODE_ABR: - I6_ERROR("H.265 encoder does not support ABR mode!"); + HAL_ERROR("i6_venc", "H.265 encoder does not support ABR mode!"); case HAL_VIDMODE_AVBR: channel.rate.mode = I6_VENC_RATEMODE_H265AVBR; channel.rate.h265Avbr = (i6_venc_rate_h26xvbr){ .gop = config->gop, @@ -528,7 +528,7 @@ int i6_video_create(char index, hal_vidconfig *config) (unsigned int)(MAX(config->bitrate, config->maxBitrate)) << 10, .maxQual = config->maxQual, .minQual = config->minQual }; break; default: - I6_ERROR("H.265 encoder does not support this mode!"); + HAL_ERROR("i6_venc", "H.265 encoder does not support this mode!"); } } else if (config->codec == HAL_VIDCODEC_H264) { channel.attrib.codec = I6_VENC_CODEC_H264; @@ -563,9 +563,9 @@ int i6_video_create(char index, hal_vidconfig *config) (unsigned int)(MAX(config->bitrate, config->maxBitrate)) << 10, .maxQual = config->maxQual, .minQual = config->minQual }; break; default: - I6_ERROR("H.264 encoder does not support this mode!"); + HAL_ERROR("i6_venc", "H.264 encoder does not support this mode!"); } - } else I6_ERROR("This codec is not supported by the hardware!"); + } else HAL_ERROR("i6_venc", "This codec is not supported by the hardware!"); attrib->maxHeight = config->height; attrib->maxWidth = config->width; attrib->bufSize = config->height * config->width; @@ -640,7 +640,7 @@ int i6_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg) int ret; if (ret = i6_channel_bind(index, 1)) { - fprintf(stderr, "[i6_venc] Binding the encoder channel " + HAL_DANGER("i6_venc", "Binding the encoder channel " "%d failed with %#x!\n", index, ret); goto abort; } @@ -648,21 +648,21 @@ int i6_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg) i6_venc_jpg param; memset(¶m, 0, sizeof(param)); if (ret = i6_venc.fnGetJpegParam(index, ¶m)) { - fprintf(stderr, "[i6_venc] Reading the JPEG settings " + HAL_DANGER("i6_venc", "Reading the JPEG settings " "%d failed with %#x!\n", index, ret); goto abort; } param.quality = quality; if (ret = i6_venc.fnSetJpegParam(index, ¶m)) { - fprintf(stderr, "[i6_venc] Writing the JPEG settings " + HAL_DANGER("i6_venc", "Writing the JPEG settings " "%d failed with %#x!\n", index, ret); goto abort; } unsigned int count = 1; if (i6_venc.fnStartReceivingEx(index, &count)) { - fprintf(stderr, "[i6_venc] Requesting one frame " + HAL_DANGER("i6_venc", "Requesting one frame " "%d failed with %#x!\n", index, ret); goto abort; } @@ -675,23 +675,23 @@ int i6_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg) FD_SET(fd, &readFds); ret = select(fd + 1, &readFds, NULL, NULL, &timeout); if (ret < 0) { - fprintf(stderr, "[i6_venc] Select operation failed!\n"); + HAL_DANGER("i6_venc", "Select operation failed!\n"); goto abort; } else if (ret == 0) { - fprintf(stderr, "[i6_venc] Capture stream timed out!\n"); + HAL_DANGER("i6_venc", "Capture stream timed out!\n"); goto abort; } if (FD_ISSET(fd, &readFds)) { i6_venc_stat stat; if (i6_venc.fnQuery(index, &stat)) { - fprintf(stderr, "[i6_venc] Querying the encoder channel " + HAL_DANGER("i6_venc", "Querying the encoder channel " "%d failed with %#x!\n", index, ret); goto abort; } if (!stat.curPacks) { - fprintf(stderr, "[i6_venc] Current frame is empty, skipping it!\n"); + HAL_DANGER("i6_venc", "Current frame is empty, skipping it!\n"); goto abort; } @@ -699,13 +699,13 @@ int i6_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg) memset(&strm, 0, sizeof(strm)); strm.packet = (i6_venc_pack*)malloc(sizeof(i6_venc_pack) * stat.curPacks); if (!strm.packet) { - fprintf(stderr, "[i6_venc] Memory allocation on channel %d failed!\n", index); + HAL_DANGER("i6_venc", "Memory allocation on channel %d failed!\n", index); goto abort; } strm.count = stat.curPacks; if (ret = i6_venc.fnGetStream(index, &strm, stat.curPacks)) { - fprintf(stderr, "[i6_venc] Getting the stream on " + HAL_DANGER("i6_venc", "Getting the stream on " "channel %d failed with %#x!\n", index, ret); free(strm.packet); strm.packet = NULL; @@ -753,7 +753,7 @@ void *i6_video_thread(void) ret = i6_venc.fnGetDescriptor(i); if (ret < 0) { - fprintf(stderr, "[i6_venc] Getting the encoder descriptor failed with %#x!\n", ret); + HAL_DANGER("i6_venc", "Getting the encoder descriptor failed with %#x!\n", ret); return NULL; } i6_state[i].fileDesc = ret; @@ -779,10 +779,10 @@ void *i6_video_thread(void) timeout.tv_usec = 0; ret = select(maxFd + 1, &readFds, NULL, NULL, &timeout); if (ret < 0) { - fprintf(stderr, "[i6_venc] Select operation failed!\n"); + HAL_DANGER("i6_venc", "Select operation failed!\n"); break; } else if (ret == 0) { - fprintf(stderr, "[i6_venc] Main stream loop timed out!\n"); + HAL_WARNING("i6_venc", "Main stream loop timed out!\n"); continue; } else { for (int i = 0; i < I6_VENC_CHN_NUM; i++) { @@ -792,26 +792,26 @@ void *i6_video_thread(void) memset(&stream, 0, sizeof(stream)); if (ret = i6_venc.fnQuery(i, &stat)) { - fprintf(stderr, "[i6_venc] Querying the encoder channel " + HAL_DANGER("i6_venc", "Querying the encoder channel " "%d failed with %#x!\n", i, ret); break; } if (!stat.curPacks) { - fprintf(stderr, "[i6_venc] Current frame is empty, skipping it!\n"); + HAL_WARNING("i6_venc", "Current frame is empty, skipping it!\n"); continue; } stream.packet = (i6_venc_pack*)malloc( sizeof(i6_venc_pack) * stat.curPacks); if (!stream.packet) { - fprintf(stderr, "[i6_venc] Memory allocation on channel %d failed!\n", i); + HAL_DANGER("i6_venc", "Memory allocation on channel %d failed!\n", i); break; } stream.count = stat.curPacks; if (ret = i6_venc.fnGetStream(i, &stream, 40)) { - fprintf(stderr, "[i6_venc] Getting the stream on " + HAL_DANGER("i6_venc", "Getting the stream on " "channel %d failed with %#x!\n", i, ret); break; } @@ -856,7 +856,7 @@ void *i6_video_thread(void) } if (ret = i6_venc.fnFreeStream(i, &stream)) { - fprintf(stderr, "[i6_venc] Releasing the stream on " + HAL_DANGER("i6_venc", "Releasing the stream on " "channel %d failed with %#x!\n", i, ret); } free(stream.packet); @@ -865,7 +865,7 @@ void *i6_video_thread(void) } } } - fprintf(stderr, "[i6_venc] Shutting down encoding thread...\n"); + HAL_INFO("i6_venc", "Shutting down encoding thread...\n"); } void i6_system_deinit(void) diff --git a/src/hal/star/i6_isp.h b/src/hal/star/i6_isp.h index 6ca2c11..6f58d12 100644 --- a/src/hal/star/i6_isp.h +++ b/src/hal/star/i6_isp.h @@ -10,32 +10,22 @@ typedef struct { } i6_isp_impl; static int i6_isp_load(i6_isp_impl *isp_lib) { - if (!(isp_lib->handleIspAlgo = dlopen("libispalgo.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6_isp] Failed to load dependency library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(isp_lib->handleIspAlgo = dlopen("libispalgo.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6_isp", "Failed to load dependency library!\nError: %s\n", dlerror()); - if (!(isp_lib->handleCus3a = dlopen("libcus3a.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6_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))) { - fprintf(stderr, "[i6_isp] Failed to load library!\nError: %s\n", dlerror()); + if (!(isp_lib->handle = dlopen("libmi_isp.so", RTLD_LAZY | RTLD_GLOBAL))) return EXIT_FAILURE; - } if (!(isp_lib->fnLoadChannelConfig = (int(*)(int channel, char *path, unsigned int key)) - dlsym(isp_lib->handle, "MI_ISP_API_CmdLoadBinFile"))) { - fprintf(stderr, "[i6_isp] Failed to acquire symbol MI_ISP_API_CmdLoadBinFile!\nError: %s\n", dlerror()); + hal_symbol_load("i6_isp", isp_lib->handle, "MI_ISP_API_CmdLoadBinFile"))) return EXIT_FAILURE; - } if (!(isp_lib->fnSetColorToGray = (int(*)(int channel, char *enable)) - dlsym(isp_lib->handle, "MI_ISP_IQ_SetColorToGray"))) { - fprintf(stderr, "[i6_isp] Failed to acquire symbol MI_ISP_IQ_SetColorToGray!\n"); + hal_symbol_load("i6_isp", isp_lib->handle, "MI_ISP_IQ_SetColorToGray"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6_rgn.h b/src/hal/star/i6_rgn.h index 299b314..fbd3ada 100644 --- a/src/hal/star/i6_rgn.h +++ b/src/hal/star/i6_rgn.h @@ -105,70 +105,48 @@ typedef struct { } i6_rgn_impl; static int i6_rgn_load(i6_rgn_impl *rgn_lib) { - if (!(rgn_lib->handle = dlopen("libmi_rgn.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6_rgn] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(rgn_lib->handle = dlopen("libmi_rgn.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6_rgn", "Failed to load library!\nError: %s\n", dlerror()); if (!(rgn_lib->fnDeinit = (int(*)(void)) - dlsym(rgn_lib->handle, "MI_RGN_DeInit"))) { - fprintf(stderr, "[i6_rgn] Failed to acquire symbol MI_RGN_DeInit!\n"); + hal_symbol_load("i6_rgn", rgn_lib->handle, "MI_RGN_DeInit"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnInit = (int(*)(i6_rgn_pal *palette)) - dlsym(rgn_lib->handle, "MI_RGN_Init"))) { - fprintf(stderr, "[i6_rgn] Failed to acquire symbol MI_RGN_Init!\n"); + hal_symbol_load("i6_rgn", rgn_lib->handle, "MI_RGN_Init"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnCreateRegion = (int(*)(unsigned int handle, i6_rgn_cnf *config)) - dlsym(rgn_lib->handle, "MI_RGN_Create"))) { - fprintf(stderr, "[i6_rgn] Failed to acquire symbol MI_RGN_Create!\n"); + hal_symbol_load("i6_rgn", rgn_lib->handle, "MI_RGN_Create"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnDestroyRegion = (int(*)(unsigned int handle)) - dlsym(rgn_lib->handle, "MI_RGN_Destroy"))) { - fprintf(stderr, "[i6_rgn] Failed to acquire symbol MI_RGN_Destroy!\n"); + hal_symbol_load("i6_rgn", rgn_lib->handle, "MI_RGN_Destroy"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnGetRegionConfig = (int(*)(unsigned int handle, i6_rgn_cnf *config)) - dlsym(rgn_lib->handle, "MI_RGN_GetAttr"))) { - fprintf(stderr, "[i6_rgn] Failed to acquire symbol MI_RGN_GetAttr!\n"); + hal_symbol_load("i6_rgn", rgn_lib->handle, "MI_RGN_GetAttr"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnAttachChannel = (int(*)(unsigned int handle, i6_sys_bind *dest, i6_rgn_chn *config)) - dlsym(rgn_lib->handle, "MI_RGN_AttachToChn"))) { - fprintf(stderr, "[i6_rgn] Failed to acquire symbol MI_RGN_AttachToChn!\n"); + hal_symbol_load("i6_rgn", rgn_lib->handle, "MI_RGN_AttachToChn"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnDetachChannel = (int(*)(unsigned int handle, i6_sys_bind *dest)) - dlsym(rgn_lib->handle, "MI_RGN_DetachFromChn"))) { - fprintf(stderr, "[i6_rgn] Failed to acquire symbol MI_RGN_DetachFromChn!\n"); + hal_symbol_load("i6_rgn", rgn_lib->handle, "MI_RGN_DetachFromChn"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnGetChannelConfig = (int(*)(unsigned int handle, i6_sys_bind *dest, i6_rgn_chn *config)) - dlsym(rgn_lib->handle, "MI_RGN_GetDisplayAttr"))) { - fprintf(stderr, "[i6_rgn] Failed to acquire symbol MI_RGN_GetDisplayAttr!\n"); + hal_symbol_load("i6_rgn", rgn_lib->handle, "MI_RGN_GetDisplayAttr"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnSetChannelConfig = (int(*)(unsigned int handle, i6_sys_bind *dest, i6_rgn_chn *config)) - dlsym(rgn_lib->handle, "MI_RGN_SetDisplayAttr"))) { - fprintf(stderr, "[i6_rgn] Failed to acquire symbol MI_RGN_SetDisplayAttr!\n"); + hal_symbol_load("i6_rgn", rgn_lib->handle, "MI_RGN_SetDisplayAttr"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnSetBitmap = (int(*)(unsigned int handle, i6_rgn_bmp *bitmap)) - dlsym(rgn_lib->handle, "MI_RGN_SetBitMap"))) { - fprintf(stderr, "[i6_rgn] Failed to acquire symbol MI_RGN_SetBitMap!\n"); + hal_symbol_load("i6_rgn", rgn_lib->handle, "MI_RGN_SetBitMap"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6_snr.h b/src/hal/star/i6_snr.h index b762263..a53b603 100644 --- a/src/hal/star/i6_snr.h +++ b/src/hal/star/i6_snr.h @@ -90,70 +90,48 @@ typedef struct { } i6_snr_impl; static int i6_snr_load(i6_snr_impl *snr_lib) { - if (!(snr_lib->handle = dlopen("libmi_sensor.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6_snr] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(snr_lib->handle = dlopen("libmi_sensor.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6_snr", "Failed to load library!\nError: %s\n", dlerror()); if (!(snr_lib->fnDisable = (int(*)(unsigned int sensor)) - dlsym(snr_lib->handle, "MI_SNR_Disable"))) { - fprintf(stderr, "[i6_snr] Failed to acquire symbol MI_SNR_Disable!\n"); + hal_symbol_load("i6_snr", snr_lib->handle, "MI_SNR_Disable"))) return EXIT_FAILURE; - } if (!(snr_lib->fnEnable = (int(*)(unsigned int sensor)) - dlsym(snr_lib->handle, "MI_SNR_Enable"))) { - fprintf(stderr, "[i6_snr] Failed to acquire symbol MI_SNR_Enable!\n"); + hal_symbol_load("i6_snr", snr_lib->handle, "MI_SNR_Enable"))) return EXIT_FAILURE; - } if (!(snr_lib->fnSetFramerate = (int(*)(unsigned int sensor, unsigned int framerate)) - dlsym(snr_lib->handle, "MI_SNR_SetFps"))) { - fprintf(stderr, "[i6_snr] Failed to acquire symbol MI_SNR_SetFps!\n"); + hal_symbol_load("i6_snr", snr_lib->handle, "MI_SNR_SetFps"))) return EXIT_FAILURE; - } if (!(snr_lib->fnGetPadInfo = (int(*)(unsigned int sensor, i6_snr_pad *info)) - dlsym(snr_lib->handle, "MI_SNR_GetPadInfo"))) { - fprintf(stderr, "[i6_snr] Failed to acquire symbol MI_SNR_GetPadInfo!\n"); + hal_symbol_load("i6_snr", snr_lib->handle, "MI_SNR_GetPadInfo"))) return EXIT_FAILURE; - } if (!(snr_lib->fnGetPlaneInfo = (int(*)(unsigned int sensor, unsigned int index, i6_snr_plane *info)) - dlsym(snr_lib->handle, "MI_SNR_GetPlaneInfo"))) { - fprintf(stderr, "[i6_snr] Failed to acquire symbol MI_SNR_GetPlaneInfo!\n"); + hal_symbol_load("i6_snr", snr_lib->handle, "MI_SNR_GetPlaneInfo"))) return EXIT_FAILURE; - } if (!(snr_lib->fnSetPlaneMode = (int(*)(unsigned int sensor, unsigned char active)) - dlsym(snr_lib->handle, "MI_SNR_SetPlaneMode"))) { - fprintf(stderr, "[i6_snr] Failed to acquire symbol MI_SNR_SetPlaneMode!\n"); + hal_symbol_load("i6_snr", snr_lib->handle, "MI_SNR_SetPlaneMode"))) return EXIT_FAILURE; - } if (!(snr_lib->fnCurrentResolution = (int(*)(unsigned int sensor, unsigned char *index, i6_snr_res *resolution)) - dlsym(snr_lib->handle, "MI_SNR_GetCurRes"))) { - fprintf(stderr, "[i6_snr] Failed to acquire symbol MI_SNR_GetCurRes!\n"); + hal_symbol_load("i6_snr", snr_lib->handle, "MI_SNR_GetCurRes"))) return EXIT_FAILURE; - } if (!(snr_lib->fnGetResolution = (int(*)(unsigned int sensor, unsigned char index, i6_snr_res *resolution)) - dlsym(snr_lib->handle, "MI_SNR_GetRes"))) { - fprintf(stderr, "[i6_snr] Failed to acquire symbol MI_SNR_GetRes!\n"); + hal_symbol_load("i6_snr", snr_lib->handle, "MI_SNR_GetRes"))) return EXIT_FAILURE; - } if (!(snr_lib->fnGetResolutionCount = (int(*)(unsigned int sensor, unsigned int *count)) - dlsym(snr_lib->handle, "MI_SNR_QueryResCount"))) { - fprintf(stderr, "[i6_snr] Failed to acquire symbol MI_SNR_QueryResCount!\n"); + hal_symbol_load("i6_snr", snr_lib->handle, "MI_SNR_QueryResCount"))) return EXIT_FAILURE; - } if (!(snr_lib->fnSetResolution = (int(*)(unsigned int sensor, unsigned char index)) - dlsym(snr_lib->handle, "MI_SNR_SetRes"))) { - fprintf(stderr, "[i6_snr] Failed to acquire symbol MI_SNR_SetRes!\n"); + hal_symbol_load("i6_snr", snr_lib->handle, "MI_SNR_SetRes"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6_sys.h b/src/hal/star/i6_sys.h index 9944386..f90718a 100644 --- a/src/hal/star/i6_sys.h +++ b/src/hal/star/i6_sys.h @@ -84,59 +84,41 @@ typedef struct { } i6_sys_impl; static int i6_sys_load(i6_sys_impl *sys_lib) { - if (!(sys_lib->handleCamOsWrapper = dlopen("libcam_os_wrapper.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6_sys] Failed to load dependency library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(sys_lib->handleCamOsWrapper = dlopen("libcam_os_wrapper.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6_sys", "Failed to load dependency library!\nError: %s\n", dlerror()); - if (!(sys_lib->handle = dlopen("libmi_sys.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6_sys] Failed to load library!\nError: %s\n", dlerror()); + if (!(sys_lib->handle = dlopen("libmi_sys.so", RTLD_LAZY | RTLD_GLOBAL))) return EXIT_FAILURE; - } if (!(sys_lib->fnExit = (int(*)(void)) - dlsym(sys_lib->handle, "MI_SYS_Exit"))) { - fprintf(stderr, "[i6_sys] Failed to acquire symbol MI_SYS_Exit!\n"); + hal_symbol_load("i6_sys", sys_lib->handle, "MI_SYS_Exit"))) return EXIT_FAILURE; - } if (!(sys_lib->fnGetVersion = (int(*)(i6_sys_ver *version)) - dlsym(sys_lib->handle, "MI_SYS_GetVersion"))) { - fprintf(stderr, "[i6_sys] Failed to acquire symbol MI_SYS_GetVersion!\n"); + hal_symbol_load("i6_sys", sys_lib->handle, "MI_SYS_GetVersion"))) return EXIT_FAILURE; - } if (!(sys_lib->fnInit = (int(*)(void)) - dlsym(sys_lib->handle, "MI_SYS_Init"))) { - fprintf(stderr, "[i6_sys] Failed to acquire symbol MI_SYS_Init!\n"); + hal_symbol_load("i6_sys", sys_lib->handle, "MI_SYS_Init"))) return EXIT_FAILURE; - } if (!(sys_lib->fnBind = (int(*)(i6_sys_bind *source, i6_sys_bind *dest, unsigned int srcFps, unsigned int dstFps)) - dlsym(sys_lib->handle, "MI_SYS_BindChnPort"))) { - fprintf(stderr, "[i6_sys] Failed to acquire symbol MI_SYS_BindChnPort!\n"); + hal_symbol_load("i6_sys", sys_lib->handle, "MI_SYS_BindChnPort"))) return EXIT_FAILURE; - } if (!(sys_lib->fnBindExt = (int(*)(i6_sys_bind *source, i6_sys_bind *dest, unsigned int srcFps, unsigned int dstFps, i6_sys_link link, unsigned int linkParam)) - dlsym(sys_lib->handle, "MI_SYS_BindChnPort2"))) { - fprintf(stderr, "[i6_sys] Failed to acquire symbol MI_SYS_BindChnPort2!\n"); + hal_symbol_load("i6_sys", sys_lib->handle, "MI_SYS_BindChnPort2"))) return EXIT_FAILURE; - } if (!(sys_lib->fnSetOutputDepth = (int(*)(i6_sys_bind *bind, unsigned int usrDepth, unsigned int bufDepth)) - dlsym(sys_lib->handle, "MI_SYS_SetChnOutputPortDepth"))) { - fprintf(stderr, "[i6_sys] Failed to acquire symbol MI_SYS_SetChnOutputPortDepth!\n"); + hal_symbol_load("i6_sys", sys_lib->handle, "MI_SYS_SetChnOutputPortDepth"))) return EXIT_FAILURE; - } if (!(sys_lib->fnUnbind = (int(*)(i6_sys_bind *source, i6_sys_bind *dest)) - dlsym(sys_lib->handle, "MI_SYS_UnBindChnPort"))) { - fprintf(stderr, "[i6_sys] Failed to acquire symbol MI_SYS_UnBindChnPort!\n"); + hal_symbol_load("i6_sys", sys_lib->handle, "MI_SYS_UnBindChnPort"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6_venc.h b/src/hal/star/i6_venc.h index 0a92f9a..3634782 100644 --- a/src/hal/star/i6_venc.h +++ b/src/hal/star/i6_venc.h @@ -290,118 +290,80 @@ typedef struct { } i6_venc_impl; static int i6_venc_load(i6_venc_impl *venc_lib) { - if (!(venc_lib->handle = dlopen("libmi_venc.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6_venc] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(venc_lib->handle = dlopen("libmi_venc.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6_venc", "Failed to load library!\nError: %s\n", dlerror()); if (!(venc_lib->fnCreateChannel = (int(*)(int channel, i6_venc_chn *config)) - dlsym(venc_lib->handle, "MI_VENC_CreateChn"))) { - fprintf(stderr, "[i6_venc] Failed to acquire symbol MI_VENC_CreateChn!\n"); + hal_symbol_load("i6_venc", venc_lib->handle, "MI_VENC_CreateChn"))) return EXIT_FAILURE; - } if (!(venc_lib->fnDestroyChannel = (int(*)(int channel)) - dlsym(venc_lib->handle, "MI_VENC_DestroyChn"))) { - fprintf(stderr, "[i6_venc] Failed to acquire symbol MI_VENC_DestroyChn!\n"); + hal_symbol_load("i6_venc", venc_lib->handle, "MI_VENC_DestroyChn"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetChannelConfig = (int(*)(int channel, i6_venc_chn *config)) - dlsym(venc_lib->handle, "MI_VENC_GetChnAttr"))) { - fprintf(stderr, "[i6_venc] Failed to acquire symbol MI_VENC_GetChnAttr!\n"); + hal_symbol_load("i6_venc", venc_lib->handle, "MI_VENC_GetChnAttr"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetChannelDeviceId = (int(*)(int channel, unsigned int *device)) - dlsym(venc_lib->handle, "MI_VENC_GetChnDevid"))) { - fprintf(stderr, "[i6_venc] Failed to acquire symbol MI_VENC_GetChnDevid!\n"); + hal_symbol_load("i6_venc", venc_lib->handle, "MI_VENC_GetChnDevid"))) return EXIT_FAILURE; - } if (!(venc_lib->fnResetChannel = (int(*)(int channel)) - dlsym(venc_lib->handle, "MI_VENC_ResetChn"))) { - fprintf(stderr, "[i6_venc] Failed to acquire symbol MI_VENC_ResetChn!\n"); + hal_symbol_load("i6_venc", venc_lib->handle, "MI_VENC_ResetChn"))) return EXIT_FAILURE; - } if (!(venc_lib->fnSetChannelConfig = (int(*)(int channel, i6_venc_chn *config)) - dlsym(venc_lib->handle, "MI_VENC_SetChnAttr"))) { - fprintf(stderr, "[i6_venc] Failed to acquire symbol MI_VENC_SetChnAttr!\n"); + hal_symbol_load("i6_venc", venc_lib->handle, "MI_VENC_SetChnAttr"))) return EXIT_FAILURE; - } if (!(venc_lib->fnFreeDescriptor = (int(*)(int channel)) - dlsym(venc_lib->handle, "MI_VENC_CloseFd"))) { - fprintf(stderr, "[i6_venc] Failed to acquire symbol MI_VENC_CloseFd!\n"); + hal_symbol_load("i6_venc", venc_lib->handle, "MI_VENC_CloseFd"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetDescriptor = (int(*)(int channel)) - dlsym(venc_lib->handle, "MI_VENC_GetFd"))) { - fprintf(stderr, "[i6_venc] Failed to acquire symbol MI_VENC_GetFd!\n"); + hal_symbol_load("i6_venc", venc_lib->handle, "MI_VENC_GetFd"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetJpegParam = (int(*)(int channel, i6_venc_jpg *param)) - dlsym(venc_lib->handle, "MI_VENC_GetJpegParam"))) { - fprintf(stderr, "[i6_venc] Failed to acquire symbol MI_VENC_CloseFd!\n"); + hal_symbol_load("i6_venc", venc_lib->handle, "MI_VENC_GetJpegParam"))) return EXIT_FAILURE; - } if (!(venc_lib->fnSetJpegParam = (int(*)(int channel, i6_venc_jpg *param)) - dlsym(venc_lib->handle, "MI_VENC_SetJpegParam"))) { - fprintf(stderr, "[i6_venc] Failed to acquire symbol MI_VENC_GetFd!\n"); + hal_symbol_load("i6_venc", venc_lib->handle, "MI_VENC_SetJpegParam"))) return EXIT_FAILURE; - } if (!(venc_lib->fnFreeStream = (int(*)(int channel, i6_venc_strm *stream)) - dlsym(venc_lib->handle, "MI_VENC_ReleaseStream"))) { - fprintf(stderr, "[i6_venc] Failed to acquire symbol MI_VENC_ReleaseStream!\n"); + hal_symbol_load("i6_venc", venc_lib->handle, "MI_VENC_ReleaseStream"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetStream = (int(*)(int channel, i6_venc_strm *stream, unsigned int timeout)) - dlsym(venc_lib->handle, "MI_VENC_GetStream"))) { - fprintf(stderr, "[i6_venc] Failed to acquire symbol MI_VENC_GetStream!\n"); + hal_symbol_load("i6_venc", venc_lib->handle, "MI_VENC_GetStream"))) return EXIT_FAILURE; - } if (!(venc_lib->fnQuery = (int(*)(int channel, i6_venc_stat *stats)) - dlsym(venc_lib->handle, "MI_VENC_Query"))) { - fprintf(stderr, "[i6_venc] Failed to acquire symbol MI_VENC_Query!\n"); + hal_symbol_load("i6_venc", venc_lib->handle, "MI_VENC_Query"))) return EXIT_FAILURE; - } if (!(venc_lib->fnSetSourceConfig = (int(*)(int channel, i6_venc_src_conf *config)) - dlsym(venc_lib->handle, "MI_VENC_SetInputSourceConfig"))) { - fprintf(stderr, "[i6_venc] Failed to acquire symbol MI_VENC_SetInputSourceConfig!\n"); + hal_symbol_load("i6_venc", venc_lib->handle, "MI_VENC_SetInputSourceConfig"))) return EXIT_FAILURE; - } if (!(venc_lib->fnRequestIdr = (int(*)(int channel, char instant)) - dlsym(venc_lib->handle, "MI_VENC_RequestIdr"))) { - fprintf(stderr, "[i6_venc] Failed to acquire symbol MI_VENC_RequestIdr!\n"); + hal_symbol_load("i6_venc", venc_lib->handle, "MI_VENC_RequestIdr"))) return EXIT_FAILURE; - } if (!(venc_lib->fnStartReceiving = (int(*)(int channel)) - dlsym(venc_lib->handle, "MI_VENC_StartRecvPic"))) { - fprintf(stderr, "[i6_venc] Failed to acquire symbol MI_VENC_StartRecvPic!\n"); + hal_symbol_load("i6_venc", venc_lib->handle, "MI_VENC_StartRecvPic"))) return EXIT_FAILURE; - } if (!(venc_lib->fnStartReceivingEx = (int(*)(int channel, int *count)) - dlsym(venc_lib->handle, "MI_VENC_StartRecvPicEx"))) { - fprintf(stderr, "[i6_venc] Failed to acquire symbol MI_VENC_StartRecvPicEx!\n"); + hal_symbol_load("i6_venc", venc_lib->handle, "MI_VENC_StartRecvPicEx"))) return EXIT_FAILURE; - } if (!(venc_lib->fnStopReceiving = (int(*)(int channel)) - dlsym(venc_lib->handle, "MI_VENC_StopRecvPic"))) { - fprintf(stderr, "[i6_venc] Failed to acquire symbol MI_VENC_StopRecvPic!\n"); + hal_symbol_load("i6_venc", venc_lib->handle, "MI_VENC_StopRecvPic"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6_vif.h b/src/hal/star/i6_vif.h index 4eedf74..c2ab867 100644 --- a/src/hal/star/i6_vif.h +++ b/src/hal/star/i6_vif.h @@ -54,46 +54,32 @@ typedef struct { } i6_vif_impl; static int i6_vif_load(i6_vif_impl *vif_lib) { - if (!(vif_lib->handle = dlopen("libmi_vif.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6_vif] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(vif_lib->handle = dlopen("libmi_vif.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6_vif", "Failed to load library!\nError: %s\n", dlerror()); if (!(vif_lib->fnDisableDevice = (int(*)(int device)) - dlsym(vif_lib->handle, "MI_VIF_DisableDev"))) { - fprintf(stderr, "[i6_vif] Failed to acquire symbol MI_VIF_DisableDev!\n"); + hal_symbol_load("i6_vif", vif_lib->handle, "MI_VIF_DisableDev"))) return EXIT_FAILURE; - } if (!(vif_lib->fnEnableDevice = (int(*)(int device)) - dlsym(vif_lib->handle, "MI_VIF_EnableDev"))) { - fprintf(stderr, "[i6_vif] Failed to acquire symbol MI_VIF_EnableDev!\n"); + hal_symbol_load("i6_vif", vif_lib->handle, "MI_VIF_EnableDev"))) return EXIT_FAILURE; - } if (!(vif_lib->fnSetDeviceConfig = (int(*)(int device, i6_vif_dev *config)) - dlsym(vif_lib->handle, "MI_VIF_SetDevAttr"))) { - fprintf(stderr, "[i6_vif] Failed to acquire symbol MI_VIF_SetDevAttr!\n"); + hal_symbol_load("i6_vif", vif_lib->handle, "MI_VIF_SetDevAttr"))) return EXIT_FAILURE; - } if (!(vif_lib->fnDisablePort = (int(*)(int channel, int port)) - dlsym(vif_lib->handle, "MI_VIF_DisableChnPort"))) { - fprintf(stderr, "[i6_vif] Failed to acquire symbol MI_VIF_DisableChnPort!\n"); + hal_symbol_load("i6_vif", vif_lib->handle, "MI_VIF_DisableChnPort"))) return EXIT_FAILURE; - } if (!(vif_lib->fnEnablePort = (int(*)(int channel, int port)) - dlsym(vif_lib->handle, "MI_VIF_EnableChnPort"))) { - fprintf(stderr, "[i6_vif] Failed to acquire symbol MI_VIF_EnableChnPort!\n"); + hal_symbol_load("i6_vif", vif_lib->handle, "MI_VIF_EnableChnPort"))) return EXIT_FAILURE; - } if (!(vif_lib->fnSetPortConfig = (int(*)(int channel, int port, i6_vif_port *config)) - dlsym(vif_lib->handle, "MI_VIF_SetChnPortAttr"))) { - fprintf(stderr, "[i6_vif] Failed to acquire symbol MI_VIF_SetChnPortAttr!\n"); + hal_symbol_load("i6_vif", vif_lib->handle, "MI_VIF_SetChnPortAttr"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6_vpe.h b/src/hal/star/i6_vpe.h index ca51c4f..70e0fdb 100644 --- a/src/hal/star/i6_vpe.h +++ b/src/hal/star/i6_vpe.h @@ -123,64 +123,44 @@ typedef struct { } i6_vpe_impl; static int i6_vpe_load(i6_vpe_impl *vpe_lib) { - if (!(vpe_lib->handle = dlopen("libmi_vpe.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6_vpe] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(vpe_lib->handle = dlopen("libmi_vpe.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6_vpe", "Failed to load library!\nError: %s\n", dlerror()); if (!(vpe_lib->fnCreateChannel = (int(*)(int channel, i6_vpe_chn *config)) - dlsym(vpe_lib->handle, "MI_VPE_CreateChannel"))) { - fprintf(stderr, "[i6_vpe] Failed to acquire symbol MI_VPE_CreateChannel!\n"); + hal_symbol_load("i6_vpe", vpe_lib->handle, "MI_VPE_CreateChannel"))) return EXIT_FAILURE; - } if (!(vpe_lib->fnDestroyChannel = (int(*)(int channel)) - dlsym(vpe_lib->handle, "MI_VPE_DestroyChannel"))) { - fprintf(stderr, "[i6_vpe] Failed to acquire symbol MI_VPE_DestroyChannel!\n"); + hal_symbol_load("i6_vpe", vpe_lib->handle, "MI_VPE_DestroyChannel"))) return EXIT_FAILURE; - } if (!(vpe_lib->fnSetChannelConfig = (int(*)(int channel, i6_vpe_chn *config)) - dlsym(vpe_lib->handle, "MI_VPE_SetChannelAttr"))) { - fprintf(stderr, "[i6_vpe] Failed to acquire symbol MI_VPE_SetChannelAttr!\n"); + hal_symbol_load("i6_vpe", vpe_lib->handle, "MI_VPE_SetChannelAttr"))) return EXIT_FAILURE; - } if (!(vpe_lib->fnSetChannelParam = (int(*)(int channel, i6_vpe_para *config)) - dlsym(vpe_lib->handle, "MI_VPE_SetChannelParam"))) { - fprintf(stderr, "[i6_vpe] Failed to acquire symbol MI_VPE_SetChannelParam!\n"); + hal_symbol_load("i6_vpe", vpe_lib->handle, "MI_VPE_SetChannelParam"))) return EXIT_FAILURE; - } if (!(vpe_lib->fnStartChannel = (int(*)(int channel)) - dlsym(vpe_lib->handle, "MI_VPE_StartChannel"))) { - fprintf(stderr, "[i6_vpe] Failed to acquire symbol MI_VPE_StartChannel!\n"); + hal_symbol_load("i6_vpe", vpe_lib->handle, "MI_VPE_StartChannel"))) return EXIT_FAILURE; - } if (!(vpe_lib->fnStopChannel = (int(*)(int channel)) - dlsym(vpe_lib->handle, "MI_VPE_StopChannel"))) { - fprintf(stderr, "[i6_vpe] Failed to acquire symbol MI_VPE_StopChannel!\n"); + hal_symbol_load("i6_vpe", vpe_lib->handle, "MI_VPE_StopChannel"))) return EXIT_FAILURE; - } if (!(vpe_lib->fnDisablePort = (int(*)(int channel, int port)) - dlsym(vpe_lib->handle, "MI_VPE_DisablePort"))) { - fprintf(stderr, "[i6_vpe] Failed to acquire symbol MI_VPE_DisablePort!\n"); + hal_symbol_load("i6_vpe", vpe_lib->handle, "MI_VPE_DisablePort"))) return EXIT_FAILURE; - } if (!(vpe_lib->fnEnablePort = (int(*)(int channel, int port)) - dlsym(vpe_lib->handle, "MI_VPE_EnablePort"))) { - fprintf(stderr, "[i6_vpe] Failed to acquire symbol MI_VPE_EnablePort!\n"); + hal_symbol_load("i6_vpe", vpe_lib->handle, "MI_VPE_EnablePort"))) return EXIT_FAILURE; - } if (!(vpe_lib->fnSetPortConfig = (int(*)(int channel, int port, i6_vpe_port *config)) - dlsym(vpe_lib->handle, "MI_VPE_SetPortMode"))) { - fprintf(stderr, "[i6_vpe] Failed to acquire symbol MI_VPE_SetPortMode!\n"); + hal_symbol_load("i6_vpe", vpe_lib->handle, "MI_VPE_SetPortMode"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6c_aud.h b/src/hal/star/i6c_aud.h index 9ad584e..4de3851 100644 --- a/src/hal/star/i6c_aud.h +++ b/src/hal/star/i6c_aud.h @@ -144,76 +144,52 @@ typedef struct { } i6c_aud_impl; static int i6c_aud_load(i6c_aud_impl *aud_lib) { - if (!(aud_lib->handle = dlopen("libmi_ai.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6c_aud] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(aud_lib->handle = dlopen("libmi_ai.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6c_aud", "Failed to load library!\nError: %s\n", dlerror()); if (!(aud_lib->fnAttachToDevice = (int(*)(int device, i6c_aud_input inputs[], unsigned char inputSize)) - dlsym(aud_lib->handle, "MI_AI_AttachIf"))) { - fprintf(stderr, "[i6c_aud] Failed to acquire symbol MI_AI_AttachIf!\n"); + hal_symbol_load("i6c_aud", aud_lib->handle, "MI_AI_AttachIf"))) return EXIT_FAILURE; - } if (!(aud_lib->fnDisableDevice = (int(*)(int device)) - dlsym(aud_lib->handle, "MI_AI_Close"))) { - fprintf(stderr, "[i6c_aud] Failed to acquire symbol MI_AI_Close!\n"); + hal_symbol_load("i6c_aud", aud_lib->handle, "MI_AI_Close"))) return EXIT_FAILURE; - } if (!(aud_lib->fnEnableDevice = (int(*)(int device, i6c_aud_cnf *config)) - dlsym(aud_lib->handle, "MI_AI_Open"))) { - fprintf(stderr, "[i6c_aud] Failed to acquire symbol MI_AI_Open!\n"); + hal_symbol_load("i6c_aud", aud_lib->handle, "MI_AI_Open"))) return EXIT_FAILURE; - } if (!(aud_lib->fnDisableGroup = (int(*)(int device, unsigned char group)) - dlsym(aud_lib->handle, "MI_AI_DisableChnGroup"))) { - fprintf(stderr, "[i6c_aud] Failed to acquire symbol MI_AI_DisableChnGroup!\n"); + hal_symbol_load("i6c_aud", aud_lib->handle, "MI_AI_DisableChnGroup"))) return EXIT_FAILURE; - } if (!(aud_lib->fnEnableGroup = (int(*)(int device, unsigned char group)) - dlsym(aud_lib->handle, "MI_AI_EnableChnGroup"))) { - fprintf(stderr, "[i6c_aud] Failed to acquire symbol MI_AI_EnableChnGroup!\n"); + hal_symbol_load("i6c_aud", aud_lib->handle, "MI_AI_EnableChnGroup"))) return EXIT_FAILURE; - } if (!(aud_lib->fnSetI2SConfig = (int(*)(i6c_aud_input input, i6c_aud_i2s *config)) - dlsym(aud_lib->handle, "MI_AI_SetI2SConfig"))) { - fprintf(stderr, "[i6c_aud] Failed to acquire symbol MI_AI_SetI2SConfig!\n"); + hal_symbol_load("i6c_aud", aud_lib->handle, "MI_AI_SetI2SConfig"))) return EXIT_FAILURE; - } if (!(aud_lib->fnSetGain = (int(*)(i6c_aud_input input, char leftLevel, char rightLevel)) - dlsym(aud_lib->handle, "MI_AI_SetIfGain"))) { - fprintf(stderr, "[i6c_aud] Failed to acquire symbol MI_AI_SetIfGain!\n"); + hal_symbol_load("i6c_aud", aud_lib->handle, "MI_AI_SetIfGain"))) return EXIT_FAILURE; - } if (!(aud_lib->fnSetMute = (int(*)(int device, unsigned char group, char actives[], unsigned char activeSize)) - dlsym(aud_lib->handle, "MI_AI_SetMute"))) { - fprintf(stderr, "[i6c_aud] Failed to acquire symbol MI_AI_SetMute!\n"); + hal_symbol_load("i6c_aud", aud_lib->handle, "MI_AI_SetMute"))) return EXIT_FAILURE; - } if (!(aud_lib->fnSetVolume = (int(*)(int device, unsigned char group, char levels[], unsigned char levelSize)) - dlsym(aud_lib->handle, "MI_AI_SetGain"))) { - fprintf(stderr, "[i6c_aud] Failed to acquire symbol MI_AI_SetGain!\n"); + hal_symbol_load("i6c_aud", aud_lib->handle, "MI_AI_SetGain"))) return EXIT_FAILURE; - } if (!(aud_lib->fnFreeFrame = (int(*)(int device, unsigned char group, i6c_aud_frm *frame, i6c_aud_frm *echoFrame)) - dlsym(aud_lib->handle, "MI_AI_ReleaseData"))) { - fprintf(stderr, "[i6c_aud] Failed to acquire symbol MI_AI_ReleaseData!\n"); + hal_symbol_load("i6c_aud", aud_lib->handle, "MI_AI_ReleaseData"))) return EXIT_FAILURE; - } if (!(aud_lib->fnGetFrame = (int(*)(int device, unsigned char group, i6c_aud_frm *frame, i6c_aud_frm *echoFrame, int millis)) - dlsym(aud_lib->handle, "MI_AI_Read"))) { - fprintf(stderr, "[i6c_aud] Failed to acquire symbol MI_AI_Read!\n"); + hal_symbol_load("i6c_aud", aud_lib->handle, "MI_AI_Read"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6c_common.h b/src/hal/star/i6c_common.h index a0b2c4c..dc1c0a5 100644 --- a/src/hal/star/i6c_common.h +++ b/src/hal/star/i6c_common.h @@ -6,16 +6,9 @@ #include #include +#include "../symbols.h" #include "../types.h" -#define I6C_ERROR(x, ...) \ - do { \ - fprintf(stderr, "[i6c_hal] \033[31m"); \ - fprintf(stderr, (x), ##__VA_ARGS__); \ - fprintf(stderr, "\033[0m"); \ - return EXIT_FAILURE; \ - } while (0) - typedef enum { I6C_BAYER_RG, I6C_BAYER_GR, diff --git a/src/hal/star/i6c_hal.c b/src/hal/star/i6c_hal.c index b5fb442..8309844 100644 --- a/src/hal/star/i6c_hal.c +++ b/src/hal/star/i6c_hal.c @@ -132,7 +132,7 @@ void *i6c_audio_thread(void) while (keepRunning) { if (ret = i6c_aud.fnGetFrame(_i6c_aud_dev, _i6c_aud_chn, &frame, NULL, 128)) { - fprintf(stderr, "[i6c_aud] Getting the frame failed " + HAL_WARNING("i6c_aud", "Getting the frame failed " "with %#x!\n", ret); continue; } @@ -149,11 +149,11 @@ void *i6c_audio_thread(void) if (ret = i6c_aud.fnFreeFrame(_i6c_aud_dev, _i6c_aud_chn, &frame, NULL)) { - fprintf(stderr, "[i6c_aud] Releasing the frame failed" + HAL_WARNING("i6c_aud", "Releasing the frame failed" " with %#x!\n", ret); } } - fprintf(stderr, "[i6c_aud] Shutting down capture thread...\n"); + HAL_INFO("i6c_aud", "Shutting down capture thread...\n"); } int i6c_channel_bind(char index, char framerate) @@ -454,12 +454,12 @@ int i6c_region_create(char handle, hal_rect rect, short opacity) region.size.height = rect.height; if (i6c_rgn.fnGetRegionConfig(0, handle, ®ionCurr)) { - fprintf(stderr, "[i6c_rgn] Creating region %d...\n", handle); + HAL_INFO("i6c_rgn", "Creating region %d...\n", handle); if (ret = i6c_rgn.fnCreateRegion(0, handle, ®ion)) return ret; } else if (regionCurr.size.height != region.size.height || regionCurr.size.width != region.size.width) { - fprintf(stderr, "[i6c_rgn] Parameters are different, recreating " + HAL_INFO("i6c_rgn", "Parameters are different, recreating " "region %d...\n", handle); for (char i = 0; i < I6C_VENC_CHN_NUM; i++) { if (!i6c_state[i].enable) continue; @@ -472,10 +472,10 @@ int i6c_region_create(char handle, hal_rect rect, short opacity) } if (i6c_rgn.fnGetChannelConfig(0, handle, &channel, &attribCurr)) - fprintf(stderr, "[i6c_rgn] Attaching region %d...\n", handle); + HAL_INFO("i6c_rgn", "Attaching region %d...\n", handle); else if (attribCurr.point.x != rect.x || attribCurr.point.x != rect.y || attribCurr.osd.bgFgAlpha[1] != opacity) { - fprintf(stderr, "[i6c_rgn] Parameters are different, reattaching " + HAL_INFO("i6c_rgn", "Parameters are different, reattaching " "region %d...\n", handle); for (char i = 0; i < I6C_VENC_CHN_NUM; i++) { if (!i6c_state[i].enable) continue; @@ -558,7 +558,7 @@ int i6c_video_create(char index, hal_vidconfig *config) channel.rate.mjpgQp.quality = MAX(config->minQual, config->maxQual); break; default: - I6C_ERROR("MJPEG encoder can only support CBR or fixed QP modes!"); + HAL_ERROR("i6c_venc", "MJPEG encoder can only support CBR or fixed QP modes!"); } channel.attrib.mjpg.maxHeight = ALIGN_UP(config->height, 2); @@ -592,7 +592,7 @@ int i6c_video_create(char index, hal_vidconfig *config) .fpsNum = config->framerate, .fpsDen = 1, .interQual = config->maxQual, .predQual = config->minQual }; break; case HAL_VIDMODE_ABR: - I6C_ERROR("H.265 encoder does not support ABR mode!"); + HAL_ERROR("i6c_venc", "H.265 encoder does not support ABR mode!"); case HAL_VIDMODE_AVBR: channel.rate.mode = I6C_VENC_RATEMODE_H265AVBR; channel.rate.h265Avbr = (i6c_venc_rate_h26xvbr){ .gop = config->gop, @@ -600,7 +600,7 @@ int i6c_video_create(char index, hal_vidconfig *config) (unsigned int)(MAX(config->bitrate, config->maxBitrate)) << 10, .maxQual = config->maxQual, .minQual = config->minQual }; break; default: - I6C_ERROR("H.265 encoder does not support this mode!"); + HAL_ERROR("i6c_venc", "H.265 encoder does not support this mode!"); } } else if (config->codec == HAL_VIDCODEC_H264) { channel.attrib.codec = I6C_VENC_CODEC_H264; @@ -635,9 +635,9 @@ int i6c_video_create(char index, hal_vidconfig *config) (unsigned int)(MAX(config->bitrate, config->maxBitrate)) << 10, .maxQual = config->maxQual, .minQual = config->minQual }; break; default: - I6C_ERROR("H.264 encoder does not support this mode!"); + HAL_ERROR("i6c_venc", "H.264 encoder does not support this mode!"); } - } else I6C_ERROR("This codec is not supported by the hardware!"); + } else HAL_ERROR("i6c_venc", "This codec is not supported by the hardware!"); _i6c_venc_dev[index] = I6C_VENC_DEV_H26X_0; attrib->maxHeight = config->height; attrib->maxWidth = config->width; @@ -734,7 +734,7 @@ int i6c_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg) int ret; if (ret = i6c_channel_bind(index, 1)) { - fprintf(stderr, "[i6c_venc] Binding the encoder channel " + HAL_DANGER("i6c_venc", "Binding the encoder channel " "%d failed with %#x!\n", index, ret); goto abort; } @@ -742,21 +742,21 @@ int i6c_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg) i6c_venc_jpg param; memset(¶m, 0, sizeof(param)); if (ret = i6c_venc.fnGetJpegParam(_i6c_venc_dev[index], index, ¶m)) { - fprintf(stderr, "[i6c_venc] Reading the JPEG settings " + HAL_DANGER("i6c_venc", "Reading the JPEG settings " "%d failed with %#x!\n", index, ret); goto abort; } param.quality = quality; if (ret = i6c_venc.fnSetJpegParam(_i6c_venc_dev[index], index, ¶m)) { - fprintf(stderr, "[i6c_venc] Writing the JPEG settings " + HAL_DANGER("i6c_venc", "Writing the JPEG settings " "%d failed with %#x!\n", index, ret); goto abort; } unsigned int count = 1; if (i6c_venc.fnStartReceivingEx(_i6c_venc_dev[index], index, &count)) { - fprintf(stderr, "[i6c_venc] Requesting one frame " + HAL_DANGER("i6c_venc", "Requesting one frame " "%d failed with %#x!\n", index, ret); goto abort; } @@ -769,23 +769,23 @@ int i6c_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg) FD_SET(fd, &readFds); ret = select(fd + 1, &readFds, NULL, NULL, &timeout); if (ret < 0) { - fprintf(stderr, "[i6c_venc] Select operation failed!\n"); + HAL_DANGER("i6c_venc", "Select operation failed!\n"); goto abort; } else if (ret == 0) { - fprintf(stderr, "[i6c_venc] Capture stream timed out!\n"); + HAL_DANGER("i6c_venc", "Capture stream timed out!\n"); goto abort; } if (FD_ISSET(fd, &readFds)) { i6c_venc_stat stat; if (i6c_venc.fnQuery(_i6c_venc_dev[index], index, &stat)) { - fprintf(stderr, "[i6c_venc] Querying the encoder channel " + HAL_DANGER("i6c_venc", "Querying the encoder channel " "%d failed with %#x!\n", index, ret); goto abort; } if (!stat.curPacks) { - fprintf(stderr, "[i6c_venc] Current frame is empty, skipping it!\n"); + HAL_DANGER("i6c_venc", "Current frame is empty, skipping it!\n"); goto abort; } @@ -793,13 +793,13 @@ int i6c_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg) memset(&strm, 0, sizeof(strm)); strm.packet = (i6c_venc_pack*)malloc(sizeof(i6c_venc_pack) * stat.curPacks); if (!strm.packet) { - fprintf(stderr, "[i6c_venc] Memory allocation on channel %d failed!\n", index); + HAL_DANGER("i6c_venc", "Memory allocation on channel %d failed!\n", index); goto abort; } strm.count = stat.curPacks; if (ret = i6c_venc.fnGetStream(_i6c_venc_dev[index], index, &strm, stat.curPacks)) { - fprintf(stderr, "[i6c_venc] Getting the stream on " + HAL_DANGER("i6c_venc", "Getting the stream on " "channel %d failed with %#x!\n", index, ret); free(strm.packet); strm.packet = NULL; @@ -847,7 +847,7 @@ void *i6c_video_thread(void) ret = i6c_venc.fnGetDescriptor(_i6c_venc_dev[i], i); if (ret < 0) { - fprintf(stderr, "[i6c_venc] Getting the encoder descriptor failed with %#x!\n", ret); + HAL_DANGER("i6c_venc", "Getting the encoder descriptor failed with %#x!\n", ret); return NULL; } i6c_state[i].fileDesc = ret; @@ -873,10 +873,10 @@ void *i6c_video_thread(void) timeout.tv_usec = 0; ret = select(maxFd + 1, &readFds, NULL, NULL, &timeout); if (ret < 0) { - fprintf(stderr, "[i6c_venc] Select operation failed!\n"); + HAL_DANGER("i6c_venc", "Select operation failed!\n"); break; } else if (ret == 0) { - fprintf(stderr, "[i6c_venc] Main stream loop timed out!\n"); + HAL_WARNING("i6c_venc", "Main stream loop timed out!\n"); continue; } else { for (int i = 0; i < I6C_VENC_CHN_NUM; i++) { @@ -886,26 +886,26 @@ void *i6c_video_thread(void) memset(&stream, 0, sizeof(stream)); if (ret = i6c_venc.fnQuery(_i6c_venc_dev[i], i, &stat)) { - fprintf(stderr, "[i6c_venc] Querying the encoder channel " + HAL_DANGER("i6c_venc", "Querying the encoder channel " "%d failed with %#x!\n", i, ret); break; } if (!stat.curPacks) { - fprintf(stderr, "[i6c_venc] Current frame is empty, skipping it!\n"); + HAL_INFO("i6c_venc", "Current frame is empty, skipping it!\n"); continue; } stream.packet = (i6c_venc_pack*)malloc( sizeof(i6c_venc_pack) * stat.curPacks); if (!stream.packet) { - fprintf(stderr, "[i6c_venc] Memory allocation on channel %d failed!\n", i); + HAL_DANGER("i6c_venc", "Memory allocation on channel %d failed!\n", i); break; } stream.count = stat.curPacks; if (ret = i6c_venc.fnGetStream(_i6c_venc_dev[i], i, &stream, 40)) { - fprintf(stderr, "[i6c_venc] Getting the stream on " + HAL_DANGER("i6c_venc", "Getting the stream on " "channel %d failed with %#x!\n", i, ret); break; } @@ -950,7 +950,7 @@ void *i6c_video_thread(void) } if (ret = i6c_venc.fnFreeStream(_i6c_venc_dev[i], i, &stream)) { - fprintf(stderr, "[i6c_venc] Releasing the stream on " + HAL_DANGER("i6c_venc", "Releasing the stream on " "channel %d failed with %#x!\n", i, ret); } free(stream.packet); @@ -959,7 +959,7 @@ void *i6c_video_thread(void) } } } - fprintf(stderr, "[i6c_venc] Shutting down encoding thread...\n"); + HAL_INFO("i6c_venc", "Shutting down encoding thread...\n"); } void i6c_system_deinit(void) diff --git a/src/hal/star/i6c_isp.h b/src/hal/star/i6c_isp.h index b8fd9f6..0ad1eb7 100644 --- a/src/hal/star/i6c_isp.h +++ b/src/hal/star/i6c_isp.h @@ -53,92 +53,62 @@ typedef struct { } i6c_isp_impl; static int i6c_isp_load(i6c_isp_impl *isp_lib) { - if (!(isp_lib->handleIspAlgo = dlopen("libispalgo.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6c_isp] Failed to load dependency library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(isp_lib->handleIspAlgo = dlopen("libispalgo.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6c_isp", "Failed to load dependency library!\nError: %s\n", dlerror()); - if (!(isp_lib->handleCus3a = dlopen("libcus3a.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6c_isp] Failed to load dependency library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(isp_lib->handleCus3a = dlopen("libcus3a.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6c_isp", "Failed to load dependency library!\nError: %s\n", dlerror()); - if (!(isp_lib->handle = dlopen("libmi_isp.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6c_isp] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(isp_lib->handle = dlopen("libmi_isp.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6c_isp", "Failed to load library!\nError: %s\n", dlerror()); if (!(isp_lib->fnCreateDevice = (int(*)(int device, unsigned int *combo)) - dlsym(isp_lib->handle, "MI_ISP_CreateDevice"))) { - fprintf(stderr, "[i6c_isp] Failed to acquire symbol MI_ISP_CreateDevice!\n"); + hal_symbol_load("i6c_isp", isp_lib->handle, "MI_ISP_CreateDevice"))) return EXIT_FAILURE; - } if (!(isp_lib->fnDestroyDevice = (int(*)(int device)) - dlsym(isp_lib->handle, "MI_ISP_DestoryDevice"))) { - fprintf(stderr, "[i6c_isp] Failed to acquire symbol MI_ISP_DestoryDevice!\n"); + hal_symbol_load("i6c_isp", isp_lib->handle, "MI_ISP_DestoryDevice"))) return EXIT_FAILURE; - } if (!(isp_lib->fnCreateChannel = (int(*)(int device, int channel, i6c_isp_chn *config)) - dlsym(isp_lib->handle, "MI_ISP_CreateChannel"))) { - fprintf(stderr, "[i6c_isp] Failed to acquire symbol MI_ISP_CreateChannel!\n"); + hal_symbol_load("i6c_isp", isp_lib->handle, "MI_ISP_CreateChannel"))) return EXIT_FAILURE; - } if (!(isp_lib->fnDestroyChannel = (int(*)(int device, int channel)) - dlsym(isp_lib->handle, "MI_ISP_DestroyChannel"))) { - fprintf(stderr, "[i6c_isp] Failed to acquire symbol MI_ISP_DestroyChannel!\n"); + hal_symbol_load("i6c_isp", isp_lib->handle, "MI_ISP_DestroyChannel"))) return EXIT_FAILURE; - } if (!(isp_lib->fnLoadChannelConfig = (int(*)(int device, int channel, char *path, unsigned int key)) - dlsym(isp_lib->handle, "MI_ISP_ApiCmdLoadBinFile"))) { - fprintf(stderr, "[i6c_isp] Failed to acquire symbol MI_ISP_ApiCmdLoadBinFile!\n"); + hal_symbol_load("i6c_isp", isp_lib->handle, "MI_ISP_ApiCmdLoadBinFile"))) return EXIT_FAILURE; - } if (!(isp_lib->fnSetChannelParam = (int(*)(int device, int channel, i6c_isp_para *config)) - dlsym(isp_lib->handle, "MI_ISP_SetChnParam"))) { - fprintf(stderr, "[i6c_isp] Failed to acquire symbol MI_ISP_SetChnParam!\n"); + hal_symbol_load("i6c_isp", isp_lib->handle, "MI_ISP_SetChnParam"))) return EXIT_FAILURE; - } if (!(isp_lib->fnStartChannel = (int(*)(int device, int channel)) - dlsym(isp_lib->handle, "MI_ISP_StartChannel"))) { - fprintf(stderr, "[i6c_isp] Failed to acquire symbol MI_ISP_StartChannel!\n"); + hal_symbol_load("i6c_isp", isp_lib->handle, "MI_ISP_StartChannel"))) return EXIT_FAILURE; - } if (!(isp_lib->fnStopChannel = (int(*)(int device, int channel)) - dlsym(isp_lib->handle, "MI_ISP_StopChannel"))) { - fprintf(stderr, "[i6c_isp] Failed to acquire symbol MI_ISP_StopChannel!\n"); + hal_symbol_load("i6c_isp", isp_lib->handle, "MI_ISP_StopChannel"))) return EXIT_FAILURE; - } if (!(isp_lib->fnDisablePort = (int(*)(int device, int channel, int port)) - dlsym(isp_lib->handle, "MI_ISP_DisableOutputPort"))) { - fprintf(stderr, "[i6c_isp] Failed to acquire symbol MI_ISP_DisableOutputPort!\n"); + hal_symbol_load("i6c_isp", isp_lib->handle, "MI_ISP_DisableOutputPort"))) return EXIT_FAILURE; - } if (!(isp_lib->fnEnablePort = (int(*)(int device, int channel, int port)) - dlsym(isp_lib->handle, "MI_ISP_EnableOutputPort"))) { - fprintf(stderr, "[i6c_isp] Failed to acquire symbol MI_ISP_EnableOutputPort!\n"); + hal_symbol_load("i6c_isp", isp_lib->handle, "MI_ISP_EnableOutputPort"))) return EXIT_FAILURE; - } if (!(isp_lib->fnSetPortConfig = (int(*)(int device, int channel, int port, i6c_isp_port *config)) - dlsym(isp_lib->handle, "MI_ISP_SetOutputPortParam"))) { - fprintf(stderr, "[i6c_isp] Failed to acquire symbol MI_ISP_SetOutputPortParam!\n"); + hal_symbol_load("i6c_isp", isp_lib->handle, "MI_ISP_SetOutputPortParam"))) return EXIT_FAILURE; - } if (!(isp_lib->fnSetColorToGray = (int(*)(int device, int channel, char *enable)) - dlsym(isp_lib->handle, "MI_ISP_IQ_SetColorToGray"))) { - fprintf(stderr, "[i6c_isp] Failed to acquire symbol MI_ISP_IQ_SetColorToGray!\n"); + hal_symbol_load("i6c_isp", isp_lib->handle, "MI_ISP_IQ_SetColorToGray"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6c_rgn.h b/src/hal/star/i6c_rgn.h index 8faee0d..ec19d5a 100644 --- a/src/hal/star/i6c_rgn.h +++ b/src/hal/star/i6c_rgn.h @@ -105,70 +105,50 @@ typedef struct { } i6c_rgn_impl; static int i6c_rgn_load(i6c_rgn_impl *rgn_lib) { - if (!(rgn_lib->handle = dlopen("libmi_rgn.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6c_rgn] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(rgn_lib->handle = dlopen("libmi_rgn.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6c_rgn", "Failed to load library!\nError: %s\n", dlerror()); if (!(rgn_lib->fnDeinit = (int(*)(unsigned short chip)) - dlsym(rgn_lib->handle, "MI_RGN_DeInit"))) { - fprintf(stderr, "[i6c_rgn] Failed to acquire symbol MI_RGN_DeInit!\n"); + hal_symbol_load("i6c_rgn", rgn_lib->handle, "MI_RGN_DeInit"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnInit = (int(*)(unsigned short chip, i6c_rgn_pal *palette)) - dlsym(rgn_lib->handle, "MI_RGN_Init"))) { - fprintf(stderr, "[i6c_rgn] Failed to acquire symbol MI_RGN_Init!\n"); + hal_symbol_load("i6c_rgn", rgn_lib->handle, "MI_RGN_Init"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnCreateRegion = (int(*)(unsigned short chip, unsigned int handle, i6c_rgn_cnf *config)) - dlsym(rgn_lib->handle, "MI_RGN_Create"))) { - fprintf(stderr, "[i6c_rgn] Failed to acquire symbol MI_RGN_Create!\n"); + hal_symbol_load("i6c_rgn", rgn_lib->handle, "MI_RGN_Create"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnDestroyRegion = (int(*)(unsigned short chip, unsigned int handle)) - dlsym(rgn_lib->handle, "MI_RGN_Destroy"))) { - fprintf(stderr, "[i6c_rgn] Failed to acquire symbol MI_RGN_Destroy!\n"); + hal_symbol_load("i6c_rgn", rgn_lib->handle, "MI_RGN_Destroy"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnGetRegionConfig = (int(*)(unsigned short chip, unsigned int handle, i6c_rgn_cnf *config)) - dlsym(rgn_lib->handle, "MI_RGN_GetAttr"))) { - fprintf(stderr, "[i6c_rgn] Failed to acquire symbol MI_RGN_GetAttr!\n"); + hal_symbol_load("i6c_rgn", rgn_lib->handle, "MI_RGN_GetAttr"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnAttachChannel = (int(*)(unsigned short chip, unsigned int handle, i6c_sys_bind *dest, i6c_rgn_chn *config)) - dlsym(rgn_lib->handle, "MI_RGN_AttachToChn"))) { - fprintf(stderr, "[i6c_rgn] Failed to acquire symbol MI_RGN_AttachToChn!\n"); + hal_symbol_load("i6c_rgn", rgn_lib->handle, "MI_RGN_AttachToChn"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnDetachChannel = (int(*)(unsigned short chip, unsigned int handle, i6c_sys_bind *dest)) - dlsym(rgn_lib->handle, "MI_RGN_DetachFromChn"))) { - fprintf(stderr, "[i6c_rgn] Failed to acquire symbol MI_RGN_DetachFromChn!\n"); + hal_symbol_load("i6c_rgn", rgn_lib->handle, "MI_RGN_DetachFromChn"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnGetChannelConfig = (int(*)(unsigned short chip, unsigned int handle, i6c_sys_bind *dest, i6c_rgn_chn *config)) - dlsym(rgn_lib->handle, "MI_RGN_GetDisplayAttr"))) { + hal_symbol_load("i6c_rgn", rgn_lib->handle, "MI_RGN_GetDisplayAttr"))) { fprintf(stderr, "[i6c_rgn] Failed to acquire symbol MI_RGN_GetDisplayAttr!\n"); return EXIT_FAILURE; } if (!(rgn_lib->fnSetChannelConfig = (int(*)(unsigned short chip, unsigned int handle, i6c_sys_bind *dest, i6c_rgn_chn *config)) - dlsym(rgn_lib->handle, "MI_RGN_SetDisplayAttr"))) { - fprintf(stderr, "[i6c_rgn] Failed to acquire symbol MI_RGN_SetDisplayAttr!\n"); + hal_symbol_load("i6c_rgn", rgn_lib->handle, "MI_RGN_SetDisplayAttr"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnSetBitmap = (int(*)(unsigned short chip, unsigned int handle, i6c_rgn_bmp *bitmap)) - dlsym(rgn_lib->handle, "MI_RGN_SetBitMap"))) { - fprintf(stderr, "[i6c_rgn] Failed to acquire symbol MI_RGN_SetBitMap!\n"); + hal_symbol_load("i6c_rgn", rgn_lib->handle, "MI_RGN_SetBitMap"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6c_scl.h b/src/hal/star/i6c_scl.h index 0a846a5..4b8c84f 100644 --- a/src/hal/star/i6c_scl.h +++ b/src/hal/star/i6c_scl.h @@ -43,70 +43,48 @@ typedef struct { } i6c_scl_impl; static int i6c_scl_load(i6c_scl_impl *scl_lib) { - if (!(scl_lib->handle = dlopen("libmi_scl.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6c_scl] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(scl_lib->handle = dlopen("libmi_scl.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6c_scl", "Failed to load library!\nError: %s\n", dlerror()); if (!(scl_lib->fnCreateDevice = (int(*)(int device, unsigned int *binds)) - dlsym(scl_lib->handle, "MI_SCL_CreateDevice"))) { - fprintf(stderr, "[i6c_scl] Failed to acquire symbol MI_SCL_CreateDevice!\n"); + hal_symbol_load("i6c_scl", scl_lib->handle, "MI_SCL_CreateDevice"))) return EXIT_FAILURE; - } if (!(scl_lib->fnDestroyDevice = (int(*)(int device)) - dlsym(scl_lib->handle, "MI_SCL_DestroyDevice"))) { - fprintf(stderr, "[i6c_scl] Failed to acquire symbol MI_SCL_DestroyDevice!\n"); + hal_symbol_load("i6c_scl", scl_lib->handle, "MI_SCL_DestroyDevice"))) return EXIT_FAILURE; - } if (!(scl_lib->fnAdjustChannelRotation = (int(*)(int device, int channel, int *rotate)) - dlsym(scl_lib->handle, "MI_SCL_SetChnParam"))) { - fprintf(stderr, "[i6c_scl] Failed to acquire symbol MI_SCL_SetChnParam!\n"); + hal_symbol_load("i6c_scl", scl_lib->handle, "MI_SCL_SetChnParam"))) return EXIT_FAILURE; - } if (!(scl_lib->fnCreateChannel = (int(*)(int device, int channel, unsigned int *reserved)) - dlsym(scl_lib->handle, "MI_SCL_CreateChannel"))) { - fprintf(stderr, "[i6c_scl] Failed to acquire symbol MI_SCL_CreateChannel!\n"); + hal_symbol_load("i6c_scl", scl_lib->handle, "MI_SCL_CreateChannel"))) return EXIT_FAILURE; - } if (!(scl_lib->fnDestroyChannel = (int(*)(int device, int channel)) - dlsym(scl_lib->handle, "MI_SCL_DestroyChannel"))) { - fprintf(stderr, "[i6c_scl] Failed to acquire symbol MI_SCL_DestroyChannel!\n"); + hal_symbol_load("i6c_scl", scl_lib->handle, "MI_SCL_DestroyChannel"))) return EXIT_FAILURE; - } if (!(scl_lib->fnStartChannel = (int(*)(int device, int channel)) - dlsym(scl_lib->handle, "MI_SCL_StartChannel"))) { - fprintf(stderr, "[i6c_scl] Failed to acquire symbol MI_SCL_StartChannel!\n"); + hal_symbol_load("i6c_scl", scl_lib->handle, "MI_SCL_StartChannel"))) return EXIT_FAILURE; - } if (!(scl_lib->fnStopChannel = (int(*)(int device, int channel)) - dlsym(scl_lib->handle, "MI_SCL_StopChannel"))) { - fprintf(stderr, "[i6c_scl] Failed to acquire symbol MI_SCL_StopChannel!\n"); + hal_symbol_load("i6c_scl", scl_lib->handle, "MI_SCL_StopChannel"))) return EXIT_FAILURE; - } if (!(scl_lib->fnDisablePort = (int(*)(int device, int channel, int port)) - dlsym(scl_lib->handle, "MI_SCL_DisableOutputPort"))) { - fprintf(stderr, "[i6c_scl] Failed to acquire symbol MI_SCL_DisableOutputPort!\n"); + hal_symbol_load("i6c_scl", scl_lib->handle, "MI_SCL_DisableOutputPort"))) return EXIT_FAILURE; - } if (!(scl_lib->fnEnablePort = (int(*)(int device, int channel, int port)) - dlsym(scl_lib->handle, "MI_SCL_EnableOutputPort"))) { - fprintf(stderr, "[i6c_scl] Failed to acquire symbol MI_SCL_EnableOutputPort!\n"); + hal_symbol_load("i6c_scl", scl_lib->handle, "MI_SCL_EnableOutputPort"))) return EXIT_FAILURE; - } if (!(scl_lib->fnSetPortConfig = (int(*)(int device, int channel, int port, i6c_scl_port *config)) - dlsym(scl_lib->handle, "MI_SCL_SetOutputPortParam"))) { - fprintf(stderr, "[i6c_scl] Failed to acquire symbol MI_SCL_SetOutputPortParam!\n"); + hal_symbol_load("i6c_scl", scl_lib->handle, "MI_SCL_SetOutputPortParam"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6c_snr.h b/src/hal/star/i6c_snr.h index 08b1142..5a3a2b3 100644 --- a/src/hal/star/i6c_snr.h +++ b/src/hal/star/i6c_snr.h @@ -99,70 +99,48 @@ typedef struct { } i6c_snr_impl; static int i6c_snr_load(i6c_snr_impl *snr_lib) { - if (!(snr_lib->handle = dlopen("libmi_sensor.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6c_snr] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(snr_lib->handle = dlopen("libmi_sensor.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6c_snr", "Failed to load library!\nError: %s\n", dlerror()); if (!(snr_lib->fnDisable = (int(*)(unsigned int sensor)) - dlsym(snr_lib->handle, "MI_SNR_Disable"))) { - fprintf(stderr, "[i6c_snr] Failed to acquire symbol MI_SNR_Disable!\n"); + hal_symbol_load("i6c_snr", snr_lib->handle, "MI_SNR_Disable"))) return EXIT_FAILURE; - } if (!(snr_lib->fnEnable = (int(*)(unsigned int sensor)) - dlsym(snr_lib->handle, "MI_SNR_Enable"))) { - fprintf(stderr, "[i6c_snr] Failed to acquire symbol MI_SNR_Enable!\n"); + hal_symbol_load("i6c_snr", snr_lib->handle, "MI_SNR_Enable"))); return EXIT_FAILURE; - } if (!(snr_lib->fnSetFramerate = (int(*)(unsigned int sensor, unsigned int framerate)) - dlsym(snr_lib->handle, "MI_SNR_SetFps"))) { - fprintf(stderr, "[i6c_snr] Failed to acquire symbol MI_SNR_SetFps!\n"); + hal_symbol_load("i6c_snr", snr_lib->handle, "MI_SNR_SetFps"))) return EXIT_FAILURE; - } if (!(snr_lib->fnGetPadInfo = (int(*)(unsigned int sensor, i6c_snr_pad *info)) - dlsym(snr_lib->handle, "MI_SNR_GetPadInfo"))) { - fprintf(stderr, "[i6c_snr] Failed to acquire symbol MI_SNR_GetPadInfo!\n"); + hal_symbol_load("i6c_snr", snr_lib->handle, "MI_SNR_GetPadInfo"))) return EXIT_FAILURE; - } if (!(snr_lib->fnGetPlaneInfo = (int(*)(unsigned int sensor, unsigned int index, i6c_snr_plane *info)) - dlsym(snr_lib->handle, "MI_SNR_GetPlaneInfo"))) { - fprintf(stderr, "[i6c_snr] Failed to acquire symbol MI_SNR_GetPlaneInfo!\n"); + hal_symbol_load("i6c_snr", snr_lib->handle, "MI_SNR_GetPlaneInfo"))) return EXIT_FAILURE; - } if (!(snr_lib->fnSetPlaneMode = (int(*)(unsigned int sensor, unsigned char active)) - dlsym(snr_lib->handle, "MI_SNR_SetPlaneMode"))) { - fprintf(stderr, "[i6c_snr] Failed to acquire symbol MI_SNR_SetPlaneMode!\n"); + hal_symbol_load("i6c_snr", snr_lib->handle, "MI_SNR_SetPlaneMode"))) return EXIT_FAILURE; - } if (!(snr_lib->fnCurrentResolution = (int(*)(unsigned int sensor, unsigned char *index, i6c_snr_res *resolution)) - dlsym(snr_lib->handle, "MI_SNR_GetCurRes"))) { - fprintf(stderr, "[i6c_snr] Failed to acquire symbol MI_SNR_GetCurRes!\n"); + hal_symbol_load("i6c_snr", snr_lib->handle, "MI_SNR_GetCurRes"))) return EXIT_FAILURE; - } if (!(snr_lib->fnGetResolution = (int(*)(unsigned int sensor, unsigned char index, i6c_snr_res *resolution)) - dlsym(snr_lib->handle, "MI_SNR_GetRes"))) { - fprintf(stderr, "[i6c_snr] Failed to acquire symbol MI_SNR_GetRes!\n"); + hal_symbol_load("i6c_snr", snr_lib->handle, "MI_SNR_GetRes"))) return EXIT_FAILURE; - } if (!(snr_lib->fnGetResolutionCount = (int(*)(unsigned int sensor, unsigned int *count)) - dlsym(snr_lib->handle, "MI_SNR_QueryResCount"))) { - fprintf(stderr, "[i6c_snr] Failed to acquire symbol MI_SNR_QueryResCount!\n"); + hal_symbol_load("i6c_snr", snr_lib->handle, "MI_SNR_QueryResCount"))) return EXIT_FAILURE; - } if (!(snr_lib->fnSetResolution = (int(*)(unsigned int sensor, unsigned char index)) - dlsym(snr_lib->handle, "MI_SNR_SetRes"))) { - fprintf(stderr, "[i6c_snr] Failed to acquire symbol MI_SNR_SetRes!\n"); + hal_symbol_load("i6c_snr", snr_lib->handle, "MI_SNR_SetRes"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6c_sys.h b/src/hal/star/i6c_sys.h index dace89d..5ee7add 100644 --- a/src/hal/star/i6c_sys.h +++ b/src/hal/star/i6c_sys.h @@ -145,65 +145,45 @@ typedef struct { } i6c_sys_impl; static int i6c_sys_load(i6c_sys_impl *sys_lib) { - if (!(sys_lib->handleCamOsWrapper = dlopen("libcam_os_wrapper.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6c_sys] Failed to load dependency library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(sys_lib->handleCamOsWrapper = dlopen("libcam_os_wrapper.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6c_sys", "Failed to load dependency library!\nError: %s\n", dlerror()); - if (!(sys_lib->handle = dlopen("libmi_sys.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6c_sys] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(sys_lib->handle = dlopen("libmi_sys.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6c_sys", "Failed to load library!\nError: %s\n", dlerror()); if (!(sys_lib->fnExit = (int(*)(unsigned short chip)) - dlsym(sys_lib->handle, "MI_SYS_Exit"))) { - fprintf(stderr, "[i6c_sys] Failed to acquire symbol MI_SYS_Exit!\n"); + hal_symbol_load("i6c_sys", sys_lib->handle, "MI_SYS_Exit"))) return EXIT_FAILURE; - } if (!(sys_lib->fnGetVersion = (int(*)(unsigned short chip, i6c_sys_ver *version)) - dlsym(sys_lib->handle, "MI_SYS_GetVersion"))) { - fprintf(stderr, "[i6c_sys] Failed to acquire symbol MI_SYS_GetVersion!\n"); + hal_symbol_load("i6c_sys", sys_lib->handle, "MI_SYS_GetVersion"))) return EXIT_FAILURE; - } if (!(sys_lib->fnInit = (int(*)(unsigned short chip)) - dlsym(sys_lib->handle, "MI_SYS_Init"))) { - fprintf(stderr, "[i6c_sys] Failed to acquire symbol MI_SYS_Init!\n"); + hal_symbol_load("i6c_sys", sys_lib->handle, "MI_SYS_Init"))) return EXIT_FAILURE; - } if (!(sys_lib->fnBind = (int(*)(unsigned short chip, i6c_sys_bind *source, i6c_sys_bind *dest, i6c_sys_link *link)) - dlsym(sys_lib->handle, "MI_SYS_BindChnPort"))) { - fprintf(stderr, "[i6c_sys] Failed to acquire symbol MI_SYS_BindChnPort!\n"); + hal_symbol_load("i6c_sys", sys_lib->handle, "MI_SYS_BindChnPort"))) return EXIT_FAILURE; - } if (!(sys_lib->fnBindExt = (int(*)(unsigned short chip, i6c_sys_bind *source, i6c_sys_bind *dest, unsigned int srcFps, unsigned int dstFps, i6c_sys_link link, unsigned int linkParam)) - dlsym(sys_lib->handle, "MI_SYS_BindChnPort2"))) { - fprintf(stderr, "[i6c_sys] Failed to acquire symbol MI_SYS_BindChnPort2!\n"); + hal_symbol_load("i6c_sys", sys_lib->handle, "MI_SYS_BindChnPort2"))) return EXIT_FAILURE; - } if (!(sys_lib->fnSetOutputDepth = (int(*)(unsigned short chip, i6c_sys_bind *bind, unsigned int usrDepth, unsigned int bufDepth)) - dlsym(sys_lib->handle, "MI_SYS_SetChnOutputPortDepth"))) { - fprintf(stderr, "[i6c_sys] Failed to acquire symbol MI_SYS_SetChnOutputPortDepth!\n"); + hal_symbol_load("i6c_sys", sys_lib->handle, "MI_SYS_SetChnOutputPortDepth"))) return EXIT_FAILURE; - } if (!(sys_lib->fnUnbind = (int(*)(unsigned short chip, i6c_sys_bind *source, i6c_sys_bind *dest)) - dlsym(sys_lib->handle, "MI_SYS_UnBindChnPort"))) { - fprintf(stderr, "[i6c_sys] Failed to acquire symbol MI_SYS_UnBindChnPort!\n"); + hal_symbol_load("i6c_sys", sys_lib->handle, "MI_SYS_UnBindChnPort"))) return EXIT_FAILURE; - } if (!(sys_lib->fnConfigPool = (int(*)(unsigned short chip, i6c_sys_pool *config)) - dlsym(sys_lib->handle, "MI_SYS_ConfigPrivateMMAPool"))) { - fprintf(stderr, "[i6c_sys] Failed to acquire symbol MI_SYS_ConfigPrivateMMAPool!\n"); + hal_symbol_load("i6c_sys", sys_lib->handle, "MI_SYS_ConfigPrivateMMAPool"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6c_venc.h b/src/hal/star/i6c_venc.h index cea1ff0..68008c9 100644 --- a/src/hal/star/i6c_venc.h +++ b/src/hal/star/i6c_venc.h @@ -307,124 +307,84 @@ typedef struct { } i6c_venc_impl; static int i6c_venc_load(i6c_venc_impl *venc_lib) { - if (!(venc_lib->handle = dlopen("libmi_venc.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6c_venc] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(venc_lib->handle = dlopen("libmi_venc.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6c_venc", "Failed to load library!\nError: %s\n", dlerror()); if (!(venc_lib->fnCreateDevice = (int(*)(unsigned int device, i6c_venc_init *config)) - dlsym(venc_lib->handle, "MI_VENC_CreateDev"))) { - fprintf(stderr, "[i6c_venc] Failed to acquire symbol MI_VENC_CreateDev!\n"); + hal_symbol_load("i6c_venc", venc_lib->handle, "MI_VENC_CreateDev"))) return EXIT_FAILURE; - } if (!(venc_lib->fnDestroyDevice = (int(*)(unsigned int device)) - dlsym(venc_lib->handle, "MI_VENC_DestroyDev"))) { - fprintf(stderr, "[i6c_venc] Failed to acquire symbol MI_VENC_DestroyDev!\n"); + hal_symbol_load("i6c_venc", venc_lib->handle, "MI_VENC_DestroyDev"))) return EXIT_FAILURE; - } if (!(venc_lib->fnCreateChannel = (int(*)(unsigned int device, unsigned int channel, i6c_venc_chn *config)) - dlsym(venc_lib->handle, "MI_VENC_CreateChn"))) { - fprintf(stderr, "[i6c_venc] Failed to acquire symbol MI_VENC_CreateChn!\n"); + hal_symbol_load("i6c_venc", venc_lib->handle, "MI_VENC_CreateChn"))) return EXIT_FAILURE; - } if (!(venc_lib->fnDestroyChannel = (int(*)(unsigned int device, unsigned int channel)) - dlsym(venc_lib->handle, "MI_VENC_DestroyChn"))) { - fprintf(stderr, "[i6c_venc] Failed to acquire symbol MI_VENC_DestroyChn!\n"); + hal_symbol_load("i6c_venc", venc_lib->handle, "MI_VENC_DestroyChn"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetChannelConfig = (int(*)(unsigned int device, unsigned int channel, i6c_venc_chn *config)) - dlsym(venc_lib->handle, "MI_VENC_GetChnAttr"))) { - fprintf(stderr, "[i6c_venc] Failed to acquire symbol MI_VENC_GetChnAttr!\n"); + hal_symbol_load("i6c_venc", venc_lib->handle, "MI_VENC_GetChnAttr"))) return EXIT_FAILURE; - } if (!(venc_lib->fnResetChannel = (int(*)(unsigned int device, unsigned int channel)) - dlsym(venc_lib->handle, "MI_VENC_ResetChn"))) { - fprintf(stderr, "[i6c_venc] Failed to acquire symbol MI_VENC_ResetChn!\n"); + hal_symbol_load("i6c_venc", venc_lib->handle, "MI_VENC_ResetChn"))) return EXIT_FAILURE; - } if (!(venc_lib->fnSetChannelConfig = (int(*)(unsigned int device, unsigned int channel, i6c_venc_chn *config)) - dlsym(venc_lib->handle, "MI_VENC_SetChnAttr"))) { - fprintf(stderr, "[i6c_venc] Failed to acquire symbol MI_VENC_SetChnAttr!\n"); + hal_symbol_load("i6c_venc", venc_lib->handle, "MI_VENC_SetChnAttr"))) return EXIT_FAILURE; - } if (!(venc_lib->fnFreeDescriptor = (int(*)(unsigned int device, unsigned int channel)) - dlsym(venc_lib->handle, "MI_VENC_CloseFd"))) { - fprintf(stderr, "[i6c_venc] Failed to acquire symbol MI_VENC_CloseFd!\n"); + hal_symbol_load("i6c_venc", venc_lib->handle, "MI_VENC_CloseFd"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetDescriptor = (int(*)(unsigned int device, unsigned int channel)) - dlsym(venc_lib->handle, "MI_VENC_GetFd"))) { - fprintf(stderr, "[i6c_venc] Failed to acquire symbol MI_VENC_GetFd!\n"); + hal_symbol_load("i6c_venc", venc_lib->handle, "MI_VENC_GetFd"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetJpegParam = (int(*)(unsigned int device, unsigned int channel, i6c_venc_jpg *param)) - dlsym(venc_lib->handle, "MI_VENC_GetJpegParam"))) { - fprintf(stderr, "[i6c_venc] Failed to acquire symbol MI_VENC_CloseFd!\n"); + hal_symbol_load("i6c_venc", venc_lib->handle, "MI_VENC_GetJpegParam"))) return EXIT_FAILURE; - } if (!(venc_lib->fnSetJpegParam = (int(*)(unsigned int device, unsigned int channel, i6c_venc_jpg *param)) - dlsym(venc_lib->handle, "MI_VENC_SetJpegParam"))) { - fprintf(stderr, "[i6c_venc] Failed to acquire symbol MI_VENC_GetFd!\n"); + hal_symbol_load("i6c_venc", venc_lib->handle, "MI_VENC_SetJpegParam"))) return EXIT_FAILURE; - } if (!(venc_lib->fnFreeStream = (int(*)(unsigned int device, unsigned int channel, i6c_venc_strm *stream)) - dlsym(venc_lib->handle, "MI_VENC_ReleaseStream"))) { - fprintf(stderr, "[i6c_venc] Failed to acquire symbol MI_VENC_ReleaseStream!\n"); + hal_symbol_load("i6c_venc", venc_lib->handle, "MI_VENC_ReleaseStream"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetStream = (int(*)(unsigned int device, unsigned int channel, i6c_venc_strm *stream, unsigned int timeout)) - dlsym(venc_lib->handle, "MI_VENC_GetStream"))) { - fprintf(stderr, "[i6c_venc] Failed to acquire symbol MI_VENC_GetStream!\n"); + hal_symbol_load("i6c_venc", venc_lib->handle, "MI_VENC_GetStream"))) return EXIT_FAILURE; - } if (!(venc_lib->fnQuery = (int(*)(unsigned int device, unsigned int channel, i6c_venc_stat *stats)) - dlsym(venc_lib->handle, "MI_VENC_Query"))) { - fprintf(stderr, "[i6c_venc] Failed to acquire symbol MI_VENC_Query!\n"); + hal_symbol_load("i6c_venc", venc_lib->handle, "MI_VENC_Query"))) return EXIT_FAILURE; - } if (!(venc_lib->fnSetSourceConfig = (int(*)(unsigned int device, unsigned int channel, i6c_venc_src_conf *config)) - dlsym(venc_lib->handle, "MI_VENC_SetInputSourceConfig"))) { - fprintf(stderr, "[i6c_venc] Failed to acquire symbol MI_VENC_SetInputSourceConfig!\n"); + hal_symbol_load("i6c_venc", venc_lib->handle, "MI_VENC_SetInputSourceConfig"))) return EXIT_FAILURE; - } if (!(venc_lib->fnRequestIdr = (int(*)(unsigned int device, unsigned int channel, char instant)) - dlsym(venc_lib->handle, "MI_VENC_RequestIdr"))) { - fprintf(stderr, "[i6c_venc] Failed to acquire symbol MI_VENC_RequestIdr!\n"); + hal_symbol_load("i6c_venc", venc_lib->handle, "MI_VENC_RequestIdr"))) return EXIT_FAILURE; - } if (!(venc_lib->fnStartReceiving = (int(*)(unsigned int device, unsigned int channel)) - dlsym(venc_lib->handle, "MI_VENC_StartRecvPic"))) { - fprintf(stderr, "[i6c_venc] Failed to acquire symbol MI_VENC_StartRecvPic!\n"); + hal_symbol_load("i6c_venc", venc_lib->handle, "MI_VENC_StartRecvPic"))) return EXIT_FAILURE; - } if (!(venc_lib->fnStartReceivingEx = (int(*)(unsigned int device, unsigned int channel, int *count)) - dlsym(venc_lib->handle, "MI_VENC_StartRecvPicEx"))) { - fprintf(stderr, "[i6c_venc] Failed to acquire symbol MI_VENC_StartRecvPicEx!\n"); + hal_symbol_load("i6c_venc", venc_lib->handle, "MI_VENC_StartRecvPicEx"))) return EXIT_FAILURE; - } if (!(venc_lib->fnStopReceiving = (int(*)(unsigned int device, unsigned int channel)) - dlsym(venc_lib->handle, "MI_VENC_StopRecvPic"))) { - fprintf(stderr, "[i6c_venc] Failed to acquire symbol MI_VENC_StopRecvPic!\n"); + hal_symbol_load("i6c_venc", venc_lib->handle, "MI_VENC_StopRecvPic"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6c_vif.h b/src/hal/star/i6c_vif.h index fd49388..4827eb1 100644 --- a/src/hal/star/i6c_vif.h +++ b/src/hal/star/i6c_vif.h @@ -70,58 +70,40 @@ typedef struct { } i6c_vif_impl; static int i6c_vif_load(i6c_vif_impl *vif_lib) { - if (!(vif_lib->handle = dlopen("libmi_vif.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6c_vif] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(vif_lib->handle = dlopen("libmi_vif.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6c_vif", "Failed to load library!\nError: %s\n", dlerror()); if (!(vif_lib->fnDisableDevice = (int(*)(int device)) - dlsym(vif_lib->handle, "MI_VIF_DisableDev"))) { - fprintf(stderr, "[i6c_vif] Failed to acquire symbol MI_VIF_DisableDev!\n"); + hal_symbol_load("i6c_vif", vif_lib->handle, "MI_VIF_DisableDev"))) return EXIT_FAILURE; - } if (!(vif_lib->fnEnableDevice = (int(*)(int device)) - dlsym(vif_lib->handle, "MI_VIF_EnableDev"))) { - fprintf(stderr, "[i6c_vif] Failed to acquire symbol MI_VIF_EnableDev!\n"); + hal_symbol_load("i6c_vif", vif_lib->handle, "MI_VIF_EnableDev"))) return EXIT_FAILURE; - } if (!(vif_lib->fnSetDeviceConfig = (int(*)(int device, i6c_vif_dev *config)) - dlsym(vif_lib->handle, "MI_VIF_SetDevAttr"))) { - fprintf(stderr, "[i6c_vif] Failed to acquire symbol MI_VIF_SetDevAttr!\n"); + hal_symbol_load("i6c_vif", vif_lib->handle, "MI_VIF_SetDevAttr"))) return EXIT_FAILURE; - } if (!(vif_lib->fnCreateGroup = (int(*)(int group, i6c_vif_grp *config)) - dlsym(vif_lib->handle, "MI_VIF_CreateDevGroup"))) { - fprintf(stderr, "[i6c_vif] Failed to acquire symbol MI_VIF_CreateDevGroup!\n"); + hal_symbol_load("i6c_vif", vif_lib->handle, "MI_VIF_CreateDevGroup"))) return EXIT_FAILURE; - } if (!(vif_lib->fnDestroyGroup = (int(*)(int group)) - dlsym(vif_lib->handle, "MI_VIF_DestroyDevGroup"))) { - fprintf(stderr, "[i6c_vif] Failed to acquire symbol MI_VIF_DestroyDevGroup!\n"); + hal_symbol_load("i6c_vif", vif_lib->handle, "MI_VIF_DestroyDevGroup"))) return EXIT_FAILURE; - } if (!(vif_lib->fnDisablePort = (int(*)(int device, int port)) - dlsym(vif_lib->handle, "MI_VIF_DisableOutputPort"))) { - fprintf(stderr, "[i6c_vif] Failed to acquire symbol MI_VIF_DisableOutputPort!\n"); + hal_symbol_load("i6c_vif", vif_lib->handle, "MI_VIF_DisableOutputPort"))) return EXIT_FAILURE; - } if (!(vif_lib->fnEnablePort = (int(*)(int device, int port)) - dlsym(vif_lib->handle, "MI_VIF_EnableOutputPort"))) { - fprintf(stderr, "[i6c_vif] Failed to acquire symbol MI_VIF_EnableOutputPort!\n"); + hal_symbol_load("i6c_vif", vif_lib->handle, "MI_VIF_EnableOutputPort"))) return EXIT_FAILURE; - } if (!(vif_lib->fnSetPortConfig = (int(*)(int device, int port, i6c_vif_port *config)) - dlsym(vif_lib->handle, "MI_VIF_SetOutputPortAttr"))) { - fprintf(stderr, "[i6c_vif] Failed to acquire symbol MI_VIF_SetOutputPortAttr!\n"); + hal_symbol_load("i6c_vif", vif_lib->handle, "MI_VIF_SetOutputPortAttr"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6f_aud.h b/src/hal/star/i6f_aud.h index 00c9de8..a1954ce 100644 --- a/src/hal/star/i6f_aud.h +++ b/src/hal/star/i6f_aud.h @@ -130,82 +130,56 @@ typedef struct { } i6f_aud_impl; static int i6f_aud_load(i6f_aud_impl *aud_lib) { - if (!(aud_lib->handle = dlopen("libmi_ai.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6f_aud] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(aud_lib->handle = dlopen("libmi_ai.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6f_aud", "Failed to load library!\nError: %s\n", dlerror()); if (!(aud_lib->fnDisableDevice = (int(*)(int device)) - dlsym(aud_lib->handle, "MI_AI_Disable"))) { - fprintf(stderr, "[i6f_aud] Failed to acquire symbol MI_AI_Disable!\n"); + hal_symbol_load("i6f_aud", aud_lib->handle, "MI_AI_Disable"))) return EXIT_FAILURE; - } if (!(aud_lib->fnEnableDevice = (int(*)(int device)) - dlsym(aud_lib->handle, "MI_AI_Enable"))) { - fprintf(stderr, "[i6f_aud] Failed to acquire symbol MI_AI_Enable!\n"); + hal_symbol_load("i6f_aud", aud_lib->handle, "MI_AI_Enable"))) return EXIT_FAILURE; - } if (!(aud_lib->fnSetDeviceConfig = (int(*)(int device, i6f_aud_cnf *config)) - dlsym(aud_lib->handle, "MI_AI_SetPubAttr"))) { - fprintf(stderr, "[i6f_aud] Failed to acquire symbol MI_AI_SetPubAttr!\n"); + hal_symbol_load("i6f_aud", aud_lib->handle, "MI_AI_SetPubAttr"))) return EXIT_FAILURE; - } if (!(aud_lib->fnDisableChannel = (int(*)(int device, int channel)) - dlsym(aud_lib->handle, "MI_AI_DisableChn"))) { - fprintf(stderr, "[i6f_aud] Failed to acquire symbol MI_AI_DisableChn!\n"); + hal_symbol_load("i6f_aud", aud_lib->handle, "MI_AI_DisableChn"))) return EXIT_FAILURE; - } if (!(aud_lib->fnEnableChannel = (int(*)(int device, int channel)) - dlsym(aud_lib->handle, "MI_AI_EnableChn"))) { - fprintf(stderr, "[i6f_aud] Failed to acquire symbol MI_AI_EnableChn!\n"); + hal_symbol_load("i6f_aud", aud_lib->handle, "MI_AI_EnableChn"))) return EXIT_FAILURE; - } if (!(aud_lib->fnDisableEncoding = (int(*)(int device, int channel)) - dlsym(aud_lib->handle, "MI_AI_DisableAenc"))) { - fprintf(stderr, "[i6f_aud] Failed to acquire symbol MI_AI_DisableChn!\n"); + hal_symbol_load("i6f_aud", aud_lib->handle, "MI_AI_DisableAenc"))) return EXIT_FAILURE; - } if (!(aud_lib->fnEnableEncoding = (int(*)(int device, int channel)) - dlsym(aud_lib->handle, "MI_AI_EnableAenc"))) { - fprintf(stderr, "[i6f_aud] Failed to acquire symbol MI_AI_EnableChn!\n"); + hal_symbol_load("i6f_aud", aud_lib->handle, "MI_AI_EnableAenc"))) return EXIT_FAILURE; - } if (!(aud_lib->fnSetEncodingParam = (int(*)(int device, int channel, i6f_aud_para *param)) - dlsym(aud_lib->handle, "MI_AI_SetAencAttr"))) { - fprintf(stderr, "[i6f_aud] Failed to acquire symbol MI_AI_SetAencAttr!\n"); + hal_symbol_load("i6f_aud", aud_lib->handle, "MI_AI_SetAencAttr"))) return EXIT_FAILURE; - } if (!(aud_lib->fnSetMute = (int(*)(int device, int channel, char active)) - dlsym(aud_lib->handle, "MI_AI_SetMute"))) { - fprintf(stderr, "[i6f_aud] Failed to acquire symbol MI_AI_SetMute!\n"); + hal_symbol_load("i6f_aud", aud_lib->handle, "MI_AI_SetMute"))) return EXIT_FAILURE; - } if (!(aud_lib->fnSetVolume = (int(*)(int device, int channel, int dbLevel)) - dlsym(aud_lib->handle, "MI_AI_SetVqeVolume"))) { - fprintf(stderr, "[i6f_aud] Failed to acquire symbol MI_AI_SetVqeVolume!\n"); + hal_symbol_load("i6f_aud", aud_lib->handle, "MI_AI_SetVqeVolume"))) return EXIT_FAILURE; - } if (!(aud_lib->fnFreeFrame = (int(*)(int device, int channel, i6f_aud_frm *frame, i6f_aud_efrm *encFrame)) - dlsym(aud_lib->handle, "MI_AI_ReleaseFrame"))) { - fprintf(stderr, "[i6f_aud] Failed to acquire symbol MI_AI_ReleaseFrame!\n"); + hal_symbol_load("i6f_aud", aud_lib->handle, "MI_AI_ReleaseFrame"))) return EXIT_FAILURE; - } if (!(aud_lib->fnGetFrame = (int(*)(int device, int channel, i6f_aud_frm *frame, i6f_aud_efrm *encFrame, int millis)) - dlsym(aud_lib->handle, "MI_AI_GetFrame"))) { - fprintf(stderr, "[i6f_aud] Failed to acquire symbol MI_AI_GetFrame!\n"); + hal_symbol_load("i6f_aud", aud_lib->handle, "MI_AI_GetFrame"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6f_common.h b/src/hal/star/i6f_common.h index dad1d26..10d473f 100644 --- a/src/hal/star/i6f_common.h +++ b/src/hal/star/i6f_common.h @@ -6,16 +6,9 @@ #include #include +#include "../symbols.h" #include "../types.h" -#define I6F_ERROR(x, ...) \ - do { \ - fprintf(stderr, "[i6f_hal] \033[31m"); \ - fprintf(stderr, (x), ##__VA_ARGS__); \ - fprintf(stderr, "\033[0m"); \ - return EXIT_FAILURE; \ - } while (0) - typedef enum { I6F_BAYER_RG, I6F_BAYER_GR, diff --git a/src/hal/star/i6f_hal.c b/src/hal/star/i6f_hal.c index a84b6c8..3561d1b 100644 --- a/src/hal/star/i6f_hal.c +++ b/src/hal/star/i6f_hal.c @@ -126,7 +126,7 @@ void *i6f_audio_thread(void) while (keepRunning) { if (ret = i6f_aud.fnGetFrame(_i6f_aud_dev, _i6f_aud_chn, &frame, NULL, 128)) { - fprintf(stderr, "[i6f_aud] Getting the frame failed " + HAL_WARNING("i6f_aud", "Getting the frame failed " "with %#x!\n", ret); continue; } @@ -143,11 +143,11 @@ void *i6f_audio_thread(void) if (ret = i6f_aud.fnFreeFrame(_i6f_aud_dev, _i6f_aud_chn, &frame, NULL)) { - fprintf(stderr, "[i6f_aud] Releasing the frame failed" + HAL_WARNING("i6f_aud", "Releasing the frame failed" " with %#x!\n", ret); } } - fprintf(stderr, "[i6f_aud] Shutting down capture thread...\n"); + HAL_INFO("i6f_aud", "Shutting down capture thread...\n"); } int i6f_channel_bind(char index, char framerate) @@ -432,12 +432,12 @@ int i6f_region_create(char handle, hal_rect rect, short opacity) region.size.height = rect.height; if (i6f_rgn.fnGetRegionConfig(0, handle, ®ionCurr)) { - fprintf(stderr, "[i6f_rgn] Creating region %d...\n", handle); + HAL_INFO("i6f_rgn", "Creating region %d...\n", handle); if (ret = i6f_rgn.fnCreateRegion(0, handle, ®ion)) return ret; } else if (regionCurr.size.height != region.size.height || regionCurr.size.width != region.size.width) { - fprintf(stderr, "[i6f_rgn] Parameters are different, recreating " + HAL_INFO("i6f_rgn", "Parameters are different, recreating " "region %d...\n", handle); for (char i = 0; i < I6F_VENC_CHN_NUM; i++) { if (!i6f_state[i].enable) continue; @@ -450,10 +450,10 @@ int i6f_region_create(char handle, hal_rect rect, short opacity) } if (i6f_rgn.fnGetChannelConfig(0, handle, &channel, &attribCurr)) - fprintf(stderr, "[i6f_rgn] Attaching region %d...\n", handle); + HAL_INFO("i6f_rgn", "Attaching region %d...\n", handle); else if (attribCurr.point.x != rect.x || attribCurr.point.x != rect.y || attribCurr.osd.bgFgAlpha[1] != opacity) { - fprintf(stderr, "[i6f_rgn] Parameters are different, reattaching " + HAL_INFO("i6f_rgn", "Parameters are different, reattaching " "region %d...\n", handle); for (char i = 0; i < I6F_VENC_CHN_NUM; i++) { if (!i6f_state[i].enable) continue; @@ -536,7 +536,7 @@ int i6f_video_create(char index, hal_vidconfig *config) channel.rate.mjpgQp.quality = MAX(config->minQual, config->maxQual); break; default: - I6F_ERROR("MJPEG encoder can only support CBR or fixed QP modes!"); + HAL_ERROR("i6f_venc", "MJPEG encoder can only support CBR or fixed QP modes!"); } channel.attrib.mjpg.maxHeight = ALIGN_UP(config->height, 2); @@ -570,7 +570,7 @@ int i6f_video_create(char index, hal_vidconfig *config) .fpsNum = config->framerate, .fpsDen = 1, .interQual = config->maxQual, .predQual = config->minQual }; break; case HAL_VIDMODE_ABR: - I6F_ERROR("H.265 encoder does not support ABR mode!"); + HAL_ERROR("i6f_venc", "H.265 encoder does not support ABR mode!"); case HAL_VIDMODE_AVBR: channel.rate.mode = I6F_VENC_RATEMODE_H265AVBR; channel.rate.h265Avbr = (i6f_venc_rate_h26xvbr){ .gop = config->gop, @@ -578,7 +578,7 @@ int i6f_video_create(char index, hal_vidconfig *config) (unsigned int)(MAX(config->bitrate, config->maxBitrate)) << 10, .maxQual = config->maxQual, .minQual = config->minQual }; break; default: - I6F_ERROR("H.265 encoder does not support this mode!"); + HAL_ERROR("i6f_venc", "H.265 encoder does not support this mode!"); } } else if (config->codec == HAL_VIDCODEC_H264) { channel.attrib.codec = I6F_VENC_CODEC_H264; @@ -613,9 +613,9 @@ int i6f_video_create(char index, hal_vidconfig *config) (unsigned int)(MAX(config->bitrate, config->maxBitrate)) << 10, .maxQual = config->maxQual, .minQual = config->minQual }; break; default: - I6F_ERROR("H.264 encoder does not support this mode!"); + HAL_ERROR("i6f_venc", "H.264 encoder does not support this mode!"); } - } else I6F_ERROR("This codec is not supported by the hardware!"); + } else HAL_ERROR("i6f_venc", "This codec is not supported by the hardware!"); _i6f_venc_dev[index] = I6F_VENC_DEV_H26X_0; attrib->maxHeight = config->height; attrib->maxWidth = config->width; @@ -693,7 +693,7 @@ int i6f_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg) int ret; if (ret = i6f_channel_bind(index, 1)) { - fprintf(stderr, "[i6f_venc] Binding the encoder channel " + HAL_DANGER("i6f_venc", "Binding the encoder channel " "%d failed with %#x!\n", index, ret); goto abort; } @@ -702,7 +702,7 @@ int i6f_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg) i6f_venc_jpg param; memset(¶m, 0, sizeof(param)); if (ret = i6f_venc.fnGetJpegParam(_i6f_venc_dev[index], index, ¶m)) { - fprintf(stderr, "[i6f_venc] Reading the JPEG settings " + HAL_DANGER("i6f_venc", "Reading the JPEG settings " "%d failed with %#x!\n", index, ret); goto abort; } @@ -710,14 +710,14 @@ int i6f_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg) return ret; param.quality = quality; if (ret = i6f_venc.fnSetJpegParam(_i6f_venc_dev[index], index, ¶m)) { - fprintf(stderr, "[i6f_venc] Writing the JPEG settings " + HAL_DANGER("i6f_venc", "Writing the JPEG settings " "%d failed with %#x!\n", index, ret); goto abort; } unsigned int count = 1; if (i6f_venc.fnStartReceivingEx(_i6f_venc_dev[index], index, &count)) { - fprintf(stderr, "[i6f_venc] Requesting one frame " + HAL_DANGER("i6f_venc", "Requesting one frame " "%d failed with %#x!\n", index, ret); goto abort; } @@ -730,23 +730,23 @@ int i6f_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg) FD_SET(fd, &readFds); ret = select(fd + 1, &readFds, NULL, NULL, &timeout); if (ret < 0) { - fprintf(stderr, "[i6f_venc] Select operation failed!\n"); + HAL_DANGER("i6f_venc", "Select operation failed!\n"); goto abort; } else if (ret == 0) { - fprintf(stderr, "[i6f_venc] Capture stream timed out!\n"); + HAL_DANGER("i6f_venc", "Capture stream timed out!\n"); goto abort; } if (FD_ISSET(fd, &readFds)) { i6f_venc_stat stat; if (i6f_venc.fnQuery(_i6f_venc_dev[index], index, &stat)) { - fprintf(stderr, "[i6f_venc] Querying the encoder channel " + HAL_DANGER("i6f_venc", "Querying the encoder channel " "%d failed with %#x!\n", index, ret); goto abort; } if (!stat.curPacks) { - fprintf(stderr, "[i6f_venc] Current frame is empty, skipping it!\n"); + HAL_DANGER("i6f_venc", "Current frame is empty, skipping it!\n"); goto abort; } @@ -754,13 +754,13 @@ int i6f_video_snapshot_grab(char index, char quality, hal_jpegdata *jpeg) memset(&strm, 0, sizeof(strm)); strm.packet = (i6f_venc_pack*)malloc(sizeof(i6f_venc_pack) * stat.curPacks); if (!strm.packet) { - fprintf(stderr, "[i6f_venc] Memory allocation on channel %d failed!\n", index); + HAL_DANGER("i6f_venc", "Memory allocation on channel %d failed!\n", index); goto abort; } strm.count = stat.curPacks; if (ret = i6f_venc.fnGetStream(_i6f_venc_dev[index], index, &strm, stat.curPacks)) { - fprintf(stderr, "[i6f_venc] Getting the stream on " + HAL_DANGER("i6f_venc", "Getting the stream on " "channel %d failed with %#x!\n", index, ret); free(strm.packet); strm.packet = NULL; @@ -808,7 +808,7 @@ void *i6f_video_thread(void) ret = i6f_venc.fnGetDescriptor(_i6f_venc_dev[i], i); if (ret < 0) { - fprintf(stderr, "[i6f_venc] Getting the encoder descriptor failed with %#x!\n", ret); + HAL_DANGER("i6f_venc", "Getting the encoder descriptor failed with %#x!\n", ret); return NULL; } i6f_state[i].fileDesc = ret; @@ -834,10 +834,10 @@ void *i6f_video_thread(void) timeout.tv_usec = 0; ret = select(maxFd + 1, &readFds, NULL, NULL, &timeout); if (ret < 0) { - fprintf(stderr, "[i6f_venc] Select operation failed!\n"); + HAL_DANGER("i6f_venc", "Select operation failed!\n"); break; } else if (ret == 0) { - fprintf(stderr, "[i6f_venc] Main stream loop timed out!\n"); + HAL_WARNING("i6f_venc", "Main stream loop timed out!\n"); continue; } else { for (int i = 0; i < I6F_VENC_CHN_NUM; i++) { @@ -848,26 +848,26 @@ void *i6f_video_thread(void) memset(&stream, 0, sizeof(stream)); if (ret = i6f_venc.fnQuery(_i6f_venc_dev[i], i, &stat)) { - fprintf(stderr, "[i6f_venc] Querying the encoder channel " + HAL_DANGER("i6f_venc", "Querying the encoder channel " "%d failed with %#x!\n", i, ret); break; } if (!stat.curPacks) { - fprintf(stderr, "[i6f_venc] Current frame is empty, skipping it!\n"); + HAL_WARNING("i6f_venc", "Current frame is empty, skipping it!\n"); continue; } stream.packet = (i6f_venc_pack*)malloc( sizeof(i6f_venc_pack) * stat.curPacks); if (!stream.packet) { - fprintf(stderr, "[i6f_venc] Memory allocation on channel %d failed!\n", i); + HAL_DANGER("i6f_venc", "Memory allocation on channel %d failed!\n", i); break; } stream.count = stat.curPacks; if (ret = i6f_venc.fnGetStream(_i6f_venc_dev[i], i, &stream, 40)) { - fprintf(stderr, "[i6f_venc] Getting the stream on " + HAL_DANGER("i6f_venc", "Getting the stream on " "channel %d failed with %#x!\n", i, ret); break; } @@ -911,17 +911,16 @@ void *i6f_video_thread(void) (*i6f_vid_cb)(i, &outStrm); } - if (ret = i6f_venc.fnFreeStream(_i6f_venc_dev[i], i, &stream)) { - fprintf(stderr, "[i6f_venc] Releasing the stream on " + if (ret = i6f_venc.fnFreeStream(_i6f_venc_dev[i], i, &stream)) + HAL_WARNING("i6f_venc", "Releasing the stream on " "channel %d failed with %#x!\n", i, ret); - } free(stream.packet); stream.packet = NULL; } } } } - fprintf(stderr, "[i6f_venc] Shutting down encoding thread...\n"); + HAL_INFO("i6f_venc", "Shutting down encoding thread...\n"); } void i6f_system_deinit(void) diff --git a/src/hal/star/i6f_isp.h b/src/hal/star/i6f_isp.h index 356ffa8..f9aaf2f 100644 --- a/src/hal/star/i6f_isp.h +++ b/src/hal/star/i6f_isp.h @@ -50,92 +50,63 @@ typedef struct { } i6f_isp_impl; static int i6f_isp_load(i6f_isp_impl *isp_lib) { - if (!(isp_lib->handleIspAlgo = dlopen("libispalgo.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6f_isp] Failed to load dependency library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(isp_lib->handleIspAlgo = dlopen("libispalgo.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6f_isp", "Failed to load dependency library!\nError: %s\n", dlerror()); + - if (!(isp_lib->handleCus3a = dlopen("libcus3a.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6f_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))) { - fprintf(stderr, "[i6f_isp] Failed to load library!\nError: %s\n", dlerror()); + 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)) - dlsym(isp_lib->handle, "MI_ISP_CreateDevice"))) { - fprintf(stderr, "[i6f_isp] Failed to acquire symbol MI_ISP_CreateDevice!\n"); + hal_symbol_load("i6f_isp", isp_lib->handle, "MI_ISP_CreateDevice"))) return EXIT_FAILURE; - } if (!(isp_lib->fnDestroyDevice = (int(*)(int device)) - dlsym(isp_lib->handle, "MI_ISP_DestoryDevice"))) { - fprintf(stderr, "[i6f_isp] Failed to acquire symbol MI_ISP_DestoryDevice!\n"); + hal_symbol_load("i6f_isp", isp_lib->handle, "MI_ISP_DestoryDevice"))) return EXIT_FAILURE; - } if (!(isp_lib->fnCreateChannel = (int(*)(int device, int channel, i6f_isp_chn *config)) - dlsym(isp_lib->handle, "MI_ISP_CreateChannel"))) { - fprintf(stderr, "[i6f_isp] Failed to acquire symbol MI_ISP_CreateChannel!\n"); + hal_symbol_load("i6f_isp", isp_lib->handle, "MI_ISP_CreateChannel"))) return EXIT_FAILURE; - } if (!(isp_lib->fnDestroyChannel = (int(*)(int device, int channel)) - dlsym(isp_lib->handle, "MI_ISP_DestroyChannel"))) { - fprintf(stderr, "[i6f_isp] Failed to acquire symbol MI_ISP_DestroyChannel!\n"); + hal_symbol_load("i6f_isp", isp_lib->handle, "MI_ISP_DestroyChannel"))) return EXIT_FAILURE; - } if (!(isp_lib->fnLoadChannelConfig = (int(*)(int device, int channel, char *path, unsigned int key)) - dlsym(isp_lib->handle, "MI_ISP_ALGO_API_CmdLoadBinFile"))) { - fprintf(stderr, "[i6f_isp] Failed to acquire symbol MI_ISP_ALGO_API_CmdLoadBinFile!\n"); + hal_symbol_load("i6f_isp", isp_lib->handle, "MI_ISP_ALGO_API_CmdLoadBinFile"))) return EXIT_FAILURE; - } if (!(isp_lib->fnSetChannelParam = (int(*)(int device, int channel, i6f_isp_para *config)) - dlsym(isp_lib->handle, "MI_ISP_SetChnParam"))) { - fprintf(stderr, "[i6f_isp] Failed to acquire symbol MI_ISP_SetChnParam!\n"); + hal_symbol_load("i6f_isp", isp_lib->handle, "MI_ISP_SetChnParam"))) return EXIT_FAILURE; - } if (!(isp_lib->fnStartChannel = (int(*)(int device, int channel)) - dlsym(isp_lib->handle, "MI_ISP_StartChannel"))) { - fprintf(stderr, "[i6f_isp] Failed to acquire symbol MI_ISP_StartChannel!\n"); + hal_symbol_load("i6f_isp", isp_lib->handle, "MI_ISP_StartChannel"))) return EXIT_FAILURE; - } if (!(isp_lib->fnStopChannel = (int(*)(int device, int channel)) - dlsym(isp_lib->handle, "MI_ISP_StopChannel"))) { - fprintf(stderr, "[i6f_isp] Failed to acquire symbol MI_ISP_StopChannel!\n"); + hal_symbol_load("i6f_isp", isp_lib->handle, "MI_ISP_StopChannel"))) return EXIT_FAILURE; - } if (!(isp_lib->fnDisablePort = (int(*)(int device, int channel, int port)) - dlsym(isp_lib->handle, "MI_ISP_DisableOutputPort"))) { - fprintf(stderr, "[i6f_isp] Failed to acquire symbol MI_ISP_DisableOutputPort!\n"); + hal_symbol_load("i6f_isp", isp_lib->handle, "MI_ISP_DisableOutputPort"))) return EXIT_FAILURE; - } if (!(isp_lib->fnEnablePort = (int(*)(int device, int channel, int port)) - dlsym(isp_lib->handle, "MI_ISP_EnableOutputPort"))) { - fprintf(stderr, "[i6f_isp] Failed to acquire symbol MI_ISP_EnableOutputPort!\n"); + hal_symbol_load("i6f_isp", isp_lib->handle, "MI_ISP_EnableOutputPort"))) return EXIT_FAILURE; - } if (!(isp_lib->fnSetPortConfig = (int(*)(int device, int channel, int port, i6f_isp_port *config)) - dlsym(isp_lib->handle, "MI_ISP_SetOutputPortParam"))) { - fprintf(stderr, "[i6f_isp] Failed to acquire symbol MI_ISP_SetOutputPortParam!\n"); + hal_symbol_load("i6f_isp", isp_lib->handle, "MI_ISP_SetOutputPortParam"))) return EXIT_FAILURE; - } if (!(isp_lib->fnSetColorToGray = (int(*)(int device, int channel, char *enable)) - dlsym(isp_lib->handle, "MI_ISP_IQ_SetColorToGray"))) { - fprintf(stderr, "[i6f_isp] Failed to acquire symbol MI_ISP_IQ_SetColorToGray!\n"); + hal_symbol_load("i6f_isp", isp_lib->handle, "MI_ISP_IQ_SetColorToGray"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6f_rgn.h b/src/hal/star/i6f_rgn.h index 2899e11..a16a446 100644 --- a/src/hal/star/i6f_rgn.h +++ b/src/hal/star/i6f_rgn.h @@ -105,70 +105,49 @@ typedef struct { } i6f_rgn_impl; static int i6f_rgn_load(i6f_rgn_impl *rgn_lib) { - if (!(rgn_lib->handle = dlopen("libmi_rgn.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6f_rgn] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(rgn_lib->handle = dlopen("libmi_rgn.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6f_rgn", "Failed to load library!\nError: %s\n", dlerror()); + if (!(rgn_lib->fnDeinit = (int(*)(unsigned short chip)) - dlsym(rgn_lib->handle, "MI_RGN_DeInit"))) { - fprintf(stderr, "[i6f_rgn] Failed to acquire symbol MI_RGN_DeInit!\n"); + hal_symbol_load("i6f_rgn", rgn_lib->handle, "MI_RGN_DeInit"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnInit = (int(*)(unsigned short chip, i6f_rgn_pal *palette)) - dlsym(rgn_lib->handle, "MI_RGN_Init"))) { - fprintf(stderr, "[i6f_rgn] Failed to acquire symbol MI_RGN_Init!\n"); + hal_symbol_load("i6f_rgn", rgn_lib->handle, "MI_RGN_Init"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnCreateRegion = (int(*)(unsigned short chip, unsigned int handle, i6f_rgn_cnf *config)) - dlsym(rgn_lib->handle, "MI_RGN_Create"))) { - fprintf(stderr, "[i6f_rgn] Failed to acquire symbol MI_RGN_Create!\n"); + hal_symbol_load("i6f_rgn", rgn_lib->handle, "MI_RGN_Create"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnGetRegionConfig = (int(*)(unsigned short chip, unsigned int handle, i6f_rgn_cnf *config)) - dlsym(rgn_lib->handle, "MI_RGN_GetAttr"))) { - fprintf(stderr, "[i6f_rgn] Failed to acquire symbol MI_RGN_GetAttr!\n"); + hal_symbol_load("i6f_rgn", rgn_lib->handle, "MI_RGN_GetAttr"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnDestroyRegion = (int(*)(unsigned short chip, unsigned int handle)) - dlsym(rgn_lib->handle, "MI_RGN_Destroy"))) { - fprintf(stderr, "[i6f_rgn] Failed to acquire symbol MI_RGN_Destroy!\n"); + hal_symbol_load("i6f_rgn", rgn_lib->handle, "MI_RGN_Destroy"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnAttachChannel = (int(*)(unsigned short chip, unsigned int handle, i6f_sys_bind *dest, i6f_rgn_chn *config)) - dlsym(rgn_lib->handle, "MI_RGN_AttachToChn"))) { - fprintf(stderr, "[i6f_rgn] Failed to acquire symbol MI_RGN_AttachToChn!\n"); + hal_symbol_load("i6f_rgn", rgn_lib->handle, "MI_RGN_AttachToChn"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnDetachChannel = (int(*)(unsigned short chip, unsigned int handle, i6f_sys_bind *dest)) - dlsym(rgn_lib->handle, "MI_RGN_DetachFromChn"))) { - fprintf(stderr, "[i6f_rgn] Failed to acquire symbol MI_RGN_DetachFromChn!\n"); + hal_symbol_load("i6f_rgn", rgn_lib->handle, "MI_RGN_DetachFromChn"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnGetChannelConfig = (int(*)(unsigned short chip, unsigned int handle, i6f_sys_bind *dest, i6f_rgn_chn *config)) - dlsym(rgn_lib->handle, "MI_RGN_GetDisplayAttr"))) { - fprintf(stderr, "[i6f_rgn] Failed to acquire symbol MI_RGN_GetDisplayAttr!\n"); + hal_symbol_load("i6f_rgn", rgn_lib->handle, "MI_RGN_GetDisplayAttr"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnSetChannelConfig = (int(*)(unsigned short chip, unsigned int handle, i6f_sys_bind *dest, i6f_rgn_chn *config)) - dlsym(rgn_lib->handle, "MI_RGN_SetDisplayAttr"))) { - fprintf(stderr, "[i6f_rgn] Failed to acquire symbol MI_RGN_SetDisplayAttr!\n"); + hal_symbol_load("i6f_rgn", rgn_lib->handle, "MI_RGN_SetDisplayAttr"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnSetBitmap = (int(*)(unsigned short chip, unsigned int handle, i6f_rgn_bmp *bitmap)) - dlsym(rgn_lib->handle, "MI_RGN_SetBitMap"))) { - fprintf(stderr, "[i6f_rgn] Failed to acquire symbol MI_RGN_SetBitMap!\n"); + hal_symbol_load("i6f_rgn", rgn_lib->handle, "MI_RGN_SetBitMap"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6f_scl.h b/src/hal/star/i6f_scl.h index ad8faa5..9c63b34 100644 --- a/src/hal/star/i6f_scl.h +++ b/src/hal/star/i6f_scl.h @@ -40,70 +40,48 @@ typedef struct { } i6f_scl_impl; static int i6f_scl_load(i6f_scl_impl *scl_lib) { - if (!(scl_lib->handle = dlopen("libmi_scl.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6f_scl] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(scl_lib->handle = dlopen("libmi_scl.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6f_scl", "Failed to load library!\nError: %s\n", dlerror()); if (!(scl_lib->fnCreateDevice = (int(*)(int device, unsigned int *binds)) - dlsym(scl_lib->handle, "MI_SCL_CreateDevice"))) { - fprintf(stderr, "[i6f_scl] Failed to acquire symbol MI_SCL_CreateDevice!\n"); + hal_symbol_load("i6f_scl", scl_lib->handle, "MI_SCL_CreateDevice"))) return EXIT_FAILURE; - } if (!(scl_lib->fnDestroyDevice = (int(*)(int device)) - dlsym(scl_lib->handle, "MI_SCL_DestroyDevice"))) { - fprintf(stderr, "[i6f_scl] Failed to acquire symbol MI_SCL_DestroyDevice!\n"); + hal_symbol_load("i6f_scl", scl_lib->handle, "MI_SCL_DestroyDevice"))) return EXIT_FAILURE; - } if (!(scl_lib->fnAdjustChannelRotation = (int(*)(int device, int channel, int *rotate)) - dlsym(scl_lib->handle, "MI_SCL_SetChnParam"))) { - fprintf(stderr, "[i6f_scl] Failed to acquire symbol MI_SCL_SetChnParam!\n"); + hal_symbol_load("i6f_scl", scl_lib->handle, "MI_SCL_SetChnParam"))) return EXIT_FAILURE; - } if (!(scl_lib->fnCreateChannel = (int(*)(int device, int channel, unsigned int *reserved)) - dlsym(scl_lib->handle, "MI_SCL_CreateChannel"))) { - fprintf(stderr, "[i6f_scl] Failed to acquire symbol MI_SCL_CreateChannel!\n"); + hal_symbol_load("i6f_scl", scl_lib->handle, "MI_SCL_CreateChannel"))) return EXIT_FAILURE; - } if (!(scl_lib->fnDestroyChannel = (int(*)(int device, int channel)) - dlsym(scl_lib->handle, "MI_SCL_DestroyChannel"))) { - fprintf(stderr, "[i6f_scl] Failed to acquire symbol MI_SCL_DestroyChannel!\n"); + hal_symbol_load("i6f_scl", scl_lib->handle, "MI_SCL_DestroyChannel"))) return EXIT_FAILURE; - } if (!(scl_lib->fnStartChannel = (int(*)(int device, int channel)) - dlsym(scl_lib->handle, "MI_SCL_StartChannel"))) { - fprintf(stderr, "[i6f_scl] Failed to acquire symbol MI_SCL_StartChannel!\n"); + hal_symbol_load("i6f_scl", scl_lib->handle, "MI_SCL_StartChannel"))) return EXIT_FAILURE; - } if (!(scl_lib->fnStopChannel = (int(*)(int device, int channel)) - dlsym(scl_lib->handle, "MI_SCL_StopChannel"))) { - fprintf(stderr, "[i6f_scl] Failed to acquire symbol MI_SCL_StopChannel!\n"); + hal_symbol_load("i6f_scl", scl_lib->handle, "MI_SCL_StopChannel"))) return EXIT_FAILURE; - } if (!(scl_lib->fnDisablePort = (int(*)(int device, int channel, int port)) - dlsym(scl_lib->handle, "MI_SCL_DisableOutputPort"))) { - fprintf(stderr, "[i6f_scl] Failed to acquire symbol MI_SCL_DisableOutputPort!\n"); + hal_symbol_load("i6f_scl", scl_lib->handle, "MI_SCL_DisableOutputPort"))) return EXIT_FAILURE; - } if (!(scl_lib->fnEnablePort = (int(*)(int device, int channel, int port)) - dlsym(scl_lib->handle, "MI_SCL_EnableOutputPort"))) { - fprintf(stderr, "[i6f_scl] Failed to acquire symbol MI_SCL_EnableOutputPort!\n"); + hal_symbol_load("i6f_scl", scl_lib->handle, "MI_SCL_EnableOutputPort"))) return EXIT_FAILURE; - } if (!(scl_lib->fnSetPortConfig = (int(*)(int device, int channel, int port, i6f_scl_port *config)) - dlsym(scl_lib->handle, "MI_SCL_SetOutputPortParam"))) { - fprintf(stderr, "[i6f_scl] Failed to acquire symbol MI_SCL_SetOutputPortParam!\n"); + hal_symbol_load("i6f_scl", scl_lib->handle, "MI_SCL_SetOutputPortParam"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6f_snr.h b/src/hal/star/i6f_snr.h index fec3fdb..61e9236 100644 --- a/src/hal/star/i6f_snr.h +++ b/src/hal/star/i6f_snr.h @@ -99,70 +99,48 @@ typedef struct { } i6f_snr_impl; static int i6f_snr_load(i6f_snr_impl *snr_lib) { - if (!(snr_lib->handle = dlopen("libmi_sensor.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6f_snr] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(snr_lib->handle = dlopen("libmi_sensor.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6f_snr", "Failed to load library!\nError: %s\n", dlerror()); if (!(snr_lib->fnDisable = (int(*)(unsigned int sensor)) - dlsym(snr_lib->handle, "MI_SNR_Disable"))) { - fprintf(stderr, "[i6f_snr] Failed to acquire symbol MI_SNR_Disable!\n"); + hal_symbol_load("i6f_snr", snr_lib->handle, "MI_SNR_Disable"))) return EXIT_FAILURE; - } if (!(snr_lib->fnEnable = (int(*)(unsigned int sensor)) - dlsym(snr_lib->handle, "MI_SNR_Enable"))) { - fprintf(stderr, "[i6f_snr] Failed to acquire symbol MI_SNR_Enable!\n"); + hal_symbol_load("i6f_snr", snr_lib->handle, "MI_SNR_Enable"))) return EXIT_FAILURE; - } if (!(snr_lib->fnSetFramerate = (int(*)(unsigned int sensor, unsigned int framerate)) - dlsym(snr_lib->handle, "MI_SNR_SetFps"))) { - fprintf(stderr, "[i6f_snr] Failed to acquire symbol MI_SNR_SetFps!\n"); + hal_symbol_load("i6f_snr", snr_lib->handle, "MI_SNR_SetFps"))) return EXIT_FAILURE; - } if (!(snr_lib->fnGetPadInfo = (int(*)(unsigned int sensor, i6f_snr_pad *info)) - dlsym(snr_lib->handle, "MI_SNR_GetPadInfo"))) { - fprintf(stderr, "[i6f_snr] Failed to acquire symbol MI_SNR_GetPadInfo!\n"); + hal_symbol_load("i6f_snr", snr_lib->handle, "MI_SNR_GetPadInfo"))) return EXIT_FAILURE; - } if (!(snr_lib->fnGetPlaneInfo = (int(*)(unsigned int sensor, unsigned int index, i6f_snr_plane *info)) - dlsym(snr_lib->handle, "MI_SNR_GetPlaneInfo"))) { - fprintf(stderr, "[i6f_snr] Failed to acquire symbol MI_SNR_GetPlaneInfo!\n"); + hal_symbol_load("i6f_snr", snr_lib->handle, "MI_SNR_GetPlaneInfo"))) return EXIT_FAILURE; - } if (!(snr_lib->fnSetPlaneMode = (int(*)(unsigned int sensor, unsigned char active)) - dlsym(snr_lib->handle, "MI_SNR_SetPlaneMode"))) { - fprintf(stderr, "[i6f_snr] Failed to acquire symbol MI_SNR_SetPlaneMode!\n"); + hal_symbol_load("i6f_snr", snr_lib->handle, "MI_SNR_SetPlaneMode"))) return EXIT_FAILURE; - } if (!(snr_lib->fnCurrentResolution = (int(*)(unsigned int sensor, unsigned char *index, i6f_snr_res *resolution)) - dlsym(snr_lib->handle, "MI_SNR_GetCurRes"))) { - fprintf(stderr, "[i6f_snr] Failed to acquire symbol MI_SNR_GetCurRes!\n"); + hal_symbol_load("i6f_snr", snr_lib->handle, "MI_SNR_GetCurRes"))) return EXIT_FAILURE; - } if (!(snr_lib->fnGetResolution = (int(*)(unsigned int sensor, unsigned char index, i6f_snr_res *resolution)) - dlsym(snr_lib->handle, "MI_SNR_GetRes"))) { - fprintf(stderr, "[i6f_snr] Failed to acquire symbol MI_SNR_GetRes!\n"); + hal_symbol_load("i6f_snr", snr_lib->handle, "MI_SNR_GetRes"))) return EXIT_FAILURE; - } if (!(snr_lib->fnGetResolutionCount = (int(*)(unsigned int sensor, unsigned int *count)) - dlsym(snr_lib->handle, "MI_SNR_QueryResCount"))) { - fprintf(stderr, "[i6f_snr] Failed to acquire symbol MI_SNR_QueryResCount!\n"); + hal_symbol_load("i6f_snr", snr_lib->handle, "MI_SNR_QueryResCount"))) return EXIT_FAILURE; - } if (!(snr_lib->fnSetResolution = (int(*)(unsigned int sensor, unsigned char index)) - dlsym(snr_lib->handle, "MI_SNR_SetRes"))) { - fprintf(stderr, "[i6f_snr] Failed to acquire symbol MI_SNR_SetRes!\n"); + hal_symbol_load("i6f_snr", snr_lib->handle, "MI_SNR_SetRes"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6f_sys.h b/src/hal/star/i6f_sys.h index 1e295db..3aac593 100644 --- a/src/hal/star/i6f_sys.h +++ b/src/hal/star/i6f_sys.h @@ -129,66 +129,45 @@ typedef struct { } i6f_sys_impl; static int i6f_sys_load(i6f_sys_impl *sys_lib) { - if (!(sys_lib->handleCamOsWrapper = dlopen("libcam_os_wrapper.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6f_sys] Failed to load dependency library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(sys_lib->handleCamOsWrapper = dlopen("libcam_os_wrapper.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6f_sys", "Failed to load dependency library!\nError: %s\n", dlerror()); - if (!(sys_lib->handle = dlopen("libmi_sys.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6f_sys] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(sys_lib->handle = dlopen("libmi_sys.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6f_sys", "Failed to load library!\nError: %s\n", dlerror()); if (!(sys_lib->fnExit = (int(*)(unsigned short chip)) - dlsym(sys_lib->handle, "MI_SYS_Exit"))) { - fprintf(stderr, "[i6f_sys] Failed to acquire symbol MI_SYS_Exit!\n"); + hal_symbol_load("i6f_sys", sys_lib->handle, "MI_SYS_Exit"))) return EXIT_FAILURE; - } if (!(sys_lib->fnGetVersion = (int(*)(unsigned short chip, i6f_sys_ver *version)) - dlsym(sys_lib->handle, "MI_SYS_GetVersion"))) { - fprintf(stderr, "[i6f_sys] Failed to acquire symbol MI_SYS_GetVersion!\n"); + hal_symbol_load("i6f_venc", sys_lib->handle, "MI_SYS_GetVersion"))) return EXIT_FAILURE; - } if (!(sys_lib->fnInit = (int(*)(unsigned short chip)) - dlsym(sys_lib->handle, "MI_SYS_Init"))) { - fprintf(stderr, "[i6f_sys] Failed to acquire symbol MI_SYS_Init!\n"); + hal_symbol_load("i6f_venc", sys_lib->handle, "MI_SYS_Init"))) return EXIT_FAILURE; - } if (!(sys_lib->fnBind = (int(*)(unsigned short chip, i6f_sys_bind *source, i6f_sys_bind *dest, i6f_sys_link *link)) - dlsym(sys_lib->handle, "MI_SYS_BindChnPort"))) { - fprintf(stderr, "[i6f_sys] Failed to acquire symbol MI_SYS_BindChnPort!\n"); + hal_symbol_load("i6f_venc", sys_lib->handle, "MI_SYS_BindChnPort"))) return EXIT_FAILURE; - } if (!(sys_lib->fnBindExt = (int(*)(unsigned short chip, i6f_sys_bind *source, i6f_sys_bind *dest, unsigned int srcFps, unsigned int dstFps, i6f_sys_link link, unsigned int linkParam)) - dlsym(sys_lib->handle, "MI_SYS_BindChnPort2"))) { - fprintf(stderr, "[i6f_sys] Failed to acquire symbol MI_SYS_BindChnPort2!\n"); + hal_symbol_load("i6f_venc", sys_lib->handle, "MI_SYS_BindChnPort2"))) return EXIT_FAILURE; - } if (!(sys_lib->fnSetOutputDepth = (int(*)(unsigned short chip, i6f_sys_bind *bind, unsigned int usrDepth, unsigned int bufDepth)) - dlsym(sys_lib->handle, "MI_SYS_SetChnOutputPortDepth"))) { - fprintf(stderr, "[i6f_sys] Failed to acquire symbol MI_SYS_SetChnOutputPortDepth!\n"); + hal_symbol_load("i6f_venc", sys_lib->handle, "MI_SYS_SetChnOutputPortDepth"))) return EXIT_FAILURE; - } - if (!(sys_lib->fnUnbind = (int(*)(unsigned short chip, i6f_sys_bind *source, i6f_sys_bind *dest)) - dlsym(sys_lib->handle, "MI_SYS_UnBindChnPort"))) { - fprintf(stderr, "[i6f_sys] Failed to acquire symbol MI_SYS_UnBindChnPort!\n"); + hal_symbol_load("i6f_venc", sys_lib->handle, "MI_SYS_UnBindChnPort"))) return EXIT_FAILURE; - } if (!(sys_lib->fnConfigPool = (int(*)(unsigned short chip, i6f_sys_pool *config)) - dlsym(sys_lib->handle, "MI_SYS_ConfigPrivateMMAPool"))) { - fprintf(stderr, "[i6f_sys] Failed to acquire symbol MI_SYS_ConfigPrivateMMAPool!\n"); + hal_symbol_load("i6f_venc", sys_lib->handle, "MI_SYS_ConfigPrivateMMAPool"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6f_venc.h b/src/hal/star/i6f_venc.h index 7f9eaf0..d820561 100644 --- a/src/hal/star/i6f_venc.h +++ b/src/hal/star/i6f_venc.h @@ -306,124 +306,84 @@ typedef struct { } i6f_venc_impl; static int i6f_venc_load(i6f_venc_impl *venc_lib) { - if (!(venc_lib->handle = dlopen("libmi_venc.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6f_venc] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(venc_lib->handle = dlopen("libmi_venc.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6f_venc", "Failed to load library!\nError: %s\n", dlerror()); if (!(venc_lib->fnCreateDevice = (int(*)(unsigned int device, i6f_venc_init *config)) - dlsym(venc_lib->handle, "MI_VENC_CreateDev"))) { - fprintf(stderr, "[i6f_venc] Failed to acquire symbol MI_VENC_CreateDev!\n"); + hal_symbol_load("i6f_venc", venc_lib->handle, "MI_VENC_CreateDev"))) return EXIT_FAILURE; - } if (!(venc_lib->fnDestroyDevice = (int(*)(unsigned int device)) - dlsym(venc_lib->handle, "MI_VENC_DestroyDev"))) { - fprintf(stderr, "[i6f_venc] Failed to acquire symbol MI_VENC_DestroyDev!\n"); + hal_symbol_load("i6f_venc", venc_lib->handle, "MI_VENC_DestroyDev"))) return EXIT_FAILURE; - } if (!(venc_lib->fnCreateChannel = (int(*)(unsigned int device, unsigned int channel, i6f_venc_chn *config)) - dlsym(venc_lib->handle, "MI_VENC_CreateChn"))) { - fprintf(stderr, "[i6f_venc] Failed to acquire symbol MI_VENC_CreateChn!\n"); + hal_symbol_load("i6f_venc", venc_lib->handle, "MI_VENC_CreateChn"))) return EXIT_FAILURE; - } if (!(venc_lib->fnDestroyChannel = (int(*)(unsigned int device, unsigned int channel)) - dlsym(venc_lib->handle, "MI_VENC_DestroyChn"))) { - fprintf(stderr, "[i6f_venc] Failed to acquire symbol MI_VENC_DestroyChn!\n"); + hal_symbol_load("i6f_venc", venc_lib->handle, "MI_VENC_DestroyChn"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetChannelConfig = (int(*)(unsigned int device, unsigned int channel, i6f_venc_chn *config)) - dlsym(venc_lib->handle, "MI_VENC_GetChnAttr"))) { - fprintf(stderr, "[i6f_venc] Failed to acquire symbol MI_VENC_GetChnAttr!\n"); + hal_symbol_load("i6f_venc", venc_lib->handle, "MI_VENC_GetChnAttr"))) return EXIT_FAILURE; - } if (!(venc_lib->fnResetChannel = (int(*)(unsigned int device, unsigned int channel)) - dlsym(venc_lib->handle, "MI_VENC_ResetChn"))) { - fprintf(stderr, "[i6f_venc] Failed to acquire symbol MI_VENC_ResetChn!\n"); + hal_symbol_load("i6f_venc", venc_lib->handle, "MI_VENC_ResetChn"))) return EXIT_FAILURE; - } if (!(venc_lib->fnSetChannelConfig = (int(*)(unsigned int device, unsigned int channel, i6f_venc_chn *config)) - dlsym(venc_lib->handle, "MI_VENC_SetChnAttr"))) { - fprintf(stderr, "[i6f_venc] Failed to acquire symbol MI_VENC_SetChnAttr!\n"); + hal_symbol_load("i6f_venc", venc_lib->handle, "MI_VENC_SetChnAttr"))) return EXIT_FAILURE; - } if (!(venc_lib->fnFreeDescriptor = (int(*)(unsigned int device, unsigned int channel)) - dlsym(venc_lib->handle, "MI_VENC_CloseFd"))) { - fprintf(stderr, "[i6f_venc] Failed to acquire symbol MI_VENC_CloseFd!\n"); + hal_symbol_load("i6f_venc", venc_lib->handle, "MI_VENC_CloseFd"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetDescriptor = (int(*)(unsigned int device, unsigned int channel)) - dlsym(venc_lib->handle, "MI_VENC_GetFd"))) { - fprintf(stderr, "[i6f_venc] Failed to acquire symbol MI_VENC_GetFd!\n"); + hal_symbol_load("i6f_venc", venc_lib->handle, "MI_VENC_GetFd"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetJpegParam = (int(*)(unsigned int device, unsigned int channel, i6f_venc_jpg *param)) - dlsym(venc_lib->handle, "MI_VENC_GetJpegParam"))) { - fprintf(stderr, "[i6f_venc] Failed to acquire symbol MI_VENC_CloseFd!\n"); + hal_symbol_load("i6f_venc", venc_lib->handle, "MI_VENC_GetJpegParam"))) return EXIT_FAILURE; - } if (!(venc_lib->fnSetJpegParam = (int(*)(unsigned int device, unsigned int channel, i6f_venc_jpg *param)) - dlsym(venc_lib->handle, "MI_VENC_SetJpegParam"))) { - fprintf(stderr, "[i6f_venc] Failed to acquire symbol MI_VENC_GetFd!\n"); + hal_symbol_load("i6f_venc", venc_lib->handle, "MI_VENC_SetJpegParam"))) return EXIT_FAILURE; - } if (!(venc_lib->fnFreeStream = (int(*)(unsigned int device, unsigned int channel, i6f_venc_strm *stream)) - dlsym(venc_lib->handle, "MI_VENC_ReleaseStream"))) { - fprintf(stderr, "[i6f_venc] Failed to acquire symbol MI_VENC_ReleaseStream!\n"); + hal_symbol_load("i6f_venc", venc_lib->handle, "MI_VENC_ReleaseStream"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetStream = (int(*)(unsigned int device, unsigned int channel, i6f_venc_strm *stream, unsigned int timeout)) - dlsym(venc_lib->handle, "MI_VENC_GetStream"))) { - fprintf(stderr, "[i6f_venc] Failed to acquire symbol MI_VENC_GetStream!\n"); + hal_symbol_load("i6f_venc", venc_lib->handle, "MI_VENC_GetStream"))) return EXIT_FAILURE; - } if (!(venc_lib->fnQuery = (int(*)(unsigned int device, unsigned int channel, i6f_venc_stat *stats)) - dlsym(venc_lib->handle, "MI_VENC_Query"))) { - fprintf(stderr, "[i6f_venc] Failed to acquire symbol MI_VENC_Query!\n"); + hal_symbol_load("i6f_venc", venc_lib->handle, "MI_VENC_Query"))) return EXIT_FAILURE; - } if (!(venc_lib->fnSetSourceConfig = (int(*)(unsigned int device, unsigned int channel, i6f_venc_src_conf *config)) - dlsym(venc_lib->handle, "MI_VENC_SetInputSourceConfig"))) { - fprintf(stderr, "[i6f_venc] Failed to acquire symbol MI_VENC_SetInputSourceConfig!\n"); + hal_symbol_load("i6f_venc", venc_lib->handle, "MI_VENC_SetInputSourceConfig"))) return EXIT_FAILURE; - } if (!(venc_lib->fnRequestIdr = (int(*)(unsigned int device, unsigned int channel, char instant)) - dlsym(venc_lib->handle, "MI_VENC_RequestIdr"))) { - fprintf(stderr, "[i6f_venc] Failed to acquire symbol MI_VENC_RequestIdr!\n"); + hal_symbol_load("i6f_venc", venc_lib->handle, "MI_VENC_RequestIdr"))) return EXIT_FAILURE; - } if (!(venc_lib->fnStartReceiving = (int(*)(unsigned int device, unsigned int channel)) - dlsym(venc_lib->handle, "MI_VENC_StartRecvPic"))) { - fprintf(stderr, "[i6f_venc] Failed to acquire symbol MI_VENC_StartRecvPic!\n"); + hal_symbol_load("i6f_venc", venc_lib->handle, "MI_VENC_StartRecvPic"))) return EXIT_FAILURE; - } if (!(venc_lib->fnStartReceivingEx = (int(*)(unsigned int device, unsigned int channel, int *count)) - dlsym(venc_lib->handle, "MI_VENC_StartRecvPicEx"))) { - fprintf(stderr, "[i6f_venc] Failed to acquire symbol MI_VENC_StartRecvPicEx!\n"); + hal_symbol_load("i6f_venc", venc_lib->handle, "MI_VENC_StartRecvPicEx"))) return EXIT_FAILURE; - } if (!(venc_lib->fnStopReceiving = (int(*)(unsigned int device, unsigned int channel)) - dlsym(venc_lib->handle, "MI_VENC_StopRecvPic"))) { - fprintf(stderr, "[i6f_venc] Failed to acquire symbol MI_VENC_StopRecvPic!\n"); + hal_symbol_load("i6f_venc", venc_lib->handle, "MI_VENC_StopRecvPic"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/star/i6f_vif.h b/src/hal/star/i6f_vif.h index 8e67f85..cb482b8 100644 --- a/src/hal/star/i6f_vif.h +++ b/src/hal/star/i6f_vif.h @@ -69,58 +69,40 @@ typedef struct { } i6f_vif_impl; static int i6f_vif_load(i6f_vif_impl *vif_lib) { - if (!(vif_lib->handle = dlopen("libmi_vif.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[i6f_vif] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(vif_lib->handle = dlopen("libmi_vif.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("i6f_vif", "Failed to load library!\nError: %s\n", dlerror()); if (!(vif_lib->fnDisableDevice = (int(*)(int device)) - dlsym(vif_lib->handle, "MI_VIF_DisableDev"))) { - fprintf(stderr, "[i6f_vif] Failed to acquire symbol MI_VIF_DisableDev!\n"); + hal_symbol_load("i6f_vif", vif_lib->handle, "MI_VIF_DisableDev"))) return EXIT_FAILURE; - } if (!(vif_lib->fnEnableDevice = (int(*)(int device)) - dlsym(vif_lib->handle, "MI_VIF_EnableDev"))) { - fprintf(stderr, "[i6f_vif] Failed to acquire symbol MI_VIF_EnableDev!\n"); + hal_symbol_load("i6f_vif", vif_lib->handle, "MI_VIF_EnableDev"))) return EXIT_FAILURE; - } if (!(vif_lib->fnSetDeviceConfig = (int(*)(int device, i6f_vif_dev *config)) - dlsym(vif_lib->handle, "MI_VIF_SetDevAttr"))) { - fprintf(stderr, "[i6f_vif] Failed to acquire symbol MI_VIF_SetDevAttr!\n"); + hal_symbol_load("i6f_vif", vif_lib->handle, "MI_VIF_SetDevAttr"))) return EXIT_FAILURE; - } if (!(vif_lib->fnCreateGroup = (int(*)(int group, i6f_vif_grp *config)) - dlsym(vif_lib->handle, "MI_VIF_CreateDevGroup"))) { - fprintf(stderr, "[i6f_vif] Failed to acquire symbol MI_VIF_CreateDevGroup!\n"); + hal_symbol_load("i6f_vif", vif_lib->handle, "MI_VIF_CreateDevGroup"))) return EXIT_FAILURE; - } if (!(vif_lib->fnDestroyGroup = (int(*)(int group)) - dlsym(vif_lib->handle, "MI_VIF_DestroyDevGroup"))) { - fprintf(stderr, "[i6f_vif] Failed to acquire symbol MI_VIF_DestroyDevGroup!\n"); + hal_symbol_load("i6f_vif", vif_lib->handle, "MI_VIF_DestroyDevGroup"))) return EXIT_FAILURE; - } if (!(vif_lib->fnDisablePort = (int(*)(int device, int port)) - dlsym(vif_lib->handle, "MI_VIF_DisableOutputPort"))) { - fprintf(stderr, "[i6f_vif] Failed to acquire symbol MI_VIF_DisableOutputPort!\n"); + hal_symbol_load("i6f_vif", vif_lib->handle, "MI_VIF_DisableOutputPort"))) return EXIT_FAILURE; - } if (!(vif_lib->fnEnablePort = (int(*)(int device, int port)) - dlsym(vif_lib->handle, "MI_VIF_EnableOutputPort"))) { - fprintf(stderr, "[i6f_vif] Failed to acquire symbol MI_VIF_EnableOutputPort!\n"); + hal_symbol_load("i6f_vif", vif_lib->handle, "MI_VIF_EnableOutputPort"))) return EXIT_FAILURE; - } if (!(vif_lib->fnSetPortConfig = (int(*)(int device, int port, i6f_vif_port *config)) - dlsym(vif_lib->handle, "MI_VIF_SetOutputPortAttr"))) { - fprintf(stderr, "[i6f_vif] Failed to acquire symbol MI_VIF_SetOutputPortAttr!\n"); + hal_symbol_load("i6f_vif", vif_lib->handle, "MI_VIF_SetOutputPortAttr"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/symbols.h b/src/hal/symbols.h new file mode 100644 index 0000000..adfd19a --- /dev/null +++ b/src/hal/symbols.h @@ -0,0 +1,15 @@ +#pragma once + +#include +#include + +#include "macros.h" + +static void inline *hal_symbol_load(const char *module, void *handle, const char *symbol) { + void *function = dlsym(handle, symbol); + if (!function) { + HAL_DANGER(module, "Failed to acquire symbol %s!\n", symbol); + return (void*)0; + } + return function; +} \ No newline at end of file diff --git a/src/hal/types.h b/src/hal/types.h index de46462..159c2c5 100644 --- a/src/hal/types.h +++ b/src/hal/types.h @@ -1,5 +1,7 @@ #pragma once +#include "macros.h" + #ifndef ALIGN_BACK #define ALIGN_BACK(x, a) (((x) / (a)) * (a)) #endif @@ -125,4 +127,4 @@ typedef struct { hal_vidpack *pack; unsigned int count; unsigned int seq; -} hal_vidstream; +} hal_vidstream; \ No newline at end of file diff --git a/src/rtsp/timer.c b/src/rtsp/timer.c deleted file mode 100644 index 5aa3c02..0000000 --- a/src/rtsp/timer.c +++ /dev/null @@ -1,106 +0,0 @@ -#ifndef _RTSP_TIMER_H -#define _RTSP_TIMER_H -#include -#include "common.h" - -typedef struct timekeeper_object { - struct timespec tv1; - struct timespec tv2; - long sum; - long max; - long min; - unsigned int cnt; -} timekeeper_object; - - -typedef timekeeper_object *timekeeper_handle; - -static inline timekeeper_handle timekeeper_create(void); -static inline void timekeeper_delete(timekeeper_handle h); -static inline void timekeeper_print(timekeeper_handle h,const char *reporter); -static inline void timekeeper_start(timekeeper_handle h); -static inline void timekeeper_stop(timekeeper_handle h); - -static inline void -timesub(timekeeper_handle h); - -static inline void timekeeper_delete(timekeeper_handle h) -{ - FREE(h); -} - -static inline timekeeper_handle timekeeper_create() -{ - timekeeper_handle nh; - TALLOC(nh,return NULL); - nh->sum = 0; - nh->max = 0; - nh->min = 0x7fffffff; - nh->cnt = 0; - return nh; -} - -static inline void timekeeper_print(timekeeper_handle h,const char *reporter) -{ - double avg = 0; - - ASSERT(h,ERR("timekeeper_handle is null\n")); - - avg = (double)h->sum / (double)h->cnt / 1000.0; - printf("%s spends: min[%ldus], max[%ldus], avg[%.3fms], in %u times\n", reporter,h->min, h->max, avg,h->cnt); -} - -static inline void timekeeper_start(timekeeper_handle h) -{ - ASSERT(h,ERR("timekeeper_handle is null\n")); - - clock_gettime(CLOCK_REALTIME, &h->tv1); - //gettimeofday(&h->tv1,NULL); -} - -/* -void timekeeper_get_sec(timekeeper_handle h) -{ - clock_gettime(CLOCK_REALTIME_HR, h->tv1); -} -*/ - -static inline void timekeeper_stop(timekeeper_handle h) -{ - ASSERT(h,ERR("timekeeper_handle is null\n")); - - clock_gettime(CLOCK_REALTIME, &h->tv2); - //gettimeofday(&h->tv2,NULL); - - timesub(h); -} - - -static inline void -timesub(timekeeper_handle h) -{ - long sec; - long nsec; - - long usec; - long avg = 0; - - sec = h->tv2.tv_sec - h->tv1.tv_sec; - nsec = h->tv2.tv_nsec - h->tv1.tv_nsec; - - if (nsec < 0) { - sec--; - nsec += 1000000000; - } - - usec = nsec / 1000; - - if (h->max < usec) - h->max = usec; - if (h->min > usec) - h->min = usec; - h->sum += usec; - h->cnt++; - avg = h->sum / h->cnt; -} -#endif \ No newline at end of file