From patchwork Mon Apr 8 20:13:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 47954 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3f98:b0:1a7:a0dc:8de5 with SMTP id ay24csp136733pzb; Mon, 8 Apr 2024 13:17:12 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWE/9UpyEaOgPBQL2VVbSESqrGKLNXcKQqfDNuVc54AtGno/Kd+sUQvWYet6j8jYwaaT4oUvnBIVfZE59vofVHpQE2ZNvGs7Ao1kQ== X-Google-Smtp-Source: AGHT+IFx36iGcWlSMjSVc0mxHQD4rz6X8t1d1y8vrbd7dLt9zpSN70tQoV8mAtThDKw5XmUrUQJA X-Received: by 2002:a50:8e55:0:b0:56d:c721:d0b2 with SMTP id 21-20020a508e55000000b0056dc721d0b2mr7534296edx.33.1712607432488; Mon, 08 Apr 2024 13:17:12 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id z22-20020a05640240d600b0056c3ae53842si3976051edb.263.2024.04.08.13.17.12; Mon, 08 Apr 2024 13:17:12 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@outlook.com header.s=selector1 header.b=gNWgD5RB; arc=fail (body hash mismatch); spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id F231668D3E1; Mon, 8 Apr 2024 23:16:05 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2068.outbound.protection.outlook.com [40.92.89.68]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 67CA868D3B8 for ; Mon, 8 Apr 2024 23:16:04 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KU3vIuQ0nRKhsJJ1dpncy8bNqqOXBSAl2HALXIuo4NEYAqWFD9OnRTLV/ZoatWWzUKtICyO9HbV7icQHL7vl9x3IDvuwg8WgqjWZDDJXSASq6183hpY7K8y1Q+MJp95TuHUYsWx8AGElxHgI6ZrgJtZJ/7bYkgP5JQsmv6ELKFNCIruVO0ZdUtnpWJVnAdoTWwont1/nYGGj1giiPykN9UmKbK8Fhku3dB6uSnGVE+sD0KtotQ74neTsZvO9BCROTcCPbHJJqy360x92h3vJVdGslyRe8mbhXHBxrMYtemjeK0NBdv/PoYqNu56piIec057zvaMO5io9zcIFOKNbrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CF/kcKZmITjEMC5XYUhrDW/tn1caAHY7O5c1UfVGFoc=; b=EiQQyK/f5pvBWIMjQ7vc9WrhvRGy6stTrgWx8UmRICIqO49byw0oc4/95Bd+Mebon9eZYhzromUnrV+6VeRTqLydsQjlmreGwhtC1NScfp+deEvO5+08jjkLQBrsW90rs0ChxLxyMhAcUmRl9hfelDxlqODbJlWrTLCnhFPd9ZfzpBCnPX9wLnmQ7rsc/2E9qLtbqQ/yyFr6cBUO0kM7wLpvDzoooBICZoaL6RSHSPWvkQBQbs3rYMxwiGmvfcppX3gPnPcRrjFsNlirBHvYefdPkymH/lzEPpQizA0qMZVvwflsbZjsMSaBWYfWd6mTmeJpiqqwRI2SA34PMBYJlQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CF/kcKZmITjEMC5XYUhrDW/tn1caAHY7O5c1UfVGFoc=; b=gNWgD5RBi6WEU2ESLAfAGLK9Wr5fsipxTi3/lg29llYFnvo48+k7Asto0JCek9dfwnM8tdAaobbS76mclrk2MKVfxbkvNCVlPOvlNNI+npqnG3m4e9v8t2mopTq0ybCOexIzjE1Vm5UyBuHWJwRp8LRHYmtli7HqTYvW8r/ueIityEiLcpZDMRR+K5rV4YwCqVZd8xPLs4n0ClJu5BVvLpPdhPXgrq1oAcaTcXLv93DOzpWqMyRU0g/DFLlGyxCN7Kah4wCrvGWFBtUGZoe9K9Xg501qhqfEXNNsI98oUX28MRkNhveVHfz7PEK6M4yUI/0Z/x7iV3MfqIabvhCLHw== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by AM8P250MB0171.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:322::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7409.46; Mon, 8 Apr 2024 20:16:02 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::4a3b:cf76:cddc:c68d]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::4a3b:cf76:cddc:c68d%4]) with mapi id 15.20.7409.042; Mon, 8 Apr 2024 20:16:02 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 8 Apr 2024 22:13:58 +0200 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [zFCDuV5+fvGiaXx5AN3OTrXejzgSgPcMg5LzBwltmIY=] X-ClientProxiedBy: ZR0P278CA0124.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:20::21) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20240408201405.2136840-19-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|AM8P250MB0171:EE_ X-MS-Office365-Filtering-Correlation-Id: 94f74e8d-eec5-46d2-f3d2-08dc5808b664 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Fo7VLYb9ncv9QnS25f/shp1UUgX1As0mPlVp7xd/sLxGes32DrtGWRuko5/4r0SmITfNiemRFWq1NT2oOdR8LZmNjfXMhXWt/YeDQd0WwgTU+bOhYIJDgrGjc6xKHPUyeWmDPXeFlvKWyXc9eo6lCrPoy9mdCCl+25sUqMxNFg8VxMbiztH2jiq2IIlHNol+CVuWnQX1MGZJBIsdbIVcTJBxkESGEaxiwMzDz8YfQwcy64fPIVPlUqnVv5X4H0QQdTptmy/laymtxF45yRj1WV/GuhwpLv9hAifhcXbWxPykuVDJKcHRDCA/4Bp/70BARa1XIM4Pajd4eYoL3yClGYys4PL/IdG/zusN3vkOLGUZjUtEfqvmOlmKnSb5xUXbwSp6iETmd5ue+fEdCfEnhcCcSGvF5+s21xPw3CwFCaqzRY2iCMrFsMoawzBrrxbIWhVcsXkagIfX0EShs/c37v7aXHoUh2LvZnBAL5BHirhij2/VE9sF2xC/uRN7QM31a/3crCirNthFWIggi5fnkRbnKcb57FcABNTiHwdvZgndGJT0pStpMGmvBPiqiRQDmzBqeRugewEIevzbv6Hf9DM8d0WVyVYB/o6OdN3uOZ40pEDA5H03XD/sDp5t1080 X-MS-Exchange-AntiSpam-MessageData-ChunkCount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LKWVCCkt7y1xrXQRVNWkmQGSGtx+3caI8KIHNbF6fLnKqt1TUmDy/iZqTyeYzPIGnk8QjsvPRn4ERYJEp1hUJ5v1KpyyY/OZJavq8TUEfVUw1sb5ObClZoF1cmiss6AHBrX4HBR8QN04OrNsbzmRx0vOn0h9MUXGoRIXDSUpLxlo94LMSea/8vC2r4iF+nt1DWwXDeR9AEpJ5wyV6vqGHjgFCmjqT0QJMvY/+7W5NDyMpkBQ6wexq9Q== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 94f74e8d-eec5-46d2-f3d2-08dc5808b664 X-MS-Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 08 Apr 2024 20:16:02.4407 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM8P250MB0171 Subject: [FFmpeg-devel] [PATCH v2 20/27] avcodec/pngdec: Switch to ProgressFrames 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: n8gdK0HdyBOF Avoids implicit av_frame_ref() and therefore allocations and error checks. It also avoids explicitly allocating the AVFrames (done implicitly when getting the buffer). Signed-off-by: Andreas Rheinhardt --- libavcodec/pngdec.c | 67 ++++++++++++++++++--------------------------- 1 file changed, 27 insertions(+), 40 deletions(-) diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index 5a99b4a1c4..f7751223b8 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -42,8 +42,8 @@ #include "apng.h" #include "png.h" #include "pngdsp.h" +#include "progressframe.h" #include "thread.h" -#include "threadframe.h" #include "zlib_wrapper.h" #include @@ -63,8 +63,8 @@ typedef struct PNGDecContext { AVCodecContext *avctx; GetByteContext gb; - ThreadFrame last_picture; - ThreadFrame picture; + ProgressFrame last_picture; + ProgressFrame picture; AVDictionary *frame_metadata; @@ -874,7 +874,7 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, s->bpp += byte_depth; } - ff_thread_release_ext_buffer(&s->picture); + ff_progress_frame_unref(&s->picture); if (s->dispose_op == APNG_DISPOSE_OP_PREVIOUS) { /* We only need a buffer for the current picture. */ ret = ff_thread_get_buffer(avctx, p, 0); @@ -883,8 +883,8 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, } else if (s->dispose_op == APNG_DISPOSE_OP_BACKGROUND) { /* We need a buffer for the current picture as well as * a buffer for the reference to retain. */ - ret = ff_thread_get_ext_buffer(avctx, &s->picture, - AV_GET_BUFFER_FLAG_REF); + ret = ff_progress_frame_get_buffer(avctx, &s->picture, + AV_GET_BUFFER_FLAG_REF); if (ret < 0) return ret; ret = ff_thread_get_buffer(avctx, p, 0); @@ -892,8 +892,9 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, return ret; } else { /* The picture output this time and the reference to retain coincide. */ - if ((ret = ff_thread_get_ext_buffer(avctx, &s->picture, - AV_GET_BUFFER_FLAG_REF)) < 0) + ret = ff_progress_frame_get_buffer(avctx, &s->picture, + AV_GET_BUFFER_FLAG_REF); + if (ret < 0) return ret; ret = av_frame_ref(p, s->picture.f); if (ret < 0) @@ -1254,7 +1255,7 @@ static void handle_p_frame_png(PNGDecContext *s, AVFrame *p) ls = FFMIN(ls, s->width * s->bpp); - ff_thread_await_progress(&s->last_picture, INT_MAX, 0); + ff_progress_frame_await(&s->last_picture, INT_MAX); for (j = 0; j < s->height; j++) { for (i = 0; i < ls; i++) pd[i] += pd_last[i]; @@ -1286,7 +1287,7 @@ static int handle_p_frame_apng(AVCodecContext *avctx, PNGDecContext *s, return AVERROR_PATCHWELCOME; } - ff_thread_await_progress(&s->last_picture, INT_MAX, 0); + ff_progress_frame_await(&s->last_picture, INT_MAX); // copy unchanged rectangles from the last frame for (y = 0; y < s->y_offset; y++) @@ -1674,7 +1675,7 @@ exit_loop: } /* handle P-frames only if a predecessor frame is available */ - if (s->last_picture.f->data[0]) { + if (s->last_picture.f) { if ( !(avpkt->flags & AV_PKT_FLAG_KEY) && avctx->codec_tag != AV_RL32("MPNG") && s->last_picture.f->width == p->width && s->last_picture.f->height== p->height @@ -1691,12 +1692,11 @@ exit_loop: if (CONFIG_APNG_DECODER && s->dispose_op == APNG_DISPOSE_OP_BACKGROUND) apng_reset_background(s, p); - ff_thread_report_progress(&s->picture, INT_MAX, 0); - - return 0; - + ret = 0; fail: - ff_thread_report_progress(&s->picture, INT_MAX, 0); + if (s->picture.f) + ff_progress_frame_report(&s->picture, INT_MAX); + return ret; } @@ -1783,8 +1783,8 @@ static int decode_frame_png(AVCodecContext *avctx, AVFrame *p, goto the_end; if (!(avctx->active_thread_type & FF_THREAD_FRAME)) { - ff_thread_release_ext_buffer(&s->last_picture); - FFSWAP(ThreadFrame, s->picture, s->last_picture); + ff_progress_frame_unref(&s->last_picture); + FFSWAP(ProgressFrame, s->picture, s->last_picture); } *got_frame = 1; @@ -1835,12 +1835,9 @@ static int decode_frame_apng(AVCodecContext *avctx, AVFrame *p, return ret; if (!(avctx->active_thread_type & FF_THREAD_FRAME)) { - if (s->dispose_op == APNG_DISPOSE_OP_PREVIOUS) { - ff_thread_release_ext_buffer(&s->picture); - } else { - ff_thread_release_ext_buffer(&s->last_picture); - FFSWAP(ThreadFrame, s->picture, s->last_picture); - } + if (s->dispose_op != APNG_DISPOSE_OP_PREVIOUS) + FFSWAP(ProgressFrame, s->picture, s->last_picture); + ff_progress_frame_unref(&s->picture); } *got_frame = 1; @@ -1853,8 +1850,7 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) { PNGDecContext *psrc = src->priv_data; PNGDecContext *pdst = dst->priv_data; - ThreadFrame *src_frame = NULL; - int ret; + const ProgressFrame *src_frame; if (dst == src) return 0; @@ -1879,12 +1875,7 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) src_frame = psrc->dispose_op == APNG_DISPOSE_OP_PREVIOUS ? &psrc->last_picture : &psrc->picture; - ff_thread_release_ext_buffer(&pdst->last_picture); - if (src_frame && src_frame->f->data[0]) { - ret = ff_thread_ref_frame(&pdst->last_picture, src_frame); - if (ret < 0) - return ret; - } + ff_progress_frame_replace(&pdst->last_picture, src_frame); return 0; } @@ -1895,10 +1886,6 @@ static av_cold int png_dec_init(AVCodecContext *avctx) PNGDecContext *s = avctx->priv_data; s->avctx = avctx; - s->last_picture.f = av_frame_alloc(); - s->picture.f = av_frame_alloc(); - if (!s->last_picture.f || !s->picture.f) - return AVERROR(ENOMEM); ff_pngdsp_init(&s->dsp); @@ -1909,10 +1896,8 @@ static av_cold int png_dec_end(AVCodecContext *avctx) { PNGDecContext *s = avctx->priv_data; - ff_thread_release_ext_buffer(&s->last_picture); - av_frame_free(&s->last_picture.f); - ff_thread_release_ext_buffer(&s->picture); - av_frame_free(&s->picture.f); + ff_progress_frame_unref(&s->last_picture); + ff_progress_frame_unref(&s->picture); av_freep(&s->buffer); s->buffer_size = 0; av_freep(&s->last_row); @@ -1940,6 +1925,7 @@ const FFCodec ff_apng_decoder = { UPDATE_THREAD_CONTEXT(update_thread_context), .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS, .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | + FF_CODEC_CAP_USES_PROGRESSFRAMES | FF_CODEC_CAP_ICC_PROFILES, }; #endif @@ -1958,6 +1944,7 @@ const FFCodec ff_png_decoder = { .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS, .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | FF_CODEC_CAP_INIT_CLEANUP | + FF_CODEC_CAP_USES_PROGRESSFRAMES | FF_CODEC_CAP_ICC_PROFILES, }; #endif