diff --git a/src/hal/hisi/v3_aud.h b/src/hal/hisi/v3_aud.h index 00fdcb8..a54b505 100644 --- a/src/hal/hisi/v3_aud.h +++ b/src/hal/hisi/v3_aud.h @@ -67,52 +67,36 @@ typedef struct { } v3_aud_impl; static int v3_aud_load(v3_aud_impl *aud_lib) { - if (!(aud_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[v3_aud] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(aud_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("v3_aud", "Failed to load library!\nError: %s\n", dlerror()); if (!(aud_lib->fnDisableDevice = (int(*)(int device)) - dlsym(aud_lib->handle, "HI_MPI_AI_Disable"))) { - fprintf(stderr, "[v3_aud] Failed to acquire symbol HI_MPI_AI_Disable!\n"); + hal_symbol_load("v3_aud", aud_lib->handle, "HI_MPI_AI_Disable"))) return EXIT_FAILURE; - } if (!(aud_lib->fnEnableDevice = (int(*)(int device)) - dlsym(aud_lib->handle, "HI_MPI_AI_Enable"))) { - fprintf(stderr, "[v3_aud] Failed to acquire symbol HI_MPI_AI_Enable!\n"); + hal_symbol_load("v3_aud", aud_lib->handle, "HI_MPI_AI_Enable"))) return EXIT_FAILURE; - } if (!(aud_lib->fnSetDeviceConfig = (int(*)(int device, v3_aud_cnf *config)) - dlsym(aud_lib->handle, "HI_MPI_AI_SetPubAttr"))) { - fprintf(stderr, "[v3_aud] Failed to acquire symbol HI_MPI_AI_SetPubAttr!\n"); + hal_symbol_load("v3_aud", aud_lib->handle, "HI_MPI_AI_SetPubAttr"))) return EXIT_FAILURE; - } if (!(aud_lib->fnDisableChannel = (int(*)(int device, int channel)) - dlsym(aud_lib->handle, "HI_MPI_AI_DisableChn"))) { - fprintf(stderr, "[v3_aud] Failed to acquire symbol HI_MPI_AI_DisableChn!\n"); + hal_symbol_load("v3_aud", aud_lib->handle, "HI_MPI_AI_DisableChn"))) return EXIT_FAILURE; - } if (!(aud_lib->fnEnableChannel = (int(*)(int device, int channel)) - dlsym(aud_lib->handle, "HI_MPI_AI_EnableChn"))) { - fprintf(stderr, "[v3_aud] Failed to acquire symbol HI_MPI_AI_EnableChn!\n"); + hal_symbol_load("v3_aud", aud_lib->handle, "HI_MPI_AI_EnableChn"))) return EXIT_FAILURE; - } if (!(aud_lib->fnFreeFrame = (int(*)(int device, int channel, v3_aud_frm *frame, v3_aud_efrm *encFrame)) - dlsym(aud_lib->handle, "HI_MPI_AI_ReleaseFrame"))) { - fprintf(stderr, "[v3_aud] Failed to acquire symbol HI_MPI_AI_ReleaseFrame!\n"); + hal_symbol_load("v3_aud", aud_lib->handle, "HI_MPI_AI_ReleaseFrame"))) return EXIT_FAILURE; - } if (!(aud_lib->fnGetFrame = (int(*)(int device, int channel, v3_aud_frm *frame, v3_aud_efrm *encFrame, int millis)) - dlsym(aud_lib->handle, "HI_MPI_AI_GetFrame"))) { - fprintf(stderr, "[v3_aud] Failed to acquire symbol HI_MPI_AI_GetFrame!\n"); + hal_symbol_load("v3_aud", aud_lib->handle, "HI_MPI_AI_GetFrame"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/hisi/v3_common.h b/src/hal/hisi/v3_common.h index 4fac809..01be933 100644 --- a/src/hal/hisi/v3_common.h +++ b/src/hal/hisi/v3_common.h @@ -6,16 +6,9 @@ #include #include +#include "../symbols.h" #include "../types.h" -#define V3_ERROR(x, ...) \ - do { \ - fprintf(stderr, "[v3_hal] \033[31m"); \ - fprintf(stderr, (x), ##__VA_ARGS__); \ - fprintf(stderr, "\033[0m"); \ - return EXIT_FAILURE; \ - } while (0) - typedef enum { V3_BAYER_RG, V3_BAYER_GR, diff --git a/src/hal/hisi/v3_hal.c b/src/hal/hisi/v3_hal.c index 84d7541..fe97c9d 100644 --- a/src/hal/hisi/v3_hal.c +++ b/src/hal/hisi/v3_hal.c @@ -111,7 +111,7 @@ void *v3_audio_thread(void) while (keepRunning) { if (ret = v3_aud.fnGetFrame(_v3_aud_dev, _v3_aud_chn, &frame, &echoFrame, 128)) { - fprintf(stderr, "[v3_aud] Getting the frame failed " + HAL_WARNING("v3_aud", "Getting the frame failed " "with %#x!\n", ret); continue; } @@ -128,11 +128,11 @@ void *v3_audio_thread(void) if (ret = v3_aud.fnFreeFrame(_v3_aud_dev, _v3_aud_chn, &frame, &echoFrame)) { - fprintf(stderr, "[v3_aud] Releasing the frame failed" + HAL_WARNING("v3_aud", "Releasing the frame failed" " with %#x!\n", ret); } } - fprintf(stderr, "[v3_aud] Shutting down capture thread...\n"); + HAL_INFO("v3_aud", "Shutting down capture thread...\n"); } int v3_channel_bind(char index) @@ -220,8 +220,8 @@ void *v3_image_thread(void) int ret; if (ret = v3_isp.fnRun(_v3_isp_dev)) - fprintf(stderr, "[v3_isp] Operation failed with %#x!\n", ret); - fprintf(stderr, "[v3_isp] Shutting down ISP thread...\n"); + HAL_DANGER("v3_isp", "Operation failed with %#x!\n", ret); + HAL_INFO("v3_isp", "Shutting down ISP thread...\n"); } int v3_pipeline_create(void) @@ -355,12 +355,12 @@ int v3_region_create(char handle, hal_rect rect, short opacity) region.overlay.canvas = handle + 1; if (v3_rgn.fnGetRegionConfig(handle, ®ionCurr)) { - fprintf(stderr, "[v3_rgn] Creating region %d...\n", handle); + HAL_INFO("v3_rgn", "Creating region %d...\n", handle); if (ret = v3_rgn.fnCreateRegion(handle, ®ion)) return ret; } else if (regionCurr.overlay.size.height != region.overlay.size.height || regionCurr.overlay.size.width != region.overlay.size.width) { - fprintf(stderr, "[v3_rgn] Parameters are different, recreating " + HAL_INFO("v3_rgn", "Parameters are different, recreating " "region %d...\n", handle); v3_rgn.fnDetachChannel(handle, &channel); v3_rgn.fnDestroyRegion(handle); @@ -369,9 +369,9 @@ int v3_region_create(char handle, hal_rect rect, short opacity) } if (v3_rgn.fnGetChannelConfig(handle, &channel, &attribCurr)) - fprintf(stderr, "[v3_rgn] Attaching region %d...\n", handle); + HAL_INFO("v3_rgn", "Attaching region %d...\n", handle); else if (attribCurr.overlay.point.x != rect.x || attribCurr.overlay.point.x != rect.y) { - fprintf(stderr, "[v3_rgn] Position has changed, reattaching " + HAL_INFO("v3_rgn", "Position has changed, reattaching " "region %d...\n", handle); v3_rgn.fnDetachChannel(handle, &channel); } @@ -422,14 +422,14 @@ int v3_sensor_config(void) { fd = open(v3_snr_endp, O_RDWR); else fd = open("/dev/mipi", O_RDWR); if (fd < 0) - V3_ERROR("Opening imaging device has failed!\n"); + HAL_ERROR("v3_snr", "Opening imaging device has failed!\n"); ioctl(fd, _IOW(V3_SNR_IOC_MAGIC, V3_SNR_CMD_RST_MIPI, unsigned int), &config.device); ioctl(fd, _IOW(V3_SNR_IOC_MAGIC, V3_SNR_CMD_RST_SENS, unsigned int), &config.device); if (ioctl(fd, _IOW(V3_SNR_IOC_MAGIC, V3_SNR_CMD_CONF_DEV, v3_snr_dev), &config)) - V3_ERROR("Configuring imaging device has failed!\n"); + HAL_ERROR("v3_snr", "Configuring imaging device has failed!\n"); ioctl(fd, _IOW(V3_SNR_IOC_MAGIC, V3_SNR_CMD_UNRST_MIPI, unsigned int), &config.device); @@ -449,7 +449,7 @@ void v3_sensor_deconfig(void) { fd = open(v3_snr_endp, O_RDWR); else fd = open("/dev/mipi", O_RDWR); if (fd < 0) - fprintf(stderr, "[v3_hal] Opening imaging device has failed!\n"); + HAL_DANGER("v3_snr", "Opening imaging device has failed!\n"); ioctl(fd, _IOW(V3_SNR_IOC_MAGIC, V3_SNR_CMD_RST_SENS, unsigned int), &config.device); @@ -475,12 +475,12 @@ int v3_sensor_init(char *name, char *obj) if (v3_snr_drv.handle = dlopen(path, RTLD_NOW | RTLD_GLOBAL)) break; } if (!v3_snr_drv.handle) - V3_ERROR("Failed to load the sensor driver"); + HAL_ERROR("v3_snr", "Failed to load the sensor driver"); if (!(v3_snr_drv.fnRegisterCallback = (int(*)(void))dlsym(v3_snr_drv.handle, "sensor_register_callback"))) - V3_ERROR("Failed to connect the callback register function"); + HAL_ERROR("v3_snr", "Failed to connect the callback register function"); if (!(v3_snr_drv.fnUnRegisterCallback = (int(*)(void))dlsym(v3_snr_drv.handle, "sensor_unregister_callback"))) - V3_ERROR("Failed to connect the callback register function"); + HAL_ERROR("v3_snr", "Failed to connect the callback register function"); return EXIT_SUCCESS; } @@ -527,7 +527,7 @@ int v3_video_create(char index, hal_vidconfig *config) channel.rate.mjpgQp = (v3_venc_rate_mjpgqp){ .srcFps = config->framerate, .dstFps = config->framerate, .quality = config->maxQual }; break; default: - V3_ERROR("MJPEG encoder can only support CBR, VBR or fixed QP modes!"); + HAL_ERROR("v3_venc", "MJPEG encoder can only support CBR, VBR or fixed QP modes!"); } goto attach; } else if (config->codec == HAL_VIDCODEC_H265) { @@ -556,7 +556,7 @@ int v3_video_create(char index, hal_vidconfig *config) .statTime = 1, .srcFps = config->framerate, .dstFps = config->framerate, .bitrate = config->bitrate }; break; default: - V3_ERROR("H.265 encoder does not support this mode!"); + HAL_ERROR("v3_venc", "H.265 encoder does not support this mode!"); } } else if (config->codec == HAL_VIDCODEC_H264) { channel.attrib.codec = V3_VENC_CODEC_H264; @@ -584,9 +584,9 @@ int v3_video_create(char index, hal_vidconfig *config) .statTime = 1, .srcFps = config->framerate, .dstFps = config->framerate, .bitrate = config->bitrate }; break; default: - V3_ERROR("H.264 encoder does not support this mode!"); + HAL_ERROR("v3_venc", "H.264 encoder does not support this mode!"); } - } else V3_ERROR("This codec is not supported by the hardware!"); + } else HAL_ERROR("v3_venc", "This codec is not supported by the hardware!"); attrib->maxPic.width = config->width; attrib->maxPic.height = config->height; attrib->bufSize = config->height * config->width * 2; @@ -656,14 +656,14 @@ int v3_video_snapshot_grab(char index, hal_jpegdata *jpeg) int ret; if (ret = v3_channel_bind(index)) { - fprintf(stderr, "[v3_venc] Binding the encoder channel " + HAL_DANGER("v3_venc", "Binding the encoder channel " "%d failed with %#x!\n", index, ret); goto abort; } unsigned int count = 1; if (v3_venc.fnStartReceivingEx(index, &count)) { - fprintf(stderr, "[v3_venc] Requesting one frame " + HAL_DANGER("v3_venc", "Requesting one frame " "%d failed with %#x!\n", index, ret); goto abort; } @@ -676,23 +676,23 @@ int v3_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, "[v3_venc] Select operation failed!\n"); + HAL_DANGER("v3_venc", "Select operation failed!\n"); goto abort; } else if (ret == 0) { - fprintf(stderr, "[v3_venc] Capture stream timed out!\n"); + HAL_DANGER("v3_venc", "Capture stream timed out!\n"); goto abort; } if (FD_ISSET(fd, &readFds)) { v3_venc_stat stat; if (v3_venc.fnQuery(index, &stat)) { - fprintf(stderr, "[v3_venc] Querying the encoder channel " + HAL_DANGER("v3_venc", "Querying the encoder channel " "%d failed with %#x!\n", index, ret); goto abort; } if (!stat.curPacks) { - fprintf(stderr, "[v3_venc] Current frame is empty, skipping it!\n"); + HAL_DANGER("v3_venc", "Current frame is empty, skipping it!\n"); goto abort; } @@ -700,13 +700,13 @@ int v3_video_snapshot_grab(char index, hal_jpegdata *jpeg) memset(&strm, 0, sizeof(strm)); strm.packet = (v3_venc_pack*)malloc(sizeof(v3_venc_pack) * stat.curPacks); if (!strm.packet) { - fprintf(stderr, "[v3_venc] Memory allocation on channel %d failed!\n", index); + HAL_DANGER("v3_venc", "Memory allocation on channel %d failed!\n", index); goto abort; } strm.count = stat.curPacks; if (ret = v3_venc.fnGetStream(index, &strm, stat.curPacks)) { - fprintf(stderr, "[v3_venc] Getting the stream on " + HAL_DANGER("v3_venc", "Getting the stream on " "channel %d failed with %#x!\n", index, ret); free(strm.packet); strm.packet = NULL; @@ -754,7 +754,7 @@ void *v3_video_thread(void) ret = v3_venc.fnGetDescriptor(i); if (ret < 0) { - fprintf(stderr, "[v3_venc] Getting the encoder descriptor failed with %#x!\n", ret); + HAL_DANGER("v3_venc", "Getting the encoder descriptor failed with %#x!\n", ret); return NULL; } v3_state[i].fileDesc = ret; @@ -780,10 +780,10 @@ void *v3_video_thread(void) timeout.tv_usec = 0; ret = select(maxFd + 1, &readFds, NULL, NULL, &timeout); if (ret < 0) { - fprintf(stderr, "[v3_venc] Select operation failed!\n"); + HAL_DANGER("v3_venc", "Select operation failed!\n"); break; } else if (ret == 0) { - fprintf(stderr, "[v3_venc] Main stream loop timed out!\n"); + HAL_WARNING("v3_venc", "Main stream loop timed out!\n"); continue; } else { for (int i = 0; i < V3_VENC_CHN_NUM; i++) { @@ -793,26 +793,26 @@ void *v3_video_thread(void) memset(&stream, 0, sizeof(stream)); if (ret = v3_venc.fnQuery(i, &stat)) { - fprintf(stderr, "[v3_venc] Querying the encoder channel " + HAL_DANGER("v3_venc", "Querying the encoder channel " "%d failed with %#x!\n", i, ret); break; } if (!stat.curPacks) { - fprintf(stderr, "[v3_venc] Current frame is empty, skipping it!\n"); + HAL_WARNING("v3_venc", " Current frame is empty, skipping it!\n"); continue; } stream.packet = (v3_venc_pack*)malloc( sizeof(v3_venc_pack) * stat.curPacks); if (!stream.packet) { - fprintf(stderr, "[v3_venc] Memory allocation on channel %d failed!\n", i); + HAL_DANGER("v3_venc", "Memory allocation on channel %d failed!\n", i); break; } stream.count = stat.curPacks; if (ret = v3_venc.fnGetStream(i, &stream, 40)) { - fprintf(stderr, "[v3_venc] Getting the stream on " + HAL_DANGER("v3_venc", "Getting the stream on " "channel %d failed with %#x!\n", i, ret); break; } @@ -845,7 +845,7 @@ void *v3_video_thread(void) } if (ret = v3_venc.fnFreeStream(i, &stream)) { - fprintf(stderr, "[v3_venc] Releasing the stream on " + HAL_WARNING("v3_venc", "Releasing the stream on " "channel %d failed with %#x!\n", i, ret); } free(stream.packet); @@ -854,7 +854,7 @@ void *v3_video_thread(void) } } } - fprintf(stderr, "[v3_venc] Shutting down encoding thread...\n"); + HAL_INFO("v3_venc", "Shutting down encoding thread...\n"); } void v3_system_deinit(void) @@ -877,7 +877,7 @@ int v3_system_init(char *snrConfig) } if (v3_parse_sensor_config(snrConfig, &v3_config) != CONFIG_OK) - V3_ERROR("Can't load sensor config\n"); + HAL_ERROR("v3_sys", "Can't load sensor config\n"); if (ret = v3_sensor_init(v3_config.dll_file, v3_config.sensor_type)) return ret; diff --git a/src/hal/hisi/v3_isp.h b/src/hal/hisi/v3_isp.h index 4e465ad..5c5e15d 100644 --- a/src/hal/hisi/v3_isp.h +++ b/src/hal/hisi/v3_isp.h @@ -38,82 +38,56 @@ static int v3_isp_load(v3_isp_impl *isp_lib) { !(isp_lib->handleAe = dlopen("lib_hiae.so", RTLD_LAZY | RTLD_GLOBAL)) || !(isp_lib->handleAwb = dlopen("lib_hiawb.so", RTLD_LAZY | RTLD_GLOBAL)) || !(isp_lib->handleDefog = dlopen("lib_hidefog.so", RTLD_LAZY | RTLD_GLOBAL)) || - !(isp_lib->handleIrAuto = dlopen("lib_hiirauto.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[v3_isp] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + !(isp_lib->handleIrAuto = dlopen("lib_hiirauto.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("v3_isp", "Failed to load library!\nError: %s\n", dlerror()); if (!(fnISP_AlgRegisterDehaze = (int(*)(int)) - dlsym(isp_lib->handleDefog, "ISP_AlgRegisterDehaze"))) { - fprintf(stderr, "[v4_isp] Failed to acquire symbol ISP_AlgRegisterDehaze!\n"); + hal_symbol_load("v3_isp", isp_lib->handleDefog, "ISP_AlgRegisterDehaze"))) return EXIT_FAILURE; - } if (!(fnISP_AlgRegisterDrc = (int(*)(int)) - dlsym(isp_lib->handle, "ISP_AlgRegisterDrc"))) { - fprintf(stderr, "[v4_isp] Failed to acquire symbol ISP_AlgRegisterDrc!\n"); + hal_symbol_load("v3_isp", isp_lib->handle, "ISP_AlgRegisterDrc"))) return EXIT_FAILURE; - } if (!(isp_lib->fnExit = (int(*)(int device)) - dlsym(isp_lib->handle, "HI_MPI_ISP_Exit"))) { - fprintf(stderr, "[v3_isp] Failed to acquire symbol HI_MPI_ISP_Exit!\n"); + hal_symbol_load("v3_isp", isp_lib->handle, "HI_MPI_ISP_Exit"))) return EXIT_FAILURE; - } if (!(isp_lib->fnInit = (int(*)(int device)) - dlsym(isp_lib->handle, "HI_MPI_ISP_Init"))) { - fprintf(stderr, "[v3_isp] Failed to acquire symbol HI_MPI_ISP_Init!\n"); + hal_symbol_load("v3_isp", isp_lib->handle, "HI_MPI_ISP_Init"))) return EXIT_FAILURE; - } if (!(isp_lib->fnMemInit = (int(*)(int device)) - dlsym(isp_lib->handle, "HI_MPI_ISP_MemInit"))) { - fprintf(stderr, "[v3_isp] Failed to acquire symbol HI_MPI_ISP_MemInit!\n"); + hal_symbol_load("v3_isp", isp_lib->handle, "HI_MPI_ISP_MemInit"))) return EXIT_FAILURE; - } if (!(isp_lib->fnRun = (int(*)(int device)) - dlsym(isp_lib->handle, "HI_MPI_ISP_Run"))) { - fprintf(stderr, "[v3_isp] Failed to acquire symbol HI_MPI_ISP_Run!\n"); + hal_symbol_load("v3_isp", isp_lib->handle, "HI_MPI_ISP_Run"))) return EXIT_FAILURE; - } if (!(isp_lib->fnSetDeviceConfig = (int(*)(int device, v3_isp_dev *config)) - dlsym(isp_lib->handle, "HI_MPI_ISP_SetPubAttr"))) { - fprintf(stderr, "[v3_isp] Failed to acquire symbol HI_MPI_ISP_SetPubAttr!\n"); + hal_symbol_load("v3_isp", isp_lib->handle, "HI_MPI_ISP_SetPubAttr"))) return EXIT_FAILURE; - } if (!(isp_lib->fnSetWDRMode = (int(*)(int device, v3_common_wdr *mode)) - dlsym(isp_lib->handle, "HI_MPI_ISP_SetWDRMode"))) { - fprintf(stderr, "[v3_isp] Failed to acquire symbol HI_MPI_ISP_SetWDRMode!\n"); + hal_symbol_load("v3_isp", isp_lib->handle, "HI_MPI_ISP_SetWDRMode"))) return EXIT_FAILURE; - } if (!(isp_lib->fnRegisterAE = (int(*)(int device, v3_isp_alg *library)) - dlsym(isp_lib->handleAe, "HI_MPI_AE_Register"))) { - fprintf(stderr, "[v3_isp] Failed to acquire symbol HI_MPI_AE_Register!\n"); + hal_symbol_load("v3_isp", isp_lib->handleAe, "HI_MPI_AE_Register"))) return EXIT_FAILURE; - } if (!(isp_lib->fnRegisterAWB = (int(*)(int device, v3_isp_alg *library)) - dlsym(isp_lib->handleAwb, "HI_MPI_AWB_Register"))) { - fprintf(stderr, "[v3_isp] Failed to acquire symbol HI_MPI_AWB_Register!\n"); + hal_symbol_load("v3_isp", isp_lib->handleAwb, "HI_MPI_AWB_Register"))) return EXIT_FAILURE; - } if (!(isp_lib->fnUnregisterAE = (int(*)(int device, v3_isp_alg *library)) - dlsym(isp_lib->handleAe, "HI_MPI_AE_UnRegister"))) { - fprintf(stderr, "[v3_isp] Failed to acquire symbol HI_MPI_AE_UnRegister!\n"); + hal_symbol_load("v3_isp", isp_lib->handleAe, "HI_MPI_AE_UnRegister"))) return EXIT_FAILURE; - } if (!(isp_lib->fnUnregisterAWB = (int(*)(int device, v3_isp_alg *library)) - dlsym(isp_lib->handleAwb, "HI_MPI_AWB_UnRegister"))) { - fprintf(stderr, "[v3_isp] Failed to acquire symbol HI_MPI_AWB_UnRegister!\n"); + hal_symbol_load("v3_isp", isp_lib->handleAwb, "HI_MPI_AWB_UnRegister"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/hisi/v3_rgn.h b/src/hal/hisi/v3_rgn.h index 3164a00..7b7a3d3 100644 --- a/src/hal/hisi/v3_rgn.h +++ b/src/hal/hisi/v3_rgn.h @@ -134,64 +134,44 @@ static int v3_rgn_load(v3_rgn_impl *rgn_lib) { if ( !(rgn_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL)) && (!(rgn_lib->handleGoke = dlopen("libgk_api.so", RTLD_LAZY | RTLD_GLOBAL)) || - !(rgn_lib->handle = dlopen("libhi_mpi.so", RTLD_LAZY | RTLD_GLOBAL)))) { - fprintf(stderr, "[v3_rgn] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + !(rgn_lib->handle = dlopen("libhi_mpi.so", RTLD_LAZY | RTLD_GLOBAL)))) + HAL_ERROR("v3_rgn", "Failed to load library!\nError: %s\n", dlerror()); if (!(rgn_lib->fnCreateRegion = (int(*)(unsigned int handle, v3_rgn_cnf *config)) - dlsym(rgn_lib->handle, "HI_MPI_RGN_Create"))) { - fprintf(stderr, "[v3_rgn] Failed to acquire symbol HI_MPI_RGN_Create!\n"); + hal_symbol_load("v3_rgn", rgn_lib->handle, "HI_MPI_RGN_Create"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnDestroyRegion = (int(*)(unsigned int handle)) - dlsym(rgn_lib->handle, "HI_MPI_RGN_Destroy"))) { - fprintf(stderr, "[v3_rgn] Failed to acquire symbol HI_MPI_RGN_Destroy!\n"); + hal_symbol_load("v3_rgn", rgn_lib->handle, "HI_MPI_RGN_Destroy"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnGetRegionConfig = (int(*)(unsigned int handle, v3_rgn_cnf *config)) - dlsym(rgn_lib->handle, "HI_MPI_RGN_GetAttr"))) { - fprintf(stderr, "[v3_rgn] Failed to acquire symbol HI_MPI_RGN_GetAttr!\n"); + hal_symbol_load("v3_rgn", rgn_lib->handle, "HI_MPI_RGN_GetAttr"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnSetRegionConfig = (int(*)(unsigned int handle, v3_rgn_cnf *config)) - dlsym(rgn_lib->handle, "HI_MPI_RGN_SetAttr"))) { - fprintf(stderr, "[v3_rgn] Failed to acquire symbol HI_MPI_RGN_SetAttr!\n"); + hal_symbol_load("v3_rgn", rgn_lib->handle, "HI_MPI_RGN_SetAttr"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnAttachChannel = (int(*)(unsigned int handle, v3_sys_bind *dest, v3_rgn_chn *config)) - dlsym(rgn_lib->handle, "HI_MPI_RGN_AttachToChn"))) { - fprintf(stderr, "[v3_rgn] Failed to acquire symbol HI_MPI_RGN_AttachToChn!\n"); + hal_symbol_load("v3_rgn", rgn_lib->handle, "HI_MPI_RGN_AttachToChn"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnDetachChannel = (int(*)(unsigned int handle, v3_sys_bind *dest)) - dlsym(rgn_lib->handle, "HI_MPI_RGN_DetachFromChn"))) { - fprintf(stderr, "[v3_rgn] Failed to acquire symbol HI_MPI_RGN_DetachFromChn!\n"); + hal_symbol_load("v3_rgn", rgn_lib->handle, "HI_MPI_RGN_DetachFromChn"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnGetChannelConfig = (int(*)(unsigned int handle, v3_sys_bind *dest, v3_rgn_chn *config)) - dlsym(rgn_lib->handle, "HI_MPI_RGN_GetDisplayAttr"))) { - fprintf(stderr, "[v3_rgn] Failed to acquire symbol HI_MPI_RGN_GetDisplayAttr!\n"); + hal_symbol_load("v3_rgn", rgn_lib->handle, "HI_MPI_RGN_GetDisplayAttr"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnSetChannelConfig = (int(*)(unsigned int handle, v3_sys_bind *dest, v3_rgn_chn *config)) - dlsym(rgn_lib->handle, "HI_MPI_RGN_SetDisplayAttr"))) { - fprintf(stderr, "[v3_rgn] Failed to acquire symbol HI_MPI_RGN_SetDisplayAttr!\n"); + hal_symbol_load("v3_rgn", rgn_lib->handle, "HI_MPI_RGN_SetDisplayAttr"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnSetBitmap = (int(*)(unsigned int handle, v3_rgn_bmp *bitmap)) - dlsym(rgn_lib->handle, "HI_MPI_RGN_SetBitMap"))) { - fprintf(stderr, "[v3_rgn] Failed to acquire symbol HI_MPI_RGN_SetBitMap!\n"); + hal_symbol_load("v3_rgn", rgn_lib->handle, "HI_MPI_RGN_SetBitMap"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/hisi/v3_sys.h b/src/hal/hisi/v3_sys.h index 3a55f2b..7929bb5 100644 --- a/src/hal/hisi/v3_sys.h +++ b/src/hal/hisi/v3_sys.h @@ -90,58 +90,40 @@ static int v3_sys_load(v3_sys_impl *sys_lib) { if (!(sys_lib->handleUpvqe = dlopen("libupvqe.so", RTLD_LAZY | RTLD_GLOBAL)) || !(sys_lib->handleDnvqe = dlopen("libdnvqe.so", RTLD_LAZY | RTLD_GLOBAL)) || !(sys_lib->handleVoiceEngine = dlopen("libVoiceEngine.so", RTLD_LAZY | RTLD_GLOBAL)) || - !(sys_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[v3_sys] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + !(sys_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("v3_sys", "Failed to load library!\nError: %s\n", dlerror()); if (!(sys_lib->fnExit = (int(*)(void)) - dlsym(sys_lib->handle, "HI_MPI_SYS_Exit"))) { - fprintf(stderr, "[v3_sys] Failed to acquire symbol HI_MPI_SYS_Exit!\n"); + hal_symbol_load("v3_sys", sys_lib->handle, "HI_MPI_SYS_Exit"))) return EXIT_FAILURE; - } if (!(sys_lib->fnGetChipId = (int(*)(unsigned int *chip)) - dlsym(sys_lib->handle, "HI_MPI_SYS_GetChipId"))) { - fprintf(stderr, "[v3_sys] Failed to acquire symbol HI_MPI_SYS_GetChipId!\n"); + hal_symbol_load("v3_sys", sys_lib->handle, "HI_MPI_SYS_GetChipId"))) return EXIT_FAILURE; - } if (!(sys_lib->fnGetVersion = (int(*)(v3_sys_ver *version)) - dlsym(sys_lib->handle, "HI_MPI_SYS_GetVersion"))) { - fprintf(stderr, "[v3_sys] Failed to acquire symbol HI_MPI_SYS_GetVersion!\n"); + hal_symbol_load("v3_sys", sys_lib->handle, "HI_MPI_SYS_GetVersion"))) return EXIT_FAILURE; - } if (!(sys_lib->fnInit = (int(*)(void)) - dlsym(sys_lib->handle, "HI_MPI_SYS_Init"))) { - fprintf(stderr, "[v3_sys] Failed to acquire symbol HI_MPI_SYS_Init!\n"); + hal_symbol_load("v3_sys", sys_lib->handle, "HI_MPI_SYS_Init"))) return EXIT_FAILURE; - } if (!(sys_lib->fnSetAlignment = (int(*)(unsigned int *width)) - dlsym(sys_lib->handle, "HI_MPI_SYS_SetConf"))) { - fprintf(stderr, "[v3_sys] Failed to acquire symbol HI_MPI_SYS_SetConf!\n"); + hal_symbol_load("v3_sys", sys_lib->handle, "HI_MPI_SYS_SetConf"))) return EXIT_FAILURE; - } if (!(sys_lib->fnBind = (int(*)(v3_sys_bind *source, v3_sys_bind *dest)) - dlsym(sys_lib->handle, "HI_MPI_SYS_Bind"))) { - fprintf(stderr, "[v3_sys] Failed to acquire symbol HI_MPI_SYS_Bind!\n"); + hal_symbol_load("v3_sys", sys_lib->handle, "HI_MPI_SYS_Bind"))) return EXIT_FAILURE; - } if (!(sys_lib->fnUnbind = (int(*)(v3_sys_bind *source, v3_sys_bind *dest)) - dlsym(sys_lib->handle, "HI_MPI_SYS_UnBind"))) { - fprintf(stderr, "[v3_sys] Failed to acquire symbol HI_MPI_SYS_UnBind!\n"); + hal_symbol_load("v3_sys", sys_lib->handle, "HI_MPI_SYS_UnBind"))) return EXIT_FAILURE; - } if (!(sys_lib->fnGetViVpssMode = (int(*)(unsigned int *onlineOn)) - dlsym(sys_lib->handle, "HI_MPI_SYS_GetViVpssMode"))) { - fprintf(stderr, "[v3_sys] Failed to acquire symbol HI_MPI_SYS_GetViVpssMode!\n"); + hal_symbol_load("v3_sys", sys_lib->handle, "HI_MPI_SYS_GetViVpssMode"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/hisi/v3_vb.h b/src/hal/hisi/v3_vb.h index 80b4820..d689337 100644 --- a/src/hal/hisi/v3_vb.h +++ b/src/hal/hisi/v3_vb.h @@ -30,34 +30,24 @@ typedef struct { } v3_vb_impl; static int v3_vb_load(v3_vb_impl *vb_lib) { - if (!(vb_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[v3_vb] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(vb_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("v3_vb", "Failed to load library!\nError: %s\n", dlerror()); if (!(vb_lib->fnConfigPool = (int(*)(v3_vb_pool *config)) - dlsym(vb_lib->handle, "HI_MPI_VB_SetConf"))) { - fprintf(stderr, "[v3_vb] Failed to acquire symbol HI_MPI_VB_SetConf!\n"); + hal_symbol_load("v3_vb", vb_lib->handle, "HI_MPI_VB_SetConf"))) return EXIT_FAILURE; - } if (!(vb_lib->fnConfigSupplement = (int(*)(v3_vb_supl *value)) - dlsym(vb_lib->handle, "HI_MPI_VB_SetSupplementConf"))) { - fprintf(stderr, "[v3_vb] Failed to acquire symbol HI_MPI_VB_SetSupplementConf!\n"); + hal_symbol_load("v3_vb", vb_lib->handle, "HI_MPI_VB_SetSupplementConf"))) return EXIT_FAILURE; - } if (!(vb_lib->fnExit = (int(*)(void)) - dlsym(vb_lib->handle, "HI_MPI_VB_Exit"))) { - fprintf(stderr, "[v3_vb] Failed to acquire symbol HI_MPI_VB_Exit!\n"); + hal_symbol_load("v3_vb", vb_lib->handle, "HI_MPI_VB_Exit"))) return EXIT_FAILURE; - } if (!(vb_lib->fnInit = (int(*)(void)) - dlsym(vb_lib->handle, "HI_MPI_VB_Init"))) { - fprintf(stderr, "[v3_vb] Failed to acquire symbol HI_MPI_VB_Init!\n"); + hal_symbol_load("v3_vb", vb_lib->handle, "HI_MPI_VB_Init"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/hisi/v3_venc.h b/src/hal/hisi/v3_venc.h index 80c5894..5edce9e 100644 --- a/src/hal/hisi/v3_venc.h +++ b/src/hal/hisi/v3_venc.h @@ -378,112 +378,76 @@ typedef struct { } v3_venc_impl; static int v3_venc_load(v3_venc_impl *venc_lib) { - if (!(venc_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[v3_venc] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(venc_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("v3_venc", "Failed to load library!\nError: %s\n", dlerror()); if (!(venc_lib->fnCreateChannel = (int(*)(int channel, v3_venc_chn *config)) - dlsym(venc_lib->handle, "HI_MPI_VENC_CreateChn"))) { - fprintf(stderr, "[v3_venc] Failed to acquire symbol HI_MPI_VENC_CreateChn!\n"); + hal_symbol_load("v3_venc", venc_lib->handle, "HI_MPI_VENC_CreateChn"))) return EXIT_FAILURE; - } if (!(venc_lib->fnDestroyChannel = (int(*)(int channel)) - dlsym(venc_lib->handle, "HI_MPI_VENC_DestroyChn"))) { - fprintf(stderr, "[v3_venc] Failed to acquire symbol HI_MPI_VENC_DestroyChn!\n"); + hal_symbol_load("v3_venc", venc_lib->handle, "HI_MPI_VENC_DestroyChn"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetChannelConfig = (int(*)(int channel, v3_venc_chn *config)) - dlsym(venc_lib->handle, "HI_MPI_VENC_GetChnAttr"))) { - fprintf(stderr, "[v3_venc] Failed to acquire symbol HI_MPI_VENC_GetChnAttr!\n"); + hal_symbol_load("v3_venc", venc_lib->handle, "HI_MPI_VENC_GetChnAttr"))) return EXIT_FAILURE; - } if (!(venc_lib->fnResetChannel = (int(*)(int channel)) - dlsym(venc_lib->handle, "HI_MPI_VENC_ResetChn"))) { - fprintf(stderr, "[v3_venc] Failed to acquire symbol HI_MPI_VENC_ResetChn!\n"); + hal_symbol_load("v3_venc", venc_lib->handle, "HI_MPI_VENC_ResetChn"))) return EXIT_FAILURE; - } if (!(venc_lib->fnSetChannelConfig = (int(*)(int channel, v3_venc_chn *config)) - dlsym(venc_lib->handle, "HI_MPI_VENC_SetChnAttr"))) { - fprintf(stderr, "[v3_venc] Failed to acquire symbol HI_MPI_VENC_SetChnAttr!\n"); + hal_symbol_load("v3_venc", venc_lib->handle, "HI_MPI_VENC_SetChnAttr"))) return EXIT_FAILURE; - } if (!(venc_lib->fnSetColorToGray = (int(*)(int channel, int *active)) - dlsym(venc_lib->handle, "HI_MPI_VENC_SetColor2Grey"))) { - fprintf(stderr, "[v3_venc] Failed to acquire symbol HI_MPI_VENC_SetColor2Grey!\n"); + hal_symbol_load("v3_venc", venc_lib->handle, "HI_MPI_VENC_SetColor2Grey"))) return EXIT_FAILURE; - } if (!(venc_lib->fnFreeDescriptor = (int(*)(int channel)) - dlsym(venc_lib->handle, "HI_MPI_VENC_CloseFd"))) { - fprintf(stderr, "[v3_venc] Failed to acquire symbol HI_MPI_VENC_CloseFd!\n"); + hal_symbol_load("v3_venc", venc_lib->handle, "HI_MPI_VENC_CloseFd"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetDescriptor = (int(*)(int channel)) - dlsym(venc_lib->handle, "HI_MPI_VENC_GetFd"))) { - fprintf(stderr, "[v3_venc] Failed to acquire symbol HI_MPI_VENC_GetFd!\n"); + hal_symbol_load("v3_venc", venc_lib->handle, "HI_MPI_VENC_GetFd"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetJpegParam = (int(*)(int channel, v3_venc_jpg *param)) - dlsym(venc_lib->handle, "HI_MPI_VENC_GetJpegParam"))) { - fprintf(stderr, "[v3_venc] Failed to acquire symbol HI_MPI_VENC_GetJpegParam!\n"); + hal_symbol_load("v3_venc", venc_lib->handle, "HI_MPI_VENC_GetJpegParam"))) return EXIT_FAILURE; - } if (!(venc_lib->fnSetJpegParam = (int(*)(int channel, v3_venc_jpg *param)) - dlsym(venc_lib->handle, "HI_MPI_VENC_SetJpegParam"))) { - fprintf(stderr, "[v3_venc] Failed to acquire symbol HI_MPI_VENC_SetJpegParam!\n"); + hal_symbol_load("v3_venc", venc_lib->handle, "HI_MPI_VENC_SetJpegParam"))) return EXIT_FAILURE; - } if (!(venc_lib->fnFreeStream = (int(*)(int channel, v3_venc_strm *stream)) - dlsym(venc_lib->handle, "HI_MPI_VENC_ReleaseStream"))) { - fprintf(stderr, "[v3_venc] Failed to acquire symbol HI_MPI_VENC_ReleaseStream!\n"); + hal_symbol_load("v3_venc", venc_lib->handle, "HI_MPI_VENC_ReleaseStream"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetStream = (int(*)(int channel, v3_venc_strm *stream, unsigned int timeout)) - dlsym(venc_lib->handle, "HI_MPI_VENC_GetStream"))) { - fprintf(stderr, "[v3_venc] Failed to acquire symbol HI_MPI_VENC_GetStream!\n"); + hal_symbol_load("v3_venc", venc_lib->handle, "HI_MPI_VENC_GetStream"))) return EXIT_FAILURE; - } if (!(venc_lib->fnQuery = (int(*)(int channel, v3_venc_stat *stats)) - dlsym(venc_lib->handle, "HI_MPI_VENC_Query"))) { - fprintf(stderr, "[v3_venc] Failed to acquire symbol HI_MPI_VENC_Query!\n"); + hal_symbol_load("v3_venc", venc_lib->handle, "HI_MPI_VENC_Query"))) return EXIT_FAILURE; - } if (!(venc_lib->fnRequestIdr = (int(*)(int channel, int instant)) - dlsym(venc_lib->handle, "HI_MPI_VENC_RequestIDR"))) { - fprintf(stderr, "[v3_venc] Failed to acquire symbol HI_MPI_VENC_RequestIDR!\n"); + hal_symbol_load("v3_venc", venc_lib->handle, "HI_MPI_VENC_RequestIDR"))) return EXIT_FAILURE; - } if (!(venc_lib->fnStartReceiving = (int(*)(int channel)) - dlsym(venc_lib->handle, "HI_MPI_VENC_StartRecvPic"))) { - fprintf(stderr, "[v3_venc] Failed to acquire symbol HI_MPI_VENC_StartRecvPic!\n"); + hal_symbol_load("v3_venc", venc_lib->handle, "HI_MPI_VENC_StartRecvPic"))) return EXIT_FAILURE; - } if (!(venc_lib->fnStartReceivingEx = (int(*)(int channel, int *count)) - dlsym(venc_lib->handle, "HI_MPI_VENC_StartRecvPicEx"))) { - fprintf(stderr, "[v3_venc] Failed to acquire symbol HI_MPI_VENC_StartRecvPicEx!\n"); + hal_symbol_load("v3_venc", venc_lib->handle, "HI_MPI_VENC_StartRecvPicEx"))) return EXIT_FAILURE; - } if (!(venc_lib->fnStopReceiving = (int(*)(int channel)) - dlsym(venc_lib->handle, "HI_MPI_VENC_StopRecvPic"))) { - fprintf(stderr, "[v3_venc] Failed to acquire symbol HI_MPI_VENC_StopRecvPic!\n"); + hal_symbol_load("v3_venc", venc_lib->handle, "HI_MPI_VENC_StopRecvPic"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/hisi/v3_vi.h b/src/hal/hisi/v3_vi.h index c9b9ead..1441af7 100644 --- a/src/hal/hisi/v3_vi.h +++ b/src/hal/hisi/v3_vi.h @@ -108,46 +108,32 @@ typedef struct { } v3_vi_impl; static int v3_vi_load(v3_vi_impl *vi_lib) { - if (!(vi_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[v3_vi] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(vi_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("v3_vi", "Failed to load library!\nError: %s\n", dlerror()); if (!(vi_lib->fnDisableDevice = (int(*)(int device)) - dlsym(vi_lib->handle, "HI_MPI_VI_DisableDev"))) { - fprintf(stderr, "[v3_vi] Failed to acquire symbol HI_MPI_VI_DisableDev!\n"); + hal_symbol_load("v3_vi", vi_lib->handle, "HI_MPI_VI_DisableDev"))) return EXIT_FAILURE; - } if (!(vi_lib->fnEnableDevice = (int(*)(int device)) - dlsym(vi_lib->handle, "HI_MPI_VI_EnableDev"))) { - fprintf(stderr, "[v3_vi] Failed to acquire symbol HI_MPI_VI_EnableDev!\n"); + hal_symbol_load("v3_vi", vi_lib->handle, "HI_MPI_VI_EnableDev"))) return EXIT_FAILURE; - } if (!(vi_lib->fnSetDeviceConfig = (int(*)(int device, v3_vi_dev *config)) - dlsym(vi_lib->handle, "HI_MPI_VI_SetDevAttr"))) { - fprintf(stderr, "[v3_vi] Failed to acquire symbol HI_MPI_VI_SetDevAttr!\n"); + hal_symbol_load("v3_vi", vi_lib->handle, "HI_MPI_VI_SetDevAttr"))) return EXIT_FAILURE; - } if (!(vi_lib->fnDisableChannel = (int(*)(int channel)) - dlsym(vi_lib->handle, "HI_MPI_VI_DisableChn"))) { - fprintf(stderr, "[v3_vi] Failed to acquire symbol HI_MPI_VI_DisableChn!\n"); + hal_symbol_load("v3_vi", vi_lib->handle, "HI_MPI_VI_DisableChn"))) return EXIT_FAILURE; - } if (!(vi_lib->fnEnableChannel = (int(*)(int channel)) - dlsym(vi_lib->handle, "HI_MPI_VI_EnableChn"))) { - fprintf(stderr, "[v3_vi] Failed to acquire symbol HI_MPI_VI_EnableChn!\n"); + hal_symbol_load("v3_vi", vi_lib->handle, "HI_MPI_VI_EnableChn"))) return EXIT_FAILURE; - } if (!(vi_lib->fnSetChannelConfig = (int(*)(int channel, v3_vi_chn *config)) - dlsym(vi_lib->handle, "HI_MPI_VI_SetChnAttr"))) { - fprintf(stderr, "[v3_vi] Failed to acquire symbol HI_MPI_VI_SetChnAttr!\n"); + hal_symbol_load("v3_vi", vi_lib->handle, "HI_MPI_VI_SetChnAttr"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/hisi/v3_vpss.h b/src/hal/hisi/v3_vpss.h index c25ef41..ad3488b 100644 --- a/src/hal/hisi/v3_vpss.h +++ b/src/hal/hisi/v3_vpss.h @@ -52,70 +52,48 @@ typedef struct { } v3_vpss_impl; static int v3_vpss_load(v3_vpss_impl *vpss_lib) { - if (!(vpss_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL))) { - fprintf(stderr, "[v3_vpss] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + if (!(vpss_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL))) + HAL_ERROR("v3_vpss", "Failed to load library!\nError: %s\n", dlerror()); if (!(vpss_lib->fnCreateGroup = (int(*)(int group, v3_vpss_grp *config)) - dlsym(vpss_lib->handle, "HI_MPI_VPSS_CreateGrp"))) { - fprintf(stderr, "[v3_vpss] Failed to acquire symbol HI_MPI_VPSS_CreateGrp!\n"); - return EXIT_FAILURE; - } + hal_symbol_load("v3_vpss", vpss_lib->handle, "HI_MPI_VPSS_CreateGrp"))) + return EXIT_SUCCESS; if (!(vpss_lib->fnDestroyGroup = (int(*)(int group)) - dlsym(vpss_lib->handle, "HI_MPI_VPSS_DestroyGrp"))) { - fprintf(stderr, "[v3_vpss] Failed to acquire symbol HI_MPI_VPSS_DestroyGrp!\n"); + hal_symbol_load("v3_vpss", vpss_lib->handle, "HI_MPI_VPSS_DestroyGrp"))) return EXIT_FAILURE; - } if (!(vpss_lib->fnResetGroup = (int(*)(int group)) - dlsym(vpss_lib->handle, "HI_MPI_VPSS_ResetGrp"))) { - fprintf(stderr, "[v3_vpss] Failed to acquire symbol HI_MPI_VPSS_ResetGrp!\n"); + hal_symbol_load("v3_vpss", vpss_lib->handle, "HI_MPI_VPSS_ResetGrp"))) return EXIT_FAILURE; - } if (!(vpss_lib->fnSetGroupConfig = (int(*)(int group, v3_vpss_grp *config)) - dlsym(vpss_lib->handle, "HI_MPI_VPSS_SetGrpAttr"))) { - fprintf(stderr, "[v3_vpss] Failed to acquire symbol HI_MPI_VPSS_SetGrpAttr!\n"); + hal_symbol_load("v3_vpss", vpss_lib->handle, "HI_MPI_VPSS_SetGrpAttr"))) return EXIT_FAILURE; - } if (!(vpss_lib->fnStartGroup = (int(*)(int group)) - dlsym(vpss_lib->handle, "HI_MPI_VPSS_StartGrp"))) { - fprintf(stderr, "[v3_vpss] Failed to acquire symbol HI_MPI_VPSS_StartGrp!\n"); + hal_symbol_load("v3_vpss", vpss_lib->handle, "HI_MPI_VPSS_StartGrp"))) return EXIT_FAILURE; - } if (!(vpss_lib->fnStopGroup = (int(*)(int group)) - dlsym(vpss_lib->handle, "HI_MPI_VPSS_StopGrp"))) { - fprintf(stderr, "[v3_vpss] Failed to acquire symbol HI_MPI_VPSS_StopGrp!\n"); + hal_symbol_load("v3_vpss", vpss_lib->handle, "HI_MPI_VPSS_StopGrp"))) return EXIT_FAILURE; - } if (!(vpss_lib->fnDisableChannel = (int(*)(int group, int channel)) - dlsym(vpss_lib->handle, "HI_MPI_VPSS_DisableChn"))) { - fprintf(stderr, "[v3_vpss] Failed to acquire symbol HI_MPI_VPSS_DisableChn!\n"); + hal_symbol_load("v3_vpss", vpss_lib->handle, "HI_MPI_VPSS_DisableChn"))) return EXIT_FAILURE; - } if (!(vpss_lib->fnEnableChannel = (int(*)(int group, int channel)) - dlsym(vpss_lib->handle, "HI_MPI_VPSS_EnableChn"))) { - fprintf(stderr, "[v3_vpss] Failed to acquire symbol HI_MPI_VPSS_EnableChn!\n"); + hal_symbol_load("v3_vpss", vpss_lib->handle, "HI_MPI_VPSS_EnableChn"))) return EXIT_FAILURE; - } if (!(vpss_lib->fnSetChannelConfig = (int(*)(int group, int channel, v3_vpss_chn *config)) - dlsym(vpss_lib->handle, "HI_MPI_VPSS_SetChnAttr"))) { - fprintf(stderr, "[v3_vpss] Failed to acquire symbol HI_MPI_VPSS_SetChnAttr!\n"); + hal_symbol_load("v3_vpss", vpss_lib->handle, "HI_MPI_VPSS_SetChnAttr"))) return EXIT_FAILURE; - } if (!(vpss_lib->fnSetChannelMode = (int(*)(int group, int channel, v3_vpss_mode *config)) - dlsym(vpss_lib->handle, "HI_MPI_VPSS_SetChnMode"))) { - fprintf(stderr, "[v3_vpss] Failed to acquire symbol HI_MPI_VPSS_SetChnMode!\n"); + hal_symbol_load("v3_vpss", vpss_lib->handle, "HI_MPI_VPSS_SetChnMode"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/hisi/v4_aud.h b/src/hal/hisi/v4_aud.h index 658c9cd..567fa4e 100644 --- a/src/hal/hisi/v4_aud.h +++ b/src/hal/hisi/v4_aud.h @@ -77,52 +77,36 @@ static int v4_aud_load(v4_aud_impl *aud_lib) { if ( !(aud_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL)) && (!(aud_lib->handleGoke = dlopen("libgk_api.so", RTLD_LAZY | RTLD_GLOBAL)) || - !(aud_lib->handle = dlopen("libhi_mpi.so", RTLD_LAZY | RTLD_GLOBAL)))) { - fprintf(stderr, "[v4_aud] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + !(aud_lib->handle = dlopen("libhi_mpi.so", RTLD_LAZY | RTLD_GLOBAL)))) + HAL_ERROR("v4_aud", "Failed to load library!\nError: %s\n", dlerror()); if (!(aud_lib->fnDisableDevice = (int(*)(int device)) - dlsym(aud_lib->handle, "HI_MPI_AI_Disable"))) { - fprintf(stderr, "[v4_aud] Failed to acquire symbol HI_MPI_AI_Disable!\n"); + hal_symbol_load("v4_aud", aud_lib->handle, "HI_MPI_AI_Disable"))) return EXIT_FAILURE; - } if (!(aud_lib->fnEnableDevice = (int(*)(int device)) - dlsym(aud_lib->handle, "HI_MPI_AI_Enable"))) { - fprintf(stderr, "[v4_aud] Failed to acquire symbol HI_MPI_AI_Enable!\n"); + hal_symbol_load("v4_aud", aud_lib->handle, "HI_MPI_AI_Enable"))) return EXIT_FAILURE; - } if (!(aud_lib->fnSetDeviceConfig = (int(*)(int device, v4_aud_cnf *config)) - dlsym(aud_lib->handle, "HI_MPI_AI_SetPubAttr"))) { - fprintf(stderr, "[v4_aud] Failed to acquire symbol HI_MPI_AI_SetPubAttr!\n"); + hal_symbol_load("v4_aud", aud_lib->handle, "HI_MPI_AI_SetPubAttr"))) return EXIT_FAILURE; - } if (!(aud_lib->fnDisableChannel = (int(*)(int device, int channel)) - dlsym(aud_lib->handle, "HI_MPI_AI_DisableChn"))) { - fprintf(stderr, "[v4_aud] Failed to acquire symbol HI_MPI_AI_DisableChn!\n"); + hal_symbol_load("v4_aud", aud_lib->handle, "HI_MPI_AI_DisableChn"))) return EXIT_FAILURE; - } if (!(aud_lib->fnEnableChannel = (int(*)(int device, int channel)) - dlsym(aud_lib->handle, "HI_MPI_AI_EnableChn"))) { - fprintf(stderr, "[v4_aud] Failed to acquire symbol HI_MPI_AI_EnableChn!\n"); + hal_symbol_load("v4_aud", aud_lib->handle, "HI_MPI_AI_EnableChn"))) return EXIT_FAILURE; - } if (!(aud_lib->fnFreeFrame = (int(*)(int device, int channel, v4_aud_frm *frame, v4_aud_efrm *encFrame)) - dlsym(aud_lib->handle, "HI_MPI_AI_ReleaseFrame"))) { - fprintf(stderr, "[v4_aud] Failed to acquire symbol HI_MPI_AI_ReleaseFrame!\n"); + hal_symbol_load("v4_aud", aud_lib->handle, "HI_MPI_AI_ReleaseFrame"))) return EXIT_FAILURE; - } if (!(aud_lib->fnGetFrame = (int(*)(int device, int channel, v4_aud_frm *frame, v4_aud_efrm *encFrame, int millis)) - dlsym(aud_lib->handle, "HI_MPI_AI_GetFrame"))) { - fprintf(stderr, "[v4_aud] Failed to acquire symbol HI_MPI_AI_GetFrame!\n"); + hal_symbol_load("v4_aud", aud_lib->handle, "HI_MPI_AI_GetFrame"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/hisi/v4_common.h b/src/hal/hisi/v4_common.h index df33456..be6aa7b 100644 --- a/src/hal/hisi/v4_common.h +++ b/src/hal/hisi/v4_common.h @@ -6,16 +6,9 @@ #include #include +#include "../symbols.h" #include "../types.h" -#define V4_ERROR(x, ...) \ - do { \ - fprintf(stderr, "[v4_hal] \033[31m"); \ - fprintf(stderr, (x), ##__VA_ARGS__); \ - fprintf(stderr, "\033[0m"); \ - return EXIT_FAILURE; \ - } while (0) - typedef enum { V4_BAYER_RG, V4_BAYER_GR, diff --git a/src/hal/hisi/v4_hal.c b/src/hal/hisi/v4_hal.c index a105bb1..1a8d315 100644 --- a/src/hal/hisi/v4_hal.c +++ b/src/hal/hisi/v4_hal.c @@ -113,7 +113,7 @@ void *v4_audio_thread(void) while (keepRunning) { if (ret = v4_aud.fnGetFrame(_v4_aud_dev, _v4_aud_chn, &frame, &echoFrame, 128)) { - fprintf(stderr, "[v4_aud] Getting the frame failed " + HAL_WARNING("v4_aud", "Getting the frame failed " "with %#x!\n", ret); continue; } @@ -130,7 +130,7 @@ void *v4_audio_thread(void) if (ret = v4_aud.fnFreeFrame(_v4_aud_dev, _v4_aud_chn, &frame, &echoFrame)) { - fprintf(stderr, "[v4_aud] Releasing the frame failed" + HAL_WARNING("v4_aud", "Releasing the frame failed" " with %#x!\n", ret); } } @@ -219,8 +219,8 @@ void *v4_image_thread(void) int ret; if (ret = v4_isp.fnRun(_v4_isp_dev)) - fprintf(stderr, "[v4_isp] Operation failed with %#x!\n", ret); - fprintf(stderr, "[v4_isp] Shutting down ISP thread...\n"); + HAL_DANGER("v4_isp", "Operation failed with %#x!\n", ret); + HAL_INFO("v4_isp", "Shutting down ISP thread...\n"); } int v4_pipeline_create(void) @@ -407,12 +407,12 @@ int v4_region_create(char handle, hal_rect rect, short opacity) region.overlay.canvas = handle + 1; if (v4_rgn.fnGetRegionConfig(handle, ®ionCurr)) { - fprintf(stderr, "[v4_rgn] Creating region %d...\n", handle); + HAL_INFO("v4_rgn", "Creating region %d...\n", handle); if (ret = v4_rgn.fnCreateRegion(handle, ®ion)) return ret; } else if (regionCurr.overlay.size.height != region.overlay.size.height || regionCurr.overlay.size.width != region.overlay.size.width) { - fprintf(stderr, "[v4_rgn] Parameters are different, recreating " + HAL_INFO("v4_rgn", "Parameters are different, recreating " "region %d...\n", handle); v4_rgn.fnDetachChannel(handle, &channel); v4_rgn.fnDestroyRegion(handle); @@ -421,9 +421,9 @@ int v4_region_create(char handle, hal_rect rect, short opacity) } if (v4_rgn.fnGetChannelConfig(handle, &channel, &attribCurr)) - fprintf(stderr, "[v4_rgn] Attaching region %d...\n", handle); + HAL_INFO("v4_rgn", "Attaching region %d...\n", handle); else if (attribCurr.overlay.point.x != rect.x || attribCurr.overlay.point.x != rect.y) { - fprintf(stderr, "[v4_rgn] Position has changed, reattaching " + HAL_INFO("v4_rgn", "Position has changed, reattaching " "region %d...\n", handle); v4_rgn.fnDetachChannel(handle, &channel); } @@ -477,7 +477,7 @@ int v4_sensor_config(void) { fd = open(v4_snr_endp, O_RDWR); else fd = open("/dev/mipi", O_RDWR); if (fd < 0) - V4_ERROR("Opening imaging device has failed!\n"); + HAL_ERROR("v4_snr", "Opening imaging device has failed!\n"); int laneMode = 0; ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CONF_HSMODE, int), &laneMode); @@ -491,7 +491,7 @@ int v4_sensor_config(void) { ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_RST_SENS, unsigned int), &config.device); if (ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CONF_DEV, v4_snr_dev), &config)) - V4_ERROR("Configuring imaging device has failed!\n"); + HAL_ERROR("v4_snr", "Configuring imaging device has failed!\n"); ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_UNRST_MIPI, unsigned int), &config.device); @@ -511,7 +511,7 @@ void v4_sensor_deconfig(void) { fd = open(v4_snr_endp, O_RDWR); else fd = open("/dev/mipi", O_RDWR); if (fd < 0) - fprintf(stderr, "[v4_hal] Opening imaging device has failed!\n"); + HAL_DANGER("v4_snr", "Opening imaging device has failed!\n"); ioctl(fd, _IOW(V4_SNR_IOC_MAGIC, V4_SNR_CMD_CLKOFF_SENS, unsigned int), &config.device); @@ -541,10 +541,10 @@ int v4_sensor_init(char *name, char *obj) if (v4_snr_drv.handle = dlopen(path, RTLD_LAZY | RTLD_GLOBAL)) break; } if (!v4_snr_drv.handle) - V4_ERROR("Failed to load the sensor driver"); + HAL_ERROR("v4_snr", "Failed to load the sensor driver"); if (!(v4_snr_drv.obj = (v4_snr_obj*)dlsym(v4_snr_drv.handle, obj))) - V4_ERROR("Failed to connect the sensor object"); + HAL_ERROR("v4_snr", "Failed to connect the sensor object"); return EXIT_SUCCESS; } @@ -572,7 +572,7 @@ int v4_video_create(char index, hal_vidconfig *config) channel.rate.mjpgQp = (v4_venc_rate_mjpgqp){ .srcFps = config->framerate, .dstFps = config->framerate, .quality = config->maxQual }; break; default: - V4_ERROR("MJPEG encoder can only support CBR, VBR or fixed QP modes!"); + HAL_ERROR("v4_venc", "MJPEG encoder can only support CBR, VBR or fixed QP modes!"); } } else if (config->codec == HAL_VIDCODEC_H265) { channel.attrib.codec = V4_VENC_CODEC_H265; @@ -599,7 +599,7 @@ int v4_video_create(char index, hal_vidconfig *config) .statTime = 1, .srcFps = config->framerate, .dstFps = config->framerate, .maxBitrate = config->bitrate }; break; default: - V4_ERROR("H.265 encoder does not support this mode!"); + HAL_ERROR("v4_venc", "H.265 encoder does not support this mode!"); } } else if (config->codec == HAL_VIDCODEC_H264) { channel.attrib.codec = V4_VENC_CODEC_H264; @@ -626,9 +626,9 @@ int v4_video_create(char index, hal_vidconfig *config) .statTime = 1, .srcFps = config->framerate, .dstFps = config->framerate, .maxBitrate = config->bitrate }; break; default: - V4_ERROR("H.264 encoder does not support this mode!"); + HAL_ERROR("v4_venc", "H.264 encoder does not support this mode!"); } - } else V4_ERROR("This codec is not supported by the hardware!"); + } else HAL_ERROR("v4_venc", "This codec is not supported by the hardware!"); channel.attrib.maxPic.width = config->width; channel.attrib.maxPic.height = config->height; channel.attrib.bufSize = ALIGN_UP(config->height * config->width * 3 / 4, 64); @@ -702,14 +702,14 @@ int v4_video_snapshot_grab(char index, hal_jpegdata *jpeg) int ret; if (ret = v4_channel_bind(index)) { - fprintf(stderr, "[v4_venc] Binding the encoder channel " + HAL_DANGER("v4_venc", "Binding the encoder channel " "%d failed with %#x!\n", index, ret); goto abort; } unsigned int count = 1; if (v4_venc.fnStartReceivingEx(index, &count)) { - fprintf(stderr, "[v4_venc] Requesting one frame " + HAL_DANGER("v4_venc", "Requesting one frame " "%d failed with %#x!\n", index, ret); goto abort; } @@ -722,23 +722,23 @@ int v4_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, "[v4_venc] Select operation failed!\n"); + HAL_DANGER("v4_venc", "Select operation failed!\n"); goto abort; } else if (ret == 0) { - fprintf(stderr, "[v4_venc] Capture stream timed out!\n"); + HAL_DANGER("v4_venc", "Capture stream timed out!\n"); goto abort; } if (FD_ISSET(fd, &readFds)) { v4_venc_stat stat; if (v4_venc.fnQuery(index, &stat)) { - fprintf(stderr, "[v4_venc] Querying the encoder channel " + HAL_DANGER("v4_venc", "Querying the encoder channel " "%d failed with %#x!\n", index, ret); goto abort; } if (!stat.curPacks) { - fprintf(stderr, "[v4_venc] Current frame is empty, skipping it!\n"); + HAL_DANGER("v4_venc", "Current frame is empty, skipping it!\n"); goto abort; } @@ -746,13 +746,13 @@ int v4_video_snapshot_grab(char index, hal_jpegdata *jpeg) memset(&strm, 0, sizeof(strm)); strm.packet = (v4_venc_pack*)malloc(sizeof(v4_venc_pack) * stat.curPacks); if (!strm.packet) { - fprintf(stderr, "[v4_venc] Memory allocation on channel %d failed!\n", index); + HAL_DANGER("v4_venc", "Memory allocation on channel %d failed!\n", index); goto abort; } strm.count = stat.curPacks; if (ret = v4_venc.fnGetStream(index, &strm, stat.curPacks)) { - fprintf(stderr, "[v4_venc] Getting the stream on " + HAL_DANGER("v4_venc", "Getting the stream on " "channel %d failed with %#x!\n", index, ret); free(strm.packet); strm.packet = NULL; @@ -800,7 +800,7 @@ void *v4_video_thread(void) ret = v4_venc.fnGetDescriptor(i); if (ret < 0) { - fprintf(stderr, "[v4_venc] Getting the encoder descriptor failed with %#x!\n", ret); + HAL_DANGER("v4_venc", "Getting the encoder descriptor failed with %#x!\n", ret); return NULL; } v4_state[i].fileDesc = ret; @@ -826,10 +826,10 @@ void *v4_video_thread(void) timeout.tv_usec = 0; ret = select(maxFd + 1, &readFds, NULL, NULL, &timeout); if (ret < 0) { - fprintf(stderr, "[v4_venc] Select operation failed!\n"); + HAL_DANGER("v4_venc", "Select operation failed!\n"); break; } else if (ret == 0) { - fprintf(stderr, "[v4_venc] Main stream loop timed out!\n"); + HAL_WARNING("v4_venc", "Main stream loop timed out!\n"); continue; } else { for (int i = 0; i < V4_VENC_CHN_NUM; i++) { @@ -839,26 +839,26 @@ void *v4_video_thread(void) memset(&stream, 0, sizeof(stream)); if (ret = v4_venc.fnQuery(i, &stat)) { - fprintf(stderr, "[v4_venc] Querying the encoder channel " + HAL_DANGER("v4_venc", "Querying the encoder channel " "%d failed with %#x!\n", i, ret); break; } if (!stat.curPacks) { - fprintf(stderr, "[v4_venc] Current frame is empty, skipping it!\n"); + HAL_WARNING("v4_venc", "Current frame is empty, skipping it!\n"); continue; } stream.packet = (v4_venc_pack*)malloc( sizeof(v4_venc_pack) * stat.curPacks); if (!stream.packet) { - fprintf(stderr, "[v4_venc] Memory allocation on channel %d failed!\n", i); + HAL_DANGER("v4_venc", "Memory allocation on channel %d failed!\n", i); break; } stream.count = stat.curPacks; if (ret = v4_venc.fnGetStream(i, &stream, 40)) { - fprintf(stderr, "[v4_venc] Getting the stream on " + HAL_DANGER("v4_venc", "Getting the stream on " "channel %d failed with %#x!\n", i, ret); break; } @@ -891,7 +891,7 @@ void *v4_video_thread(void) } if (ret = v4_venc.fnFreeStream(i, &stream)) { - fprintf(stderr, "[v4_venc] Releasing the stream on " + HAL_WARNING("v4_venc", "Releasing the stream on " "channel %d failed with %#x!\n", i, ret); } free(stream.packet); @@ -900,7 +900,7 @@ void *v4_video_thread(void) } } } - fprintf(stderr, "[v4_venc] Shutting down encoding thread...\n"); + HAL_INFO("v4_venc", "Shutting down encoding thread...\n"); } void v4_system_deinit(void) @@ -923,7 +923,7 @@ int v4_system_init(char *snrConfig) } if (v4_parse_sensor_config(snrConfig, &v4_config) != CONFIG_OK) - V4_ERROR("Can't load sensor config\n"); + HAL_ERROR("v4_sys", "Can't load sensor config\n"); if (ret = v4_sensor_init(v4_config.dll_file, v4_config.sensor_type)) return ret; diff --git a/src/hal/hisi/v4_isp.h b/src/hal/hisi/v4_isp.h index e83d15c..b87098f 100644 --- a/src/hal/hisi/v4_isp.h +++ b/src/hal/hisi/v4_isp.h @@ -67,87 +67,60 @@ static int v4_isp_load(v4_isp_impl *isp_lib) { (isp_lib->handle = dlopen("libhi_isp.so", RTLD_LAZY | RTLD_GLOBAL))) goto loaded; - fprintf(stderr, "[v4_isp] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; + HAL_ERROR("v4_isp", "Failed to load library!\nError: %s\n", dlerror()); loaded: if (!(fnISP_AlgRegisterDehaze = (int(*)(int)) - dlsym(isp_lib->handleDehaze, "ISP_AlgRegisterDehaze"))) { - fprintf(stderr, "[v4_isp] Failed to acquire symbol ISP_AlgRegisterDehaze!\n"); + hal_symbol_load("v4_isp", isp_lib->handleDehaze, "ISP_AlgRegisterDehaze"))) return EXIT_FAILURE; - } if (!(fnISP_AlgRegisterDrc = (int(*)(int)) - dlsym(isp_lib->handleDrc, "ISP_AlgRegisterDrc"))) { - fprintf(stderr, "[v4_isp] Failed to acquire symbol ISP_AlgRegisterDrc!\n"); + hal_symbol_load("v4_isp", isp_lib->handleDrc, "ISP_AlgRegisterDrc"))) return EXIT_FAILURE; - } if (!(fnISP_AlgRegisterLdci = (int(*)(int)) - dlsym(isp_lib->handleLdci, "ISP_AlgRegisterLdci"))) { - fprintf(stderr, "[v4_isp] Failed to acquire symbol ISP_AlgRegisterLdci!\n"); + hal_symbol_load("v4_isp", isp_lib->handleLdci, "ISP_AlgRegisterLdci"))) return EXIT_FAILURE; - } if (!(fnMPI_ISP_IrAutoRunOnce = (int(*)(int, void*)) - dlsym(isp_lib->handleIrAuto, "MPI_ISP_IrAutoRunOnce"))) { - fprintf(stderr, "[v4_isp] Failed to acquire symbol MPI_ISP_IrAutoRunOnce!\n"); + hal_symbol_load("v4_isp", isp_lib->handleIrAuto, "MPI_ISP_IrAutoRunOnce"))) return EXIT_FAILURE; - } if (!(isp_lib->fnExit = (int(*)(int pipe)) - dlsym(isp_lib->handle, "HI_MPI_ISP_Exit"))) { - fprintf(stderr, "[v4_isp] Failed to acquire symbol HI_MPI_ISP_Exit!\n"); + hal_symbol_load("v4_isp", isp_lib->handle, "HI_MPI_ISP_Exit"))) return EXIT_FAILURE; - } if (!(isp_lib->fnInit = (int(*)(int pipe)) - dlsym(isp_lib->handle, "HI_MPI_ISP_Init"))) { - fprintf(stderr, "[v4_isp] Failed to acquire symbol HI_MPI_ISP_Init!\n"); + hal_symbol_load("v4_isp", isp_lib->handle, "HI_MPI_ISP_Init"))) return EXIT_FAILURE; - } if (!(isp_lib->fnMemInit = (int(*)(int pipe)) - dlsym(isp_lib->handle, "HI_MPI_ISP_MemInit"))) { - fprintf(stderr, "[v4_isp] Failed to acquire symbol HI_MPI_ISP_MemInit!\n"); + hal_symbol_load("v4_isp", isp_lib->handle, "HI_MPI_ISP_MemInit"))) return EXIT_FAILURE; - } if (!(isp_lib->fnRun = (int(*)(int pipe)) - dlsym(isp_lib->handle, "HI_MPI_ISP_Run"))) { - fprintf(stderr, "[v4_isp] Failed to acquire symbol HI_MPI_ISP_Run!\n"); + hal_symbol_load("v4_isp", isp_lib->handle, "HI_MPI_ISP_Run"))) return EXIT_FAILURE; - } if (!(isp_lib->fnSetDeviceConfig = (int(*)(int pipe, v4_isp_dev *config)) - dlsym(isp_lib->handle, "HI_MPI_ISP_SetPubAttr"))) { - fprintf(stderr, "[v4_isp] Failed to acquire symbol HI_MPI_ISP_SetPubAttr!\n"); + hal_symbol_load("v4_isp", isp_lib->handle, "HI_MPI_ISP_SetPubAttr"))) return EXIT_FAILURE; - } if (!(isp_lib->fnRegisterAE = (int(*)(int pipe, v4_isp_alg *library)) - dlsym(isp_lib->handleAe, "HI_MPI_AE_Register"))) { - fprintf(stderr, "[v4_isp] Failed to acquire symbol HI_MPI_AE_Register!\n"); + hal_symbol_load("v4_isp", isp_lib->handleAe, "HI_MPI_AE_Register"))) return EXIT_FAILURE; - } if (!(isp_lib->fnRegisterAWB = (int(*)(int pipe, v4_isp_alg *library)) - dlsym(isp_lib->handleAwb, "HI_MPI_AWB_Register"))) { - fprintf(stderr, "[v4_isp] Failed to acquire symbol HI_MPI_AWB_Register!\n"); + hal_symbol_load("v4_isp", isp_lib->handleAwb, "HI_MPI_AWB_Register"))) return EXIT_FAILURE; - } if (!(isp_lib->fnUnregisterAE = (int(*)(int pipe, v4_isp_alg *library)) - dlsym(isp_lib->handleAe, "HI_MPI_AE_UnRegister"))) { - fprintf(stderr, "[v4_isp] Failed to acquire symbol HI_MPI_AE_UnRegister!\n"); + hal_symbol_load("v4_isp", isp_lib->handleAe, "HI_MPI_AE_UnRegister"))) return EXIT_FAILURE; - } if (!(isp_lib->fnUnregisterAWB = (int(*)(int pipe, v4_isp_alg *library)) - dlsym(isp_lib->handleAwb, "HI_MPI_AWB_UnRegister"))) { - fprintf(stderr, "[v4_isp] Failed to acquire symbol HI_MPI_AWB_UnRegister!\n"); + hal_symbol_load("v4_isp", isp_lib->handleAwb, "HI_MPI_AWB_UnRegister"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/hisi/v4_rgn.h b/src/hal/hisi/v4_rgn.h index ec451fc..cdc73fd 100644 --- a/src/hal/hisi/v4_rgn.h +++ b/src/hal/hisi/v4_rgn.h @@ -144,64 +144,44 @@ static int v4_rgn_load(v4_rgn_impl *rgn_lib) { if ( !(rgn_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL)) && (!(rgn_lib->handleGoke = dlopen("libgk_api.so", RTLD_LAZY | RTLD_GLOBAL)) || - !(rgn_lib->handle = dlopen("libhi_mpi.so", RTLD_LAZY | RTLD_GLOBAL)))) { - fprintf(stderr, "[v4_rgn] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + !(rgn_lib->handle = dlopen("libhi_mpi.so", RTLD_LAZY | RTLD_GLOBAL)))) + HAL_ERROR("v4_rgn", "Failed to load library!\nError: %s\n", dlerror()); if (!(rgn_lib->fnCreateRegion = (int(*)(unsigned int handle, v4_rgn_cnf *config)) - dlsym(rgn_lib->handle, "HI_MPI_RGN_Create"))) { - fprintf(stderr, "[v4_rgn] Failed to acquire symbol HI_MPI_RGN_Create!\n"); + hal_symbol_load("v4_rgn", rgn_lib->handle, "HI_MPI_RGN_Create"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnDestroyRegion = (int(*)(unsigned int handle)) - dlsym(rgn_lib->handle, "HI_MPI_RGN_Destroy"))) { - fprintf(stderr, "[v4_rgn] Failed to acquire symbol HI_MPI_RGN_Destroy!\n"); + hal_symbol_load("v4_rgn", rgn_lib->handle, "HI_MPI_RGN_Destroy"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnGetRegionConfig = (int(*)(unsigned int handle, v4_rgn_cnf *config)) - dlsym(rgn_lib->handle, "HI_MPI_RGN_GetAttr"))) { - fprintf(stderr, "[v4_rgn] Failed to acquire symbol HI_MPI_RGN_GetAttr!\n"); + hal_symbol_load("v4_rgn", rgn_lib->handle, "HI_MPI_RGN_GetAttr"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnSetRegionConfig = (int(*)(unsigned int handle, v4_rgn_cnf *config)) - dlsym(rgn_lib->handle, "HI_MPI_RGN_SetAttr"))) { - fprintf(stderr, "[v4_rgn] Failed to acquire symbol HI_MPI_RGN_SetAttr!\n"); + hal_symbol_load("v4_rgn", rgn_lib->handle, "HI_MPI_RGN_SetAttr"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnAttachChannel = (int(*)(unsigned int handle, v4_sys_bind *dest, v4_rgn_chn *config)) - dlsym(rgn_lib->handle, "HI_MPI_RGN_AttachToChn"))) { - fprintf(stderr, "[v4_rgn] Failed to acquire symbol HI_MPI_RGN_AttachToChn!\n"); + hal_symbol_load("v4_rgn", rgn_lib->handle, "HI_MPI_RGN_AttachToChn"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnDetachChannel = (int(*)(unsigned int handle, v4_sys_bind *dest)) - dlsym(rgn_lib->handle, "HI_MPI_RGN_DetachFromChn"))) { - fprintf(stderr, "[v4_rgn] Failed to acquire symbol HI_MPI_RGN_DetachFromChn!\n"); + hal_symbol_load("v4_rgn", rgn_lib->handle, "HI_MPI_RGN_DetachFromChn"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnGetChannelConfig = (int(*)(unsigned int handle, v4_sys_bind *dest, v4_rgn_chn *config)) - dlsym(rgn_lib->handle, "HI_MPI_RGN_GetDisplayAttr"))) { - fprintf(stderr, "[v4_rgn] Failed to acquire symbol HI_MPI_RGN_GetDisplayAttr!\n"); + hal_symbol_load("v4_rgn", rgn_lib->handle, "HI_MPI_RGN_GetDisplayAttr"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnSetChannelConfig = (int(*)(unsigned int handle, v4_sys_bind *dest, v4_rgn_chn *config)) - dlsym(rgn_lib->handle, "HI_MPI_RGN_SetDisplayAttr"))) { - fprintf(stderr, "[v4_rgn] Failed to acquire symbol HI_MPI_RGN_SetDisplayAttr!\n"); + hal_symbol_load("v4_rgn", rgn_lib->handle, "HI_MPI_RGN_SetDisplayAttr"))) return EXIT_FAILURE; - } if (!(rgn_lib->fnSetBitmap = (int(*)(unsigned int handle, v4_rgn_bmp *bitmap)) - dlsym(rgn_lib->handle, "HI_MPI_RGN_SetBitMap"))) { - fprintf(stderr, "[v4_rgn] Failed to acquire symbol HI_MPI_RGN_SetBitMap!\n"); + hal_symbol_load("v4_rgn", rgn_lib->handle, "HI_MPI_RGN_SetBitMap"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/hisi/v4_sys.h b/src/hal/hisi/v4_sys.h index cd4eba5..b1638ab 100644 --- a/src/hal/hisi/v4_sys.h +++ b/src/hal/hisi/v4_sys.h @@ -117,64 +117,44 @@ static int v4_sys_load(v4_sys_impl *sys_lib) { (!(sys_lib->handleVoiceEngine = dlopen("libvoice_engine.so", RTLD_LAZY | RTLD_GLOBAL)) || !(sys_lib->handleGoke = dlopen("libgk_api.so", RTLD_LAZY | RTLD_GLOBAL)) || - !(sys_lib->handle = dlopen("libhi_mpi.so", RTLD_LAZY | RTLD_GLOBAL))))) { - fprintf(stderr, "[v4_sys] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + !(sys_lib->handle = dlopen("libhi_mpi.so", RTLD_LAZY | RTLD_GLOBAL))))) + HAL_ERROR("v4_sys", "Failed to load library!\nError: %s\n", dlerror()); if (!(sys_lib->fnExit = (int(*)(void)) - dlsym(sys_lib->handle, "HI_MPI_SYS_Exit"))) { - fprintf(stderr, "[v4_sys] Failed to acquire symbol HI_MPI_SYS_Exit!\n"); + hal_symbol_load("v4_sys", sys_lib->handle, "HI_MPI_SYS_Exit"))) return EXIT_FAILURE; - } if (!(sys_lib->fnGetChipId = (int(*)(unsigned int *chip)) - dlsym(sys_lib->handle, "HI_MPI_SYS_GetChipId"))) { - fprintf(stderr, "[v4_sys] Failed to acquire symbol HI_MPI_SYS_GetChipId!\n"); + hal_symbol_load("v4_sys", sys_lib->handle, "HI_MPI_SYS_GetChipId"))) return EXIT_FAILURE; - } if (!(sys_lib->fnGetVersion = (int(*)(v4_sys_ver *version)) - dlsym(sys_lib->handle, "HI_MPI_SYS_GetVersion"))) { - fprintf(stderr, "[v4_sys] Failed to acquire symbol HI_MPI_SYS_GetVersion!\n"); + hal_symbol_load("v4_sys", sys_lib->handle, "HI_MPI_SYS_GetVersion"))) return EXIT_FAILURE; - } if (!(sys_lib->fnInit = (int(*)(void)) - dlsym(sys_lib->handle, "HI_MPI_SYS_Init"))) { - fprintf(stderr, "[v4_sys] Failed to acquire symbol HI_MPI_SYS_Init!\n"); + hal_symbol_load("v4_sys", sys_lib->handle, "HI_MPI_SYS_Init"))) return EXIT_FAILURE; - } if (!(sys_lib->fnSetAlignment = (int(*)(unsigned int *width)) - dlsym(sys_lib->handle, "HI_MPI_SYS_SetConfig"))) { - fprintf(stderr, "[v4_sys] Failed to acquire symbol HI_MPI_SYS_SetConfig!\n"); + hal_symbol_load("v4_sys", sys_lib->handle, "HI_MPI_SYS_SetConfig"))) return EXIT_FAILURE; - } if (!(sys_lib->fnBind = (int(*)(v4_sys_bind *source, v4_sys_bind *dest)) - dlsym(sys_lib->handle, "HI_MPI_SYS_Bind"))) { - fprintf(stderr, "[v4_sys] Failed to acquire symbol HI_MPI_SYS_Bind!\n"); + hal_symbol_load("v4_sys", sys_lib->handle, "HI_MPI_SYS_Bind"))) return EXIT_FAILURE; - } if (!(sys_lib->fnUnbind = (int(*)(v4_sys_bind *source, v4_sys_bind *dest)) - dlsym(sys_lib->handle, "HI_MPI_SYS_UnBind"))) { - fprintf(stderr, "[v4_sys] Failed to acquire symbol HI_MPI_SYS_UnBind!\n"); + hal_symbol_load("v4_sys", sys_lib->handle, "HI_MPI_SYS_UnBind"))) return EXIT_FAILURE; - } if (!(sys_lib->fnGetViVpssMode = (int(*)(v4_sys_oper *mode)) - dlsym(sys_lib->handle, "HI_MPI_SYS_GetVIVPSSMode"))) { - fprintf(stderr, "[v4_sys] Failed to acquire symbol HI_MPI_SYS_GetVIVPSSMode!\n"); + hal_symbol_load("v4_sys", sys_lib->handle, "HI_MPI_SYS_GetVIVPSSMode"))) return EXIT_FAILURE; - } if (!(sys_lib->fnSetViVpssMode = (int(*)(v4_sys_oper *mode)) - dlsym(sys_lib->handle, "HI_MPI_SYS_SetVIVPSSMode"))) { - fprintf(stderr, "[v4_sys] Failed to acquire symbol HI_MPI_SYS_SetVIVPSSMode!\n"); + hal_symbol_load("v4_sys", sys_lib->handle, "HI_MPI_SYS_SetVIVPSSMode"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/hisi/v4_vb.h b/src/hal/hisi/v4_vb.h index 9f9e554..dd34dff 100644 --- a/src/hal/hisi/v4_vb.h +++ b/src/hal/hisi/v4_vb.h @@ -33,34 +33,24 @@ static int v4_vb_load(v4_vb_impl *vb_lib) { if ( !(vb_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL)) && (!(vb_lib->handleGoke = dlopen("libgk_api.so", RTLD_LAZY | RTLD_GLOBAL)) || - !(vb_lib->handle = dlopen("libhi_mpi.so", RTLD_LAZY | RTLD_GLOBAL)))) { - fprintf(stderr, "[v4_vb] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + !(vb_lib->handle = dlopen("libhi_mpi.so", RTLD_LAZY | RTLD_GLOBAL)))) + HAL_ERROR("v4_vb", "Failed to load library!\nError: %s\n", dlerror()); if (!(vb_lib->fnConfigPool = (int(*)(v4_vb_pool *config)) - dlsym(vb_lib->handle, "HI_MPI_VB_SetConfig"))) { - fprintf(stderr, "[v4_vb] Failed to acquire symbol HI_MPI_VB_SetConfig!\n"); + hal_symbol_load("v4_vb", vb_lib->handle, "HI_MPI_VB_SetConfig"))) return EXIT_FAILURE; - } if (!(vb_lib->fnConfigSupplement = (int(*)(v4_vb_supl *value)) - dlsym(vb_lib->handle, "HI_MPI_VB_SetSupplementConfig"))) { - fprintf(stderr, "[v4_vb] Failed to acquire symbol HI_MPI_VB_SetSupplementConfig!\n"); + hal_symbol_load("v4_vb", vb_lib->handle, "HI_MPI_VB_SetSupplementConfig"))) return EXIT_FAILURE; - } if (!(vb_lib->fnExit = (int(*)(void)) - dlsym(vb_lib->handle, "HI_MPI_VB_Exit"))) { - fprintf(stderr, "[v4_vb] Failed to acquire symbol HI_MPI_VB_Exit!\n"); + hal_symbol_load("v4_vb", vb_lib->handle, "HI_MPI_VB_Exit"))) return EXIT_FAILURE; - } if (!(vb_lib->fnInit = (int(*)(void)) - dlsym(vb_lib->handle, "HI_MPI_VB_Init"))) { - fprintf(stderr, "[v4_vb] Failed to acquire symbol HI_MPI_VB_Init!\n"); + hal_symbol_load("v4_vb", vb_lib->handle, "HI_MPI_VB_Init"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/hisi/v4_venc.h b/src/hal/hisi/v4_venc.h index d5f51f0..21a18e1 100644 --- a/src/hal/hisi/v4_venc.h +++ b/src/hal/hisi/v4_venc.h @@ -401,112 +401,75 @@ static int v4_venc_load(v4_venc_impl *venc_lib) { if ( !(venc_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL)) && (!(venc_lib->handleGoke = dlopen("libgk_api.so", RTLD_LAZY | RTLD_GLOBAL)) || - !(venc_lib->handle = dlopen("libhi_mpi.so", RTLD_LAZY | RTLD_GLOBAL)))) { - fprintf(stderr, "[v4_venc] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + !(venc_lib->handle = dlopen("libhi_mpi.so", RTLD_LAZY | RTLD_GLOBAL)))) + HAL_ERROR("v4_venc", "Failed to load library!\nError: %s\n", dlerror()); if (!(venc_lib->fnCreateChannel = (int(*)(int channel, v4_venc_chn *config)) - dlsym(venc_lib->handle, "HI_MPI_VENC_CreateChn"))) { - fprintf(stderr, "[v4_venc] Failed to acquire symbol HI_MPI_VENC_CreateChn!\n"); + hal_symbol_load("v4_venc", venc_lib->handle, "HI_MPI_VENC_CreateChn"))) return EXIT_FAILURE; - } if (!(venc_lib->fnDestroyChannel = (int(*)(int channel)) - dlsym(venc_lib->handle, "HI_MPI_VENC_DestroyChn"))) { - fprintf(stderr, "[v4_venc] Failed to acquire symbol HI_MPI_VENC_DestroyChn!\n"); - return EXIT_FAILURE; - } + hal_symbol_load("v4_venc", venc_lib->handle, "HI_MPI_VENC_DestroyChn"))) if (!(venc_lib->fnGetChannelConfig = (int(*)(int channel, v4_venc_chn *config)) - dlsym(venc_lib->handle, "HI_MPI_VENC_GetChnAttr"))) { - fprintf(stderr, "[v4_venc] Failed to acquire symbol HI_MPI_VENC_GetChnAttr!\n"); + hal_symbol_load("v4_venc", venc_lib->handle, "HI_MPI_VENC_GetChnAttr"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetChannelParam = (int(*)(int channel, v4_venc_para *config)) - dlsym(venc_lib->handle, "HI_MPI_VENC_GetChnParam"))) { - fprintf(stderr, "[v4_venc] Failed to acquire symbol HI_MPI_VENC_GetChnParam!\n"); + hal_symbol_load("v4_venc", venc_lib->handle, "HI_MPI_VENC_GetChnParam"))) return EXIT_FAILURE; - } if (!(venc_lib->fnResetChannel = (int(*)(int channel)) - dlsym(venc_lib->handle, "HI_MPI_VENC_ResetChn"))) { - fprintf(stderr, "[v4_venc] Failed to acquire symbol HI_MPI_VENC_ResetChn!\n"); + hal_symbol_load("v4_venc", venc_lib->handle, "HI_MPI_VENC_ResetChn"))) return EXIT_FAILURE; - } if (!(venc_lib->fnSetChannelConfig = (int(*)(int channel, v4_venc_chn *config)) - dlsym(venc_lib->handle, "HI_MPI_VENC_SetChnAttr"))) { - fprintf(stderr, "[v4_venc] Failed to acquire symbol HI_MPI_VENC_SetChnAttr!\n"); + hal_symbol_load("v4_venc", venc_lib->handle, "HI_MPI_VENC_SetChnAttr"))) return EXIT_FAILURE; - } if (!(venc_lib->fnSetChannelParam = (int(*)(int channel, v4_venc_para *config)) - dlsym(venc_lib->handle, "HI_MPI_VENC_SetChnParam"))) { - fprintf(stderr, "[v4_venc] Failed to acquire symbol HI_MPI_VENC_SetChnParam!\n"); + hal_symbol_load("v4_venc", venc_lib->handle, "HI_MPI_VENC_SetChnParam"))) return EXIT_FAILURE; - } if (!(venc_lib->fnFreeDescriptor = (int(*)(int channel)) - dlsym(venc_lib->handle, "HI_MPI_VENC_CloseFd"))) { - fprintf(stderr, "[v4_venc] Failed to acquire symbol HI_MPI_VENC_CloseFd!\n"); + hal_symbol_load("v4_venc", venc_lib->handle, "HI_MPI_VENC_CloseFd"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetDescriptor = (int(*)(int channel)) - dlsym(venc_lib->handle, "HI_MPI_VENC_GetFd"))) { - fprintf(stderr, "[v4_venc] Failed to acquire symbol HI_MPI_VENC_GetFd!\n"); + hal_symbol_load("v4_venc", venc_lib->handle, "HI_MPI_VENC_GetFd"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetJpegParam = (int(*)(int channel, v4_venc_jpg *param)) - dlsym(venc_lib->handle, "HI_MPI_VENC_GetJpegParam"))) { - fprintf(stderr, "[v4_venc] Failed to acquire symbol HI_MPI_VENC_GetJpegParam!\n"); + hal_symbol_load("v4_venc", venc_lib->handle, "HI_MPI_VENC_GetJpegParam"))) return EXIT_FAILURE; - } if (!(venc_lib->fnSetJpegParam = (int(*)(int channel, v4_venc_jpg *param)) - dlsym(venc_lib->handle, "HI_MPI_VENC_SetJpegParam"))) { - fprintf(stderr, "[v4_venc] Failed to acquire symbol HI_MPI_VENC_SetJpegParam!\n"); + hal_symbol_load("v4_venc", venc_lib->handle, "HI_MPI_VENC_SetJpegParam"))) return EXIT_FAILURE; - } if (!(venc_lib->fnFreeStream = (int(*)(int channel, v4_venc_strm *stream)) - dlsym(venc_lib->handle, "HI_MPI_VENC_ReleaseStream"))) { - fprintf(stderr, "[v4_venc] Failed to acquire symbol HI_MPI_VENC_ReleaseStream!\n"); + hal_symbol_load("v4_venc", venc_lib->handle, "HI_MPI_VENC_ReleaseStream"))) return EXIT_FAILURE; - } if (!(venc_lib->fnGetStream = (int(*)(int channel, v4_venc_strm *stream, unsigned int timeout)) - dlsym(venc_lib->handle, "HI_MPI_VENC_GetStream"))) { - fprintf(stderr, "[v4_venc] Failed to acquire symbol HI_MPI_VENC_GetStream!\n"); + hal_symbol_load("v4_venc", venc_lib->handle, "HI_MPI_VENC_GetStream"))) return EXIT_FAILURE; - } if (!(venc_lib->fnQuery = (int(*)(int channel, v4_venc_stat *stats)) - dlsym(venc_lib->handle, "HI_MPI_VENC_QueryStatus"))) { - fprintf(stderr, "[v4_venc] Failed to acquire symbol HI_MPI_VENC_QueryStatus!\n"); + hal_symbol_load("v4_venc", venc_lib->handle, "HI_MPI_VENC_QueryStatus"))) return EXIT_FAILURE; - } if (!(venc_lib->fnRequestIdr = (int(*)(int channel, int instant)) - dlsym(venc_lib->handle, "HI_MPI_VENC_RequestIDR"))) { - fprintf(stderr, "[v4_venc] Failed to acquire symbol HI_MPI_VENC_RequestIDR!\n"); + hal_symbol_load("v4_venc", venc_lib->handle, "HI_MPI_VENC_RequestIDR"))) return EXIT_FAILURE; - } if (!(venc_lib->fnStartReceivingEx = (int(*)(int channel, int *count)) - dlsym(venc_lib->handle, "HI_MPI_VENC_StartRecvFrame"))) { - fprintf(stderr, "[v4_venc] Failed to acquire symbol HI_MPI_VENC_StartRecvFrame!\n"); + hal_symbol_load("v4_venc", venc_lib->handle, "HI_MPI_VENC_StartRecvFrame"))) return EXIT_FAILURE; - } if (!(venc_lib->fnStopReceiving = (int(*)(int channel)) - dlsym(venc_lib->handle, "HI_MPI_VENC_StopRecvFrame"))) { - fprintf(stderr, "[v4_venc] Failed to acquire symbol HI_MPI_VENC_StopRecvPic!\n"); + hal_symbol_load("v4_venc", venc_lib->handle, "HI_MPI_VENC_StopRecvFrame"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/hisi/v4_vi.h b/src/hal/hisi/v4_vi.h index b6e0e2b..6ff6375 100644 --- a/src/hal/hisi/v4_vi.h +++ b/src/hal/hisi/v4_vi.h @@ -156,76 +156,52 @@ static int v4_vi_load(v4_vi_impl *vi_lib) { if ( !(vi_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL)) && (!(vi_lib->handleGoke = dlopen("libgk_api.so", RTLD_LAZY | RTLD_GLOBAL)) || - !(vi_lib->handle = dlopen("libhi_mpi.so", RTLD_LAZY | RTLD_GLOBAL)))) { - fprintf(stderr, "[v4_vi] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + !(vi_lib->handle = dlopen("libhi_mpi.so", RTLD_LAZY | RTLD_GLOBAL)))) + HAL_ERROR("v4_vi", "Failed to load library!\nError: %s\n", dlerror()); if (!(vi_lib->fnDisableDevice = (int(*)(int device)) - dlsym(vi_lib->handle, "HI_MPI_VI_DisableDev"))) { - fprintf(stderr, "[v4_vi] Failed to acquire symbol HI_MPI_VI_DisableDev!\n"); + hal_symbol_load("v4_vi", vi_lib->handle, "HI_MPI_VI_DisableDev"))) return EXIT_FAILURE; - } if (!(vi_lib->fnEnableDevice = (int(*)(int device)) - dlsym(vi_lib->handle, "HI_MPI_VI_EnableDev"))) { - fprintf(stderr, "[v4_vi] Failed to acquire symbol HI_MPI_VI_EnableDev!\n"); + hal_symbol_load("v4_vi", vi_lib->handle, "HI_MPI_VI_EnableDev"))) return EXIT_FAILURE; - } if (!(vi_lib->fnSetDeviceConfig = (int(*)(int device, v4_vi_dev *config)) - dlsym(vi_lib->handle, "HI_MPI_VI_SetDevAttr"))) { - fprintf(stderr, "[v4_vi] Failed to acquire symbol HI_MPI_VI_SetDevAttr!\n"); + hal_symbol_load("v4_vi", vi_lib->handle, "HI_MPI_VI_SetDevAttr"))) return EXIT_FAILURE; - } if (!(vi_lib->fnDisableChannel = (int(*)(int pipe, int channel)) - dlsym(vi_lib->handle, "HI_MPI_VI_DisableChn"))) { - fprintf(stderr, "[v4_vi] Failed to acquire symbol HI_MPI_VI_DisableChn!\n"); + hal_symbol_load("v4_vi", vi_lib->handle, "HI_MPI_VI_DisableChn"))) return EXIT_FAILURE; - } if (!(vi_lib->fnEnableChannel = (int(*)(int pipe, int channel)) - dlsym(vi_lib->handle, "HI_MPI_VI_EnableChn"))) { - fprintf(stderr, "[v4_vi] Failed to acquire symbol HI_MPI_VI_EnableChn!\n"); + hal_symbol_load("v4_vi", vi_lib->handle, "HI_MPI_VI_EnableChn"))) return EXIT_FAILURE; - } if (!(vi_lib->fnSetChannelConfig = (int(*)(int pipe, int channel, v4_vi_chn *config)) - dlsym(vi_lib->handle, "HI_MPI_VI_SetChnAttr"))) { - fprintf(stderr, "[v4_vi] Failed to acquire symbol HI_MPI_VI_SetChnAttr!\n"); + hal_symbol_load("v4_vi", vi_lib->handle, "HI_MPI_VI_SetChnAttr"))) return EXIT_FAILURE; - } if (!(vi_lib->fnBindPipe = (int(*)(int device, v4_vi_bind *config)) - dlsym(vi_lib->handle, "HI_MPI_VI_SetDevBindPipe"))) { - fprintf(stderr, "[v4_vi] Failed to acquire symbol HI_MPI_VI_SetDevBindPipe!\n"); + hal_symbol_load("v4_vi", vi_lib->handle, "HI_MPI_VI_SetDevBindPipe"))) return EXIT_FAILURE; - } if (!(vi_lib->fnCreatePipe = (int(*)(int pipe, v4_vi_pipe *config)) - dlsym(vi_lib->handle, "HI_MPI_VI_CreatePipe"))) { - fprintf(stderr, "[v4_vi] Failed to acquire symbol HI_MPI_VI_CreatePipe!\n"); + hal_symbol_load("v4_vi", vi_lib->handle, "HI_MPI_VI_CreatePipe"))) return EXIT_FAILURE; - } if (!(vi_lib->fnDestroyPipe = (int(*)(int pipe)) - dlsym(vi_lib->handle, "HI_MPI_VI_DestroyPipe"))) { - fprintf(stderr, "[v4_vi] Failed to acquire symbol HI_MPI_VI_DestroyPipe!\n"); + hal_symbol_load("v4_vi", vi_lib->handle, "HI_MPI_VI_DestroyPipe"))) return EXIT_FAILURE; - } if (!(vi_lib->fnStartPipe = (int(*)(int pipe)) - dlsym(vi_lib->handle, "HI_MPI_VI_StartPipe"))) { - fprintf(stderr, "[v4_vi] Failed to acquire symbol HI_MPI_VI_StartPipe!\n"); + hal_symbol_load("v4_vi", vi_lib->handle, "HI_MPI_VI_StartPipe"))) return EXIT_FAILURE; - } if (!(vi_lib->fnStopPipe = (int(*)(int pipe)) - dlsym(vi_lib->handle, "HI_MPI_VI_StopPipe"))) { - fprintf(stderr, "[v4_vi] Failed to acquire symbol HI_MPI_VI_StopPipe!\n"); + hal_symbol_load("v4_vi", vi_lib->handle, "HI_MPI_VI_StopPipe"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; } diff --git a/src/hal/hisi/v4_vpss.h b/src/hal/hisi/v4_vpss.h index f21ef75..8a51974 100644 --- a/src/hal/hisi/v4_vpss.h +++ b/src/hal/hisi/v4_vpss.h @@ -67,64 +67,44 @@ static int v4_vpss_load(v4_vpss_impl *vpss_lib) { if ( !(vpss_lib->handle = dlopen("libmpi.so", RTLD_LAZY | RTLD_GLOBAL)) && (!(vpss_lib->handleGoke = dlopen("libgk_api.so", RTLD_LAZY | RTLD_GLOBAL)) || - !(vpss_lib->handle = dlopen("libhi_mpi.so", RTLD_LAZY | RTLD_GLOBAL)))) { - fprintf(stderr, "[v4_vpss] Failed to load library!\nError: %s\n", dlerror()); - return EXIT_FAILURE; - } + !(vpss_lib->handle = dlopen("libhi_mpi.so", RTLD_LAZY | RTLD_GLOBAL)))) + HAL_ERROR("v4_vpss", "Failed to load library!\nError: %s\n", dlerror()); if (!(vpss_lib->fnCreateGroup = (int(*)(int group, v4_vpss_grp *config)) - dlsym(vpss_lib->handle, "HI_MPI_VPSS_CreateGrp"))) { - fprintf(stderr, "[v4_vpss] Failed to acquire symbol HI_MPI_VPSS_CreateGrp!\n"); + hal_symbol_load("v4_vpss", vpss_lib->handle, "HI_MPI_VPSS_CreateGrp"))) return EXIT_FAILURE; - } if (!(vpss_lib->fnDestroyGroup = (int(*)(int group)) - dlsym(vpss_lib->handle, "HI_MPI_VPSS_DestroyGrp"))) { - fprintf(stderr, "[v4_vpss] Failed to acquire symbol HI_MPI_VPSS_DestroyGrp!\n"); + hal_symbol_load("v4_vpss", vpss_lib->handle, "HI_MPI_VPSS_DestroyGrp"))) return EXIT_FAILURE; - } if (!(vpss_lib->fnResetGroup = (int(*)(int group)) - dlsym(vpss_lib->handle, "HI_MPI_VPSS_ResetGrp"))) { - fprintf(stderr, "[v4_vpss] Failed to acquire symbol HI_MPI_VPSS_ResetGrp!\n"); + hal_symbol_load("v4_vpss", vpss_lib->handle, "HI_MPI_VPSS_ResetGrp"))) return EXIT_FAILURE; - } if (!(vpss_lib->fnSetGroupConfig = (int(*)(int group, v4_vpss_grp *config)) - dlsym(vpss_lib->handle, "HI_MPI_VPSS_SetGrpAttr"))) { - fprintf(stderr, "[v4_vpss] Failed to acquire symbol HI_MPI_VPSS_SetGrpAttr!\n"); + hal_symbol_load("v4_vpss", vpss_lib->handle, "HI_MPI_VPSS_SetGrpAttr"))) return EXIT_FAILURE; - } if (!(vpss_lib->fnStartGroup = (int(*)(int group)) - dlsym(vpss_lib->handle, "HI_MPI_VPSS_StartGrp"))) { - fprintf(stderr, "[v4_vpss] Failed to acquire symbol HI_MPI_VPSS_StartGrp!\n"); + hal_symbol_load("v4_vpss", vpss_lib->handle, "HI_MPI_VPSS_StartGrp"))) return EXIT_FAILURE; - } if (!(vpss_lib->fnStopGroup = (int(*)(int group)) - dlsym(vpss_lib->handle, "HI_MPI_VPSS_StopGrp"))) { - fprintf(stderr, "[v4_vpss] Failed to acquire symbol HI_MPI_VPSS_StopGrp!\n"); + hal_symbol_load("v4_vpss", vpss_lib->handle, "HI_MPI_VPSS_StopGrp"))) return EXIT_FAILURE; - } if (!(vpss_lib->fnDisableChannel = (int(*)(int group, int channel)) - dlsym(vpss_lib->handle, "HI_MPI_VPSS_DisableChn"))) { - fprintf(stderr, "[v4_vpss] Failed to acquire symbol HI_MPI_VPSS_DisableChn!\n"); + hal_symbol_load("v4_vpss", vpss_lib->handle, "HI_MPI_VPSS_DisableChn"))) return EXIT_FAILURE; - } if (!(vpss_lib->fnEnableChannel = (int(*)(int group, int channel)) - dlsym(vpss_lib->handle, "HI_MPI_VPSS_EnableChn"))) { - fprintf(stderr, "[v4_vpss] Failed to acquire symbol HI_MPI_VPSS_EnableChn!\n"); + hal_symbol_load("v4_vpss", vpss_lib->handle, "HI_MPI_VPSS_EnableChn"))) return EXIT_FAILURE; - } if (!(vpss_lib->fnSetChannelConfig = (int(*)(int group, int channel, v4_vpss_chn *config)) - dlsym(vpss_lib->handle, "HI_MPI_VPSS_SetChnAttr"))) { - fprintf(stderr, "[v4_vpss] Failed to acquire symbol HI_MPI_VPSS_SetChnAttr!\n"); + hal_symbol_load("v4_vpss", vpss_lib->handle, "HI_MPI_VPSS_SetChnAttr"))) return EXIT_FAILURE; - } return EXIT_SUCCESS; }