]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-10050 cont fix some mem issues with playing files and ignoring the audio
authorAnthony Minessale <anthm@freeswitch.org>
Wed, 22 Feb 2017 02:09:32 +0000 (20:09 -0600)
committerAnthony Minessale <anthm@freeswitch.org>
Wed, 22 Feb 2017 02:09:32 +0000 (20:09 -0600)
src/mod/applications/mod_av/avformat.c
src/mod/applications/mod_video_filter/mod_video_filter.c

index f96b7b2f1b95f8e6a12d9e38212751264740f323..e094aea751bd6f5a5fff3a52fd25683fd23b68e2 100644 (file)
@@ -1457,10 +1457,8 @@ static void *SWITCH_THREAD_FUNC file_read_thread_run(switch_thread_t *thread, vo
                        switch_buffer_zero(context->audio_buffer);
                        switch_mutex_unlock(context->mutex);
 
-                       if (context->eh.video_queue) {
-                               flush_video_queue(context->eh.video_queue, 0);
-                       }
 
+                       
                        // if (context->has_audio) stream_id = context->audio_st.st->index;
                        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "seeking to %" SWITCH_INT64_T_FMT "\n", context->seek_ts);
                        avformat_seek_file(context->fc, stream_id, 0, context->seek_ts, INT64_MAX, 0);
@@ -1474,6 +1472,10 @@ static void *SWITCH_THREAD_FUNC file_read_thread_run(switch_thread_t *thread, vo
                if (context->has_video) {
                        vid_frames = switch_queue_size(context->eh.video_queue);
                }
+               
+               if (vid_frames > context->read_fps) {
+                       switch_yield(250000);
+               }
 
                if (switch_buffer_inuse(context->audio_buffer) > AUDIO_BUF_SEC * context->audio_st.sample_rate * context->audio_st.channels * 2 &&
                        (!context->has_video || vid_frames > 5)) {
@@ -1481,6 +1483,8 @@ static void *SWITCH_THREAD_FUNC file_read_thread_run(switch_thread_t *thread, vo
                        continue;
                }
 
+
+
                av_init_packet(&pkt);
                pkt.data = NULL;
                pkt.size = 0;
@@ -2161,7 +2165,6 @@ static switch_status_t av_file_read_video(switch_file_handle_t *handle, switch_f
 
 
        if (!context->has_video || context->closed) return SWITCH_STATUS_FALSE;
-
        if ((flags & SVR_CHECK)) {
                return SWITCH_STATUS_BREAK;
        }
@@ -2185,12 +2188,15 @@ static switch_status_t av_file_read_video(switch_file_handle_t *handle, switch_f
 
                frame->img = (switch_image_t *) pop;
 
-               if (frame->img && context->handle->mm.scale_w && context->handle->mm.scale_h) {
-                       if (frame->img->d_w != context->handle->mm.scale_w || frame->img->d_h != context->handle->mm.scale_h) {
-                               switch_img_fit(&frame->img, context->handle->mm.scale_w, context->handle->mm.scale_h, SWITCH_FIT_SIZE);
+               if (frame->img) {
+                       if (frame->img && context->handle->mm.scale_w && context->handle->mm.scale_h) {
+                               if (frame->img->d_w != context->handle->mm.scale_w || frame->img->d_h != context->handle->mm.scale_h) {
+                                       switch_img_fit(&frame->img, context->handle->mm.scale_w, context->handle->mm.scale_h, SWITCH_FIT_SIZE);
+                               }
                        }
-               }
-               
+                       context->vid_ready = 1;
+               }               
+
                return SWITCH_STATUS_SUCCESS;
        }
 
@@ -2386,6 +2392,11 @@ static switch_status_t av_file_read_video(switch_file_handle_t *handle, switch_f
        }
 
        if (frame->img) {
+               if (frame->img && context->handle->mm.scale_w && context->handle->mm.scale_h) {
+                       if (frame->img->d_w != context->handle->mm.scale_w || frame->img->d_h != context->handle->mm.scale_h) {
+                               switch_img_fit(&frame->img, context->handle->mm.scale_w, context->handle->mm.scale_h, SWITCH_FIT_SIZE);
+                       }
+               }
                context->vid_ready = 1;
        }
 
index 2e0e5737240d1b8dff6fd2d2bc59c1e42d95f50d..9f659df56dd9c4bf366e7f48086f73898c4ce810 100644 (file)
@@ -43,6 +43,7 @@ SWITCH_MODULE_DEFINITION(mod_video_filter, mod_video_filter_load, mod_video_filt
 typedef struct chromakey_context_s {
        int threshold;
        switch_image_t *bgimg;
+       switch_image_t *backup_img;
        switch_image_t *bgimg_scaled;
        switch_file_handle_t vfh;
        switch_rgb_color_t bgcolor;
@@ -192,7 +193,10 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi
                return SWITCH_STATUS_SUCCESS;
        }
 
-       switch_mutex_lock(context->command_mutex);
+       if (switch_mutex_trylock(context->command_mutex) != SWITCH_STATUS_SUCCESS) {
+               switch_img_patch(frame->img, context->backup_img, 0, 0);
+               return SWITCH_STATUS_SUCCESS;
+       }
 
        data = malloc(frame->img->d_w * frame->img->d_h * 4);
        switch_assert(data);
@@ -257,6 +261,8 @@ static switch_status_t video_thread_callback(switch_core_session_t *session, swi
        }
 
        switch_img_patch(frame->img, img, 0, 0);
+       switch_img_free(&context->backup_img);
+       switch_img_copy(frame->img, &context->backup_img);
        switch_img_free(&img);
        free(data);