Playlist Viewer Fix FS#13197

While playing a track the playlist viewer may not
have a big enough temporary buffer to load and display
'max_files_in_playlist' entries

This patch attempts to load as many entries as possible

If tracks were already playing (dynamic playlist or otherwise)
The original code only gave half the plugin buffer to a playlist
loaded from file

On some targets half the plugin buffer is not enough to load all entries…

Now we attempt to get as many entries possible while at least leaving a
small buffer (MAX_PATH) for the name buffer

Change-Id: Ic06eaabc4e2550f076d625957d6d073790852743
This commit is contained in:
William Wilgus 2020-05-19 01:20:39 -05:00
parent 0c3380f9ef
commit 776ceae119
3 changed files with 32 additions and 8 deletions

View file

@ -2887,11 +2887,8 @@ int playlist_create_ex(struct playlist_info* playlist,
if (index_buffer)
{
size_t unit_size = sizeof (*playlist->indices);
#ifdef HAVE_DIRCACHE
unit_size += sizeof (*playlist->dcfrefs);
#endif
int num_indices = index_buffer_size / unit_size;
int num_indices = index_buffer_size /
playlist_get_required_bufsz(playlist, false, 1);
if (num_indices > global_settings.max_files_in_playlist)
num_indices = global_settings.max_files_in_playlist;
@ -3525,6 +3522,26 @@ char *playlist_get_name(const struct playlist_info* playlist, char *buf,
return buf;
}
/* return size of buffer needed for playlist to initialize num_indices entries */
size_t playlist_get_required_bufsz(struct playlist_info* playlist,
bool include_namebuf,
int num_indices)
{
size_t namebuf = 0;
if (!playlist)
playlist = &current_playlist;
size_t unit_size = sizeof (*playlist->indices);
#ifdef HAVE_DIRCACHE
unit_size += sizeof (*playlist->dcfrefs);
#endif
if (include_namebuf)
namebuf = AVERAGE_FILENAME_LENGTH * global_settings.max_files_in_dir;
return (num_indices * unit_size) + namebuf;
}
/* Fills info structure with information about track at specified index.
Returns 0 on success and -1 on failure */
int playlist_get_track_info(struct playlist_info* playlist, int index,

View file

@ -181,6 +181,8 @@ char *playlist_name(const struct playlist_info* playlist, char *buf,
int buf_size);
char *playlist_get_name(const struct playlist_info* playlist, char *buf,
int buf_size);
size_t playlist_get_required_bufsz(struct playlist_info* playlist,
bool include_namebuf, int num_indices);
int playlist_get_track_info(struct playlist_info* playlist, int index,
struct playlist_track_info* info);
int playlist_save(struct playlist_info* playlist, char *filename,

View file

@ -362,9 +362,14 @@ static bool playlist_viewer_init(struct playlist_viewer * viewer,
if (is_playing)
{
/* Something is playing, use half the plugin buffer for playlist
indices */
index_buffer_size = buffer_size / 2;
/* Something is playing, try to accommodate
* global_settings.max_files_in_playlist entries */
index_buffer_size = playlist_get_required_bufsz(viewer->playlist,
false, global_settings.max_files_in_playlist);
if ((unsigned)index_buffer_size >= buffer_size - MAX_PATH)
index_buffer_size = buffer_size - (MAX_PATH + 1);
index_buffer = buffer;
}