]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7513: add text to video logo in mod_conference
authorAnthony Minessale <anthm@freeswitch.org>
Tue, 21 Apr 2015 18:56:39 +0000 (13:56 -0500)
committerMichael Jerris <mike@jerris.com>
Thu, 28 May 2015 17:47:23 +0000 (12:47 -0500)
src/include/switch_core_video.h
src/mod/applications/mod_conference/mod_conference.c
src/switch_core_video.c

index cb6ce5c58283efbd354af92c8bfd70e709447702..ce2476761e01a09005c3830b37af76edc46ba4c3 100644 (file)
@@ -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);
 
 /** @} */
 
index d59ea1855dc0cdfb9f2cb2a17cb727114bdfb8b9..bb79043495e3cc129393085feb265fd284aea7f6 100644 (file)
@@ -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(&params);
 
@@ -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);
 
index 663f87870c4a4638b64a880886223eeb76a91410..7f63b675eebd7c70fef11939bb911d949ca6b4ee 100644 (file)
@@ -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 ......