From patchwork Fri May 21 09:17:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 27881 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp341315iof; Fri, 21 May 2021 02:20:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxHZ9JglvRohO8uIXw0JXxpcDWNsaq0/xOhLpOOCtzHdGDJ4So7WBXuffi8GVoZajA5qkkM X-Received: by 2002:a17:907:20ce:: with SMTP id qq14mr9196305ejb.35.1621588848314; Fri, 21 May 2021 02:20:48 -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 gf2si6112141ejb.500.2021.05.21.02.20.48; Fri, 21 May 2021 02:20:48 -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=bVbENNX2; 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 899E7689DFA; Fri, 21 May 2021 12:18:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-oln040092073013.outbound.protection.outlook.com [40.92.73.13]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DAB91689D59 for ; Fri, 21 May 2021 12:18:21 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NBON14KvlZ5sGJdcUaouKTzUh5uQlpVxGkAHseJk0MI5py8kgAdMhAfYgwg/TO6F2Z9IcSs81++k8fnYCSI+RG0N/SMT4vFkRlsHMWkWqb6bWX8PPQjqwEb7gwH+PSLrd/lOQbxKR5n71ld9WsarK92bbqnGwoo9TUybBdPh7JjTjczTTIoUplXVOJmrJJm5Wk0MiqX7lED9MUoigSJD3Tc4kGvkNVyyUTr/T/uu6ruflJs4216rhf3oAKYzgvqbIS1lABwey2ZjT3zR0VgrM0FJ1PzTMSnsnbpWl1aH651hjklmD4/ebdfE8gQYfGY9Yqzjl4noBpY3SHv1YobpfQ== 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-SenderADCheck; bh=CECqiwKKg7g0siJHW13dbVO0UdVdtOYWQc3tlIcVFsE=; b=Tv6jN4R/lj00sslIOSPWMK4dkHlI30ziJdqKWOFWX+WANIjL9lWUCnS6e6h8gN0mfgODvdciZ1UxGVtroT27vl+LbUlsBTfQrGfCLc7jGv/d2Cm4tctR3MOKL51QrZSG+lcC/9GTVwAiwMEzeDdSVnTv3Abu9FyXsGsvIp4fy1liGDG/MS7fHTNHADqL/doVyo4xMlLh+2n2uo5M3cz4PMwSg6bHFAxy1+isk6K9RmRemjEkcxrv/Jtc4a2Lga0kRSrGedZ+q+IjYfQsEualS1ErtqrbUkOGhNd3YPTAmUtC1kGn4u7ZK07E4sK47yzQkfFU2z3IQVgmxpjlt9GqLQ== 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=CECqiwKKg7g0siJHW13dbVO0UdVdtOYWQc3tlIcVFsE=; b=bVbENNX25qhFnyZ3tzf+PH9z87C97WRtDiit4tV1vORL4nbCKgjgX25FFeHFKdIIXgIoQ/oA0HHUPGgqIHHs4Ae+j7EGIHu5Iq5Q3xlzyWhw6viSnExuHJNN9o6rRJkRmDS4Y1qa8HwVN4p/Q/bzmSqaoWVzF+j5Lx0uFJpz73SrbjXomvzrfG/MUGGNpF5TIH1FW+EMoj/S2T4uHRfY4KniBXpNtOTKCmFm/+3bUdj9hstpysEatJ69JEDaW/OIdfUSMCC+Hw+W3DFtB4/ExMBu8LkXQY4qK3VBP6PcYuLGqf4Y5cYjNq4Frw9ZPYvPkQqs1dqiB9HpyDTPkR1Uug== Received: from DB3EUR04FT030.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0c::47) by DB3EUR04HT167.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0c::372) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.25; Fri, 21 May 2021 09:18:20 +0000 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com (2a01:111:e400:7e0c::41) by DB3EUR04FT030.mail.protection.outlook.com (2a01:111:e400:7e0c::99) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4129.25 via Frontend Transport; Fri, 21 May 2021 09:18:19 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:7990BC2F557508C3ABD23E886FCD8CC1A20C8912095AA980435DC9286F1EBBB7; UpperCasedChecksum:5CB25AFEEC67D9D70D9E91650B201ED340E181FE5919F7BF39BC1AA38CD0BFFC; SizeAsReceived:7595; Count:48 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::f4cc:63fc:9cef:37fb]) by HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::f4cc:63fc:9cef:37fb%6]) with mapi id 15.20.4150.025; Fri, 21 May 2021 09:18:19 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 21 May 2021 11:17:20 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [31WJTO1n+O7JhnyGvZ4sTVJrDog7IrM4] X-ClientProxiedBy: PR0P264CA0070.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:1d::34) To HE1PR0301MB2154.eurprd03.prod.outlook.com (2603:10a6:3:2a::22) X-Microsoft-Original-Message-ID: <20210521091742.184902-16-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.95.27) by PR0P264CA0070.FRAP264.PROD.OUTLOOK.COM (2603:10a6:100:1d::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4150.23 via Frontend Transport; Fri, 21 May 2021 09:18:19 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 500cfb35-80e0-4277-7229-08d91c395fa1 X-MS-Exchange-SLBlob-MailProps: q+fD6XS3/UIohmq9k/yScywu9xPSfiUS9EsImM+UzPYnCKdNUeXQrd1ATHI1UQ7gFk5n4waQ2Px7WtRQzQMvdyx9fu/aKW5Jm0l3exQ5sTSRWwK1cL8MlyVNisAHO85rTesN5Cs5cOcNBDkbCgcsDLrnwubWAW3x9kzapox4zfGzftEx5qRp+J/Aa3j5PoIX1otbDP74kBJFIpusTlemtmWcRcMXzI3JHCX+Lzju7aKmC/4z6g1GN0CrazYEi+deWhdulkFjasw50GEFhsPGogVcVYtUNuPr/a5TQSesChhDfzq6cmauMeDBpv7UUMKLXWppcDETkYfFBFoATxgj89rBtwRyvRAAWJmGGZL150W8myrVGDknvr0zltYufyCGmXpuN0KPHGt7a2QmdxDVQQAhdQ/fhgToyUsDJa629qjswZjVSER8A7Af8b4rrT85/MaILGjpvYDYB77zcQuOULktHJEKPlY36PIg9WIp3oz56p1Ym4SpHm7c1qawUL7t5Zczdrz3z8rljif/j8/oTLN+pZT08/M2jI8YDMiIpDS411BvtgZ1lm5TZXeZJ0F7FbIK6FP5X+hI97ku0FPl4i4rWu6/DVM/TvdER4r3z1N62OFEyxUjdFWt9CD+bS3grQp2xQNCZMubgjIduuFxxW1bH3UekBE83OR0FvLQa0pPmyP7peW77r589L6dB+ctlwCv8Q7s8CT+OIOAxMMnvQ== X-MS-TrafficTypeDiagnostic: DB3EUR04HT167: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: U4Yx7MaAZYdDmW5G5uLFqeheKQIHA9bC9Z35kMeqXrobRaNSyT884l+x/UaEZ9nFPXfpeUqUnsRGvme9vR7GhSm6Fg43tGip96hUT662v675xkWhQjO9o5wf+cRpTH2BHWKEP+H7k98Fe6bmvQn2aJkQmPR18w8pBqHNQdpcQMCNCAuJAP9RC9i1vqh0WOQ0HwPmshdto/hBmwt7/BX6pjv1N4lpb25DMrntRQkqLE5Rlapfv2oT1VkXoDgWAUGpCjuVqzM+cw9Q+9cn+FFIfREKH3nkezGBS9iDcuy7Tg0x7Nyb7LNNx2w33joWikepvuXHKiX1mq/2ryTmn+FUBZ5jlawBQpB8Lj+GqSiMTeKLBZbZaYThoAzUzgTNYf2UJQCw+2z84XiLu7X0W9eJjw== X-MS-Exchange-AntiSpam-MessageData: LbzGJLzRwdUfaqAW7KcC51REAeJkMRrBMXIgBL04Ho25LAKl6hADXXT9goPHy8rP9K3ni4I4XAANPoptfizclF9/AKy8V74kSRsGbc0+xC6N7pFE3BX9GZViMjc2LoNdFTE6nTTwuXTrsJ6iRFiing== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 500cfb35-80e0-4277-7229-08d91c395fa1 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 May 2021 09:18:19.6064 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: DB3EUR04FT030.eop-eur04.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB3EUR04HT167 Subject: [FFmpeg-devel] [PATCH 17/39] avcodec/libxavs: Avoid overallocating, copying packet data 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: r2bKgRPam711 When the packet size is known in advance like here, one can avoid an intermediate buffer for the packet data; also, there is no reason to add AV_INPUT_BUFFER_MIN_SIZE to the packet size any more, as the actually needed packet size can be easily calculated: It is three bytes more than the raw nal size per NALU. Signed-off-by: Andreas Rheinhardt --- libavcodec/libxavs.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/libavcodec/libxavs.c b/libavcodec/libxavs.c index 253f4bde6a..ea53c49d38 100644 --- a/libavcodec/libxavs.c +++ b/libavcodec/libxavs.c @@ -27,6 +27,7 @@ #include #include #include "avcodec.h" +#include "encode.h" #include "internal.h" #include "packet_internal.h" #include "libavutil/internal.h" @@ -85,18 +86,20 @@ static int encode_nals(AVCodecContext *ctx, AVPacket *pkt, xavs_nal_t *nals, int nnal) { XavsContext *x4 = ctx->priv_data; - uint8_t *p; - int i, s, ret, size = x4->sei_size + AV_INPUT_BUFFER_MIN_SIZE; + int64_t size = x4->sei_size; + uint8_t *p, *p_end; + int i, s, ret; if (!nnal) return 0; for (i = 0; i < nnal; i++) - size += nals[i].i_payload; + size += 3U + nals[i].i_payload; - if ((ret = ff_alloc_packet2(ctx, pkt, size, 0)) < 0) + if ((ret = ff_get_encode_buffer(ctx, pkt, size, 0)) < 0) return ret; p = pkt->data; + p_end = pkt->data + size; /* Write the SEI as part of the first frame. */ if (x4->sei_size > 0 && nnal > 0) { @@ -106,12 +109,14 @@ static int encode_nals(AVCodecContext *ctx, AVPacket *pkt, } for (i = 0; i < nnal; i++) { + int size = p_end - p; s = xavs_nal_encode(p, &size, 1, nals + i); if (s < 0) return -1; + if (s != 3U + nals[i].i_payload) + return AVERROR_BUG; p += s; } - pkt->size = p - pkt->data; return 1; } @@ -150,7 +155,7 @@ static int XAVS_frame(AVCodecContext *avctx, AVPacket *pkt, if (!ret) { if (!frame && !(x4->end_of_stream)) { - if ((ret = ff_alloc_packet2(avctx, pkt, 4, 0)) < 0) + if ((ret = ff_get_encode_buffer(avctx, pkt, 4, 0)) < 0) return ret; pkt->data[0] = 0x0; @@ -425,7 +430,8 @@ const AVCodec ff_libxavs_encoder = { .init = XAVS_init, .encode2 = XAVS_frame, .close = XAVS_close, - .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_OTHER_THREADS, + .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | + AV_CODEC_CAP_OTHER_THREADS, .caps_internal = FF_CODEC_CAP_AUTO_THREADS, .pix_fmts = (const enum AVPixelFormat[]) { AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE }, .priv_class = &xavs_class,