···175175#define PLAYLIST_SKIPPED 0x10000000
176176177177static struct playlist_info current_playlist;
178178+static struct playlist_info on_disk_playlist;
179179+178180/* REPEAT_ONE support function from playback.c */
179181extern bool audio_pending_track_skip_is_manual(void);
180182static inline bool is_manual_skip(void)
···19411943{
19421944 int handle;
19431945 struct playlist_info* playlist = ¤t_playlist;
19441944- mutex_init(&playlist->mutex);
19461946+ mutex_init(¤t_playlist.mutex);
19471947+ mutex_init(&on_disk_playlist.mutex);
1945194819461949 strmemccpy(playlist->control_filename, PLAYLIST_CONTROL_FILE,
19471950 sizeof(playlist->control_filename));
···20052008 return playlist_amount_ex(NULL);
20062009}
2007201020112011+/* Return desired index buffer size for loading a playlist from disk,
20122012+ * as determined by the user's 'max files in playlist' setting.
20132013+ *
20142014+ * Buffer size is constrained by given max_sz.
20152015+ */
20162016+size_t playlist_get_index_bufsz(size_t max_sz)
20172017+{
20182018+ size_t index_buffer_size = (global_settings.max_files_in_playlist *
20192019+ sizeof(*on_disk_playlist.indices));
20202020+20212021+ return index_buffer_size > max_sz ? max_sz : index_buffer_size;
20222022+}
20232023+20082024/*
20092009- * Create a new playlist If playlist is not NULL then we're loading a
20102010- * playlist off disk for viewing/editing. The index_buffer is used to store
20112011- * playlist indices (required for and only used if !current playlist). The
20122012- * temp_buffer (if not NULL) is used as a scratchpad when loading indices.
20252025+ * Load a playlist off disk for viewing/editing.
20262026+ * Make sure to close a previously loaded playlist before calling this again!
20132027 *
20142014- * XXX: This is really only usable by the playlist viewer. Never pass
20152015- * playlist == NULL, that cannot and will not work.
20282028+ * The index_buffer is used to store playlist indices. If no index buffer is
20292029+ * provided, the current playlist's index buffer is shared.
20302030+ * FIXME: When using the shared buffer, you must ensure that playback is
20312031+ * stopped and that no other playlist will be started while this
20322032+ * one is loaded.
20332033+ *
20342034+ * The temp_buffer (if not NULL) is used as a scratchpad when loading indices.
20162035 */
20172017-int playlist_create_ex(struct playlist_info* playlist,
20182018- const char* dir, const char* file,
20192019- void* index_buffer, int index_buffer_size,
20202020- void* temp_buffer, int temp_buffer_size)
20362036+struct playlist_info* playlist_load(const char* dir, const char* file,
20372037+ void* index_buffer, int index_buffer_size,
20382038+ void* temp_buffer, int temp_buffer_size)
20212039{
20402040+ struct playlist_info* playlist = &on_disk_playlist;
20412041+20222042 /* Initialize playlist structure */
20232043 int r = rand() % 10;
20242044···20572077 if (file)
20582078 add_indices_to_playlist(playlist, temp_buffer, temp_buffer_size);
2059207920602060- return 0;
20802080+ return playlist;
20612081}
2062208220632083/*
20642064- * Create new playlist
20842084+ * Create new (current) playlist
20652085 */
20662086int playlist_create(const char *dir, const char *file)
20672087{
+4-4
apps/playlist.h
···141141142142/* Exported functions for all playlists. Pass NULL for playlist_info
143143 structure to work with current playlist. */
144144-int playlist_create_ex(struct playlist_info* playlist,
145145- const char* dir, const char* file,
146146- void* index_buffer, int index_buffer_size,
147147- void* temp_buffer, int temp_buffer_size);
144144+size_t playlist_get_index_bufsz(size_t max_sz);
145145+struct playlist_info* playlist_load(const char* dir, const char* file,
146146+ void* index_buffer, int index_buffer_size,
147147+ void* temp_buffer, int temp_buffer_size);
148148int playlist_set_current(struct playlist_info* playlist);
149149void playlist_close(struct playlist_info* playlist);
150150void playlist_sync(struct playlist_info* playlist);