From patchwork Sun Jan 30 06:27:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 33904 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp1769731iov; Sat, 29 Jan 2022 22:28:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJzpAe9xfUGz/rQepLOyj/uLAIFg3ZrpPWOXNIJFa3LAChcn4158eEHbIg6ANMq1ru3cfnfL X-Received: by 2002:a05:6402:718:: with SMTP id w24mr15587804edx.35.1643524111371; Sat, 29 Jan 2022 22:28:31 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 2si5975979ejl.123.2022.01.29.22.28.31; Sat, 29 Jan 2022 22:28:31 -0800 (PST) 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=gK0jx4t5; 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 B154D68B0E6; Sun, 30 Jan 2022 08:28:18 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074062.outbound.protection.outlook.com [40.92.74.62]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 872C368B04C for ; Sun, 30 Jan 2022 08:28:11 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QbKCRWkETqlmGn6Kpj7joW9ad9+C8LBTxrCflPDfEJV6/nDC5+IfmXSfxaXP02hzrDwKfI9OEqY4o5spiiwqLZKQD4mMIcFDWvtidUKY0qMJ5loOBSVvBIYnCgZ4DQxC+ejqIXt4Jv0C9NnX8qgx5CLHjGY6gj6gbmDqJXn/eSyn07uyqt+t8ZWzFye8Hvx3E7xygbYUkSvuDyOqxtrgpwpK5dA6JlJWLZPlTz9Wvz68gQeKP4JxyOycXXjVbqFoAA5AtKwNc1RzNvxmHPljYaLjysRn9cs4zovSA6++mPm2LPG9fEKOv9hdMHJtG+eLhnWQyscCA9r1hN3Cs0jmwQ== 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=O4NyTRryiZm93aKcWEND1jsZaHCvzMdraiJ6cP/aATo=; b=md7jZjmHX6uqfu7axrI3k6dh/pLr+fI+wKptyylBhOJZdcsKGoy5X9nRdBlN25/7A3RwQJ8ht7qeMI5ATWzUl13S6ZiU0BZn9QXD2ug/YAJWOLyyoc+TUYyfMSKPOvzv2jbLODh/D4T3FLHF52AHrov/0BbvHVjCQnycj8HUc9O1JXV54fezlY3dN6sLUExe0HZoe9udvIL59CUroCwb4fizB4Nz1IkJ79PgKikgJHOFk0JmbwhltuxZYN1vliXE0u6VgKWXj9On1bp8bQL6l9w1eQEeVueM++zyj4GCZUms01gzFpxD/PEeWG0ALQVQ8v/Ar4WIRWZ4f/EFMmHf8Q== 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=O4NyTRryiZm93aKcWEND1jsZaHCvzMdraiJ6cP/aATo=; b=gK0jx4t5kHBHh+z0bAW96IgZMQcgIC8M2k7YT3awODu/gnyQpBdOfzFuPv+5q1W49/jZbXNgmo5wHUgFgEzARDWDd1IBKkA5Q4hecnwWwOu3S5M1JnNysIYILDFIpRNwzR5hl0Df8iNipSteCH0XwiDn73plTY+w8xE2y/zfgkPLuUVkKKmVbHXnDTjzW68w4MItLuzaPR2LJoQ/WORMHjTeZRQpPAjqGaa48v+USW+JqHQaxjM6z16jw5JeLy3Gz6G4WeRlF7p30ib8psAAYceo8+HfqO9pc3NP/h2hnS8MNI/hLmhhMsa3b7NXkkTlCyCULU5xIia/QF181T4ZMA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB4247.eurprd03.prod.outlook.com (2603:10a6:20b:7::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.20; Sun, 30 Jan 2022 06:28:07 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::ac56:2ff4:d304:ab22%6]) with mapi id 15.20.4930.021; Sun, 30 Jan 2022 06:28:07 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 30 Jan 2022 07:27:12 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [c0/Hd7rL5SXABp+qq6Akkk0nYMP0g+dC] X-ClientProxiedBy: AM6PR10CA0044.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:209:80::21) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20220130062749.936489-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 83915fcf-e21b-4907-96a4-08d9e3b9adc7 X-MS-TrafficTypeDiagnostic: AM6PR03MB4247:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: pNMnC1Wr4t88yAO6HZ2hoIcdm6xiCWtPqKP0J3tAHnhHqOlWZrvTowzdHAUsSPRTtWcQC+AD2vVPMDuLXacrIw6mz/rry+HXy7q2paDNocQbdQYTCTyVOx5fek/iZcBjpbbR2gUlBmNooI1jmVyXIA9DhxEJFljCxXoOySvbL9esrrIqZGNEcxQXXm8rsC1V9zTsjKUzVxEpaOkGgbZbQYeMvU4cHjYHb75+irk9aa1AlbBjUfNDFN/EE9CEqszAYv9IeLr3Db3MXUj/YTgCIdYg/8GNCfJyIz12PraWRc2mf3HbDJSwwTaidYi/LxgkKg4rZqGhyHOISLGvS+jFt3EwRfoW9t9xKRTBGCtAxJ21dx5QdF4sfwEjzhT7ZS7c/zQhlWh0RzqmRLIXkXYOJAHrb4jcgl406hXJrDGT6guozKkUh6GE48+jK4lu1VgXcSb2Oxs+8cA6+WK0K9RW1Puv94+wSqsNQbiJbv27yr6xdPG/j9p4OEJvNskWvnzpZoZvs+etCCrsnAIz3ido4vFKjZN9PaSy+Mc+SgVYNATJLvmefJOxxrI5b1k1ZdLg X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sxLgn2CxEmgKNjaU3S2uphdziE2pufY7VLvRTKSOGFTsVUDwgbatj4y2CNFOd+srL+0iEB8fzjAlmHet16XQL9IQht6prJj5PYgJ5V6qT+MGPxbGI7m9V6f7y+m1kz1zQ3XDdmsJhMRHtvjeokKlIYfS3KnfDC8mbu6rP8lSG1nMDlA5gJtfnnDfrmXxSv7tCeZ4HeEI6ydSbjQvveq2K2am+RIceZDPB1GEZIuAO75XvPgOGvBfQHdCcc1lxDAhERMGtdxYN81HaPyb1asIUzTcBSZKOifHIkWA9uRfQRg1783g5GdrdU4xbkx1DWcusmsxicHrCP8XnqcrfkrQzBJl/0YbZO9G2I/4Ckaa16Arz5ZFpCZ/rAMz9MDmUQPVconfTNPF8+jC0HGc6V8qLtm0c/CgAG38A6Ugr5PxgAZOF5DKV1pQz8z6KH/sQ3Bk1+KCc9Lzy24kzutUvXAi/6aH4gJ/Zp9zXlm1DG5M2mRrNhPPbzTeWPbQA89vSRHgIIBaKYkpyqjLSVd31vcd1UCbVOiPfuqU3dkm3bMjLwoE8AZH54OxfAHDejyJqEpbLEBJMrTfgdxn+emdmae+UYEAXcnHXnKbyenG9CfIRluDJnF/hfKiRxMJFWg33krK/ZecgOoFc7/pqv+2CRAmOVTUcBWjd1uFmwWc7hmeZyy8ECBNElePs4DsvaB4uvro0I8O1RP7L0qWN6FMGezBgeysLCS1UAoj2zlO4BicbwtjufilmrDTjnKqj34BqPXdnxj5P5AWGi4NZle5vGEc/4PnofvQUh3m1O9zUK4YBFx1P6+J1aKFnkIjUVH3cfxnrQ9et+P9G3XZiT/Xp0XXbDW7O7lzQ1I/mU/9ArWOFYgr3IrDyP2yEzaClhvkVk2jOpBjf8+7Y3Xk2+BHM/Xosnqs84wV1Li7jgiaIlFodaQ4m7+9VpW7EfSfOvGpIBup5hX2aWsbBTQo6zUGpS/cNw== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 83915fcf-e21b-4907-96a4-08d9e3b9adc7 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jan 2022 06:28:07.4410 (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: AM6PR03MB4247 Subject: [FFmpeg-devel] [PATCH 04/41] avcodec/mpegvideo: Enable private contexts 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: 9+wx00rcwnEd MpegEncContext is used by many different codecs and every one of these uses just a subset of its fields. If one tries to separate this and e.g. add a real MpegContext and extension structures (say MpegDecContext and MpegEncContext), one runs into two difficulties: a) Some code is shared between decoder and encoder of the same format and they therefore use the same contexts, either MpegEncContext itself or identical extensions thereof. The latter is the case for H.261 as well as WMV2. b) In case of slice threading, the generic code can only allocate and initialize the structure it knows about; right now this is an MpegEncContext. If the codec has an even more extensive structure, it is only available for the main thread's MpegEncContext. Fixing this would involve making ff_mpv_common_init() aware of the size the size of slice context to allocate and would be part of separating the main thread's context from the slice contexts in general. This commit only intends to tackle the first issue by adding a pointer to MpegEncContext that codecs can set to a common context so that the aforementioned codecs can use this context (together with the MpegEncContext) in their common code. This will allow to move fields only used by the main thread to more specialized contexts. Signed-off-by: Andreas Rheinhardt --- libavcodec/mpegvideo.h | 3 +++ libavcodec/mpegvideo_dec.c | 2 ++ 2 files changed, 5 insertions(+) diff --git a/libavcodec/mpegvideo.h b/libavcodec/mpegvideo.h index 84d79d2e59..5e406b9a9c 100644 --- a/libavcodec/mpegvideo.h +++ b/libavcodec/mpegvideo.h @@ -84,6 +84,9 @@ typedef struct MpegEncContext { * offsets used in ASM. */ struct AVCodecContext *avctx; + /* The following pointer is intended for codecs sharing code + * between decoder and encoder and in need of a common context to do so. */ + void *private_ctx; /* the following parameters must be initialized before encoding */ int width, height;///< picture size. must be a multiple of 16 int gop_size; diff --git a/libavcodec/mpegvideo_dec.c b/libavcodec/mpegvideo_dec.c index 1e238bd1e1..dc38f6b267 100644 --- a/libavcodec/mpegvideo_dec.c +++ b/libavcodec/mpegvideo_dec.c @@ -62,10 +62,12 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, // FIXME can parameters change on I-frames? // in that case dst may need a reinit if (!s->context_initialized) { + void *private_ctx = s->private_ctx; int err; memcpy(s, s1, sizeof(*s)); s->avctx = dst; + s->private_ctx = private_ctx; s->bitstream_buffer = NULL; s->bitstream_buffer_size = s->allocated_bitstream_buffer_size = 0;