From 95893bf8d59fca07e4121b89c305654f982dacd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20B=C3=A9rub=C3=A9?= Date: Fri, 31 May 2024 15:10:04 -0400 Subject: [PATCH] (Continued) --- src/hal/inge/tx_hal.c | 94 +++++++++++++++++++++++++++++++++++++++++++ src/hal/inge/tx_hal.h | 7 ++++ src/hal/inge/tx_osd.h | 24 ++++++++++- 3 files changed, 124 insertions(+), 1 deletion(-) diff --git a/src/hal/inge/tx_hal.c b/src/hal/inge/tx_hal.c index 646827b..e1265aa 100644 --- a/src/hal/inge/tx_hal.c +++ b/src/hal/inge/tx_hal.c @@ -12,6 +12,8 @@ int (*tx_venc_cb)(char, hal_vidstream*); tx_isp_snr _tx_isp_snr; +char _tx_aud_chn = 0; +char _tx_aud_dev = 0; char _tx_fs_chn = 0; void tx_hal_deinit(void) @@ -44,6 +46,39 @@ int tx_hal_init(void) return EXIT_SUCCESS; } +void tx_audio_deinit(void) +{ + tx_aud.fnDisableChannel(_tx_aud_dev, _tx_aud_chn); + + tx_aud.fnDisableDevice(_tx_aud_dev); +} + +int tx_audio_init(void) +{ + int ret; + + { + tx_aud_cnf config; + config.rate = 48000; + config.bit = TX_AUD_BIT_16; + config.mode = TX_AUD_SND_MONO; + config.frmNum = 0; + config.packNumPerFrm = 0; + config.chnNum = 0; + if (ret = tx_aud.fnSetDeviceConfig(_tx_aud_dev, &config)) + return ret; + } + if (ret = tx_aud.fnEnableDevice(_tx_aud_dev)) + return ret; + + if (ret = tx_aud.fnEnableChannel(_tx_aud_dev, _tx_aud_chn)) + return ret; + if (ret = tx_aud.fnSetVolume(_tx_aud_dev, _tx_aud_chn, 0xF6)) + return ret; + + return EXIT_SUCCESS; +} + int tx_pipeline_create(short width, short height, char framerate) { int ret; @@ -64,6 +99,65 @@ void tx_pipeline_destroy() tx_fs.fnDestroyChannel(_tx_fs_chn); } +int tx_region_create(int *handle, char group, hal_rect rect) +{ + int ret; + + tx_osd_rgn region, regionCurr; + tx_osd_grp attrib, attribCurr; + + region.type = TX_OSD_TYPE_PIC; + region.pixFmt = TX_PIXFMT_RGB555LE; + region.rect.p0.x = rect.x; + region.rect.p0.y = rect.y; + region.rect.p1.x = rect.x + rect.width - 1; + region.rect.p1.y = rect.y + rect.height - 1; + region.data.picture = NULL; + + if (ret = tx_osd.fnGetRegionConfig(&handle, ®ionCurr)) { + fprintf(stderr, "[tx_osd] Creating region %d...\n", group); + if (ret = tx_osd.fnCreateRegion(®ion)) + return 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, "[tx_osd] Parameters are different, recreating " + "region %d...\n", group); + if (ret = tx_osd.fnSetRegionConfig(&handle, ®ion)) + return ret; + } + + if (tx_osd.fnGetGroupConfig(&handle, group, &attribCurr)) + fprintf(stderr, "[tx_osd] Attaching region %d...\n", group); + + memset(&attrib, 0, sizeof(attrib)); + attrib.show = 1; + attrib.alphaOn = 1; + attrib.fgAlpha = 255; + + tx_osd.fnRegisterRegion(&handle, group, &attrib); + tx_osd.fnStartGroup(group); + + return ret; +} + +void tx_region_destroy(int *handle, char group) +{ + tx_osd.fnStopGroup(group); + tx_osd.fnUnregisterRegion(&handle, group); +} + +int tx_region_setbitmap(int *handle, hal_bitmap *bitmap) +{ + tx_osd_rgn region; + tx_osd.fnGetRegionConfig(&handle, ®ion); + region.type = TX_OSD_TYPE_PIC; + region.rect.p1.x = region.rect.p0.x + bitmap->dim.width - 1; + region.rect.p1.y = region.rect.p0.y + bitmap->dim.height - 1; + region.pixFmt = TX_PIXFMT_RGB555LE; + region.data.picture = bitmap->data; + return tx_osd.fnSetRegionConfig(&handle, ®ion); +} + void *tx_video_thread(void) { diff --git a/src/hal/inge/tx_hal.h b/src/hal/inge/tx_hal.h index f8969ff..cefde9b 100644 --- a/src/hal/inge/tx_hal.h +++ b/src/hal/inge/tx_hal.h @@ -16,9 +16,16 @@ extern int (*tx_venc_cb)(char, hal_vidstream*); void tx_hal_deinit(void); int tx_hal_init(void); +void tx_audio_deinit(void); +int tx_audio_init(void); + int tx_pipeline_create(short width, short height, char framerate); void tx_pipeline_destroy(void); +int tx_region_create(int *handle, char group, hal_rect rect); +void tx_region_destroy(int *handle, char group); +int tx_region_setbitmap(int *handle, hal_bitmap *bitmap); + void *tx_video_thread(void); void tx_system_deinit(void); diff --git a/src/hal/inge/tx_osd.h b/src/hal/inge/tx_osd.h index cdceeb6..a14bb79 100644 --- a/src/hal/inge/tx_osd.h +++ b/src/hal/inge/tx_osd.h @@ -38,7 +38,7 @@ typedef struct { typedef struct { int show; - tx_common_pnt pos; + tx_common_pnt point; float scaleX, scaleY; int alphaOn; int fgAlpha; @@ -51,6 +51,7 @@ typedef struct { int (*fnCreateRegion)(tx_osd_rgn *config); int (*fnDestroyRegion)(int handle); + int (*fnGetRegionConfig)(int handle, tx_osd_rgn *config); int (*fnRegisterRegion)(int handle, int group, tx_osd_grp *config); int (*fnSetRegionConfig)(int handle, tx_osd_rgn *config); int (*fnUnregisterRegion)(int handle, int group); @@ -59,6 +60,8 @@ typedef struct { int (*fnCreateGroup)(int group); int (*fnDestroyGroup)(int group); int (*fnGetGroupConfig)(int handle, int group, tx_osd_grp *config); + int (*fnStartGroup)(int group); + int (*fnStopGroup)(int group); } tx_osd_impl; static int tx_osd_load(tx_osd_impl *osd_lib) { @@ -79,6 +82,12 @@ static int tx_osd_load(tx_osd_impl *osd_lib) { return EXIT_FAILURE; } + if (!(osd_lib->fnGetRegionConfig = (int(*)(int handle, tx_osd_rgn *config)) + dlsym(osd_lib->handle, "IMP_OSD_GetRgnAttr"))) { + fprintf(stderr, "[tx_osd] Failed to acquire symbol IMP_OSD_GetRgnAttr!\n"); + return EXIT_FAILURE; + } + if (!(osd_lib->fnRegisterRegion = (int(*)(int handle, int group, tx_osd_grp *config)) dlsym(osd_lib->handle, "IMP_OSD_RegisterRgn"))) { fprintf(stderr, "[tx_osd] Failed to acquire symbol IMP_OSD_RegisterRgn!\n"); @@ -121,6 +130,19 @@ static int tx_osd_load(tx_osd_impl *osd_lib) { return EXIT_FAILURE; } + if (!(osd_lib->fnStartGroup = (int(*)(int group)) + dlsym(osd_lib->handle, "IMP_OSD_Start"))) { + fprintf(stderr, "[tx_osd] Failed to acquire symbol IMP_OSD_Start!\n"); + return EXIT_FAILURE; + } + + if (!(osd_lib->fnStopGroup = (int(*)(int group)) + dlsym(osd_lib->handle, "IMP_OSD_Stop"))) { + fprintf(stderr, "[tx_osd] Failed to acquire symbol IMP_OSD_Stop!\n"); + return EXIT_FAILURE; + } + + return EXIT_SUCCESS; }