From patchwork Mon Nov 21 00:08:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 39360 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp1808960pzb; Sun, 20 Nov 2022 16:08:35 -0800 (PST) X-Google-Smtp-Source: AA0mqf4K/OEOiKvqIxbwjSH0mvLH/3sXhL9yisNVxuakE5DvGWjgwC65Vt4e3up/vdUxszzGGdXV X-Received: by 2002:a17:907:8b14:b0:7b5:addd:ea67 with SMTP id sz20-20020a1709078b1400b007b5adddea67mr3160231ejc.11.1668989315570; Sun, 20 Nov 2022 16:08:35 -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 rh16-20020a17090720f000b007ae61d89b4bsi6202485ejb.283.2022.11.20.16.08.34; Sun, 20 Nov 2022 16:08:35 -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="ojcWGn/T"; 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 B95A268BC30; Mon, 21 Nov 2022 02:08:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03olkn2025.outbound.protection.outlook.com [40.92.59.25]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9E7B468B5DB for ; Mon, 21 Nov 2022 02:08:25 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JokYGB0kxaI0NfItR40MNb5GGjqlCIWz7hZOzAIwVN5kyUuvBtDbmz/EMQ1L2k43QYXVU+VeeN6y8h9YbFl52PVPIfurrOzrRuVi5q8AvOPCBsnPr3R5IHMTGgtk273aAQTcnR5n6tiblOzT7q/2kMcQ9mZgQLr9XRDtBBRe4pXHsjEeMpfFDwpS0KscxeISSLBKLoPnMbYHV2n/rGTrOKwD+6pAhRKULh1tL96yvPubsJKcpgCnf7aCxKQF/TC2+C0sTyhBX5+VcyetsMo3IJ1m6Hkovz4F0ArGy5Cja/XXGA6vuaoof21ioueM9VcuvPoZxMNUnqh6UNVoTOipmg== 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=RwZWxNUhFTDk7dHR29kpR5FSSOSfEmARBT0fVCfNdzI=; b=XHkMJjq0jE3raXJ8M5pJV0QfK2JBnbagXjARphPm8l70gcBpSLIqlFOKf0EqN/lAYn9qZYIZhKAxC7Mn4sxMfOSBMx2ikpb+DDgdXEpmhkl5Fmtmdaq1gzPpuZtkDnPDN8JzEheoRq2cshPqCYuwJ+AvGIq1zZ1OwhzkE0mR4bu67407XnkI+dXOAuwJflm0d1MO2m7DXqUIyUEhWtgTfoa9GuzsL5+sSELpIf0g1ozSQlyYGlqEBrU6VSpBVuGS+iWedo8k/4Xn9uDSpkb9y+P9zdzOX538wlBEP57sodjOjZgvlOd6KWykyK/pVrob6/73nk/C1uUOXkU/eJfwoA== 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=RwZWxNUhFTDk7dHR29kpR5FSSOSfEmARBT0fVCfNdzI=; b=ojcWGn/TKSHNOlPyzpeZ5s+Ei/p1iOebnstFrKeDC69wZ7EMxctVikctH73v1sx+fCapHDg6Y/DBb7CxnrcGCa8Qf7slEdU0FhNmeosTJJ624Tse3nc7jtOY87gBkrRdbfxv74Q/XtKt4x5iatjewGUhaoPVhtdGjTkt7lS6OTPS9Z7X1GmF81vma0aSfMJDBijn53AIawadukbjzAc0FXpfpC0Rlurc0vi6ksmZOFR3PEVi2ACeED+siwDVUrIU+wEriTVy4ryPtUNhldQqk+1p2xh6NcydjJAspB/MbqApP+KeBF+1OCTMrGHramxCpnwWR2hiIs/YcMt+Nh473g== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DB4P250MB0805.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:38f::16) 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 00:08:23 +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 00:08:23 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 21 Nov 2022 01:08:35 +0100 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [VVOOLFddW/rvi64kiOtlgx4VPMfV2ayEXu+1FVS7z2o=] X-ClientProxiedBy: FR3P281CA0149.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:95::20) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20221121000835.2127431-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DB4P250MB0805:EE_ X-MS-Office365-Filtering-Correlation-Id: 5f26ef53-6534-4a21-bbff-08dacb54814e X-MS-Exchange-SLBlob-MailProps: EgT5Wr3QDKw9/h+mHxnUXG9e+4x8F4ua3P7BXXzxcScs0fIbiGh38r4YbmFjB/AHDb+m8EZ6tupqPOX7fNHGIXwyllW2k49Vg1vbN4VT4ejAI+F1pAHbd0Wfrja95bTVU/Zqv2hwIkMrQkMN4EzGJjAXdHma/IrpEt0q0UZhmH0CBzGbzGRMUz+F/7/dImptXdY5XMQCIGclY6Q480ujXNemybbE4HmiZeDQs8mz2x1JFCQX6BvQIyDr6L9tMXfN9zAXtO0gFT4fcv+jOYtcj34LJX/kdBGX90eIPhx/Agm5GhZKf3x/dEBhkeQkj89F0prnsyj5knraJnv0SBJI+SuCZ9KFkurYDXFQFTb0AfYGd5y6ntnCg4ljMx1OgTqYy6o3j+ByaUuuHRiEw1Y5pCGUGV2hZ1BiCpazEaZQFztOPvD5za/ZKbhIPo8YqVQvaIeQFawW1ZIE0ljq6d9z1AXoNdI6r+7zI5fHK9suw8P699jRzr1ZWLjGXDsiB/YsBlKV3xAlNv6qoHo5Qx0M68UWU0qYCSr4Ou9d427vZWa5s/iIH0oRvY0tr4wLQG3mevfPceBkYVPr+UhwWzORmF8yLGkBoRrr+uboevpFp5kuwA5E7fM3CrGmanEMR3N1kA6qVj2EB7IfgtOqI71HSzPIc9ty46PDi/KvbUnkMHO9wowdKB4nIIrStApVzqSWsxTVRl1418HZbJ9BOBaHM8fXjTz/jflIJOXjW1bahr8= X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UqkS6J1D8VybqgSyxTkhDM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-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Nov 2022 00:08:23.6114 (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: DB4P250MB0805 Subject: [FFmpeg-devel] [PATCH v2 6/7] 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: FtiLgS7o+QYy 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 f42ef73b37..f3d95c3fe5 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" @@ -57,7 +58,8 @@ typedef struct FlashSVContext { AVCodecContext *avctx; - uint8_t *previous_frame; + const uint8_t *previous_frame; + AVBufferRef *prev_frame_buf; int image_width, image_height; int block_width, block_height; int block_size; @@ -89,7 +91,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; } @@ -193,26 +195,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) { @@ -224,15 +217,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) { @@ -244,6 +229,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; }