avcodec/libjxldec: consume input on error

libjxl consumes no input if it returns an error, so this loops over
and over while it spits out the same error many times. If we got an
error from libjxl and consumed no input, then we instead consume the
whole packet.

Signed-off-by: Leo Izen <leo.izen@gmail.com>
This commit is contained in:
Leo Izen
2025-08-27 11:53:23 -04:00
parent 74e61981b5
commit 1dcb0c6c3e

View File

@@ -414,12 +414,20 @@ static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame)
* the number of bytes that it did read
*/
remaining = JxlDecoderReleaseInput(ctx->decoder);
pkt->data += pkt->size - remaining;
size_t consumed = pkt->size - remaining;
pkt->data += consumed;
pkt->size = remaining;
switch(jret) {
case JXL_DEC_ERROR:
av_log(avctx, AV_LOG_ERROR, "Unknown libjxl decode error\n");
/*
* we consume all remaining input on error, if nothing was consumed
* this prevents libjxl from consuming nothing forever
* and just dumping the last error over and over
*/
if (!consumed)
av_packet_unref(pkt);
return AVERROR_INVALIDDATA;
case JXL_DEC_NEED_MORE_INPUT:
av_log(avctx, AV_LOG_DEBUG, "NEED_MORE_INPUT event emitted\n");