[vlc-commits] demux: timestamps_filter: handle single pcr continuity

Francois Cartegnie git at videolan.org
Wed Dec 18 20:59:32 CET 2019


vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Mon Dec 16 21:19:42 2019 +0100| [f74ed2d6de995fc0a4fdae4e7b3ba3f34208d340] | committer: Francois Cartegnie

demux: timestamps_filter: handle single pcr continuity

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=f74ed2d6de995fc0a4fdae4e7b3ba3f34208d340
---

 modules/demux/timestamps_filter.h | 44 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 43 insertions(+), 1 deletion(-)

diff --git a/modules/demux/timestamps_filter.h b/modules/demux/timestamps_filter.h
index 5c726b111d..2b8f0112b0 100644
--- a/modules/demux/timestamps_filter.h
+++ b/modules/demux/timestamps_filter.h
@@ -39,6 +39,13 @@ struct timestamps_filter_s
     struct moving_average_s mva;
     vlc_tick_t sequence_offset;
     vlc_tick_t contiguous_last;
+    /**/
+    struct name
+    {
+        vlc_tick_t stream;
+        vlc_tick_t contiguous;
+    } sync;
+    /**/
     unsigned sequence;
 };
 
@@ -67,6 +74,8 @@ static void timestamps_filter_init(struct timestamps_filter_s *tf)
     mva_init(&tf->mva);
     tf->sequence_offset = 0;
     tf->contiguous_last = 0;
+    tf->sync.stream = 0;
+    tf->sync.contiguous = 0;
     tf->sequence = -1;
 }
 
@@ -90,7 +99,9 @@ static bool timestamps_filter_push(const char *s, struct timestamps_filter_s *tf
             if(llabs(i_dts - prev->dts) > i_maxdiff || b_discontinuity) /* Desync */
             {
                 prev->diff = mva_get(&tf->mva);
-                tf->sequence_offset = tf->contiguous_last - i_dts + prev->diff;
+                tf->sync.stream = i_dts;
+                tf->sync.contiguous = tf->contiguous_last + prev->diff;
+                tf->sequence_offset = tf->sync.contiguous - tf->sync.stream;
 #ifdef DEBUG_TIMESTAMPS_FILTER
                 printf("%4.4s found offset of %ld\n", s, (prev->dts - i_dts));
 #endif
@@ -156,7 +167,29 @@ static int timestamps_filter_es_out_Control(es_out_t *out, int i_query, va_list
             int64_t pcr = va_arg(va_list, int64_t);
 
             if(timestamps_filter_push("PCR ", &p_sys->pcrtf, pcr, 0, p_sys->b_discontinuity, true))
+            {
                 p_sys->pcrtf.sequence++;
+                /* Handle special start case, there was 1 single PCR before */
+                if(p_sys->pcrtf.mva.i_packet == 2)
+                {
+                    vlc_tick_t max = 0;
+                    for(int i=0; i<p_sys->es_list.i_size; i++)
+                    {
+                        struct tf_es_out_id_s *cur = (struct tf_es_out_id_s *)p_sys->es_list.p_elems[i];
+                        if(cur->contiguous && cur->tf.contiguous_last)
+                            max = __MAX(max, cur->tf.contiguous_last);
+                    }
+                    if(max)
+                    {
+#ifdef DEBUG_TIMESTAMPS_FILTER
+                    printf("PCR  no previous value, using %ld\n", max);
+#endif
+                    p_sys->pcrtf.sync.stream = pcr;
+                    p_sys->pcrtf.sync.contiguous = max;
+                    p_sys->pcrtf.sequence_offset = max - pcr;
+                    }
+                }
+            }
 
             pcr += p_sys->pcrtf.sequence_offset;
 
@@ -230,6 +263,15 @@ static int timestamps_filter_es_out_Send(es_out_t *out, es_out_id_t *id, block_t
 #endif
         }
     }
+    else /* PCR had discontinuity, we're in a new segment */
+    {
+        if(cur->tf.mva.i_packet == 1)
+        {
+          cur->tf.sync.stream = p_sys->pcrtf.sync.stream;
+          cur->tf.sync.contiguous = p_sys->pcrtf.sync.contiguous;
+          cur->tf.sequence_offset = cur->tf.sync.contiguous - cur->tf.sync.stream;
+        }
+    }
 
     /* Record our state */
     if(p_sys->pcrtf.mva.i_packet > 0)



More information about the vlc-commits mailing list