FS-10249: [mod_av] Audio gradually falls behind video in recordings
This commit is contained in:
parent
7ef54c2926
commit
efbf7e5473
|
@ -444,9 +444,9 @@ static switch_status_t add_stream(MediaStream *mst, AVFormatContext *fc, AVCodec
|
||||||
c->width = mst->width;
|
c->width = mst->width;
|
||||||
c->height = mst->height;
|
c->height = mst->height;
|
||||||
c->bit_rate = mm->vb;
|
c->bit_rate = mm->vb;
|
||||||
mst->st->time_base.den = 1000;
|
mst->st->time_base.den = 90000;
|
||||||
mst->st->time_base.num = 1;
|
mst->st->time_base.num = 1;
|
||||||
c->time_base.den = 1000;
|
c->time_base.den = 90000;
|
||||||
c->time_base.num = 1;
|
c->time_base.num = 1;
|
||||||
c->gop_size = 25; /* emit one intra frame every x frames at mmst */
|
c->gop_size = 25; /* emit one intra frame every x frames at mmst */
|
||||||
c->pix_fmt = AV_PIX_FMT_YUV420P;
|
c->pix_fmt = AV_PIX_FMT_YUV420P;
|
||||||
|
@ -705,7 +705,7 @@ static void *SWITCH_THREAD_FUNC video_thread_run(switch_thread_t *thread, void *
|
||||||
{
|
{
|
||||||
av_file_context_t *context = (av_file_context_t *) obj;
|
av_file_context_t *context = (av_file_context_t *) obj;
|
||||||
void *pop = NULL;
|
void *pop = NULL;
|
||||||
switch_image_t *img = NULL, *tmp_img = NULL;
|
switch_image_t *img = NULL;
|
||||||
int d_w = context->eh.video_st->width, d_h = context->eh.video_st->height;
|
int d_w = context->eh.video_st->width, d_h = context->eh.video_st->height;
|
||||||
int size = 0, skip = 0, skip_freq = 0, skip_count = 0, skip_total = 0, skip_total_count = 0;
|
int size = 0, skip = 0, skip_freq = 0, skip_count = 0, skip_total = 0, skip_total_count = 0;
|
||||||
uint64_t delta_avg = 0, delta_sum = 0, delta_i = 0, delta = 0, last_ts = 0;
|
uint64_t delta_avg = 0, delta_sum = 0, delta_i = 0, delta = 0, last_ts = 0;
|
||||||
|
@ -733,16 +733,10 @@ static void *SWITCH_THREAD_FUNC video_thread_run(switch_thread_t *thread, void *
|
||||||
if (!d_w) d_w = img->d_w;
|
if (!d_w) d_w = img->d_w;
|
||||||
if (!d_h) d_h = img->d_h;
|
if (!d_h) d_h = img->d_h;
|
||||||
|
|
||||||
if (d_w && d_h && (d_w != img->d_w || d_h != img->d_h)) {
|
//if (d_w && d_h && (d_w != img->d_w || d_h != img->d_h)) {
|
||||||
/* scale to match established stream */
|
/* scale to match established stream */
|
||||||
|
// switch_img_fit(&img, d_w, d_h, SWITCH_FIT_SIZE);
|
||||||
switch_img_scale(img, &tmp_img, d_w, d_h);
|
//}
|
||||||
if (tmp_img) {
|
|
||||||
switch_img_free(&img);
|
|
||||||
img = tmp_img;
|
|
||||||
tmp_img = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -826,7 +820,7 @@ static void *SWITCH_THREAD_FUNC video_thread_run(switch_thread_t *thread, void *
|
||||||
|
|
||||||
context->eh.video_st->frame->pts = context->eh.timer->samplecount;
|
context->eh.video_st->frame->pts = context->eh.timer->samplecount;
|
||||||
} else {
|
} else {
|
||||||
context->eh.video_st->frame->pts = context->eh.timer->samplecount + 1;
|
context->eh.video_st->frame->pts = (context->eh.timer->samplecount) + 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1058,7 +1052,7 @@ SWITCH_STANDARD_APP(record_av_function)
|
||||||
context.eh.mutex = mutex;
|
context.eh.mutex = mutex;
|
||||||
context.eh.video_st = &video_st;
|
context.eh.video_st = &video_st;
|
||||||
context.eh.fc = fc;
|
context.eh.fc = fc;
|
||||||
if (switch_core_timer_init(&timer, "soft", 1, 1, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
|
if (switch_core_timer_init(&timer, "soft", 1, 90, switch_core_session_get_pool(session)) != SWITCH_STATUS_SUCCESS) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Timer Activation Fail\n");
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_ERROR, "Timer Activation Fail\n");
|
||||||
goto end;
|
goto end;
|
||||||
}
|
}
|
||||||
|
@ -1854,7 +1848,7 @@ static switch_status_t av_file_open(switch_file_handle_t *handle, const char *pa
|
||||||
if (context->has_video) {
|
if (context->has_video) {
|
||||||
switch_queue_create(&context->eh.video_queue, context->read_fps, handle->memory_pool);
|
switch_queue_create(&context->eh.video_queue, context->read_fps, handle->memory_pool);
|
||||||
switch_mutex_init(&context->eh.mutex, SWITCH_MUTEX_NESTED, handle->memory_pool);
|
switch_mutex_init(&context->eh.mutex, SWITCH_MUTEX_NESTED, handle->memory_pool);
|
||||||
switch_core_timer_init(&context->video_timer, "soft", 66, 1, context->pool);
|
switch_core_timer_init(&context->video_timer, "soft", (int)(1000.0f / context->read_fps), 1, context->pool);
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -2600,7 +2594,7 @@ static switch_status_t av_file_write_video(switch_file_handle_t *handle, switch_
|
||||||
switch_threadattr_create(&thd_attr, handle->memory_pool);
|
switch_threadattr_create(&thd_attr, handle->memory_pool);
|
||||||
//switch_threadattr_priority_set(thd_attr, SWITCH_PRI_REALTIME);
|
//switch_threadattr_priority_set(thd_attr, SWITCH_PRI_REALTIME);
|
||||||
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
|
switch_threadattr_stacksize_set(thd_attr, SWITCH_THREAD_STACKSIZE);
|
||||||
switch_core_timer_init(&context->video_timer, "soft", 1, 1, context->pool);
|
switch_core_timer_init(&context->video_timer, "soft", 1, 90, context->pool);
|
||||||
context->eh.timer = &context->video_timer;
|
context->eh.timer = &context->video_timer;
|
||||||
context->audio_st.frame->pts = 0;
|
context->audio_st.frame->pts = 0;
|
||||||
context->audio_st.next_pts = 0;
|
context->audio_st.next_pts = 0;
|
||||||
|
|
|
@ -10082,7 +10082,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_receive_message(switch_core_se
|
||||||
const char *val;
|
const char *val;
|
||||||
int ok = 0;
|
int ok = 0;
|
||||||
|
|
||||||
if ((!(val = switch_channel_get_variable(session->channel, "rtp_jitter_buffer_during_bridge")) || switch_false(val))) {
|
if (!switch_channel_test_flag(session->channel, CF_VIDEO_READY) &&
|
||||||
|
(!(val = switch_channel_get_variable(session->channel, "rtp_jitter_buffer_during_bridge")) || switch_false(val))) {
|
||||||
|
|
||||||
if (switch_channel_test_flag(session->channel, CF_JITTERBUFFER) && switch_channel_test_cap_partner(session->channel, CC_FS_RTP)) {
|
if (switch_channel_test_flag(session->channel, CF_JITTERBUFFER) && switch_channel_test_cap_partner(session->channel, CC_FS_RTP)) {
|
||||||
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
|
switch_log_printf(SWITCH_CHANNEL_SESSION_LOG(session), SWITCH_LOG_DEBUG,
|
||||||
"%s PAUSE Jitterbuffer\n", switch_channel_get_name(session->channel));
|
"%s PAUSE Jitterbuffer\n", switch_channel_get_name(session->channel));
|
||||||
|
|
|
@ -591,6 +591,11 @@ static void *SWITCH_THREAD_FUNC video_bug_thread(switch_thread_t *thread, void *
|
||||||
switch_timer_t timer = { 0 };
|
switch_timer_t timer = { 0 };
|
||||||
switch_mm_t mm = { 0 };
|
switch_mm_t mm = { 0 };
|
||||||
int fps = 15;
|
int fps = 15;
|
||||||
|
int vw = 1280;
|
||||||
|
int vh = 720;
|
||||||
|
int last_w = 0, last_h = 0, other_last_w = 0, other_last_h = 0;
|
||||||
|
switch_rgb_color_t color = { 0 };
|
||||||
|
switch_color_set_rgb(&color, "#000000");
|
||||||
|
|
||||||
buf = switch_core_session_alloc(bug->session, buflen);
|
buf = switch_core_session_alloc(bug->session, buflen);
|
||||||
frame.packet = buf;
|
frame.packet = buf;
|
||||||
|
@ -617,6 +622,9 @@ static void *SWITCH_THREAD_FUNC video_bug_thread(switch_thread_t *thread, void *
|
||||||
fps = (int) mm.fps;
|
fps = (int) mm.fps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mm.vw) vw = mm.vw;
|
||||||
|
if (mm.vh) vh = mm.vh;
|
||||||
|
|
||||||
switch_core_timer_init(&timer, "soft", 1000 / fps, (90000 / (1000 / fps)), NULL);
|
switch_core_timer_init(&timer, "soft", 1000 / fps, (90000 / (1000 / fps)), NULL);
|
||||||
|
|
||||||
while (bug->ready) {
|
while (bug->ready) {
|
||||||
|
@ -633,6 +641,9 @@ static void *SWITCH_THREAD_FUNC video_bug_thread(switch_thread_t *thread, void *
|
||||||
|
|
||||||
flush_video_queue(main_q, 1);
|
flush_video_queue(main_q, 1);
|
||||||
|
|
||||||
|
w = vw / 2;
|
||||||
|
h = vh;
|
||||||
|
|
||||||
if ((status = switch_queue_trypop(main_q, &pop)) == SWITCH_STATUS_SUCCESS) {
|
if ((status = switch_queue_trypop(main_q, &pop)) == SWITCH_STATUS_SUCCESS) {
|
||||||
switch_img_free(&img);
|
switch_img_free(&img);
|
||||||
|
|
||||||
|
@ -643,8 +654,12 @@ static void *SWITCH_THREAD_FUNC video_bug_thread(switch_thread_t *thread, void *
|
||||||
img = (switch_image_t *) pop;
|
img = (switch_image_t *) pop;
|
||||||
new_main = 1;
|
new_main = 1;
|
||||||
|
|
||||||
w = img->d_w;
|
if (IMG && !(last_w == img->d_w && last_h == img->d_h)) {
|
||||||
h = img->d_h;
|
switch_img_fill(IMG, 0, 0, w, h, &color);
|
||||||
|
}
|
||||||
|
|
||||||
|
last_w = img->d_w;
|
||||||
|
last_h = img->d_h;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (other_q) {
|
if (other_q) {
|
||||||
|
@ -653,55 +668,48 @@ static void *SWITCH_THREAD_FUNC video_bug_thread(switch_thread_t *thread, void *
|
||||||
if ((status = switch_queue_trypop(other_q, &other_pop)) == SWITCH_STATUS_SUCCESS) {
|
if ((status = switch_queue_trypop(other_q, &other_pop)) == SWITCH_STATUS_SUCCESS) {
|
||||||
switch_img_free(&other_img);
|
switch_img_free(&other_img);
|
||||||
other_img = (switch_image_t *) other_pop;
|
other_img = (switch_image_t *) other_pop;
|
||||||
|
|
||||||
|
if (IMG && !(other_last_w == other_img->d_w && other_last_h == other_img->d_h)) {
|
||||||
|
switch_img_fill(IMG, w, 0, w, h, &color);
|
||||||
|
}
|
||||||
|
|
||||||
|
other_last_w = other_img->d_w;
|
||||||
|
other_last_h = other_img->d_h;
|
||||||
new_other = 1;
|
new_other = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (other_img) {
|
|
||||||
if (!w) w = other_img->d_w;
|
|
||||||
if (!h) h = other_img->d_h;
|
|
||||||
|
|
||||||
if (other_img->d_w != w || other_img->d_h != h) {
|
if (img && new_main) {
|
||||||
switch_image_t *tmp_img = NULL;
|
switch_img_fit(&img, w, h, SWITCH_FIT_SIZE);
|
||||||
|
|
||||||
switch_img_scale(other_img, &tmp_img, w, h);
|
|
||||||
switch_img_free(&other_img);
|
|
||||||
other_img = tmp_img;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(w&&h)) continue;
|
if (other_img && new_other) {
|
||||||
|
switch_img_fit(&other_img, w, h, SWITCH_FIT_SIZE);
|
||||||
if (img) {
|
|
||||||
if (img->d_w != w || img->d_h != h) {
|
|
||||||
switch_image_t *tmp_img = NULL;
|
|
||||||
|
|
||||||
switch_img_scale(img, &tmp_img, w, h);
|
|
||||||
switch_img_free(&img);
|
|
||||||
img = tmp_img;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
w *= 2;
|
if (!IMG) {
|
||||||
|
IMG = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, vw, vh, 1);
|
||||||
if (!IMG || IMG->d_h != h || IMG->d_w != w) {
|
|
||||||
switch_rgb_color_t color = { 0 };
|
|
||||||
|
|
||||||
switch_img_free(&IMG);
|
|
||||||
IMG = switch_img_alloc(NULL, SWITCH_IMG_FMT_I420, w, h, 1);
|
|
||||||
new_canvas = 1;
|
new_canvas = 1;
|
||||||
switch_color_set_rgb(&color, "#000000");
|
|
||||||
switch_img_fill(IMG, 0, 0, IMG->d_w, IMG->d_h, &color);
|
switch_img_fill(IMG, 0, 0, IMG->d_w, IMG->d_h, &color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (IMG) {
|
if (IMG) {
|
||||||
|
|
||||||
|
|
||||||
if (img && (new_canvas || new_main)) {
|
if (img && (new_canvas || new_main)) {
|
||||||
switch_img_patch(IMG, img, 0, 0);
|
int x = 0, y = 0;
|
||||||
|
switch_img_find_position(POS_CENTER_MID, w, h, img->d_w, img->d_h, &x, &y);
|
||||||
|
|
||||||
|
switch_img_patch(IMG, img, x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (other_img && (new_canvas || new_other)) {
|
if (other_img && (new_canvas || new_other)) {
|
||||||
switch_img_patch(IMG, other_img, w / 2, 0);
|
int x = 0, y = 0;
|
||||||
|
switch_img_find_position(POS_CENTER_MID, w, h, other_img->d_w, other_img->d_h, &x, &y);
|
||||||
|
|
||||||
|
switch_img_patch(IMG, other_img, w + x, y);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue