summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorroman.artiukhin <bahusdrive@gmail.com>2023-10-31 09:17:02 +0200
committerRoman Artiukhin <bahusdrive@gmail.com>2023-10-31 13:46:07 -0400
commit11b8336c64a54e376d22722b7bf8e5af902b9fba (patch)
tree90f20bef346e4015400febfbc3c80a0351a42f28
parentba627987465b565356fe373a5225f241c98c7710 (diff)
downloadrockbox-11b8336c64a54e376d22722b7bf8e5af902b9fba.tar.gz
rockbox-11b8336c64a54e376d22722b7bf8e5af902b9fba.zip
Fix rewind on resume is applied for skip length across tracks action after auto frequency switch
Add resume adjustments flag in mp3entry struct which is required for proper AUDIO_START_RESTART resume handling Fixup for 4fb37ecb (#5196) Change-Id: Ie9ecfe2b637bba38e442066333d71eeff01030ad
-rw-r--r--apps/playback.c53
-rw-r--r--lib/rbcodec/metadata/metadata.h1
2 files changed, 25 insertions, 29 deletions
diff --git a/apps/playback.c b/apps/playback.c
index 031e981915..7a2790cbe2 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -123,9 +123,6 @@ static enum audio_buffer_state
123/** Main state control **/ 123/** Main state control **/
124static bool ff_rw_mode SHAREDBSS_ATTR = false; /* Pre-ff-rewind mode (A,O-) */ 124static bool ff_rw_mode SHAREDBSS_ATTR = false; /* Pre-ff-rewind mode (A,O-) */
125 125
126static long seek_on_finish_load_time = 0;
127static int seek_on_finish_load_id3_hid = 0;
128
129static enum play_status 126static enum play_status
130{ 127{
131 PLAY_STOPPED = 0, 128 PLAY_STOPPED = 0,
@@ -1255,7 +1252,7 @@ static void audio_update_and_announce_next_track(const struct mp3entry *id3_next
1255 1252
1256/* Bring the user current mp3entry up to date and set a new offset for the 1253/* Bring the user current mp3entry up to date and set a new offset for the
1257 buffered metadata */ 1254 buffered metadata */
1258static void playing_id3_sync(struct track_info *user_infop, struct audio_resume_info *resume_info) 1255static void playing_id3_sync(struct track_info *user_infop, struct audio_resume_info *resume_info, bool skip_resume_adjustments)
1259{ 1256{
1260 id3_mutex_lock(); 1257 id3_mutex_lock();
1261 1258
@@ -1263,18 +1260,25 @@ static void playing_id3_sync(struct track_info *user_infop, struct audio_resume_
1263 1260
1264 pcm_play_lock(); 1261 pcm_play_lock();
1265 1262
1266 if (resume_info && id3) 1263 if (id3)
1267 { 1264 {
1268 id3->elapsed = resume_info->elapsed; 1265 if (resume_info)
1269 id3->offset = resume_info->offset; 1266 {
1267 id3->elapsed = resume_info->elapsed;
1268 id3->offset = resume_info->offset;
1269 }
1270 id3->skip_resume_adjustments = skip_resume_adjustments;
1270 } 1271 }
1272
1271 id3_write(PLAYING_ID3, id3); 1273 id3_write(PLAYING_ID3, id3);
1272 1274
1273 if (!resume_info && id3) 1275 if (!resume_info && id3)
1274 { 1276 {
1275 id3->offset = 0; 1277 id3->offset = 0;
1276 id3->elapsed = 0; 1278 id3->elapsed = 0;
1279 id3->skip_resume_adjustments = false;
1277 } 1280 }
1281
1278 pcm_play_unlock(); 1282 pcm_play_unlock();
1279 1283
1280 id3_mutex_unlock(); 1284 id3_mutex_unlock();
@@ -1580,16 +1584,8 @@ static bool audio_start_codec(bool auto_skip)
1580 return false; 1584 return false;
1581 } 1585 }
1582 1586
1583 bool delayed_seek = false; 1587 #ifdef HAVE_TAGCACHE
1584 if (info.id3_hid == seek_on_finish_load_id3_hid) 1588 bool autoresume_enable = !cur_id3->skip_resume_adjustments && global_settings.autoresume_enable;
1585 {
1586 cur_id3->elapsed = seek_on_finish_load_time;
1587 cur_id3->offset = 0;
1588 delayed_seek = true;
1589 }
1590
1591#ifdef HAVE_TAGCACHE
1592 bool autoresume_enable = !delayed_seek && global_settings.autoresume_enable;
1593 1589
1594 if (autoresume_enable && !(cur_id3->elapsed || cur_id3->offset)) 1590 if (autoresume_enable && !(cur_id3->elapsed || cur_id3->offset))
1595 { 1591 {
@@ -1639,8 +1635,11 @@ static bool audio_start_codec(bool auto_skip)
1639 and back again will cause accumulation of silent rewinds - that's not 1635 and back again will cause accumulation of silent rewinds - that's not
1640 our job to track directly nor could it be in any reasonable way 1636 our job to track directly nor could it be in any reasonable way
1641 */ 1637 */
1642 if (!delayed_seek) 1638 if (!cur_id3->skip_resume_adjustments)
1639 {
1643 resume_rewind_adjust_progress(cur_id3, &cur_id3->elapsed, &cur_id3->offset); 1640 resume_rewind_adjust_progress(cur_id3, &cur_id3->elapsed, &cur_id3->offset);
1641 cur_id3->skip_resume_adjustments = true;
1642 }
1644 1643
1645 /* Update the codec API with the metadata and track info */ 1644 /* Update the codec API with the metadata and track info */
1646 id3_write(CODEC_ID3, cur_id3); 1645 id3_write(CODEC_ID3, cur_id3);
@@ -2434,7 +2433,7 @@ static void audio_on_finish_load_track(int id3_hid)
2434 change otherwise */ 2433 change otherwise */
2435 bool was_valid = valid_mp3entry(id3_get(PLAYING_ID3)); 2434 bool was_valid = valid_mp3entry(id3_get(PLAYING_ID3));
2436 2435
2437 playing_id3_sync(&info, NULL); 2436 playing_id3_sync(&info, NULL, true);
2438 2437
2439 if (!was_valid) 2438 if (!was_valid)
2440 { 2439 {
@@ -2448,9 +2447,6 @@ static void audio_on_finish_load_track(int id3_hid)
2448 { 2447 {
2449 audio_handle_track_load_status(LOAD_TRACK_ERR_START_CODEC); 2448 audio_handle_track_load_status(LOAD_TRACK_ERR_START_CODEC);
2450 } 2449 }
2451
2452 seek_on_finish_load_time = 0;
2453 seek_on_finish_load_id3_hid = 0;
2454} 2450}
2455 2451
2456/* Called when handles other than metadata handles have finished buffering 2452/* Called when handles other than metadata handles have finished buffering
@@ -2627,7 +2623,7 @@ static void audio_begin_track_change(enum pcm_track_change_type type,
2627 if (audio_start_codec(!track_skip_is_manual)) 2623 if (audio_start_codec(!track_skip_is_manual))
2628 { 2624 {
2629 if (track_skip_is_manual) 2625 if (track_skip_is_manual)
2630 playing_id3_sync(&info, NULL); 2626 playing_id3_sync(&info, NULL, true);
2631 return; 2627 return;
2632 } 2628 }
2633 } 2629 }
@@ -2791,6 +2787,7 @@ static void audio_start_playback(const struct audio_resume_info *resume_info,
2791 static struct audio_resume_info resume = { 0, 0 }; 2787 static struct audio_resume_info resume = { 0, 0 };
2792 enum play_status old_status = play_status; 2788 enum play_status old_status = play_status;
2793 2789
2790 bool skip_resume_adjustments = false;
2794 if (resume_info) 2791 if (resume_info)
2795 { 2792 {
2796 resume.elapsed = resume_info->elapsed; 2793 resume.elapsed = resume_info->elapsed;
@@ -2828,6 +2825,7 @@ static void audio_start_playback(const struct audio_resume_info *resume_info,
2828 2825
2829 resume.elapsed = id3_get(PLAYING_ID3)->elapsed; 2826 resume.elapsed = id3_get(PLAYING_ID3)->elapsed;
2830 resume.offset = id3_get(PLAYING_ID3)->offset; 2827 resume.offset = id3_get(PLAYING_ID3)->offset;
2828 skip_resume_adjustments = id3_get(PLAYING_ID3)->skip_resume_adjustments;
2831 2829
2832 track_list_clear(TRACK_LIST_CLEAR_ALL); 2830 track_list_clear(TRACK_LIST_CLEAR_ALL);
2833 pcmbuf_update_frequency(); 2831 pcmbuf_update_frequency();
@@ -2904,7 +2902,7 @@ static void audio_start_playback(const struct audio_resume_info *resume_info,
2904 /* This is the currently playing track - get metadata, stat */ 2902 /* This is the currently playing track - get metadata, stat */
2905 struct track_info info; 2903 struct track_info info;
2906 track_list_current(0, &info); 2904 track_list_current(0, &info);
2907 playing_id3_sync(&info, &resume); 2905 playing_id3_sync(&info, &resume, skip_resume_adjustments);
2908 2906
2909 if (valid_mp3entry(id3_get(PLAYING_ID3))) 2907 if (valid_mp3entry(id3_get(PLAYING_ID3)))
2910 { 2908 {
@@ -3225,14 +3223,11 @@ static void audio_on_ff_rewind(long time)
3225 struct track_info cur_info; 3223 struct track_info cur_info;
3226 track_list_current(0, &cur_info); 3224 track_list_current(0, &cur_info);
3227 3225
3228 /* Track must complete the loading _now_ since a codec and audio
3229 handle are needed in order to do the seek */
3230 bool finish_load = cur_info.audio_hid < 0; 3226 bool finish_load = cur_info.audio_hid < 0;
3231 if (finish_load) 3227 if (finish_load)
3232 { 3228 {
3233 seek_on_finish_load_time = time; 3229 // track is not yet loaded so simply update resume details for upcoming finish_load_track and quit
3234 seek_on_finish_load_id3_hid = cur_info.id3_hid; 3230 playing_id3_sync(&cur_info, &(struct audio_resume_info){ time, 0 }, true);
3235 // Wait till playback thread receives finish load track event and seek then
3236 return; 3231 return;
3237 } 3232 }
3238 3233
diff --git a/lib/rbcodec/metadata/metadata.h b/lib/rbcodec/metadata/metadata.h
index cab387e36c..eda1fb0d7d 100644
--- a/lib/rbcodec/metadata/metadata.h
+++ b/lib/rbcodec/metadata/metadata.h
@@ -286,6 +286,7 @@ struct mp3entry {
286 /* resume related */ 286 /* resume related */
287 unsigned long offset; /* bytes played */ 287 unsigned long offset; /* bytes played */
288 int index; /* playlist index */ 288 int index; /* playlist index */
289 bool skip_resume_adjustments;
289 290
290#ifdef HAVE_TAGCACHE 291#ifdef HAVE_TAGCACHE
291 unsigned char autoresumable; /* caches result of autoresumable() */ 292 unsigned char autoresumable; /* caches result of autoresumable() */