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");
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);
} else {
size = switch_queue_size(eh->video_queue);
-
+
if (size > 5 && !eh->finalize) {
skip = size;
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 {
- switch_core_timer_sync(eh->timer);
+ uint64_t delta_tmp;
- 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;
+ switch_core_timer_sync(eh->timer);
+ delta_tmp = eh->timer->samplecount - last_ts;
+
+ 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;
}
}
switch_core_media_parse_rtp_bugs(&v_engine->rtp_bugs, val);
}
- if (switch_channel_test_flag(session->channel, CF_AVPF)) {
- smh->mparams->manual_video_rtp_bugs = RTP_BUG_SEND_LINEAR_TIMESTAMPS;
- }
+ //if (switch_channel_test_flag(session->channel, CF_AVPF)) {
+ //smh->mparams->manual_video_rtp_bugs = RTP_BUG_SEND_LINEAR_TIMESTAMPS;
+ //}
switch_rtp_intentional_bugs(v_engine->rtp_session, v_engine->rtp_bugs | smh->mparams->manual_video_rtp_bugs);