From patchwork Fri May 21 09:17:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 27880 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp341041iof; Fri, 21 May 2021 02:20:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmstU0sJn0WpNhpTz/C28Z5lLLQAJ9W1dXpicKrURcyCyRun/KpNIJzyk0DbX5+WofDu/m X-Received: by 2002:a50:9f05:: with SMTP id b5mr10209497edf.24.1621588825421; Fri, 21 May 2021 02:20:25 -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 hd8si1935764ejc.202.2021.05.21.02.20.24; Fri, 21 May 2021 02:20:25 -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=CP5sgYNo; 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 A1509689D84; Fri, 21 May 2021 12:18:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-oln040092066064.outbound.protection.outlook.com [40.92.66.64]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DDCCD689CDF for ; Fri, 21 May 2021 12:18:18 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OjMB/MUdVkereSQC1m5Fx9CUJUoLKq//jAajfxqzsHY2P0gI7d0isgYeLKnNtzGRexsNUvm2KzAlZi4gaun47Tsv+4HuWLAjjsMTxdThAcQWPteU0nXbXiOER7Ga30tv9PgaqyzJoYhjJFfqDC0L9BDXwxmQvE7Xv8Q6jXETBfRNTmk3M63WtEIh/DS9byHyqtFdK6kFDuX+5aIENaqAka4JmxxjvTdjR+ewgDU/lSkX3/3ZSueMAhIGZNbN137tSRki4XGAk/Jwe9NdGbd9akzJykq/3TL+Kf9i5KG6kkbf81E/gHIEk6glzPFxGSrhYFayWVwrvWBYzU1KAP8k5g== 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=SDFsIFVR0BjT9l+q/zwhr/j2j27Oh/DyuzsLcea1I9k=; b=nV70CtKDeHzMs5hfSEd0LGdxC9RGzuJxTTy6AqYzP37w79pNRV4xvBXOdDl/ElC3qe6CptzsGIpAVPonc779A4z7dDhmTTwwBjLWQrsfdPqOF/5q9ITtVTmIf3LJWQZp8KYw5l11+VQubBI6uhACg6ZEhetf6Ph8GwgYc3NNx/eeJ3pzC+jSd/2tFss0MbsTIBP7nG5dy5XlUAWptgM7l3VjIfvVgBbH2Kd9aQFziqEQDpuLKbURXB42m7fOalJUcCxgOHzDyGcTeyne6b3zy0m9KteNbp9sIvM/BGifhseRaMNqLdqkjVx+78Sbdetj3z2QFSsRbUa4JjV3/if6CQ== 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=SDFsIFVR0BjT9l+q/zwhr/j2j27Oh/DyuzsLcea1I9k=; b=CP5sgYNoI/oLzQFW2uOFHdKuhDH9vQSiqGytytx//F6USTCv14XcWvhgOGlLCNa3MyxTF24TMX9YvTpxBenRHkIJSIUTaZOqPKkseQmU9H3dlVEWZ7Zv+37FvQSsbSsNvt4Gnf7An26yIHZf5mg6r3N5NlwctroLJo9fNce02jBkjpqopfCPPKqRXYeRVnm2Fx0vIgzVwu90JP1UEKcwvjn+87pPuDod0pYi1FaRXjOjXOfLnHGAMuA6tTrG/2Rc5sf2W+aX/T8s3qalIC+x4/pWTkefWMqjgnPch0iuG9NZ1aDEm1tBWSJgZ1Kckp4WznLg+gtPaGmiLpICN39gwA== Received: from VE1EUR01FT010.eop-EUR01.prod.protection.outlook.com (2a01:111:e400:7e19::4f) by VE1EUR01HT017.eop-EUR01.prod.protection.outlook.com (2a01:111:e400:7e19::292) 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:17 +0000 Received: from HE1PR0301MB2154.eurprd03.prod.outlook.com (2a01:111:e400:7e19::41) by VE1EUR01FT010.mail.protection.outlook.com (2a01:111:e400:7e19::83) 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:17 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:EA31B629F9083984170C2D15CBC8373504159A3B691398116CF34B2B4B7F9A79; UpperCasedChecksum:46C0982EE5DBAF28CAD1CA317F49963166233708CF68D6522BB1488CB59DFF6C; SizeAsReceived:7601; 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:17 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 21 May 2021 11:17:18 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [a7Eek+KpnYShDUMJfPtRNrePcgeqnpp8] 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-14-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:16 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: d7e35b8a-fc39-49cc-a4da-08d91c395e66 X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNU/M7M4vrgvBd+IenKLBfau3xIG7ENhZ3aoX79knlxCC3d1ldBI1QYz2Bn2/gC7F3nRBHJwLRM0PCfUNHcYpjf7v7wn1JJ37chIuCOkEr18CXnY4ys8nk06BkXwVbNATF0KidSS2l4zys5/G/+MrmWS9bAIJJhdONevbfZUbmjxpmXgkg2dZ24T2ZcsGLCSIsXnq/4RCUuYYpptGKt9E1369j4cwCT9MH82FBRcijbxxSzwsxK8SVfAIMCmZBtaiT6p2sptjBfSsAz5F9R1vUWcFSoAr9jrmx39WXeGFkZPefGfnaxfiOqAmjS1D/g8TKACqpr91sRtDYg5yAeBMh+FByZSXsoDEeSBiHuFKOSyqAWLpjSb84F6n22iipW+R1e9LziBes64EXNSKR8i68zMP+t4bOPZEpyQEkYKFUSGgGyYSpAutqADMG2gpU7PE1u54M2mQSV8Sizr3iuWqySH7SWT0eWMwD0qAs37xHHVPMiS85jawtQWq7yzhzsMLkb1FXf174YefRnVIkHidZQcX9nwdZBiOMYqxyKO8p0iCUCyEe5QLs3jFtshBbe1E1YBxBJIoXmyLUgzBQV2Saqr0x49lWwBakvxumzSKpfqOJmx4xCoWe8KSGIbgHFO40JgX7RDy/2rhCSfXsfZj+gk+H+qz91EYTp0bikbVMLh3Eh/uSXFPgNOHE2uujmtzVDqaiKk5WzSdgfOvY+ujfxApgjU2YgAplI= X-MS-TrafficTypeDiagnostic: VE1EUR01HT017: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CuIg/5uitlRFR4tf0+XBDDFW+8JlP5fqGjObUR5Jw9vdV3tDWsucfD9Cksc4gvt03yHAOix77G2oTNqJlbE2CMIVv9ZLatxnBUvEQe38LiTfkEUzuHjxD+I0jrSJkF502Soum20TUZjYjjnCuoah0SpyHgLs/JzCsZprgFOhQszFx1JSlpLZW1RhFUdotl+dXPljcXNtX88mDCb/Q0G/1ffUx2tMMdV5q6sMrKG93luigxyROw96A8Vw7J5mjx8BHEmAM+hWacHBqstQGlMDFLzghppl14eyimbPSVnKiwGeFGuRNX8+E4VIKQ3bQa+1pTLDlabV5wJIL3He3ZzVaC2/cHivVLYtnWsrKyRHtHEdb2Y2EHvBd7lqUStZ1CTOetg9ISnupg32nO1/8Nvehw== X-MS-Exchange-AntiSpam-MessageData: onZ8kNHOJxCPzX3OO4QnHOwdnYHpgqvok8HO5q2t0Jw4MdsxZqNkIFyMAwETalnByeupSsOowMNvusC+HJeLCgejZ/qIzeuyZcZF3EhRPzoQSooZPZ9DR0GnPiWqwWaF75XIrg7K64LhPuK9bLFsUQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d7e35b8a-fc39-49cc-a4da-08d91c395e66 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 May 2021 09:18:17.4223 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: VE1EUR01FT010.eop-EUR01.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: VE1EUR01HT017 Subject: [FFmpeg-devel] [PATCH 15/39] avcodec/libx264: Avoid copying 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: kqotW1FAEpqR Here the packet size is known before allocating the packet because the encoder provides said information (and works with internal buffers itself), so one can use this information to avoid the implicit use of another intermediate buffer for the packet data; and by switching to ff_get_encode_buffer() one can also allow user-supplied buffers. Signed-off-by: Andreas Rheinhardt --- libavcodec/libx264.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index 1c27f7b441..36fdb567ff 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -28,6 +28,7 @@ #include "libavutil/time.h" #include "libavutil/intreadwrite.h" #include "avcodec.h" +#include "encode.h" #include "internal.h" #include "packet_internal.h" #include "atsc_a53.h" @@ -144,7 +145,7 @@ static int encode_nals(AVCodecContext *ctx, AVPacket *pkt, for (i = 0; i < nnal; i++) size += 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; @@ -1147,12 +1148,13 @@ AVCodec ff_libx264_encoder = { .long_name = NULL_IF_CONFIG_SMALL("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_H264, + .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | + AV_CODEC_CAP_OTHER_THREADS | + AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, .priv_data_size = sizeof(X264Context), .init = X264_init, .encode2 = X264_frame, .close = X264_close, - .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_OTHER_THREADS | - AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, .priv_class = &x264_class, .defaults = x264_defaults, #if X264_BUILD < 153 @@ -1182,12 +1184,13 @@ const AVCodec ff_libx264rgb_encoder = { .long_name = NULL_IF_CONFIG_SMALL("libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_H264, + .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | + AV_CODEC_CAP_OTHER_THREADS | + AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, .priv_data_size = sizeof(X264Context), .init = X264_init, .encode2 = X264_frame, .close = X264_close, - .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_OTHER_THREADS | - AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, .priv_class = &rgbclass, .defaults = x264_defaults, .pix_fmts = pix_fmts_8bit_rgb, @@ -1213,12 +1216,13 @@ const AVCodec ff_libx262_encoder = { .long_name = NULL_IF_CONFIG_SMALL("libx262 MPEG2VIDEO"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_MPEG2VIDEO, + .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | + AV_CODEC_CAP_OTHER_THREADS | + AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, .priv_data_size = sizeof(X264Context), .init = X264_init, .encode2 = X264_frame, .close = X264_close, - .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_OTHER_THREADS | - AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, .priv_class = &X262_class, .defaults = x264_defaults, .pix_fmts = pix_fmts_8bit,