]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
FS-9497 #resolve [AV sync record issue]
authorAnthony Minessale <anthm@freeswitch.org>
Fri, 9 Sep 2016 21:48:34 +0000 (16:48 -0500)
committerAnthony Minessale <anthm@freeswitch.org>
Fri, 9 Sep 2016 21:48:43 +0000 (16:48 -0500)
src/mod/applications/mod_av/avformat.c
src/switch_core_media.c

index 264dd33e151e4da5fd164424b55ca8a37a087672..883a5be51f25035c09eaf1bcd235bbc5a7d80ac4 100644 (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 {
-                       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;
                        }
                }
index c301165bcb784ad20736555b077f5b86ac849969..98bedcd1ccf8423f35195b2d1d0ebec4f922a590 100644 (file)
@@ -7091,9 +7091,9 @@ SWITCH_DECLARE(switch_status_t) switch_core_media_activate_rtp(switch_core_sessi
                                        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);