From patchwork Mon Apr 11 23:50:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 35267 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:671c:b0:7c:62c8:b2d1 with SMTP id q28csp1303735pzh; Mon, 11 Apr 2022 16:50:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwjNIn/8QtAkiXrrgT9Cw6pnfrYnxaCyWoGXUlvdWzXOUbT848LtKtyYuxuYiZEvxvwdJim X-Received: by 2002:aa7:c790:0:b0:41d:7e0f:f15c with SMTP id n16-20020aa7c790000000b0041d7e0ff15cmr6802318eds.129.1649721036438; Mon, 11 Apr 2022 16:50:36 -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 pj9-20020a170906d78900b006e8046cba4asi8503062ejb.914.2022.04.11.16.50.36; Mon, 11 Apr 2022 16:50:36 -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=HKkkfaL2; 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 52D3768B32A; Tue, 12 Apr 2022 02:50:34 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-DB5-obe.outbound.protection.outlook.com (mail-oln040092064077.outbound.protection.outlook.com [40.92.64.77]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5D62968B2EE for ; Tue, 12 Apr 2022 02:50:27 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PHxS++vGFtdewzdjASkfJj4rzXVZ9J8jpNC5Bgys1muphX6QRpLRRdoDHV/6e/hoSU5nw1lhhqMShcAuTkYnDQncREkoznNKvyKAkH9lqHY2UkfSsH6DDHUqxgiAgaH54PiOY5P6fs/gXL+UMmxwG2OyNmRbRAt61aGGtgi6IzkqNza4eOc+oolI/LabM9780FtZ6bOoJ4ovjp2nDjIMUhda1bb6vqwrs9Tr4QgIG6he5oSpzIA8/Xt7qoisJQic90zgO2dr+WCJvSdPdDDinNUlqAbENxwl1ZZrK6FdiG7CVEonhkQt9cRCknZMCLkNx+hgZL80XLMQ3OXNIEDDgQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=+GRQecRgQOMUdGEPDWT145FiFIatrE/+n1Xw0TB31yM=; b=Nw/FtfHmZAh/lhdHW1cLmLEo+fI7jfqOJLJaGSNz6WvoEtX9I1wiRnHy1PVb+eCz6vGYUNE2oZzBPRjX6VV/drujch09cUnjuMwNKgIb7wNK13Xf1+UyDz4+EFgQR0IiAU3oT7EzM1WQWL3epC8c6zHROf3MOXL87/npHduIZ7wfAXIEbLXXS6ALHQZJgLlm72NPMIqis6KUytNskYeQcr5F2nfkU+2TTdAwsv1mhXWG6mozxTSEqhxOvvQacAx/R40pRTJhsUllOp2ZrJntkDTiVAz4QFCzqtphaX796s1M8g6OoFZDfc4VOp1V8cDunoCYj14pqhiBU3ktiZYBjQ== 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=+GRQecRgQOMUdGEPDWT145FiFIatrE/+n1Xw0TB31yM=; b=HKkkfaL2REQe2XWBRsVOYF7vWE5nP9r7Fp76pXfqDs5BoeZm3i51KcjjXooNM+IQ5zAOZXlJBvxqfjvsZ8gue6BysW/ig6Eq6TYyGMUXdjVgr2HURXbL8G+wofodf9M4VNtseLytOWtbtpJhlPqMp2LzrJvpe6T4JzZ8xzgL5ILipQECt6IznwEzSAhNBAba+6l202/YZ8Uu2hoxQIUylKVt1n0EOwaoGFEu7sveVEA/VLCjL3dpTtPR8vI6mXJMmC1Yzh8R1++vzsrU4cXvw8oUN9rV4f9/wQALmpbOTJdkYeg13koR4wwnRdNWeGA0N3cgPjiAovS8AKfYd5lkWg== Received: from DU2PR01MB7950.eurprd01.prod.exchangelabs.com (2603:10a6:10:239::19) by DB9PR01MB9977.eurprd01.prod.exchangelabs.com (2603:10a6:10:300::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5123.19; Mon, 11 Apr 2022 23:50:25 +0000 Received: from DU2PR01MB7950.eurprd01.prod.exchangelabs.com ([fe80::bd41:5eb6:c582:c000]) by DU2PR01MB7950.eurprd01.prod.exchangelabs.com ([fe80::bd41:5eb6:c582:c000%7]) with mapi id 15.20.5144.030; Mon, 11 Apr 2022 23:50:25 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 12 Apr 2022 01:50:15 +0200 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [tlc1J+DVDRgMLacY0exoR8hitsd7tWEk] X-ClientProxiedBy: ZR0P278CA0060.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:21::11) To DU2PR01MB7950.eurprd01.prod.exchangelabs.com (2603:10a6:10:239::19) X-Microsoft-Original-Message-ID: <20220411235017.316325-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7f594add-4ea7-405d-45f6-08da1c160cbd X-MS-Exchange-SLBlob-MailProps: S/btQ8cKWiThIBhrdRr4cDPWJ93ZpY+lQbnm5c+Kw9flfnO/725VKaaneys4gcj9nF864SqyVuBpATiVFAE1q5Ws3WSz7wcXewnx+kmCCnPD7cnUK8yX/RVod7rb68tba9l7gKrewG9KcDRUlfAh+GCNAzwsyajV9hf1hR7kb2L8QgSNvtrwGLmeDIu9JxCLMxWp+gxkdxG1pfEt6TPLhmL+9Y7GFGK3OhRwz6mAaPk5KjUhzJ73ruMfNuf7wgKxso5TCtpApfX0phTvnEhjzgLc4LqoL8yX8B1acPtg57Sz2/p5eaqsloY5rV6Mx75L/j5EOV6vRMo63fJMaXmD092M4cvhendSgygz137IBNgypCoNeDm/YJZ442w506aMmZGVXuY1DQ1e5DBIubYKAWhmpmyZ+V57jQSo3sa+TphS7WwjmE0BGWbO5YCsaTkFSG6/IIF91x6kvaKlRvNy0PTHPYqBPRWXzF2KcwqY+yAsY91vV7TE5HAIWCOORThfAvRWQhMZeR0hBL6yKEpLaADUTjVvK4ZFaMKUFfKmNB9ll+IjuKtnOYqLyaM71a1hAVWxie7g9a0aKKjK7meVO2lWOxqv8wRkaet7ZaUZ53OvbW5nz4gvmCt82iV1tUo1XzS0Cfp7fGHznpbqnE7CQoRY0AzMfjLwVQ1g+rdZC8how2Gm+vzwSayD8ho8PI2Gl8jdipT8MNFVz9Ji0sKTmKtYdAyLFCsTjNuy0jzveoFIRVTz65YnZSX/Hwa+zcw4kq65X4D9vYo= X-MS-TrafficTypeDiagnostic: DB9PR01MB9977:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: I5dzrvH8TbZM96XX5sFXJfesK948+k3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08da1c160cbd X-MS-Exchange-CrossTenant-AuthSource: DU2PR01MB7950.eurprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Apr 2022 23:50:25.6810 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB9PR01MB9977 Subject: [FFmpeg-devel] [PATCH 2/4] avcodec/mpegvideo_enc: Fix unnecessary linear growth of buffer 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: A9ehTDdCuuEf If one encodes MJPEG with a single slice and uses input with AV_FRAME_DATA_ICC_PROFILE side data, the current allocation code in ff_mpv_encode_picture() will always increase the size of the temporary buffer used for allocating packets by the size needed for to write the ICC chunk even when the current buffer is actually large enough. This commit fixes this. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo_enc.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 4a5e5a5059..434bbb3a68 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -1684,9 +1684,8 @@ int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, /* output? */ if (s->new_picture->data[0]) { int growing_buffer = context_count == 1 && !pkt->data && !s->data_partitioning; - size_t pkt_size = growing_buffer ? FFMAX(s->mb_width*s->mb_height*64+10000, avctx->internal->byte_buffer_size) - AV_INPUT_BUFFER_PADDING_SIZE - : - s->mb_width*s->mb_height*(MAX_MB_BYTES+100)+10000; + size_t pkt_size = 10000 + s->mb_width * s->mb_height * + (growing_buffer ? 64 : (MAX_MB_BYTES + 100)); if (CONFIG_MJPEG_ENCODER && avctx->codec_id == AV_CODEC_ID_MJPEG) { ret = ff_mjpeg_add_icc_profile_size(avctx, s->new_picture, &pkt_size); if (ret < 0) @@ -1694,6 +1693,7 @@ int ff_mpv_encode_picture(AVCodecContext *avctx, AVPacket *pkt, } if ((ret = ff_alloc_packet(avctx, pkt, pkt_size)) < 0) return ret; + pkt->size = avctx->internal->byte_buffer_size - AV_INPUT_BUFFER_PADDING_SIZE; if (s->mb_info) { s->mb_info_ptr = av_packet_new_side_data(pkt, AV_PKT_DATA_H263_MB_INFO,