summaryrefslogtreecommitdiffstats
path: root/player/loadfile.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2018-04-22 19:40:36 +0200
committerJan Ekström <jeebjp@gmail.com>2018-04-29 02:21:32 +0300
commit6c8362ef54f4e90476553cb6b64996cc414da06d (patch)
treeab3fa75a18958bacc08c473304f59519a58f5969 /player/loadfile.c
parent8135e25600ace2894df274e6a825cfef525fee77 (diff)
downloadmpv-6c8362ef54f4e90476553cb6b64996cc414da06d.tar.bz2
mpv-6c8362ef54f4e90476553cb6b64996cc414da06d.tar.xz
encode: rewrite half of it
The main change is that we wait with opening the muxer ("writing headers") until we have data from all streams. This fixes race conditions at init due to broken assumptions in the old code. This also changes a lot of other stuff. I found and fixed a few API violations (often things for which better mechanisms were invented, and the old ones are not valid anymore). I try to get away from the public mutex and shared fields in encode_lavc_context. For now it's still needed for some timestamp-related fields, but most are gone. It also removes some bad code duplication between audio and video paths.
Diffstat (limited to 'player/loadfile.c')
-rw-r--r--player/loadfile.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/player/loadfile.c b/player/loadfile.c
index 8065b6f007..cf3c1eb013 100644
--- a/player/loadfile.c
+++ b/player/loadfile.c
@@ -1302,9 +1302,9 @@ reopen_file:
#if HAVE_ENCODING
if (mpctx->encode_lavc_ctx && mpctx->current_track[0][STREAM_VIDEO])
- encode_lavc_expect_stream(mpctx->encode_lavc_ctx, AVMEDIA_TYPE_VIDEO);
+ encode_lavc_expect_stream(mpctx->encode_lavc_ctx, STREAM_VIDEO);
if (mpctx->encode_lavc_ctx && mpctx->current_track[0][STREAM_AUDIO])
- encode_lavc_expect_stream(mpctx->encode_lavc_ctx, AVMEDIA_TYPE_AUDIO);
+ encode_lavc_expect_stream(mpctx->encode_lavc_ctx, STREAM_AUDIO);
if (mpctx->encode_lavc_ctx) {
encode_lavc_set_metadata(mpctx->encode_lavc_ctx,
mpctx->demuxer->metadata);
@@ -1556,6 +1556,20 @@ void mp_play_files(struct MPContext *mpctx)
}
cancel_open(mpctx);
+
+#if HAVE_ENCODING
+ if (mpctx->encode_lavc_ctx) {
+ // Make sure all streams get finished.
+ uninit_audio_out(mpctx);
+ uninit_video_out(mpctx);
+
+ if (!encode_lavc_free(mpctx->encode_lavc_ctx))
+ mpctx->stop_play = PT_ERROR;
+
+ mpctx->encode_lavc_ctx = NULL;
+ }
+#endif
+
}
// Abort current playback and set the given entry to play next.