From patchwork Fri May 21 09:17:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 27865 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp341850iof; Fri, 21 May 2021 02:21:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeOA85Bt7HEnEZeLUjzrubPG3GAD2IIGi758FdGtVKA5F8jY2oyXkZnmXeWFL1IOE0ZM50 X-Received: by 2002:a05:6402:16db:: with SMTP id r27mr9751176edx.375.1621588901358; Fri, 21 May 2021 02:21:41 -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 e7si6217206edk.255.2021.05.21.02.21.40; Fri, 21 May 2021 02:21:41 -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=iLPiT0K2; 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 E6A93689EEC; Fri, 21 May 2021 12:18:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074087.outbound.protection.outlook.com [40.92.74.87]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3C4E9689DAD for ; Fri, 21 May 2021 12:18:26 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lp9p2T1pfIZ4IMySMvpF0ktkY6+z9N14IkoDYibV7xfLEG6bqGCNPBMCY4VWGzoyMCrnkjzTiHV+y1Gaz0gaTihcjmN4DB3OltKOiJopK281L+si5ND9itNb9F4ccdnVYzCyi5j0odteqVeIZy8Tmm2gHIjcdwQERi/MrWz214bzqA9QFoJZg7ozbHzz9CPDgTUHi087ZmQdXi02zabEYde5rZjv4t748Tpdvi+u6rAUrXs8mDK7KPfhLrWap3+1tCmNqAM8GUiT8sX9ceKmTgKjsi8n5wuAeHDp2EtCvzlir/C9DPDX6ku+ZDS84JLG+1w/YpGvuVlIqkTcHa1ILA== 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=Zb1+e1TiiiDEKu/wb5R65shY9OebouBGQBYa6aXUvdw=; b=FpxDRq3BNE/h0GhdtSNIvKHYHsGLRAbZgzomMGeWFt3rmIBPpvdColo/C/Qnrb+D9FFl388Y4lqmU4dlPTWop8RPvhs8AyoDdHUEVoWetWDBLfC+4T/8fsmCmLrKOtQtTns4F/GyprRp3mMiFOXyKyAFBxn657OPJP1gDKOK8PtT4RiqoBoyKuezN8xFjmJmfK8WadJSnA2FnNoQ+0KUs15qEmp1bfy5xYv7uGTj96b53KxEzNc07MYjkKb202whaTtYlBj2Hq5Qj6dMo3mD4yg6Su7Or6pxF0Yu/Uq51vk80Sju2kVEMb5nbYTNnWyezPV4qUMxwBM2ba+ED1vIqw== 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=Zb1+e1TiiiDEKu/wb5R65shY9OebouBGQBYa6aXUvdw=; b=iLPiT0K24nulqVC5McZ2snl/tG76NndcKMaSUJoWZpMU0miT5egRc7W8OKhj+s+jvo0gzgOX3lbNVwRPs3qdkqDvCjOU/ZajhPmxVcqKvskFqRpf9CpmnKX9oE92Z+/k5/fUPoaG7mU4JMe3r26URdo3zfinBes97boqZz9Oc7qwyBLdYrjMejTKLlt5M0SHuZzWAmb0BSinQ5RZhqXM747h5iVMIJ0UfYIRk5v1EcN+yf22xJZcuVa0SB7bTQaq24eF0x3eUQUA6fK+583DtHRwuV5nBVM7M7NSD0VXseo4aNoju7IpJf3ioVsgunlza9YAmtg+ipUz1oCn1AKM/Q== Received: from DB3EUR04FT030.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0c::45) by DB3EUR04HT192.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0c::381) 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:25 +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:25 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:F8D08948325125908A1C9901DA9EC7650C911D294D6CACDDC6E84558E7091142; UpperCasedChecksum:C21FACC10E7671328908F9CB6486D85ED873D90AB6382670EBA2BEB05F22B2D4; SizeAsReceived:7600; 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:25 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 21 May 2021 11:17:24 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [P7Pt8X6IYgxrFnWQqU24V5T7/rSnhDo+] 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-20-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:24 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 030061fa-cec7-4097-ac3c-08d91c39631f X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNU/M7M4vrgvBd+IenKLBfauLQAzQmnoW8wXeY5Jd3kXNegAXG6XnxEWDI7Sq8/FxeLAjDBuFQzmvhWQ7slfQRjGGtPq454xhuzAo5A11POQjHPCRAKmPHElwiE8osoE9UMXWYvJch9ol0txlZZm8I5Wm/JXcbvYIUn7WpdC3h08cBumaUrAMZDaX9yCTDRM1guT30dgaTR6s64lxb6BypWeLTio2frBz4O2+WXAJRfP+E7+n+9isJ9BqHeI83rlqQdunk2AsAgPitO0a+TMDByah8h+KLu6KZ2Mbk9KEN2Hx7NKdvHT5lmTVBgcxUMvb/YJ/wj4ceVp4nhbpLL9Pf4rqFOa3enxnqpRsAxRyTHSLNPfHMd5YlDveSVdcI9ln/dCmxFN6ff3LMvwlZ4NLLyGRyLbw58ApIz5QTLxa7yfz/a55EpPd3DvfR+xUB47Kc2urWh061GqbnSBt2yQSx2vCpz/Kb7nw9xMOHWg8NQcw9L/UcwfIAjCaRqunQZ1MX1rZ/pJTsbIshWbRTCjgGbAP7A5qyTQ4s6BKTvcopqcCHPazXUZE+ZFYY7Bg2rN6C2Cqd5bMXEskHvbh1YG/Y6GmbFtpe8YjIpbutkYewMDpsE698aODUNwJcFPMyC9eBzmoKvfpaTKOnPS6APxMDXr9Pwh9oZDCvo6LR+HfujO+DEiR5vsDqg+G/G+Btg9u9BDTNM16BWEsEGIlZA1Dh4ZvElO2ui+VJM= X-MS-TrafficTypeDiagnostic: DB3EUR04HT192: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pmeNu0GUwghrldeiwaMgEVNszg/MLUGH2WJwDWktPGPVsk+BVqz+xZ2h06U+zTuGrd5rnhQ9CAxhn/W2i50bqnuDwlnlEbz73k+SrkRBh0d/vi3UkLtVrzqXdLWJ9naxVDMd/w+FP7aRJ777tTnCr3weiJ0pPn946fI7xmL6gS2aplbbtcaBFTvkxNFDw4MAi8qQAZZpqxMy18lYOZI9lBwswmnRYpkypK57rChD1pEGa22NWjtXbtstliHk9qgAZjvjO/BefGI7MuRGJ6bMAqltKGnwP/+TPa06OKF41vFAZ3OWBi3+3eMm+ecPBjAgUJoZ6ExjnU33nfPfans3IO2uLmVyPS/Dbd/qo/eHUOg4bCdbCIkayC1Ln6uDeqnz6mOjNTTDmkyy04Bsscy9lw== X-MS-Exchange-AntiSpam-MessageData: 8cqqgTY3Ds/QGS022mrPztdP+58BzR7ncXNjPqUkGVL8S4r3QeRO4T7/HgOdKtVIsJM1PviaIXRdIBOxjDnt24B4i1ba6ZI/tU7l+LN4egKDOHIsnlkyMVf6+0UcQFfQL5h5zfQLH45eyTyhurOSCg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 030061fa-cec7-4097-ac3c-08d91c39631f X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 May 2021 09:18:25.3728 (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: DB3EUR04HT192 Subject: [FFmpeg-devel] [PATCH 21/39] avcodec/flacenc: Avoid copying packet data, allow user-supplied buffers 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: Zypl00hFmHBt The FLAC encoder calculates the size in advance, so one can avoid an intermediate buffer for the packet data by using ff_get_encode_buffer() and also set AV_CODEC_CAP_DR1 at the same time. Signed-off-by: Andreas Rheinhardt --- The size was actually exact in all my tests; it seems the only way for which the size could be inexact were if the limit in set_sr_golomb_flac() (or rather set_ur_golomb_jpegls()) were triggered, but I am not sure whether this is even possible (it better be not, because if it were possible, the put_bits(pb, esc_len, i - 1) (with esc_len == 0) would run into the av_assert2() in put_bits()). libavcodec/flacenc.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libavcodec/flacenc.c b/libavcodec/flacenc.c index 37ed1e4cce..e5a6dbe68d 100644 --- a/libavcodec/flacenc.c +++ b/libavcodec/flacenc.c @@ -27,6 +27,7 @@ #include "avcodec.h" #include "bswapdsp.h" +#include "encode.h" #include "put_bits.h" #include "golomb.h" #include "internal.h" @@ -1378,7 +1379,7 @@ static int flac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, } } - if ((ret = ff_alloc_packet2(avctx, avpkt, frame_bytes, 0)) < 0) + if ((ret = ff_get_encode_buffer(avctx, avpkt, frame_bytes, 0)) < 0) return ret; out_bytes = write_frame(s, avpkt); @@ -1396,10 +1397,11 @@ static int flac_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, avpkt->pts = frame->pts; avpkt->duration = ff_samples_to_time_base(avctx, frame->nb_samples); - avpkt->size = out_bytes; s->next_pts = avpkt->pts + avpkt->duration; + av_shrink_packet(avpkt, out_bytes); + *got_packet_ptr = 1; return 0; } @@ -1463,7 +1465,8 @@ const AVCodec ff_flac_encoder = { .init = flac_encode_init, .encode2 = flac_encode_frame, .close = flac_encode_close, - .capabilities = AV_CODEC_CAP_SMALL_LAST_FRAME | AV_CODEC_CAP_DELAY, + .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | + AV_CODEC_CAP_SMALL_LAST_FRAME, .sample_fmts = (const enum AVSampleFormat[]){ AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_NONE },