From 4b9b004403168fb4e7f2af435d7aab9911c0b7f3 Mon Sep 17 00:00:00 2001 From: Anthony Minessale Date: Tue, 21 Apr 2015 13:56:39 -0500 Subject: [PATCH] FS-7513: add text to video logo in mod_conference --- src/include/switch_core_video.h | 1 + .../mod_conference/mod_conference.c | 20 +++++- src/switch_core_video.c | 67 +++++++++++++++++++ 3 files changed, 87 insertions(+), 1 deletion(-) diff --git a/src/include/switch_core_video.h b/src/include/switch_core_video.h index cb6ce5c582..ce2476761e 100644 --- a/src/include/switch_core_video.h +++ b/src/include/switch_core_video.h @@ -239,6 +239,7 @@ SWITCH_DECLARE(switch_status_t) switch_img_fit(switch_image_t **srcP, int width, SWITCH_DECLARE(switch_img_position_t) parse_img_position(const char *name); SWITCH_DECLARE(void) switch_img_find_position(switch_img_position_t pos, int sw, int sh, int iw, int ih, int *xP, int *yP); SWITCH_DECLARE(switch_status_t) switch_img_convert(switch_image_t *src, switch_convert_fmt_t fmt, void *dest, switch_size_t *size); +SWITCH_DECLARE(switch_image_t *) switch_img_write_text_img(int w, int h, const char *text); /** @} */ diff --git a/src/mod/applications/mod_conference/mod_conference.c b/src/mod/applications/mod_conference/mod_conference.c index d59ea1855d..bb79043495 100644 --- a/src/mod/applications/mod_conference/mod_conference.c +++ b/src/mod/applications/mod_conference/mod_conference.c @@ -404,6 +404,7 @@ typedef struct mcu_layer_s { switch_image_t *cur_img; switch_image_t *banner_img; switch_image_t *logo_img; + switch_image_t *logo_text_img; switch_image_t *mute_img; switch_img_txt_handle_t *txthandle; conference_file_node_t *fnode; @@ -1019,6 +1020,7 @@ static void reset_layer(mcu_canvas_t *canvas, mcu_layer_t *layer) switch_img_free(&layer->banner_img); switch_img_free(&layer->logo_img); + switch_img_free(&layer->logo_text_img); layer->banner_patched = 0; layer->is_avatar = 0; @@ -1108,6 +1110,13 @@ static void scale_and_patch(conference_obj_t *conference, mcu_layer_t *layer, sw switch_img_fit(&layer->logo_img, ew, eh); switch_img_find_position(layer->logo_pos, ew, eh, layer->logo_img->d_w, layer->logo_img->d_h, &ex, &ey); switch_img_patch(IMG, layer->logo_img, x_pos + ex, y_pos + ey); + if (layer->logo_text_img) { + int tx = 0, ty = 0; + switch_img_find_position(POS_LEFT_BOT, + layer->logo_img->d_w, layer->logo_img->d_h, layer->logo_text_img->d_w, layer->logo_text_img->d_h, &tx, &ty); + switch_img_patch(IMG, layer->logo_text_img, x_pos + ex + tx, y_pos + ey + ty); + } + } } else { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG10, "insert at %d,%d\n", 0, 0); @@ -1187,6 +1196,7 @@ static void layer_set_logo(conference_member_t *member, mcu_layer_t *layer, cons if (path) { switch_img_free(&layer->logo_img); + switch_img_free(&layer->logo_text_img); } if (*path == '{') { @@ -1232,7 +1242,13 @@ static void layer_set_logo(conference_member_t *member, mcu_layer_t *layer, cons layer->logo_img = switch_img_read_png(path, SWITCH_IMG_FMT_ARGB); } - layer->logo_pos = pos; + if (layer->logo_img) { + layer->logo_pos = pos; + + if ((var = switch_event_get_header(params, "text"))) { + layer->logo_text_img = switch_img_write_text_img(layer->screen_w, layer->screen_h, var); + } + } if (params) switch_event_destroy(¶ms); @@ -1330,6 +1346,7 @@ static void layer_set_banner(conference_member_t *member, mcu_layer_t *layer, co switch_img_free(&layer->banner_img); switch_img_free(&layer->logo_img); + switch_img_free(&layer->logo_text_img); layer->banner_img = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, layer->screen_w, font_size * 2, 1); if (layer->txthandle) { @@ -2170,6 +2187,7 @@ static void *SWITCH_THREAD_FUNC conference_video_muxing_thread_run(switch_thread layer->banner_patched = 0; switch_img_free(&layer->banner_img); switch_img_free(&layer->logo_img); + switch_img_free(&layer->logo_text_img); switch_img_free(&layer->mute_img); switch_mutex_unlock(conference->canvas->mutex); diff --git a/src/switch_core_video.c b/src/switch_core_video.c index 663f87870c..7f63b675ee 100644 --- a/src/switch_core_video.c +++ b/src/switch_core_video.c @@ -744,6 +744,73 @@ SWITCH_DECLARE(switch_status_t) switch_img_txt_handle_render(switch_img_txt_hand #endif } +SWITCH_DECLARE(switch_image_t *) switch_img_write_text_img(int w, int h, const char *text) +{ + const char *fg ="#cccccc"; + const char *bg = "#142e55"; + const char *font_face = NULL; + const char *fontsz = "4%"; + const char *txt = "Value Optimized Out!"; + int argc = 0; + char *argv[6] = { 0 }; + switch_rgb_color_t bgcolor = { 0 }; + int width, font_size = 0; + int len = 0; + char *duptxt = strdup(text); + switch_img_txt_handle_t *txthandle = NULL; + switch_image_t *txtimg = NULL; + + if (strchr(text, ':')) { + argc = switch_split(duptxt, ':', argv); + + if (argc > 0) { + fg = argv[0]; + } + + if (argc > 1) { + bg = argv[1]; + } + + if (argc > 2) { + font_face = argv[2]; + } + + if (argc > 3) { + fontsz = argv[3]; + } + + if (argc > 4) { + txt = argv[4]; + } + } + + if (!txt) txt = duptxt; + + if (strrchr(fontsz, '%')) { + font_size = 1 + ((int) (float)h * (atof(fontsz) / 100.0f)); + } else { + font_size = atoi(fontsz); + } + + len = strlen(txt); + + if (len < 5) len = 5; + + width = (int) (float)(font_size * 0.75f * len); + + txtimg = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, width, font_size * 2, 1); + + switch_img_txt_handle_create(&txthandle, font_face, fg, bg, font_size, 0, NULL); + switch_color_set_rgb(&bgcolor, bg); + + switch_img_fill(txtimg, 0, 0, txtimg->d_w, txtimg->d_h, &bgcolor); + switch_img_txt_handle_render(txthandle, + txtimg, + font_size / 2, font_size / 2, + txt, NULL, fg, bg, 0, 0); + switch_img_txt_handle_destroy(&txthandle); + return txtimg; +} /* WARNING: patch a big IMG with a rect hole, note this function is WIP ......