Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

playlist viewer: move on-disk playlist struct to playlist.c

Change-Id: I40281142f2fa930f0c68b9612c12fca14885ac37

+48 -50
+33 -13
apps/playlist.c
··· 175 175 #define PLAYLIST_SKIPPED 0x10000000 176 176 177 177 static struct playlist_info current_playlist; 178 + static struct playlist_info on_disk_playlist; 179 + 178 180 /* REPEAT_ONE support function from playback.c */ 179 181 extern bool audio_pending_track_skip_is_manual(void); 180 182 static inline bool is_manual_skip(void) ··· 1941 1943 { 1942 1944 int handle; 1943 1945 struct playlist_info* playlist = &current_playlist; 1944 - mutex_init(&playlist->mutex); 1946 + mutex_init(&current_playlist.mutex); 1947 + mutex_init(&on_disk_playlist.mutex); 1945 1948 1946 1949 strmemccpy(playlist->control_filename, PLAYLIST_CONTROL_FILE, 1947 1950 sizeof(playlist->control_filename)); ··· 2005 2008 return playlist_amount_ex(NULL); 2006 2009 } 2007 2010 2011 + /* Return desired index buffer size for loading a playlist from disk, 2012 + * as determined by the user's 'max files in playlist' setting. 2013 + * 2014 + * Buffer size is constrained by given max_sz. 2015 + */ 2016 + size_t playlist_get_index_bufsz(size_t max_sz) 2017 + { 2018 + size_t index_buffer_size = (global_settings.max_files_in_playlist * 2019 + sizeof(*on_disk_playlist.indices)); 2020 + 2021 + return index_buffer_size > max_sz ? max_sz : index_buffer_size; 2022 + } 2023 + 2008 2024 /* 2009 - * Create a new playlist If playlist is not NULL then we're loading a 2010 - * playlist off disk for viewing/editing. The index_buffer is used to store 2011 - * playlist indices (required for and only used if !current playlist). The 2012 - * temp_buffer (if not NULL) is used as a scratchpad when loading indices. 2025 + * Load a playlist off disk for viewing/editing. 2026 + * Make sure to close a previously loaded playlist before calling this again! 2013 2027 * 2014 - * XXX: This is really only usable by the playlist viewer. Never pass 2015 - * playlist == NULL, that cannot and will not work. 2028 + * The index_buffer is used to store playlist indices. If no index buffer is 2029 + * provided, the current playlist's index buffer is shared. 2030 + * FIXME: When using the shared buffer, you must ensure that playback is 2031 + * stopped and that no other playlist will be started while this 2032 + * one is loaded. 2033 + * 2034 + * The temp_buffer (if not NULL) is used as a scratchpad when loading indices. 2016 2035 */ 2017 - int playlist_create_ex(struct playlist_info* playlist, 2018 - const char* dir, const char* file, 2019 - void* index_buffer, int index_buffer_size, 2020 - void* temp_buffer, int temp_buffer_size) 2036 + struct playlist_info* playlist_load(const char* dir, const char* file, 2037 + void* index_buffer, int index_buffer_size, 2038 + void* temp_buffer, int temp_buffer_size) 2021 2039 { 2040 + struct playlist_info* playlist = &on_disk_playlist; 2041 + 2022 2042 /* Initialize playlist structure */ 2023 2043 int r = rand() % 10; 2024 2044 ··· 2057 2077 if (file) 2058 2078 add_indices_to_playlist(playlist, temp_buffer, temp_buffer_size); 2059 2079 2060 - return 0; 2080 + return playlist; 2061 2081 } 2062 2082 2063 2083 /* 2064 - * Create new playlist 2084 + * Create new (current) playlist 2065 2085 */ 2066 2086 int playlist_create(const char *dir, const char *file) 2067 2087 {
+4 -4
apps/playlist.h
··· 141 141 142 142 /* Exported functions for all playlists. Pass NULL for playlist_info 143 143 structure to work with current playlist. */ 144 - int playlist_create_ex(struct playlist_info* playlist, 145 - const char* dir, const char* file, 146 - void* index_buffer, int index_buffer_size, 147 - void* temp_buffer, int temp_buffer_size); 144 + size_t playlist_get_index_bufsz(size_t max_sz); 145 + struct playlist_info* playlist_load(const char* dir, const char* file, 146 + void* index_buffer, int index_buffer_size, 147 + void* temp_buffer, int temp_buffer_size); 148 148 int playlist_set_current(struct playlist_info* playlist); 149 149 void playlist_close(struct playlist_info* playlist); 150 150 void playlist_sync(struct playlist_info* playlist);
+11 -33
apps/playlist_viewer.c
··· 125 125 126 126 static struct playlist_viewer viewer; 127 127 128 - /* Used when viewing playlists on disk */ 129 - static struct playlist_info temp_playlist; 130 - static bool temp_playlist_init = false; 131 - 132 128 static void playlist_buffer_init(struct playlist_buffer *pb, char *names_buffer, 133 129 int names_buffer_size) 134 130 { ··· 367 363 const char* filename, bool reload, 368 364 int *most_recent_selection) 369 365 { 370 - char* buffer; 371 - size_t buffer_size; 366 + char *buffer, *index_buffer = NULL; 367 + size_t buffer_size, index_buffer_size = 0; 372 368 bool is_playing = audio_status() & (AUDIO_STATUS_PLAY | AUDIO_STATUS_PAUSE); 373 369 bool have_list = filename || is_playing; 374 370 if (!have_list && (global_status.resume_index != -1)) ··· 390 386 } 391 387 392 388 buffer = plugin_get_buffer(&buffer_size); 393 - if (!buffer) 389 + if (!buffer || buffer_size <= MAX_PATH) 394 390 return false; 395 391 396 392 if (!filename) ··· 403 399 /* Viewing playlist on disk */ 404 400 const char *dir, *file; 405 401 char *temp_ptr; 406 - char *index_buffer = NULL; 407 - ssize_t index_buffer_size = 0; 408 - 409 - /* Initialize temp playlist 410 - * TODO - move this to playlist.c */ 411 - if (!temp_playlist_init) 412 - { 413 - mutex_init(&temp_playlist.mutex); 414 - temp_playlist_init = true; 415 - } 416 - 417 - viewer->playlist = &temp_playlist; 418 402 419 403 /* Separate directory from filename */ 420 404 temp_ptr = strrchr(filename+1,'/'); ··· 433 417 434 418 if (is_playing) 435 419 { 436 - /* Something is playing, try to accommodate 437 - * global_settings.max_files_in_playlist entries */ 438 - index_buffer_size = (global_settings.max_files_in_playlist * 439 - sizeof(*viewer->playlist->indices)); 440 - 441 - if ((unsigned)index_buffer_size >= buffer_size - MAX_PATH) 442 - index_buffer_size = buffer_size - (MAX_PATH + 1); 420 + index_buffer = buffer; 421 + index_buffer_size = playlist_get_index_bufsz(buffer_size - (MAX_PATH + 1)); 443 422 444 - index_buffer = buffer; 423 + buffer += index_buffer_size; 424 + buffer_size -= index_buffer_size; 445 425 } 446 426 447 - playlist_create_ex(viewer->playlist, dir, file, index_buffer, 448 - index_buffer_size, buffer+index_buffer_size, 449 - buffer_size-index_buffer_size); 427 + viewer->playlist = playlist_load(dir, file, 428 + index_buffer, index_buffer_size, 429 + buffer, buffer_size); 450 430 431 + /* Merge separated dir and filename again */ 451 432 if (temp_ptr) 452 433 *temp_ptr = '/'; 453 - 454 - buffer += index_buffer_size; 455 - buffer_size -= index_buffer_size; 456 434 } 457 435 playlist_buffer_init(&viewer->buffer, buffer, buffer_size); 458 436