From 105a291bb7602c5cfb8fcef574920b821027b12f Mon Sep 17 00:00:00 2001 From: Brian West Date: Wed, 29 Nov 2017 14:27:00 -0600 Subject: [PATCH] FS-10892: [mod_av] Lip Sync Improvements #resolve --- src/mod/applications/mod_av/avformat.c | 18 ++++++++++++++---- .../mod_conference/conference_record.c | 4 ++-- .../mod_conference/conference_video.c | 12 ++++++------ 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/mod/applications/mod_av/avformat.c b/src/mod/applications/mod_av/avformat.c index 644261699f..04101629c4 100644 --- a/src/mod/applications/mod_av/avformat.c +++ b/src/mod/applications/mod_av/avformat.c @@ -132,6 +132,7 @@ struct av_file_context { switch_size_t mux_buf_len; switch_time_t last_vid_write; + int audio_timer; }; typedef struct av_file_context av_file_context_t; @@ -1585,11 +1586,17 @@ static switch_status_t av_file_open(switch_file_handle_t *handle, const char *pa context->seek_ts = -1; context->offset = DFT_RECORD_OFFSET; context->handle = handle; - + context->audio_timer = 1; + if (handle->params) { if ((tmp = switch_event_get_header(handle->params, "av_video_offset"))) { context->offset = atoi(tmp); } + if ((tmp = switch_event_get_header(handle->params, "video_time_audio"))) { + if (tmp && switch_false(tmp)) { + context->audio_timer = 0; + } + } } switch_mutex_init(&context->mutex, SWITCH_MUTEX_NESTED, handle->memory_pool); @@ -1910,9 +1917,12 @@ GCC_DIAG_ON(deprecated-declarations) delta = context->video_timer.samplecount - context->last_vid_write; - if (delta >= 60) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Video timer sync: %ld/%d %ld\n", context->audio_st[0].next_pts, context->video_timer.samplecount, context->audio_st[0].next_pts- context->video_timer.samplecount); - sample_start = context->video_timer.samplecount * (handle->samplerate / 1000); + if (context->audio_timer || delta >= 60) { + uint32_t new_pts = context->video_timer.samplecount * (handle->samplerate / 1000); + if (!context->audio_timer) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Delta of %d detected. Video timer sync: %ld/%d %ld\n", delta, context->audio_st[0].next_pts, context->video_timer.samplecount, new_pts - context->audio_st[0].next_pts); + } + sample_start = new_pts; } context->last_vid_write = context->video_timer.samplecount; diff --git a/src/mod/applications/mod_conference/conference_record.c b/src/mod/applications/mod_conference/conference_record.c index 784101fb7f..e54c8fcb96 100644 --- a/src/mod/applications/mod_conference/conference_record.c +++ b/src/mod/applications/mod_conference/conference_record.c @@ -233,7 +233,7 @@ void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t *thread, v flags |= SWITCH_FILE_FLAG_VIDEO; if (canvas) { - rec->path = switch_core_sprintf(rec->pool, "{channels=%d,samplerate=%d,vw=%d,vh=%d,fps=%0.2f}%s", + rec->path = switch_core_sprintf(rec->pool, "{video_time_audio=false,channels=%d,samplerate=%d,vw=%d,vh=%d,fps=%0.2f}%s", conference->channels, conference->rate, canvas->width, @@ -241,7 +241,7 @@ void *SWITCH_THREAD_FUNC conference_record_thread_run(switch_thread_t *thread, v conference->video_fps.fps, orig_path); } else { - rec->path = switch_core_sprintf(rec->pool, "{channels=%d,samplerate=%d,vw=%d,vh=%d,fps=%0.2f}%s", + rec->path = switch_core_sprintf(rec->pool, "{video_time_audio=false,channels=%d,samplerate=%d,vw=%d,vh=%d,fps=%0.2f}%s", conference->channels, conference->rate, conference->canvas_width, diff --git a/src/mod/applications/mod_conference/conference_video.c b/src/mod/applications/mod_conference/conference_video.c index d94847d098..19732ffbc5 100644 --- a/src/mod/applications/mod_conference/conference_video.c +++ b/src/mod/applications/mod_conference/conference_video.c @@ -1353,6 +1353,12 @@ switch_status_t conference_video_attach_video_layer(conference_member_t *member, return SWITCH_STATUS_FALSE; } + switch_mutex_lock(canvas->mutex); + + layer = &canvas->layers[idx]; + + layer->tagged = 0; + if (!zstr(member->video_role_id) && !zstr(layer->geometry.role_id) && !strcmp(layer->geometry.role_id, member->video_role_id)) { conference_utils_member_set_flag(member, MFLAG_DED_VID_LAYER); } @@ -1363,12 +1369,6 @@ switch_status_t conference_video_attach_video_layer(conference_member_t *member, } } - switch_mutex_lock(canvas->mutex); - - layer = &canvas->layers[idx]; - - layer->tagged = 0; - if (layer->fnode || layer->geometry.fileonly) { switch_goto_status(SWITCH_STATUS_FALSE, end); }