diff options
author | wm4 <wm4@nowhere> | 2020-03-22 21:08:44 +0100 |
---|---|---|
committer | wm4 <wm4@nowhere> | 2020-03-22 21:08:44 +0100 |
commit | 6169fba79679aff0c4b07fbae03ed30e9f6f7eb6 (patch) | |
tree | 8a20ff452679a00ca900f182a260c5acb549ce63 /common/encode_lavc.c | |
parent | 37f441d61b1e2f92a31fe8f71dc965254d8e0d95 (diff) | |
download | mpv-6169fba79679aff0c4b07fbae03ed30e9f6f7eb6.tar.bz2 mpv-6169fba79679aff0c4b07fbae03ed30e9f6f7eb6.tar.xz |
encode: fix occasional init crash due to initialization order issues
Looks like the recent change to this actually made it crash whenever
audio happened to be initialized first, due to not setting the
mux_stream field before the on_ready callback. Mess a way around this.
Also remove a stray unused variable from ao_lavc.c.
Diffstat (limited to 'common/encode_lavc.c')
-rw-r--r-- | common/encode_lavc.c | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/common/encode_lavc.c b/common/encode_lavc.c index 4d435a11ca..94428c6733 100644 --- a/common/encode_lavc.c +++ b/common/encode_lavc.c @@ -395,10 +395,11 @@ void encode_lavc_stream_eof(struct encode_lavc_context *ctx, // Signal that you are ready to encode (you provide the codec params etc. too). // This returns a muxing handle which you can use to add encodec packets. // Can be called only once per stream. info is copied by callee as needed. -static struct mux_stream *encode_lavc_add_stream(struct encode_lavc_context *ctx, - struct encoder_stream_info *info, - void (*on_ready)(void *ctx), - void *on_ready_ctx) +static void encode_lavc_add_stream(struct encoder_context *enc, + struct encode_lavc_context *ctx, + struct encoder_stream_info *info, + void (*on_ready)(void *ctx), + void *on_ready_ctx) { struct encode_priv *p = ctx->priv; @@ -433,13 +434,12 @@ static struct mux_stream *encode_lavc_add_stream(struct encode_lavc_context *ctx dst->on_ready = on_ready; dst->on_ready_ctx = on_ready_ctx; + enc->mux_stream = dst; maybe_init_muxer(ctx); done: pthread_mutex_unlock(&ctx->lock); - - return dst; } // Write a packet. This will take over ownership of `pkt` @@ -922,8 +922,7 @@ bool encoder_init_codec_and_muxer(struct encoder_context *p, if (avcodec_parameters_from_context(p->info.codecpar, p->encoder) < 0) goto fail; - p->mux_stream = encode_lavc_add_stream(p->encode_lavc_ctx, &p->info, - on_ready, ctx); + encode_lavc_add_stream(p, p->encode_lavc_ctx, &p->info, on_ready, ctx); if (!p->mux_stream) goto fail; |