From patchwork Fri May 21 09:17:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 27860 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:b214:0:0:0:0:0 with SMTP id b20csp342737iof; Fri, 21 May 2021 02:23:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwwoBsYpEjPacVQ44WIglPfHBE5f3fvcW13cTtWoMce0Om6vlbWvn4vhAi0JrKZs7VdmIQq X-Received: by 2002:a05:6402:5174:: with SMTP id d20mr10330547ede.248.1621588994988; Fri, 21 May 2021 02:23:14 -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 g11si690012edu.494.2021.05.21.02.23.14; Fri, 21 May 2021 02:23:14 -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=XHUx6MGb; 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 51B3268A000; Fri, 21 May 2021 12:18:41 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074057.outbound.protection.outlook.com [40.92.74.57]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 906E668A000 for ; Fri, 21 May 2021 12:18:39 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GoSWAdaqMQmIop+IiiJQc24/T1YRiAnOCPprU4nnzeVF9BgzlB10J7OPq+Ju88AcIh3lcQR5Lt1W+06GJlT0lPfhEeCfieH1TCX7sEgYMo+i63Jyow78D7jPE4/UVHJDFUwP1HJXzl5eHsy2RJs46B6r6rEF9tvXbjbDED9JqYJdmNUTuSnnZUs2/sjJDuCHjqwW6sGcClSQRzYto5ds+k0wT7hC8nV/b8bRYUMdWvvBQduFgbGV6Ij1f+HpbWdEa0nOwXIjzr7jPD6Xesq2R/Rh9ssAY+Cvp33LAtKGbyQShSylWw7zl+z6zDVihQfmIODx/wJlKYpVrrGVrcqMTg== 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=hOsSMM2E2ByPZQih/3kpaqqBjUZEzmJTXOGIjJAMm9o=; b=X+MWji2fOfVHxLbC9zSsZ4oJc8OmbwfofTpcX9CMxZ5ukn/MjRnW8cpeRnoIlUyhtOeQZcpSi5ggB73g3RAlMq0bb/LS7CDbaIiPdTaw5AU2yMLx5etAv8cq8J45eeC1zNkErfvrPKRL4Xyy6rqpgs4WwvivFxy7/x6gircnxV/eJz6NWZjNDIaGwl8MzcBFihQEzV5O2GJh6cDEVCBd8Xuy0TjsHDBWZxyDB+lNlJL8Kzg3ZJDW2DZYYX5Ip4Wuzcfxuk3mfbx4W3KebaBsvqoaZ0nrHWpFQ5oIdnTChlFD8yb0Wopckc4ZGsGZFi9Dq9t+BQ6pseE6vyB1aijYfQ== 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=hOsSMM2E2ByPZQih/3kpaqqBjUZEzmJTXOGIjJAMm9o=; b=XHUx6MGbhOx5w2vzLwvW2aMDvP7YBJ6b0LaZg+IQAtcJ59JmaLpmdM40TLKcbYeQC3NouJoDoVYM3+F2v2aySlqNp1WmH1VXaQ3F7B8oPgWxCz2EMBylvuAo2h5pC8mAXjbTyXD/CohyzrTwvZILZUg53bBb19AaXYGji+oEzisgCQU8ZkoJsCzSufnr3tlQFuLXRqSrAQLdhf3m3W7JvdVInOXpxGcmE9V6fFNdldgT/yXXv3LnBWUl9Web6cHyyiD9YLNM2OLa7R13Apx5GKnMmbZNeXMVvD2knrZp2AeAfFADmg5OX9snk4+KeTdnWn61uXwlRC2yiJ5wjJh7og== Received: from DB3EUR04FT030.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0c::53) by DB3EUR04HT144.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0c::228) 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:38 +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:38 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:A31F070AC139AA9724F2A45B3208CE094B3FF53B1CCAD912D2B5C3C96A2D535D; UpperCasedChecksum:7708A3186DF1CF86E305334B69DA56C54422F175A30768DC0403FB4889B57594; SizeAsReceived:7750; Count:50 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:38 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 21 May 2021 11:17:35 +0200 Message-ID: X-Mailer: git-send-email 2.27.0 In-Reply-To: References: X-TMN: [eyd83Oiwkuh/2s/D58anYDiT8mnJMfLP] 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-31-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:37 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 50 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 1027e79f-e176-4365-0d2a-08d91c396ac4 X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNU/M7M4vrgvBd+IenKLBfauU/cuv7cFkMNp0wy3Bdc2NYQZ9Zmq5nqLOstT3/ShkT7hMriWMGZ/6/wc/kMeDZYFKPXAV1qnmWK4WANS0z8EZP06vPmxevNUVWyxfh6ftVXD7Crq3ld7R++C2aL8x9CukC45w7ERTDbPIMThaItTABrASsrJHS6xkE6mfwilWjYYcjssC28oFc01EW6b5UspfHfwWRaPvdAlqzCqY8vTfNYPpGIIb/HSq/UUQKVq8xUstkDzuDB0jW0QTndGvNUQ/4S9JZ7eL+LFBfJppVSXPXwefFl/y3RIyKkji8P1lMl0uw5di1E8txAX81X0Jzqv//eh0R8R0F61d5E243LxjMkqhGyr44XgZCOg+y/maxyeLNAOUHORCYzU+wrZhBzttGQPo93PBtM6MCqjV6DxCMI5htPzNbBW7t97n0QuKOkygdZSCW3XTG7EkuH7BxnxiSiLZsVxWTQf5CJGEKytPGHfWE3GXTJmnXkGdcj3NGzsmEUX1RyWEHu+Tn1sURU+f21PMZ74Us74T7x+4afH0HrrOJQznkUZIiBFBwNDGwtPrkWtevr1QtmkTHBuaVo7O6eoslxD6DCDzjf0Kn0fIE9zrIZmmzkeCmkXU1BbKq/Y5wtJIapqdbBBohv4a28wS0MKZ/27dypbvvz9jnONSou8DXR+H//jqr0Lru9wTYyh5trYGSSnlcv99phHKyqFOAgtP1h4M0c= X-MS-TrafficTypeDiagnostic: DB3EUR04HT144: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zon3zLYbmn4GUKmG0ea7yp8aKatScR5Xv+MUx5jOadc1V3LJHTxkFDPPKOT4SLECOKQ6N+H6tMiLkvBia3mZcHeDTD7LKz94GzVH4/9A2WRKL3HM+O/Uq5SvWg2VZG0aV7cwPecdT2HVCzIDhltiKL//66bq4IfqbV7uc7XXQYK3sJXyNx/wXCdTR5+BaUpoffslCO+qMaCr3NdVanGuLMka6i2gFb7k0ipHF1jBd67BuQ0FW8k+OLiumdRBIljLBUAEa/+3mQ3hzmzgVi/xbl1uSeHlKEx8IXaYPA0eNbxv0og/vmuxRVPJIPI4Y+NKTwu1KH2Rrh57FnI/6KbMJha717qpDdrorLOSx3S8Ja/zEtgk4nk9a5NqvjtYjHtevJIcfWZR0yFBY9k984PUJA== X-MS-Exchange-AntiSpam-MessageData: yd3MQOkSwprA9pmwyTlvbnKzeeDWjOIE823CYJxVkUaKWM5zC/sNuu6SlMhnClj9Z1rdGcN2GTfvEzIERw39JLd7XSYPeGsFvJLPhL5T9fbZDIqE4QjRfNklDN/ZeyMWDWiVR9RGkw+f/t4hOQOLaQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1027e79f-e176-4365-0d2a-08d91c396ac4 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 May 2021 09:18:38.2061 (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: DB3EUR04HT144 Subject: [FFmpeg-devel] [PATCH 32/39] avcodec/frame_thread_encoder: Avoid dictionaries 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: 9yUN2MJiGG8l avcodec_open2() allows to provide options via an AVDictionary; but it is also allowed to set options by simply setting the value of the AVCodecContext or via the AVOptions API if the codec has a private class. Any options provided via an AVDictionary have already been applied before ff_frame_thread_init(), so in order to copy all the options from the main AVCodecContext and its private context, it is enough to av_opt_copy() these options. The current code does this, but it does more: It also copies the user-provided AVDictionary and uses it for the initialization of each of the worker-AVCodecContexts. This is completely unnecessary, because said options have already been copied from the main context. Furthermore, these options were also examined to decide if frame threading should be used for huffman encoding in case this would incur nondeterminism. This is wrong, because options not set via the AVDictionary are ignored. So instead inspect the values stored in the contexts directly instead of searching for an options in the provided AVDictionary. (In order to maintain the current behaviour, the default value of the "non_deterministic" option has been changed to false, because the absence of a an entry with said key in the AVDictionary had the consequence of disallowing nondeterminism. Finally, the AVDictionary has been removed from the signature of ff_frame_thread_encoder_init(). Signed-off-by: Andreas Rheinhardt --- libavcodec/avcodec.c | 2 +- libavcodec/frame_thread_encoder.c | 25 ++++++++----------------- libavcodec/frame_thread_encoder.h | 2 +- libavcodec/huffyuvenc.c | 2 +- 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index 882700f357..6f61ae246d 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -303,7 +303,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code if (CONFIG_FRAME_THREAD_ENCODER && av_codec_is_encoder(avctx->codec)) { unlock_avcodec(codec); //we will instantiate a few encoders thus kick the counter to prevent false detection of a problem - ret = ff_frame_thread_encoder_init(avctx, options ? *options : NULL); + ret = ff_frame_thread_encoder_init(avctx); lock_avcodec(codec); if (ret < 0) goto free_and_end; diff --git a/libavcodec/frame_thread_encoder.c b/libavcodec/frame_thread_encoder.c index 778317d60b..5d14442c01 100644 --- a/libavcodec/frame_thread_encoder.c +++ b/libavcodec/frame_thread_encoder.c @@ -121,7 +121,8 @@ end: return NULL; } -int ff_frame_thread_encoder_init(AVCodecContext *avctx, AVDictionary *options){ +int ff_frame_thread_encoder_init(AVCodecContext *avctx) +{ int i=0; ThreadContext *c; @@ -148,18 +149,14 @@ int ff_frame_thread_encoder_init(AVCodecContext *avctx, AVDictionary *options){ if (avctx->codec_id == AV_CODEC_ID_HUFFYUV || avctx->codec_id == AV_CODEC_ID_FFVHUFF) { int warn = 0; - int context_model = 0; - AVDictionaryEntry *con = av_dict_get(options, "context", NULL, AV_DICT_MATCH_CASE); - - if (con && con->value) - context_model = atoi(con->value); + int64_t tmp; if (avctx->flags & AV_CODEC_FLAG_PASS1) warn = 1; - else if(context_model > 0) { - AVDictionaryEntry *t = av_dict_get(options, "non_deterministic", - NULL, AV_DICT_MATCH_CASE); - warn = !t || !t->value || !atoi(t->value) ? 1 : 0; + else if (av_opt_get_int(avctx->priv_data, "context", 0, &tmp) >= 0 && + tmp > 0) { + warn = av_opt_get_int(avctx->priv_data, "non_deterministic", 0, &tmp) < 0 + || !tmp; } // huffyuv does not support these with multiple frame threads currently if (warn) { @@ -202,7 +199,6 @@ int ff_frame_thread_encoder_init(AVCodecContext *avctx, AVDictionary *options){ } for(i=0; ithread_count ; i++){ - AVDictionary *tmp = NULL; int ret; void *tmpv; AVCodecContext *thread_avctx = avcodec_alloc_context3(avctx->codec); @@ -225,13 +221,8 @@ int ff_frame_thread_encoder_init(AVCodecContext *avctx, AVDictionary *options){ thread_avctx->thread_count = 1; thread_avctx->active_thread_type &= ~FF_THREAD_FRAME; - av_dict_copy(&tmp, options, 0); - av_dict_set(&tmp, "threads", "1", 0); - if(avcodec_open2(thread_avctx, avctx->codec, &tmp) < 0) { - av_dict_free(&tmp); + if (avcodec_open2(thread_avctx, avctx->codec, NULL) < 0) goto fail; - } - av_dict_free(&tmp); av_assert0(!thread_avctx->internal->frame_thread_encoder); thread_avctx->internal->frame_thread_encoder = c; if(pthread_create(&c->worker[i], NULL, worker, thread_avctx)) { diff --git a/libavcodec/frame_thread_encoder.h b/libavcodec/frame_thread_encoder.h index c400d6b32c..2cdc40a830 100644 --- a/libavcodec/frame_thread_encoder.h +++ b/libavcodec/frame_thread_encoder.h @@ -23,7 +23,7 @@ #include "avcodec.h" -int ff_frame_thread_encoder_init(AVCodecContext *avctx, AVDictionary *options); +int ff_frame_thread_encoder_init(AVCodecContext *avctx); void ff_frame_thread_encoder_free(AVCodecContext *avctx); int ff_thread_video_encode_frame(AVCodecContext *avctx, AVPacket *pkt, AVFrame *frame, int *got_packet_ptr); diff --git a/libavcodec/huffyuvenc.c b/libavcodec/huffyuvenc.c index b35f5c3342..266984c026 100644 --- a/libavcodec/huffyuvenc.c +++ b/libavcodec/huffyuvenc.c @@ -1016,7 +1016,7 @@ static av_cold int encode_end(AVCodecContext *avctx) #define COMMON_OPTIONS \ { "non_deterministic", "Allow multithreading for e.g. context=1 at the expense of determinism", \ - OFFSET(non_determ), AV_OPT_TYPE_BOOL, { .i64 = 1 }, \ + OFFSET(non_determ), AV_OPT_TYPE_BOOL, { .i64 = 0 }, \ 0, 1, VE }, \ { "pred", "Prediction method", OFFSET(predictor), AV_OPT_TYPE_INT, { .i64 = LEFT }, LEFT, MEDIAN, VE, "pred" }, \ { "left", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = LEFT }, INT_MIN, INT_MAX, VE, "pred" }, \