diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2023-03-17 20:41:59 +0000 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2023-03-24 11:10:12 +0000 |
commit | 1f1893f520719a701d0a88632217c76e744d67bc (patch) | |
tree | bf7642f644fa251b98aae4a9a31d4d7bfd14fc43 | |
parent | ac1cbd5dd020dd0205745a2491958468e8b1f4ad (diff) | |
download | rockbox-1f1893f520.tar.gz rockbox-1f1893f520.zip |
playlist: Remove in-ram filename storage
Use the playlist control file for directory playback instead of
storing filenames in RAM. The implementation of that feature is
very iffy and probably responsible for random crashes that may
occur when skipping through directories rapidly.
Change-Id: I3863940cd4542410d8046a3ca47508b5d97309a1
-rw-r--r-- | apps/playlist.c | 94 | ||||
-rw-r--r-- | apps/playlist.h | 5 |
2 files changed, 18 insertions, 81 deletions
diff --git a/apps/playlist.c b/apps/playlist.c index c3e001986a..6f37f9fb88 100644 --- a/apps/playlist.c +++ b/apps/playlist.c @@ -601,15 +601,13 @@ static void empty_playlist_unlocked(struct playlist_info* playlist, bool resume) playlist->filename[0] = '\0'; - chunk_alloc_free(&playlist->name_chunk_buffer); - playlist->seed = 0; playlist->num_cached = 0; playlist->utf8 = true; playlist->control_created = false; - playlist->in_ram = false; playlist->modified = false; + playlist->dirplay = true; playlist->control_fd = -1; @@ -704,9 +702,9 @@ static void new_playlist_unlocked(struct playlist_info* playlist, { fileused = ""; - /* only the current playlist can be in RAM */ + /* only the current playlist can use dirplay */ if (dirused && playlist == ¤t_playlist) - playlist->in_ram = true; + playlist->dirplay = true; else dirused = ""; /* empty playlist */ } @@ -1252,14 +1250,7 @@ static int get_track_filename(struct playlist_info* playlist, int index, int see } #endif /* HAVE_DIRCACHE */ - if (playlist->in_ram && !control_file && max < 0) - { - char *namebuf = chunk_get_data(&playlist->name_chunk_buffer, seek); - strmemccpy(tmp_buf, namebuf, sizeof(tmp_buf)); - chunk_put_data(&playlist->name_chunk_buffer, namebuf, seek); - NOTEF("%s [in Ram]: 0x%x %s", __func__, seek, tmp_buf); - } - else if (max < 0) + if (max < 0) { playlist_write_lock(playlist); @@ -2064,25 +2055,6 @@ static void dc_thread_playlist(void) #endif /* - * Allocate name chunk buffer header for in-ram playlists - */ -static void alloc_namebuffer(void) -{ -#if MEMORYSIZE >= 16 -# define NAME_CHUNK_SZ (200 << 10) /*200K*/ -#elif MEMORYSIZE >= 8 -# define NAME_CHUNK_SZ (100 << 10) /*100K*/ -#else -# define NAME_CHUNK_SZ (50 << 10) /*50K*/ -#endif - struct playlist_info* playlist = ¤t_playlist; - size_t namebufsz = (AVERAGE_FILENAME_LENGTH * global_settings.max_files_in_dir); - size_t name_chunks = (namebufsz + NAME_CHUNK_SZ - 1) / NAME_CHUNK_SZ; - core_chunk_alloc_init(&playlist->name_chunk_buffer, NAME_CHUNK_SZ, name_chunks); -#undef NAME_CHUNK_SZ -} - -/* * Allocate a temporary buffer for loading playlists */ static int alloc_tempbuf(size_t* buflen) @@ -2181,47 +2153,18 @@ void playlist_shutdown(void) } /* - * Add track to in_ram playlist. Used when playing directories. + * Add track to end of the playlist. Prefer playlist_insert_track(), + * this is DEPRECATED and will be going away at some point. */ int playlist_add(const char *filename) { - size_t indice = CHUNK_ALLOC_INVALID; - struct playlist_info* playlist = ¤t_playlist; - int len = strlen(filename); - - if (!chunk_alloc_is_initialized(&playlist->name_chunk_buffer)) - alloc_namebuffer(); - - if (chunk_alloc_is_initialized(&playlist->name_chunk_buffer)) - indice = chunk_alloc(&playlist->name_chunk_buffer, len + 1); + int ret = playlist_insert_track(NULL, filename, PLAYLIST_INSERT_LAST, + false, true); + if (ret < 0) + return ret; - if(indice == CHUNK_ALLOC_INVALID) - { - - notify_buffer_full(); - return -2; - } - - if(playlist->amount >= playlist->max_playlist_size) - { - notify_buffer_full(); - return -1; - } - - playlist_write_lock(playlist); - - char *namebuf = (char*)chunk_get_data(&playlist->name_chunk_buffer, indice); - strcpy(namebuf, filename); - namebuf[len] = '\0'; - chunk_put_data(&playlist->name_chunk_buffer, namebuf, indice); - - playlist->indices[playlist->amount] = indice; - dc_init_filerefs(playlist, playlist->amount, 1); - - playlist->amount++; - - playlist_write_unlock(playlist); - return 0; + playlist_set_modified(NULL, false); + return ret; } /* returns number of tracks in playlist (includes queued/inserted tracks) */ @@ -2286,8 +2229,6 @@ int playlist_create_ex(struct playlist_info* playlist, #endif } - chunk_alloc_free(&playlist->name_chunk_buffer); - new_playlist_unlocked(playlist, dir, file); /* load the playlist file */ @@ -2344,7 +2285,7 @@ bool playlist_check(int steps) struct playlist_info* playlist = ¤t_playlist; /* always allow folder navigation */ - if (global_settings.next_folder && playlist->in_ram) + if (global_settings.next_folder && playlist->dirplay) return true; int index = get_next_index(playlist, steps, -1); @@ -3125,7 +3066,7 @@ int playlist_next(int steps) playlist->index = 0; index = 0; } - else if (playlist->in_ram && global_settings.next_folder) + else if (playlist->dirplay && global_settings.next_folder) { /* we switch playlists here */ index = create_and_play_dir(steps, true); @@ -3175,7 +3116,7 @@ out: bool playlist_next_dir(int direction) { /* not to mess up real playlists */ - if(!current_playlist.in_ram) + if(!current_playlist.dirplay) return false; return create_and_play_dir(direction, false) >= 0; @@ -3208,7 +3149,7 @@ const char* playlist_peek(int steps, char* buf, size_t buf_size) temp_ptr = buf; - if (!playlist->in_ram || control_file) + if (!playlist->dirplay || control_file) { /* remove bogus dirs from beginning of path (workaround for buggy playlist creation tools) */ @@ -3442,8 +3383,7 @@ int playlist_resume(void) } else if (str2[0] != '\0') { - playlist->in_ram = true; - resume_directory(str2); + playlist->dirplay = true; } /* load the rest of the data */ diff --git a/apps/playlist.h b/apps/playlist.h index cb79eea96c..bdc2684c18 100644 --- a/apps/playlist.h +++ b/apps/playlist.h @@ -74,17 +74,14 @@ struct playlist_info { bool utf8; /* playlist is in .m3u8 format */ bool control_created; /* has control file been created? */ - bool in_ram; /* playlist stored in ram (dirplay) */ bool modified; /* has playlist been modified by the user? */ + bool dirplay; /* are we playing a directory directly? */ int fd; /* descriptor of the open playlist file */ int control_fd; /* descriptor of the open control file */ int max_playlist_size; /* Max number of files in playlist. Mirror of global_settings.max_files_in_playlist */ unsigned long *indices; /* array of indices */ - struct chunk_alloc_header name_chunk_buffer; /* chunk buffer for - in-ram playlist */ - int index; /* index of current playing track */ int first_index; /* index of first song in playlist */ int amount; /* number of tracks in the index */ |