From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 36EB546D7C for ; Mon, 10 Jul 2023 23:58:08 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A0B3968C5C8; Tue, 11 Jul 2023 02:57:56 +0300 (EEST) Received: from mail-yb1-f176.google.com (mail-yb1-f176.google.com [209.85.219.176]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2AF0468C56B for ; Tue, 11 Jul 2023 02:57:49 +0300 (EEST) Received: by mail-yb1-f176.google.com with SMTP id 3f1490d57ef6-c4cb5681f55so684261276.1 for ; Mon, 10 Jul 2023 16:57:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1689033467; x=1691625467; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dE7eSClDX28wgdnT1FBE7RlHr45S2hNXsmPSp/AXzHE=; b=BoD+Y/4Ntuc/dQ8oJ2/DjiNUl8Wc8K1I0uZSn6KmQwCj2IxW4N7xWZTUBu8ofPpPrv mfXtO6+4HeZWKsuca2YyGnMWlVpOF9V7y3ZH4XXziEfml80s4BA2xLXF8PpaZaldnmcz mGeluz6x9IVa+n0hcniWYDQuwYoBOmtwDTApzZhmdNRAETv3zhwAvlsA97+ziPzo7aDe XnxS3iKP4rJVauOT2Lw4DKpO0+mZFaZiEVLpgp1Qe5DSxQyXWqkl8CKymIDNXeUQfPVX kcV34AdrOw9DM/ZbXgzclH/mluoXMw9AwI3zsI5odpsCQViiyeexHd+2ZDTpMgjBP8KD UwAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689033467; x=1691625467; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dE7eSClDX28wgdnT1FBE7RlHr45S2hNXsmPSp/AXzHE=; b=BWviQkJZ/fwgZ+bFhLwUUlNbtF9k0a2NW9CQcYc7DqLSIMYs422UKP2fMbMeGhr84p R4KZbDRxil0X6ev/YgEkC4KDrp5pNx1+q8tHivWipf/xLIVtyyqmnuNn072AbAnbOjkm 4CAsgkWAlQiKdUKLVsC5MlZAbm+CDKG8QU88/5FHqBBHc8gYKgPWl/6dD8O0sTTxYL8+ TGgGQhd8BMae2sFLQfhCfAA9/qYOpqxZ+e3YZ7SDlx0Hs6Unh1+zWdwmNVAJlnAPBrAL pxxJvwbCfua0SoPdWeIOYPo1JyJNTbXy46bkZr6xYgQoiYKcFnl92vMfF2c5v75OeFSb iwBA== X-Gm-Message-State: ABy/qLZ5ou1Q+4o3UpFEZSQ7LKMuj1cPA6jv+0xb+q8cegnCoG4trKlq 9Ja6+pBcJAHyrqQyvQnQD8xdBiEvcPg= X-Google-Smtp-Source: APBJJlFwKwwdZhmFqvFtg+uHCWAkuRNOHvM276T0GmG/TNF0F5eX5u6WIxUpxmZLsioYrccd8Du71w== X-Received: by 2002:a81:9a0c:0:b0:573:9743:a0a2 with SMTP id r12-20020a819a0c000000b005739743a0a2mr7565068ywg.1.1689033467376; Mon, 10 Jul 2023 16:57:47 -0700 (PDT) Received: from gauss.local (c-98-224-219-15.hsd1.mi.comcast.net. [98.224.219.15]) by smtp.gmail.com with ESMTPSA id v2-20020a0dd302000000b005707fb5110bsm263450ywd.58.2023.07.10.16.57.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jul 2023 16:57:47 -0700 (PDT) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Mon, 10 Jul 2023 19:57:41 -0400 Message-ID: <20230710235744.30513-2-leo.izen@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230710235744.30513-1-leo.izen@gmail.com> References: <20230710235744.30513-1-leo.izen@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v5 1/4] avcodec/libjxldec: use internal AVFrame as buffered space X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Leo Izen Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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. Signed-off-by: Leo Izen --- libavcodec/libjxldec.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) diff --git a/libavcodec/libjxldec.c b/libavcodec/libjxldec.c index e45ac02c07..93c173cecc 100644 --- a/libavcodec/libjxldec.c +++ b/libavcodec/libjxldec.c @@ -58,6 +58,7 @@ typedef struct LibJxlDecodeContext { int64_t frame_duration; int prev_is_last; AVRational timebase; + AVFrame *frame; } LibJxlDecodeContext; static int libjxl_init_jxl_decoder(AVCodecContext *avctx) @@ -104,6 +105,9 @@ static av_cold int libjxl_decode_init(AVCodecContext *avctx) ctx->avpkt = avctx->internal->in_pkt; ctx->pts = 0; + ctx->frame = av_frame_alloc(); + if (!ctx->frame) + return AVERROR(ENOMEM); return libjxl_init_jxl_decoder(avctx); } @@ -406,10 +410,6 @@ static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame) return AVERROR_INVALIDDATA; case JXL_DEC_NEED_MORE_INPUT: av_log(avctx, AV_LOG_DEBUG, "NEED_MORE_INPUT event emitted\n"); - if (!pkt->size) { - av_packet_unref(pkt); - return AVERROR(EAGAIN); - } continue; case JXL_DEC_BASIC_INFO: av_log(avctx, AV_LOG_DEBUG, "BASIC_INFO event emitted\n"); @@ -438,16 +438,18 @@ static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame) continue; case JXL_DEC_COLOR_ENCODING: av_log(avctx, AV_LOG_DEBUG, "COLOR_ENCODING event emitted\n"); - if ((ret = libjxl_color_encoding_event(avctx, frame)) < 0) + if ((ret = libjxl_color_encoding_event(avctx, ctx->frame)) < 0) return ret; continue; case JXL_DEC_NEED_IMAGE_OUT_BUFFER: av_log(avctx, AV_LOG_DEBUG, "NEED_IMAGE_OUT_BUFFER event emitted\n"); - if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) + ret = ff_get_buffer(avctx, ctx->frame, 0); + if (ret < 0) return ret; - ctx->jxl_pixfmt.align = frame->linesize[0]; - if (JxlDecoderSetImageOutBuffer(ctx->decoder, &ctx->jxl_pixfmt, frame->data[0], frame->buf[0]->size) - != JXL_DEC_SUCCESS) { + ctx->jxl_pixfmt.align = ctx->frame->linesize[0]; + if (JxlDecoderSetImageOutBuffer(ctx->decoder, &ctx->jxl_pixfmt, + ctx->frame->data[0], ctx->frame->buf[0]->size) + != JXL_DEC_SUCCESS) { av_log(avctx, AV_LOG_ERROR, "Bad libjxl dec need image out buffer event\n"); return AVERROR_EXTERNAL; } @@ -461,8 +463,8 @@ static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame) case JXL_DEC_FRAME: av_log(avctx, AV_LOG_DEBUG, "FRAME event emitted\n"); if (!ctx->basic_info.have_animation || ctx->prev_is_last) { - frame->pict_type = AV_PICTURE_TYPE_I; - frame->flags |= AV_FRAME_FLAG_KEY; + ctx->frame->pict_type = AV_PICTURE_TYPE_I; + ctx->frame->flags |= AV_FRAME_FLAG_KEY; } if (ctx->basic_info.have_animation) { JxlFrameHeader header; @@ -481,20 +483,21 @@ static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame) /* full image is one frame, even if animated */ av_log(avctx, AV_LOG_DEBUG, "FULL_IMAGE event emitted\n"); if (ctx->iccp) { - AVFrameSideData *sd = av_frame_new_side_data_from_buf(frame, AV_FRAME_DATA_ICC_PROFILE, ctx->iccp); + AVFrameSideData *sd = av_frame_new_side_data_from_buf(ctx->frame, AV_FRAME_DATA_ICC_PROFILE, ctx->iccp); if (!sd) return AVERROR(ENOMEM); /* ownership is transfered, and it is not ref-ed */ ctx->iccp = NULL; } if (avctx->pkt_timebase.num) { - frame->pts = av_rescale_q(ctx->pts, ctx->timebase, avctx->pkt_timebase); - frame->duration = av_rescale_q(ctx->frame_duration, ctx->timebase, avctx->pkt_timebase); + ctx->frame->pts = av_rescale_q(ctx->pts, ctx->timebase, avctx->pkt_timebase); + ctx->frame->duration = av_rescale_q(ctx->frame_duration, ctx->timebase, avctx->pkt_timebase); } else { - frame->pts = ctx->pts; - frame->duration = ctx->frame_duration; + ctx->frame->pts = ctx->pts; + ctx->frame->duration = ctx->frame_duration; } ctx->pts += ctx->frame_duration; + av_frame_move_ref(frame, ctx->frame); return 0; case JXL_DEC_SUCCESS: av_log(avctx, AV_LOG_DEBUG, "SUCCESS event emitted\n"); @@ -525,6 +528,7 @@ static av_cold int libjxl_decode_close(AVCodecContext *avctx) JxlDecoderDestroy(ctx->decoder); ctx->decoder = NULL; av_buffer_unref(&ctx->iccp); + av_frame_free(&ctx->frame); return 0; } -- 2.41.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".