From c199d9a3692574dc3cfe328d793c5498338470d8 Mon Sep 17 00:00:00 2001 From: Roman Artiukhin Date: Wed, 18 Feb 2026 14:53:52 +0200 Subject: [PATCH] playback: fix single mode briefly plays audio from the next track before pausing Change-Id: Iab82427d5429210701e65103325f72c7919685e1 --- apps/pcmbuf.c | 11 ++++++++++- apps/playback.c | 20 +++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/apps/pcmbuf.c b/apps/pcmbuf.c index b32cb4c429..6bd39d4dc0 100644 --- a/apps/pcmbuf.c +++ b/apps/pcmbuf.c @@ -799,8 +799,10 @@ static void pcmbuf_pcm_callback(const void **start, size_t *size) if (desc) { + bool track_change = index == chunk_transidx; + /* If last chunk in the track, notify of track change */ - if (index == chunk_transidx) + if (track_change) { chunk_transidx = INVALID_BUF_INDEX; audio_pcmbuf_track_change(true); @@ -808,6 +810,13 @@ static void pcmbuf_pcm_callback(const void **start, size_t *size) /* Free it for reuse */ chunk_ridx = index = index_next(index); + + if (track_change && !audio_pcmbuf_may_play()) + { + current_desc = NULL; + *size = 0; + return; + } } /*- Process the new one -*/ diff --git a/apps/playback.c b/apps/playback.c index 22c19c4755..bdd2cfe14f 100644 --- a/apps/playback.c +++ b/apps/playback.c @@ -325,6 +325,7 @@ static unsigned int track_event_flags = TEF_NONE; /* (A, O-) */ static int skip_offset = 0; /* (A, O) */ static bool track_skip_is_manual = false; +static bool pause_on_track_change = false; /* Track change notification */ static struct @@ -1502,7 +1503,7 @@ static bool halt_decoding_track(bool stop) codec_skip_pending = false; codec_seeking = false; - + pause_on_track_change = false; return retval; } @@ -2733,12 +2734,6 @@ static void audio_finalise_track_change(void) { buf_read_cuesheet(info.cuesheet_hid); track_id3 = bufgetid3(info.id3_hid); - - if (single_mode_do_pause(info.id3_hid)) - { - play_status = PLAY_PAUSED; - pcmbuf_pause(true); - } } /* Sync the next track information */ have_info = track_list_current(1, &info); @@ -2934,8 +2929,9 @@ static void audio_on_codec_complete(int status) int id3_hid = 0; if (audio_can_change_track(&trackstat, &id3_hid)) { + pause_on_track_change = single_mode_do_pause(id3_hid); audio_begin_track_change( - single_mode_do_pause(id3_hid) + pause_on_track_change ? TRACK_CHANGE_END_OF_DATA : TRACK_CHANGE_AUTO, trackstat); } @@ -2954,6 +2950,12 @@ static void audio_on_codec_seek_complete(void) (Q_AUDIO_TRACK_CHANGED) */ static void audio_on_track_changed(void) { + if (pause_on_track_change) + { + play_status = PLAY_PAUSED; + pause_on_track_change = false; + } + /* Finish whatever is pending so that the WPS is in sync */ audio_finalise_track_change(); @@ -3850,7 +3852,7 @@ void audio_pcmbuf_track_change(bool pcmbuf) /* May pcmbuf start PCM playback when the buffer is full enough? */ bool audio_pcmbuf_may_play(void) { - return play_status == PLAY_PLAYING && !ff_rw_mode; + return play_status == PLAY_PLAYING && !ff_rw_mode && !pause_on_track_change; }