splitmuxsrc: Calculate the end offset of a fragment once known
authorSebastian Dröge <sebastian@centricular.com>
Wed, 4 Dec 2024 14:42:49 +0000 (16:42 +0200)
committerGStreamer Marge Bot <gitlab-merge-bot@gstreamer-foundation.org>
Thu, 5 Dec 2024 23:28:24 +0000 (23:28 +0000)
If a new fragment is added with a valid duration but no offset then the start
offset is set later based on the end offset of the previous fragment. At that
point the end offset of this fragment can also be calculated and not doing so
would give the next fragment the same start offset.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/8069>

subprojects/gst-plugins-good/gst/multifile/gstsplitmuxpartreader.c

index b3ea7da61c8617dace70f6267cea509f85ae7246..13d339610fe5d34c49b8f7565c53cdd99dc8a87e 100644 (file)
@@ -1457,6 +1457,14 @@ gst_splitmux_part_reader_set_start_offset (GstSplitMuxPartReader * reader,
   reader->ts_offset = ts_offset;
   GST_INFO_OBJECT (reader, "Time offset now %" GST_TIME_FORMAT,
       GST_TIME_ARGS (time_offset));
+
+  if (!reader->need_duration_measuring
+      && reader->info.start_offset != GST_CLOCK_TIME_NONE) {
+    reader->end_offset = reader->info.start_offset + reader->info.duration;
+    GST_INFO_OBJECT (reader, "End offset set to %" GST_TIME_FORMAT,
+        GST_TIME_ARGS (reader->end_offset));
+  }
+
   SPLITMUX_PART_UNLOCK (reader);
 }
 
@@ -1470,6 +1478,14 @@ gst_splitmux_part_reader_set_duration (GstSplitMuxPartReader * reader,
 
   GST_INFO_OBJECT (reader, "Duration manually set to %" GST_TIME_FORMAT,
       GST_TIME_ARGS (duration));
+
+  if (!reader->need_duration_measuring
+      && reader->info.start_offset != GST_CLOCK_TIME_NONE) {
+    reader->end_offset = reader->info.start_offset + reader->info.duration;
+    GST_INFO_OBJECT (reader, "End offset set to %" GST_TIME_FORMAT,
+        GST_TIME_ARGS (reader->end_offset));
+  }
+
   SPLITMUX_PART_UNLOCK (reader);
 }