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

Francois Cartegnie git at videolan.org
Mon Jan 13 18:09:45 CET 2020


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

demux: timestamps_filter: handle single pcr continuity

(cherry picked from commit f74ed2d6de995fc0a4fdae4e7b3ba3f34208d340)

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

 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 0156dbe2f9..e884d20c61 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;
     mtime_t sequence_offset;
     mtime_t contiguous_last;
+    /**/
+    struct name
+    {
+        mtime_t stream;
+        mtime_t contiguous;
+    } sync;
+    /**/
     unsigned sequence;
 };
 
@@ -66,6 +73,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;
 }
 
@@ -89,7 +98,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
@@ -155,7 +166,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)
+                {
+                    mtime_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;
 
@@ -229,6 +262,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