tsmux: Fix PCR calculation for CBR live streams
authorVivia Nikolaidou <vivia@ahiru.eu>
Fri, 10 Jul 2020 18:14:01 +0000 (21:14 +0300)
committerGStreamer Merge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Tue, 28 Jul 2020 16:18:45 +0000 (16:18 +0000)
Take the first ever timestamp as an offset

Part-of: <https://gitlab.freedesktop.org/gstreamer/gst-plugins-bad/-/merge_requests/1431>

gst/mpegtsmux/tsmux/tsmux.c
gst/mpegtsmux/tsmux/tsmux.h

index 2856d03..647d6e5 100644 (file)
@@ -157,6 +157,8 @@ tsmux_new (void)
   mux->new_stream_func = (TsMuxNewStreamFunc) tsmux_stream_new;
   mux->new_stream_data = NULL;
 
+  mux->first_pcr_ts = G_MININT64;
+
   return mux;
 }
 
@@ -1252,7 +1254,12 @@ get_current_pcr (TsMux * mux, gint64 cur_ts)
   if (!mux->bitrate)
     return ts_to_pcr (cur_ts);
 
-  return ts_to_pcr (CLOCK_BASE) +
+  if (mux->first_pcr_ts == G_MININT64) {
+    g_assert (cur_ts != G_MININT64);
+    mux->first_pcr_ts = cur_ts;
+  }
+
+  return ts_to_pcr (mux->first_pcr_ts) +
       gst_util_uint64_scale (mux->n_bytes * 8, TSMUX_SYS_CLOCK_FREQ,
       mux->bitrate);
 }
index 8dbb9da..9f067a3 100644 (file)
@@ -200,6 +200,8 @@ struct TsMux {
 
   /* For the per-PID continuity counter */
   guint8 pid_packet_counts[8192];
+
+  gint64 first_pcr_ts;
 };
 
 /* create/free new muxer session */