From patchwork Tue Feb 1 13:06:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 33980 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2c4e:0:0:0:0 with SMTP id x14csp600956iov; Tue, 1 Feb 2022 05:08:16 -0800 (PST) X-Google-Smtp-Source: ABdhPJxmuyf9RevlIMyfFhviRxJ+4mO5lsOpPAaTZeKs9e6fkwLM0zDJXOT961yW/OC1PVNvRxBY X-Received: by 2002:a17:906:bcd2:: with SMTP id lw18mr17200911ejb.647.1643720896269; Tue, 01 Feb 2022 05:08:16 -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 b10si10867349edz.437.2022.02.01.05.08.15; Tue, 01 Feb 2022 05:08:16 -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=sA0LHXYd; 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 E064B68B2B9; Tue, 1 Feb 2022 15:07:38 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2063.outbound.protection.outlook.com [40.92.89.63]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A56BA68B2A8 for ; Tue, 1 Feb 2022 15:07:31 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FuqSZtcLW6m+GGKblptrN732ny4x75bliDxQq4qPYPujQLHp4U950uFI0MsRFTT33fLkexbfYvG6ICNAyowaIbOGNYKDkn9FxEmAsT3/VBtlqKwrr4XlsfbnJ99C+aG3fKh+0SGUzqtXd8UAkK036e9FLRwHaJ/zpzUskebeqTTTA//xs+1FMLiR004weRYZT0VZ2IjGo3CZ6dCVjWB2t5gxmIB+z6u4mNdJcW2Z9UrpBaPz+3wGfGr92xZQqi4oOaRU7LIJ+u3GlcQa11Zy8FFiUe8tK7LP8rviSfwfGQpVJuEoCebBsUeV13db4B1DIZ38KA0WyvEtNtYUnACGig== 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=tEoQhMsnfZm05PvmHwfwjTaIg9cpp/FywxhM7zdz2SU=; b=G7+/03KnMuft/v3dSxqQk82A9DF/vp2FG9t4oBWpeHS9kpHBHElfBzAPMZJfCT0MAIIznxW2XDJlOHnD7lHB6povTGeBKbcJPTCnH9XRkDC3EQz54ylBpMybK/jI/SXq4+6BpOkJrJQ+8OHZzOY8yJ4o6E82aRN0UPCX+yFCFRnc6QL6Bg6thRkJPnDSpxsyUkvUAZnn+7jgXi5Bqu3b/hsrsoS08WXXXVGaVtDi7UAsh/jLv/DmiQKscHV9wPYhfaPwKNaNNA/lyM48Cq0XqxLQnTBkuvUSLXsfF5h5tIl3Ps4Mn1jXFK5oJ4yVxfc/BaX9GMt6HmlRtEctU/e5Ag== 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=tEoQhMsnfZm05PvmHwfwjTaIg9cpp/FywxhM7zdz2SU=; b=sA0LHXYdYNDFEbGlelvE3bxUCEhjsU3FRsovegD0FIfmRTpf1grydEVjDzBx4Ch7FVTZtnIhhp2LZyx43iweJhVby5mn3pV+8iyOLwmGZM3hdXX8HQUYD7f7Xh6bm5kcnamA8RZcdaikt0a5JTpLZHq3yR1DMez5CSxZOMwsdLDCRyk5ddzeQK1TloodhGdCnc8gGKbDj2hUJu9uvEerIGGfMTADqPHunJwgOxEym3HZ7YppoQTjbDt8GHmXyR/Rq2pp/cNp5CQRgnVvs2coV4oDM+R8A9JI6IVcNdBMW1lRjdC2RyVJxNCJyAkIUfIFRDrjqNUpkqakhwY30TvYMQ== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by DB6PR03MB3046.eurprd03.prod.outlook.com (2603:10a6:6:34::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4930.21; Tue, 1 Feb 2022 13:07:24 +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.4951.011; Tue, 1 Feb 2022 13:07:24 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 1 Feb 2022 14:06:02 +0100 Message-ID: X-Mailer: git-send-email 2.32.0 In-Reply-To: References: X-TMN: [SOhSENleGAG1Y7v2LBG62xyjwZEgMM/H] X-ClientProxiedBy: AM6P195CA0092.EURP195.PROD.OUTLOOK.COM (2603:10a6:209:86::33) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20220201130706.1420875-4-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1c1531bc-6c36-4cf4-9850-08d9e583c9f2 X-MS-TrafficTypeDiagnostic: DB6PR03MB3046:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NdxMhCPo/eaqHzPMMlYTWH9eMoEqkjuTYd/4sYnwBDT4HdXW4s+Yc2dvi4PpF5wGkQAVV5N/75LLkKwCYBG4zWVzU6c+hXho63bUWGJhC0veB2pY8g8bW2zXmv5b2O3OtwBrrA3w7KLrTCM8rbGWYTr79zVm9m9ieCniseo0FPk+516+8dmf48EeuwMrpovaGTiifxLNQyWpsi98GC5TWTsWpXC78cQEgItwm8YhY+Lj8K9igvz2TRMoh/jssiq6yHK8syYc//TKipxYmeOuSEjVZzcFRZ0SeyD9Pw/xcaGlr61WKq4XKnulvGKobb3MFgDHZCzNXB54tNMgEecGGF6KZT/xOTGuGJeqScsC7oTIPtOs5AyQ+btYLK9bziNqOp3QYvhfC47EYw8nVpMr8NsEVjevBgn550T7yqt9st//NUQnFOrcetwRy9NhJOpocMs+LjZh+Mk0dBmm4E5X57+nif91PtKh+WfHf24Q28GouBLRZlf3ioCPhVMg8nGYEIzSBKfwDYGq8mo1Cs8D1cZBp/Xyvu1qmJXZBWG33dUIf03AlXANfLubQcdMVxd9 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bD98T6bqUw5nwq999m1okwqi+PRxwfDgZZVHy53JnTF45JIrOFLH5aZd5WgHOdtd/YhK7ypq/6VhKPX8wpIqifsWGUZHFAvkow3xWnd/p14An35f2gXc/2vVQnrG17N1x3OcP7ojBQbLehVKfPkknrUS64JzRkv5rtDExdCZrglZQKPDwzPZzcjXPp+HPLoHzfApLPcJKbAh2C2maIH8wx5zXvGRnTzWwfv+vFV9W4aofi1f/b5QGSNei3/qO/Z+G3oNWdsEsSo5OgqLiRSVsUXCNuBshdzVkVHuREPyxyuRL37dlW4TnTZ7aTMmGmQ+OPQ/s4OOVfOneQJT1ZfdG7uOYzzuuecBgRmeZA/Hko/KI2wwTMHrGdrVp6tWfT0QWReARSFE27GxPT0aQaZjkBSECK4erGyEKqlc+qPj6+rxpHf+2fmA4wYEWNO644SzTcy4TxuhOVWJHfj5tlVesYOzQHsaXmFfXV6wG+kPEcB2+0pJuMTvPdQkyVdjaUu2z5cdMFNwEGQFZ8j71aoYoSKr3v5OAMcELASzqQfb2tkARNMuIvMtOauyqRoRvxgsVF8zHDp8jaaJlNAzCS78JzxtOtFZc8sr9yo77/A6qioL5HUkp039En+/1mTllCvAbv3CNx9pzzU0P4v7zSRm1XbBzwurbQLgo0pt2cW2huIKE8tQhlfoazCvmjgUVQIT9IxsN5YfeBP+sVmqj56a9GAiXpH5gFuRKFMOtVcIoOWUGnG9GCGh0e1Y/pXp1hPW9/ptyeZzijcwB4B9VZdCz8z4bN0f7mYKRpgVCTy6C2sdCOLvdynezUeGzopwxuyjKoZad4OKknAHuUd1bGaPeyVxAd/Ed7kzfUxk2HRoJwsMmlr+JtJSvfy/QQ7N66ezKVPFCAJDsnQEC17YEQVeuKjZhVcM/SMEqQnV3dwL0GgLYAxTnxdFQKNVSOXJGtp1Jf3G9VM3kBZKSk7q9YvMmg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1c1531bc-6c36-4cf4-9850-08d9e583c9f2 X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Feb 2022 13:07:24.2481 (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: DB6PR03MB3046 Subject: [FFmpeg-devel] [PATCH v2 05/69] 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: dokmOE2ygYs+ 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 | 3 +++ 2 files changed, 6 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..cc23e070ea 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; @@ -76,6 +78,7 @@ int ff_mpeg_update_thread_context(AVCodecContext *dst, if ((err = ff_mpv_common_init(s)) < 0) { memset(s, 0, sizeof(*s)); s->avctx = dst; + s->private_ctx = private_ctx; return err; } }