From c2eeb639b04e0a13928208abebdb896eb06c258c Mon Sep 17 00:00:00 2001 From: Mathieu Duponchelle Date: Tue, 4 May 2021 14:38:28 +0200 Subject: [PATCH] basetsmux: fix SCTE pts_adjustment with offsets When there are elements between the demuxer and the muxer that introduce an offset to the running time, or when offsets are set on pads by the application, this shift must be taken into account when calculating the final pts_adjustement. Part-of: --- .../gst-plugins-bad/gst/mpegtsmux/gstbasetsmux.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/subprojects/gst-plugins-bad/gst/mpegtsmux/gstbasetsmux.c b/subprojects/gst-plugins-bad/gst/mpegtsmux/gstbasetsmux.c index d60afb0147..fc78be58cd 100644 --- a/subprojects/gst-plugins-bad/gst/mpegtsmux/gstbasetsmux.c +++ b/subprojects/gst-plugins-bad/gst/mpegtsmux/gstbasetsmux.c @@ -1550,8 +1550,9 @@ deep_copy_sit (const GstMpegtsSCTESIT * sit) * to the application to ensure that that is the case. */ static void -handle_scte35_section (GstBaseTsMux * mux, GstMpegtsSection * section, - guint64 mpeg_pts_offset, GstStructure * rtime_map) +handle_scte35_section (GstBaseTsMux * mux, GstEvent * event, + GstMpegtsSection * section, guint64 mpeg_pts_offset, + GstStructure * rtime_map) { GstMpegtsSCTESIT *sit; guint i; @@ -1744,6 +1745,11 @@ handle_scte35_section (GstBaseTsMux * mux, GstMpegtsSection * section, * - Our own 1-hour offset */ pts_adjust = sit->pts_adjustment + mpeg_pts_offset + TS_MUX_CLOCK_BASE; + + /* Account for offsets potentially introduced between the demuxer and us */ + pts_adjust += + GSTTIME_TO_MPEGTIME (gst_event_get_running_time_offset (event)); + pts_adjust &= 0x1ffffffff; section_data = g_memdup (section->data, section->section_length); section_data[4] |= pts_adjust >> 32; @@ -1790,7 +1796,7 @@ gst_base_ts_mux_send_event (GstElement * element, GstEvent * event) GST_DEBUG ("Received event with mpegts section"); if (section->section_type == GST_MPEGTS_SECTION_SCTE_SIT) { - handle_scte35_section (mux, section, 0, NULL); + handle_scte35_section (mux, event, section, 0, NULL); } else { /* TODO: Check that the section type is supported */ tsmux_add_mpegts_si_section (mux->tsmux, section); @@ -1847,7 +1853,8 @@ gst_base_ts_mux_sink_event (GstAggregator * agg, GstAggregatorPad * agg_pad, &rtime_map, NULL); gst_structure_get_uint64 (s, "mpeg-pts-offset", &mpeg_pts_offset); - handle_scte35_section (mux, section, mpeg_pts_offset, rtime_map); + handle_scte35_section (mux, event, section, mpeg_pts_offset, + rtime_map); if (rtime_map) gst_structure_free (rtime_map); mux->last_scte35_event_seqnum = gst_event_get_seqnum (event);