From patchwork Thu Apr 29 23:57:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 27529 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a11:4023:0:0:0:0 with SMTP id ky35csp2019975pxb; Thu, 29 Apr 2021 17:04:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxIxtVQCjmfrbzL3X3ByDJfO6epAxI4o0rnClkyvqbeDK8ZS4HpLAAnGWI/IAC7sUxlM+ey X-Received: by 2002:a17:906:e118:: with SMTP id gj24mr1108565ejb.205.1619741089840; Thu, 29 Apr 2021 17:04:49 -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 fi16si1518971ejb.693.2021.04.29.17.04.49; Thu, 29 Apr 2021 17:04:49 -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=dM8oTF8i; 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 0330068A4DB; Fri, 30 Apr 2021 03:00:19 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR06-VI1-obe.outbound.protection.outlook.com (mail-vi1eur06olkn2056.outbound.protection.outlook.com [40.92.17.56]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 433BF68A4E2 for ; Fri, 30 Apr 2021 03:00:16 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gHS4qcW0TGInsuGOKOt7jbLuwFmH0cg89qGxKt8jgaWH4BlIgCe+M+zIo4wUN0qrGUeM87YkS3lX+h7D9QSzvNdRri2qc5bwW6lyN+Nq3WgUabAV1cuRkhNEbu+al+HFbKHV/KgRVACJK9WsKWeMnTBnWm0tsyR4ubpi2hQZ9lpMCjmyCciHb7egOji6nG1slckyZDTVT3/6bElQVk4h37q9APQkvoLbFw2kZxHd5c/GhEVC9o1OSfKq24ApOJLUJ5WvdVn+EAOjs8dQZdM6kqa+12fb//Sc9QRszcDDqVLnpp1/WWdgyag4muSA+oW3C5epaeT7dhPyrQ4dGgi5XA== 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=/+QNwiPfBmst54afvs2aF8y79hbAl+CozeA23RbTg7g=; b=DXyErKm45zWdjtXpey46kKiQKMxS0qZGwAXB/Ijcjv6xGzlc5xBREoTrNxLZdqP8wAG1qdHnCffEBTYf3FHBRM/H+KmcrJuNyM/dbJ82NXBDVqco5lQrWBdc+b6ClQf11x+JWZoodjVTUF6Tx0x5Utl7E9qXeaktuxwUAdblXLMYU+NVcXUS7Lq1lQx0xL0F8CUisLwWfcVubR8S9xa1gQvte2NSsyIw+EeI6OFchAYGFWU02sg2bbKQmO9IRueqOg0/ejt/FUeJXbhZq9VvOVmtJlIDcShKgcl2e+5EBS7fKdtcxRb3H6CxBKrWq+fC75e/F4yaj1/C453Ky8MWJA== 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=/+QNwiPfBmst54afvs2aF8y79hbAl+CozeA23RbTg7g=; b=dM8oTF8ims4jjChan/TqDuDPN0vAT7PbuCSXWYd1nIU7MA8wS4vMaf333UHdqo5/hlohUOTNqWnWvYn0tO2Ez4AfH1lyrkJpC7GGIr39mzQR2SlCP4g+G83wCnT0vAbXFXfFsRTQtmIokM55icMq0cAjBKojs7dBAW7CEUQVZPeJdc0hkoPF08Yc/TJ5hG77Cc7byc/RWfp4Ib3jA2P2nyZkUf1UZ2nkTE1AHaJPrb7HdyPSrAY7jbFkKemLAV+jkuHc/89Bqa2JivSMQnhyGWnSofDgDBQlil0DSvNlEjuI0CgksW9CEK5Ejq7hG/7HXLt1t7F3q6CbkyhdBq8fPA== Received: from AM7EUR06FT057.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::52) by AM7EUR06HT011.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::375) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.27; Fri, 30 Apr 2021 00:00:15 +0000 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com (2a01:111:e400:fc36::4f) by AM7EUR06FT057.mail.protection.outlook.com (2a01:111:e400:fc36::445) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.27 via Frontend Transport; Fri, 30 Apr 2021 00:00:15 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:4A982348044D2844B231B3CE3C3EEFAF86C1C2A9A1E36F3BB6E6DBF3DDC5FE0B; UpperCasedChecksum:541798AAC00FC67EE9E87029039B9C6CCA298AA8D2EE38D50B952253F5416A14; SizeAsReceived:7777; Count:50 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::45bb:c44f:2b75:23b7]) by HE1PR0301MB2154.eurprd03.prod.outlook.com ([fe80::45bb:c44f:2b75:23b7%5]) with mapi id 15.20.4065.027; Fri, 30 Apr 2021 00:00:15 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 30 Apr 2021 01:57:16 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [fM0m5/qnTl9lZLonzWu0rLjI4JvtiGv5] X-ClientProxiedBy: ZR0P278CA0088.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::21) To HE1PR0301MB2154.eurprd03.prod.outlook.com (2603:10a6:3:2a::22) X-Microsoft-Original-Message-ID: <20210429235717.2067041-44-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.193.248.86) by ZR0P278CA0088.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4087.27 via Frontend Transport; Fri, 30 Apr 2021 00:00:14 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 21ae0cc5-f3b7-4649-e966-08d90b6aeefd X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiQnJqnaHo6w7XTEhYoMxTOUqqC1aAam4by48Ty4c++T584zuR2GPh9dESXs213GS1qasFp6r0d19jD6RUBCPZpR4XHRCU6U9Q36xL+vVEztgY7i7/IhXmN1NMiazzSjif7TOK9g+pBguhm9z9lCpYqgvoQ48mtB14E6x+Ll6cBN/9+52jfbpqGWQEN3fNOqssS2OKXYMPyhT0G7rsXrjpshoeAcVwxORkb49kv2a4Hx8gcD+2B+aTZV5Wg3scf9TdeonlvBZ+Oh+FUr+frTqO5xDhUNwIX1iePT/Q+NbnmFv0gYAD3W22q18/qe3nGTcK031ZW5GS9XuLUx91XY8Bn66sy+GWqAMpvHd3KjQuzUNqjKxLgUZHVECKp7wZIERrxqxERqs/LlSHQgWPLDqFkqdTncJ1XBTiFO0zimTI870v5E6THue4guDJrb3Q8OYAAPmFGMwf0Z/s3Kwvr9yii/hJ3oJa2pT/0S0uhoJay4DVuRN5qfBHnheD551TdX9f07wT35+YJU/PlkJLrXfPau5reRIo4F9xJ/7cVbxyYaeTLRxoLv1aqHDA1kWq5nMz0lB4OUoYmMoi0P6Bw/zVEae+4BAZQqZLBTbBOAhRkn0rg/50Ake6oYPiqqZeHU+W6yJJ3cKuDAsNOrhp9RGPPxV+jLfF2GskaUdOKjGRj7RSXnSgo/f/UK6OVqfQ2kMa3sWY64fSWiIKSByfQ7Piv8NXDRZQm347kevYsPe//lybJxjjGGyOhcQOFQxH12HSw= X-MS-TrafficTypeDiagnostic: AM7EUR06HT011: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: z9qvcP+9pgjaDxNTdnE+G2iRMBfX93jZ59S5Vk9+D2NI67rdCD4If4bO9YzfK444r8jAUeW9nRjvJrDhnqJsr0EHKJOuO7LCGgwsSgg6itfZ++IZ7gYzQiYL6Wcw73T2JwjuDfRuDbhml7+K5jdsI0qdyO58whhLkYZryyyuGbJE03QYjMcaQcWdwLB97EG9fpmKYwEPVgByP7b+mukUUxGQHwycbb/ZzhHLbbFzW+I8WGy5dldQi8UMGGpnAxIN7uCFd6kHNq/NsrOtk6zQBlA7MboKorV0gJ2h+kaL0M2lfAojZXNp86dx99lfaDFGvCsflFmb9Mgr/1UbhoU/D+2ZaUEYmpU+1xZUs6akTgnOKPuHhpBThW2atQkxc5I0R+h9QgQEh1VPVzkA2wjq7Q== X-MS-Exchange-AntiSpam-MessageData: nCznmZuf+Rx6AFLxh5rsnSLr224kE3tlV//c2q+EGInuPaoxjjtQvThluqaAmphDiwMOL0MgxVWxr+fRhWEtbJCQ40CR80m0pxpAWfNd6DIicrb5EeYLxmmR+2op33LNeKLroFK3ng3RKR2gPjX1Wg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21ae0cc5-f3b7-4649-e966-08d90b6aeefd X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2021 00:00:15.5691 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: AM7EUR06FT057.eop-eur06.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: AM7EUR06HT011 Subject: [FFmpeg-devel] [PATCH 45/46] avcodec/yuv4enc: 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: Ah7L9FIP1dU4 When the packet size is known in advance like here, 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 --- libavcodec/yuv4enc.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/libavcodec/yuv4enc.c b/libavcodec/yuv4enc.c index 259395d9da..995c994b53 100644 --- a/libavcodec/yuv4enc.c +++ b/libavcodec/yuv4enc.c @@ -21,6 +21,7 @@ */ #include "avcodec.h" +#include "encode.h" #include "internal.h" static int yuv4_encode_frame(AVCodecContext *avctx, AVPacket *pkt, @@ -30,7 +31,9 @@ static int yuv4_encode_frame(AVCodecContext *avctx, AVPacket *pkt, uint8_t *y, *u, *v; int i, j, ret; - if ((ret = ff_alloc_packet2(avctx, pkt, 6 * (avctx->width + 1 >> 1) * (avctx->height + 1 >> 1), 0)) < 0) + ret = ff_get_encode_buffer(avctx, pkt, 6 * (avctx->width + 1 >> 1) + * (avctx->height + 1 >> 1), 0); + if (ret < 0) return ret; dst = pkt->data; @@ -62,6 +65,7 @@ const AVCodec ff_yuv4_encoder = { .long_name = NULL_IF_CONFIG_SMALL("Uncompressed packed 4:2:0"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_YUV4, + .capabilities = AV_CODEC_CAP_DR1, .encode2 = yuv4_encode_frame, .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE }, };