From 8be9c49fcd8b23463199036eda5fc290ded6d078 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 25 Aug 2013 20:40:21 +0200 Subject: core: add a playlist demuxer Modeled after the old playlist_parser.c, but actually new code, and it works a bit differently. Demuxers (and sometimes streams) are the component that should be used to open files and to determine the file format. This was already done for subtitles, but playlists still use a separate code path. --- mpvcore/mplayer.c | 45 ++++++++++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 13 deletions(-) (limited to 'mpvcore/mplayer.c') diff --git a/mpvcore/mplayer.c b/mpvcore/mplayer.c index 2d5265d41b..43a7b5d9b0 100644 --- a/mpvcore/mplayer.c +++ b/mpvcore/mplayer.c @@ -4133,6 +4133,19 @@ static void stream_dump(struct MPContext *mpctx) } } +// Replace the current playlist entry with playlist contents. Moves the entries +// from the given playlist pl, so the entries don't actually need to be copied. +static void transfer_playlist(struct MPContext *mpctx, struct playlist *pl) +{ + if (mpctx->demuxer->playlist->first) { + playlist_transfer_entries(mpctx->playlist, mpctx->demuxer->playlist); + if (mpctx->playlist->current) + playlist_remove(mpctx->playlist, mpctx->playlist->current); + } else { + MP_WARN(mpctx, "Empty playlist!\n"); + } +} + // Start playing the current playlist entry. // Handle initialization and deinitialization. static void play_current_file(struct MPContext *mpctx) @@ -4213,11 +4226,7 @@ static void play_current_file(struct MPContext *mpctx) mpctx->resolve_result = resolve_url(stream_filename, opts); if (mpctx->resolve_result) { if (mpctx->resolve_result->playlist) { - // Replace entry with playlist contents - playlist_transfer_entries(mpctx->playlist, - mpctx->resolve_result->playlist); - if (mpctx->playlist->current) - playlist_remove(mpctx->playlist, mpctx->playlist->current); + transfer_playlist(mpctx, mpctx->resolve_result->playlist); goto terminate_playback; } stream_filename = mpctx->resolve_result->url; @@ -4258,12 +4267,29 @@ goto_reopen_demuxer: ; mpctx->demuxer = demux_open(mpctx->stream, opts->demuxer_name, NULL, opts); mpctx->master_demuxer = mpctx->demuxer; - if (!mpctx->demuxer) { mp_tmsg(MSGT_CPLAYER, MSGL_ERR, "Failed to recognize file format.\n"); goto terminate_playback; } + MP_TARRAY_APPEND(NULL, mpctx->sources, mpctx->num_sources, mpctx->demuxer); + + mpctx->initialized_flags |= INITIALIZED_DEMUXER; + + if (mpctx->demuxer->playlist) { + if (mpctx->demuxer->stream->safe_origin || opts->load_unsafe_playlists) { + transfer_playlist(mpctx, mpctx->demuxer->playlist); + } else { + MP_ERR(mpctx, "\nThis looks like a playlist, but playlist support " + "will not be used automatically.\nThe main problem with " + "playlist safety is that playlist entries can be arbitrary,\n" + "and an attacker could make mpv poke around in your local " + "filesystem or network.\nUse --playlist=file or the " + "--load-unsafe-playlists option to load them anyway.\n"); + } + goto terminate_playback; + } + if (mpctx->demuxer->matroska_data.ordered_chapters) build_ordered_chapter_timeline(mpctx); @@ -4275,11 +4301,6 @@ goto_reopen_demuxer: ; print_timeline(mpctx); - if (!mpctx->num_sources) { - MP_TARRAY_APPEND(NULL, mpctx->sources, mpctx->num_sources, - mpctx->demuxer); - } - if (mpctx->timeline) { // With Matroska, the "master" file usually dictates track layout etc. // On the contrary, the EDL and CUE demuxers are empty wrappers, as @@ -4298,8 +4319,6 @@ goto_reopen_demuxer: ; if (mpctx->timeline) timeline_set_part(mpctx, mpctx->timeline_part, true); - mpctx->initialized_flags |= INITIALIZED_DEMUXER; - add_subtitle_fonts_from_sources(mpctx); open_subtitles_from_options(mpctx); -- cgit v1.2.3