]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-11413: [freeswitch-core,mod_conference,mod_local_stream] High memory footprint...
authorAnthony Minessale <anthm@freeswitch.org>
Wed, 26 Sep 2018 23:21:17 +0000 (03:21 +0400)
committerAndrey Volk <andrey@signalwire.com>
Tue, 27 Nov 2018 21:19:35 +0000 (01:19 +0400)
src/mod/applications/mod_av/avformat.c
src/mod/applications/mod_conference/conference_file.c
src/mod/formats/mod_local_stream/mod_local_stream.c

index 84900b601c8e9ba8fc126a1f6f5e6178e3bb23aa..d5ad0d6e254506554a2768f0c3f01c9ee83676e1 100644 (file)
@@ -2357,6 +2357,7 @@ static switch_status_t av_file_read_video(switch_file_handle_t *handle, switch_f
                }
 
                if (pop && status == SWITCH_STATUS_SUCCESS) {
+                       switch_img_free(&context->last_img);
                        context->last_img = (switch_image_t *)pop;
                        switch_img_copy(context->last_img, &frame->img);
                        context->vid_ready = 1;
@@ -2467,6 +2468,7 @@ GCC_DIAG_ON(deprecated-declarations)
                        if (switch_micro_time_now() - mst->next_pts > -10000) {
                                frame->img = img;
                        } else {
+                               switch_img_free(&context->last_img);
                                context->last_img = img;
                                return SWITCH_STATUS_BREAK;
                        }
index f4e2866052be04285b4649251b0b47aecbd073bb..8f0dc1d8b7c549d51668828d91e9b029164bcfea 100644 (file)
@@ -248,7 +248,7 @@ switch_status_t conference_file_play(conference_obj_t *conference, char *file, u
 
        flags = SWITCH_FILE_FLAG_READ | SWITCH_FILE_DATA_SHORT;
 
-       if (conference_utils_test_flag(conference, CFLAG_TRANSCODE_VIDEO)) {
+       if (conference_utils_test_flag(conference, CFLAG_TRANSCODE_VIDEO) && conference->conference_video_mode == CONF_VIDEO_MODE_MUX) {
                flags |= SWITCH_FILE_FLAG_VIDEO;
        }
 
index 8edba9aa944da717d06de2626e50424a956ba314..d07bfb34f3550115c82213707ad11b544b9469d0 100644 (file)
@@ -529,10 +529,11 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
                                                                source->has_video = 1;
                                                                if (source->total) {
                                                                        if (switch_queue_trypush(source->video_q, vid_frame.img) == SWITCH_STATUS_SUCCESS) {
+                                                                               vid_frame.img = NULL;
                                                                                flush = 0;
                                                                        }
                                                                }
-
+                                                               
                                                                if (flush) {
                                                                        switch_img_free(&vid_frame.img);
                                                                        flush_video_queue(source->video_q);
@@ -645,13 +646,15 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
                                                if (!pop) break;
 
                                                img = (switch_image_t *) pop;
-
+                                               
                                                switch_mutex_lock(source->mutex);
                                                if (source->context_list) {
                                                        if (source->total == 1) {
-                                                               if (switch_queue_trypush(source->context_list->video_q, img) != SWITCH_STATUS_SUCCESS) {
+                                                               if (!switch_test_flag(source->context_list->handle, SWITCH_FILE_FLAG_VIDEO)) {
                                                                        flush_video_queue(source->context_list->video_q);
-
+                                                               } else if (switch_queue_trypush(source->context_list->video_q, img) != SWITCH_STATUS_SUCCESS) {
+                                                                       flush_video_queue(source->context_list->video_q);
+                                                                       
                                                                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Flushing video queue\n");
                                                                        if (++source->context_list->video_flushes > 1) {
                                                                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Disconnecting file\n");
@@ -659,6 +662,7 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
                                                                        }
                                                                } else {
                                                                        source->context_list->video_flushes = 0;
+                                                                       img = NULL;
                                                                }
                                                        } else {
                                                                for (cp = source->context_list; cp && RUNNING; cp = cp->next) {
@@ -671,7 +675,9 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
                                                                                imgcp = NULL;
                                                                                switch_img_copy(img, &imgcp);
                                                                                if (imgcp) {
-                                                                                       if (switch_queue_trypush(cp->video_q, imgcp) != SWITCH_STATUS_SUCCESS) {
+                                                                                       if (!switch_test_flag(cp->handle, SWITCH_FILE_FLAG_VIDEO)) {
+                                                                                               flush_video_queue(cp->video_q);
+                                                                                       } else if (switch_queue_trypush(cp->video_q, imgcp) != SWITCH_STATUS_SUCCESS) {
                                                                                                flush_video_queue(cp->video_q);
                                                                                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Flushing video queue\n");
                                                                                                if (++cp->video_flushes > 1) {
@@ -684,10 +690,10 @@ static void *SWITCH_THREAD_FUNC read_stream_thread(switch_thread_t *thread, void
                                                                                }
                                                                        }
                                                                }
-                                                               switch_img_free(&img);
                                                        }
                                                }
                                                switch_mutex_unlock(source->mutex);
+                                               switch_img_free(&img);
                                        }
                                }
                        }
@@ -887,7 +893,7 @@ static switch_status_t local_stream_file_open(switch_file_handle_t *handle, cons
 
        context->pool = pool;
 
-       switch_queue_create(&context->video_q, 500, context->pool);
+       switch_queue_create(&context->video_q, 40, context->pool);
 
        handle->samples = 0;
        handle->samplerate = source->rate;
@@ -907,7 +913,7 @@ static switch_status_t local_stream_file_open(switch_file_handle_t *handle, cons
                goto end;
        }
 
-       if (!switch_core_has_video() ||
+       if (!switch_core_has_video() || !source->has_video ||
                (switch_test_flag(handle, SWITCH_FILE_FLAG_VIDEO) && !source->has_video && !source->blank_img && !source->cover_art && !source->banner_txt)) {
                switch_clear_flag_locked(handle, SWITCH_FILE_FLAG_VIDEO);
        }
@@ -1037,7 +1043,7 @@ static switch_status_t local_stream_file_read_video(switch_file_handle_t *handle
                buf_qsize = 1;
        }
 
-       while(context->ready && context->source->ready && (flags & SVR_FLUSH) && switch_queue_size(context->video_q) > min_qsize) {
+       while(context->ready && context->source->ready && switch_queue_size(context->video_q) > min_qsize) {
                if (switch_queue_trypop(context->video_q, &pop) == SWITCH_STATUS_SUCCESS) {
                        switch_image_t *img = (switch_image_t *) pop;
                        switch_img_free(&img);
@@ -1151,11 +1157,7 @@ static switch_status_t local_stream_file_read(switch_file_handle_t *handle, void
                return SWITCH_STATUS_FALSE;
        }
 
-       if (context->source->has_video)  {
-               if (!switch_test_flag(handle, SWITCH_FILE_FLAG_VIDEO)) {
-                       switch_set_flag_locked(handle, SWITCH_FILE_FLAG_VIDEO);
-               }
-       } else {
+       if (!context->source->has_video)  {
                if (switch_test_flag(handle, SWITCH_FILE_FLAG_VIDEO)) {
                        switch_clear_flag_locked(handle, SWITCH_FILE_FLAG_VIDEO);
                }