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 /demux | |
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 'demux')
-rw-r--r-- | demux/demux_libarchive.c | 3 | ||||
-rw-r--r-- | demux/demux_mkv_timeline.c | 6 | ||||
-rw-r--r-- | demux/demux_playlist.c | 3 |
3 files changed, 6 insertions, 6 deletions
diff --git a/demux/demux_libarchive.c b/demux/demux_libarchive.c index f2e669aa72..b038e149d9 100644 --- a/demux/demux_libarchive.c +++ b/demux/demux_libarchive.c @@ -82,8 +82,7 @@ static int open_file(struct demuxer *demuxer, enum demux_check check) for (int n = 0; n < num_files; n++) playlist_add_file(pl, files[n]); - for (struct playlist_entry *e = pl->first; e; e = e->next) - e->stream_flags = demuxer->stream_origin; + playlist_set_stream_flags(pl, demuxer->stream_origin); demuxer->filetype = "archive"; demuxer->fully_read = true; diff --git a/demux/demux_mkv_timeline.c b/demux/demux_mkv_timeline.c index 22d859c75c..1062aa3685 100644 --- a/demux/demux_mkv_timeline.c +++ b/demux/demux_mkv_timeline.c @@ -258,8 +258,10 @@ static void find_ordered_chapter_sources(struct tl_ctx *ctx) playlist_parse_file(opts->ordered_chapters_files, ctx->tl->cancel, ctx->global); talloc_steal(tmp, pl); - for (struct playlist_entry *e = pl ? pl->first : NULL; e; e = e->next) - MP_TARRAY_APPEND(tmp, filenames, num_filenames, e->filename); + for (int n = 0; n < pl->num_entries; n++) { + MP_TARRAY_APPEND(tmp, filenames, num_filenames, + pl->entries[n]->filename); + } } else if (!ctx->demuxer->stream->is_local_file) { MP_WARN(ctx, "Playback source is not a " "normal disk file. Will not search for related files.\n"); diff --git a/demux/demux_playlist.c b/demux/demux_playlist.c index b40beda980..417642e75a 100644 --- a/demux/demux_playlist.c +++ b/demux/demux_playlist.c @@ -462,8 +462,7 @@ static int open_file(struct demuxer *demuxer, enum demux_check check) bool ok = fmt->parse(p) >= 0 && !p->error; if (p->add_base) playlist_add_base_path(p->pl, mp_dirname(demuxer->filename)); - for (struct playlist_entry *e = p->pl->first; e; e = e->next) - e->stream_flags = demuxer->stream_origin; + playlist_set_stream_flags(p->pl, demuxer->stream_origin); demuxer->playlist = talloc_steal(demuxer, p->pl); demuxer->filetype = p->format ? p->format : fmt->name; demuxer->fully_read = true; |