From 9c06f44b03ec170ab5083552c332932b6ce1bb4f Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Wed, 19 Mar 2025 22:05:16 +0100 Subject: [PATCH] Introduce VSS_NEW_AUDIO_FILE to fix playlist updates. The playlist event handler handles afsi change events by moving the affected entry to the end of the playlist. This is the right thing to do if the event was triggered by virtual streaming system streaming a new file. It is incorrect, however, if the event was triggered by a subcommand such as touch. This commit introduces the new afs event type VSS_NEW_AUDIO_FILE to distinguish between the two different use cases. The audio file table event handler ignores the VSS_NEW_AUDIO_FILE event while the playlist event handler ignores the AFSI_CHANGE event. The moods event handler treats both events equally, Get rid of a pointless static one-liner function in playlist.c while at it. --- afs.h | 2 ++ aft.c | 10 ++++------ m4/lls/server_cmd.suite.m4 | 4 +--- mood.c | 1 + playlist.c | 21 ++++----------------- 5 files changed, 12 insertions(+), 26 deletions(-) diff --git a/afs.h b/afs.h index 622ac70f..b46aeed1 100644 --- a/afs.h +++ b/afs.h @@ -39,6 +39,8 @@ enum afs_events { AFSI_CHANGE, /** The afh info struct of an audio file changed. */ AFHI_CHANGE, + /** The vss streams a new file, implies afsi and afhi change */ + VSS_NEW_AUDIO_FILE, /** An audio file was renamed. */ AUDIO_FILE_RENAME, /** An audio file was added. */ diff --git a/aft.c b/aft.c index 383439d0..8abfbc94 100644 --- a/aft.c +++ b/aft.c @@ -1108,6 +1108,7 @@ again: ret = -E_HASH_MISMATCH; goto out; } + old_afsi = d->afsi; d->afsi.num_played++; d->afsi.last_played = time(NULL); @@ -1115,14 +1116,11 @@ again: d->afsi.last_played = old_afsi.last_played; aced.aft_row = current_aft_row; aced.old_afsi = &old_afsi; - afd.audio_format_id = d->afsi.audio_format_id; load_chunk_table(&afd.afhi, &chunk_table_obj); - /* - * No need to update the status items as the AFSI_CHANGE event will - * recreate them. - */ - ret = afs_event(AFSI_CHANGE, NULL, &aced); + make_status_items(); + + ret = afs_event(VSS_NEW_AUDIO_FILE, NULL, &aced); if (ret < 0) goto out; ret = save_afd(&afd); diff --git a/m4/lls/server_cmd.suite.m4 b/m4/lls/server_cmd.suite.m4 index 6056541c..1b282f3a 100644 --- a/m4/lls/server_cmd.suite.m4 +++ b/m4/lls/server_cmd.suite.m4 @@ -553,9 +553,7 @@ m4_include(`com_ll.m4') all other fields are left unchanged. This mimics what happens when the virtual streaming system selects the file for streaming. - If the file is admissible for the current mood (or contained in the - current playlist), its score is recomputed according to the changed - values. + If the file is admissible for the current mood, its score is recomputed. [/description] [option numplayed] short_opt = n diff --git a/mood.c b/mood.c index 01ef2c8a..c697b168 100644 --- a/mood.c +++ b/mood.c @@ -756,6 +756,7 @@ int moods_event_handler(enum afs_events event, __a_unused struct para_buffer *pb case ATTRIBUTE_RENAME: return reload_current_mood(); /* changes to the aft only require to re-examine the audio file */ + case VSS_NEW_AUDIO_FILE: case AFSI_CHANGE: { struct afsi_change_event_data *aced = data; return mood_update_audio_file(aced->aft_row, aced->old_afsi); diff --git a/playlist.c b/playlist.c index 3a7df149..93acf774 100644 --- a/playlist.c +++ b/playlist.c @@ -28,19 +28,6 @@ struct playlist_instance { }; static struct playlist_instance current_playlist; -/** - * Re-insert an audio file into the tree of admissible files. - * - * \param aft_row Determines the audio file. - * - * \return The return value of score_update(). - */ -static int playlist_update_audio_file(const struct osl_row *aft_row) -{ - /* always re-insert to the top of the tree */ - return score_update(aft_row, 0); -} - static int add_playlist_entry(char *path, void *data) { struct playlist_instance *pi = data; @@ -263,13 +250,13 @@ static int handle_audio_file_event(enum afs_events event, void *data) int playlists_event_handler(enum afs_events event, __a_unused struct para_buffer *pb, void *data) { - struct afsi_change_event_data *aced = data; - if (!current_playlist.name) return 1; switch (event) { - case AFSI_CHANGE: - return playlist_update_audio_file(aced->aft_row); + case VSS_NEW_AUDIO_FILE: { /* move the row to the end of the playlist */ + struct afsi_change_event_data *aced = data; + return score_update(aced->aft_row, 0); + } case AUDIO_FILE_RENAME: case AUDIO_FILE_ADD: return handle_audio_file_event(event, data); -- 2.39.5