From patchwork Sat Nov 19 02:59:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 39339 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp773386pzb; Fri, 18 Nov 2022 19:00:28 -0800 (PST) X-Google-Smtp-Source: AA0mqf4M366RYmifQRdR6QXqgwjV6LJ7ABdYz4l3i0HZwFVolJkXEWNJ5UUki9nNU0c3km0pS2Ac X-Received: by 2002:a17:906:a113:b0:7b2:7c9a:1849 with SMTP id t19-20020a170906a11300b007b27c9a1849mr8121152ejy.733.1668826828252; Fri, 18 Nov 2022 19:00:28 -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 dd17-20020a1709069b9100b0078d93325645si4541702ejc.405.2022.11.18.19.00.27; Fri, 18 Nov 2022 19:00:28 -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="pZl/V1Ze"; 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 2849C68BC2D; Sat, 19 Nov 2022 05:00:10 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2057.outbound.protection.outlook.com [40.92.89.57]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9A67468BBE3 for ; Sat, 19 Nov 2022 05:00:07 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ThqUS3dwbxmW4TQM8W++Mgf80EGeQpRLk3XZUDHA/A1ReIppeLFu0X40EIzZc7TbPeds6Ow+twKTGkbL6rSjBQAj3a4sdqiJUZHgkJKEpugiwTPWpvtz+ZKmssPtIHxonvm7/N8XcBgrqW6acBgXSSZlctw2mcgxzikSBafeQuMqYc+5c25SFWZrjDkwwtXtdzcTwHO5q1Xvgt9e8Q+f8TifWQKP4C8/59Ng6cN/hx0NgN8sBg8wIRnrQX0cVH0xRsww6UjE8eaCGG+/fRpTBfixWcY+JAQQ9Dw0XABs28Wq1XhwDSSS10I2kgyNq0iCD7SRptdAKFNwcB0bpVJnSQ== 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=MIXn+qJNpjmY6WYXOthocVLlmFznM1y1fBtqP+OG2DA=; b=g8kgk2MxArJ7PNatv7VP9H6cbgc91rlcayZJwNDnwf1pQOFho6uJbHB6lK2B/rKTueEfk6U1dwu8tWyBxouqiWcA46TV1iA8z1Km1aHpw4rUxnubTRWzBht+hJp1LjRYfhl2ZgOr+VaIraJZTaTOxngIkSsQp1EEsUVpqUtPpJWl8o3RVG4wjCFh5Jcifn7CorCvi4qxKnj/Kd3eCQAb0XuOk0WIYIdIhIll1dxsNr960qiHDFO7t0oiQyWn00YbIRTmyEVlma716Gvkymtkw+zOrw2l3M3yNB8LCQAeur824ah8yRA6YLO/et75jpcuxgogF8Hnq0fliI5nPzPLbQ== 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=MIXn+qJNpjmY6WYXOthocVLlmFznM1y1fBtqP+OG2DA=; b=pZl/V1ZeaDvn/n5FJSUBPzudI26KqQ7iOOrFgQjAeREyGie8qLKCnVhhzH8g5kra1ieXHk1UVSA/nmmiGl5RSqoHnMrbfo3853/8MoB3W5kfJtv2wMH8VYWOm+idUxaYa5ZT3DyGsAcwmHusUxb/0lN/fHFUELz0EC6cbjyTxcbbXGzbvQcRTzhORdgRy2B6EqSu7zUsi/ganRbGVNbDm9hpLyKZ4gMYNjlBLjQK4BIYIUdBNDpY1eb7qFlEmLSHiKE3SlmVReZYfOC4ZNyF3QfgOhe9yqUIi3ssLko+19jVyKHMijoub05vMWX519PHqv2BWIgIyFykgUy14kJ8jw== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0127.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:270::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5834.9; Sat, 19 Nov 2022 02:59:53 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5188:7559:45ea:5f52]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5188:7559:45ea:5f52%5]) with mapi id 15.20.5813.018; Sat, 19 Nov 2022 02:59:53 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 19 Nov 2022 03:59:54 +0100 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [+A9i+1HvohepB9wGoovjYEN9SbsWPQBVU4ILnnvB4pE=] X-ClientProxiedBy: FR2P281CA0044.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:92::18) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20221119025955.1758795-5-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0127:EE_ X-MS-Office365-Filtering-Correlation-Id: be369ffa-8a86-4757-50d4-08dac9da21dc X-MS-Exchange-SLBlob-MailProps: EgT5Wr3QDKzQ+EiUC8SRy4slEJiQUIdM0XCSjL6oTNrhKLxclXxawG86UjDc10MtcXYJheNXeiXo1V2CRjYjXshrsceEZO8I7rLNbQwiV4ltOxe9+ajNXuV5GKMxBZE4ajVTSIwghbEXWBUc0ERsVvZF/8YbQXWmTJdZjSAll/m4ckpNStrn7QJ9qGJoQLndwcjqTvsLkN5wYkZstdvgun+O+4KQ00HVP/J6KmG4gaD+A7pgQtD3Rpj2fX/xmIx8OMkmaj+Io9Ob+/xctvzbDUKgCwF0orMKs0CMtfzut7JvGKXENehf1l8giyOUYTAi8QQt6UAamZoB22Msg7ABnCwYPF3SG4JztD8kdjJEYvgp1njxeoAV2PpDrFT6n0PA85lH25yQWtsFs6V7mNBdZiH8y30gsIVss3nWy+rfGrX1gWHflmUf8GaHiuobdjs6c00iLvrqkNI8bwsowVGgB3a8FLpooK1mhyhsN5db99gSOsxmq6zmsQRlRTdj7ZuOlXmYSNoCqxu1ZhTXtTpZdjetcqbnmmYmQPGPJROJwVYRoGETbWHV99aE4n89YPsjUzreVTvH144Wn/r9AQXkPw22m+FrOqwhGaWYw/Fnqg1MIfCDCHBXDIi2gk1YKHrfGSZHXd4XGNfuNpv39ez54t/CdO6kiUyaNNNWTSB83KEcDaHeGgXR3hcUGQEDr8RC9l/wz8gbYATJz+oyf8gc6Qa9QRQdKpEv87Y3Hzp0Eic= X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PscsH+ylJn+2Yu98IhxJhD/QBOUT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uthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Nov 2022 02:59:53.6361 (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: DU2P250MB0127 Subject: [FFmpeg-devel] [PATCH 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: JoBxZygr/tyQ Signed-off-by: Andreas Rheinhardt --- libavcodec/flashsvenc.c | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/libavcodec/flashsvenc.c b/libavcodec/flashsvenc.c index f42ef73b37..3c3d9c8813 100644 --- a/libavcodec/flashsvenc.c +++ b/libavcodec/flashsvenc.c @@ -48,6 +48,8 @@ #include #include +#include "libavutil/buffer.h" + #include "avcodec.h" #include "codec_internal.h" #include "encode.h" @@ -58,6 +60,7 @@ typedef struct FlashSVContext { AVCodecContext *avctx; uint8_t *previous_frame; + AVBufferRef *prev_frame_buf; int image_width, image_height; int block_width, block_height; int block_size; @@ -89,7 +92,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 +196,19 @@ static int flashsv_encode_frame(AVCodecContext *avctx, AVPacket *pkt, { FlashSVContext * const s = avctx->priv_data; const AVFrame * const p = pict; - const uint8_t *pfptr; 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"); + if (!s->prev_frame_buf) { + s->prev_frame_buf = av_buffer_ref(pict->buf[0]); + if (!s->prev_frame_buf) return AVERROR(ENOMEM); - } + s->previous_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 +220,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])); + s->previous_frame, &I_frame); //mark the frame type so the muxer can mux it correctly if (I_frame) { @@ -244,6 +232,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; }