summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Wilgus <me.theuser@yahoo.com>2020-05-19 01:20:39 -0500
committerWilliam Wilgus <me.theuser@yahoo.com>2020-05-20 18:41:58 +0200
commit776ceae1198207e639408a8d0fa404f6a1ff7976 (patch)
treec5bde6aa64994e603bebe5c4709937d409c0fd7a
parent0c3380f9efbbcfc3dfdb2551fa51458f7edc5a5c (diff)
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
-rw-r--r--apps/playlist.c27
-rw-r--r--apps/playlist.h2
-rw-r--r--apps/playlist_viewer.c11
3 files changed, 32 insertions, 8 deletions
diff --git a/apps/playlist.c b/apps/playlist.c
index 0b5662b47c..2bdc1f39cc 100644
--- a/apps/playlist.c
+++ b/apps/playlist.c
@@ -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,
diff --git a/apps/playlist.h b/apps/playlist.h
index 6048001ff7..220a577fb2 100644
--- a/apps/playlist.h
+++ b/apps/playlist.h
@@ -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,
diff --git a/apps/playlist_viewer.c b/apps/playlist_viewer.c
index 54451992a7..751f1e21a7 100644
--- a/apps/playlist_viewer.c
+++ b/apps/playlist_viewer.c
@@ -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;
}