Skip to content

Commit

Permalink
Reducing the executable size by building module strings as they are n…
Browse files Browse the repository at this point in the history
…eeded, inlining repetitive symbol loading stuff
  • Loading branch information
wberube committed Jul 10, 2024
1 parent ee45813 commit 391cb3e
Show file tree
Hide file tree
Showing 45 changed files with 593 additions and 1,419 deletions.
54 changes: 14 additions & 40 deletions src/hal/inge/t31_aud.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
9 changes: 1 addition & 8 deletions src/hal/inge/t31_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,9 @@
#include <string.h>
#include <sys/select.h>

#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,
Expand Down
34 changes: 9 additions & 25 deletions src/hal/inge/t31_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
48 changes: 24 additions & 24 deletions src/hal/inge/t31_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -301,13 +301,13 @@ int t31_region_create(int *handle, hal_rect rect, short opacity)
region.data.picture = NULL;

if (t31_osd.fnGetRegionConfig(*handle, &regionCurr)) {
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(&region)) < 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, &region))
return ret;
Expand All @@ -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;
Expand Down Expand Up @@ -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:
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
Expand All @@ -500,37 +500,37 @@ 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;
}

t31_venc_strm strm;
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;
Expand Down Expand Up @@ -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;
Expand All @@ -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++) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit 391cb3e

Please sign in to comment.