From patchwork Mon Nov 21 01:07:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 39371 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp1833108pzb; Sun, 20 Nov 2022 17:07:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf4M9CukIXfYE4f5iYQhy9z1PwpANdiK9tAUrkmQ4GJ+cyqDV6X4pYhF6W9wbSjtFEwhxGPl X-Received: by 2002:a17:906:9f02:b0:7b5:f5c9:b450 with SMTP id fy2-20020a1709069f0200b007b5f5c9b450mr2690859ejc.65.1668992858105; Sun, 20 Nov 2022 17:07:38 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id f21-20020a0564021e9500b0045c3f6adb7csi9214389edf.215.2022.11.20.17.07.37; Sun, 20 Nov 2022 17:07:38 -0800 (PST) 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=hIE0aKIB; 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 8E83E68BCFC; Mon, 21 Nov 2022 03:07:27 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-AM0-obe.outbound.protection.outlook.com (mail-am0eur02olkn2059.outbound.protection.outlook.com [40.92.49.59]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 21F8768BCF0 for ; Mon, 21 Nov 2022 03:07:21 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=njoNyOTcrnEWnN9aK1MkhGeL8i6zc48WyGEzQP1cEDDy12obQkzY9baUtO0ce9xVWgdmEUBPz/Qmda8vrrIe0K1VcmuMt86JpkaVi40hOKnLxioj+RREvhSkfU/2Zt1hjTMQ4kNwDeVTgZdN/R6bny4AQfA2q3XDtHgYS9S42f3ZmRUf6vsX6nYIpcW/ZyhR7gscnfAnZoUe5R6B0xJAb0sUY3VqydbwvRj+mfzpf1+zpCxsE0yUrpLj5uizp7essdLsudppbPLyyI4wYUoM/7emI/Zd8us12nMTazizJ/MF0UH73eXaem/kG931aI6l/Lb46wWjK9fz5C50yAG1dw== 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=QOwbpkQjeySyR5Uff10erHqKfDfTXcIkUuygMdhwuqo=; b=HSF/jJb1VkXyZG/Jy7osY/kjnCG2tBC2Ok3DzLdIKI4bjfzrvwtNwcqMsXtQH42ktyZd7atlyge4OgOrxJmI5CE5meQeLBfiy3O/fFF78IpYowA5AvQ+FTuGZPBLN4TEd7w3nleh14DAY+UMdAjQiou+/8sUMStxBJjpR5gSNOz6El37uULrjdAm/Rkly1mHTYIPDtH4f9fw6dO69UuD6dZJM9lE1vvKwzwgl1da65uTohS2Hlsst7jpd/5dIBno7U8Ax3Cyod6bO/7WUNncCo6u5+GOGCP65o1VN8rpkP4a2jRrE3+4bio+svz+XXMuA3wntKkLiYHtMhuyyxWwjQ== 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=QOwbpkQjeySyR5Uff10erHqKfDfTXcIkUuygMdhwuqo=; b=hIE0aKIBQgy6FcemMkAEWzz/DdVHSsQJI9yLK/UiBwDa1FyRa45bZuxLsPiKFINvxJdOi27ubxxHs42csPksaRy38/XH3GYbwgktlTleA1RKfvzt2sLSYV4mVKN/eLDFCsqqu953aqQtdwMlUyXrM8XyIzqvB/xXYe68MWT2vAJMID6JEClWQDsF89E6aUZcnHrC7dzKogU8AtkJrAYIqx9c2L0WvygSD9ttWwjJ7nKFAZftj/QoLNv+OLhjlObfaQHNdaIae3x4VgygDQlzMrMlmLnjA+3oSqiPnCwq4xMjaAoORsltbmQy0TEQM3yg7zp2YrLMxC1DakNCUmxcag== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by PRAP250MB0465.EURP250.PROD.OUTLOOK.COM (2603:10a6:102:278::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5834.15; Mon, 21 Nov 2022 01:07:08 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::c37:cabe:316a:60b2]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::c37:cabe:316a:60b2%4]) with mapi id 15.20.5834.011; Mon, 21 Nov 2022 01:07:08 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 21 Nov 2022 02:07:15 +0100 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [B3pfj1G5UwS9ERk72kKmApS7wdQ9yRBitca+P50USp0=] X-ClientProxiedBy: FR0P281CA0075.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:1e::10) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20221121010716.2131624-4-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|PRAP250MB0465:EE_ X-MS-Office365-Filtering-Correlation-Id: 18cefafd-2656-4dbd-68f3-08dacb5cb689 X-MS-Exchange-SLBlob-MailProps: EgT5Wr3QDKw9/h+mHxnUXPC9/FuzQkCXCWSV0A+Ps+2JN0s+7c94ubJ5WwbTe3ZrJCXSwhATt+Pbk/L1QnJxfKwEfDsPe9agmrpcBwlKrOiMqEfc0xsLOiQA135FOe9q89qs/gbDcQZLFNcLqx7wQCfzB8vRdrKfnb64v/pTQ7vftF188y3pTV/Xb50VvlfR4epPiLti0vMHaXdAXfl0nC52W3IUR61eT1SWF8xvd/ZGLOzHVKiOltnf0vVjFN2UiaaxwA3ZOTgyitv/sjVOVTTjdB4WJwuDfPwamzcMrEAJokNpCxLgBL4nhk+WPLKETkRNAuQVTCAj991Uqs4seUagk8qTG1zG2ehFZrdtCpIv/xUf+rdFdaK8GlJkHpBYZIdDxCwGDcMPqk9Qp3XotrEGgPZEZuNy0h/FEhVB2kIeVU8dD+My9vJGVEeWHc888NTHQzlFaEWCYX+dr4jCnTqywG3uSb+Uer3kK3RHL5+oKjyBnDmXLhVDs884gZwgvDhzxQNHAnFNzhkKYFHV0tJx+mSwwnsjljEFnL7X1qw44U7bmzypdHrUgqrNSxGaDm5NhTH8tCHfxvki8DxAeH1iNgQVGeqMlUJU+pYjJKFgnOtZ9wSAGMSA/DsCcB3YP606YKMFsdj7NEEUz8SB+YDcTl/MK7ZqwDykMtuGfK1c8GyLV2E4XgWvnl/bKDXFwT77Zc0m6SFt4yUW+seW9jAiWu/k4wpdEa7hCO97mLk= X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JOOqt9yQCdK6cy6oZsTfHsWej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AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2022 01:07:08.7796 (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: PRAP250MB0465 Subject: [FFmpeg-devel] [PATCH v2 5/6] avcodec/flashsvenc: Avoid copying frame 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: K6gWIwYwd99E Signed-off-by: Andreas Rheinhardt --- libavcodec/flashsvenc.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/libavcodec/flashsvenc.c b/libavcodec/flashsvenc.c index ba693ca8f3..c4b16dff84 100644 --- a/libavcodec/flashsvenc.c +++ b/libavcodec/flashsvenc.c @@ -44,10 +44,11 @@ * Speed up. Make the difference check faster. */ -#include -#include +#include #include +#include "libavutil/buffer.h" + #include "avcodec.h" #include "codec_internal.h" #include "encode.h" @@ -60,7 +61,8 @@ typedef struct FlashSVContext { AVCodecContext *avctx; - uint8_t *previous_frame; + const uint8_t *previous_frame; + AVBufferRef *prev_frame_buf; int image_width, image_height; unsigned packet_size; int block_width, block_height; @@ -93,7 +95,7 @@ static av_cold int flashsv_encode_end(AVCodecContext *avctx) { FlashSVContext *s = avctx->priv_data; - av_freep(&s->previous_frame); + av_buffer_unref(&s->prev_frame_buf); return 0; } @@ -203,26 +205,17 @@ static int flashsv_encode_frame(AVCodecContext *avctx, AVPacket *pkt, { FlashSVContext * const s = avctx->priv_data; const AVFrame * const p = pict; - const uint8_t *pfptr; + const uint8_t *prev_frame = s->previous_frame; int res; int I_frame = 0; int opt_w = 4, opt_h = 4; /* First frame needs to be a keyframe */ if (!s->previous_frame) { - s->previous_frame = av_mallocz(FFABS(p->linesize[0]) * s->image_height); - if (!s->previous_frame) { - av_log(avctx, AV_LOG_ERROR, "Memory allocation failed.\n"); - return AVERROR(ENOMEM); - } + prev_frame = pict->data[0]; I_frame = 1; } - if (p->linesize[0] < 0) - pfptr = s->previous_frame - (s->image_height - 1) * p->linesize[0]; - else - pfptr = s->previous_frame; - /* Check the placement of keyframes */ if (avctx->gop_size > 0 && avctx->frame_number >= s->last_key_frame + avctx->gop_size) { @@ -234,15 +227,7 @@ static int flashsv_encode_frame(AVCodecContext *avctx, AVPacket *pkt, return res; pkt->size = encode_bitstream(s, p, pkt->data, pkt->size, opt_w * 16, opt_h * 16, - pfptr, &I_frame); - - //save the current frame - if (p->linesize[0] > 0) - memcpy(s->previous_frame, p->data[0], s->image_height * p->linesize[0]); - else - memcpy(s->previous_frame, - p->data[0] + p->linesize[0] * (s->image_height - 1), - s->image_height * FFABS(p->linesize[0])); + prev_frame, &I_frame); //mark the frame type so the muxer can mux it correctly if (I_frame) { @@ -254,6 +239,12 @@ static int flashsv_encode_frame(AVCodecContext *avctx, AVPacket *pkt, pkt->flags |= AV_PKT_FLAG_KEY; *got_packet = 1; + //save the current frame + res = av_buffer_replace(&s->prev_frame_buf, pict->buf[0]); + if (res < 0) + return res; + s->previous_frame = pict->data[0]; + return 0; }