From 6169fba79679aff0c4b07fbae03ed30e9f6f7eb6 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 22 Mar 2020 21:08:44 +0100 Subject: 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. --- audio/out/ao_lavc.c | 1 - common/encode_lavc.c | 15 +++++++-------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/audio/out/ao_lavc.c b/audio/out/ao_lavc.c index e4700d7f1b..a38c01e0b2 100644 --- a/audio/out/ao_lavc.c +++ b/audio/out/ao_lavc.c @@ -232,7 +232,6 @@ static void encode(struct ao *ao, double apts, void **data) // whatever the fuck this code does? MP_WARN(ao, "audio frame pts went backwards (%d <- %d), autofixed\n", (int)frame->pts, (int)ac->lastpts); - int64_t prets = frame->pts; frame_pts = ac->lastpts + 1; ac->lastpts = frame_pts; frame->pts = av_rescale_q(frame_pts, ac->worst_time_base, 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; -- cgit v1.2.3