rendered paste bodydiff --git a/apps/playback.c b/apps/playback.cindex cca5b73..bf02914 100644--- a/apps/playback.c+++ b/apps/playback.c@@ -222,6 +222,10 @@ static int track_widx = 0; /* Track being buffered (A) */ static struct track_info *prev_ti = NULL; /* Pointer to the previously played track */ +/* Set by buffering_audio_callback when the low buffer event is received, to+ avoid flodding the audio queue with fill_file_buffer messages. */+static bool lowbuffer_event_sent = false;+ /* Set by the audio thread when the current track information has updated * and the WPS may need to update its cached information */ static bool track_changed = false;@@ -553,7 +557,8 @@ struct mp3entry* audio_current_track(void) struct mp3entry* audio_next_track(void) {- int next_idx = track_ridx;+ int next_idx;+ int offset = ci.new_track + wps_offset; if (!audio_have_tracks()) return NULL;@@ -565,7 +570,7 @@ struct mp3entry* audio_next_track(void) return &curtrack_id3; } - next_idx = (next_idx + 1) & MAX_TRACK_MASK;+ next_idx = (track_ridx + offset + 1) & MAX_TRACK_MASK; if (next_idx == track_widx) {@@ -629,17 +634,19 @@ void audio_resume(void) queue_send(&audio_queue, Q_AUDIO_PAUSE, false); } -void audio_next(void)+static void audio_skip(int direction) {- if (playlist_check(ci.new_track + wps_offset + 1))+ if (playlist_check(ci.new_track + wps_offset + direction)) { if (global_settings.beep) pcmbuf_beep(5000, 100, 2500*global_settings.beep); - LOGFQUEUE("audio > audio Q_AUDIO_SKIP 1");- queue_post(&audio_queue, Q_AUDIO_SKIP, 1);+ LOGFQUEUE("audio > audio Q_AUDIO_SKIP %d", direction);+ queue_post(&audio_queue, Q_AUDIO_SKIP, direction); /* Update wps while our message travels inside deep playback queues. */- wps_offset++;+ playlist_next(direction);+ last_peek_offset -= direction;+ wps_offset += direction; track_changed = true; } else@@ -650,25 +657,14 @@ void audio_next(void) } } -void audio_prev(void)+void audio_next(void) {- if (playlist_check(ci.new_track + wps_offset - 1))- {- if (global_settings.beep)- pcmbuf_beep(5000, 100, 2500*global_settings.beep);+ audio_skip(1);+} - LOGFQUEUE("audio > audio Q_AUDIO_SKIP -1");- queue_post(&audio_queue, Q_AUDIO_SKIP, -1);- /* Update wps while our message travels inside deep playback queues. */- wps_offset--;- track_changed = true;- }- else- {- /* No more tracks. */- if (global_settings.beep)- pcmbuf_beep(1000, 100, 1000*global_settings.beep);- }+void audio_prev(void)+{+ audio_skip(-1); } void audio_next_dir(void)@@ -1466,8 +1462,11 @@ static void buffering_audio_callback(enum callback_event ev, int value) switch (ev) { case EVENT_BUFFER_LOW:- LOGFQUEUE("buffering > audio Q_AUDIO_FILL_BUFFER");- queue_post(&audio_queue, Q_AUDIO_FILL_BUFFER, 0);+ if (!lowbuffer_event_sent) {+ LOGFQUEUE("buffering > audio Q_AUDIO_FILL_BUFFER");+ queue_post(&audio_queue, Q_AUDIO_FILL_BUFFER, 0);+ lowbuffer_event_sent = true;+ } break; case EVENT_HANDLE_REBUFFER:@@ -1476,6 +1475,7 @@ static void buffering_audio_callback(enum callback_event ev, int value) break; case EVENT_HANDLE_FINISHED:+ logf("handle %d finished buffering", value); strip_tags(value); break; @@ -1895,6 +1895,9 @@ static void audio_fill_file_buffer(bool start_play, size_t offset) bool had_next_track = audio_next_track() != NULL; bool continue_buffering; + if (ci.new_track != 0)+ return;+ /* Must reset the buffer before use if trashed or voice only - voice file size shouldn't have changed so we can go straight from BUFFER_STATE_VOICED_ONLY to BUFFER_STATE_INITIALIZED */@@ -1930,6 +1933,7 @@ static void audio_fill_file_buffer(bool start_play, size_t offset) track_changed = true; audio_generate_postbuffer_events();+ lowbuffer_event_sent = false; } static void audio_rebuffer(void)@@ -2001,12 +2005,13 @@ static int audio_check_new_track(void) return Q_CODEC_REQUEST_FAILED; } }- /* Update the playlist */- last_peek_offset -= ci.new_track; - if (auto_dir_skip || !automatic_skip)+ if (auto_dir_skip) {- /* If the track change was manual or the result of an auto dir skip,+ /* Update the playlist */+ last_peek_offset -= ci.new_track;++ /* If the track change was the result of an auto dir skip, we need to update the playlist now */ next_playlist_index = playlist_next(ci.new_track); @@ -2061,10 +2066,9 @@ static int audio_check_new_track(void) { playlist_end = false; wps_offset = -ci.new_track;+ track_changed = true; } - track_changed = true;- /* If it is not safe to even skip this many track entries */ if (ci.new_track >= track_count || ci.new_track <= track_count - MAX_TRACK) {@@ -2296,8 +2300,11 @@ static void audio_new_playlist(void) audio_fill_file_buffer(false, 0); } +/* Called on manual track skip */ static void audio_initiate_track_change(long direction) {+ logf("audio_initiate_track_change(%ld)", direction);+ playlist_end = false; ci.new_track += direction; wps_offset -= direction;@@ -2305,6 +2312,7 @@ static void audio_initiate_track_change(long direction) skipped_during_pause = true; } +/* Called on manual dir skip */ static void audio_initiate_dir_change(long direction) { playlist_end = false;