From d8b37973d2d9395665f2af8c5bc40bc3eb1cb48a Mon Sep 17 00:00:00 2001 From: Vivia Nikolaidou Date: Fri, 10 Jul 2020 21:14:01 +0300 Subject: [PATCH] tsmux: Fix PCR calculation for CBR live streams Take the first ever timestamp as an offset Part-of: --- gst/mpegtsmux/tsmux/tsmux.c | 9 ++++++++- gst/mpegtsmux/tsmux/tsmux.h | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/gst/mpegtsmux/tsmux/tsmux.c b/gst/mpegtsmux/tsmux/tsmux.c index 2856d03..647d6e5 100644 --- a/gst/mpegtsmux/tsmux/tsmux.c +++ b/gst/mpegtsmux/tsmux/tsmux.c @@ -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); } diff --git a/gst/mpegtsmux/tsmux/tsmux.h b/gst/mpegtsmux/tsmux/tsmux.h index 8dbb9da..9f067a3 100644 --- a/gst/mpegtsmux/tsmux/tsmux.h +++ b/gst/mpegtsmux/tsmux/tsmux.h @@ -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 */ -- 2.7.4