FS-10050 cont fix some mem issues with playing files and ignoring the audio

This commit is contained in:
Anthony Minessale 2017-02-21 20:09:32 -06:00
parent 888c8f96fa
commit dcbd39cc26
2 changed files with 27 additions and 10 deletions

View File

@ -1457,9 +1457,7 @@ static void *SWITCH_THREAD_FUNC file_read_thread_run(switch_thread_t *thread, vo
switch_buffer_zero(context->audio_buffer); switch_buffer_zero(context->audio_buffer);
switch_mutex_unlock(context->mutex); 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; // 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); switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "seeking to %" SWITCH_INT64_T_FMT "\n", context->seek_ts);
@ -1475,12 +1473,18 @@ static void *SWITCH_THREAD_FUNC file_read_thread_run(switch_thread_t *thread, vo
vid_frames = switch_queue_size(context->eh.video_queue); 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 && 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)) { (!context->has_video || vid_frames > 5)) {
switch_yield(context->has_video ? 1000 : 10000); switch_yield(context->has_video ? 1000 : 10000);
continue; continue;
} }
av_init_packet(&pkt); av_init_packet(&pkt);
pkt.data = NULL; pkt.data = NULL;
pkt.size = 0; 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 (!context->has_video || context->closed) return SWITCH_STATUS_FALSE;
if ((flags & SVR_CHECK)) { if ((flags & SVR_CHECK)) {
return SWITCH_STATUS_BREAK; return SWITCH_STATUS_BREAK;
} }
@ -2185,10 +2188,13 @@ static switch_status_t av_file_read_video(switch_file_handle_t *handle, switch_f
frame->img = (switch_image_t *) pop; frame->img = (switch_image_t *) pop;
if (frame->img && context->handle->mm.scale_w && context->handle->mm.scale_h) { if (frame->img) {
if (frame->img->d_w != context->handle->mm.scale_w || frame->img->d_h != context->handle->mm.scale_h) { if (frame->img && context->handle->mm.scale_w && 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->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; 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) {
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; context->vid_ready = 1;
} }

View File

@ -43,6 +43,7 @@ SWITCH_MODULE_DEFINITION(mod_video_filter, mod_video_filter_load, mod_video_filt
typedef struct chromakey_context_s { typedef struct chromakey_context_s {
int threshold; int threshold;
switch_image_t *bgimg; switch_image_t *bgimg;
switch_image_t *backup_img;
switch_image_t *bgimg_scaled; switch_image_t *bgimg_scaled;
switch_file_handle_t vfh; switch_file_handle_t vfh;
switch_rgb_color_t bgcolor; 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; 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); data = malloc(frame->img->d_w * frame->img->d_h * 4);
switch_assert(data); 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_patch(frame->img, img, 0, 0);
switch_img_free(&context->backup_img);
switch_img_copy(frame->img, &context->backup_img);
switch_img_free(&img); switch_img_free(&img);
free(data); free(data);