avcodec/libjxldec: goto SUCCESS when frame is completed

Fix #21260

The early code didn't reset the JxlDecoder. If the
caller re-send the same packet to JxlDecoder after
avcodec_flush_buffers() (free ctx->frame). It will
directly hit SUCCESS event (skip all EVENTs).

In this case, the ctx->frame already flushed by
avcodec_flush_buffers, so the received frame
will be invalid (has no private_ref) that causes
assertion in decode_receive_frame_internal().

MPV meet this issue because it seek the jxl image
(second read the same pkt) when it does crop
through config `C vf toggle crop=in_w:in_w/2.4`.

This patch make sure hit the entire SUCCESS event
(contains reset the JxlDecoder) when frame_complete
is true.

Signed-off-by: Jack Lau <jacklau1222gm@gmail.com>
This commit is contained in:
Jack Lau
2025-12-23 10:53:23 +08:00
committed by James Almer
parent d60c1d72c1
commit 13c91c97d1

View File

@@ -450,9 +450,8 @@ static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame)
av_log(avctx, AV_LOG_ERROR, "Unexpected end of JXL codestream\n");
return AVERROR_INVALIDDATA;
} else if (ctx->frame_complete) {
libjxl_finalize_frame(avctx, frame, ctx->frame);
ctx->jret = JXL_DEC_SUCCESS;
return 0;
goto success;
}
return AVERROR_EOF;
}
@@ -591,6 +590,7 @@ static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame)
* but it will also be fired when the next image of
* an image2pipe sequence is loaded up
*/
success:
libjxl_finalize_frame(avctx, frame, ctx->frame);
JxlDecoderReset(ctx->decoder);
libjxl_init_jxl_decoder(avctx);