From patchwork Fri May 21 09:17:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 27873 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp341555iof; Fri, 21 May 2021 02:21:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyQKjG+rIuey9Xb4DMvMn+FN1r9HAIW+2d6oG/0sOV61YStlUKyF0Sxzpv7JgxjrW4Jg6+J X-Received: by 2002:a05:6402:51ce:: with SMTP id r14mr10212064edd.151.1621588868422; Fri, 21 May 2021 02:21:08 -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 w17si4787291edq.159.2021.05.21.02.21.08; Fri, 21 May 2021 02:21:08 -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=FpUG3VJG; 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 49FF3689E84; Fri, 21 May 2021 12:18:27 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-oln040092075093.outbound.protection.outlook.com [40.92.75.93]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9EF02689E13 for ; Fri, 21 May 2021 12:18:24 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Wc0X7J7HtgKnBxDc3skoDATZKZ2CWn/nqI582qVmI0Boe+1+1y6PuyYv37t35UHrC7158Ca5gWnoBZ91JEA5S18vjrcX7EnaRyNAazowKOMEMQ30lSugmiw9T8nQeKd4SojdZvx6kB7YNbySfG8W2E7xwJ5up3pYgLoVPFccA1br5wRfDq1cRQQYDqw6oWLirfkCKOkCsNw/n330tReZFpHw6/B+jCmQWLbjvewlkIqd/+SOeyK3QqLte8+gMceUqKaoIHpzbu4NmVI0YI5AcoRwPVVR4JK6ySnLWsOOqwzR2/S9W20hJpykw1IgGjKRRpBuljmMtzfkaH7Lsc+S3Q== 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=VAM1zI8xdsPD+sh0b6dnQIS8KI6aEcljhYvGM9jeOm0=; b=EbmB54xhjOIwtQ5dkef2R6VDhj9RUESAxCBmN6rR5YeLZ7xaUpM9uiMLuTe2cssxda5Tq9PcHDEMGW8J7sB2iT29iyu+6H6LHtzB4bjc9UbeNmqGpNKhUlsh3FTWodmT43SA8bj2RT0Kxh9Ujl4bo4bGqdahSbkVvzYaIJLOt2N9XvP/O9BiCUedrpEbYcUj0wsAmFoX45igIWpcdu6jOjZuik17s2GUfmPUJjF0fmQLYD22BjgLIOz6+uD7Azk0sy1k0eSS+iEsRwBfF3FmdlEoUg0iA9ZFajCLQEpV/fiP5H/Te7YzJzk7JDc5dO4yDuFREc22d8zPV51Suok5HQ== 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=VAM1zI8xdsPD+sh0b6dnQIS8KI6aEcljhYvGM9jeOm0=; b=FpUG3VJGS7eAgEHuUoJh2qhFYsNNnrHnnryF4S7tywUE++mEn7orWX3ikGW/IKTtGuWFHDVnh6AuL/DjB/Q0aTj3xJTv9Nhyw7yG6ErgywUOWG5YlTL5uCN4aTw/ob67Q1HhIFsKYO35uWgRqspwA8K95zuDAZGuHcMNQLWzk4tC2SlN753UGnWB/b3jHF9WDG6isSkydZ3LLVkYDN9DpQcGN2XAL/bg9F6jSJcYbhsJJWO/YwCLDakWcX5hSTdn6P4PArDbrLF7Ab1gunhUUVHHR9JKwqVdwDsaINkOPyv4dzg48SdW+SEItDy1BUCueE6Y7szNzqI0payql/OO8Q== Received: from DB3EUR04FT030.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0c::50) by DB3EUR04HT150.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0c::132) 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:23 +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:23 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:97B3F21A1BF56A1A90802BAD30F4E03911A091CBD97D4631E59B894E3DB860C6; UpperCasedChecksum:C75BD905A47A66910333D16055157177AEC1404C23D7DA5EA632ACD9E8E8C3F4; SizeAsReceived:7680; 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:23 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 21 May 2021 11:17:22 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [KOiUXXqijKnjiU1jtsInZsCkHVqXQaUH] 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-18-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:22 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 48 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 0c6aff3c-fdc8-48f5-09f1-08d91c396179 X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNU/M7M4vrgvBd+IenKLBfauqlx93HHcvn67vjFjhWkjF0Vu6OGnRSodSFp5LH5HaE9mRUECA3ReDONGPf4wrURoCrkKPpBYqfsU+gaOW6MpqLGsZFTiWiJGjBXy4VOdagWo3p6efxi+6y0t/jV4Ojl68AaIbu5eaAI0LUWcKsEhWhyAVjecq3HrB/FgnX9RjJAPLzCuGLWI5gumzB4gAtD2AUovdEBc5+c1X7s+JskZonRVcBaGjVb3XK0EqIKCQw4nMXa7g0+N/qa2FAAMdNl5d/8bL9CjcbrG9Nr/QEezkpfpexMuW3I9HgJ8R8gea/3lb4XFpgokQcLmBU5WRt6HyT6597MOjmgl38m5S1A9ZNLK49vIc6TtEiip1pnHzcKoDwK/BJwzA9AcsYVQNPiuc0RvG378/r/EpR3oZpqSMtRk9XhBbbg0l/Yql1TGD0RU7Vou6Eg6ipFPvfJqxLQvMX60/bAWFYmENaf3a4LhkGJ2K6LkE2KDrZt/nG8I1IRe7Z2FIgTfgrQ0/+1HPMZeWmevLltnyGMd9tV5n++jYCtdTRCvrH1RtbW4cxzIpsO/jGibVdyS24N9wolJQ61T68Wb3n6u0Ts9IPaaDymEKyzjlBaSt8+pU1aymx7qElobnkM4FQXsiCEzViv2e/52wGSWqEK+fDQnSRbnp8/BBmjDa+/v4B7GKjEIVdbK913A8Y2aulkjemMXK0SbCsI44mnCsF/CSpA= X-MS-TrafficTypeDiagnostic: DB3EUR04HT150: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hHNElECgw6k+4TrWZUIzmzyuMF/ZQhlIWsbadkKxzFsYU9obVY7OwrkGKZ+4PAgS0C7aECy9Xu0+KA8GyFBhibDWpmY73CbTE6Vqu7q5OdshzPWCz1Oiafk5uJ1XEnwbn5y1Rtu/24ZscC0nlq12x4LV75lkyH4n/Edq8vZRTW0X3/5acHGYcOW3V7yHXoUdBLuhA7SdksAgQOn+yAPa+oqi16A9u/jl58cQrGvyqONv1In1thLtsH7qtad6D/EF/12pGObUrXBETFKGXiQjs0mfXMFcFIULOeyFqcWEMLAn/B1svr/OlLMxuigq6Px7S33mSRnl/A8k1oVjma1iyBrqDbVEiB557Io50nWQFecBlu7n7fJRmto/NuteIel95d4gvgRMbO9cRfLHKjCrgQ== X-MS-Exchange-AntiSpam-MessageData: jWeSm2djpfpwF/8CK+6lmx7ZM+uE+xY7E6WAGxOfnJNLR1P6+cvWWMvpx/cRW9x3tPTmpo1VfWzFa4Ci8Vn9XXtriJbTtoGhDWd9QVEVB7a0F+NnBorXErUeSqQkf1qfzcW8o/sdtb6q5SKdkHIE4Q== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0c6aff3c-fdc8-48f5-09f1-08d91c396179 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 May 2021 09:18:23.0608 (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: DB3EUR04HT150 Subject: [FFmpeg-devel] [PATCH 19/39] avcodec/pnmenc: Avoid intermediate buffer, 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: pxKLqZ/hXDJz For all p*m encoders a very sharp upper bound for the size of the output packets is available before the packet is allocated. This can be used to avoid an intermediate buffer when encoding by using ff_get_encode_buffer() instead of ff_alloc_packet2() (without min_size); this also adds support for user-supplied buffers. Signed-off-by: Andreas Rheinhardt --- libavcodec/pnmenc.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/libavcodec/pnmenc.c b/libavcodec/pnmenc.c index 80c7b66332..2e8b6372a3 100644 --- a/libavcodec/pnmenc.c +++ b/libavcodec/pnmenc.c @@ -23,6 +23,7 @@ #include "libavutil/imgutils.h" #include "libavutil/pixdesc.h" #include "avcodec.h" +#include "encode.h" #include "internal.h" static int pnm_encode_frame(AVCodecContext *avctx, AVPacket *pkt, @@ -34,7 +35,7 @@ static int pnm_encode_frame(AVCodecContext *avctx, AVPacket *pkt, int size = av_image_get_buffer_size(avctx->pix_fmt, avctx->width, avctx->height, 1); - if ((ret = ff_alloc_packet2(avctx, pkt, size + 200, 0)) < 0) + if ((ret = ff_get_encode_buffer(avctx, pkt, size + 200, 0)) < 0) return ret; bytestream_start = @@ -141,8 +142,8 @@ static int pnm_encode_frame(AVCodecContext *avctx, AVPacket *pkt, ptr2 += p->linesize[2]; } } - pkt->size = bytestream - bytestream_start; pkt->flags |= AV_PKT_FLAG_KEY; + av_shrink_packet(pkt, bytestream - bytestream_start); *got_packet = 1; return 0; @@ -154,6 +155,7 @@ const AVCodec ff_pgm_encoder = { .long_name = NULL_IF_CONFIG_SMALL("PGM (Portable GrayMap) image"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_PGM, + .capabilities = AV_CODEC_CAP_DR1, .encode2 = pnm_encode_frame, .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_GRAY8, AV_PIX_FMT_GRAY16BE, AV_PIX_FMT_NONE @@ -168,6 +170,7 @@ const AVCodec ff_pgmyuv_encoder = { .long_name = NULL_IF_CONFIG_SMALL("PGMYUV (Portable GrayMap YUV) image"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_PGMYUV, + .capabilities = AV_CODEC_CAP_DR1, .encode2 = pnm_encode_frame, .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUV420P16BE, AV_PIX_FMT_NONE @@ -182,6 +185,7 @@ const AVCodec ff_ppm_encoder = { .long_name = NULL_IF_CONFIG_SMALL("PPM (Portable PixelMap) image"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_PPM, + .capabilities = AV_CODEC_CAP_DR1, .encode2 = pnm_encode_frame, .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_RGB24, AV_PIX_FMT_RGB48BE, AV_PIX_FMT_NONE @@ -196,6 +200,7 @@ const AVCodec ff_pbm_encoder = { .long_name = NULL_IF_CONFIG_SMALL("PBM (Portable BitMap) image"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_PBM, + .capabilities = AV_CODEC_CAP_DR1, .encode2 = pnm_encode_frame, .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_MONOWHITE, AV_PIX_FMT_NONE }, @@ -209,6 +214,7 @@ const AVCodec ff_pfm_encoder = { .long_name = NULL_IF_CONFIG_SMALL("PFM (Portable FloatMap) image"), .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_PFM, + .capabilities = AV_CODEC_CAP_DR1, .encode2 = pnm_encode_frame, .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_GBRPF32, AV_PIX_FMT_NONE },