diff options
author | Christian Soffke <christian.soffke@gmail.com> | 2024-11-19 08:08:06 +0100 |
---|---|---|
committer | Christian Soffke <christian.soffke@gmail.com> | 2024-11-23 09:05:39 -0500 |
commit | 46a4361bf17c8ba7eea7cb598f54ee51528404a0 (patch) | |
tree | 4152e7dc97cba2da772de6b57ff77322c14d49aa | |
parent | 2591f6ad0210835d0ed6e7fd067ff6362eb9af0e (diff) | |
download | rockbox-46a4361bf1.tar.gz rockbox-46a4361bf1.zip |
playlist viewer: move on-disk playlist struct to playlist.c
Change-Id: I40281142f2fa930f0c68b9612c12fca14885ac37
-rw-r--r-- | apps/playlist.c | 46 | ||||
-rw-r--r-- | apps/playlist.h | 8 | ||||
-rw-r--r-- | apps/playlist_viewer.c | 44 |
3 files changed, 48 insertions, 50 deletions
diff --git a/apps/playlist.c b/apps/playlist.c index fe22335210..fa4ec6bd68 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -175,6 +175,8 @@ #define PLAYLIST_SKIPPED 0x10000000 static struct playlist_info current_playlist; +static struct playlist_info on_disk_playlist; + /* REPEAT_ONE support function from playback.c */ extern bool audio_pending_track_skip_is_manual(void); static inline bool is_manual_skip(void) @@ -1941,7 +1943,8 @@ void playlist_init(void) { int handle; struct playlist_info* playlist = ¤t_playlist; - mutex_init(&playlist->mutex); + mutex_init(¤t_playlist.mutex); + mutex_init(&on_disk_playlist.mutex); strmemccpy(playlist->control_filename, PLAYLIST_CONTROL_FILE, sizeof(playlist->control_filename)); @@ -2005,20 +2008,37 @@ int playlist_amount(void) return playlist_amount_ex(NULL); } +/* Return desired index buffer size for loading a playlist from disk, + * as determined by the user's 'max files in playlist' setting. + * + * Buffer size is constrained by given max_sz. + */ +size_t playlist_get_index_bufsz(size_t max_sz) +{ + size_t index_buffer_size = (global_settings.max_files_in_playlist * + sizeof(*on_disk_playlist.indices)); + + return index_buffer_size > max_sz ? max_sz : index_buffer_size; +} + /* - * Create a new playlist If playlist is not NULL then we're loading a - * playlist off disk for viewing/editing. The index_buffer is used to store - * playlist indices (required for and only used if !current playlist). The - * temp_buffer (if not NULL) is used as a scratchpad when loading indices. + * Load a playlist off disk for viewing/editing. + * Make sure to close a previously loaded playlist before calling this again! + * + * The index_buffer is used to store playlist indices. If no index buffer is + * provided, the current playlist's index buffer is shared. + * FIXME: When using the shared buffer, you must ensure that playback is + * stopped and that no other playlist will be started while this + * one is loaded. * - * XXX: This is really only usable by the playlist viewer. Never pass - * playlist == NULL, that cannot and will not work. + * The temp_buffer (if not NULL) is used as a scratchpad when loading indices. */ -int playlist_create_ex(struct playlist_info* playlist, - const char* dir, const char* file, - void* index_buffer, int index_buffer_size, - void* temp_buffer, int temp_buffer_size) +struct playlist_info* playlist_load(const char* dir, const char* file, + void* index_buffer, int index_buffer_size, + void* temp_buffer, int temp_buffer_size) { + struct playlist_info* playlist = &on_disk_playlist; + /* Initialize playlist structure */ int r = rand() % 10; @@ -2057,11 +2077,11 @@ int playlist_create_ex(struct playlist_info* playlist, if (file) add_indices_to_playlist(playlist, temp_buffer, temp_buffer_size); - return 0; + return playlist; } /* - * Create new playlist + * Create new (current) playlist */ int playlist_create(const char *dir, const char *file) { diff --git a/apps/playlist.h b/apps/playlist.h index 9b8c1da424..d9b4834bd9 100644 --- a/apps/playlist.h +++ b/apps/playlist.h @@ -141,10 +141,10 @@ bool playlist_dynamic_only(void); /* Exported functions for all playlists. Pass NULL for playlist_info structure to work with current playlist. */ -int playlist_create_ex(struct playlist_info* playlist, - const char* dir, const char* file, - void* index_buffer, int index_buffer_size, - void* temp_buffer, int temp_buffer_size); +size_t playlist_get_index_bufsz(size_t max_sz); +struct playlist_info* playlist_load(const char* dir, const char* file, + void* index_buffer, int index_buffer_size, + void* temp_buffer, int temp_buffer_size); int playlist_set_current(struct playlist_info* playlist); void playlist_close(struct playlist_info* playlist); void playlist_sync(struct playlist_info* playlist); diff --git a/apps/playlist_viewer.c b/apps/playlist_viewer.c index 14391a96bb..c3c6f6fa29 100644 --- a/apps/playlist_viewer.c +++ b/apps/playlist_viewer.c @@ -125,10 +125,6 @@ struct playlist_search_data static struct playlist_viewer viewer; -/* Used when viewing playlists on disk */ -static struct playlist_info temp_playlist; -static bool temp_playlist_init = false; - static void playlist_buffer_init(struct playlist_buffer *pb, char *names_buffer, int names_buffer_size) { @@ -367,8 +363,8 @@ static bool playlist_viewer_init(struct playlist_viewer * viewer, const char* filename, bool reload, int *most_recent_selection) { - char* buffer; - size_t buffer_size; + char *buffer, *index_buffer = NULL; + size_t buffer_size, index_buffer_size = 0; bool is_playing = audio_status() & (AUDIO_STATUS_PLAY | AUDIO_STATUS_PAUSE); bool have_list = filename || is_playing; if (!have_list && (global_status.resume_index != -1)) @@ -390,7 +386,7 @@ static bool playlist_viewer_init(struct playlist_viewer * viewer, } buffer = plugin_get_buffer(&buffer_size); - if (!buffer) + if (!buffer || buffer_size <= MAX_PATH) return false; if (!filename) @@ -403,18 +399,6 @@ static bool playlist_viewer_init(struct playlist_viewer * viewer, /* Viewing playlist on disk */ const char *dir, *file; char *temp_ptr; - char *index_buffer = NULL; - ssize_t index_buffer_size = 0; - - /* Initialize temp playlist - * TODO - move this to playlist.c */ - if (!temp_playlist_init) - { - mutex_init(&temp_playlist.mutex); - temp_playlist_init = true; - } - - viewer->playlist = &temp_playlist; /* Separate directory from filename */ temp_ptr = strrchr(filename+1,'/'); @@ -433,26 +417,20 @@ static bool playlist_viewer_init(struct playlist_viewer * viewer, if (is_playing) { - /* Something is playing, try to accommodate - * global_settings.max_files_in_playlist entries */ - index_buffer_size = (global_settings.max_files_in_playlist * - sizeof(*viewer->playlist->indices)); - - if ((unsigned)index_buffer_size >= buffer_size - MAX_PATH) - index_buffer_size = buffer_size - (MAX_PATH + 1); - index_buffer = buffer; + index_buffer_size = playlist_get_index_bufsz(buffer_size - (MAX_PATH + 1)); + + buffer += index_buffer_size; + buffer_size -= index_buffer_size; } - playlist_create_ex(viewer->playlist, dir, file, index_buffer, - index_buffer_size, buffer+index_buffer_size, - buffer_size-index_buffer_size); + viewer->playlist = playlist_load(dir, file, + index_buffer, index_buffer_size, + buffer, buffer_size); + /* Merge separated dir and filename again */ if (temp_ptr) *temp_ptr = '/'; - - buffer += index_buffer_size; - buffer_size -= index_buffer_size; } playlist_buffer_init(&viewer->buffer, buffer, buffer_size); |