diff --git a/audio/decode/ad_spdif.c b/audio/decode/ad_spdif.c index decd97206d..19a9b7d2f6 100644 --- a/audio/decode/ad_spdif.c +++ b/audio/decode/ad_spdif.c @@ -149,10 +149,13 @@ done: MP_WARN(da, "Failed to parse codec profile.\n"); } -static int init_filter(struct mp_filter *da, AVPacket *pkt) +static int init_filter(struct mp_filter *da) { struct spdifContext *spdif_ctx = da->priv; + AVPacket *pkt = spdif_ctx->avpkt = av_packet_alloc(); + MP_HANDLE_OOM(spdif_ctx->avpkt); + int profile = FF_PROFILE_UNKNOWN; int c_rate = 0; determine_codec_params(da, pkt, &profile, &c_rate); @@ -296,12 +299,14 @@ static void process(struct mp_filter *da) struct mp_aframe *out = NULL; double pts = mpkt->pts; + if (!spdif_ctx->lavf_ctx) { + if (init_filter(da) < 0) + goto done; + assert(spdif_ctx->avpkt); + } + mp_set_av_packet(spdif_ctx->avpkt, mpkt, NULL); spdif_ctx->avpkt->pts = spdif_ctx->avpkt->dts = 0; - if (!spdif_ctx->lavf_ctx) { - if (init_filter(da, spdif_ctx->avpkt) < 0) - goto done; - } spdif_ctx->out_buffer_len = 0; int ret = av_write_frame(spdif_ctx->lavf_ctx, spdif_ctx->avpkt); avio_flush(spdif_ctx->lavf_ctx->pb); @@ -425,9 +430,6 @@ static struct mp_decoder *create(struct mp_filter *parent, return NULL; } - spdif_ctx->avpkt = av_packet_alloc(); - MP_HANDLE_OOM(spdif_ctx->avpkt); - return &spdif_ctx->public; }