FS-9497 #resolve [AV sync record issue]

This commit is contained in:
Anthony Minessale committed 2016-09-09 16:48:43 -05:00
1 parent f6ad006daf
commit fd724a7b97
2 files changed
+31 -22

No files matched your search

+28 -19
View File
@@ -615,7 +615,7 @@ static void *SWITCH_THREAD_FUNC video_thread_run(switch_thread_t *thread, void *
switch_image_t *img = NULL, *tmp_img = NULL;
int d_w = eh->video_st->width, d_h = eh->video_st->height;
int size = 0, skip = 0, skip_freq = 0, skip_count = 0, skip_total = 0, skip_total_count = 0;
uint64_t hard_delta = 0, delta = 0, last_ts = 0;
uint64_t delta_avg = 0, delta_sum = 0, delta_i = 0, delta = 0, last_ts = 0;
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "video thread start\n");
@@ -626,10 +626,6 @@ static void *SWITCH_THREAD_FUNC video_thread_run(switch_thread_t *thread, void *
top:
if (eh->mm->fps) {
hard_delta = 1000 / eh->mm->fps;
}
if (switch_queue_pop(eh->video_queue, &pop) == SWITCH_STATUS_SUCCESS) {
switch_img_free(&img);
@@ -663,7 +659,7 @@ static void *SWITCH_THREAD_FUNC video_thread_run(switch_thread_t *thread, void *
} else {
size = switch_queue_size(eh->video_queue);
if (size > 5 && !eh->finalize) {
skip = size;
@@ -693,25 +689,38 @@ static void *SWITCH_THREAD_FUNC video_thread_run(switch_thread_t *thread, void *
fill_avframe(eh->video_st->frame, img);
if (hard_delta) {
delta = hard_delta;
}
if (eh->finalize) {
if (delta_i && !delta_avg) {
delta_avg = (int)(double)(delta_sum / delta_i);
delta_i = 0;
delta_sum = delta_avg;
}
if (delta_avg) {
delta = delta_avg;
} else if (eh->mm->fps) {
delta = 1000 / eh->mm->fps;
} else {
delta = 33;
}
if ((eh->finalize && delta) || hard_delta) {
eh->video_st->frame->pts += delta;
} else {
uint64_t delta_tmp;
switch_core_timer_sync(eh->timer);
delta_tmp = eh->timer->samplecount - last_ts;
if (eh->video_st->frame->pts == eh->timer->samplecount) {
// never use the same pts, or the encoder coughs
eh->video_st->frame->pts++;
} else {
uint64_t delta_tmp = eh->timer->samplecount - last_ts;
if (delta_tmp > 10) {
delta = delta_tmp;
if (delta_tmp != last_ts) {
delta_sum += delta_tmp;
delta_i++;
if (delta_i >= 60) {
delta_avg = (int)(double)(delta_sum / delta_i);
delta_i = 0;
delta_sum = delta_avg;
}
eh->video_st->frame->pts = eh->timer->samplecount;
}
}