History

avcodec/libjxldec: use internal AVFrame as buffered space

Before this commit, the decoder erroneously assumes that the AVFrame passed to the receive_frame is the same one each time. Now it keeps an internal AVFrame to write into, and copies it over when it's done.

Leo Izen committed 3 years ago

Commit 7a69f731 parent 245910d1 file · +21 −16Browse files

Unified · Split

libavcodec/libjxldec.c+21−16
@@ -58,6 +58,7 @@ typedef struct LibJxlDecodeContext { · 57 unmodified lines
58 int64_t frame_duration;58 int64_t frame_duration;
59 int prev_is_last;59 int prev_is_last;
60 AVRational timebase;60 AVRational timebase;
61 AVFrame *frame;
61} LibJxlDecodeContext;62} LibJxlDecodeContext;
62 63
63static int libjxl_init_jxl_decoder(AVCodecContext *avctx)64static int libjxl_init_jxl_decoder(AVCodecContext *avctx)
@@ -104,6 +105,9 @@ static av_cold int libjxl_decode_init(AVCodecContext *avctx) · 40 unmodified lines
104 105
105 ctx->avpkt = avctx->internal->in_pkt;106 ctx->avpkt = avctx->internal->in_pkt;
106 ctx->pts = 0;107 ctx->pts = 0;
108 ctx->frame = av_frame_alloc();
109 if (!ctx->frame)
110 return AVERROR(ENOMEM);
107 111
108 return libjxl_init_jxl_decoder(avctx);112 return libjxl_init_jxl_decoder(avctx);
109}113}
@@ -406,10 +410,6 @@ static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame) · 296 unmodified lines
406 return AVERROR_INVALIDDATA;410 return AVERROR_INVALIDDATA;
407 case JXL_DEC_NEED_MORE_INPUT:411 case JXL_DEC_NEED_MORE_INPUT:
408 av_log(avctx, AV_LOG_DEBUG, "NEED_MORE_INPUT event emitted\n");412 av_log(avctx, AV_LOG_DEBUG, "NEED_MORE_INPUT event emitted\n");
409 if (!pkt->size) {
410 av_packet_unref(pkt);
411 return AVERROR(EAGAIN);
412 }
413 continue;413 continue;
414 case JXL_DEC_BASIC_INFO:414 case JXL_DEC_BASIC_INFO:
415 av_log(avctx, AV_LOG_DEBUG, "BASIC_INFO event emitted\n");415 av_log(avctx, AV_LOG_DEBUG, "BASIC_INFO event emitted\n");
@@ -438,16 +438,19 @@ static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame) · 22 unmodified lines
438 continue;438 continue;
439 case JXL_DEC_COLOR_ENCODING:439 case JXL_DEC_COLOR_ENCODING:
440 av_log(avctx, AV_LOG_DEBUG, "COLOR_ENCODING event emitted\n");440 av_log(avctx, AV_LOG_DEBUG, "COLOR_ENCODING event emitted\n");
441 if ((ret = libjxl_color_encoding_event(avctx, frame)) < 0)441 ret = libjxl_color_encoding_event(avctx, ctx->frame);
442 if (ret < 0)
442 return ret;443 return ret;
443 continue;444 continue;
444 case JXL_DEC_NEED_IMAGE_OUT_BUFFER:445 case JXL_DEC_NEED_IMAGE_OUT_BUFFER:
445 av_log(avctx, AV_LOG_DEBUG, "NEED_IMAGE_OUT_BUFFER event emitted\n");446 av_log(avctx, AV_LOG_DEBUG, "NEED_IMAGE_OUT_BUFFER event emitted\n");
446 if ((ret = ff_get_buffer(avctx, frame, 0)) < 0)447 ret = ff_get_buffer(avctx, ctx->frame, 0);
448 if (ret < 0)
447 return ret;449 return ret;
448 ctx->jxl_pixfmt.align = frame->linesize[0];450 ctx->jxl_pixfmt.align = ctx->frame->linesize[0];
449 if (JxlDecoderSetImageOutBuffer(ctx->decoder, &ctx->jxl_pixfmt, frame->data[0], frame->buf[0]->size)451 if (JxlDecoderSetImageOutBuffer(ctx->decoder, &ctx->jxl_pixfmt,
450 != JXL_DEC_SUCCESS) {452 ctx->frame->data[0], ctx->frame->buf[0]->size)
453 != JXL_DEC_SUCCESS) {
451 av_log(avctx, AV_LOG_ERROR, "Bad libjxl dec need image out buffer event\n");454 av_log(avctx, AV_LOG_ERROR, "Bad libjxl dec need image out buffer event\n");
452 return AVERROR_EXTERNAL;455 return AVERROR_EXTERNAL;
453 }456 }
@@ -461,8 +464,8 @@ static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame) · 7 unmodified lines
461 case JXL_DEC_FRAME:464 case JXL_DEC_FRAME:
462 av_log(avctx, AV_LOG_DEBUG, "FRAME event emitted\n");465 av_log(avctx, AV_LOG_DEBUG, "FRAME event emitted\n");
463 if (!ctx->basic_info.have_animation || ctx->prev_is_last) {466 if (!ctx->basic_info.have_animation || ctx->prev_is_last) {
464 frame->pict_type = AV_PICTURE_TYPE_I;467 ctx->frame->pict_type = AV_PICTURE_TYPE_I;
465 frame->flags |= AV_FRAME_FLAG_KEY;468 ctx->frame->flags |= AV_FRAME_FLAG_KEY;
466 }469 }
467 if (ctx->basic_info.have_animation) {470 if (ctx->basic_info.have_animation) {
468 JxlFrameHeader header;471 JxlFrameHeader header;
@@ -481,20 +484,21 @@ static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame) · 12 unmodified lines
481 /* full image is one frame, even if animated */484 /* full image is one frame, even if animated */
482 av_log(avctx, AV_LOG_DEBUG, "FULL_IMAGE event emitted\n");485 av_log(avctx, AV_LOG_DEBUG, "FULL_IMAGE event emitted\n");
483 if (ctx->iccp) {486 if (ctx->iccp) {
484 AVFrameSideData *sd = av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_ICC_PROFILE, ctx->iccp);487 AVFrameSideData *sd = av_frame_new_side_data_from_buf(ctx->frame, AV_FRAME_DATA_ICC_PROFILE, ctx->iccp);
485 if (!sd)488 if (!sd)
486 return AVERROR(ENOMEM);489 return AVERROR(ENOMEM);
487 /* ownership is transfered, and it is not ref-ed */490 /* ownership is transfered, and it is not ref-ed */
488 ctx->iccp = NULL;491 ctx->iccp = NULL;
489 }492 }
490 if (avctx->pkt_timebase.num) {493 if (avctx->pkt_timebase.num) {
491 frame->pts = av_rescale_q(ctx->pts, ctx->timebase, avctx->pkt_timebase);494 ctx->frame->pts = av_rescale_q(ctx->pts, ctx->timebase, avctx->pkt_timebase);
492 frame->duration = av_rescale_q(ctx->frame_duration, ctx->timebase, avctx->pkt_timebase);495 ctx->frame->duration = av_rescale_q(ctx->frame_duration, ctx->timebase, avctx->pkt_timebase);
493 } else {496 } else {
494 frame->pts = ctx->pts;497 ctx->frame->pts = ctx->pts;
495 frame->duration = ctx->frame_duration;498 ctx->frame->duration = ctx->frame_duration;
496 }499 }
497 ctx->pts += ctx->frame_duration;500 ctx->pts += ctx->frame_duration;
501 av_frame_move_ref(frame, ctx->frame);
498 return 0;502 return 0;
499 case JXL_DEC_SUCCESS:503 case JXL_DEC_SUCCESS:
500 av_log(avctx, AV_LOG_DEBUG, "SUCCESS event emitted\n");504 av_log(avctx, AV_LOG_DEBUG, "SUCCESS event emitted\n");
@@ -525,6 +529,7 @@ static av_cold int libjxl_decode_close(AVCodecContext *avctx) · 24 unmodified lines
525 JxlDecoderDestroy(ctx->decoder);529 JxlDecoderDestroy(ctx->decoder);
526 ctx->decoder = NULL;530 ctx->decoder = NULL;
527 av_buffer_unref(&ctx->iccp);531 av_buffer_unref(&ctx->iccp);
532 av_frame_free(&ctx->frame);
528 533
529 return 0;534 return 0;
530}535}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t