From patchwork Thu May 19 15:14:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 35833 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:9992:b0:82:461d:f3b with SMTP id ve18csp124978pzb; Thu, 19 May 2022 08:14:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy1bIxwaB7gCpBy5q2wFml/8ODUvdFeEs33Ev1U4rJAE8g8H/VdFpljvSeFHdDS7wMZ9Bjw X-Received: by 2002:a17:907:629a:b0:6d7:b33e:43f4 with SMTP id nd26-20020a170907629a00b006d7b33e43f4mr4868179ejc.149.1652973294795; Thu, 19 May 2022 08:14:54 -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 di22-20020a170906731600b006fe9cf88961si1567639ejc.908.2022.05.19.08.14.53; Thu, 19 May 2022 08:14:54 -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=fZhhaz7Y; 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 90C5F68B30F; Thu, 19 May 2022 18:14:50 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2043.outbound.protection.outlook.com [40.92.89.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6FC2668B30F for ; Thu, 19 May 2022 18:14:43 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FMGLE4Lq7T/gqMXCo5TPeEFF0Y+N8hGIIHO/xH/4hsaIPfbZu2PCn9l7D6NAPBufjpzR23sv6J9l8EcZ7nSTRhO4l0XY45tQfI4/vtbmpUs8GR71Qq3XjRgIF2MJKa7T0KltddG7mJ6esHJrh8T6t++aKX97eKvsGxtmlx0P9EJGsQzhpqke5/VQX7thP1Mdmn0ChAn/o5ftM0blIUKicMLNZyFBrDsUEwQ6FqlR/tUiC09puysVPTr/a+B2opVie50Yb0uQ3lHVCKAKbpPdXSO4mVJdgmEzdKZjC8nx3gPfDJEVkx7+vIekU3D8GAThhfuKBqy1LRcsBERqHp5DVA== 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=EouGnrHHStC5i9BN7D35hQ3+6vvGuzxVRj62C9PjdMg=; b=g4aDMBsOEmXvGyW3L/iTra9krxX59w8WJdpT22JjbchFaPGL1pzVXd5oTzXKm9x6YxlRf38bZG+GIoVHmH8mkq8KrWN86+QED6IDwlWF1mIjE/GJm5hXMOPto/4Dy2t36xFm299MqikE4mRb32aULpGXSIJc047XJx5xPvUWFG0myKUzOB2UPwhvhjoroTh7vhgCgSe99TP/pLY14bvCkLH1uYg1eL7yZ+yTa+XDuZGnmIL7PzQsMl0fKKEhN2D9Z9ETNiher69A3uRkoJXFmBne3Hr1aqANDW7yjmIqnX+9+3SSNmqTxEiVwVtN6wkehqhec0ahYCqrKOUfE2RqRQ== 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=EouGnrHHStC5i9BN7D35hQ3+6vvGuzxVRj62C9PjdMg=; b=fZhhaz7YFZkv1fzfCDUCPjFxerZ1rpIoW8Sf+iwEZRR56SQ+uluGQWumuf2PwO7RdVpsevLW8thQ+coHiN7XkZiHi4tEq/m3Hfaww/t3qNWdKZ6kxUuTVlcAijsPZzYx79kLy9gGKa938tOiR1hyA84RzTip8jvg2aWGPmIcnqMdxjuXA88xUvuTzyvRzeFY2AnUgfFz7oQnpCfIqWlFfu/GAZG/6N/KW6gcxbr27fGqCab2t6B0w4fQBrvFSUuTVdENtkMGt5pfxRAgNxUzN35X9l5n5yBraZnPcQDskrC5zDBxpwckuPvKHH/KarvjohStSRfzqKk8HjJRvDwQvg== Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) by AS8PR01MB7621.eurprd01.prod.exchangelabs.com (2603:10a6:20b:2a1::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5273.14; Thu, 19 May 2022 15:14:41 +0000 Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::60b9:9f29:40cc:f01c]) by DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::60b9:9f29:40cc:f01c%10]) with mapi id 15.20.5250.018; Thu, 19 May 2022 15:14:41 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 19 May 2022 17:14:28 +0200 Message-ID: X-Mailer: git-send-email 2.32.0 X-TMN: [YV0eSWcHNkdsd+v9cM1vzRjGKCxYyLEE] X-ClientProxiedBy: ZR0P278CA0141.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:40::20) To DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) X-Microsoft-Original-Message-ID: <20220519151428.1744788-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 32f8b6ba-616c-4545-814d-08da39aa4c2a X-MS-Exchange-SLBlob-MailProps: EpEO96k6WomN+6scf6kWJ+ofDI3LGmcUSgmHeR1bbwbTf1TPxZ+dHXmSyzAb0rOJVgu4L6TyhK/uz7eY5PTZvdOulZ+Zu1Hme+MNpGImhfOJrWlc79gl06fcxmI8iCpkWXSgBApYhB4HXchQ6AlXVbRWc2MIn9CoErboapjV5fIQBIrq+oDUhLUOEebAvqyfT6Yhdp/9fWZWdkXhaSv3LN+tdQEkPhpU1Z7P5lNUyv0PMmGIQir0Cd7gVN5e5rxjXHtp3HE+9prfKjDXS/6ziQX6ee01upEvJVK883jYaUGp6izsMyJyrqPiFXFEqtPu3gSeGt20bQgSe2VQm+XmRa6LodMnIrceYIHkY9xuw2AK5rtrjsm1C2gG46g8Ke2E+fEu+OprWU3pq2tMNZlXGtLeAFmcw7iCO+yAWulE11B69Fy/HjLuiuGMo4y9/CbLtxWUsuvJN+f+XNt+IDlGtkoOMuCUwlMqT1bANM4+ggH7bq27VI+VVlTBH89ZQd/5Ldaz8YynwltyRXderI/XmK9lPyImvBBZBDViHgBNqVYDPjqkbYGxO5AzN2qtdx0WH5N87iVe1M7QRjh0xApMjjV/GKOr/sL/FD3TuVkj0UwFH/4H6K0C2dBFjEkmc1LEtNGy+VJ8pKQzLucAWFW+MnLVssYI+Vib9C3EkwOIpwfz0rQTMSzh66elKMul+Tg4i69WMPrjn4NGBi6kU/EQD7ybtuzZqfST9HdkTYIsrYRM4WpLbj9ROJqINRZzQZ/TUsr6nJJDXEE= X-MS-TrafficTypeDiagnostic: AS8PR01MB7621:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4mHnkpT3eUscS0jM+kjAnMseMvm7SILHrA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-Exchange-CrossTenant-Network-Message-Id: 32f8b6ba-616c-4545-814d-08da39aa4c2a X-MS-Exchange-CrossTenant-AuthSource: DB6PR0101MB2214.eurprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 May 2022 15:14:41.6892 (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: AS8PR01MB7621 Subject: [FFmpeg-devel] [PATCH] avcodec/pthread_frame: Don't update the first thread ctx before freeing 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: RRO1UvqE+MAB Currently, ff_frame_thread_free() uses the last worker thread to updates the first worker thread via update_context_from_thread() immediately before freeing all these worker threads. This is a remnant of the time in which the first worker was special. (E.g. the first worker shared its AVCodecInternal with the public AVCodecContext.) But these times are over (none of the uses of is_copy matter for ff_frame_thread_free()); nowadays the only thing that update_context_from_thread() does is referencing a few buffers/frames and replacing them with other references instead. These new references will then be freed immediately thereafter when the first worker thread is freed. Ensuring that the code is free of double-frees is achieved by using reference-counted structures (or in case of AVChannelLayouts: by giving each worker its own copy). Some archaeology: a) Updating the first worker thread from the last one used has been done since frame-threading was added in 37b00b47cbeecd66bb34c5c7c534d016d6e8da24. b) The precursor to ff_mpv_common_end() checked for is_copy before freeing pictures (i.e. it only freed them for the first worker thread). c) Commits c2dfb1e37cc72bf144545c4410a4621cbff5c4b1 and e33811bd2686411233cb0eb4a4ee45eb99d7e736 modified the update_thread_context function of the H.264 decoder so that it could fail before calling ff_mpeg_update_thread_context(). d) This led to a double free/an assert violation with an H.264 sample for which ff_mpeg_update_thread_context() is not reached for the final update_context_from_thread(). Commit a6e4796fbf0aa9b13451a8ef917ecc4e80d1d272 added code to fix this sample. e) This issue was fixed (even with the last mentioned commit reverted) when the H.264 decoder was deMpegEncContextized in commit b7fe35c9e50e1701274364adf7280bf4a02b092b (merging commit 2c541554076cc8a72e7145d4da30389ca763f32f). f) mpegvideo.c stopped using is_copy when it was switched to refcounted frames in 759001c534287a96dc96d1e274665feb7059145d. g) 1f4cf92cfbd3accbae582ac63126ed5570ddfd37 removed the init_thread_copy callbacks; now no FFCodec.close callback checks for is_copy at all any more. Signed-off-by: Andreas Rheinhardt --- libavcodec/pthread_frame.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index c667706206..8faea75a49 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -714,13 +714,6 @@ void ff_frame_thread_free(AVCodecContext *avctx, int thread_count) } } - if (fctx->prev_thread && fctx->prev_thread != fctx->threads) - if (update_context_from_thread(fctx->threads->avctx, fctx->prev_thread->avctx, 0) < 0) { - av_log(avctx, AV_LOG_ERROR, "Final thread update failed\n"); - fctx->prev_thread->avctx->internal->is_copy = fctx->threads->avctx->internal->is_copy; - fctx->threads->avctx->internal->is_copy = 1; - } - for (i = 0; i < thread_count; i++) { PerThreadContext *p = &fctx->threads[i]; AVCodecContext *ctx = p->avctx;