From 899dfa957f23bc92c2fa54bda9b856435639fd8c Mon Sep 17 00:00:00 2001 From: wm4 Date: Thu, 2 Jul 2015 14:02:32 +0200 Subject: [PATCH] player: unentangle --stream-dump The final goal is making opening the demuxer and opening the stream the same operation. Stream dumping is a rather uninteresting feature, but has a small number of vocal users, and it's easy to keep. --- player/core.h | 2 +- player/loadfile.c | 12 ++++++------ player/misc.c | 13 ++++++++----- 3 files changed, 15 insertions(+), 12 deletions(-) diff --git a/player/core.h b/player/core.h index b3e8018b12..06d3a29734 100644 --- a/player/core.h +++ b/player/core.h @@ -425,7 +425,7 @@ float mp_get_cache_percent(struct MPContext *mpctx); bool mp_get_cache_idle(struct MPContext *mpctx); void update_window_title(struct MPContext *mpctx, bool force); void error_on_track(struct MPContext *mpctx, struct track *track); -void stream_dump(struct MPContext *mpctx); +int stream_dump(struct MPContext *mpctx, const char *source_filename); int mpctx_run_reentrant(struct MPContext *mpctx, void (*thread_fn)(void *arg), void *thread_arg); struct mpv_global *create_sub_global(struct MPContext *mpctx); diff --git a/player/loadfile.c b/player/loadfile.c index 3f753d1dfd..976e729287 100644 --- a/player/loadfile.c +++ b/player/loadfile.c @@ -1079,6 +1079,12 @@ static void play_current_file(struct MPContext *mpctx) if (process_open_hooks(mpctx) < 0) goto terminate_playback; + if (opts->stream_dump && opts->stream_dump[0]) { + if (stream_dump(mpctx, mpctx->stream_open_filename) < 0) + mpctx->error_playing = 1; + goto terminate_playback; + } + int stream_flags = STREAM_READ; if (!opts->load_unsafe_playlists) stream_flags |= mpctx->playing->stream_flags; @@ -1087,12 +1093,6 @@ static void play_current_file(struct MPContext *mpctx) if (!mpctx->stream) goto terminate_playback; - if (opts->stream_dump && opts->stream_dump[0]) { - stream_dump(mpctx); - mpctx->error_playing = 1; - goto terminate_playback; - } - // Must be called before enabling cache. mp_nav_init(mpctx); diff --git a/player/misc.c b/player/misc.c index f3d9214828..613b475365 100644 --- a/player/misc.c +++ b/player/misc.c @@ -200,17 +200,17 @@ void error_on_track(struct MPContext *mpctx, struct track *track) } } -void stream_dump(struct MPContext *mpctx) +int stream_dump(struct MPContext *mpctx, const char *source_filename) { struct MPOpts *opts = mpctx->opts; - char *filename = opts->stream_dump; - stream_t *stream = mpctx->stream; - assert(stream && filename); + stream_t *stream = stream_open(source_filename, mpctx->global); + if (!stream) + return -1; int64_t size = 0; stream_control(stream, STREAM_CTRL_GET_SIZE, &size); - stream_set_capture_file(stream, filename); + stream_set_capture_file(stream, opts->stream_dump); while (mpctx->stop_play == KEEP_PLAYING && !stream->eof) { if (!opts->quiet && ((stream->pos / (1024 * 1024)) % 2) == 1) { @@ -221,6 +221,9 @@ void stream_dump(struct MPContext *mpctx) stream_fill_buffer(stream); mp_process_input(mpctx); } + + free_stream(stream); + return 0; } void merge_playlist_files(struct playlist *pl)