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

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/libjxldec.c+21−16
@@ -58,6 +58,7 @@ typedef struct LibJxlDecodeContext { · 57 unmodified lines
5858 int64_t frame_duration;
5959 int prev_is_last;
6060 AVRational timebase;
61+ AVFrame *frame;
6162 } LibJxlDecodeContext;
6263
6364 static int libjxl_init_jxl_decoder(AVCodecContext *avctx)
@@ -104,6 +105,9 @@ static av_cold int libjxl_decode_init(AVCodecContext *avctx) · 40 unmodified lines
104105
105106 ctx->avpkt = avctx->internal->in_pkt;
106107 ctx->pts = 0;
108+ ctx->frame = av_frame_alloc();
109+ if (!ctx->frame)
110+ return AVERROR(ENOMEM);
107111
108112 return libjxl_init_jxl_decoder(avctx);
109113 }
@@ -406,10 +410,6 @@ static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame) · 296 unmodified lines
406410 return AVERROR_INVALIDDATA;
407411 case JXL_DEC_NEED_MORE_INPUT:
408412 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− }
413413 continue;
414414 case JXL_DEC_BASIC_INFO:
415415 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
438438 continue;
439439 case JXL_DEC_COLOR_ENCODING:
440440 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)
442443 return ret;
443444 continue;
444445 case JXL_DEC_NEED_IMAGE_OUT_BUFFER:
445446 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)
447449 return ret;
448− ctx->jxl_pixfmt.align = frame->linesize[0];
449− if (JxlDecoderSetImageOutBuffer(ctx->decoder, &ctx->jxl_pixfmt, frame->data[0], frame->buf[0]->size)
450− != JXL_DEC_SUCCESS) {
450+ ctx->jxl_pixfmt.align = ctx->frame->linesize[0];
451+ if (JxlDecoderSetImageOutBuffer(ctx->decoder, &ctx->jxl_pixfmt,
452+ ctx->frame->data[0], ctx->frame->buf[0]->size)
453+ != JXL_DEC_SUCCESS) {
451454 av_log(avctx, AV_LOG_ERROR, "Bad libjxl dec need image out buffer event\n");
452455 return AVERROR_EXTERNAL;
453456 }
@@ -461,8 +464,8 @@ static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame) · 7 unmodified lines
461464 case JXL_DEC_FRAME:
462465 av_log(avctx, AV_LOG_DEBUG, "FRAME event emitted\n");
463466 if (!ctx->basic_info.have_animation || ctx->prev_is_last) {
464− frame->pict_type = AV_PICTURE_TYPE_I;
465− frame->flags |= AV_FRAME_FLAG_KEY;
467+ ctx->frame->pict_type = AV_PICTURE_TYPE_I;
468+ ctx->frame->flags |= AV_FRAME_FLAG_KEY;
466469 }
467470 if (ctx->basic_info.have_animation) {
468471 JxlFrameHeader header;
@@ -481,20 +484,21 @@ static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame) · 12 unmodified lines
481484 /* full image is one frame, even if animated */
482485 av_log(avctx, AV_LOG_DEBUG, "FULL_IMAGE event emitted\n");
483486 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);
485488 if (!sd)
486489 return AVERROR(ENOMEM);
487490 /* ownership is transfered, and it is not ref-ed */
488491 ctx->iccp = NULL;
489492 }
490493 if (avctx->pkt_timebase.num) {
491− 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);
494+ ctx->frame->pts = av_rescale_q(ctx->pts, ctx->timebase, avctx->pkt_timebase);
495+ ctx->frame->duration = av_rescale_q(ctx->frame_duration, ctx->timebase, avctx->pkt_timebase);
493496 } else {
494− frame->pts = ctx->pts;
495− frame->duration = ctx->frame_duration;
497+ ctx->frame->pts = ctx->pts;
498+ ctx->frame->duration = ctx->frame_duration;
496499 }
497500 ctx->pts += ctx->frame_duration;
501+ av_frame_move_ref(frame, ctx->frame);
498502 return 0;
499503 case JXL_DEC_SUCCESS:
500504 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
525529 JxlDecoderDestroy(ctx->decoder);
526530 ctx->decoder = NULL;
527531 av_buffer_unref(&ctx->iccp);
532+ av_frame_free(&ctx->frame);
528533
529534 return 0;
530535 }

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