From patchwork Mon May 31 07:55:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 27995 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp2656703iof; Mon, 31 May 2021 00:57:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyjCvS0CH9ws2687bMNPVNOZJb83Ee1d4h2BRKncsw4AvgjGAbDaLOy+mKs4W61+QbRIX32 X-Received: by 2002:a05:6402:3495:: with SMTP id v21mr17919593edc.185.1622447825094; Mon, 31 May 2021 00:57:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1622447825; cv=none; d=google.com; s=arc-20160816; b=KFVLMwb6VJGBanlFn/kSpcTBKnXd/7zSoE2hUoI6q4HWK1vLTwlgwTP5Z2lidAojIA 7oq4d9aUxuod9g9ReqiYo3svIyKRql+3OEYx3f4u1X3SY3ZBoczBuREH1/0NY3ug58xY ZDY36zQxeH6am/cDb2Js1gkuheMxr/CoTbT7SDpkKLBTrJ7WmHLlY1K5UNCHgHEugliN f2y5tQ6F8TflWakvXAu9Pds+N//CB3JivDE6nMMAy4YCaoQes5jq6MBk5lq7GQEAB+Wy ENofz4jCBKXRHyn11YmCuP8Q9rlTgUtuB2AHi2v/umWnk3L/L9qhoKdTY9h2dbGLvQGi NBsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:delivered-to; bh=LhhhNSwY03cgT9P6YL7e3Ew+3JK8Hdk1DLxL/2GJ5G4=; b=ucSK0x033ifvUcAFytFKRuEBD73ueXXahf8yjDcNpqBb3UxaTr56Z7k7sdaB9UjmRZ 027T0HpcO6zVqf47AWlj2uqLv+QTfMwy/7xb6OXxcCTzvpdHtky4/jXb8qdP0tgvoLwY t+mdej3fvuLX0VFfFb5iNtRqodu+HMReTyZk7WkLASoSgULklwLzQv8BU0Ddl/Efr0Gm PJh9/dAjBUDdPr+h1L36oD2v77MYNwuYNfyM34wVl8rGJSaGZFUPaacme+qmur8kTHK7 Fk2WaOfYo7TETD8XJQDLCmWmZMfLxi/F9ATL/rNDRQRfNZEbK+UXWW/DrPZ/sWyVeofm kPig== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s3si10969853edd.497.2021.05.31.00.57.03; Mon, 31 May 2021 00:57:05 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id D6CE768979B; Mon, 31 May 2021 10:55:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F08B6687FE1 for ; Mon, 31 May 2021 10:55:28 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id AA4E4240476 for ; Mon, 31 May 2021 09:55:25 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id n3ZNpZxfx-Zh for ; Mon, 31 May 2021 09:55:25 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 2520924069C for ; Mon, 31 May 2021 09:55:22 +0200 (CEST) Received: by libav.khirnov.net (Postfix, from userid 1000) id 0551F3A15EB; Mon, 31 May 2021 09:55:21 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Mon, 31 May 2021 09:55:02 +0200 Message-Id: <20210531075515.19544-11-anton@khirnov.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210531075515.19544-1-anton@khirnov.net> References: <20210531075515.19544-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 11/24] sws: do not reallocate scratch buffers for each slice 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: il4mNRRuLOt0 --- libswscale/swscale.c | 20 ++++++++++++-------- libswscale/swscale_internal.h | 6 ++++++ libswscale/utils.c | 3 +++ 3 files changed, 21 insertions(+), 8 deletions(-) diff --git a/libswscale/swscale.c b/libswscale/swscale.c index 37c7cf60dd..2db40a6807 100644 --- a/libswscale/swscale.c +++ b/libswscale/swscale.c @@ -871,7 +871,6 @@ int attribute_align_arg sws_scale(struct SwsContext *c, int i, ret; const uint8_t *src2[4]; uint8_t *dst2[4]; - uint8_t *rgb0_tmp = NULL; int macro_height = isBayer(c->srcFormat) ? 2 : (1 << c->chrSrcVSubSample); // copy strides, so they can safely be modified int srcStride2[4]; @@ -928,11 +927,14 @@ int attribute_align_arg sws_scale(struct SwsContext *c, if (c->src0Alpha && !c->dst0Alpha && isALPHA(c->dstFormat)) { uint8_t *base; int x,y; - rgb0_tmp = av_malloc(FFABS(srcStride[0]) * srcSliceH + 32); - if (!rgb0_tmp) + + av_fast_malloc(&c->rgb0_scratch, &c->rgb0_scratch_allocated, + FFABS(srcStride[0]) * srcSliceH + 32); + if (!c->rgb0_scratch) return AVERROR(ENOMEM); - base = srcStride[0] < 0 ? rgb0_tmp - srcStride[0] * (srcSliceH-1) : rgb0_tmp; + base = srcStride[0] < 0 ? c->rgb0_scratch - srcStride[0] * (srcSliceH-1) : + c->rgb0_scratch; for (y=0; ysrcW); for (x=c->src0Alpha-1; x<4*c->srcW; x+=4) { @@ -944,11 +946,14 @@ int attribute_align_arg sws_scale(struct SwsContext *c, if (c->srcXYZ && !(c->dstXYZ && c->srcW==c->dstW && c->srcH==c->dstH)) { uint8_t *base; - rgb0_tmp = av_malloc(FFABS(srcStride[0]) * srcSliceH + 32); - if (!rgb0_tmp) + + av_fast_malloc(&c->xyz_scratch, &c->xyz_scratch_allocated, + FFABS(srcStride[0]) * srcSliceH + 32); + if (!c->xyz_scratch) return AVERROR(ENOMEM); - base = srcStride[0] < 0 ? rgb0_tmp - srcStride[0] * (srcSliceH-1) : rgb0_tmp; + base = srcStride[0] < 0 ? c->xyz_scratch - srcStride[0] * (srcSliceH-1) : + c->xyz_scratch; xyz12Torgb48(c, (uint16_t*)base, (const uint16_t*)src2[0], srcStride[0]/2, srcSliceH); src2[0] = base; @@ -996,6 +1001,5 @@ int attribute_align_arg sws_scale(struct SwsContext *c, rgb48Toxyz12(c, dst16, dst16, dstStride2[0]/2, ret); } - av_free(rgb0_tmp); return ret; } diff --git a/libswscale/swscale_internal.h b/libswscale/swscale_internal.h index a1de95cee0..e8a434427b 100644 --- a/libswscale/swscale_internal.h +++ b/libswscale/swscale_internal.h @@ -626,6 +626,12 @@ typedef struct SwsContext { SwsDither dither; SwsAlphaBlend alphablend; + + uint8_t *rgb0_scratch; + unsigned int rgb0_scratch_allocated; + + uint8_t *xyz_scratch; + unsigned int xyz_scratch_allocated; } SwsContext; //FIXME check init (where 0) diff --git a/libswscale/utils.c b/libswscale/utils.c index 6bac7b658d..d45d7afcbf 100644 --- a/libswscale/utils.c +++ b/libswscale/utils.c @@ -2293,6 +2293,9 @@ void sws_freeContext(SwsContext *c) av_freep(&c->gamma); av_freep(&c->inv_gamma); + av_freep(&c->rgb0_scratch); + av_freep(&c->xyz_scratch); + ff_free_filters(c); av_free(c);