From 3e810a67212a618ebdeb5a7eaf8a851547792f10 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Fri, 12 Apr 2024 15:52:23 +0200 Subject: [PATCH] hlsdemux2: Refactor update of GstHLSTimeMap values This was also missing transferring the PDT if present Part-of: --- .../adaptivedemux2/hls/gsthlsdemux-stream.c | 8 +-- .../ext/adaptivedemux2/hls/gsthlsdemux.c | 50 +++++++++++-------- .../ext/adaptivedemux2/hls/gsthlsdemux.h | 2 + 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux-stream.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux-stream.c index f03aa288b1..75f9a0428a 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux-stream.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux-stream.c @@ -537,8 +537,8 @@ gst_hlsdemux_stream_handle_internal_time (GstHLSDemuxStream * hls_stream, if (hls_stream->parser_type == GST_HLS_PARSER_ISOBMFF) hls_stream->presentation_offset = internal_time - current_stream_time; - map->stream_time = current_stream_time; - map->internal_time = internal_time; + gst_time_map_set_values (map, current_stream_time, internal_time, + current_segment->datetime); gst_hls_demux_start_rendition_streams (demux); return GST_HLS_PARSER_RESULT_DONE; @@ -550,8 +550,8 @@ gst_hlsdemux_stream_handle_internal_time (GstHLSDemuxStream * hls_stream, "DISCONT segment, Updating time map to stream_time:%" GST_STIME_FORMAT " internal_time:%" GST_TIME_FORMAT, GST_STIME_ARGS (internal_time), GST_TIME_ARGS (current_stream_time)); - map->stream_time = current_stream_time; - map->internal_time = internal_time; + gst_time_map_set_values (map, current_stream_time, internal_time, + current_segment->datetime); return GST_HLS_PARSER_RESULT_DONE; } diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c index 33a30d80b5..1aaca05915 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.c @@ -916,6 +916,34 @@ gst_hls_time_map_free (GstHLSTimeMap * map) g_free (map); } +void +gst_time_map_set_values (GstHLSTimeMap * map, GstClockTimeDiff stream_time, + GstClockTime internal_time, GDateTime * pdt) +{ + GstClockTime offset = 0; + + if (stream_time < 0) { + offset = -stream_time; + stream_time = 0; + /* Handle negative stream times. This can happen for example when the server + * returns an older playlist. + * + * Shift the values accordingly to end up with non-negative reference stream + * time */ + GST_DEBUG ("Shifting values before storage (offset : %" GST_TIME_FORMAT ")", + GST_TIME_ARGS (offset)); + } + + map->stream_time = stream_time; + map->internal_time = internal_time; + if (pdt) { + if (offset) + map->pdt = g_date_time_add (pdt, offset / GST_USECOND); + else + map->pdt = g_date_time_ref (pdt); + } +} + void gst_hls_demux_add_time_mapping (GstHLSDemux * demux, gint64 dsn, GstClockTimeDiff stream_time, GDateTime * pdt) @@ -925,7 +953,6 @@ gst_hls_demux_add_time_mapping (GstHLSDemux * demux, gint64 dsn, #endif GstHLSTimeMap *map; GList *tmp; - GstClockTime offset = 0; /* Check if we don't already have a mapping for the given dsn */ for (tmp = demux->mappings; tmp; tmp = tmp->next) { @@ -955,28 +982,9 @@ gst_hls_demux_add_time_mapping (GstHLSDemux * demux, gint64 dsn, g_free (datestring); #endif - if (stream_time < 0) { - offset = -stream_time; - stream_time = 0; - /* Handle negative stream times. This can happen for example when the server - * returns an older playlist. - * - * Shift the values accordingly to end up with non-negative reference stream - * time */ - GST_DEBUG_OBJECT (demux, - "Shifting values before storage (offset : %" GST_TIME_FORMAT ")", - GST_TIME_ARGS (offset)); - } - map = gst_hls_time_map_new (); map->dsn = dsn; - map->stream_time = stream_time; - if (pdt) { - if (offset) - map->pdt = g_date_time_add (pdt, offset / GST_USECOND); - else - map->pdt = g_date_time_ref (pdt); - } + gst_time_map_set_values (map, stream_time, GST_CLOCK_TIME_NONE, pdt); demux->mappings = g_list_append (demux->mappings, map); } diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.h b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.h index f47fc42573..857577f042 100644 --- a/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.h +++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/hls/gsthlsdemux.h @@ -129,6 +129,8 @@ gboolean gst_hls_demux_change_variant_playlist (GstHLSDemux * demux, GstFlowReturn gst_hls_demux_update_variant_playlist (GstHLSDemux * demux, GError ** err); +void gst_time_map_set_values (GstHLSTimeMap *map, GstClockTimeDiff stream_time, + GstClockTime internal_time, GDateTime *pdt); void gst_hls_demux_add_time_mapping (GstHLSDemux * demux, gint64 dsn, GstClockTimeDiff stream_time, GDateTime * pdt); void gst_hls_update_time_mappings (GstHLSDemux * demux,