aboutsummaryrefslogtreecommitdiff
path: root/patches/0008-yp3-no-rewind-on-pause-while-a-book-is-still-loading.patch
blob: e8e8e581ade0fddaaa0ef41d52c30432e46bd9dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
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