From patchwork Thu Apr 29 23:57:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 27511 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a11:4023:0:0:0:0 with SMTP id ky35csp2019623pxb; Thu, 29 Apr 2021 17:04:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1njN4+ljhtf431HrlJ+YM86d1mw+TWI+kk3TTTLCZFVv/9A7xbsamDBbzVoTPBCAWsI03 X-Received: by 2002:aa7:d6c6:: with SMTP id x6mr2491700edr.193.1619741066062; Thu, 29 Apr 2021 17:04:26 -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 hp35si1834977ejc.361.2021.04.29.17.04.16; Thu, 29 Apr 2021 17:04:26 -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="CIWuTcx/"; 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 35A0F68A4DF; Fri, 30 Apr 2021 03:00:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR06-DB8-obe.outbound.protection.outlook.com (mail-db8eur06olkn2078.outbound.protection.outlook.com [40.92.51.78]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5B38768A484 for ; Fri, 30 Apr 2021 03:00:10 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JxW1wd7rdQvcTEwmrYl5/U1xNk/mUpX3fYSDQHMXbkGQpx3Fhd2H0b6R++gayC9SLSWTh+Feq7ESgFna9USxw+G+WXU4tJXwmMyT+i9r6MFxmt7KIzjrtLUbY4EdCLP2H49Xxdt6ULI0AuO9O5eoojJY5TeUHSQ+eGIPQB5L6sfAdkJjRA9eSyHEONlKu5kZAuwRCVBxEGiLSo+Im4w9P/w2fxKzZ3260xF5EqYBpP4FwpHlak8odVWKdyjRzU+Owact8medXXqOgpJC7bpLmmBnu3qOD55xwYGwxabl+Kzbwy5qqkPewuEdr2KemrGH36dO0ojuzol+eMYo4EsZfQ== 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=1JD0dGDeBzSWBgTmpm1/W6Vvgup0d62DSMEYOSsCe/Q=; b=l5iqXDWUspJF51AE+lOBt3n165LWgfya8Pw6GFwIXXytZGo2Uaska3+qfzHDrCzkTBrlzKDQ0tg5JSb5s1lzLyEe3DHsQkONg0EZjIyC3jRw3NfmSR19bZ+u/6j9yqEx3LyitOcXcBqpckn3DNxRjfOAyd9j0OL7WWyK2N9dtTlUQMh8iPy9GwLoW+CC78iZAISSGMmNlHXjpaUdfllDDHLisAqIoRkK7w2tPw/EQD1EsquKQi54EpoftZmKRMkow8nbGIESXRYfg8dyILAs9S1o60d7w+IqUasQdFvj2xUuLq5guhchuws4LNcKyAPlzcY7PJt63mCLu/SEssn2yg== 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=1JD0dGDeBzSWBgTmpm1/W6Vvgup0d62DSMEYOSsCe/Q=; b=CIWuTcx/sSuVG+fP4jPnZxKdgWPylg2fG62OQMEjFCQZ3hjT6PbKd/POX39gTEDBxFE1f2b9E65mBwowQhWrdkNAmqjshISFzC5iz9gvJkZ5F3aPde1JEYlMhPh9Zweitif58peCPFyk1SOm8m8hnQHsne1b5nx183jglAGwy+HXcabfdAee/Xr5WB6L0ZlLClKJRA2mlC+6hm/pB3Xp+xCnH0jMfK0xzKFL8ELjOX59sdvaH2j3deBrO4ZfJoNpYAa/PNur6906kWZrRDDjTPdnBUVVZbjwfBXWgAzlp628v7vpx7laoFRuFK7L/9j6wa7deOsYNpLnVH8vTICJZg== Received: from AM7EUR06FT057.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::4e) by AM7EUR06HT062.eop-eur06.prod.protection.outlook.com (2a01:111:e400:fc36::285) 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:09 +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:09 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:4162183377A629F5C8C474E10561AF9B4653FCEDD73410B2269FDEF658A14E01; UpperCasedChecksum:BDD41BDD690C71D0D229EE0658A040EF25A71CC0364583E498780FDDC57C182A; SizeAsReceived:7778; 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:08 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 30 Apr 2021 01:57:13 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [M1FEcQmV2roAXiauAlUiMqFmHBG6wKkO] 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-41-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:08 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: acfc0be7-2f1f-4160-42e2-08d90b6aeb08 X-MS-Exchange-SLBlob-MailProps: q+fD6XS3/UIO6YRda03MtHguxZve2k0PFRWwNVam2X8mGv8oS+krznAv4NqLV0HWO1oVe17A2AghLp/DC6KWlD5L+tFuVjeu9nK0W6Zztvnom5vJqQfI/661y17ktn28YsaTkTNJiP/Cq2nSOuH8XoZ6HQXkELG2kEwDiiZgEx4We0M+6fxYj2LupyM3kr0YYCNnBFJZGMBpYqAD2s5tkG2577ZmROBrUWG7DiugV7khj5LS3qroO90syfhZQTi9lXGOL7rt2nqnGpm56zMfCZrDNRn260d42FhcETLZHPKL1OP7uh3z+LEO0rqTJJfwT6ij4p4I+nGW4EhmnTYn476/6Yv3xFzH2AEuXuLavWjsLAYlOaeWvriwsde+3Sr4b3G+78PkA+YRBC1jFOQ9RKJJ9GJexASRB0LnGbe4jEnNn/UtrpP57psQv0xlNOmOAy3Y+OORf5MqNpftOuHUpCsec6gpMeQ3Ak8pkxFp+x/HxNuu7RepgtsEK9Yg3GflsljEpFoNXZYOsyciOy/pTM/X+X6LNClLHJOn2wvFMroxQex8ZmWjmcG5It0yGgIR0mB6JpCCqYOS5C5Cr6ZNIZDf8iTNVpuo5a1CLr2A1p40295qLwYaE1i/qzT7mHUmxIr53cJsnxXWdhQUmER/ZNOVxphIGAg8pD7Cztx8balUZYOFiPlEOte73P4muwTdCJZ36V8SxcDT/vrOn4HWTw== X-MS-TrafficTypeDiagnostic: AM7EUR06HT062: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: IELl3voasW5TdME9PQtcBTAIBXKHbmcmFaKDoqAFP0PAk6Fz94EmTsA4B0uwcydEGhAcDOt4/efPmi0s1eYOfUuhhrIWNPmOOHw8mAiYShkSmR1A4ZIp9UfSBdwg4+BcuA/795ZP0/14GunH5VvaFriqv6goSYxBcyE8p8qJp/X96KQ2VXFA+0SgVmI3dKaim8ESBL22le7r1gzaXfFYlVP9SxPkp0tjqXzgCYBnFIwNkj95NuBkW59hvAzCQdyS/+5HAp4QK8gTxWnDUQKLV77uOc92MNRAs7Bjm5Bzi119NMG3rlbwoU78bcHnyvwV+GBYjp5Hv5hGnezD4ce8NRUNO+rZd2+iZxNOl6kXhtps3AM6jPQinJmTsMv7ZZ7fy7HiTkGd5q3Ehk6NbsNH1w== X-MS-Exchange-AntiSpam-MessageData: ewcStlpGchZPmkYsiDv1ktllZKWkXUX9XzFQ3FYeGts1MdyTQhOgdiN8YTgFfKK5ggQ4pblNZqXbXqqsAnvTK1rfwWoMqkDYLgH38YdFpvXRgcw4ig2eoL12YYgnd7F41Gdt3Xpu9ICaWHuIVKYwRA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: acfc0be7-2f1f-4160-42e2-08d90b6aeb08 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Apr 2021 00:00:08.8961 (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: AM7EUR06HT062 Subject: [FFmpeg-devel] [PATCH 42/46] avcodec/videotoolboxenc: 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: QlWnET+j+e6e Here the packet size is known before allocating the packet because the encoder provides said information (and works with internal buffers itself), so one 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 --- This is completely untested (but actually also trivial). I hope someone can actually test it. libavcodec/videotoolboxenc.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c index e576ff7d7e..f3e66c9e06 100644 --- a/libavcodec/videotoolboxenc.c +++ b/libavcodec/videotoolboxenc.c @@ -32,6 +32,7 @@ #include "internal.h" #include #include "atsc_a53.h" +#include "encode.h" #include "h264.h" #include "h264_sei.h" #include @@ -1974,7 +1975,7 @@ static int vtenc_cm_to_avpacket( sei_nalu_size + nalu_count * ((int)sizeof(start_code) - (int)length_code_size); - status = ff_alloc_packet2(avctx, pkt, out_buf_size, out_buf_size); + status = ff_get_encode_buffer(avctx, pkt, out_buf_size, 0); if (status < 0) return status; @@ -2017,7 +2018,6 @@ static int vtenc_cm_to_avpacket( time_base_num = avctx->time_base.num; pkt->pts = pts.value / time_base_num; pkt->dts = dts.value / time_base_num - dts_delta; - pkt->size = out_buf_size; return 0; } @@ -2664,12 +2664,12 @@ const AVCodec ff_h264_videotoolbox_encoder = { .long_name = NULL_IF_CONFIG_SMALL("VideoToolbox H.264 Encoder"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_H264, + .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY, .priv_data_size = sizeof(VTEncContext), .pix_fmts = avc_pix_fmts, .init = vtenc_init, .encode2 = vtenc_frame, .close = vtenc_close, - .capabilities = AV_CODEC_CAP_DELAY, .priv_class = &h264_videotoolbox_class, .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP, @@ -2698,12 +2698,13 @@ const AVCodec ff_hevc_videotoolbox_encoder = { .long_name = NULL_IF_CONFIG_SMALL("VideoToolbox H.265 Encoder"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_HEVC, + .capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | + AV_CODEC_CAP_HARDWARE, .priv_data_size = sizeof(VTEncContext), .pix_fmts = hevc_pix_fmts, .init = vtenc_init, .encode2 = vtenc_frame, .close = vtenc_close, - .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_HARDWARE, .priv_class = &hevc_videotoolbox_class, .caps_internal = FF_CODEC_CAP_INIT_THREADSAFE | FF_CODEC_CAP_INIT_CLEANUP,