From patchwork Mon Apr 29 21:13:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 48376 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:1509:b0:1a9:af23:56c1 with SMTP id nq9csp2270384pzb; Mon, 29 Apr 2024 14:15:10 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVUgFlMH95IXgIWkjYAQKsVoGWUPjrQAIfPldttaume7s1No/0VLgFnj1IPs5F/LhbJo3valt4Grc+dZnPM3vhAmSWs+q/bCTmhJQ== X-Google-Smtp-Source: AGHT+IEG31eJBouDcmCFXe7+dGLznN1eFIQjjCEm0cP4Mo617jL3A5/TLWTFUTUZSqgnTZDu0Ov4 X-Received: by 2002:a50:9fae:0:b0:56b:d139:490 with SMTP id c43-20020a509fae000000b0056bd1390490mr5589114edf.6.1714425309964; Mon, 29 Apr 2024 14:15:09 -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 21-20020a508755000000b005727d050380si2229464edv.326.2024.04.29.14.15.09; Mon, 29 Apr 2024 14:15:09 -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=JXL5rd+O; 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 4AD5668D534; Tue, 30 Apr 2024 00:15:03 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02olkn2025.outbound.protection.outlook.com [40.92.50.25]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8347C68D4E8 for ; Tue, 30 Apr 2024 00:14:56 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RSbZAQhk9+EEYsyJ2TNCmadcgP3+7xY7Jp7QFgtVQ8gIDWVRMqBXHV/G5XEChIBNszykWv8GfBBduBio43DvJBGpODXfp2pf4/DaHuQUFG8aw6xZCKKyqAgBDp96AjfiModBIi0GV3yTslb5i4G18Pr/mLusuDOB+R7UoSpzLurejUAYrgbMsY6XTf9C8NGUGCzassBC1AADKWTNJMrlOhGmjuBzw73CiKbTG9K7QKtDz983CJfMWpTptFtMvisCoYkrqxYCpmxqFn2zjY0CrgtNUwWUXW2LBS7eKM2BxCIhSfZxrlMv5nAhiO3I/MOjLhLubG9P4fWoskoPAD+NXQ== 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=7ubgCtFPHi/YnoOYncv5i8X87fV+WAHP1A99BilG7nY=; b=DZ+bF5qkCI5VGbOiKm+Wwbg61C262Mu3gjpFu8pU98NPOfoZiZ0vFhHn4Sf7vgsMQfRNRIImLPWosZvi6ARLL7VYOo+KrKGjDu0uG9o7Pm7mufCrxh/eG1WlXmyAUiz2b9uTf3oJt13dTVgF9LPC9hXWkC9cO/DmMYuhxt4Gf0OPtCIa7BwFXkeuHPSqE12zLHLD4ACmjAEjNWry/Kduaz/GPa/w443+pQ3dKoqCRQ+vDvlW4NiOx0/Z5S9myHzwWQC2Q87ODRj58eNKZAGyOViudHp4jSKmidtliXItG9I78YZT1oyF015WJYV4+tMzJO+753F7pZ1qmFlR7tFfcw== 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=7ubgCtFPHi/YnoOYncv5i8X87fV+WAHP1A99BilG7nY=; b=JXL5rd+OnCHP+lRl0nLISWYPDm9s7c+1yxPUWy1WUA3sdX5H8tJj/6M8ZSWiOpuQsuyqDz7O21YwpdiPS7J9bhNyk8EX1sk8mAG2bqAFefEVsZDN2XUzL8uQZ8v9cmqqONAcFOyze4GW/3V+TC+5v9EEvSN5UiXDphufJhbZHTbHMuyZL4v/6kjpGMx9CmHwGTxe+I2r/mPB5ACkCuvcmKOuQgxEkV7Wz3ZU1RTEkvuCLO7yTDvK2VnHwYB/TeBnTFIuJ9f9PnCPoIt6izkdDDDameHNdMpyRGpflrO1Pq38dRJPcQ/t1Mw97YFJLEhw85Ruk1s+LsSu59vRjKE5Fw== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by PR3P250MB0372.EURP250.PROD.OUTLOOK.COM (2603:10a6:102:17f::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7519.34; Mon, 29 Apr 2024 21:14:55 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::1f29:8206:b8c3:45bb]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::1f29:8206:b8c3:45bb%3]) with mapi id 15.20.7519.031; Mon, 29 Apr 2024 21:14:55 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 29 Apr 2024 23:13:57 +0200 Message-ID: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: X-TMN: [WReF+PwxP62ae1H0vlIzaGe6vgu1MJ06PXJ/TGhetog=] X-ClientProxiedBy: ZR0P278CA0199.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:6a::21) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20240429211438.3274834-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|PR3P250MB0372:EE_ X-MS-Office365-Filtering-Correlation-Id: a3d33853-4d1b-4eea-bb41-08dc68916ad7 X-Microsoft-Antispam: BCL:0; ARA:14566002|461199019|3412199016|440099019|1710799017; X-Microsoft-Antispam-Message-Info: atHZOb643KOcYvX3FokRpjedQE/1tlA3AXjv/iB31/tGOu2jlTo4CCr3wII/XyhCZI+JM7yQlbRi1Fpg93owhf6qntqOkGBOX+4a+e/puL5TBWcVNaGDk0Jh4LqZB5HxpUbU/plgdvoI4UYnh9nbGyLDIjB5gKOBumQIGrnjiYO7yJNyH5sEE9Fn6x29ypqNSyJy22guAI7P76xvEgAb4wyBC4MhsLIjLkqm8LAqReaBN2fR6l9mwfLl++I7eqbJdOpSWb9QeGCHBoTEpgCli5ch8T08YzRTd4+oc6rQF5kEIN3yS/XXsFAKLZTWUVYujZ8r8yuJzfYEs8cJ8mrdWFUNpsl0xhhlygqvM1pw6/RgHBgraoaxOghXc+cjy+mU3zIJTvBGBzS/7GKRCnb0ThtTFSMUuhmDw1R5gtaA4qbsSTPGDSfPtodQSHXgKdMU4rPhMzt5MYVtzhnsFOBRs5oX9KvhXqeBrVdvfZD2dbEYIrNg+oFppEH6uDWmFxrrrd6xe7Vg3yjpDdys2EphXdryhxyqK0+9sgr0r5oAsldju6+Tfx3uo499VYaZIeFVLR/JorLW0UkuMe1N2v2T4bHaajyjyhffO+lIKOucoiwZENy0LApavsRXv3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XL822QEEncySoTd2X/+Fj01MS4nscT7t5jAuVoGBLwTbdgDn3PwykFbssh2tkoaaYSFSWTTPksPM+0rozdu4Zm/kNuBckda7a+wAFqCzP1lwZpF7lXHvm+AQLCDX+LvE2CUrxSWJSOt+WLY369J6eHQXtg0a/P6CJTErzdBHg6Cn54oReFA5i+NBdUYS0lE3iQ5PeGoWn9ISc7yGVFx2X8Suxz56pym/Fwjhpzv3qTVK2CK6MVuWtn8XBc2SQCEJtvQN1fSbu+mj3A== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a3d33853-4d1b-4eea-bb41-08dc68916ad7 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 29 Apr 2024 21:14:55.3407 (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: PR3P250MB0372 Subject: [FFmpeg-devel] [PATCH 16/57] avcodec/mpegvideo: Redo aligning mb_height for VC-1 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: /EVZUnFWZGtV VC-1 can switch from between being progressive and interlaced on a per-frame basis. In the latter case, the number of macroblocks is aligned to two (or equivalently, the height to 32); therefore certain buffers are allocated for the bigger mb_height (see 950fb8acb42f4dab9b1638721992991c0584dbf5 and 017e234c204f8ffb5f85a073231247881be1ac6f). This commit changes how this is done: Aligning these buffers is restricted to VC-1 and it is done directly by aligning mb_height (but not MpegEncContext.mb_height) instead of adding something in an ad-hoc manner. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.c | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/libavcodec/mpegvideo.c b/libavcodec/mpegvideo.c index 2ef69a5224..ce1edca95d 100644 --- a/libavcodec/mpegvideo.c +++ b/libavcodec/mpegvideo.c @@ -364,14 +364,8 @@ av_cold void ff_mpv_idct_init(MpegEncContext *s) static int init_duplicate_context(MpegEncContext *s) { - int y_size = s->b8_stride * (2 * s->mb_height + 1); - int c_size = s->mb_stride * (s->mb_height + 1); - int yc_size = y_size + 2 * c_size; int i; - if (s->mb_height & 1) - yc_size += 2*s->b8_stride + 2*s->mb_stride; - if (s->encoding) { s->me.map = av_mallocz(2 * ME_MAP_SIZE * sizeof(*s->me.map)); if (!s->me.map) @@ -397,6 +391,11 @@ static int init_duplicate_context(MpegEncContext *s) } if (s->out_format == FMT_H263) { + int mb_height = s->msmpeg4_version == 6 /* VC-1 like */ ? + FFALIGN(s->mb_height, 2) : s->mb_height; + int y_size = s->b8_stride * (2 * mb_height + 1); + int c_size = s->mb_stride * (mb_height + 1); + int yc_size = y_size + 2 * c_size; /* ac values */ if (!FF_ALLOCZ_TYPED_ARRAY(s->ac_val_base, yc_size)) return AVERROR(ENOMEM); @@ -538,17 +537,24 @@ void ff_mpv_common_defaults(MpegEncContext *s) int ff_mpv_init_context_frame(MpegEncContext *s) { int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y; + int mb_height; if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO && !s->progressive_sequence) s->mb_height = (s->height + 31) / 32 * 2; else s->mb_height = (s->height + 15) / 16; + /* VC-1 can change from being progressive to interlaced on a per-frame + * basis. We therefore allocate certain buffers so big that they work + * in both instances. */ + mb_height = s->msmpeg4_version == 6 /* VC-1 like*/ ? + FFALIGN(s->mb_height, 2) : s->mb_height; + s->mb_width = (s->width + 15) / 16; s->mb_stride = s->mb_width + 1; s->b8_stride = s->mb_width * 2 + 1; - mb_array_size = s->mb_height * s->mb_stride; - mv_table_size = (s->mb_height + 2) * s->mb_stride + 1; + mb_array_size = mb_height * s->mb_stride; + mv_table_size = (mb_height + 2) * s->mb_stride + 1; /* set default edge pos, will be overridden * in decode_header if needed */ @@ -564,13 +570,10 @@ int ff_mpv_init_context_frame(MpegEncContext *s) s->block_wrap[4] = s->block_wrap[5] = s->mb_stride; - y_size = s->b8_stride * (2 * s->mb_height + 1); - c_size = s->mb_stride * (s->mb_height + 1); + y_size = s->b8_stride * (2 * mb_height + 1); + c_size = s->mb_stride * (mb_height + 1); yc_size = y_size + 2 * c_size; - if (s->mb_height & 1) - yc_size += 2*s->b8_stride + 2*s->mb_stride; - if (!FF_ALLOCZ_TYPED_ARRAY(s->mb_index2xy, s->mb_num + 1)) return AVERROR(ENOMEM); for (y = 0; y < s->mb_height; y++) @@ -602,7 +605,7 @@ int ff_mpv_init_context_frame(MpegEncContext *s) } if (s->msmpeg4_version >= 3) { - s->coded_block_base = av_mallocz(y_size + (s->mb_height&1)*2*s->b8_stride); + s->coded_block_base = av_mallocz(y_size); if (!s->coded_block_base) return AVERROR(ENOMEM); s->coded_block = s->coded_block_base + s->b8_stride + 1;