1
0
Fork 0
forked from len0rd/rockbox

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

Change-Id: I40281142f2fa930f0c68b9612c12fca14885ac37
This commit is contained in:
Christian Soffke 2024-11-19 08:08:06 +01:00
parent 2591f6ad02
commit 46a4361bf1
3 changed files with 49 additions and 51 deletions

View file

@ -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 = &current_playlist;
mutex_init(&playlist->mutex);
mutex_init(&current_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);
}
/*
* 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.
/* Return desired index buffer size for loading a playlist from disk,
* as determined by the user's 'max files in playlist' setting.
*
* XXX: This is really only usable by the playlist viewer. Never pass
* playlist == NULL, that cannot and will not work.
* Buffer size is constrained by given max_sz.
*/
int playlist_create_ex(struct playlist_info* playlist,
const char* dir, const char* file,
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;
}
/*
* 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.
*
* The temp_buffer (if not NULL) is used as a scratchpad when loading indices.
*/
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)
{

View file

@ -141,8 +141,8 @@ 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,
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);

View file

@ -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,27 +417,21 @@ 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;
}
playlist_create_ex(viewer->playlist, dir, file, index_buffer,
index_buffer_size, buffer+index_buffer_size,
buffer_size-index_buffer_size);
if (temp_ptr)
*temp_ptr = '/';
index_buffer_size = playlist_get_index_bufsz(buffer_size - (MAX_PATH + 1));
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 = '/';
}
playlist_buffer_init(&viewer->buffer, buffer, buffer_size);
viewer->moving_track = -1;