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 801CE468D2 for ; Sat, 24 Jun 2023 04:39:17 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9509568C15F; Sat, 24 Jun 2023 07:39:04 +0300 (EEST) Received: from mail-qk1-f169.google.com (mail-qk1-f169.google.com [209.85.222.169]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 26C0168B838 for ; Sat, 24 Jun 2023 07:38:57 +0300 (EEST) Received: by mail-qk1-f169.google.com with SMTP id af79cd13be357-7576b53e75eso29342285a.1 for ; Fri, 23 Jun 2023 21:38:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1687581536; x=1690173536; 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=Y7cr8TDWfam2sZdgJ6lp3BZf9VZHH//dn/mZB7/Y5Fg=; b=cn6gQdUt7xF01Jjl7BDAXfHiSIz/qz7KyzFexEoMGC9YdAy+u0WrJ/uuAlpaCWUAFL 6eB3YFGTivVBOgFfU4HI9OioXAPgyhSFVufPQdJypYYu8yqbfAto1V8fBkWSqDZqTiB1 MGZkKFdc1PsATT4r3O4hE7ffJhp6sl+bQWN9y7+uWJia6wKswt3y8Hh7AnB/i/AMftBZ ieAw3irIXP84M5f4cpJ7pF6fS0SxvXW/K4n2RUpRQOMjd9MVwnTAgh1bAusAnQbcE1DU s3zd4CXuAqeOTCDrYuQmDhlbYwxl6Ka7eJuPS0mzKYhUpVVxpbS4CdVimDGd4OlWdP9H aZvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687581536; x=1690173536; 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=Y7cr8TDWfam2sZdgJ6lp3BZf9VZHH//dn/mZB7/Y5Fg=; b=QX3lBkSCACKirN3ebiMFWDZKHSMgAz5nSA4SWyEICwCoBTgRfgXV9TWBvpQhtYK3Ez xxKLdTv3fOwWaiDf8VGKMh06neiIQOJlpNtlWa5iDLhWbu+ZBeUOe6+85pbiU9FVIfKd nwThwW1nqd7mMi3VpCGMDSvv07y0M4WH1FLc1H3kIDmn6I3nIElQGzfI4k2mIA8A0esc p9mvJtCYICMR5b2pVyqiLEhxhYO1ximckeMcJNMvArWdba+AQVa9uXJM/j084saY78fb qtZXvUtdM0wcy++M9byAEpyKVyeupv7er1eFm0gtOrTE1VZeHs7dz+wXiEB+iRsaqitV SDCA== X-Gm-Message-State: AC+VfDy85t3wqU3U1Y6IskxOGjGCxPLQ3rG/9SV8O0LUcXFlM2tVYxnC C+cSMG2vqdH6Ne/aXRgVKi2ucBXbf1k= X-Google-Smtp-Source: ACHHUZ4JzY1kb4wHxrimMiAZbL89tzDSG+mWhU8vnUaO0yQT0v3cUUQo5c7DWn0IIAxp9D7gj5MjSw== X-Received: by 2002:a05:620a:171f:b0:75d:e31a:a015 with SMTP id az31-20020a05620a171f00b0075de31aa015mr27203374qkb.2.1687581535776; Fri, 23 Jun 2023 21:38:55 -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 m11-20020a0dca0b000000b0055aafcef659sm173719ywd.5.2023.06.23.21.38.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 21:38:55 -0700 (PDT) From: Leo Izen To: ffmpeg-devel@ffmpeg.org Date: Sat, 24 Jun 2023 00:38:50 -0400 Message-ID: <20230624043853.12237-2-leo.izen@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230624043853.12237-1-leo.izen@gmail.com> References: <20230624043853.12237-1-leo.izen@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v3 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. --- libavcodec/libjxldec.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/libavcodec/libjxldec.c b/libavcodec/libjxldec.c index 50417bcb02..cea7ea0d3b 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); } @@ -351,10 +355,12 @@ static int libjxl_receive_frame(AVCodecContext *avctx, AVFrame *frame) size_t remaining; if (!pkt->size) { + av_log(avctx, AV_LOG_DEBUG, "Fetching new packet\n"); av_packet_unref(pkt); ret = ff_decode_get_packet(avctx, pkt); if (ret < 0 && ret != AVERROR_EOF) return ret; + av_log(avctx, AV_LOG_DEBUG, "Fetched packet of size: %d\n", pkt->size); if (!pkt->size) { /* jret set by the last iteration of the loop */ if (jret == JXL_DEC_NEED_MORE_INPUT) { @@ -389,10 +395,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"); @@ -421,16 +423,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; } @@ -444,8 +448,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; @@ -464,20 +468,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"); @@ -508,6 +513,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; } @@ -521,7 +527,7 @@ const FFCodec ff_libjxl_decoder = { .init = libjxl_decode_init, FF_CODEC_RECEIVE_FRAME_CB(libjxl_receive_frame), .close = libjxl_decode_close, - .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_OTHER_THREADS, + .p.capabilities = AV_CODEC_CAP_OTHER_THREADS, .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE | FF_CODEC_CAP_AUTO_THREADS | FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_ICC_PROFILES, -- 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".