]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-7502: add patch level for media bugs to call them as needed
authorAnthony Minessale <anthm@freeswitch.org>
Wed, 22 Apr 2015 16:01:47 +0000 (11:01 -0500)
committerMichael Jerris <mike@jerris.com>
Thu, 28 May 2015 17:47:24 +0000 (12:47 -0500)
src/include/switch_core.h
src/include/switch_types.h
src/mod/applications/mod_conference/mod_conference.c
src/mod/applications/mod_cv/mod_cv.cpp
src/switch_core_media_bug.c
src/switch_core_video.c

index cb24be1cefd85e9244057949b4a2c5321ece0ac1..a935b2570b391eae52c541c6b740caa642b2e401 100644 (file)
@@ -251,6 +251,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_pop(switch_core_session_t
                                                                
 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_exec_all(switch_core_session_t *orig_session, 
                                                                                                                           const char *function, switch_media_bug_exec_cb_t cb, void *user_data);
+SWITCH_DECLARE(uint32_t) switch_core_media_bug_patch_video(switch_core_session_t *orig_session, switch_frame_t *frame);
 SWITCH_DECLARE(uint32_t) switch_core_media_bug_count(switch_core_session_t *orig_session, const char *function);
 /*!
   \brief Add a media bug to the session
index 000611bea48725603fe194287c43ea4d2dcbf2c4..a73ee619e00cd79c4bdf59ab7745f304882620b5 100644 (file)
@@ -489,7 +489,8 @@ typedef enum {
        SWITCH_ABC_TYPE_TAP_NATIVE_WRITE,
        SWITCH_ABC_TYPE_CLOSE,
        SWITCH_ABC_TYPE_READ_VIDEO_PING,
-       SWITCH_ABC_TYPE_STREAM_VIDEO_PING
+       SWITCH_ABC_TYPE_STREAM_VIDEO_PING,
+       SWITCH_ABC_TYPE_VIDEO_PATCH
 } switch_abc_type_t;
 
 typedef struct {
@@ -1731,7 +1732,8 @@ typedef enum {
        SMBF_MASK = (1 << 16),
        SMBF_READ_VIDEO_PING = (1 << 17),
        SMBF_READ_VIDEO_STREAM = (1 << 18),
-       SMBF_WRITE_VIDEO_STREAM = (1 << 19)
+       SMBF_WRITE_VIDEO_STREAM = (1 << 19),
+       SMBF_VIDEO_PATCH = (1 << 20)
 } switch_media_bug_flag_enum_t;
 typedef uint32_t switch_media_bug_flag_t;
 
index 329ffb77d343c07887531ffbb9924456943681b3..0050f4782e07d031b944b0a0803bebd4fd4181b0 100644 (file)
@@ -391,6 +391,7 @@ typedef struct mcu_layer_s {
        int member_id;
        int idx;
        int tagged;
+       int bugged;
        int screen_w;
        int screen_h;
        int x_pos;
@@ -1100,6 +1101,15 @@ static void scale_and_patch(conference_obj_t *conference, mcu_layer_t *layer, sw
                switch_assert(layer->img);
 
                if (switch_img_scale(img, &layer->img, img_w, img_h) == SWITCH_STATUS_SUCCESS) {
+                       if (layer->bugged && layer->member_id > -1) {
+                               conference_member_t *member;
+                               if ((member = conference_member_get(conference, layer->member_id))) {
+                                       switch_frame_t write_frame = { 0 };
+                                       write_frame.img = layer->img;
+                                       switch_core_media_bug_patch_video(member->session, &write_frame);
+                                       switch_thread_rwlock_unlock(member->rwlock);
+                               }
+                       }
                        switch_img_patch(IMG, layer->img, x_pos, y_pos);
                }
 
@@ -1921,11 +1931,12 @@ static void *SWITCH_THREAD_FUNC conference_video_muxing_thread_run(switch_thread
                        } else {
                                img = imember->avatar_png_img;
                        }
-                                                               
+                       
+                       layer = NULL;
+                                       
                        if (img) {
                                int i;
 
-                               layer = NULL;
                                used++;
 
                                switch_mutex_lock(conference->canvas->mutex);
@@ -2030,6 +2041,10 @@ static void *SWITCH_THREAD_FUNC conference_video_muxing_thread_run(switch_thread
                                                
                                                img = NULL;
                                                layer->tagged = 1;
+
+                                               if (switch_core_media_bug_count(imember->session, "patch:video")) {
+                                                       layer->bugged = 1;
+                                               }
                                        }
                                }
 
@@ -2073,6 +2088,7 @@ static void *SWITCH_THREAD_FUNC conference_video_muxing_thread_run(switch_thread
                                        }
                                        layer->tagged = 0;
                                }
+                               layer->bugged = 0;
                        }
                }
 
@@ -2162,14 +2178,14 @@ static void *SWITCH_THREAD_FUNC conference_video_muxing_thread_run(switch_thread
                        write_frame.packetlen = 0;
                        
                        //switch_core_session_write_video_frame(imember->session, &write_frame, SWITCH_IO_FLAG_NONE, 0);
-
+                       
                        if (switch_frame_buffer_dup(imember->fb, &write_frame, &dupframe) == SWITCH_STATUS_SUCCESS) {
                                switch_queue_push(imember->mux_out_queue, dupframe);
                                dupframe = NULL;
                        }
 
                        if (imember->session) {
-                               switch_core_session_rwunlock(imember->session);
+                               switch_core_session_rwunlock(imember->session);                                 
                        }
                }
 
index 3ce074047b4249444a05145ffbc736776941648d..4baad69194f8b51de3cf600a5fd20c8dbbabf83e 100644 (file)
@@ -195,11 +195,10 @@ static void context_render_text(cv_context_t *context, struct overlay *overlay,
     if (!text) text = overlay->text;
 
     int len = strlen(text);
-    if (len < 5) len = 5;
-
 
-    width = (int) (float)(font_size * 0.75f * len);
+    if (len < 5) len = 5;
 
+    width = (int) (float)(font_size * .95f * len);
 
     switch_color_set_rgb(&bgcolor, overlay->bg);
 
@@ -817,7 +816,7 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi
         }
     }
 
-    if (context->debug || !context->overlay_count) {
+    if (context->rawImage && (context->debug || !context->overlay_count)) {
         libyuv::RGB24ToI420((uint8_t *)context->rawImage->imageData, context->w * 3,
                             frame->img->planes[0], frame->img->stride[0],
                             frame->img->planes[1], frame->img->stride[1],
@@ -1151,6 +1150,7 @@ static switch_bool_t cv_bug_callback(switch_media_bug_t *bug, void *user_data, s
         }
         break;
     case SWITCH_ABC_TYPE_READ_VIDEO_PING:
+       case SWITCH_ABC_TYPE_VIDEO_PATCH:
         {
             switch_frame_t *frame = switch_core_media_bug_get_video_ping_frame(bug);
             video_thread_callback(context->session, frame, context);
@@ -1173,6 +1173,8 @@ SWITCH_STANDARD_APP(cv_bug_start_function)
     int x, n;
     char *argv[25] = { 0 };
     int argc;
+       switch_media_bug_flag_t flags = SMBF_READ_VIDEO_PING;
+       const char *function = "mod_cv";
 
     if ((bug = (switch_media_bug_t *) switch_channel_get_private(channel, "_cv_bug_"))) {
         if (!zstr(data) && !strcasecmp(data, "stop")) {
@@ -1197,9 +1199,14 @@ SWITCH_STANDARD_APP(cv_bug_start_function)
         parse_params(context, 1, argc, argv);
     }
 
+       if (!strcasecmp(argv[0], "patch") || !strcasecmp(argv[1], "patch")) {
+               function = "patch:video";
+               flags = SMBF_VIDEO_PATCH;
+       }
+
     switch_thread_rwlock_rdlock(MODULE_INTERFACE->rwlock);
 
-    if ((status = switch_core_media_bug_add(session, "cv_bug", NULL, cv_bug_callback, context, 0, SMBF_READ_VIDEO_PING, &bug)) != SWITCH_STATUS_SUCCESS) {
+    if ((status = switch_core_media_bug_add(session, function, NULL, cv_bug_callback, context, 0, flags, &bug)) != SWITCH_STATUS_SUCCESS) {
         switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Failure!\n");
         switch_thread_rwlock_unlock(MODULE_INTERFACE->rwlock);
         return;
@@ -1227,6 +1234,8 @@ SWITCH_STANDARD_API(cv_bug_api_function)
     char *nested_cascade_path = NULL;
     char *lbuf = NULL;
     int x, n, i;
+       switch_media_bug_flag_t flags = SMBF_READ_VIDEO_PING;
+       const char *function = "mod_cv";
 
     if (zstr(cmd)) {
         goto usage;
@@ -1256,7 +1265,7 @@ SWITCH_STANDARD_API(cv_bug_api_function)
                 switch_channel_set_private(channel, "_cv_bug_", NULL);
                 switch_core_media_bug_remove(rsession, &bug);
                 stream->write_function(stream, "+OK Success\n");
-            } else if (!strcasecmp(action, "start") || !strcasecmp(action, "mod")) {
+            } else if (!strcasecmp(action, "start") || !strcasecmp(action, "mod") || !strcasecmp(action, "patch")) {
                 context = (cv_context_t *) switch_core_media_bug_get_user_data(bug);
                 switch_assert(context);
                 parse_params(context, 2, argc, argv);
@@ -1268,7 +1277,7 @@ SWITCH_STANDARD_API(cv_bug_api_function)
         goto done;
     }
 
-    if (!zstr(action) && strcasecmp(action, "start")) {
+    if (!zstr(action) && strcasecmp(action, "start") && strcasecmp(action, "patch")) {
         goto usage;
     }
 
@@ -1281,7 +1290,13 @@ SWITCH_STANDARD_API(cv_bug_api_function)
 
     switch_thread_rwlock_rdlock(MODULE_INTERFACE->rwlock);
 
-    if ((status = switch_core_media_bug_add(rsession, "cv_bug", NULL, cv_bug_callback, context, 0, SMBF_READ_VIDEO_PING, &bug)) != SWITCH_STATUS_SUCCESS) {
+       if (!strcasecmp(action, "patch")) {
+               function = "patch:video";
+               flags = SMBF_VIDEO_PATCH;
+       }
+
+    if ((status = switch_core_media_bug_add(rsession, function, NULL, 
+                                                                                       cv_bug_callback, context, 0, flags, &bug)) != SWITCH_STATUS_SUCCESS) {
         stream->write_function(stream, "-ERR Failure!\n");
         switch_thread_rwlock_unlock(MODULE_INTERFACE->rwlock);
         goto done;
index 993231b28ea7ee5583ed05a3f12d04e30b2760e8..8c27f4beae8aa43c7d7fe294b1751d7aae6e497d 100644 (file)
@@ -832,6 +832,7 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_bug_pop(switch_core_session_t
        return SWITCH_STATUS_FALSE;
 }
 
+
 SWITCH_DECLARE(uint32_t) switch_core_media_bug_count(switch_core_session_t *orig_session, const char *function)
 {
        switch_media_bug_t *bp;
@@ -850,6 +851,41 @@ SWITCH_DECLARE(uint32_t) switch_core_media_bug_count(switch_core_session_t *orig
        return x;
 }
 
+SWITCH_DECLARE(uint32_t) switch_core_media_bug_patch_video(switch_core_session_t *orig_session, switch_frame_t *frame)
+{
+       switch_media_bug_t *bp;
+       uint32_t x = 0, ok = SWITCH_TRUE, prune = 0;
+
+       if (orig_session->bugs) {
+               switch_thread_rwlock_rdlock(orig_session->bug_rwlock);
+               for (bp = orig_session->bugs; bp; bp = bp->next) {
+                       if (!switch_test_flag(bp, SMBF_PRUNE) && !switch_test_flag(bp, SMBF_LOCK) && !strcmp(bp->function, "patch:video")) {
+                               if (bp->ready && frame->img && switch_test_flag(bp, SMBF_VIDEO_PATCH)) {
+                                       bp->ping_frame = frame;
+                                       if (bp->callback) {
+                                               if (bp->callback(bp, bp->user_data, SWITCH_ABC_TYPE_VIDEO_PATCH) == SWITCH_FALSE
+                                                       || (bp->stop_time && bp->stop_time <= switch_epoch_time_now(NULL))) {
+                                                       ok = SWITCH_FALSE;
+                                               }
+                                       }
+                                       bp->ping_frame = NULL;
+                               }
+
+                               if (ok == SWITCH_FALSE) {
+                                       switch_set_flag(bp, SMBF_PRUNE);
+                                       prune++;
+                               } else x++;
+                       }
+               }
+               switch_thread_rwlock_unlock(orig_session->bug_rwlock);
+               if (prune) {
+                       switch_core_media_bug_prune(orig_session);
+               }
+       }
+
+       return x;
+}
+
 SWITCH_DECLARE(switch_status_t) switch_core_media_bug_exec_all(switch_core_session_t *orig_session, 
                                                                                                                           const char *function, switch_media_bug_exec_cb_t cb, void *user_data)
 {
index 63d02dff3bb93d46148a2f6a0d18ed229717ab90..35a9c51ce4564176e1b2ea5bc709af18c27c33cd 100644 (file)
@@ -836,7 +836,7 @@ SWITCH_DECLARE(switch_image_t *) switch_img_write_text_img(int w, int h, const c
 
     if (len < 5) len = 5;
 
-    width = (int) (float)(font_size * 0.75f * len);
+    width = (int) (float)(font_size * 0.95f * len);
        
        txtimg = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, width, font_size * 2, 1);