aboutsummaryrefslogtreecommitdiff
path: root/patches/0008-yp3-no-rewind-on-pause-while-a-book-is-still-loading.patch
diff options
context:
space:
mode:
Diffstat (limited to 'patches/0008-yp3-no-rewind-on-pause-while-a-book-is-still-loading.patch')
-rw-r--r--patches/0008-yp3-no-rewind-on-pause-while-a-book-is-still-loading.patch70
1 files changed, 70 insertions, 0 deletions
diff --git a/patches/0008-yp3-no-rewind-on-pause-while-a-book-is-still-loading.patch b/patches/0008-yp3-no-rewind-on-pause-while-a-book-is-still-loading.patch
new file mode 100644
index 0000000..e8e8e58
--- /dev/null
+++ b/patches/0008-yp3-no-rewind-on-pause-while-a-book-is-still-loading.patch
@@ -0,0 +1,70 @@
+From cab74ec7312b907abd750b7ea807b2a4371e6f74 Mon Sep 17 00:00:00 2001
+From: YP3 Audiobook <noreply@example.invalid>
+Date: Fri, 27 Nov 2026 00:05:54 +0000
+Subject: [PATCH 08/11] yp3: no rewind-on-pause while a book is still loading
+
+Booting into a long M4B with Bluetooth headphones connecting sometimes
+loaded the book twice. Playback was paused during the load, and the
+pause's "rewind duration on pause" (2 s, the audiobook default) seeked
+to elapsed - 2 s, clamped to 0. A seek halts the codec, and halted
+mid-load it was started again, reading the whole index a second time.
+
+Rewind on pause now only when there is something to rewind: the track
+has played (elapsed > 0) and its index is not being read.
+
+---
+ apps/codec_thread.c | 6 ++++++
+ apps/codec_thread.h | 1 +
+ apps/gui/wps.c | 7 +++++--
+ 3 files changed, 12 insertions(+), 2 deletions(-)
+
+diff --git a/apps/codec_thread.c b/apps/codec_thread.c
+index a4f5b39c..fc6eeecf 100644
+--- a/apps/codec_thread.c
++++ b/apps/codec_thread.c
+@@ -598,6 +598,12 @@ static void codec_load_progress_callback(int percent)
+ load_percent = percent >= 100 ? -1 : percent;
+ }
+
++/* A track start is reading its index (load_progress), however briefly */
++bool codec_loading(void)
++{
++ return load_percent >= 0;
++}
++
+ /* 0-99 while a track start is reading its index and has taken longer than
+ * half a second (no flash for a short one), else -1 */
+ int codec_load_progress(void)
+diff --git a/apps/codec_thread.h b/apps/codec_thread.h
+index 36749228..6f0776d8 100644
+--- a/apps/codec_thread.h
++++ b/apps/codec_thread.h
+@@ -51,6 +51,7 @@ size_t codec_finish_stream(void);
+ void codec_unload(void);
+ int codec_loaded(void);
+ int codec_load_progress(void);
++bool codec_loading(void);
+
+ /* */
+
+diff --git a/apps/gui/wps.c b/apps/gui/wps.c
+index ebbca5fe..3fd19a0e 100644
+--- a/apps/gui/wps.c
++++ b/apps/gui/wps.c
+@@ -140,8 +140,11 @@ void wps_do_action(enum wps_do_action_type action, bool updatewps)
+ {
+ audio_pause();
+
+- if (global_settings.pause_rewind) {
+- unsigned long elapsed = audio_current_track()->elapsed;
++ unsigned long elapsed = audio_current_track()->elapsed;
++ /* Nothing to rewind until the track plays: a seek while a long
++ book still loads restarts the codec, which reads the whole
++ index again (a pause during the load at boot did) */
++ if (global_settings.pause_rewind && elapsed > 0 && !codec_loading()) {
+ long newpos = elapsed - (global_settings.pause_rewind * 1000);
+
+ audio_pre_ff_rewind();
+--
+2.56.1
+