diff options
author | wm4 <wm4@nowhere> | 2019-12-28 21:12:02 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2019-12-28 21:32:15 +0100 |
commit | 582f3f7cc01f81345df5c20a012b1f47587e6a97 (patch) | |
tree | 03ddce6c9cc0e5aa48135b5af45a57ec37150355 /common/playlist.h | |
parent | 4564a22d13b693efed847ba77361ea4e2448a7bf (diff) | |
download | mpv-582f3f7cc01f81345df5c20a012b1f47587e6a97.tar.bz2 mpv-582f3f7cc01f81345df5c20a012b1f47587e6a97.tar.xz |
playlist: change from linked list to an array
Although a linked list was ideal at first, there are cases where it
sucks, and became increasingly awkward (with the mpv command API
preferring integer indexes to access the list). In future, we probably
want to add more playlist-related functionality, so better change it to
an array now.
An array isn't always ideal either. Since playlist entries are still
separate objects (because in some cases you need a stable "iterator" to
it), but you still need to efficiently get the next/previous playlist
entry, there's a pl_index field, that needs to be maintained. E.g.
adding an entry at the start of the playlist => update the pl_index
field for all other entries. Well, it's not really worth to do something
more complicated to avoid these things.
This commit is probably buggy as shit. It's not like I bothered to test
everything. That's _your_ role.
Diffstat (limited to 'common/playlist.h')
-rw-r--r-- | common/playlist.h | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/common/playlist.h b/common/playlist.h index bbf6821428..d0f17e315f 100644 --- a/common/playlist.h +++ b/common/playlist.h @@ -26,8 +26,9 @@ struct playlist_param { }; struct playlist_entry { - struct playlist_entry *prev, *next; + // Invariant: (pl && pl->entries[pl_index] == this) || (!pl && pl_index < 0) struct playlist *pl; + int pl_index; char *filename; @@ -59,7 +60,8 @@ struct playlist_entry { }; struct playlist { - struct playlist_entry *first, *last; + struct playlist_entry **entries; + int num_entries; // This provides some sort of stable iterator. If this entry is removed from // the playlist, current is set to the next element (or NULL), and @@ -75,20 +77,24 @@ void playlist_entry_add_params(struct playlist_entry *e, struct playlist_entry *playlist_entry_new(const char *filename); -void playlist_insert(struct playlist *pl, struct playlist_entry *after, - struct playlist_entry *add); void playlist_add(struct playlist *pl, struct playlist_entry *add); void playlist_remove(struct playlist *pl, struct playlist_entry *entry); void playlist_clear(struct playlist *pl); +void playlist_clear_except_current(struct playlist *pl); void playlist_move(struct playlist *pl, struct playlist_entry *entry, struct playlist_entry *at); void playlist_add_file(struct playlist *pl, const char *filename); void playlist_shuffle(struct playlist *pl); +struct playlist_entry *playlist_get_first(struct playlist *pl); +struct playlist_entry *playlist_get_last(struct playlist *pl); struct playlist_entry *playlist_get_next(struct playlist *pl, int direction); +struct playlist_entry *playlist_entry_get_rel(struct playlist_entry *e, + int direction); void playlist_add_base_path(struct playlist *pl, bstr base_path); void playlist_add_redirect(struct playlist *pl, const char *redirected_from); +void playlist_set_stream_flags(struct playlist *pl, int flags); void playlist_transfer_entries(struct playlist *pl, struct playlist *source_pl); void playlist_append_entries(struct playlist *pl, struct playlist *source_pl); |