From 597b684cd6db6d2e8bb763970657d600a1b68da6 Mon Sep 17 00:00:00 2001
From: Edward Hervey <edward@centricular.com>
Date: Thu, 9 Feb 2023 17:22:34 +0100
Subject: [PATCH] adaptivedemux2: Fix non-accurate seeking

If no accurate positioning was required, default to snap to the previous segment
for improved responsiveness

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/3914>
---
 .../gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c  | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c
index 8c0b7c1e8b..157186ce13 100644
--- a/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c
+++ b/subprojects/gst-plugins-good/ext/adaptivedemux2/gstadaptivedemux.c
@@ -2241,6 +2241,12 @@ gst_adaptive_demux_handle_seek_event (GstAdaptiveDemux * demux,
 
   GST_ADAPTIVE_DEMUX_SEGMENT_LOCK (demux);
 
+  if (!IS_SNAP_SEEK (flags) && !(flags & GST_SEEK_FLAG_ACCURATE)) {
+    /* If no accurate seeking was specified, we want to default to seeking to
+     * the previous segment for efficient/fast playback. */
+    flags |= GST_SEEK_FLAG_KEY_UNIT;
+  }
+
   if (IS_SNAP_SEEK (flags)) {
     GstAdaptiveDemux2Stream *default_stream = NULL;
     GstAdaptiveDemux2Stream *stream = NULL;