From 6e69ae5b186a53cec699404eaf7b220dab54e1c7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?William=20B=C3=A9rub=C3=A9?= Date: Tue, 4 Jun 2024 11:18:12 -0400 Subject: [PATCH] Fixes and improvements mostly related to OSDs - Text rendering canvas could be insufficient due to floating conversions - Foreground alpha was wrong on some cameras (opacity setting coming soon) - New parameter to set the text color (ARGB1555 format, hexadecimal entry) --- src/hal/hisi/v3_hal.c | 3 +-- src/hal/hisi/v4_hal.c | 3 +-- src/hal/inge/t31_hal.c | 6 +++--- src/lib/rtsp/rtsp.c | 3 +-- src/lib/rtsp/rtsp.h | 3 --- src/main.c | 2 +- src/region.c | 5 +++-- src/region.h | 3 ++- src/server.c | 11 +++++++++-- src/text.c | 8 ++++---- src/text.h | 2 +- 11 files changed, 26 insertions(+), 23 deletions(-) diff --git a/src/hal/hisi/v3_hal.c b/src/hal/hisi/v3_hal.c index 802d357..84fefd8 100644 --- a/src/hal/hisi/v3_hal.c +++ b/src/hal/hisi/v3_hal.c @@ -317,8 +317,7 @@ int v3_region_create(char handle, hal_rect rect) memset(&attrib, 0, sizeof(attrib)); attrib.show = 1; attrib.type = V3_RGN_TYPE_OVERLAY; - attrib.overlay.bgAlpha = 0; - attrib.overlay.fgAlpha = 128; + attrib.overlay.fgAlpha = 255; attrib.overlay.point.x = rect.x; attrib.overlay.point.y = rect.y; attrib.overlay.layer = 7; diff --git a/src/hal/hisi/v4_hal.c b/src/hal/hisi/v4_hal.c index f608a50..db6ee6b 100644 --- a/src/hal/hisi/v4_hal.c +++ b/src/hal/hisi/v4_hal.c @@ -376,8 +376,7 @@ int v4_region_create(char handle, hal_rect rect) memset(&attrib, 0, sizeof(attrib)); attrib.show = 1; attrib.type = V4_RGN_TYPE_OVERLAY; - attrib.overlay.bgAlpha = 0; - attrib.overlay.fgAlpha = 128; + attrib.overlay.fgAlpha = 255; attrib.overlay.point.x = rect.x; attrib.overlay.point.y = rect.y; attrib.overlay.layer = 7; diff --git a/src/hal/inge/t31_hal.c b/src/hal/inge/t31_hal.c index 6549d1d..23913b2 100644 --- a/src/hal/inge/t31_hal.c +++ b/src/hal/inge/t31_hal.c @@ -248,7 +248,7 @@ int t31_region_create(int *handle, hal_rect rect) t31_osd_grp attrib, attribCurr; region.type = T31_OSD_TYPE_PIC; - region.pixFmt = T31_PIXFMT_RGB555LE; + region.pixFmt = T31_PIXFMT_BGR555LE; region.rect.p0.x = rect.x; region.rect.p0.y = rect.y; region.rect.p1.x = rect.x + rect.width - 1; @@ -274,7 +274,7 @@ int t31_region_create(int *handle, hal_rect rect) memset(&attrib, 0, sizeof(attrib)); attrib.show = 1; attrib.alphaOn = 1; - attrib.fgAlpha = 128; + attrib.fgAlpha = 255; t31_osd.fnRegisterRegion(*handle, _t31_osd_grp, &attrib); @@ -294,7 +294,7 @@ int t31_region_setbitmap(int *handle, hal_bitmap *bitmap) region.type = T31_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 = T31_PIXFMT_RGB555LE; + region.pixFmt = T31_PIXFMT_BGR555LE; region.data.picture = bitmap->data; return t31_osd.fnSetRegionConfig(*handle, ®ion); } diff --git a/src/lib/rtsp/rtsp.c b/src/lib/rtsp/rtsp.c index 7c25001..5e31d18 100644 --- a/src/lib/rtsp/rtsp.c +++ b/src/lib/rtsp/rtsp.c @@ -429,7 +429,7 @@ static int __message_proc_sock(struct list_t *e, void *p) case __METHOD_RECORDING: __method_record(con, h);break; case __METHOD_TEARDOWN: __method_teardown(con, h);break; case __METHOD_NONE: - /* state DISCONNECTED connections should be gabage collected immediately. + /* state DISCONNECTED connections should be garbage collected immediately. but sending thread might watches the connection right now. so the connection might live at here */ ASSERT(con->con_state == __CON_S_DISCONNECTED, return FAILURE); @@ -587,7 +587,6 @@ static inline int __bind_rtp(struct connection_item_t *con ) /* reset socket */ if (con->server_rtp_fd != 0) { CLOSE(con->server_rtp_fd); - //FCLOSE(con->fp_rtp_write); con->server_rtp_fd = 0; } /* setup serve rsocket */ diff --git a/src/lib/rtsp/rtsp.h b/src/lib/rtsp/rtsp.h index e62a554..c89458a 100644 --- a/src/lib/rtsp/rtsp.h +++ b/src/lib/rtsp/rtsp.h @@ -74,9 +74,6 @@ struct connection_item_t { int server_rtp_fd; int cseq; - //FILE *fp_rtcp_write; - //FILE *fp_rtcp_read; - //FILE *fp_rtp_write; FILE *fp_tcp_read; FILE *fp_tcp_write; enum __connection_state_e con_state; diff --git a/src/main.c b/src/main.c index 555e615..362480d 100644 --- a/src/main.c +++ b/src/main.c @@ -61,7 +61,7 @@ int main(int argc, char *argv[]) { if (app_config.osd_enable) start_region_handler(); - while (keepRunning) {}; + while (keepRunning) sleep(1); if (app_config.rtsp_enable) { rtsp_finish(rtspHandle); diff --git a/src/region.c b/src/region.c index dedae12..7cc48c1 100644 --- a/src/region.c +++ b/src/region.c @@ -108,9 +108,10 @@ void *region_thread(void) for (char id = 0; id < MAX_OSD; id++) { osds[id].hand = -1; + osds[id].color = DEF_COLOR; osds[id].size = DEF_SIZE; osds[id].posx = DEF_POSX; - osds[id].posy = DEF_POSY; + osds[id].posy = DEF_POSY + (DEF_SIZE * 3 / 2) * id; osds[id].updt = 0; strcpy(osds[id].font, DEF_FONT); osds[id].text[0] = '\0'; @@ -132,7 +133,7 @@ void *region_thread(void) char *font; asprintf(&font, "/usr/share/fonts/truetype/%s.ttf", osds[id].font); if (!access(font, F_OK)) { - hal_bitmap bitmap = text_create_rendered(font, osds[id].size, out); + hal_bitmap bitmap = text_create_rendered(font, osds[id].size, out, osds[id].color); hal_rect rect = { .height = bitmap.dim.height, .width = bitmap.dim.width, .x = osds[id].posx, .y = osds[id].posy }; switch (plat) { diff --git a/src/region.h b/src/region.h index e50d45e..645eab6 100644 --- a/src/region.h +++ b/src/region.h @@ -4,6 +4,7 @@ #include "hal/support.h" #include "text.h" +#define DEF_COLOR 0xFFFF #define DEF_FONT "UbuntuMono-Regular" #define DEF_POSX 16 #define DEF_POSY 16 @@ -25,7 +26,7 @@ extern int sysinfo (struct sysinfo *__info); typedef struct { double size; - int hand; + int hand, color; short posx, posy; char updt; char font[32]; diff --git a/src/server.c b/src/server.c index 05b4c17..6a0fa4a 100644 --- a/src/server.c +++ b/src/server.c @@ -683,6 +683,13 @@ void *server_thread(void *vargp) { unescape_uri(value); char *key = split(&value, "="); if (!key || !*key || !value || !*value) continue; + if (equals(key, "color")) { + char base = 16; + if (strlen(value) > 1 && value[1] == 'x') base = 0; + short result = strtol(value, &remain, base); + if (remain != value) + osds[id].color = result; + } if (equals(key, "font")) strcpy(osds[id].font, !empty(value) ? value : DEF_FONT); else if (equals(key, "text")) @@ -710,8 +717,8 @@ void *server_thread(void *vargp) { "Content-Type: application/json;charset=UTF-8\r\n" \ "Connection: close\r\n" \ "\r\n" \ - "{\"id\":%d,\"pos\":[%d,%d],\"font\":\"%s\",\"size\":%.1f,\"text\":\"%s\"}", - id, osds[id].posx, osds[id].posy, osds[id].font, osds[id].size, osds[id].text); + "{\"id\":%d,\"color\":%#x,\"pos\":[%d,%d],\"font\":\"%s\",\"size\":%.1f,\"text\":\"%s\"}", + id, osds[id].color, osds[id].posx, osds[id].posy, osds[id].font, osds[id].size, osds[id].text); send_to_fd(client_fd, response, respLen); close_socket_fd(client_fd); continue; diff --git a/src/text.c b/src/text.c index a277287..63f4a0f 100644 --- a/src/text.c +++ b/src/text.c @@ -168,13 +168,13 @@ hal_dim text_measure_rendered(const char *font, double size, const char *text) return dim; } -hal_bitmap text_create_rendered(const char *font, double size, const char *text) +hal_bitmap text_create_rendered(const char *font, double size, const char *text, int color) { text_load_font(&sft, font, size, &lmtx); double margin, height, width; text_dim_rendered(&margin, &height, &width, text); - text_new_rendered(&canvas, width, height, 0); + text_new_rendered(&canvas, CEILING(width), CEILING(height), 0); unsigned cps[strlen(text) + 1]; int n = utf8_to_utf32(text, cps, strlen(text) + 1); @@ -198,12 +198,12 @@ hal_bitmap text_create_rendered(const char *font, double size, const char *text) SFT_GMetrics mtx; SFT_Kerning kerning; text_load_glyph(&sft, cp, &gid, &mtx); - text_new_rendered(&image, mtx.minWidth, mtx.minHeight, 0x7FFF); + text_new_rendered(&image, mtx.minWidth, mtx.minHeight, 0); sft_render(&sft, gid, image); sft_kerning(&sft, ogid, gid, &kerning); x += kerning.xShift; text_copy_rendered(&canvas, &image, x + mtx.leftSideBearing, - y + mtx.yOffset, 0xFFFF); + y + mtx.yOffset, color); x += mtx.advanceWidth; free(image.pixels); ogid = gid; diff --git a/src/text.h b/src/text.h index c54de12..554d0f4 100644 --- a/src/text.h +++ b/src/text.h @@ -14,5 +14,5 @@ return EXIT_FAILURE; \ } while (0) -hal_bitmap text_create_rendered(const char *font, double size, const char *text); +hal_bitmap text_create_rendered(const char *font, double size, const char *text, int color); hal_dim text_measure_rendered(const char *font, double size, const char *text); \ No newline at end of file