From patchwork Tue Sep 19 19:56:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43812 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp185215pzb; Tue, 19 Sep 2023 12:56:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG9RcL6cmaJP1Fq+82fC6lfXFvjnQ2B2L8khOSurB7XzFUq3qUg0j2SRr73EEZVNcOiMA+M X-Received: by 2002:a05:6512:3e03:b0:503:3644:4a98 with SMTP id i3-20020a0565123e0300b0050336444a98mr772630lfv.2.1695153402149; Tue, 19 Sep 2023 12:56:42 -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 u16-20020a056402111000b0052548800d54si10118900edv.265.2023.09.19.12.56.41; Tue, 19 Sep 2023 12:56:42 -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=lTwIWZ2J; 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 4E72668C63B; Tue, 19 Sep 2023 22:56:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2048.outbound.protection.outlook.com [40.92.91.48]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EA5E768C765 for ; Tue, 19 Sep 2023 22:56:31 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EvXPIOeHeFej63EPTNzEgoDXBRCqPaKgGjco7PSH241OXi0UMpG8v3ewN0rdTGztcfYXb5IT5hWuF9apt2eQ5cN7xvXRHOc2vEeR1YXIuJ70t6L3W2sRGAIohahJAtrG4ohdEiiMsHpM1i+t6azwv6V8BDpehaG+zyl8k4InDDoUKGEk+H75/L3a/j2CsmLFU+OfhxpzLKh8WuhMd6Vo4dkbIITF0Y5a72azWwVy24nIJKIQC1KT0Nf0Hs0QFF22Rjx7Qst3Z2IAnU5Y1tFfiXQRhifjTQhp7X9MLRGvSe3rQP/OqDmOLsM1v73YiyVD2Eu9tONKQYcq8EJjQvKzog== 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=2PFWExMD3UzCAqUCvBoraX9/GTtpSFu6tPGh+luxgB4=; b=DnhuJ74F4WnTBjuUTJrSJ0C6WcXGYeZS+vxvYe28rpDG67eG0JwgNVp/5blmV19W8VQjmdwzWCAWKks9vVjLYWSsOzzzMqKnnnGgseIznQO7QuY/wJYf0qd+IwdNCxN5xffRPoEc3yL/y6sPvWFl1BN0D9/vgeNynOZyoegGGXFz0GA6HcGbB5npWXiHZ/I5ehLJXM7jyxDun5FAgXAOTjJPqkUFI+0KCiRJEILjIFcI4BL7R2kB/Cm4GsQ0YkABZrak5uRr4BnIDCU35pbHHGcDpFLniceH+u5Ice6RtMrDgFO7LOOC+rGcqc7kxlwawOzcLkwnXBHlRZY3rKkpuw== 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=2PFWExMD3UzCAqUCvBoraX9/GTtpSFu6tPGh+luxgB4=; b=lTwIWZ2JcntklJZBL8gl8sQlozXEfNSLQx/NEjBkrsnrRqGzD6msio9WntHCOmeUisLMsIYpjKclSRzkKWu7i01MEYHDwcr6f5Xb/fqXK3CsKMu3ahwg+9jR6V5GUVuUepV/OgI9rQ9yVLvvEhvgimT1Hs3zT0beybfMVaDqKNaYsbT4KOdrB7mFHEBsP286dcy7qcGzStbk2auwZ4qprUqhvh8JTz8PbK15XOMl07jJRjm41mfI4ekD8MJSVrbK1r0AlmzGeDuLq0ohxplYogq9zkz5Jf5AYnwRjxwpB7Lt/JT6c+fCPv12BEQDCKqi/jeSRcSiHAJgpUuMDHVJyA== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0303.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:27c::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:56:29 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:56:29 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:56:53 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [0l8yCUY1eVG1mDgY6ivB6ZNpEnV+xJwc] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0303:EE_ X-MS-Office365-Filtering-Correlation-Id: c6346953-38fc-4943-1c2c-08dbb94a83af X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RPxs2HBibOcg0PrsrfvtnIQ/sy9fhNKWtOoQWzXd2kvDr0HTr/+h3KTMW71naPSXmOkh4cLdEmcFkAbodG/3rtGfiJUXIiL/Vg41uhLDcNvpVR6u7fxPKNnzsuMi1SmxO7ToSllgqumJ0ZtuyxpLyW41coOBkBD3Vkxe1Dqsn3kJsMoehACIcg+CxEyHTfRPNLHv3l/xI2LvvXk4CDt+tNz7UPcKYUE4+r9mvX5kcDMyTphn3MqtYPRCzPLur+9pmb1K6bV9QhIsDkVopQjv21uXFzm5ZWDalJcdvlYUuGhqWmD7F5vnC2i59GPXgw7dO2tMKkXVxxtnjJgX9zHXwJfynMVuV5qu9FBSyqgrYxAz3sGqNhxYdLRPIHY2oQe3VSO5N7WW3MEL4zdXCteST2fIu7SDwzD0ZtqaaGrWNGqBGGBC/aa514M+8Ty41aJ92qprfl7MfnXGFirK1vE12JlayEvk13gSA3FpCDgh6Q/xwjW1NUqs8Yymbkt1TA4AamHkWe+QoGRMmJ/ZunBQjcyf4jOmWcqi1h6gqnvEPlq+AbBPjSrLbi2uaLysIutgsaOf9jtN8ba0aunn15uFqc/AA5npvx7L9CWmowrztqQ/SXh9UovbqSMYwtGTKmwy X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: LxQQu2XRn7SHIBowwLSZDtaOlo4exgNI6CuFM5b2XIgWTb+fEYFxg1Uo7F60alQEOeZguY6RaH+G+N9DUBWfRp2QWZuizGKJ3nGNYfqFpuNruQeC/BHUJuMU3i5eWxf30VLI/RG9iRuiQF8BzOAHgPLYkjxxE25Tl/FTCcyrEUjiKuf50rNcRux+aN4+BsnyWSs33uPFTTnW98baRfMRTK3WlMfEoLLx5S7DbOFRlof5bFA8Q3bi9WwRyobXctIxbW+16VK2rCCfUl4YtWnJbjlHLcka2YDD596kOIOoivtOkfqJLtve10GOwXU0T8cPeojxnpuBz2NvNOpeXjXVpEjgg/oOBk7Xe3LDDou11v51zg9pPARNPxYumTvM2acbRW3THdEwDhJlNAp3SO739zqjmHKJkdm7RBgqM6vbLeY2CJQ5SE6BHj6HcMBoxivRpyaHXJlr3EDmbmtgEq/+C8K+0zoRRgmXo0ejT+ddjD8AOnDEK0ljnjQnsCZMTXndG80DjgRlBKXmm7CVhmrFFrkQ2NunYa1GUpocCp8puN/cv0pp609g+o4p7x5lYFYDNMC3EksFTMEqfm6N+7/cr88lvBk0RTfCZKuayHF4GTxCb2YkT55EquafBuaf1uPi74CXrKaqW2klgzLeH8DJvGfefXUk8x4+zKQYoMlztvMXu9kddpkUdWTNWec7XBGXEQVmm/TaO340sf0MqXeDkmqv03TTDQ3Tm3bko4Oc6OrdYoriDfs6xz1ZKFjulpFqKdF4bAsxqwqUEtxIT9GKZA6L8qKUQ9xW0e6IxFw3t87XtM8iWQ2zfL5CewGnuCJPnLTBculLWWIJAswrYti9HsV6gPvg4m9Igt3mOpaoifAYBCThgIC35wK3Uw3NwmTvI9oBYEzs7mx7eg8bKQjJy+SWxrm6mJeqfnUhQwHZ17/TW8wj1//ozVFmznusE9PiDCmGIZdOt3YfJIfCbx0LBHTt3At6r4YpsOqO0mZE7iyXE9JRMyWik/5KT4hcfR2bqgn3NYg2S52Wudt4uB9GqyY6KcEH8dfmiDBKGCb9FCE1O4Ii45n0QfF1tpb6sFDy2tcBJ6nGDcBi7WsE50uMCKnw0KXWHSgNkSZux7q22h18vLUDgaHYlPzL6uHfgBawKdjl2gPEV+HdNbGAc8RlfMzPjz71AMILLAcD7TVlv3Kj36HtHJEvqkUm90xf7irDMTbKLoNGIlAzhRjqnC2Kph0H45Bz3NZDJrvIHSKJEEakFWlJlxxoT6UbA6+e5h3z X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c6346953-38fc-4943-1c2c-08dbb94a83af X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:56:29.3895 (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: DU2P250MB0303 Subject: [FFmpeg-devel] [PATCH 01/42] tests/fate-run: Ensure that THREADS=random is actually random 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: O66F2Y+IK050 From the documentation of GNU awk [1]: "In most awk implementations, including gawk, rand() starts generating numbers from the same starting number, or seed, each time you run awk.45 Thus, a program generates the same results each time you run it. The numbers are random within one awk run but predictable from run to run. This is convenient for debugging, but if you want a program to do different things each time it is used, you must change the seed to a value that is different in each run. To do this, use srand()." This commit does exactly this. [1]: https://www.gnu.org/software/gawk/manual/html_node/Numeric-Functions.html#index-rand_0028_0029-function Signed-off-by: Andreas Rheinhardt --- tests/fate-run.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/fate-run.sh b/tests/fate-run.sh index 743d9b3620..8efb1586b8 100755 --- a/tests/fate-run.sh +++ b/tests/fate-run.sh @@ -37,7 +37,7 @@ case $threads in random*) threads_max=${threads#random} [ -z "$threads_max" ] && threads_max=16 - threads=$(awk "BEGIN { print 1+int(rand() * $threads_max) }" < /dev/null) + threads=$(awk "BEGIN { srand(); print 1+int(rand() * $threads_max) }" < /dev/null) ;; esac From patchwork Tue Sep 19 19:56:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43813 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp185284pzb; Tue, 19 Sep 2023 12:56:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEvCpnbGQeHeXFTKcxv+s+Ex5YjvI7vkOxPm9r2sFohHFduAdSCuwElHDaUnQ9TvCCZdop5 X-Received: by 2002:a5d:408d:0:b0:321:6de5:68b4 with SMTP id o13-20020a5d408d000000b003216de568b4mr497140wrp.52.1695153411644; Tue, 19 Sep 2023 12:56:51 -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 qt16-20020a170906ecf000b009945340230esi10274707ejb.174.2023.09.19.12.56.51; Tue, 19 Sep 2023 12:56:51 -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=BU9z2pCe; 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 5266A68C945; Tue, 19 Sep 2023 22:56:46 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2055.outbound.protection.outlook.com [40.92.91.55]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 42B9168C915 for ; Tue, 19 Sep 2023 22:56:39 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AWyA3zHD4mBuDIdL0YFd3Nz7zlVwR/p7h/PNcP/KwDx4wk34fYYJvGg8WyPfiveOXD0cuS+13vhTUcTGYUu8Us53QiIaizFkwBSSka08RsWsnjg3cLjGpZ04PZx5lpbryIOJJnTovDcG+SDdcDp2j/whOezKO096fiuslc64tyT2zKgk6VFwouPsmBBIOhjVjHyqEhSN37ky3TAhdGEP38xJlW+SLXMaPJxh1aMcO90ZfRu54adrnyXYWnsueuarXulounNa78F1JkvRLboyV492zEupTOcbpPDLyPfFQ9/GWLtVSdS4nJaOdR+joZW0/s4gazUq8ebN5x1tYfyt/w== 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=zgHJkda654S7RKxkb9g0N/ImBExnzD/cvLMebeC+Sgs=; b=Rwqh3eGu0OrwrEDdGf/X+atoL0T9OTx+so8j3HQMbh2BNjc9yBM/ieMunFiWTYCcX9Xq6GtSBHb+09MzD4AnkzvGGPSpu/UCVfsBNvGo3qCeAaYGm861gF0PJu3frpRSFR9VfRHmXhYV9irmjIRBVALXa1ssYKZpTD0+O91guKRyY6nyF5fka/d1OcFz6hHk7ATOCxMtf5NjBxciZGTuP0F4ZNlGD/XAAE+nTOCyrCQXy7YU0PBjulXW1UFfE/yn6HQGxRkcZqOg7bS4w84NguC77QeFCuZrpPJXJKp9g9zJjvncwO4JhAbx9hMmeOBE3F0T03Dk519BD0UEGj06fQ== 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=zgHJkda654S7RKxkb9g0N/ImBExnzD/cvLMebeC+Sgs=; b=BU9z2pCeURGh/S2SSAygOCZRm0Gh0bmmWornckXScOs4X6MAsdgijk2sEcKaxDmpkrRXVeUIK1V03CzJDXeUZYZMnbS32DZRck62ZH8ZIaW6zKF7CKqtfjkWPq34L5eZEdkB2IA70MqO7QVZryVTFWYOPOq+CeAfy3JJge3NuntY+BB91n0EJYsji97wTXGplhDxp231w0Ua3u/7sjqINb7UiR1t6wIuQeuY/Qck9SCOykuneLalawlP/7P1U+NhfgF3ZYKtun1phVMWE6OBEddSUjUSbX5YEmgRMlxlEIFH4aF9B5C6SI4as73u66cgounI3x2DpgNYkSNpT33M1A== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0303.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:27c::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:56:37 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:56:37 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:56:54 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [4eeTTegnlsLpO+h+yPJuYyLy5fOX5Ii9] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0303:EE_ X-MS-Office365-Filtering-Correlation-Id: 7e07cf1e-8647-4a9c-0b79-08dbb94a8889 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: r9Nhk7Fi3nBEDHXmV3QU9aOZh8wyRz2vlVYgqcrjgc9i0uFIkowi006jUSYQSOI/8x42X2nV5QZsA9tTqdiW9hGMjIU088FCyaQJcVzY7gbMoEdWrcgtJxbC7fgx3qGYVmzWfvDcXdnP2pT/keuiMJTz6tEpNyKmEwWoc+htNGvbR1bs35793g3Zb2XmAF8JgWHMgvRORNUGOqh9R67K+DNWspSOLmywKbUL5IQZwQQ3jBfhijDmguBFZIldf6Z+m8sCNKuPOoRySAfD/b4XunAX5QEbZ8ERfBT8Ejnpz3S5XOgVGO3XZZb8c+7XlOsjfmgsrx6QLguK6Rf2eh1gRy8BYjA3SLhtQRSbcSRM2pY6KJoeQnwBi40MQUelUXpxTY3b1wKxApMkG9fDPK+p9tvsugcYZqsuywaXTnv6TGOEnUyGO0Z00Kx8Wxk/5kkMS+/PG26YL72VXBaHWrnjhXD1/CvgI75ECxA2iEJkLfdtToFuto2koRbdyxUgoj0j0L5gm6ByxevIRhPliEX0KvFsGZ3xAq8FKPeCipSuCLjKBr0ey7dWi9DGDH7HQLHvS2z1PbhBaYfo95NHgj/Tp8HB3raZPxk8u7z2d5EgnPprWdNul2+XjPytalXdQwf2 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 09LRYORoyfigL10bhX4HgwkCD2XCbi4XoY2ldcBb1ug9TWmLIi3rFWO8SdjoyNZJo3E8jfxzoO5YnSlpTKnV8lVf8KKNsxfuHeb7VRcu2h1nqqy7vYHR0sGrC/21lf11JGP6uxkV3dmUlmxMqTixxLx+avU3zr9uXRS3ALh0k3530LuLRfGjdtB7Jtp16MwBfe9kUkYiwKlhbNshxpJQCotIxHqm10jaq6GcFD2bNNFSyO50EOZieeDkyWfoUN+lx1HxMDunfrnWPXxSvtpckxV6mnF2YGNq4YLwC3M0gR0YWIpUsX1V1F231IoO1zG0CYWXz3BuMVjj8IrVv/sPqfOdz8TqUbzlOBe5J70ytHBr/YeRITLaxt+sfV3fZjbGFhLk4DvU8uAU6Q8iFISIk9t9Et6u/mWmrkZciK/i3kg2DR07+DpWrMiq2sh3/SQwLp3Q+8VZggvJ60LsrRfx7zlIRrLyHPN/z/XdZKC8yTO8tmmflJwdaKRMg3ZrNPXEpsYO8E7uPVwhgPOYernZBOz+yo465o3OjXJJxwNTrlaDCM5RTbzMX76dyYXkn7A2DYU9OinrQsV3mQxXbZTMekbxhrcf7a1UcuM0oWRepst/MHQj+zi04+DocVAh0mr57EgztVpWMn7HpmhjVWpVn3p3jyzSnTbj8PJCgD+pMPEiaZ4n0KPB0YjAQKax3opZC59mkcqWLInbZUiaDI4fOXIoUep/Eoh9Q/eAXEo6fpLJOxh14lVEE8U91qTefxRALPq6cYwRQc82wH6NvEiMJZlsVvCkAizOj3XAfgXlZvi4SpxT5xAZed+oVLTbH02nPj+ojzbZSY4L6F3uXjsMAbfqz27RwIxrzDk+hXyr0ueypYTNp0lSwIVwcnyp5gb3/nj43AlVhC3u3MLDdCSf5dxenA1PizkDg5BKYazDc3eX0pd120PLeZHJSmtPTUW6X+TtkVxOY8er/PGvCZ3x13DNqCI/tyVLKmNdFbh7QHUpp1/1gGr7cgodCdmIs4piDBD1BwP/+8YqBdLX7aGD2+RQQNvnaJLwTQob+R6rPma3Qov1lAFd4TdBCSWX+Eyth2rEBjFHRzfdpp4aCRSSDv2GTrTUCR0e06AeH42QG7uANhVtdhc2uK7cwjKPg1ZCo8Xg6XD+3VUgxw4osbYo0k6aB/Uas58ldFuORLmlUrR9keeD6GyV4C1vhnsk5Sf/mHqCzWC+1OOBakWYD2DSDREOpOfNk/zDfb7llOKEV8LPl33mdyx9856Q9qjfMd8m X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7e07cf1e-8647-4a9c-0b79-08dbb94a8889 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:56:37.4787 (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: DU2P250MB0303 Subject: [FFmpeg-devel] [PATCH 02/42] avcodec/refstruct: Add simple API for refcounted objects 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: vqZk5udtvE0Y For now, this API is supposed to replace all the internal uses of reference counted objects in libavcodec; "internal" here means that the object is created in libavcodec and is never put directly in the hands of anyone outside of it. It is intended to be made public eventually, but for now I enjoy the ability to modify it freely. Several shortcomings of the AVBuffer API motivated this API: a) The unnecessary allocations (and ensuing error checks) when using the API. Besides the need for runtime checks it imposes upon the developer the burden of thinking through what happens in case an error happens. Furthermore, these error paths are typically not covered by FATE. b) The AVBuffer API is designed with buffers and not with objects in mind: The type for the actual buffers used is uint8_t*; it pretends to be able to make buffers writable, but this is wrong in case the buffer is not a POD. Another instance of this thinking is the lack of a reset callback in the AVBufferPool API. c) The AVBuffer API incurs unnecessary indirections by going through the AVBufferRef.data pointer. In case the user tries to avoid this indirection and stores a pointer to AVBuffer.data separately (which also allows to use the correct type), the user has to keep these two pointers in sync in case they can change (and in any case has two pointers occupying space in the containing context). See the following commit using this API for H.264 parameter sets for an example of the removal of such syncing code as well as the casts involved in the parts where only the AVBufferRef* pointer was stored. d) Given that the AVBuffer API allows custom allocators, creating refcounted objects with dedicated free functions often involves a lot of boilerplate like this: obj = av_mallocz(sizeof(*obj)); ref = av_buffer_create((uint8_t*)obj, sizeof(*obj), free_func, opaque, 0); if (!ref) { av_free(obj); return AVERROR(ENOMEM); } (There is also a corresponding av_free() at the end of free_func().) This is now just obj = ff_refstruct_alloc_ext(sizeof(*obj), 0, opaque, free_func); if (!obj) return AVERROR(ENOMEM); See the subsequent patch for the framepool (i.e. get_buffer.c) for an example. This API does things differently; it is designed to be lightweight* as well as geared to the common case where the allocator of the underlying object does not matter as long as it is big enough and suitably aligned. This allows to allocate the user data together with the API's bookkeeping data which avoids an allocation as well as the need for separate pointers to the user data and the API's bookkeeping data. This entails that the actual allocation of the object is performed by refstruct, not the user. This is responsible for avoiding the boilerplate code mentioned in d). As a downside, custom allocators are not supported, but it will become apparent in subsequent commits that there are enough usecases to make it worthwhile. Another advantage of this API is that one only needs to include the relevant header if one uses the API and not when one includes the header or some other component that uses it. This is because there is no refstruct type analog of AVBufferRef. This brings with it one further downside: It is not apparent from the pointer itself whether the underlying object is managed by the refstruct API or whether this pointer is a reference to it (or merely a pointer to it). Finally, this API supports const-qualified opaque pointees; this will allow to avoid casting const away by the CBS code. *: Basically the only exception to the you-only-pay-for-what-you-use rule is that it always uses atomics for the refcount. Signed-off-by: Andreas Rheinhardt --- I am the most unsure about whether to use FFRefStructOpaque at all or not just a void*; the only beneficiary of this is CBS where it saves casting one const away. I am also open to other naming suggestions like RefObject (RefObj?) for this API. libavcodec/Makefile | 1 + libavcodec/refstruct.c | 139 +++++++++++++++++++++++++++++++++++++++ libavcodec/refstruct.h | 145 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 285 insertions(+) create mode 100644 libavcodec/refstruct.c create mode 100644 libavcodec/refstruct.h diff --git a/libavcodec/Makefile b/libavcodec/Makefile index bf3b0a93f9..7541f38535 100644 --- a/libavcodec/Makefile +++ b/libavcodec/Makefile @@ -55,6 +55,7 @@ OBJS = ac3_parser.o \ profiles.o \ qsv_api.o \ raw.o \ + refstruct.o \ utils.o \ version.o \ vlc.o \ diff --git a/libavcodec/refstruct.c b/libavcodec/refstruct.c new file mode 100644 index 0000000000..917cf6b7ac --- /dev/null +++ b/libavcodec/refstruct.c @@ -0,0 +1,139 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include +#include +#include + +#include "internal.h" +#include "refstruct.h" + +#include "libavutil/macros.h" +#include "libavutil/mem.h" + +typedef struct RefCount { + /** + * An uintptr_t is big enough to hold the address of every reference, + * so no overflow can happen when incrementing the refcount as long as + * the user does not throw away references. + */ + atomic_uintptr_t refcount; + FFRefStructOpaque opaque; + void (*free_cb)(FFRefStructOpaque opaque, void *obj); +} RefCount; + +#if __STDC_VERSION__ >= 201112L +#define REFCOUNT_OFFSET FFALIGN(sizeof(RefCount), FFMAX3(STRIDE_ALIGN, 16, _Alignof(max_align_t))) +#else +#define REFCOUNT_OFFSET FFALIGN(sizeof(RefCount), FFMAX(STRIDE_ALIGN, 16)) +#endif + +static RefCount *get_refcount(void *obj) +{ + return (RefCount*)((char*)obj - REFCOUNT_OFFSET); +} + +static void *get_userdata(void *buf) +{ + return (char*)buf + REFCOUNT_OFFSET; +} + +static void refcount_init(RefCount *ref, FFRefStructOpaque opaque, + void (*free_cb)(FFRefStructOpaque opaque, void *obj)) +{ + atomic_init(&ref->refcount, 1); + ref->opaque = opaque; + ref->free_cb = free_cb; +} + +void *ff_refstruct_alloc_ext_c(size_t size, unsigned flags, FFRefStructOpaque opaque, + void (*free_cb)(FFRefStructOpaque opaque, void *obj)) +{ + void *buf, *obj; + + if (size > SIZE_MAX - REFCOUNT_OFFSET) + return NULL; + buf = av_malloc(size + REFCOUNT_OFFSET); + if (!buf) + return NULL; + refcount_init(buf, opaque, free_cb); + obj = get_userdata(buf); + if (!(flags & FF_REFSTRUCT_FLAG_NO_ZEROING)) + memset(obj, 0, size); + + return obj; +} + +void *ff_refstruct_allocz(size_t size) +{ + return ff_refstruct_alloc_ext(size, 0, NULL, NULL); +} + +void ff_refstruct_unref(void *objp) +{ + void *obj; + RefCount *ref; + + memcpy(&obj, objp, sizeof(obj)); + if (!obj) + return; + memcpy(objp, &(void *){ NULL }, sizeof(obj)); + + ref = get_refcount(obj); + if (atomic_fetch_sub_explicit(&ref->refcount, 1, memory_order_acq_rel) == 1) { + if (ref->free_cb) + ref->free_cb(ref->opaque, obj); + av_free(ref); + } + + return; +} + +void *ff_refstruct_ref(void *obj) +{ + RefCount *ref = get_refcount(obj); + + atomic_fetch_add_explicit(&ref->refcount, 1, memory_order_relaxed); + + return obj; +} + +const void *ff_refstruct_ref_c(const void *obj) +{ + /* Casting const away here is fine, as it is only supposed + * to apply to the user's data and not our bookkeeping data. */ + RefCount *ref = get_refcount((void*)obj); + + atomic_fetch_add_explicit(&ref->refcount, 1, memory_order_relaxed); + + return obj; +} + +void ff_refstruct_replace(void *dstp, const void *src) +{ + const void *dst; + memcpy(&dst, dstp, sizeof(dst)); + + if (src == dst) + return; + ff_refstruct_unref(dstp); + if (src) { + dst = ff_refstruct_ref_c(src); + memcpy(dstp, &dst, sizeof(dst)); + } +} diff --git a/libavcodec/refstruct.h b/libavcodec/refstruct.h new file mode 100644 index 0000000000..0086717c17 --- /dev/null +++ b/libavcodec/refstruct.h @@ -0,0 +1,145 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_REFSTRUCT_H +#define AVCODEC_REFSTRUCT_H + +#include + +/** + * RefStruct is an API for creating reference-counted objects + * with minimal overhead. The API is designed for objects, + * not buffers like the AVBuffer API. The main differences + * to the AVBuffer API are as follows: + * + * - It uses void* instead of uint8_t* as its base type due to + * its focus on objects. + * - There are no equivalents of AVBuffer and AVBufferRef. + * E.g. there is no way to get the usable size of the object: + * The user is supposed to know what is at the other end of + * the pointer. It also avoids one level of indirection. + * - Custom allocators are not supported. This allows to simplify + * the implementation and reduce the amount of allocations. + * - It also has the advantage that the user's free callback need + * only free the resources owned by the object, but not the + * object itself. + * - Because referencing (and replacing) an object managed by the + * RefStruct API does not involve allocations, they can not fail + * and therefore need not be checked. + * + * @note Referencing and unreferencing the buffers is thread-safe and thus + * may be done from multiple threads simultaneously without any need for + * additional locking. + */ + +/** + * This union is used for all opaque parameters in this API to spare the user + * to cast const away in case the opaque to use is const-qualified. + * + * The functions provided by this API with an FFRefStructOpaque come in pairs + * named foo_c and foo. The foo function accepts void* as opaque and is just + * a wrapper around the foo_c function; "_c" means "(potentially) const". + */ +typedef union { + void *nc; + const void *c; +} FFRefStructOpaque; + +/** + * If this flag is set in ff_refstruct_alloc_ext_c(), the object will not + * be initially zeroed. + */ +#define FF_REFSTRUCT_FLAG_NO_ZEROING (1 << 0) + +/** + * Allocate a refcounted object of usable size `size` managed via + * the RefStruct API. + * + * By default (in the absence of flags to the contrary), + * the returned object is initially zeroed. + * + * @param size Desired usable size of the returned object. + * @param flags A bitwise combination of FF_REFSTRUCT_FLAG_* flags. + * @param opaque A pointer that will be passed to the free_cb callback. + * @param free_cb A callback for freeing this object's content + * when its reference count reaches zero; + * it must not free the object itself. + * @return A pointer to an object of the desired size or NULL on failure. + */ +void *ff_refstruct_alloc_ext_c(size_t size, unsigned flags, FFRefStructOpaque opaque, + void (*free_cb)(FFRefStructOpaque opaque, void *obj)); + +/** + * A wrapper around ff_refstruct_alloc_ext_c() for the common case + * of a non-const qualified opaque. + * + * @see ff_refstruct_alloc_ext_c() + */ +static inline +void *ff_refstruct_alloc_ext(size_t size, unsigned flags, void *opaque, + void (*free_cb)(FFRefStructOpaque opaque, void *obj)) +{ + return ff_refstruct_alloc_ext_c(size, flags, (FFRefStructOpaque){.nc = opaque}, + free_cb); +} + +/** + * Equivalent to ff_refstruct_alloc_ext(size, 0, NULL, NULL) + */ +void *ff_refstruct_allocz(size_t size); + +/** + * Decrement the reference count of the underlying object and automatically + * free the object if there are no more references to it. + * + * `*objp == NULL` is legal and a no-op. + * + * @param objp Pointer to a pointer that is either NULL or points to an object + * managed via this API. `*objp` is set to NULL on return. + */ +void ff_refstruct_unref(void *objp); + +/** + * Create a new reference to an object managed via this API, + * i.e. increment the reference count of the underlying object + * and return obj. + * @return a pointer equal to obj. + */ +void *ff_refstruct_ref(void *obj); + +/** + * Analog of ff_refstruct_ref(), but for constant objects. + * @see ff_refstruct_ref() + */ +const void *ff_refstruct_ref_c(const void *obj); + +/** + * Ensure `*dstp` refers to the same object as src. + * + * If `*dstp` is already equal to src, do nothing. Otherwise unreference `*dstp` + * and replace it with a new reference to src in case `src != NULL` (this + * involves incrementing the reference count of src's underlying object) or + * with NULL otherwise. + * + * @param dstp Pointer to a pointer that is either NULL or points to an object + * managed via this API. + * @param src A pointer to an object managed via this API or NULL. + */ +void ff_refstruct_replace(void *dstp, const void *src); + +#endif /* AVCODEC_REFSTRUCT_H */ From patchwork Tue Sep 19 19:56:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43814 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp185371pzb; Tue, 19 Sep 2023 12:57:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHuZdYNiCy/C/X5qu8W2OArarMR/7YziSBuKgf/AptZnDBmwyx/Bv2nB8O2hZjGMhk7ahZQ X-Received: by 2002:a5d:4a11:0:b0:31f:fe07:fde7 with SMTP id m17-20020a5d4a11000000b0031ffe07fde7mr491840wrq.1.1695153422074; Tue, 19 Sep 2023 12:57:02 -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 a6-20020a17090640c600b0098cf3eaee47si11316443ejk.689.2023.09.19.12.57.01; Tue, 19 Sep 2023 12:57:02 -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=s8rTfWQS; 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 4FE7A68C843; Tue, 19 Sep 2023 22:56:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2101.outbound.protection.outlook.com [40.92.91.101]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C305D68C63C for ; Tue, 19 Sep 2023 22:56:46 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d9t1nm6hUdo2FXmoQX+R6gXrKlLJYS7L9gzvxH/raaYW83KeROAbvWJY8MESomKBJySfgqD1mrGWmpMW1uW7cT6gLN8RBbcqkAptAqiHx8jQ4h7tKJNUQFONDX+ojO0apdlf0TiCE3yyHPwhYpypXN89cAbAUfHZN2b8My1OagDmMjqmIMLicaWj45dIezopB1V82D3vB4JK1tGBRlzwwsOWQ44nt/X84DkF0nrVJ4BG3jJ+DxBff1/ATZl+JDkPFCjfDWTOGE5fOTGoQx77TrZ4xWxqYtibL3mv3ENCzat+3gxiwFYOo3mf+E1V3U5FcFQei0YNn62aPFUC/RBKZQ== 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=ytaasbqJ0RzrauE76QkDEgFflRWfwI4v4QT9PnKRWNY=; b=mKhbGuoTe0oHwVQh/AbsQb1uEoFDOPdJ6unWePwHISgkOMsWtahOsgP8B0W6hfN7A/vtXuRDSiPNz1wMpAEGI5n+AGQCxdgGuUmDCoDQC9SX0L3LDs9dsqcW6koIgjfWsHZY4cXXi4Hb/IwQPoAfi9W+nn68Tk423XbccwsSEQGR9IOkdkNIPKhhyYCvpMve1i1ciF64aEWxnqz+sCZ47UkA9z11uPe81JaLUr3DKf8QCy+ZWIjqBqrkOe+LN3Vhmkt5FBglaBlRJKNPtawaMawSfhzDd+ZpAXksA2UcgqFH959a8IHGRXyXBntSpDPFqV5XJU//UINhhzZgBJmkGQ== 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=ytaasbqJ0RzrauE76QkDEgFflRWfwI4v4QT9PnKRWNY=; b=s8rTfWQSU/9O3Q6wpppKKG+p+3fDKhWP3jdSVperqocZb/ZwmU1ApJRn8W5M0MR7grDnzOwY4/XTtMJwCDndCAlK8guobLuPLp9wRC7Ieo6Hm1W1C1U+m9mgqo5xD1DrqhEriUxUc1vAexdnbpH9XmIH7nrJqIVRkMJ6kLWOIlP/vO2dMg5IzZmW+T4PCBvD+AB3TIY8OOR2GGBis4YaqGa7LvLIhR//dq4NfodNIhy0k133618mpWPVYke9iA+Ki2cInGKG/UompiZWV+Ob4Wv1Z1cv9d5gon1oulqrtDukUUWKecOdI1V86uckuARWW5vsGND70Ryg1hSXe54eIA== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0303.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:27c::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:56:45 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:56:45 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:56:55 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [8VswBUT6/gajMM1BF8RYOQ6FLiXAJ4+u] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0303:EE_ X-MS-Office365-Filtering-Correlation-Id: 01b2f255-1518-458d-99f3-08dbb94a8d41 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rkhZBNAc4GrUjpi/9YWYv8kGGovRFChRqPFn8yF1sMfDmBWKn+th8V7xfGXIsiptPrkcb5AQ+OaR5B5bMxjDLZt+KVUtHGEdJLRxAV81VExPxeIhm4zT5qiJJuin5UMaw2YiWgWGavbJZpULJJTjx5dZ5uBLYnnp7XigpkFQNbUOG2K8AyRbnrgk8Sy6t8jgaupW6JQ6BeHfFyxuKaeQR2a4NZPXZ4Uek6CIi13KAsnF0jjTfyS0YWtDAu+rxtuqIDZOCJ/M9p4sQMC7B0Ube5cDKFQe8S0cThf+wDsP/vJz+HbKGINf9edDxVBPIf2mT562PjXpP0D0HRjdg+j+thX37Q8LNJN2L2RQZX0Hn783AN+6AxWb6xwenW6m13+qxXW0ZJ9tLftgdYcwMSQP3zghGQY5xBnGRdKid8tdrzuSWee3MqHdU1MvGQHJax3s2lT4+7RVZ4Gc+2V2hjP+XBDaSIlL3q0E3xU1N17SEh2jvo7+jHabFQxrX8zqMhhCK2p8t5+5zsOo+pZSY3cGjQY9owYXMp5yPBoHrWxqVU7vZTDpJh43EsISNyxcQ6tq5YBUQuVQ1qZsj3Xn2xM1NQ9ac9yZapowb9veKjDQZyk1XHIh1bDf9rYUXqtqN30Z X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uCXsjXfAvY2t+EEdKmNvCju/h8yxQBv+aO5iQf2eO6IzXA2PL/VA5lH2IoQIzCeWAcShFR/gs/Dn9ffJUbFY83YRJzOShsXwEFcCRbco6XGWiR2cUaG7rLzpvxJkr374ZiZIaFDzX0cWZU5S8nNEnqlJqovTUC8OABLTjchQD48mNE7LUm4HhuSl7Wg6SOnsHm8IT4bYjkPrNcsRyk2BtAPjG0a3QO/GBLyJ+Fi7aKg7RGi5nIBeAo6y2AE5NrZYMHkKW5maaymrGL/I/JwXIAibNEcv5VR6Z/V/e7oYgM8BW8s4oiw9R2Kq1fT8/eCNBzxei3aVag3tpxJTKNWTkbclO6JtVDYcSz/q0TY0WghNdMO59kHZIcSM5qM2e1HLKKB9dPhuvMjkVXF9kGoRvugYGT7ezu78xohBziyUw9L4ilLqgzkPODoUwAxiTl+eTLSEor5TOYKm4oNCw4+xqP3EkSniuPCwURz2+T5jtvSqb8+Fr0kQPjGh4KqkCECro3144KXI+A7lx39lRfGS3aaC6N9CCxhBnOZksrWzrss5r88oBPGPNkJ70Voa8hqUdbsz+pnRHN/6ma45H0yCK16hgCCql3IYVGBi6uh2GsyBc6o+3QwGJgI32HVGVPhx75L5pcKncMiYIG9V1Cw0wCz2+PJS+XNW76+GEwo4r3QrYesdetcB/EMjur0uyzW2SgzBqVgxkaEzz/R4xAydAMPmXsZQDSju7auCN7UhOHj37j6rMtrCJRuct2k/ZEqBHtZk6rR8EyTn377Ro5VWzgSF3d2zX7Qx2Hn9xqxCi6RjoUPpfO2vQ4mIzaXiEvkk2XNHDdkkprYIp0Uf7D/5vRp4EBuorniNQbH4NN0JmcJg8IRxJCysj2iDu+sCP5Krzl6DWPw7t9HbCyt0cm8Rbxi6DH5O9dwR+c20mrsBa81lIgfc+niBlA36EC05FFrdzwJgNyz6OSPZYH0ovYVkf7tCJ+un/gVHJevlrTzqo6n7UWeQ+UTOJRrm5B3Xy4EzHfZndjIjorWB7GiuiT4iD+txpDdeD15g8wD3jwp5lRNBzJ5PCT3NReODHPi8w+kkLdFhdd46HhMU8ynGDDBdpLanERzkcGxzHDqn3A1gOkCyhiYRJorTD51W831euMLyf7EWlUu9MrHQnRNjsSrqDnBQrAj6QxKu4jH1mT3joSDe6SKmoll8Au4stcLvOqzyovv6pGvs8wBjWwy7KcyiS9k/icCFgPgofaUL+wfMv+/BMyw7/GTVAR2+GOFinRpx X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 01b2f255-1518-458d-99f3-08dbb94a8d41 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:56:45.4106 (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: DU2P250MB0303 Subject: [FFmpeg-devel] [PATCH 03/42] avcodec/get_buffer: Use RefStruct API for FramePool 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: 45CfHniJH/CD Avoids allocations and frees and error checks for said allocations; also avoids a few indirections and casts. Signed-off-by: Andreas Rheinhardt --- libavcodec/avcodec.c | 3 ++- libavcodec/get_buffer.c | 44 ++++++++++---------------------------- libavcodec/internal.h | 2 +- libavcodec/pthread_frame.c | 7 +++--- 4 files changed, 17 insertions(+), 39 deletions(-) diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index 131834b6de..6365ab87a6 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -43,6 +43,7 @@ #include "frame_thread_encoder.h" #include "hwconfig.h" #include "internal.h" +#include "refstruct.h" #include "thread.h" /** @@ -458,7 +459,7 @@ av_cold int avcodec_close(AVCodecContext *avctx) av_frame_free(&avci->in_frame); av_frame_free(&avci->recon_frame); - av_buffer_unref(&avci->pool); + ff_refstruct_unref(&avci->pool); ff_hwaccel_uninit(avctx); diff --git a/libavcodec/get_buffer.c b/libavcodec/get_buffer.c index a04fd878de..647f8a3df7 100644 --- a/libavcodec/get_buffer.c +++ b/libavcodec/get_buffer.c @@ -32,6 +32,7 @@ #include "avcodec.h" #include "internal.h" +#include "refstruct.h" typedef struct FramePool { /** @@ -52,40 +53,18 @@ typedef struct FramePool { int samples; } FramePool; -static void frame_pool_free(void *opaque, uint8_t *data) +static void frame_pool_free(FFRefStructOpaque unused, void *obj) { - FramePool *pool = (FramePool*)data; + FramePool *pool = obj; int i; for (i = 0; i < FF_ARRAY_ELEMS(pool->pools); i++) av_buffer_pool_uninit(&pool->pools[i]); - - av_freep(&data); -} - -static AVBufferRef *frame_pool_alloc(void) -{ - FramePool *pool = av_mallocz(sizeof(*pool)); - AVBufferRef *buf; - - if (!pool) - return NULL; - - buf = av_buffer_create((uint8_t*)pool, sizeof(*pool), - frame_pool_free, NULL, 0); - if (!buf) { - av_freep(&pool); - return NULL; - } - - return buf; } static int update_frame_pool(AVCodecContext *avctx, AVFrame *frame) { - FramePool *pool = avctx->internal->pool ? - (FramePool*)avctx->internal->pool->data : NULL; - AVBufferRef *pool_buf; + FramePool *pool = avctx->internal->pool; int i, ret, ch, planes; if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) { @@ -109,10 +88,9 @@ FF_ENABLE_DEPRECATION_WARNINGS return 0; } - pool_buf = frame_pool_alloc(); - if (!pool_buf) + pool = ff_refstruct_alloc_ext(sizeof(*pool), 0, NULL, frame_pool_free); + if (!pool) return AVERROR(ENOMEM); - pool = (FramePool*)pool_buf->data; switch (avctx->codec_type) { case AVMEDIA_TYPE_VIDEO: { @@ -189,18 +167,18 @@ FF_ENABLE_DEPRECATION_WARNINGS default: av_assert0(0); } - av_buffer_unref(&avctx->internal->pool); - avctx->internal->pool = pool_buf; + ff_refstruct_unref(&avctx->internal->pool); + avctx->internal->pool = pool; return 0; fail: - av_buffer_unref(&pool_buf); + ff_refstruct_unref(&pool); return ret; } static int audio_get_buffer(AVCodecContext *avctx, AVFrame *frame) { - FramePool *pool = (FramePool*)avctx->internal->pool->data; + FramePool *pool = avctx->internal->pool; int planes = pool->planes; int i; @@ -245,7 +223,7 @@ fail: static int video_get_buffer(AVCodecContext *s, AVFrame *pic) { - FramePool *pool = (FramePool*)s->internal->pool->data; + FramePool *pool = s->internal->pool; int i; if (pic->data[0] || pic->data[1] || pic->data[2] || pic->data[3]) { diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 83e0bc3fb2..eb9e0d707c 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -62,7 +62,7 @@ typedef struct AVCodecInternal { */ int pad_samples; - AVBufferRef *pool; + struct FramePool *pool; void *thread_ctx; diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index 138576778d..7e274b0559 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -35,6 +35,7 @@ #include "hwconfig.h" #include "internal.h" #include "pthread_internal.h" +#include "refstruct.h" #include "thread.h" #include "threadframe.h" #include "version_major.h" @@ -329,9 +330,7 @@ FF_ENABLE_DEPRECATION_WARNINGS dst->hwaccel_flags = src->hwaccel_flags; - err = av_buffer_replace(&dst->internal->pool, src->internal->pool); - if (err < 0) - return err; + ff_refstruct_replace(&dst->internal->pool, src->internal->pool); } if (for_user) { @@ -740,7 +739,7 @@ void ff_frame_thread_free(AVCodecContext *avctx, int thread_count) av_freep(&ctx->priv_data); } - av_buffer_unref(&ctx->internal->pool); + ff_refstruct_unref(&ctx->internal->pool); av_packet_free(&ctx->internal->last_pkt_props); av_freep(&ctx->internal); av_buffer_unref(&ctx->hw_frames_ctx); From patchwork Tue Sep 19 19:56:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43815 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp185444pzb; Tue, 19 Sep 2023 12:57:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHCORyxWRrZqMzO/HmoXNYhoJJAoMl+D1RxFhPeNkU36fNhNYIcEUjEptt0VukpuPvFrui6 X-Received: by 2002:a17:906:1ce:b0:9a1:af6f:e375 with SMTP id 14-20020a17090601ce00b009a1af6fe375mr325379ejj.35.1695153433128; Tue, 19 Sep 2023 12:57:13 -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 ce21-20020a170906b25500b009ae104e5dacsi3993737ejb.34.2023.09.19.12.57.11; Tue, 19 Sep 2023 12:57:13 -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=T2b6bloX; 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 62E7E68C90A; Tue, 19 Sep 2023 22:56:54 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2101.outbound.protection.outlook.com [40.92.91.101]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 00DA3680101 for ; Tue, 19 Sep 2023 22:56:51 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SkH4zItbUxt5OYsffR5pFwJXhbc4c0PAOoL2j+SgFlMZcuz4yC2s8BOHE04AB6wTLQPa7utwMyPMysaYcl4rtrZuQx2vyfgwVkspUe5jjzLgM/FvZre+Shg4qMPw8HacP5lWJHq5KEQCmfxry6zcZxC7JTmb+p5kbTtJNucBDXkCwA1vXlMHqYWrQ9nQf4E4U52pby5972uHPUJlI63b/T/hBXJMMQJRZ1uK+k0MWhQlJmurif4zA0cwyf1kQrKweZKR7/JX8WNGH6Fzlfys+VFEuAU4TSF9axedBQeysO8PhnRSErw2vWyrG0qifniv1vWimKbCEwzI6O+Ma+bTvQ== 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=xvn9mL0d5HCnV1MN5pbhoqA6niILppjfvwTbkAN/qRk=; b=XDjEeuL2nzj9OTwMHBC56rvDeY6SKihxW/iuNlyuUoYPmKVJdEFUxxzlTN8aJ7cnb0vnMa+Fzdr7KRipSNAkLDnd0B2rHBhc5v8U+iTUeY0X44+v1lbltcEm2pSFZH6KZ8mFg1wj9DtBdt9vXSj3iORnIZUzepU9ZBnzWl75fc4+sJmAS36eLrGc9rE1LOpmMAe7aICc4lqFz/Vxr46MhQNEKfa4ntY8h7Vj+OL6m6f3/e3RefTjl4a3sU6cJ8XcRkHPCnLPjsUO155xlXfdZY6Hz6KbPyeayHmAbDl3ot3ztAq3c3bi5SeF6+RQNNU33gLWKNrt9SWe8H06pQYN5Q== 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=xvn9mL0d5HCnV1MN5pbhoqA6niILppjfvwTbkAN/qRk=; b=T2b6bloXTIFMiiTxHf6s0JQkHq7GA5y3yM1QASSbs5B2al0cG82HQt7zUEeBTp3BeZfFKUmo0LgGTSXxEpplNAlFWaZ9DPxvWJSWmL6NeUD/MlTWBewjDpkU+6QTQbzi6b7e5BCtMxMqel3Gvkmskz3BjwXSaWwfPG3yKueHM6ELJji3dz36IiTiKa42qgb/6wH+rro48iRtG6RdlFeT/g2/jqPBAi/egPAACC4koEI5P0yEPVKCtlR8EZgaBOVjB+idOjpG2nK8FGnrKUIkC7nk93TPSw+99tVIwsIb69XRrA7rEy2pzbHuG4U1w2WhzOj9rGqVNtZZXcpi43gcGw== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0303.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:27c::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:56:50 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:56:50 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:56:56 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [FExxg0o4+UHbktQzvUfeLAcEyBEBm9a0] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-4-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0303:EE_ X-MS-Office365-Filtering-Correlation-Id: 6d38ac21-01cf-4004-3740-08dbb94a9073 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: R8qQ73t4Hyw7YHoLUeBxQbpHk2MWruesiHDPm/jVajSmcFudP6YNg2xwz0SlGfn64GEAlg2Czk8+tuxNd0ruUaUMLGw8g10Xmf0rWmBmthV6ZMYNtyBbbEB/7msNjrOo5hQeuOi0MIpmLUuHk/QQ4BJk+r03zWTQT2fGzKni9WeauxSNMEp0s+EKFp/MHqBy3r/wcvCVpXicL70vCjzQdL71GzEkqSwj7XwAFrFB2K5JiOXqN/CVKDDN/npCLbCo8YHBBFLcp1M52eWi4VzpJNlTNTU5Gh8uue4YgzLcKeSHf6hgA6dInXhDLKjv1IqqqIgZWbggF/vob9HChCz3Gdd96jjjna1A633S+IWAxlSfeo0P+iH8BNDHKCA142YAm8Iws6gTigS7u+4gPbuq09xQnYVyku+9dYapSbKuUz7RB9TB0FQoUp/ePTVaZ1TFJ/f+v0WIkE73Z2DyQDURtBn7IRYs94Xkcnfu3ExYQD/dMMwjIbEqjN+pso+itrj/IfKhhlkXX6Zrm6RNBK8zWWFBjFvpxAM2DXIH+zduuaIwsRNchP8iAUEX2yHm8m2nHqN2BEms9Ilyjwpne03QMPuYHIJYD+M/pRDMMyK0dzvXk7fiXxEgUlzx4cp0pPtH X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dVmYca19DKebDHaFu+H8VKmh3a7lsWxHWBbYraM8RX+vG4Zx2vbF549v8vm4t8oJQ1zs/LYwkffse2OxiiAFMFaStELh6jiY/g31M5Vs1Jx2pegSvteTNKCpv3jRA4vveNuur5c7dp9L+JgBrs5UV+mMcv4xigYizRJt8JdHqTz8RnNWDME6YbPhgOV846DaoL5F26wv3G4Yr0+YCwBidPSlNJiUoS0hPT+ozOOL3Zs1+RTslTLm7Wkkv2R5hvzWBLuG3h6eQd4KvB+4LIrNqpqll5mFIetLZ7hi+catBdtnw5vYU1t9KQk/t3LLlUPmD+L1CEZzONKhaDVCGlpzNpjzHg+vQvM4YZjSLfAebixPuRpL2SPMvSCuBwufH9teX+oGub4n+eHRuVHMae46vBTHplUKOYxfmBeKLIPqr2vB8N0T/AU66w+0djZwJUHCEqA5QufuZxrsgZSkr0a30QNRo6YjxMj6VUczLIrpCstMyOIDQY2lMSu/SMu2Q7Lx4Xu3VXkgGKBMRnPPvbCbi/S0SlIlSexZB9i2JKDYe/J1gSApmuro6L59BkOcKoY0tKemIxulbWeOG9MT5RzfNkaZdjeefbHSfDW6CiU14f2pMmi/kW4MthOGlh2KmtmpUh8CX4jFQygK35+8eUU0OpAUnbIL68H3iCCvVU4MzzSd++ehH7Qkd0sEea1aKxKciGRadK48Ihk8yMaaD+89m31NgsP68JCFmaitirENbrKO9qiZxkTzGRoyXAOkJO2ejvUVKd5U4Ty42JEORgbB/NZyQgng6PLctJnXjcjWygbg43NLpAEJmjRzpWQZY2NWCr3Lb3F87hAIJ/Ncjl64dVeftQTL7B/z58yrUD1rPDhsL4Eo2f/4z265d/jOVLd0ck2P0XWlGyPjxo6U/JvpJp+s1TAiwkOl6adohQzzJS6o0ye1VJKOEKMXc7j5elBIdUxI5cjcqxjNltih0uwSw2Psuo5TsnPwoUJ7PHbfz4/dq2jbVclfg9n6mTmvaurzzqFiJVeXVg6xaxAbKXIqlj8iOyigbMU63GIxbMFkqPpkIPXsA3PuWMV/7z4hEnhbTClJx9BWjx+77ZbKQtVKNH4njU9G9XWhos/Oo5emEOF31PlHoK50LQ6JI9cOMbTLnOwSMwl73Hv6gDzpBT7Aq0p/3d890AuFzyMg7swe9gqzWzT+updICCyVSgIhHa14GahSmEaoDUngiB1j+jqzNbc2uzY+4jJEL59tZbFiG+oFLx6lfYStGaMlRk5M1NXd X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6d38ac21-01cf-4004-3740-08dbb94a9073 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:56:50.7637 (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: DU2P250MB0303 Subject: [FFmpeg-devel] [PATCH 04/42] avcodec/h264_ps: Use RefStruct API for SPS/PPS 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: 4oJwNqoYoJ/R Avoids allocations and error checks for these allocations; e.g. syncing buffers across threads can't fail any more and needn't be checked. It also avoids having to keep H264ParamSets.pps and H264ParamSets.pps_ref and PPS.sps and PPS.sps_ref in sync and gets rid of casts and indirections. (The removal of these checks and the syncing code even more than offset the additional code for RefStruct.) Signed-off-by: Andreas Rheinhardt --- libavcodec/h264_parser.c | 9 ++---- libavcodec/h264_picture.c | 10 +++---- libavcodec/h264_ps.c | 57 +++++++++++++------------------------- libavcodec/h264_ps.h | 13 ++++----- libavcodec/h264_refs.c | 2 +- libavcodec/h264_sei.c | 2 +- libavcodec/h264_slice.c | 41 ++++++++------------------- libavcodec/h264dec.h | 1 - libavcodec/mediacodecdec.c | 4 +-- libavcodec/vulkan_h264.c | 4 +-- 10 files changed, 50 insertions(+), 93 deletions(-) diff --git a/libavcodec/h264_parser.c b/libavcodec/h264_parser.c index 43abc45f9c..3574010a64 100644 --- a/libavcodec/h264_parser.c +++ b/libavcodec/h264_parser.c @@ -47,6 +47,7 @@ #include "h264data.h" #include "mpegutils.h" #include "parser.h" +#include "refstruct.h" #include "startcode.h" typedef struct H264ParseContext { @@ -373,13 +374,7 @@ static inline int parse_nal_units(AVCodecParserContext *s, goto fail; } - av_buffer_unref(&p->ps.pps_ref); - p->ps.pps = NULL; - p->ps.sps = NULL; - p->ps.pps_ref = av_buffer_ref(p->ps.pps_list[pps_id]); - if (!p->ps.pps_ref) - goto fail; - p->ps.pps = (const PPS*)p->ps.pps_ref->data; + ff_refstruct_replace(&p->ps.pps, p->ps.pps_list[pps_id]); p->ps.sps = p->ps.pps->sps; sps = p->ps.sps; diff --git a/libavcodec/h264_picture.c b/libavcodec/h264_picture.c index 31b5e231c2..25d0d96ddb 100644 --- a/libavcodec/h264_picture.c +++ b/libavcodec/h264_picture.c @@ -32,6 +32,7 @@ #include "h264dec.h" #include "hwaccel_internal.h" #include "mpegutils.h" +#include "refstruct.h" #include "thread.h" #include "threadframe.h" @@ -49,7 +50,7 @@ void ff_h264_unref_picture(H264Context *h, H264Picture *pic) av_buffer_unref(&pic->qscale_table_buf); av_buffer_unref(&pic->mb_type_buf); - av_buffer_unref(&pic->pps_buf); + ff_refstruct_unref(&pic->pps); for (i = 0; i < 2; i++) { av_buffer_unref(&pic->motion_val_buf[i]); av_buffer_unref(&pic->ref_index_buf[i]); @@ -61,9 +62,10 @@ void ff_h264_unref_picture(H264Context *h, H264Picture *pic) static void h264_copy_picture_params(H264Picture *dst, const H264Picture *src) { + ff_refstruct_replace(&dst->pps, src->pps); + dst->qscale_table = src->qscale_table; dst->mb_type = src->mb_type; - dst->pps = src->pps; for (int i = 0; i < 2; i++) { dst->motion_val[i] = src->motion_val[i]; @@ -113,8 +115,7 @@ int ff_h264_ref_picture(H264Context *h, H264Picture *dst, H264Picture *src) dst->qscale_table_buf = av_buffer_ref(src->qscale_table_buf); dst->mb_type_buf = av_buffer_ref(src->mb_type_buf); - dst->pps_buf = av_buffer_ref(src->pps_buf); - if (!dst->qscale_table_buf || !dst->mb_type_buf || !dst->pps_buf) { + if (!dst->qscale_table_buf || !dst->mb_type_buf) { ret = AVERROR(ENOMEM); goto fail; } @@ -174,7 +175,6 @@ int ff_h264_replace_picture(H264Context *h, H264Picture *dst, const H264Picture ret = av_buffer_replace(&dst->qscale_table_buf, src->qscale_table_buf); ret |= av_buffer_replace(&dst->mb_type_buf, src->mb_type_buf); - ret |= av_buffer_replace(&dst->pps_buf, src->pps_buf); if (ret < 0) goto fail; diff --git a/libavcodec/h264_ps.c b/libavcodec/h264_ps.c index 53446e9aab..dcc51b96db 100644 --- a/libavcodec/h264_ps.c +++ b/libavcodec/h264_ps.c @@ -34,6 +34,7 @@ #include "h2645_vui.h" #include "h264_ps.h" #include "golomb.h" +#include "refstruct.h" #define MIN_LOG2_MAX_FRAME_NUM 4 @@ -85,7 +86,7 @@ static const int level_max_dpb_mbs[][2] = { static void remove_pps(H264ParamSets *s, int id) { - av_buffer_unref(&s->pps_list[id]); + ff_refstruct_unref(&s->pps_list[id]); } static void remove_sps(H264ParamSets *s, int id) @@ -95,11 +96,11 @@ static void remove_sps(H264ParamSets *s, int id) if (s->sps_list[id]) { /* drop all PPS that depend on this SPS */ for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++) - if (s->pps_list[i] && ((PPS*)s->pps_list[i]->data)->sps_id == id) + if (s->pps_list[i] && s->pps_list[i]->sps_id == id) remove_pps(s, i); } #endif - av_buffer_unref(&s->sps_list[id]); + ff_refstruct_unref(&s->sps_list[id]); } static inline int decode_hrd_parameters(GetBitContext *gb, void *logctx, @@ -271,31 +272,27 @@ void ff_h264_ps_uninit(H264ParamSets *ps) int i; for (i = 0; i < MAX_SPS_COUNT; i++) - av_buffer_unref(&ps->sps_list[i]); + ff_refstruct_unref(&ps->sps_list[i]); for (i = 0; i < MAX_PPS_COUNT; i++) - av_buffer_unref(&ps->pps_list[i]); + ff_refstruct_unref(&ps->pps_list[i]); - av_buffer_unref(&ps->pps_ref); - - ps->pps = NULL; + ff_refstruct_unref(&ps->pps); ps->sps = NULL; } int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, H264ParamSets *ps, int ignore_truncation) { - AVBufferRef *sps_buf; int profile_idc, level_idc, constraint_set_flags = 0; unsigned int sps_id; int i, log2_max_frame_num_minus4; SPS *sps; int ret; - sps_buf = av_buffer_allocz(sizeof(*sps)); - if (!sps_buf) + sps = ff_refstruct_allocz(sizeof(*sps)); + if (!sps) return AVERROR(ENOMEM); - sps = (SPS*)sps_buf->data; sps->data_size = gb->buffer_end - gb->buffer; if (sps->data_size > sizeof(sps->data)) { @@ -580,17 +577,17 @@ int ff_h264_decode_seq_parameter_set(GetBitContext *gb, AVCodecContext *avctx, * original one. * otherwise drop all PPSes that depend on it */ if (ps->sps_list[sps_id] && - !memcmp(ps->sps_list[sps_id]->data, sps_buf->data, sps_buf->size)) { - av_buffer_unref(&sps_buf); + !memcmp(ps->sps_list[sps_id], sps, sizeof(*sps))) { + ff_refstruct_unref(&sps); } else { remove_sps(ps, sps_id); - ps->sps_list[sps_id] = sps_buf; + ps->sps_list[sps_id] = sps; } return 0; fail: - av_buffer_unref(&sps_buf); + ff_refstruct_unref(&sps); return AVERROR_INVALIDDATA; } @@ -689,19 +686,16 @@ static int more_rbsp_data_in_pps(const SPS *sps, void *logctx) return 1; } -static void pps_free(void *opaque, uint8_t *data) +static void pps_free(FFRefStructOpaque unused, void *obj) { - PPS *pps = (PPS*)data; - - av_buffer_unref(&pps->sps_ref); + PPS *pps = obj; - av_freep(&data); + ff_refstruct_unref(&pps->sps); } int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avctx, H264ParamSets *ps, int bit_length) { - AVBufferRef *pps_buf; const SPS *sps; unsigned int pps_id = get_ue_golomb(gb); PPS *pps; @@ -714,15 +708,9 @@ int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avct return AVERROR_INVALIDDATA; } - pps = av_mallocz(sizeof(*pps)); + pps = ff_refstruct_alloc_ext(sizeof(*pps), 0, NULL, pps_free); if (!pps) return AVERROR(ENOMEM); - pps_buf = av_buffer_create((uint8_t*)pps, sizeof(*pps), - pps_free, NULL, 0); - if (!pps_buf) { - av_freep(&pps); - return AVERROR(ENOMEM); - } pps->data_size = gb->buffer_end - gb->buffer; if (pps->data_size > sizeof(pps->data)) { @@ -745,12 +733,7 @@ int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avct ret = AVERROR_INVALIDDATA; goto fail; } - pps->sps_ref = av_buffer_ref(ps->sps_list[pps->sps_id]); - if (!pps->sps_ref) { - ret = AVERROR(ENOMEM); - goto fail; - } - pps->sps = (const SPS*)pps->sps_ref->data; + pps->sps = ff_refstruct_ref_c(ps->sps_list[pps->sps_id]); sps = pps->sps; if (sps->bit_depth_luma > 14) { @@ -852,11 +835,11 @@ int ff_h264_decode_picture_parameter_set(GetBitContext *gb, AVCodecContext *avct } remove_pps(ps, pps_id); - ps->pps_list[pps_id] = pps_buf; + ps->pps_list[pps_id] = pps; return 0; fail: - av_buffer_unref(&pps_buf); + ff_refstruct_unref(&pps); return ret; } diff --git a/libavcodec/h264_ps.h b/libavcodec/h264_ps.h index e675619635..80af4832fe 100644 --- a/libavcodec/h264_ps.h +++ b/libavcodec/h264_ps.h @@ -26,7 +26,6 @@ #include -#include "libavutil/buffer.h" #include "libavutil/pixfmt.h" #include "libavutil/rational.h" @@ -139,18 +138,16 @@ typedef struct PPS { uint32_t(*dequant4_coeff[6])[16]; uint32_t(*dequant8_coeff[6])[64]; - AVBufferRef *sps_ref; - const SPS *sps; + const SPS *sps; ///< RefStruct reference } PPS; typedef struct H264ParamSets { - AVBufferRef *sps_list[MAX_SPS_COUNT]; - AVBufferRef *pps_list[MAX_PPS_COUNT]; + const SPS *sps_list[MAX_SPS_COUNT]; ///< RefStruct references + const PPS *pps_list[MAX_PPS_COUNT]; ///< RefStruct references - AVBufferRef *pps_ref; /* currently active parameters sets */ - const PPS *pps; - const SPS *sps; + const PPS *pps; ///< RefStruct reference + const SPS *sps; ///< ordinary pointer, no RefStruct reference int overread_warning_printed[2]; } H264ParamSets; diff --git a/libavcodec/h264_refs.c b/libavcodec/h264_refs.c index 50bbe94917..1b24c493df 100644 --- a/libavcodec/h264_refs.c +++ b/libavcodec/h264_refs.c @@ -807,7 +807,7 @@ int ff_h264_execute_ref_pic_marking(H264Context *h) for (i = 0; i < FF_ARRAY_ELEMS(h->ps.pps_list); i++) { if (h->ps.pps_list[i]) { - const PPS *pps = (const PPS *)h->ps.pps_list[i]->data; + const PPS *pps = h->ps.pps_list[i]; pps_ref_count[0] = FFMAX(pps_ref_count[0], pps->ref_count[0]); pps_ref_count[1] = FFMAX(pps_ref_count[1], pps->ref_count[1]); } diff --git a/libavcodec/h264_sei.c b/libavcodec/h264_sei.c index 668204959f..8d6dc77943 100644 --- a/libavcodec/h264_sei.c +++ b/libavcodec/h264_sei.c @@ -179,7 +179,7 @@ static int decode_buffering_period(H264SEIBufferingPeriod *h, GetBitContext *gb, "non-existing SPS %d referenced in buffering period\n", sps_id); return sps_id > 31 ? AVERROR_INVALIDDATA : AVERROR_PS_NOT_FOUND; } - sps = (const SPS*)ps->sps_list[sps_id]->data; + sps = ps->sps_list[sps_id]; // NOTE: This is really so duplicated in the standard... See H.264, D.1.1 if (sps->nal_hrd_parameters_present_flag) { diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 5657327f0c..632f5b23b2 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -44,6 +44,7 @@ #include "mathops.h" #include "mpegutils.h" #include "rectangle.h" +#include "refstruct.h" #include "thread.h" #include "threadframe.h" @@ -254,10 +255,7 @@ static int alloc_picture(H264Context *h, H264Picture *pic) pic->ref_index[i] = pic->ref_index_buf[i]->data; } - pic->pps_buf = av_buffer_ref(h->ps.pps_ref); - if (!pic->pps_buf) - goto fail; - pic->pps = (const PPS*)pic->pps_buf->data; + pic->pps = ff_refstruct_ref_c(h->ps.pps); pic->mb_width = h->mb_width; pic->mb_height = h->mb_height; @@ -363,25 +361,16 @@ int ff_h264_update_thread_context(AVCodecContext *dst, // SPS/PPS for (i = 0; i < FF_ARRAY_ELEMS(h->ps.sps_list); i++) { - ret = av_buffer_replace(&h->ps.sps_list[i], h1->ps.sps_list[i]); - if (ret < 0) - return ret; + ff_refstruct_replace(&h->ps.sps_list[i], h1->ps.sps_list[i]); } for (i = 0; i < FF_ARRAY_ELEMS(h->ps.pps_list); i++) { - ret = av_buffer_replace(&h->ps.pps_list[i], h1->ps.pps_list[i]); - if (ret < 0) - return ret; + ff_refstruct_replace(&h->ps.pps_list[i], h1->ps.pps_list[i]); } - ret = av_buffer_replace(&h->ps.pps_ref, h1->ps.pps_ref); - if (ret < 0) - return ret; - h->ps.pps = NULL; + ff_refstruct_replace(&h->ps.pps, h1->ps.pps); h->ps.sps = NULL; - if (h1->ps.pps_ref) { - h->ps.pps = (const PPS*)h->ps.pps_ref->data; + if (h1->ps.pps) h->ps.sps = h->ps.pps->sps; - } if (need_reinit || !inited) { h->width = h1->width; @@ -935,7 +924,7 @@ static enum AVPixelFormat get_pixel_format(H264Context *h, int force_callback) /* export coded and cropped frame dimensions to AVCodecContext */ static void init_dimensions(H264Context *h) { - const SPS *sps = (const SPS*)h->ps.sps; + const SPS *sps = h->ps.sps; int cr = sps->crop_right; int cl = sps->crop_left; int ct = sps->crop_top; @@ -1071,17 +1060,11 @@ static int h264_init_ps(H264Context *h, const H264SliceContext *sl, int first_sl const SPS *sps; int needs_reinit = 0, must_reinit, ret; - if (first_slice) { - av_buffer_unref(&h->ps.pps_ref); - h->ps.pps = NULL; - h->ps.pps_ref = av_buffer_ref(h->ps.pps_list[sl->pps_id]); - if (!h->ps.pps_ref) - return AVERROR(ENOMEM); - h->ps.pps = (const PPS*)h->ps.pps_ref->data; - } + if (first_slice) + ff_refstruct_replace(&h->ps.pps, h->ps.pps_list[sl->pps_id]); if (h->ps.sps != h->ps.pps->sps) { - h->ps.sps = (const SPS*)h->ps.pps->sps; + h->ps.sps = h->ps.pps->sps; if (h->mb_width != h->ps.sps->mb_width || h->mb_height != h->ps.sps->mb_height || @@ -1753,7 +1736,7 @@ static int h264_slice_header_parse(const H264Context *h, H264SliceContext *sl, sl->pps_id); return AVERROR_INVALIDDATA; } - pps = (const PPS*)h->ps.pps_list[sl->pps_id]->data; + pps = h->ps.pps_list[sl->pps_id]; sps = pps->sps; sl->frame_num = get_bits(&sl->gb, sps->log2_max_frame_num); @@ -2140,7 +2123,7 @@ int ff_h264_queue_decode_slice(H264Context *h, const H2645NAL *nal) } if (!first_slice) { - const PPS *pps = (const PPS*)h->ps.pps_list[sl->pps_id]->data; + const PPS *pps = h->ps.pps_list[sl->pps_id]; if (h->ps.pps->sps_id != pps->sps_id || h->ps.pps->transform_8x8_mode != pps->transform_8x8_mode /*|| diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h index 322c06a19c..513856749a 100644 --- a/libavcodec/h264dec.h +++ b/libavcodec/h264dec.h @@ -147,7 +147,6 @@ typedef struct H264Picture { int sei_recovery_frame_cnt; int needs_fg; ///< whether picture needs film grain synthesis (see `f_grain`) - AVBufferRef *pps_buf; const PPS *pps; int mb_width, mb_height; diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c index 44f55947be..52b3a2c1f7 100644 --- a/libavcodec/mediacodecdec.c +++ b/libavcodec/mediacodecdec.c @@ -146,14 +146,14 @@ static int h264_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format) for (i = 0; i < MAX_PPS_COUNT; i++) { if (ps.pps_list[i]) { - pps = (const PPS*)ps.pps_list[i]->data; + pps = ps.pps_list[i]; break; } } if (pps) { if (ps.sps_list[pps->sps_id]) { - sps = (const SPS*)ps.sps_list[pps->sps_id]->data; + sps = ps.sps_list[pps->sps_id]; } } diff --git a/libavcodec/vulkan_h264.c b/libavcodec/vulkan_h264.c index 32ef32d640..cdc2c7fe30 100644 --- a/libavcodec/vulkan_h264.c +++ b/libavcodec/vulkan_h264.c @@ -321,7 +321,7 @@ static int vk_h264_create_params(AVCodecContext *avctx, AVBufferRef **buf) /* SPS list */ for (int i = 0; i < FF_ARRAY_ELEMS(h->ps.sps_list); i++) { if (h->ps.sps_list[i]) { - const SPS *sps_l = (const SPS *)h->ps.sps_list[i]->data; + const SPS *sps_l = h->ps.sps_list[i]; int idx = h264_params_info.stdSPSCount; set_sps(sps_l, &vksps_scaling[idx], &vksps_vui_header[idx], &vksps_vui[idx], &vksps[idx]); h264_params_info.stdSPSCount++; @@ -331,7 +331,7 @@ static int vk_h264_create_params(AVCodecContext *avctx, AVBufferRef **buf) /* PPS list */ for (int i = 0; i < FF_ARRAY_ELEMS(h->ps.pps_list); i++) { if (h->ps.pps_list[i]) { - const PPS *pps_l = (const PPS *)h->ps.pps_list[i]->data; + const PPS *pps_l = h->ps.pps_list[i]; int idx = h264_params_info.stdPPSCount; set_pps(pps_l, pps_l->sps, &vkpps_scaling[idx], &vkpps[idx]); h264_params_info.stdPPSCount++; From patchwork Tue Sep 19 19:56:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43816 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp185506pzb; Tue, 19 Sep 2023 12:57:22 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG9SRAfikA1cBxdTqnbmYX+9SRszH/U3utaxUuhp4U6hrYcjZawLtNpupmIneAq9M39SJHZ X-Received: by 2002:a05:6512:308d:b0:503:18c3:d881 with SMTP id z13-20020a056512308d00b0050318c3d881mr747112lfd.14.1695153442341; Tue, 19 Sep 2023 12:57:22 -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 b19-20020aa7cd13000000b00532ec75465fsi190396edw.585.2023.09.19.12.57.21; Tue, 19 Sep 2023 12:57:22 -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=hg0Bga4Y; 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 5E16868C91D; Tue, 19 Sep 2023 22:56:56 +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-db8eur05olkn2104.outbound.protection.outlook.com [40.92.89.104]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3F1D268C7DD for ; Tue, 19 Sep 2023 22:56:54 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Wm4yKd/ImgI6jxwyQSBj3GVjGvtG3G9udGLtfTIUBxEM+dRGjdARsOA72ISyTW+QLpf367zsVtS3bNweDA/CXqTtCbOoy2kU2TRvf2iUIj/ADmNOYdCAAot9n1z6eeA24tz6G+BvtReMIzlzdj2jdD8ReO7HBJ+9DXqsgQ9zarYJKlCEH/iOLPg3kxG07s5O2B1Dtg+G0Bdm9kF53aLk/eJgG19aCroiPWagfTCb9qDtLNcc+XFiAe+NSdoc7Y3ji/oPPBjqeSxome+/Iacj3Iy+qyIfKoW4huqXO3v+HenYM5Ld3nAyLE9V9EagwYrVNJ9JRJkDc9jno7zFwaQesA== 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=46TLRMrCcaaRQVQ0h1w3s45uYKeKl01q9bMvTOk0pDU=; b=C7g4I3OpcQDR9wIMPaQB8EFKKAgXkZg5hyCDmeFiDupsmHWxuNACswTizreQ91/8gdeunPuwy+Pak3O577SJClZLrAYhWa5gvpys8HDrOvAwbdEfy0ggbC7kq3F+PiR5B5PaGUhsTy4YUvbuF5T6l/IjXImkGaX2wcGspd/5ySDDmYKHo0EDSmS51YmWG39v1QLoPB9po/s63IIh6aPyjmcdRucb8UE4+Nc0OGRqKEpI8P9qcFhFYWhOz4LuN0wDoWTlHKzHaaqg9mAQ1MWaiU8MTnqA0fG6erdkxx5memY1E1ufcdIXu5lgDM62B2MLdqGi25a5sRE0VEmo8XONLA== 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=46TLRMrCcaaRQVQ0h1w3s45uYKeKl01q9bMvTOk0pDU=; b=hg0Bga4YzyUgcBMKGsscPZPiDQA20Sl9KbzwTVAsuWQrMfHU5InAMahgDzqlZt/lkIs4EOwZA4q6dEb+Ta6c53qC6e85P1y6ngnsEql3LWmhH9VcsA3TxNDftfUDqMlOdS4nL/7dOGNM1wqctvO4+kdMUNc9l1dT9CHF6ZAEc/rHhEa6WOutcLbRjpYkLyJ2vCnBs9SqkSQJ11BPGiG2ZURLYIsiouyjy4m41SclXotFQixGJM4B7BJ4YylCRFQx3rpG5sTfQL1rwa90gCLnqVY+3qj3iewJDZFmhycCODx4Di0fY1eortiOdR6JKfuKxDKqw85gEnsoLWgPWilMaA== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AM8P250MB0215.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:326::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:56:53 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:56:53 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:56:57 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [TjPRHSEoIwqPUY3FcvD5nHnKYSgrTbdk] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-5-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AM8P250MB0215:EE_ X-MS-Office365-Filtering-Correlation-Id: f5052b7c-639a-4988-f00d-08dbb94a91df X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ss5UdQzMz2EOJkPmkSiS4o0e2objQR+I+9FH5C52c5qpik1nH4JjXyGpRr4Nfwz2no2vD2AYs9qdYnea4yNgmz0LixfLmeVp5Fj8cAhB50revabsnhad4pjVQMh7nCfmUN8I8ydRCFvgWHpKRo54FhdWKNqbn4szgQthyT9NX6KasKu3+srmSaK3ZYXdws8TJKuNnKyz0Qosckr+AppQxPEQhSlntiBiIfOZgMaUS/kKClSbEVxN+7lbNGw08wbBvNsZZPz00xFhNtMlnmnVhW10WBMQRDC+yteo+AweJsMFK/1+LmBkzZCnDZUOQ8EkMDfd4y9Ws+HVi9lefrju1tnpkwDEyaTvn9GQ/riY4cXJmzB10L5OUjmbpDTeIR3s4xR4pEm5m7q3JKKX8ILuqWkaOhGZGuVZQC2jlx1HmmnWx3nvnm0+uMOBmlL8Jzi6yg+IpIMXwiRIFpeC8MPAFt3IS/9bh91UwHKf3F8Ww9ggYfwdx9xy/ZRVQm1Pl1hljw8xdewRDvi2XjpGJDVNPBN9DLxzPicWPypYIpNluPk0xwZ3hDmI1BdyuegQXYwTBIT+eMqvuhDdHdefupaH1im4Sj+Tj85AAlnSS40zo6k= X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FxexoGT27k05w7/5hPCy/aV1ay/wN/Tbju74Cbz7NBr40x74AvldZAUPKn6dI29CM3/KZzW2rtHIR6o3SJR/PRLqlm/3PXxmbSx0j6QjxTB1A7strCdAEjvF4KoGNi06+QQ4+njyoUU66UwLD5VIdjKHbk/3ooXv7/PsZ5IKJo+rOMcTAk3M1K52zZj7b7rRWGmtXRMb/Ho68AYCrnVgtE7vUHTxFXRYuphsPB5NBaCVZ+R7gymEVICibPQqSUJDdW5a1yKrCKa9eV+nQqdJRK8EoB5n4pde/0Cgc2+9IpLiTAgM8va8lrtHdRuOZ5zvJ484ZJwL6tbY4ndJnm/PtwV0Y9WULr1MnRDraTEaoxHJkVvUA8xhwXtBMQMdVu8N5UbvaE/jlOhdzwJbJq0hOiQTM6BxVDQ3N2B2J7JOkkGt2yF/vsi5vFuN1QuzgtRY8/WMzu99+PIofyIOVQmLXcr63N8AB+XShe6QHXAM+QrS2whqpO1eWERWG7tyLjXkMsYXQCxQrS9gM1FXP/K5VcUH8NBYeIN4JL8ep+Gf5e+BjJTsMb0A88cOTcErTbg3gZDYh9KlU4JtsMugbXcGYKuEMjDhV13RJcOdvbtwf4uH1H4bn9pw0iX4GSnB+j5JJwDk5SHlwL8pC965z9fGKW7NnONdzU/Xa85wY/RT6zOElzyAlBQmJPZb4tj6OkUtzv+GAAv6IHlCHjk5rkiKDgx9GoDe1d3gq7xAVqnkTKeUQmjPWNbCZBqe/2K/ywcIkR/mFKmX7r9zSHyGROFDPInlhZdxBgugALQ3HLvTdcakdAZGP4CIrDyvxTT+KledjlpSQSduqCB1iuJEV+WSNRS8navKIoR4gU6IDVwsT737/NoEYobWFaAU9yLCMg6aLyCH8smd7sQcelUUxNJ5PJeMcLfpvWR0MXXPY7eU3vId3OUhTSUEShF9SgFf/ualURvd74tCLIYR2fBqQtcCqNCpkqQqH0fXu60x6YxM3BeVj94UAmuKhf0XGWY7X9RZykVpXPZVeJVx8iEYoy5/mHKj04h5ny4fBtz9BVoZR+y+UQkxR8zaGXlhZmrCkdTF/NFhfgkqptaRocl/ZMX+cW4oIOiupsYQIMmzAIhxZFHWpiS3vADsrzxLxkNCiNGA14cQeQqr/E/yo1Kj2ZVEt02FvJ9ggW8cTdO0QkjV941XOpPT/OF8hWIliNk7UwLoieeY1Fl4xd8jRoC99vK97exkpOL/R/3UqBENTu2NWgOWH+ai6gMmaFAUznt4S6n5 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f5052b7c-639a-4988-f00d-08dbb94a91df X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:56:53.1839 (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: AM8P250MB0215 Subject: [FFmpeg-devel] [PATCH 05/42] avcodec/hevc_ps: Use RefStruct API for parameter sets 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: ZgpZUZ9Ua/nn Avoids allocations and error checks for these allocations; e.g. syncing buffers across threads can't fail any more and needn't be checked. It also gets rid of casts and indirections. Signed-off-by: Andreas Rheinhardt --- libavcodec/hevc_parser.c | 8 ++-- libavcodec/hevc_ps.c | 80 ++++++++++++++++---------------------- libavcodec/hevc_ps.h | 10 ++--- libavcodec/hevc_sei.c | 5 +-- libavcodec/hevcdec.c | 36 +++++++---------- libavcodec/mediacodecdec.c | 6 +-- libavcodec/videotoolbox.c | 4 +- libavcodec/vulkan_hevc.c | 16 ++++---- 8 files changed, 72 insertions(+), 93 deletions(-) diff --git a/libavcodec/hevc_parser.c b/libavcodec/hevc_parser.c index 59f9a0ff3e..87270cffb4 100644 --- a/libavcodec/hevc_parser.c +++ b/libavcodec/hevc_parser.c @@ -77,15 +77,15 @@ static int hevc_parse_slice_header(AVCodecParserContext *s, H2645NAL *nal, av_log(avctx, AV_LOG_ERROR, "PPS id out of range: %d\n", pps_id); return AVERROR_INVALIDDATA; } - ps->pps = (HEVCPPS*)ps->pps_list[pps_id]->data; + ps->pps = ps->pps_list[pps_id]; if (ps->pps->sps_id >= HEVC_MAX_SPS_COUNT || !ps->sps_list[ps->pps->sps_id]) { av_log(avctx, AV_LOG_ERROR, "SPS id out of range: %d\n", ps->pps->sps_id); return AVERROR_INVALIDDATA; } - if (ps->sps != (HEVCSPS*)ps->sps_list[ps->pps->sps_id]->data) { - ps->sps = (HEVCSPS*)ps->sps_list[ps->pps->sps_id]->data; - ps->vps = (HEVCVPS*)ps->vps_list[ps->sps->vps_id]->data; + if (ps->sps != ps->sps_list[ps->pps->sps_id]) { + ps->sps = ps->sps_list[ps->pps->sps_id]; + ps->vps = ps->vps_list[ps->sps->vps_id]; } ow = &ps->sps->output_window; diff --git a/libavcodec/hevc_ps.c b/libavcodec/hevc_ps.c index 7507d2bf9c..a6b64b92e3 100644 --- a/libavcodec/hevc_ps.c +++ b/libavcodec/hevc_ps.c @@ -28,6 +28,7 @@ #include "h2645_vui.h" #include "hevc_data.h" #include "hevc_ps.h" +#include "refstruct.h" static const uint8_t default_scaling_list_intra[] = { 16, 16, 16, 16, 17, 18, 21, 24, @@ -61,40 +62,40 @@ static const uint8_t hevc_sub_height_c[] = { static void remove_pps(HEVCParamSets *s, int id) { - if (s->pps_list[id] && s->pps == (const HEVCPPS*)s->pps_list[id]->data) + if (s->pps == s->pps_list[id]) s->pps = NULL; - av_buffer_unref(&s->pps_list[id]); + ff_refstruct_unref(&s->pps_list[id]); } static void remove_sps(HEVCParamSets *s, int id) { int i; if (s->sps_list[id]) { - if (s->sps == (const HEVCSPS*)s->sps_list[id]->data) + if (s->sps == s->sps_list[id]) s->sps = NULL; /* drop all PPS that depend on this SPS */ for (i = 0; i < FF_ARRAY_ELEMS(s->pps_list); i++) - if (s->pps_list[i] && ((HEVCPPS*)s->pps_list[i]->data)->sps_id == id) + if (s->pps_list[i] && s->pps_list[i]->sps_id == id) remove_pps(s, i); - av_assert0(!(s->sps_list[id] && s->sps == (HEVCSPS*)s->sps_list[id]->data)); + av_assert0(!(s->sps_list[id] && s->sps == s->sps_list[id])); + ff_refstruct_unref(&s->sps_list[id]); } - av_buffer_unref(&s->sps_list[id]); } static void remove_vps(HEVCParamSets *s, int id) { int i; if (s->vps_list[id]) { - if (s->vps == (const HEVCVPS*)s->vps_list[id]->data) + if (s->vps == s->vps_list[id]) s->vps = NULL; for (i = 0; i < FF_ARRAY_ELEMS(s->sps_list); i++) - if (s->sps_list[i] && ((HEVCSPS*)s->sps_list[i]->data)->vps_id == id) + if (s->sps_list[i] && s->sps_list[i]->vps_id == id) remove_sps(s, i); + ff_refstruct_unref(&s->vps_list[id]); } - av_buffer_unref(&s->vps_list[id]); } int ff_hevc_decode_short_term_rps(GetBitContext *gb, AVCodecContext *avctx, @@ -442,12 +443,10 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, int i,j; int vps_id = 0; ptrdiff_t nal_size; - HEVCVPS *vps; - AVBufferRef *vps_buf = av_buffer_allocz(sizeof(*vps)); + HEVCVPS *vps = ff_refstruct_allocz(sizeof(*vps)); - if (!vps_buf) + if (!vps) return AVERROR(ENOMEM); - vps = (HEVCVPS*)vps_buf->data; av_log(avctx, AV_LOG_DEBUG, "Decoding VPS\n"); @@ -553,17 +552,17 @@ int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, } if (ps->vps_list[vps_id] && - !memcmp(ps->vps_list[vps_id]->data, vps_buf->data, vps_buf->size)) { - av_buffer_unref(&vps_buf); + !memcmp(ps->vps_list[vps_id], vps, sizeof(*vps))) { + ff_refstruct_unref(&vps); } else { remove_vps(ps, vps_id); - ps->vps_list[vps_id] = vps_buf; + ps->vps_list[vps_id] = vps; } return 0; err: - av_buffer_unref(&vps_buf); + ff_refstruct_unref(&vps); return AVERROR_INVALIDDATA; } @@ -851,7 +850,8 @@ static int map_pixel_format(AVCodecContext *avctx, HEVCSPS *sps) } int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, - int apply_defdispwin, AVBufferRef **vps_list, AVCodecContext *avctx) + int apply_defdispwin, const HEVCVPS * const *vps_list, + AVCodecContext *avctx) { HEVCWindow *ow; int ret = 0; @@ -1269,15 +1269,13 @@ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, int ff_hevc_decode_nal_sps(GetBitContext *gb, AVCodecContext *avctx, HEVCParamSets *ps, int apply_defdispwin) { - HEVCSPS *sps; - AVBufferRef *sps_buf = av_buffer_allocz(sizeof(*sps)); + HEVCSPS *sps = ff_refstruct_allocz(sizeof(*sps)); unsigned int sps_id; int ret; ptrdiff_t nal_size; - if (!sps_buf) + if (!sps) return AVERROR(ENOMEM); - sps = (HEVCSPS*)sps_buf->data; av_log(avctx, AV_LOG_DEBUG, "Decoding SPS\n"); @@ -1296,7 +1294,7 @@ int ff_hevc_decode_nal_sps(GetBitContext *gb, AVCodecContext *avctx, apply_defdispwin, ps->vps_list, avctx); if (ret < 0) { - av_buffer_unref(&sps_buf); + ff_refstruct_unref(&sps); return ret; } @@ -1314,19 +1312,19 @@ int ff_hevc_decode_nal_sps(GetBitContext *gb, AVCodecContext *avctx, * original one. * otherwise drop all PPSes that depend on it */ if (ps->sps_list[sps_id] && - !memcmp(ps->sps_list[sps_id]->data, sps_buf->data, sps_buf->size)) { - av_buffer_unref(&sps_buf); + !memcmp(ps->sps_list[sps_id], sps, sizeof(*sps))) { + ff_refstruct_unref(&sps); } else { remove_sps(ps, sps_id); - ps->sps_list[sps_id] = sps_buf; + ps->sps_list[sps_id] = sps; } return 0; } -static void hevc_pps_free(void *opaque, uint8_t *data) +static void hevc_pps_free(FFRefStructOpaque unused, void *obj) { - HEVCPPS *pps = (HEVCPPS*)data; + HEVCPPS *pps = obj; av_freep(&pps->column_width); av_freep(&pps->row_height); @@ -1338,8 +1336,6 @@ static void hevc_pps_free(void *opaque, uint8_t *data) av_freep(&pps->tile_pos_rs); av_freep(&pps->tile_id); av_freep(&pps->min_tb_addr_zs_tab); - - av_freep(&pps); } static void colour_mapping_octants(GetBitContext *gb, HEVCPPS *pps, int inp_depth, @@ -1742,19 +1738,11 @@ int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx, ptrdiff_t nal_size; unsigned log2_parallel_merge_level_minus2; - AVBufferRef *pps_buf; - HEVCPPS *pps = av_mallocz(sizeof(*pps)); + HEVCPPS *pps = ff_refstruct_alloc_ext(sizeof(*pps), 0, NULL, hevc_pps_free); if (!pps) return AVERROR(ENOMEM); - pps_buf = av_buffer_create((uint8_t *)pps, sizeof(*pps), - hevc_pps_free, NULL, 0); - if (!pps_buf) { - av_freep(&pps); - return AVERROR(ENOMEM); - } - av_log(avctx, AV_LOG_DEBUG, "Decoding PPS\n"); nal_size = gb->buffer_end - gb->buffer; @@ -1796,8 +1784,8 @@ int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx, ret = AVERROR_INVALIDDATA; goto err; } - sps = (HEVCSPS *)ps->sps_list[pps->sps_id]->data; - vps = (HEVCVPS *)ps->vps_list[sps->vps_id]->data; + sps = ps->sps_list[pps->sps_id]; + vps = ps->vps_list[sps->vps_id]; pps->dependent_slice_segments_enabled_flag = get_bits1(gb); pps->output_flag_present_flag = get_bits1(gb); @@ -1998,12 +1986,12 @@ int ff_hevc_decode_nal_pps(GetBitContext *gb, AVCodecContext *avctx, } remove_pps(ps, pps_id); - ps->pps_list[pps_id] = pps_buf; + ps->pps_list[pps_id] = pps; return 0; err: - av_buffer_unref(&pps_buf); + ff_refstruct_unref(&pps); return ret; } @@ -2012,11 +2000,11 @@ void ff_hevc_ps_uninit(HEVCParamSets *ps) int i; for (i = 0; i < FF_ARRAY_ELEMS(ps->vps_list); i++) - av_buffer_unref(&ps->vps_list[i]); + ff_refstruct_unref(&ps->vps_list[i]); for (i = 0; i < FF_ARRAY_ELEMS(ps->sps_list); i++) - av_buffer_unref(&ps->sps_list[i]); + ff_refstruct_unref(&ps->sps_list[i]); for (i = 0; i < FF_ARRAY_ELEMS(ps->pps_list); i++) - av_buffer_unref(&ps->pps_list[i]); + ff_refstruct_unref(&ps->pps_list[i]); ps->sps = NULL; ps->pps = NULL; diff --git a/libavcodec/hevc_ps.h b/libavcodec/hevc_ps.h index ef11e51ee7..786c896709 100644 --- a/libavcodec/hevc_ps.h +++ b/libavcodec/hevc_ps.h @@ -23,7 +23,6 @@ #include -#include "libavutil/buffer.h" #include "libavutil/pixfmt.h" #include "libavutil/rational.h" @@ -437,9 +436,9 @@ typedef struct HEVCPPS { } HEVCPPS; typedef struct HEVCParamSets { - AVBufferRef *vps_list[HEVC_MAX_VPS_COUNT]; - AVBufferRef *sps_list[HEVC_MAX_SPS_COUNT]; - AVBufferRef *pps_list[HEVC_MAX_PPS_COUNT]; + const HEVCVPS *vps_list[HEVC_MAX_VPS_COUNT]; ///< RefStruct references + const HEVCSPS *sps_list[HEVC_MAX_SPS_COUNT]; ///< RefStruct references + const HEVCPPS *pps_list[HEVC_MAX_PPS_COUNT]; ///< RefStruct references /* currently active parameter sets */ const HEVCVPS *vps; @@ -457,7 +456,8 @@ typedef struct HEVCParamSets { * to an existing VPS */ int ff_hevc_parse_sps(HEVCSPS *sps, GetBitContext *gb, unsigned int *sps_id, - int apply_defdispwin, AVBufferRef **vps_list, AVCodecContext *avctx); + int apply_defdispwin, const HEVCVPS * const *vps_list, + AVCodecContext *avctx); int ff_hevc_decode_nal_vps(GetBitContext *gb, AVCodecContext *avctx, HEVCParamSets *ps); diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c index 351e699726..abdb52acd3 100644 --- a/libavcodec/hevc_sei.c +++ b/libavcodec/hevc_sei.c @@ -53,11 +53,10 @@ static int decode_nal_sei_pic_timing(HEVCSEI *s, GetBitContext *gb, const HEVCParamSets *ps, void *logctx) { HEVCSEIPictureTiming *h = &s->picture_timing; - HEVCSPS *sps; + const HEVCSPS *sps = ps->sps_list[s->active_seq_parameter_set_id]; - if (!ps->sps_list[s->active_seq_parameter_set_id]) + if (!sps) return(AVERROR(ENOMEM)); - sps = (HEVCSPS*)ps->sps_list[s->active_seq_parameter_set_id]->data; if (sps->vui.frame_field_info_present_flag) { int pic_struct = get_bits(gb, 4); diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 81b9c5e089..d64055e1f9 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -50,6 +50,7 @@ #include "hwconfig.h" #include "internal.h" #include "profiles.h" +#include "refstruct.h" #include "thread.h" #include "threadframe.h" @@ -326,7 +327,7 @@ static void export_stream_params(HEVCContext *s, const HEVCSPS *sps) { AVCodecContext *avctx = s->avctx; const HEVCParamSets *ps = &s->ps; - const HEVCVPS *vps = (const HEVCVPS*)ps->vps_list[sps->vps_id]->data; + const HEVCVPS *vps = ps->vps_list[sps->vps_id]; const HEVCWindow *ow = &sps->output_window; unsigned int num = 0, den = 0; @@ -573,7 +574,7 @@ static int set_sps(HEVCContext *s, const HEVCSPS *sps, } s->ps.sps = sps; - s->ps.vps = (HEVCVPS*) s->ps.vps_list[s->ps.sps->vps_id]->data; + s->ps.vps = s->ps.vps_list[s->ps.sps->vps_id]; return 0; @@ -616,16 +617,16 @@ static int hls_slice_header(HEVCContext *s) return AVERROR_INVALIDDATA; } if (!sh->first_slice_in_pic_flag && - s->ps.pps != (HEVCPPS*)s->ps.pps_list[sh->pps_id]->data) { + s->ps.pps != s->ps.pps_list[sh->pps_id]) { av_log(s->avctx, AV_LOG_ERROR, "PPS changed between slices.\n"); return AVERROR_INVALIDDATA; } - s->ps.pps = (HEVCPPS*)s->ps.pps_list[sh->pps_id]->data; + s->ps.pps = s->ps.pps_list[sh->pps_id]; if (s->nal_unit_type == HEVC_NAL_CRA_NUT && s->last_eos == 1) sh->no_output_of_prior_pics_flag = 1; - if (s->ps.sps != (HEVCSPS*)s->ps.sps_list[s->ps.pps->sps_id]->data) { - const HEVCSPS *sps = (HEVCSPS*)s->ps.sps_list[s->ps.pps->sps_id]->data; + if (s->ps.sps != s->ps.sps_list[s->ps.pps->sps_id]) { + const HEVCSPS *sps = s->ps.sps_list[s->ps.pps->sps_id]; enum AVPixelFormat pix_fmt; ff_hevc_clear_refs(s); @@ -3301,7 +3302,7 @@ static int hevc_decode_extradata(HEVCContext *s, uint8_t *buf, int length, int f /* export stream parameters from the first SPS */ for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) { if (first && s->ps.sps_list[i]) { - const HEVCSPS *sps = (const HEVCSPS*)s->ps.sps_list[i]->data; + const HEVCSPS *sps = s->ps.sps_list[i]; export_stream_params(s, sps); break; } @@ -3539,23 +3540,14 @@ static int hevc_update_thread_context(AVCodecContext *dst, if (s->ps.sps != s0->ps.sps) s->ps.sps = NULL; - for (i = 0; i < FF_ARRAY_ELEMS(s->ps.vps_list); i++) { - ret = av_buffer_replace(&s->ps.vps_list[i], s0->ps.vps_list[i]); - if (ret < 0) - return ret; - } + for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.vps_list); i++) + ff_refstruct_replace(&s->ps.vps_list[i], s0->ps.vps_list[i]); - for (i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) { - ret = av_buffer_replace(&s->ps.sps_list[i], s0->ps.sps_list[i]); - if (ret < 0) - return ret; - } + for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.sps_list); i++) + ff_refstruct_replace(&s->ps.sps_list[i], s0->ps.sps_list[i]); - for (i = 0; i < FF_ARRAY_ELEMS(s->ps.pps_list); i++) { - ret = av_buffer_replace(&s->ps.pps_list[i], s0->ps.pps_list[i]); - if (ret < 0) - return ret; - } + for (int i = 0; i < FF_ARRAY_ELEMS(s->ps.pps_list); i++) + ff_refstruct_replace(&s->ps.pps_list[i], s0->ps.pps_list[i]); if (s->ps.sps != s0->ps.sps) if ((ret = set_sps(s, s0->ps.sps, src->pix_fmt)) < 0) diff --git a/libavcodec/mediacodecdec.c b/libavcodec/mediacodecdec.c index 52b3a2c1f7..b8587289a2 100644 --- a/libavcodec/mediacodecdec.c +++ b/libavcodec/mediacodecdec.c @@ -223,21 +223,21 @@ static int hevc_set_extradata(AVCodecContext *avctx, FFAMediaFormat *format) for (i = 0; i < HEVC_MAX_VPS_COUNT; i++) { if (ps.vps_list[i]) { - vps = (const HEVCVPS*)ps.vps_list[i]->data; + vps = ps.vps_list[i]; break; } } for (i = 0; i < HEVC_MAX_PPS_COUNT; i++) { if (ps.pps_list[i]) { - pps = (const HEVCPPS*)ps.pps_list[i]->data; + pps = ps.pps_list[i]; break; } } if (pps) { if (ps.sps_list[pps->sps_id]) { - sps = (const HEVCSPS*)ps.sps_list[pps->sps_id]->data; + sps = ps.sps_list[pps->sps_id]; } } diff --git a/libavcodec/videotoolbox.c b/libavcodec/videotoolbox.c index 963379d483..43fd2e3fea 100644 --- a/libavcodec/videotoolbox.c +++ b/libavcodec/videotoolbox.c @@ -246,7 +246,7 @@ CFDataRef ff_videotoolbox_hvcc_extradata_create(AVCodecContext *avctx) #define COUNT_SIZE_PS(T, t) \ for (i = 0; i < HEVC_MAX_##T##PS_COUNT; i++) { \ if (h->ps.t##ps_list[i]) { \ - const HEVC##T##PS *lps = (const HEVC##T##PS *)h->ps.t##ps_list[i]->data; \ + const HEVC##T##PS *lps = h->ps.t##ps_list[i]; \ vt_extradata_size += 2 + escape_ps(NULL, lps->data, lps->data_size); \ num_##t##ps++; \ } \ @@ -369,7 +369,7 @@ CFDataRef ff_videotoolbox_hvcc_extradata_create(AVCodecContext *avctx) p += 3; \ for (i = 0; i < HEVC_MAX_##T##PS_COUNT; i++) { \ if (h->ps.t##ps_list[i]) { \ - const HEVC##T##PS *lps = (const HEVC##T##PS *)h->ps.t##ps_list[i]->data; \ + const HEVC##T##PS *lps = h->ps.t##ps_list[i]; \ int size = escape_ps(p + 2, lps->data, lps->data_size); \ /* unsigned int(16) nalUnitLength; */ \ AV_WB16(p, size); \ diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c index 52f223ceb2..395cbd3008 100644 --- a/libavcodec/vulkan_hevc.c +++ b/libavcodec/vulkan_hevc.c @@ -70,14 +70,14 @@ typedef struct HEVCHeaderSet { static int alloc_hevc_header_structs(FFVulkanDecodeContext *s, int nb_vps, - AVBufferRef * const vps_list[HEVC_MAX_VPS_COUNT]) + const HEVCVPS * const vps_list[HEVC_MAX_VPS_COUNT]) { uint8_t *data_ptr; HEVCHeaderSet *hdr; size_t buf_size = sizeof(HEVCHeaderSet) + nb_vps*sizeof(HEVCHeaderVPS); for (int i = 0; i < nb_vps; i++) { - const HEVCVPS *vps = (const HEVCVPS *)vps_list[i]->data; + const HEVCVPS *vps = vps_list[i]; buf_size += sizeof(HEVCHeaderVPSSet)*vps->vps_num_hrd_parameters; } @@ -96,7 +96,7 @@ static int alloc_hevc_header_structs(FFVulkanDecodeContext *s, hdr->hvps = (HEVCHeaderVPS *)(data_ptr + sizeof(HEVCHeaderSet)); data_ptr += sizeof(HEVCHeaderSet) + nb_vps*sizeof(HEVCHeaderVPS); for (int i = 0; i < nb_vps; i++) { - const HEVCVPS *vps = (const HEVCVPS *)vps_list[i]->data; + const HEVCVPS *vps = vps_list[i]; hdr->hvps[i].sls = (HEVCHeaderVPSSet *)data_ptr; data_ptr += sizeof(HEVCHeaderVPSSet)*vps->vps_num_hrd_parameters; } @@ -673,7 +673,7 @@ static int vk_hevc_create_params(AVCodecContext *avctx, AVBufferRef **buf) /* SPS list */ for (int i = 0; h->ps.sps_list[i]; i++) { - const HEVCSPS *sps_l = (const HEVCSPS *)h->ps.sps_list[i]->data; + const HEVCSPS *sps_l = h->ps.sps_list[i]; set_sps(sps_l, i, &hdr->hsps[i].scaling, &hdr->hsps[i].vui_header, &hdr->hsps[i].vui, &hdr->sps[i], hdr->hsps[i].nal_hdr, hdr->hsps[i].vcl_hdr, &hdr->hsps[i].ptl, &hdr->hsps[i].dpbm, @@ -683,15 +683,15 @@ static int vk_hevc_create_params(AVCodecContext *avctx, AVBufferRef **buf) /* PPS list */ for (int i = 0; h->ps.pps_list[i]; i++) { - const HEVCPPS *pps_l = (const HEVCPPS *)h->ps.pps_list[i]->data; - const HEVCSPS *sps_l = (const HEVCSPS *)h->ps.sps_list[pps_l->sps_id]->data; + const HEVCPPS *pps_l = h->ps.pps_list[i]; + const HEVCSPS *sps_l = h->ps.sps_list[pps_l->sps_id]; set_pps(pps_l, sps_l, &hdr->hpps[i].scaling, &hdr->pps[i], &hdr->hpps[i].pal); h265_params_info.stdPPSCount++; } /* VPS list */ for (int i = 0; i < nb_vps; i++) { - const HEVCVPS *vps_l = (const HEVCVPS *)h->ps.vps_list[i]->data; + const HEVCVPS *vps_l = h->ps.vps_list[i]; set_vps(vps_l, &hdr->vps[i], &hdr->hvps[i].ptl, &hdr->hvps[i].dpbm, hdr->hvps[i].hdr, hdr->hvps[i].sls); h265_params_info.stdVPSCount++; @@ -871,7 +871,7 @@ static int vk_hevc_end_frame(AVCodecContext *avctx) if (!pps) { unsigned int pps_id = h->sh.pps_id; if (pps_id < HEVC_MAX_PPS_COUNT && h->ps.pps_list[pps_id] != NULL) - pps = (const HEVCPPS *)h->ps.pps_list[pps_id]->data; + pps = h->ps.pps_list[pps_id]; } if (!pps) { From patchwork Tue Sep 19 19:56:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43817 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp185590pzb; Tue, 19 Sep 2023 12:57:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEYKfHe7H6AvRVprPoYFEwOiQHRjt6F3gugmvpos5cZcOKqaRHiXPZT2lVv29guFk4m9q97 X-Received: by 2002:a17:906:56:b0:99c:f47a:2354 with SMTP id 22-20020a170906005600b0099cf47a2354mr274731ejg.70.1695153454133; Tue, 19 Sep 2023 12:57:34 -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 l13-20020a170906078d00b0099bbcf85f18si10471943ejc.86.2023.09.19.12.57.31; Tue, 19 Sep 2023 12:57:34 -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=j8HIXaFt; 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 55E2068C943; Tue, 19 Sep 2023 22:56:58 +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-db8eur05olkn2072.outbound.protection.outlook.com [40.92.89.72]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 61BAD68C7DD for ; Tue, 19 Sep 2023 22:56:57 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NbRSZIreaguFVgmgtEQSS77iJ9Ld/24xG3HzEksZys77IsLJHLmu14ck+9ssqdDiNF/IrLMVSEBHNNlzoIdgWgU0mB7SgZzY83mbSICODCzOJEpo1jkT6N+VBbzlnsWFzhU5/y+f2mdqGPBSzXn6DopoPgv2JVZ6r9DfZutRXHv9MmMV3jDtER0B91eGVMhfXXSwhRzESMXIqWr0YWVT2wOdDVVoJpXrnx3tMcNwTinhHPpCcPzLKJSZvUSXOf3D8mI5FMnvOjp7E1B89WUK7/GcpqiThPoOjaKKSX4/RGb3GFTUCtGEr0baOcDXyaJwk1AvrIGpaRwUQWHddICA2g== 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=O2Mg3l/fg7m7pIZwrUsdWJOYEPpTZXfxdmshI8Iubk4=; b=Ao2FRWQy1/iAObg0ebs/YwIfs8cfSX7P1hbGXBSew/5RHgG6l5hc0/UDYGvSZKa95ybaFS68EMkRbgGeK6OiwaRckIbuqe7gQ4Vbe7V3X+UXyPIw6uCPHIFg0Jq94bPboGq07vt73N8s482jS+WcIRYvikJT8o/sp71BO/Pk7JGUmpWGrS87RtpxAD/WUEpoX3UIkZ11NN8OlNzY8lAAxyw77kGvg1C1D34QnaFiLrSv+zi37PyfAlOZVU/Si2btH+uw4EYQUYKL5f4/cnQagogJiXRTF3YIOhSBQQMJiZ4WJ6ifaf6Mbb/Eqj8Ju7ubFSZVu50q/dstNf64dE+C0g== 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=O2Mg3l/fg7m7pIZwrUsdWJOYEPpTZXfxdmshI8Iubk4=; b=j8HIXaFtMV1qDAJ88M8Z7Qfq88Mjot3x/ogloY867GEL34+IzVAJL5nUbK7QCHlOaLBd5ei73vyIfpZ6/nny2a7braWDw9JNW7wMIS1VQsst88cjg/LB7JhuNBmSR/EcbnUJ9KiyP2mlehMzpecLNlN9qqMpxo1Ajp8wDbLNuXMZGCZhue8hSgTQ03QGisiFG99VbjrA6EqAy/wDY/XdhvJC+6dcFnC50+2X1Nag9o3PxJAPkPl6aonB0s/HK3uX65rMnS9q53fK7ARTCfxQ/wvRfXlO35XrAha7giZAJjEjXsiscEme9ZwvRK32knRpczdmkpxuQ1tuaCTSi7lH+A== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AM8P250MB0215.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:326::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:56:55 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:56:55 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:56:58 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [RoosF64LFvWpN30ln/4Z4sgZICQvI1GL] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-6-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AM8P250MB0215:EE_ X-MS-Office365-Filtering-Correlation-Id: 7f487e81-3c22-4728-4196-08dbb94a934a X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3Ln7HW9/IjzLnKQXhh4KPqb6NT+ugV6TVq3XdvvUY/dXBM19Mlhd/phgpV4MjcBI96Sp5AC689c3bZqYL/4oGWFrLixnXtHK7GC1jVxb817eY26niK6iffluw9YtVemVwjDE+EBbN58phMDv9S6SWz+oKvpGJLTxJ9z0pOVV1PtrEPVaiUvrlq7OicB+rrWqsNCr3VQsTjnU5NGhWYoubac9d12PWrJ+2feZCFRBVkLyG4aIblzh/uvFTr/0BFOa4QfRbAFnzY1HlY3ApzeJLMNLhpt6Qj0hFvVa1hJ/m1GC58PVTSZM+uoeGZhIPFlCorSU4h9pDQrkf75oC7O3MGPlnReH2UBGNIpEbwblDx41cDeB4O/TZNq1eFmwU5b928DVozOlKKmpsMpiNQt/lw7+tzJnseb3y5BwkVbeBTnprmoMXkjkhu3arJnl4Tlo0mm7B7ScIbJ7vkNE4hKE9gPi2ZjZhPnHDsgWhhHxoM8TdBm3P7Jxoy0iEcXOkfZu+HjbS7Ms67DgPWA9xshUiMzJwh6aN7wyMB9u9aOex+DuEUlrVcDwlwuvTbRyfEdzHVEuQNJhZ2I8UZoMkSLkJJKHq0h+VTDySufSbt8WV0ri3cRSND1ydg/aeN5BnvQx X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Du5h+7SAigSHY5iF1ETMzu5St3srAChNW7PbdVMtUhaEVjq1pF8efHiK8EUNtanYXQtduxFY+WvUNj1HZZ8Bojkgo/PnvjM4h3S23XlC0gvYCIENIlI5FfjNIkifOH56F7qbhmthvtK3JacWJd3YECV0bvniYpGul9rEj6ApJFJPbpXDFplTKXdvOJOSjA/IwH81VzA2sULnaVWJPCrIvMNRxF+8jOqQ4fuY2lP6q/J1GZkpstAXVtQwF/GjxMLRRJCp+XUgRAlhT4N4tPsxp83ztSMJGQx+vfhiomVasYkuL+jK9KfVKzAW2zd0Gh2UNg380o6sL4nW7+L3CxUgTKhKcFyo9uEurK79i04wD6gnsbe65n4hjIR2w6foG6kDlhupn4Vl10EUbxSe5N29uBTli0K520IBbtt3Ws+XGfUKwKtRnyRztXAZKRXV0uWI/WE1sn2+RDA9QuDCQoU+N59AMxU0AS20MbFTIIWRBUFjAl3kPdGQnzFzcjUmcMNq3sbCs5HEOvILIohmjYH3TcK4pYxlIsH5sRnyGBzrxPb6AsQQmGvl+I+m7S7QTEPOYE3LHSy2KX9llGlmOEAKLskSYD2XzQG5pd7ZmzHqq1ZJbt4Oydf9BCj4Hvj/vbrex3PjcG/o7SleNCNkKvCchyn2xtX+1BzgJAMeiNnWZkSW1dqXRWOQfKbc4A8TJoOsv+xyvtDbwmEJwEsNMBCEiw1NUTQV8uku7eONRmWToJbma+iNjkUtgxHhRzPdeBkvZ7+C5MCybKl4Xj5S/rIKBNMisISif++joKFCnpPby4IhMXM1g2eoaTfxHtjyQVxrCs7b4OyaWbQIT392H9m7sWib91RQ3DcrWKNo+glLnmW0Inj6EYW9NUieFnuFaSGBQKt6Ov+Vos5P+6oChsdL12e3MIxBxWx0iublRY/m4ZQs49uOhMuKU5yAWOhEr+QOxdKX1bQ1KYrFx/dRb2GdsEnZPlUREEqCIPvJ/RaUD/PEoUePUWArbLEgCRghz+KrZGmt+cimW9HKRxbdz/D3o/WyE0wOHaO0cV6Ub2C0iHwKts5lpK6aII+qVzoY5inU3TP5ASYbuJM5MIVbcwb5zzCf2k1NJX1z6dy0hewM8Yv9itrrySRDrb5EEk/0gJ4n1EFKMN24I1XsGDswy+fA3OlQwkUcFaVFeC0++x6gI06+9yHBELoexlAdZPCE4D6DqkzEPQUi9HI3NLV6arcvOHTp5Ryg7ePpCf10ChS4JhJ22fdi64hYQoDV3x99L1Y9 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7f487e81-3c22-4728-4196-08dbb94a934a X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:56:55.5210 (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: AM8P250MB0215 Subject: [FFmpeg-devel] [PATCH 06/42] avcodec/vp8: Use RefStruct API for seg_map 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: +DhdF7WIX1Kf Avoids allocations and error checks when syncing the buffers. Also avoids indirections. Signed-off-by: Andreas Rheinhardt --- libavcodec/vp8.c | 23 +++++++++-------------- libavcodec/vp8.h | 2 +- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c index 64b1c7f60e..db325dc90b 100644 --- a/libavcodec/vp8.c +++ b/libavcodec/vp8.c @@ -34,6 +34,7 @@ #include "hwaccel_internal.h" #include "hwconfig.h" #include "mathops.h" +#include "refstruct.h" #include "thread.h" #include "threadframe.h" #include "vp8.h" @@ -105,10 +106,8 @@ static int vp8_alloc_frame(VP8Context *s, VP8Frame *f, int ref) if ((ret = ff_thread_get_ext_buffer(s->avctx, &f->tf, ref ? AV_GET_BUFFER_FLAG_REF : 0)) < 0) return ret; - if (!(f->seg_map = av_buffer_allocz(s->mb_width * s->mb_height))) { - ret = AVERROR(ENOMEM); + if (!(f->seg_map = ff_refstruct_allocz(s->mb_width * s->mb_height))) goto fail; - } ret = ff_hwaccel_frame_priv_alloc(s->avctx, &f->hwaccel_picture_private, &f->hwaccel_priv_buf); if (ret < 0) @@ -117,14 +116,14 @@ static int vp8_alloc_frame(VP8Context *s, VP8Frame *f, int ref) return 0; fail: - av_buffer_unref(&f->seg_map); + ff_refstruct_unref(&f->seg_map); ff_thread_release_ext_buffer(s->avctx, &f->tf); return ret; } static void vp8_release_frame(VP8Context *s, VP8Frame *f) { - av_buffer_unref(&f->seg_map); + ff_refstruct_unref(&f->seg_map); av_buffer_unref(&f->hwaccel_priv_buf); f->hwaccel_picture_private = NULL; ff_thread_release_ext_buffer(s->avctx, &f->tf); @@ -139,11 +138,7 @@ static int vp8_ref_frame(VP8Context *s, VP8Frame *dst, const VP8Frame *src) if ((ret = ff_thread_ref_frame(&dst->tf, &src->tf)) < 0) return ret; - if (src->seg_map && - !(dst->seg_map = av_buffer_ref(src->seg_map))) { - vp8_release_frame(s, dst); - return AVERROR(ENOMEM); - } + ff_refstruct_replace(&dst->seg_map, src->seg_map); if (src->hwaccel_picture_private) { dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf); if (!dst->hwaccel_priv_buf) @@ -2334,9 +2329,9 @@ int vp78_decode_mv_mb_modes(AVCodecContext *avctx, VP8Frame *curframe, if (mb_y == 0) AV_WN32A((mb - s->mb_width - 1)->intra4x4_pred_mode_top, DC_PRED * 0x01010101); - decode_mb_mode(s, &s->mv_bounds, mb, mb_x, mb_y, curframe->seg_map->data + mb_xy, + decode_mb_mode(s, &s->mv_bounds, mb, mb_x, mb_y, curframe->seg_map + mb_xy, prev_frame && prev_frame->seg_map ? - prev_frame->seg_map->data + mb_xy : NULL, 1, is_vp7); + prev_frame->seg_map + mb_xy : NULL, 1, is_vp7); s->mv_bounds.mv_min.x -= 64; s->mv_bounds.mv_max.x -= 64; } @@ -2467,9 +2462,9 @@ static av_always_inline int decode_mb_row_no_filter(AVCodecContext *avctx, void dst[2] - dst[1], 2); if (!s->mb_layout) - decode_mb_mode(s, &td->mv_bounds, mb, mb_x, mb_y, curframe->seg_map->data + mb_xy, + decode_mb_mode(s, &td->mv_bounds, mb, mb_x, mb_y, curframe->seg_map + mb_xy, prev_frame && prev_frame->seg_map ? - prev_frame->seg_map->data + mb_xy : NULL, 0, is_vp7); + prev_frame->seg_map + mb_xy : NULL, 0, is_vp7); prefetch_motion(s, mb, mb_x, mb_y, mb_xy, VP8_FRAME_PREVIOUS); diff --git a/libavcodec/vp8.h b/libavcodec/vp8.h index 6f29156b53..cb752d4498 100644 --- a/libavcodec/vp8.h +++ b/libavcodec/vp8.h @@ -152,7 +152,7 @@ typedef struct VP8ThreadData { typedef struct VP8Frame { ThreadFrame tf; - AVBufferRef *seg_map; + uint8_t *seg_map; ///< RefStruct reference AVBufferRef *hwaccel_priv_buf; void *hwaccel_picture_private; From patchwork Tue Sep 19 19:56:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43818 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp185638pzb; Tue, 19 Sep 2023 12:57:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEMHROdls2YGNe2EpLlYEP9iKY/tOzon/7rHXMFeZKv+W4N8DwcspsWbjaTPriKbeS1F3WK X-Received: by 2002:a17:907:763a:b0:9a9:ee3e:e6b6 with SMTP id jy26-20020a170907763a00b009a9ee3ee6b6mr328488ejc.3.1695153462133; Tue, 19 Sep 2023 12:57:42 -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 d22-20020a170906345600b00992ee06bddbsi10456065ejb.176.2023.09.19.12.57.41; Tue, 19 Sep 2023 12:57:42 -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="HOAWx/oa"; 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 5570C68C951; Tue, 19 Sep 2023 22:57:00 +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-db8eur05olkn2100.outbound.protection.outlook.com [40.92.89.100]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6DE4568C872 for ; Tue, 19 Sep 2023 22:56:59 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hEdfElYnI9iKYFWdZQqtSStnewVj0OQlNStNmOkdMsidlYn9AxK6eNSdEBm2H9Fw6cNElQjnLMDh+9n/UEk5dTQSw0LsEpd0ZLvnLrJwghb0J7F0YRpbSiXI+TORz9B+OOy31b9xn6AJVaFCG6vO6yUiRYmoj4zA+Ivm63KNzs+76iaSSILZlLcan06o9vRp3VrjX8wdUJf8SQ8KEkaIij6xrE0iJo4Nz6/GW1Spq7tsBvmBGRbclXMsP//abYlpV+ueWps95qEWLkpr1roPR4c5gHnshG5qUbgx8fzo61JmJ5WpES84s+7HuOkSzAgiLyT2x6msVbO/Q0FOxM47GQ== 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=OPN0x/VVQoMmRfNM3/b+Xoe28kYsYQBW7LQktr2jTLw=; b=YURdBPYMw8mRG2zKY4fuPhQkCiJfIfC/nuZUGu9Px58XdtOs6c/STuk7SVHJR0XFN2qE9095PnHWYyMnPkLpp81rkxdXlC67dS1MkFnwhGvWxdBZp+oVbDjv+OAz6P0IQ9lL1MbdGi1Fi4BYuM00gxppzvhmXn+WAGY3qklNCFO8x0ihZvrFY/WUK+SR12MOVevh0/iinQ8fM3HiUlUaNwkmlt0GIJb5j9CmWLRYibz4xdBSGqR7G8GWXDHqkcvL9tKtv0aB9sCvtmyj8YegVk+PXyM7AdT3+ivZN2wAgtRohaTCgmy/oPm9GBB2oKv/E92RhpGGCpiea6BRRfA1Jg== 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=OPN0x/VVQoMmRfNM3/b+Xoe28kYsYQBW7LQktr2jTLw=; b=HOAWx/oaJQEmsWq0gQrWLPjydtGvyneiI3ZFO0ciMjuUrTaH3Jbm6l4/MI4XjOm11m2DMkD0dN6MVHL8Z/F2R3r9jEOwiqyRw0RoQabAph1zW/+mr5xcOIy8SxmbhWLq3jPu12dMv6sIu08QGL8NhM0rtj9PGgW0NYL7Ht9hMGypYTHY5QXQVlFsmcL0crdqBJoQwkwwd5NkOvGsRMZP2H1KYfChTgYWmK2CY7bsmT726tQuohvONZKnxcRXctl/+mpsS38J1p7yN4hHcg1TOAx8syRJr4PEEkaOtnV6A6MrMtqABLucrn2UOMOZRw5isYNyyoTRttRPZDaMJFdwkw== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AM8P250MB0215.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:326::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:56:57 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:56:57 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:56:59 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [ULwRsIoC5Tbpt7RPmz1poKIrEC5yOOw3] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-7-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AM8P250MB0215:EE_ X-MS-Office365-Filtering-Correlation-Id: 3de4a902-6c43-4856-80e8-08dbb94a94c0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: He5sMbYcYYAj2UJSeoAJBMR9ELsWMfvub2kc8kaaaOrwjdVokMDfXKac54NIwWf3C0icf0PeUWFHcwbvL4fstux82IG9WxXfgIR60kQwahOWfpUPGYMcMEkeV70UfxOjQHd66CXFdei20bltvghWAKdjr69eJ6wy13Eg9JAi/SYYWcMdXnG4zEIU6fsdCpFEbaw/3svrhqKUIysEobMeZamCOqwVtR9wEsB8tToGe/NQo54WH6g903xC20bRiPRfCGAqHi8MnCIqVQdPZBi8ck3X/H8LAKFY3VpdMnHOwvlw4zH4NGTxAG0Rl7hPOtzsosuJNuB/4QbmcY6gk0VVyZiMKVXNcfKDwTNIxHCjvhYNf/b6HQbMpy0EKxm/+tzvLepMqJZyBJvuyoffYHeR04Oj+QjUVaTK5sLUn25aPfLNcE/aiWIJHEwrlsDvajRaQI1PYvWuspCTGz6P5DXUO88/gg6NAIelitcVqTDWflGZdnMsBzanAuD7R4CJlPoJ08GBAQ+FyUyCFKD46BPdkDkE7Qx0SIpuH2BgOCfE8iUAHpPgYutaNvpeKcosRErAN5TqfAvtlNIZNmxe1Hk0eh+8ay4Vb02kaCdM3FdchJlcmbcozOZJN+bBWT4wYOCa X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: aF4tpQlIykwiC8LcFd8+jMIY0QrrX0qXVQntYEAZvVcuyRFWrkzEDfew8c3o0RRy7XqD3OdNoLmpNJuTOfBlQH5xMTCCRYALT2U/9RHceASTSFYdGv1IVB3aWElmpHO575DRAXTvvthPywEn6dGPpfFNRAJO78bNxbanxOm8IGRjR0lnc8E9lSVJhvlBmAk0Lte/xd8UvLof25K6NRU71bh6GsbZ88eKMVZFLy6azvXyVRTkZR2KDA0INxEIyrRXxEMGMRVlVp/a14QSAWvyQ8JNzVUvXinN1mSDBB7f1dcLRFCAPPRWBhTQ+yI8rKObB+bnsAsZp9LvVvkTDqmlKxAb1a4cDiC1GUOAGjclY5UgcZhU0GK+5T0e/aF1RY/qyjkWgwLlJMjBGgHzk5vBOanC/leHFL7qXpwb9IYdVAbvMT7kYkcmKebcnFSzq5SbUjULDCnxWD00Yo2nAWjkWxY29T6m1i1jkAyW1toAH+Bnd7DIH/7LNw58gSy3ZHKw3dNCWnQhgkmV5etlaCpoWXfcom8uU1xcCifCMvRNaNPaTLe3zlimYPxs+V4MnDnk4m4ThGsSvJrjL8TVVs4mzTSK4SmlXe1sXteBeftRVDNkX4aOhTsKq7kWTZFfZ6Rlz13GwhUmOKnLuhntuCn8nzcqSCM06q+c+9ve2Kfo+ffPQJh1M10uWgC0EtneZZnvmRgoFCp65JIw+UaTTalQ3D/TfoZOwBtrL9ypgraamCsOt6Q0vKpEUDSs8LJMHgH3UVYF+lYe2mh+K7LAXDdPMZ5AiuD0I0Y6Oj5SUTTjmjhG7ogoqsS91NHb8EBsYDrUbQgA2qh4ggTgHVOL4d+Hxat6iX1DrviNKLYKpU9TLoagEXg7tW0RnNq/2Hmq/mgyqegzWWNoU7GLMegJZCEmkUF6GQRgY/46Rc7rHjbi8hfiWz2z8V+NVVkxtzYDWARhji4xHIbr/Cu7gRoTyGk841o3h1Y+wQHiFlegjgkJMiP6Eav4qUOwck/p3+efzfalco0WosOeewk4BOssoQwB5ccNV+/J5igmjP+lEf06kMHYcpp/riv/Q705aW/ead6OpA3S+I508l4mip4qO4rGH51xkhgLV55MrpTYspdO7cwSYtuycmgqLBcNzl3W2y9sClWGxjm1GH/IXdAgWePD3aoUeTMGhW2BxRdPIMFUebRq4zCQyRAoS0sA3KXkY6/4dXLlph9NIOVFZmO2Siry6eowujnpEFhP1tKryA61HXpo6QTeLFYvmCRYh8DTIIqA X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3de4a902-6c43-4856-80e8-08dbb94a94c0 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:56:57.9551 (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: AM8P250MB0215 Subject: [FFmpeg-devel] [PATCH 07/42] avcodec/wavpack: Use RefStruct API for DSD context 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: AttS6zFIf8l0 It avoids allocations and the corresponding error checks. It also avoids indirections and casts. Signed-off-by: Andreas Rheinhardt --- libavcodec/wavpack.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c index 966f4b83db..97705c8854 100644 --- a/libavcodec/wavpack.c +++ b/libavcodec/wavpack.c @@ -28,6 +28,7 @@ #include "bytestream.h" #include "codec_internal.h" #include "get_bits.h" +#include "refstruct.h" #include "thread.h" #include "threadframe.h" #include "unary.h" @@ -110,8 +111,7 @@ typedef struct WavpackContext { ThreadFrame curr_frame, prev_frame; Modulation modulation; - AVBufferRef *dsd_ref; - DSDContext *dsdctx; + DSDContext *dsdctx; ///< RefStruct reference int dsd_channels; } WavpackContext; @@ -990,9 +990,8 @@ static int wv_dsd_reset(WavpackContext *s, int channels) { int i; - s->dsdctx = NULL; s->dsd_channels = 0; - av_buffer_unref(&s->dsd_ref); + ff_refstruct_unref(&s->dsdctx); if (!channels) return 0; @@ -1000,10 +999,9 @@ static int wv_dsd_reset(WavpackContext *s, int channels) if (channels > INT_MAX / sizeof(*s->dsdctx)) return AVERROR(EINVAL); - s->dsd_ref = av_buffer_allocz(channels * sizeof(*s->dsdctx)); - if (!s->dsd_ref) + s->dsdctx = ff_refstruct_allocz(channels * sizeof(*s->dsdctx)); + if (!s->dsdctx) return AVERROR(ENOMEM); - s->dsdctx = (DSDContext*)s->dsd_ref->data; s->dsd_channels = channels; for (i = 0; i < channels; i++) @@ -1028,15 +1026,8 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) return ret; } - fdst->dsdctx = NULL; - fdst->dsd_channels = 0; - ret = av_buffer_replace(&fdst->dsd_ref, fsrc->dsd_ref); - if (ret < 0) - return ret; - if (fsrc->dsd_ref) { - fdst->dsdctx = (DSDContext*)fdst->dsd_ref->data; - fdst->dsd_channels = fsrc->dsd_channels; - } + ff_refstruct_replace(&fdst->dsdctx, fsrc->dsdctx); + fdst->dsd_channels = fsrc->dsd_channels; return 0; } @@ -1076,7 +1067,7 @@ static av_cold int wavpack_decode_end(AVCodecContext *avctx) ff_thread_release_ext_buffer(avctx, &s->prev_frame); av_frame_free(&s->prev_frame.f); - av_buffer_unref(&s->dsd_ref); + ff_refstruct_unref(&s->dsdctx); return 0; } From patchwork Tue Sep 19 19:57:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43819 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp185733pzb; Tue, 19 Sep 2023 12:57:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJJu/aEKQSdMs3HyNdoE4JHa59MILmxSzt4njouc6es4C8D/iKOkaFSkW3xLHb6JLluytk X-Received: by 2002:a2e:3003:0:b0:2c0:20e3:9905 with SMTP id w3-20020a2e3003000000b002c020e39905mr374913ljw.21.1695153474416; Tue, 19 Sep 2023 12:57: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 h10-20020a1709063b4a00b0099bd03ad4fdsi10556481ejf.979.2023.09.19.12.57.51; Tue, 19 Sep 2023 12:57: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="infCFm/i"; 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 7F11B68C630; Tue, 19 Sep 2023 22:57:10 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04olkn2066.outbound.protection.outlook.com [40.92.75.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 06DDE68C63C for ; Tue, 19 Sep 2023 22:57:08 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FJVBtTlJ41Hb3sgNHImCB696I9HRm52v21T/Z0g6Z1De46ICecLjd/p4nB/NaERZGcNlcvSk+OFWcnJ2klHKQLEUM0nk03Ym8+jV8/1MN4XH4O8PCpfoBof4RkwSqvpFiX39kLZQZowImiR/IzRIb1DoXbVVUfea4BP643AWVruO5TLinqPADVihZswqWL5y3CiWiOaQP9QYWel89P1KWR5+bqwOwhb8Vkz0rCKoibyrgF5XueU5Usi2AXFgfRiRn5iteLP134Se2y12gUAZ4E6NVrbejbD9Li7g5QIBnOUZxBSon5I/AS45uoeyrqhC8qOSuBh47A3wHIH7vU3GDw== 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=FaPrBl3m9hBkU5MADRKVGMBqLdcU+pMDggQ8prp1TCY=; b=E754QhpyrSVSgLmOEdXjo7BSmoYN5xRSTcFArKJQ4PYA8MN2sbY/6MLZOmvpuRkH+Rl/JxrG//oEv2NFs8LjfDi0KcICL91nRppcDfsC2kagziihOhfQH2YMRPOhUSzMqJtmk+dZEHNsqQCQAs8lB3CKB1an0sJWwT5yT2WwL1TjARmlgQ5cxY3bJnr8I+A2lA7zqLfFW1K8INj8vNZjvd94Bd3w2CzykUVVdmvEFZ0XDKjVGH3tsIwivOiV6biunKTDj1ZR5soyexjsEulYUUK7RhFevWXE81M5Gfsc+GvkBzFFUrU5vBFYQvg2uM0gLshBdXZDGZPkcnmfsr+qZw== 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=FaPrBl3m9hBkU5MADRKVGMBqLdcU+pMDggQ8prp1TCY=; b=infCFm/inOZQPCkfFLnmTtAJNGfEsnb7hmuAK/aC3ZP5pbhidltFqrwf11HHGjqhDPdegIVgtXBYhHzvWH8Mk+u76zANE5RLamKo0WWcQmJ8FmwydKdWEuOXgEIFTxJDytuBw6hM40Z0+zB109sKHtwWeQbCKYQuWzZ93/0ohlLlTozr6wictPpY9zMD6shElUWDH0E9jyJJLTp2LWwiMBhQ+z54sTaBTAztiG8qWtGJ4l5Q6hDwsueuiXx4MGWqvPVki38f3jqoLDQ22cZR7EpMsjJDumo8rWHajeVtHeU+Z6fhLFr9IGQquYg7T2GuehJdA0JbEWWFvYg+APbVOQ== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AM8P250MB0215.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:326::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:57:07 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:57:07 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:00 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [b7YQn3tWX8IUBkNDMKBIaSqUpmAG3F+f] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-8-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AM8P250MB0215:EE_ X-MS-Office365-Filtering-Correlation-Id: ef26b9f6-b095-4f02-9a0e-08dbb94a9a4f X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4VyFISreBEpR/8TTsx0P1OTbyF03/oyMxjY/Wn5YiGtzBOObSFoNEUnTJgUNN4X1vOPQn7UFABymPN2PrPJm5ECxF4icEb8dmzf3XJfCRYu6Y0qUPDEDPMqSXGxD4sX8NMk0GoWDwGA3xgVjm0YXBtvwa2Fs0syPe93zoTDwDwULnBE0E2stB4HBGGfhb3edyJRhUlw4uIfZTtNx9yF735PPTUqiBZ+lvzlY8aMnLFSCzoWkw2R8fu4SbFVu84Ws+2v7CqRW2h4u2k3XiBnFqIeDzLfbaXsk1kyNKO1SiUJlRLo1r4Z1mnQuA+1Z2/Za+w4yK+AgQqtj6zH28CaYWhKiHHGRxUvdMn4XZAKbWTNlGCfK3JSksmW8zjQvFfwo9FL0zDjRypjaPWHUkorQIBfISJquKQDZBh4/x+qRPCyX9poqZ2cNk1PBMXcJeSNh0iwVAmRl9F7uvdllupvDDfvA/L3aJ/EJjjOohEBtrcMy6Wqsu4Yh0rs4ua0gGwAmwtzj3oDYpdT2EQHD26ygbqyZnD2Y3ZiYDd8HmWdsDpqLTN+XK0CWTuB6NXpULaj/HqAoFL0JiwMXzvHSJj/PLnap4XKO0j28oNWqi7dzAd4LEPGOorGWxShcXnVE3kmi X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zHGGR4/jEozQwt3f6ax5qKDM8DeGJjZHHN7s8x9c3jNiI7Pw4EWqTbXFDgcIoMEHnvtBSPulwNc/bVUpyMm+NE0UXP/Jl/SVnZeMEQx6eiVued3zyk4littOStFo9f/6xI77HOOftHplla0z8GBN1acRgwMviP1agptww3fnLKdOLMdzBt27TbI8lNhWjmMXjAKk7jPCGUo24SnFtAw5137RtFGoPWDu2x6S3Xt3L1KsjfPAEFmxDjSCmKMKo31ZGLznhKLg7mjzDB4T7DfBty733CWi3CVdf7KkhBFJsdCOc/IjpmAcMzl6VXcsjgrCSPcNn1wdd3AEc1c0mcrVIwCXvhU2H3rnwo1PVTQRQlYOtw29cldVQMWgXHPOkTUQn1IbNFVw7rJdPwilXoWGXIu0MA/NjL7FiAxykjf6KzLDJ5cBJdxjRZrq+uv5+cFmoBiu8wW1OxJGkvRjVxQ+u8y0Lk8qBCTmBT50W4qBxeA3FVXWj1agAsmEcmF5xQR7jSmb02auCf1ZJ3oDv5vLJFN28sMYQtpKgL5tneNojdyehR1F64m6EC3IRXUBGlaU1HPr2pDJf9bOrZKAQgBoKbkHxHdijPVzf+1Ku+7fntuTGHu+6v5asmi2meffZhvoQZR8rbNuc/+BOAZnQSsITT3J5WP/GomwKo4gKjzpqifzvKnWNnU2CjyWvpcAmEXe4zV2HLSToG8mc1usIhSxpvS9cqWXB/hLYHyGuLv0+s8Jeb28hgo8AeyRmtOggE9RqQKfhOqKZiZ0Ll65nQSoYH2DsqLbcT9k7O11PTO7Mi2l5fK0duefwzdj2RkLfTF6xg1oHS+k+iHL8xyXicrtGGjr1co2DiWlTyCSRGOF4GfMTYdRy+vVZ2SlZvOUebMiU3nlo3qA8kKRmA4ux0kZ68Cj8tL17r1Dd6Oyh1TyVI7LV5hveE2KY/6N9eCeZS0XmEpVyfHLXbgmAGg6BRc4f6CDBrvZXl/NN1fOBs43JKXzYhNT4dCvJChk4UolDfqwwxXhlK36RS6FfljYXFQ8EFlh7Y30otnZbEWSCdgFoIg3GskSDyY3kpH/YXUfKZZKkdz21H+fRDfap5ujjFZZHxDe9iEuwGtwEIB9eGrpROr41hxzqHgi5uCZrNoeNdKPROSOCTqDT9LE5uJtTRzuj+if+eOib/2iw9DjE/4HfRpKQIsja9d4o0A+3StwgGPLbSYpDNZsQjRYQDtLVakefsMEMhhqk4WWuTSewA4CZwrvbtUQjzXNUxsgXd5xK/SR X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: ef26b9f6-b095-4f02-9a0e-08dbb94a9a4f X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:57:07.3053 (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: AM8P250MB0215 Subject: [FFmpeg-devel] [PATCH 08/42] avcodec/dovi_rpu: Use RefStruct API for Vdr data 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: 80WOlnStGMNk It avoids allocations and the corresponding error checks. Also avoids casts and indirections. Signed-off-by: Andreas Rheinhardt --- libavcodec/dovi_rpu.c | 54 ++++++++++++++++++------------------------- libavcodec/dovi_rpu.h | 4 ++-- libavcodec/hevcdec.c | 4 +--- 3 files changed, 26 insertions(+), 36 deletions(-) diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c index dd38936552..794fa878a7 100644 --- a/libavcodec/dovi_rpu.c +++ b/libavcodec/dovi_rpu.c @@ -26,6 +26,7 @@ #include "dovi_rpu.h" #include "golomb.h" #include "get_bits.h" +#include "refstruct.h" enum { RPU_COEFF_FIXED = 0, @@ -35,15 +36,15 @@ enum { /** * Private contents of vdr_ref. */ -typedef struct DOVIVdrRef { +typedef struct DOVIVdr { AVDOVIDataMapping mapping; AVDOVIColorMetadata color; -} DOVIVdrRef; +} DOVIVdr; void ff_dovi_ctx_unref(DOVIContext *s) { - for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr_ref); i++) - av_buffer_unref(&s->vdr_ref[i]); + for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++) + ff_refstruct_unref(&s->vdr[i]); *s = (DOVIContext) { .logctx = s->logctx, @@ -52,8 +53,8 @@ void ff_dovi_ctx_unref(DOVIContext *s) void ff_dovi_ctx_flush(DOVIContext *s) { - for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr_ref); i++) - av_buffer_unref(&s->vdr_ref[i]); + for (int i = 0; i < FF_ARRAY_ELEMS(s->vdr); i++) + ff_refstruct_unref(&s->vdr[i]); *s = (DOVIContext) { .logctx = s->logctx, @@ -61,23 +62,14 @@ void ff_dovi_ctx_flush(DOVIContext *s) }; } -int ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0) +void ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0) { - int ret; s->logctx = s0->logctx; s->mapping = s0->mapping; s->color = s0->color; s->dv_profile = s0->dv_profile; - for (int i = 0; i < DOVI_MAX_DM_ID; i++) { - if ((ret = av_buffer_replace(&s->vdr_ref[i], s0->vdr_ref[i])) < 0) - goto fail; - } - - return 0; - -fail: - ff_dovi_ctx_unref(s); - return ret; + for (int i = 0; i < DOVI_MAX_DM_ID; i++) + ff_refstruct_replace(&s->vdr[i], s0->vdr[i]); } void ff_dovi_update_cfg(DOVIContext *s, const AVDOVIDecoderConfigurationRecord *cfg) @@ -195,7 +187,7 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size) { AVDOVIRpuDataHeader *hdr = &s->header; GetBitContext *gb = &(GetBitContext){0}; - DOVIVdrRef *vdr; + DOVIVdr *vdr; int ret; uint8_t nal_prefix; @@ -278,23 +270,23 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size) if (use_prev_vdr_rpu) { int prev_vdr_rpu_id = get_ue_golomb_31(gb); VALIDATE(prev_vdr_rpu_id, 0, DOVI_MAX_DM_ID); - if (!s->vdr_ref[prev_vdr_rpu_id]) { + if (!s->vdr[prev_vdr_rpu_id]) { av_log(s->logctx, AV_LOG_ERROR, "Unknown previous RPU ID: %u\n", prev_vdr_rpu_id); goto fail; } - vdr = (DOVIVdrRef *) s->vdr_ref[prev_vdr_rpu_id]->data; + vdr = s->vdr[prev_vdr_rpu_id]; s->mapping = &vdr->mapping; } else { int vdr_rpu_id = get_ue_golomb_31(gb); VALIDATE(vdr_rpu_id, 0, DOVI_MAX_DM_ID); - if (!s->vdr_ref[vdr_rpu_id]) { - s->vdr_ref[vdr_rpu_id] = av_buffer_allocz(sizeof(DOVIVdrRef)); - if (!s->vdr_ref[vdr_rpu_id]) + if (!s->vdr[vdr_rpu_id]) { + s->vdr[vdr_rpu_id] = ff_refstruct_allocz(sizeof(DOVIVdr)); + if (!s->vdr[vdr_rpu_id]) return AVERROR(ENOMEM); } - vdr = (DOVIVdrRef *) s->vdr_ref[vdr_rpu_id]->data; + vdr = s->vdr[vdr_rpu_id]; s->mapping = &vdr->mapping; vdr->mapping.vdr_rpu_id = vdr_rpu_id; @@ -390,24 +382,24 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size) int current_dm_id = get_ue_golomb_31(gb); VALIDATE(affected_dm_id, 0, DOVI_MAX_DM_ID); VALIDATE(current_dm_id, 0, DOVI_MAX_DM_ID); - if (!s->vdr_ref[affected_dm_id]) { - s->vdr_ref[affected_dm_id] = av_buffer_allocz(sizeof(DOVIVdrRef)); - if (!s->vdr_ref[affected_dm_id]) + if (!s->vdr[affected_dm_id]) { + s->vdr[affected_dm_id] = ff_refstruct_allocz(sizeof(DOVIVdr)); + if (!s->vdr[affected_dm_id]) return AVERROR(ENOMEM); } - if (!s->vdr_ref[current_dm_id]) { + if (!s->vdr[current_dm_id]) { av_log(s->logctx, AV_LOG_ERROR, "Unknown previous RPU DM ID: %u\n", current_dm_id); goto fail; } /* Update current pointer based on current_dm_id */ - vdr = (DOVIVdrRef *) s->vdr_ref[current_dm_id]->data; + vdr = s->vdr[current_dm_id]; s->color = &vdr->color; /* Update values of affected_dm_id */ - vdr = (DOVIVdrRef *) s->vdr_ref[affected_dm_id]->data; + vdr = s->vdr[affected_dm_id]; color = &vdr->color; color->dm_metadata_id = affected_dm_id; color->scene_refresh_flag = get_ue_golomb_31(gb); diff --git a/libavcodec/dovi_rpu.h b/libavcodec/dovi_rpu.h index f6ca5bbbc5..51c5fdbb87 100644 --- a/libavcodec/dovi_rpu.h +++ b/libavcodec/dovi_rpu.h @@ -47,12 +47,12 @@ typedef struct DOVIContext { /** * Private fields internal to dovi_rpu.c */ - AVBufferRef *vdr_ref[DOVI_MAX_DM_ID+1]; + struct DOVIVdr *vdr[DOVI_MAX_DM_ID+1]; ///< RefStruct references uint8_t dv_profile; } DOVIContext; -int ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0); +void ff_dovi_ctx_replace(DOVIContext *s, const DOVIContext *s0); /** * Completely reset a DOVIContext, preserving only logctx. diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index d64055e1f9..44a9680415 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -3584,9 +3584,7 @@ static int hevc_update_thread_context(AVCodecContext *dst, if (ret < 0) return ret; - ret = ff_dovi_ctx_replace(&s->dovi_ctx, &s0->dovi_ctx); - if (ret < 0) - return ret; + ff_dovi_ctx_replace(&s->dovi_ctx, &s0->dovi_ctx); ret = av_buffer_replace(&s->sei.common.dynamic_hdr_vivid.info, s0->sei.common.dynamic_hdr_vivid.info); From patchwork Tue Sep 19 19:57:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43820 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp185795pzb; Tue, 19 Sep 2023 12:58:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFzLesMsvT1TLvBloLyjbMzuPko4fpWhtx1mSjaIAvu5gdBIqtrOBNDxadzsui8w6ytLZyH X-Received: by 2002:a17:906:cc5c:b0:9ad:ec25:825b with SMTP id mm28-20020a170906cc5c00b009adec25825bmr282022ejb.58.1695153481715; Tue, 19 Sep 2023 12:58:01 -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 u2-20020a1709064ac200b00991f598188csi11114807ejt.214.2023.09.19.12.58.01; Tue, 19 Sep 2023 12:58:01 -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=Ve+BK8Hx; 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 955CE68C89C; Tue, 19 Sep 2023 22:57:12 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04olkn2019.outbound.protection.outlook.com [40.92.75.19]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 4F3FA68C89C for ; Tue, 19 Sep 2023 22:57:11 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EBY+lu4WFVUYlrMNrLjASkSOlLmSdawn/cSAFlasNKIy3ge2G6sndMt9sr1VRnEqCr+T05iFFYxWzAFEYoSeMQWussjDKj8OiaevHonXCZzCnFDvGztWLkeY4N0tbODfJweOGbPkRO1v4woSsMtYCfo5cr81OG0Wng+67VadmSF4MU+KcSteNLJhV6lxh3NNcTTBOn0RZBjaQ3JN9+U/Daa73axoc2t8MVHRRsXw4/emPr6E7DkA7vV8mzeu/TRGkFHb+ujIGI2muzdOFVZjArQRZiiZ41WuN5FA9cU6LReNR/ThacILgko0i9tKdYJvBxs3tgkTIcbrU7uHbx/P7g== 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=7eJ4Q7qvrrAO8NHMeO+Qe3D7WKOWGGWi4IsJdwvvxnA=; b=FrszWjBTl/brBizonIFo8I1IkBIer/AN3z6uRVTO/uxztwYrfHLuPW0xldynguktRYLOGvGFIsXvufbmHSVd5S6OY+NQehZ1yb3H6/CjWomDnNvavh6jxydFsuGVnHIqT32jQF/ng0/P8jbmkCcPPa+zQhtvS5akEydoAj7QM8x+HdVybB8Mn1sljcc9u5n+VSZMATAGCHAsnWk+CFpkargtnU3Armsm8rVd65EO1TZXM6Gxlvl4f2vX2rpsTyVSGROaWr4+b29JCxp0jevUbxa+vclv2zJF+12A4L8YhzzY52B1q05ItEaohZkd5T5WNdoXa+siMd3ZriulBpRrhA== 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=7eJ4Q7qvrrAO8NHMeO+Qe3D7WKOWGGWi4IsJdwvvxnA=; b=Ve+BK8HxWkNC0bY+ZHCMvb60QOlzOy8GjDvET6xXJh4G8faKWuMa2S+RjQlf48YzTsn7v8USXAD3al+wfzSqw2eN1c3sW57UMPAZZtWAavdcIhqwLiO8gBudN6Vs74eHb+j/bPHhOFxzFN6BEWNGg+o3Kuc/8+v0qkj8ev5jK4Mrsrsb6dwO0T83X6B96wDgYanqMDJNgdRpVUXqkbvESXRHPoBN9jCkXHBsugcjNj+zYLrMuQcbnsBdlrmVkK7ZTlvaCIRh2dsvx2JAF/1ECmHveyUnvVJFyhCkPFq9nsZqNf9z4n/E0tKvbYIklk7iKX60wvuumuFItrK2l46H5w== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AM8P250MB0215.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:326::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:57:10 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:57:10 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:01 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [RVaSrwDEIscD8yJXQYBbasO4cvzQqwkV] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-9-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AM8P250MB0215:EE_ X-MS-Office365-Filtering-Correlation-Id: adbbf567-469c-4280-bffe-08dbb94a9bf0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qUrB33u5KACMe1Mp1rCFCTUaBSwr3kHxONb0PbWssCmfJcfakfJgYkI1wViRrK74t2CPZ45n/X2NmZA9s/EMPMoKQCcUN+tQc41wiXa2WtyklY2MbG68BQRyWkWNJ8uIUtOw5ZVXQFSGTvKYUY92/J3y6JML9i6sBezw5sPAMAnk1allcSQcLkzRrbqQvTpxlp678cjA+jq4PeCccitPbzyqgmPPcrfVdfLK6jifXIijYjuKpoPm0+penKF7YRP/n4ntgichG/foPQCbn2QtRqDxWsSzQP+IN3tzoNtsHK+8J8Ed0MOe81NuF9bROKDTFLRMTzarfyqQPaASe40to1Wo9O/VmwjYPQmQInRtolm+wmvIf+KBL/2zh6c6mP817NaMg06Wp33KA8HrMyc2eIEDtgSLudMwmSG9poaOSskfTqGoKRdp531zjTgmblFXl4vzHWloEGmS8WhTXM1Ql1kEUtuPOmTR3UCN0JZvxVxz5oJp0fb7GypiF06xV34UiMhOGKuTCgPwH9GttgYIPqQPoTW/XqVOnTwP99knf9HMZeVh12BmR01942waEVROEgNgPTQy/Gl8Gz/ZgXVE5l6SYahhnFbj0RLyeY4iCJXxKNuh6iCMOTXf0qBPEx32 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XE7GkbtIIgas2UIMwHXT0gObswiq4Q4sDQJ3UxrR3Rkvg5mR2pv9ZqHcoU4e89Y0fImZ/g+CylHDtTuWMqWXdH5UucrVQb6GgWf296mMC2cAxnfDA8l6KEAgkUrRlDgX31dYMKSYDqZHC7VMV/JFemHWnzbBk19YrHWWEX+vWhjUyLEtmSgcSjAf9WJ1736hwgjnTxP4A24p0rWPfssaq6C0S9hhdvMeQh8T7qsWWIhQFm4b2oz0Qi85RqNshKT4SeMI8pdznHo+X2GQaZrNMp20JbMnH2VLiJVobxgLNK382X4YHMu1iHfhqQQKR69G7NBPYNlpz6z9oxqidd4I9BfEuJS1TTxgp5qHosirRIjCVYtpoVu9y8jHauI1yr68D9qLeHm8JlkHQjpBPak4Vu+A5SE9pBPvD6UQdZ57N4Vler1vuwZRlcYR+MmAMph0+8tDvpcHZMzXGRv98WC+p3pMN+d+qHxYMsXTLL4T4pUlSYuOtYlo2GWopeKqzZ3wvmmDeUt5jcJrfYk/rLef5emubbYWyKNggrOcNNmHUiPjgDoxw7YsJreoEhtHDbWWeyts1eoND3IKSJDRAATOVWmcNv66S/+UoOIfVGJ9DlxVmRkYMqk23mTa1JkLkRJMYlzqNdlJh+dQT7szVt5TeSkgAb23QzJr18+qg+5BY5pp3D8gyZfpPlKfusrBYcv2U2+twkiy/lgRT5g+y7VJqNrE1cn7DkDxElN0TxheyH0k4xqqZqtVeh13qa6Fi8Dd8THHxYU1VG56zGop5NK1ulp2TzmUuHEGRJb2QEVWzb56z4tj+SS1ejKBt0m62S9BXhYu144Bib7TmIImfzZ4DUJbN+PSKsBxNGaf2RStm6egAAG3856dU8KPe+oZcLWQqEDM1z7r1uquYCvhdyTsR04NqT+XELfgFrGio8IEsMnq2MrC8jxvr1/Zv2pF/4x14o1njFK6X1BktZDahR4VkI3c8Ay+CkVACCqJDNKicxASG4j+TjzD8CTOWUNbKDzzgFMMjOHdBq5RElFbQ+T23GzpewMksLcmgZ0UEiBizGlXA4OJTIhLn0tWH7Yr6yxBd+kHP1Ck0yxNPkA8w5K2cHaFfiFrNOAsNEYgJsYtwn+EvnvM4PQQwa5z7BxkQUS/CMfyj7w7lhtCoTiIwHz8CuwhUe8Fsyk7gel7N+0M2n9UhIp8khxZnFK/oL5/kKkCC678j0LbIuizJygEnCGZlU3x36l+X2hkbVE+2ZLlGAd11+qWKtjq/LeDSWeogzzD X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: adbbf567-469c-4280-bffe-08dbb94a9bf0 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:57:10.0419 (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: AM8P250MB0215 Subject: [FFmpeg-devel] [PATCH 09/42] avcodec/refstruct: Allow checking for exclusive ownership 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: z4Lku+VcmRip This is the analog of av_buffer_is_writable(); it will be used in the next commit. Signed-off-by: Andreas Rheinhardt --- libavcodec/refstruct.c | 14 ++++++++++++++ libavcodec/refstruct.h | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/libavcodec/refstruct.c b/libavcodec/refstruct.c index 917cf6b7ac..604938922a 100644 --- a/libavcodec/refstruct.c +++ b/libavcodec/refstruct.c @@ -48,6 +48,11 @@ static RefCount *get_refcount(void *obj) return (RefCount*)((char*)obj - REFCOUNT_OFFSET); } +static const RefCount *cget_refcount(const void *data) +{ + return (const RefCount*)((const char*)data - REFCOUNT_OFFSET); +} + static void *get_userdata(void *buf) { return (char*)buf + REFCOUNT_OFFSET; @@ -137,3 +142,12 @@ void ff_refstruct_replace(void *dstp, const void *src) memcpy(dstp, &dst, sizeof(dst)); } } + +int ff_refstruct_exclusive(const void *data) +{ + const RefCount *ref = cget_refcount(data); + /* Casting const away here is safe, because it is a load. + * It is necessary because atomic_load_explicit() does not + * accept const atomics in C11 (see also N1807). */ + return atomic_load_explicit((atomic_uintptr_t*)&ref->refcount, memory_order_acquire) == 1; +} diff --git a/libavcodec/refstruct.h b/libavcodec/refstruct.h index 0086717c17..ee6936d77a 100644 --- a/libavcodec/refstruct.h +++ b/libavcodec/refstruct.h @@ -142,4 +142,13 @@ const void *ff_refstruct_ref_c(const void *obj); */ void ff_refstruct_replace(void *dstp, const void *src); +/** + * Check whether the reference count of an object managed + * via this API is 1. + * + * @param obj A pointer to an object managed via this API. + * @return 1 if the reference count of obj is 1; 0 otherwise. + */ +int ff_refstruct_exclusive(const void *obj); + #endif /* AVCODEC_REFSTRUCT_H */ From patchwork Tue Sep 19 19:57:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43821 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp185858pzb; Tue, 19 Sep 2023 12:58:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEChj9bc6Xlu1PVvmmCMfUH7LcnxzwFPoAAJBdz2nxwmh/kSAhlELR/LoNBJcz75iOrfUMc X-Received: by 2002:aa7:d4d7:0:b0:523:b665:e494 with SMTP id t23-20020aa7d4d7000000b00523b665e494mr400802edr.15.1695153492950; Tue, 19 Sep 2023 12:58:12 -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 v4-20020aa7d644000000b0052a48148227si10787327edr.361.2023.09.19.12.58.11; Tue, 19 Sep 2023 12:58:12 -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=mild6q6L; 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 B762868C264; Tue, 19 Sep 2023 22:57:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04olkn2072.outbound.protection.outlook.com [40.92.75.72]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DC13D68C94F for ; Tue, 19 Sep 2023 22:57:14 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OUd3P0DIbRIwp+ZI7lY537hpLnJuPjY6+eGLNpebAfDmMBMVDnPXsqq7GPdERRK5HJzB2HwTwmOnyGQjh/Rle2khvIvjAt6aKF29JKk7IoVW4hkQCSejwzKktd+IXpqPN0tnr/1idztgvn1ePFnkAFGTMd6m3SGK8/tGEUHta0dOa3Tta++tIqi3Bt7I+ZtpDWdr3bZdNUMZtzMMWlqHMsJCNsdJac3rSarvRe4OWiyhRCVZQU8VGJ6RbkupCdKqHQcN+4QsHuRznku0KknfHDR5cyYS59ToWt1mGzzoB6DhEqCAx73020ZyXBrXwdGrzeUwiWyNgBGEv9vcbJMc1w== 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=dUMyBgNeVw7MyWA7iTgI+ghLau8Ar8UBOxyjZ6GIsZk=; b=d/RsF6b9mjlv58WosXQtt2UdQuQqvlJj0iV+r5TqpMweBL5pIcAUwNwHnf434ipSNCzgV32GGOSeOx8XksRJ8kTMbSjg6wZ6hohtJ2JwlI1bsuVfEvIKEX0YUYOMqmvTd5s04jMuEZ7sHUTMZm83TIYd6DxKzGS5yrVRfDvpvG2Tbs+vg4DANycfL0lWcnXs5Ft9sepp+8CtzVEYaWZAs3V8W6WjgNlrX+mtxpPxt/TrbvMq3NQtV3+Xrcf0ka8h84FSEaIOHSb01I8W7DXdQpC9DH6BGvgsdpAbpGRO2F4kcLJoMT9kCVRpWLQvQ+3/F7ZBbqkIget+g2NSCSMwfg== 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=dUMyBgNeVw7MyWA7iTgI+ghLau8Ar8UBOxyjZ6GIsZk=; b=mild6q6L84+NMie6alI7ds+2zWJxzG5s8MkERHsCTi8sxCTgeklRUL87tKf0rTkas0d3SIPKwSHONOH7+nuICirROWho/Fyr98O1Y3/Kjm6F4peR7e6j8NiX7tDQWmRGVkPRCVi9n8wRQnGHk6EWeH06m/iDDjiftoiQbjftuBhJCoGc5C4yrHdT6vzuOd2dQzm/0DWjLRhAXV9vI5aYK+oUjHUQhHgEqhkZONeGifk1ldVIKfRQfm6+CSxF2GcA3W6ZLQggupBSsiXaoRnWn+6bRc2ntTLWQ84lrrVwyMgavsy5Xf+1YSH/almR6J5kqavKXPINBMtfJWov3XocGg== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AM8P250MB0215.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:326::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:57:13 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:57:13 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:02 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [tcRIFpTLRNWPzWKZumNWIutE5ypS9SoD] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-10-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AM8P250MB0215:EE_ X-MS-Office365-Filtering-Correlation-Id: 46cc6d44-cd53-48bd-f950-08dbb94a9da4 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: W3iEK+eMVlATrnjH+IRv16gDnLcBSYuamZV2LAdOoGfIhoG+cD4dETBJrd8ZdhvGL9vPV9DGVjN7/+N8YRW/JlEnc1f5NNgdpbWIm8WRSlYIb7SyVT5hVqebbtYPJ0AUjzekzY4OmHjsDVnt0MnbCDBsFPJ3YYoIyTtFFRSqF036SoqkYk4o1TAJTolYQit1vB5mT3eUDgV63lsRF/SThnMl/Br8aoI46u8WCT5Mjji7dYVCEgKMHOfkBIQ1B3AIiAxLGPtKDcG7+B/HuqflZ3ooJS4Ur4tfU+KTvHzO62UmxY4+7Twf+i5xg4OXf0Y8V/tE3aIpu61ap4T4CVDz6gblBb8H5zC5p3vYrHmwjAIiEbLEF+Dapzenf8580qute/Wp/+gDcHMXTO6+Zz3RMpfnmn/g+8Noon6gGJs5JuVlPxZVj7LfhweCwtYy+i075GK6fGmD8KHqN1PT0ArASh8EhVoo4i2pNM6Pl3OefQOkcFXDzE3hXky/vsqQMnTaBP/ZQ8qR/v9c7+2QV214zQg8Pd8yd8edkGo27h1kHIZ6fPA/MnvRsvh6DBlq+9EcdzFe/kPJBm6qK4YOZEWLG2J4kJz/M0cUfAFeNUQ4xwG+F2BdEVOQFiUkL9BbgTxe X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: vF649tAPBs5XiOR8YXLHXp+4GjnN0ondgtRh/h/F/v/qan3Evz87nj76cLMtvx/MjK6nNS/Jd0KUdQE3aqLhCWs8PX7tHFF8ZqTUT74YBhZofBJbJUAJ1505qx5ITrwU5l9H+X/rPbBrZHXDiJcwu47+gs6DjZ1cz+7RyscvljdrO2aPY/yluQLgr7iuKDlF4WNTxbCd943SN7QtIUSwJnvKl/alitmNkhmHrfzQFf6maV6bC39LCEdcl/Xs+BO03sNrFly8u8IRM9Lezhv+YBbDKH7I+EUBD1j5OxT/xM0HjUJd83ikTkdeFuPmS8CDL1qzWdyfR+GFLHOrnscaeqbCsfJJOVaolFo6hAtyo3pJR48PTGDMVBAdfTi1mjVRALG2G3ZTTjCK2tuWqPYUKzvY3Og6j08eUfVG3n3aC/I7KDE+yxLmt7u2hhkfhoUE/RUYimEaejbnWEpqviOvhlJ8mr2VYJhZZzakbvRaoSVPF3vqxJgJrsAJGpKebqqb2qZpL5+KjAKCF3pwcs3qhgMx4HkKcdGZHvCCpfTzulv3q3QQdOG+Xkzxo4BF9DCYg3MauT7zGlafGgurqc1rMdFKI/0Hhd/LwCVybo7jkxCkP3AK56vBxYs+jE+baSlki/WRE4zFzPMev3Arh3xsIF4d0e6ifxiLTMaBFZZW8eUYijfcTwZHKAgHPKnl+elzZMN0pMsfyy2ZCsraf2T/UL1jtEY647+LeQNWitEkgjZnOl7uxj9NUt8lcgOvSfktoOGESmWcHjJmjhb4hAKtHwW1mt/FNSIL/7p62jY+lL7xFSEMZXzthcIDOe5/IGssqDi3gjBOgI7KWTWSm7zM1EdYtT9RmW+ybYMMZsmTLd2loWqloFGXYYeX/GoQAkkE5K8Ojxe+dzgxWFxcdQMQgv88bP9T/fcnnzvWqu5bk2q0AgS2kKXlXRRmYdSz/A/19J5JZQ053GRce3B+3Qy1icweK6FFB5ASDZW/q+npeEKivaWPAcCxXI/COyyeNZUUadiuRdBz2RxLl43gqr+hKzm+MycHVukVGUl0pS8mbjG+mLbYKgAg/hR2Qa4LjnYIKSVRKGEXx8xS2f07UYry4jnfr0vIaOt9eXrrBbA9KgSDfzM3az5PUe9ZKisu8E5Q/9hQ+6XOieOOGFDrNKhid5tn3gXI/tfWJSj5CDpAK6gc/4CXFLB1HQ7VmwPLhERYWgvF9HtL8SjFZyN8CYTyVOH/BAAb1SxIptr+msrbwahmkb4zLYrpXBUwnoTcucmL X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 46cc6d44-cd53-48bd-f950-08dbb94a9da4 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:57:12.9728 (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: AM8P250MB0215 Subject: [FFmpeg-devel] [PATCH 10/42] avcodec/cbs: Use RefStruct-API for unit content 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: jEox7uzXkZ83 This avoids allocations and error checks etc. as well as duplicate pointer lists in the CodedBitstreamFooContexts. It also avoids casting const away for use as opaque, as the RefStruct API supports const opaques. The fact that some of the units are not refcounted (i.e. they are sometimes part of an encoding context like VAAPIEncodeH264Context) meant that CodedBitstreamUnit still contains two pointers, one to the content and another ownership pointer, replacing the AVBufferRef* pointer. Signed-off-by: Andreas Rheinhardt --- libavcodec/av1dec.c | 49 +++---------- libavcodec/av1dec.h | 10 +-- libavcodec/cbs.c | 101 ++++++++++++-------------- libavcodec/cbs.h | 12 +-- libavcodec/cbs_av1.c | 32 +++----- libavcodec/cbs_av1.h | 3 +- libavcodec/cbs_h264.h | 6 +- libavcodec/cbs_h2645.c | 94 ++++++++---------------- libavcodec/cbs_h265.h | 9 +-- libavcodec/cbs_h266.h | 11 +-- libavcodec/cbs_h266_syntax_template.c | 10 +-- libavcodec/cbs_internal.h | 7 +- 12 files changed, 129 insertions(+), 215 deletions(-) diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index 39ccad5bf6..87056520dd 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -37,6 +37,7 @@ #include "internal.h" #include "hwconfig.h" #include "profiles.h" +#include "refstruct.h" #include "thread.h" /**< same with Div_Lut defined in spec 7.11.3.7 */ @@ -641,7 +642,7 @@ static void av1_frame_unref(AVCodecContext *avctx, AV1Frame *f) ff_thread_release_buffer(avctx, f->f); av_buffer_unref(&f->hwaccel_priv_buf); f->hwaccel_picture_private = NULL; - av_buffer_unref(&f->header_ref); + ff_refstruct_unref(&f->header_ref); f->raw_frame_header = NULL; f->spatial_id = f->temporal_id = 0; memset(f->skip_mode_frame_idx, 0, @@ -654,9 +655,7 @@ static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *s { int ret; - ret = av_buffer_replace(&dst->header_ref, src->header_ref); - if (ret < 0) - return ret; + ff_refstruct_replace(&dst->header_ref, src->header_ref); dst->raw_frame_header = src->raw_frame_header; @@ -712,10 +711,10 @@ static av_cold int av1_decode_free(AVCodecContext *avctx) av1_frame_unref(avctx, &s->cur_frame); av_frame_free(&s->cur_frame.f); - av_buffer_unref(&s->seq_ref); - av_buffer_unref(&s->header_ref); - av_buffer_unref(&s->cll_ref); - av_buffer_unref(&s->mdcv_ref); + ff_refstruct_unref(&s->seq_ref); + ff_refstruct_unref(&s->header_ref); + ff_refstruct_unref(&s->cll_ref); + ff_refstruct_unref(&s->mdcv_ref); av_freep(&s->tile_group_info); while (s->itut_t35_fifo && av_fifo_read(s->itut_t35_fifo, &itut_t35, 1) >= 0) @@ -1160,9 +1159,7 @@ static int get_current_frame(AVCodecContext *avctx) av1_frame_unref(avctx, &s->cur_frame); - s->cur_frame.header_ref = av_buffer_ref(s->header_ref); - if (!s->cur_frame.header_ref) - return AVERROR(ENOMEM); + s->cur_frame.header_ref = ff_refstruct_ref(s->header_ref); s->cur_frame.raw_frame_header = s->raw_frame_header; @@ -1214,12 +1211,7 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) switch (unit->type) { case AV1_OBU_SEQUENCE_HEADER: - av_buffer_unref(&s->seq_ref); - s->seq_ref = av_buffer_ref(unit->content_ref); - if (!s->seq_ref) { - ret = AVERROR(ENOMEM); - goto end; - } + ff_refstruct_replace(&s->seq_ref, unit->content_ref); s->raw_seq = &obu->obu.sequence_header; @@ -1264,12 +1256,7 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) goto end; } - av_buffer_unref(&s->header_ref); - s->header_ref = av_buffer_ref(unit->content_ref); - if (!s->header_ref) { - ret = AVERROR(ENOMEM); - goto end; - } + ff_refstruct_replace(&s->header_ref, unit->content_ref); if (unit->type == AV1_OBU_FRAME) s->raw_frame_header = &obu->obu.frame.header; @@ -1356,23 +1343,11 @@ static int av1_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) case AV1_OBU_METADATA: switch (obu->obu.metadata.metadata_type) { case AV1_METADATA_TYPE_HDR_CLL: - av_buffer_unref(&s->cll_ref); - s->cll_ref = av_buffer_ref(unit->content_ref); - if (!s->cll_ref) { - s->cll = NULL; - ret = AVERROR(ENOMEM); - goto end; - } + ff_refstruct_replace(&s->cll_ref, unit->content_ref); s->cll = &obu->obu.metadata.metadata.hdr_cll; break; case AV1_METADATA_TYPE_HDR_MDCV: - av_buffer_unref(&s->mdcv_ref); - s->mdcv_ref = av_buffer_ref(unit->content_ref); - if (!s->mdcv_ref) { - s->mdcv = NULL; - ret = AVERROR(ENOMEM); - goto end; - } + ff_refstruct_replace(&s->mdcv_ref, unit->content_ref); s->mdcv = &obu->obu.metadata.metadata.hdr_mdcv; break; case AV1_METADATA_TYPE_ITUT_T35: { diff --git a/libavcodec/av1dec.h b/libavcodec/av1dec.h index 59ffed1d9b..acbeec4af3 100644 --- a/libavcodec/av1dec.h +++ b/libavcodec/av1dec.h @@ -38,7 +38,7 @@ typedef struct AV1Frame { AVBufferRef *hwaccel_priv_buf; void *hwaccel_picture_private; - AVBufferRef *header_ref; + AV1RawOBU *header_ref; ///< RefStruct reference backing raw_frame_header. AV1RawFrameHeader *raw_frame_header; int temporal_id; @@ -71,15 +71,15 @@ typedef struct AV1DecContext { CodedBitstreamFragment current_obu; AVPacket *pkt; - AVBufferRef *seq_ref; + AV1RawOBU *seq_ref; ///< RefStruct reference backing raw_seq AV1RawSequenceHeader *raw_seq; - AVBufferRef *header_ref; + AV1RawOBU *header_ref; ///< RefStruct reference backing raw_frame_header AV1RawFrameHeader *raw_frame_header; TileGroupInfo *tile_group_info; - AVBufferRef *cll_ref; + AV1RawOBU *cll_ref; ///< RefStruct reference backing cll AV1RawMetadataHDRCLL *cll; - AVBufferRef *mdcv_ref; + AV1RawOBU *mdcv_ref; ///< RefStruct reference backing mdcv AV1RawMetadataHDRMDCV *mdcv; AVFifo *itut_t35_fifo; diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index 3ec8285e21..00c462b09d 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -28,6 +28,7 @@ #include "avcodec.h" #include "cbs.h" #include "cbs_internal.h" +#include "refstruct.h" static const CodedBitstreamType *const cbs_type_table[] = { @@ -151,7 +152,7 @@ av_cold void ff_cbs_close(CodedBitstreamContext **ctx_ptr) static void cbs_unit_uninit(CodedBitstreamUnit *unit) { - av_buffer_unref(&unit->content_ref); + ff_refstruct_unref(&unit->content_ref); unit->content = NULL; av_buffer_unref(&unit->data_ref); @@ -199,7 +200,7 @@ static int cbs_read_fragment_content(CodedBitstreamContext *ctx, continue; } - av_buffer_unref(&unit->content_ref); + ff_refstruct_unref(&unit->content_ref); unit->content = NULL; av_assert0(unit->data && unit->data_ref); @@ -213,7 +214,7 @@ static int cbs_read_fragment_content(CodedBitstreamContext *ctx, av_log(ctx->log_ctx, AV_LOG_VERBOSE, "Skipping decomposition of unit %d " "(type %"PRIu32").\n", i, unit->type); - av_buffer_unref(&unit->content_ref); + ff_refstruct_unref(&unit->content_ref); unit->content = NULL; } else if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to read unit %d " @@ -773,28 +774,22 @@ int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, - AVBufferRef *content_buf) + void *content_ref) { CodedBitstreamUnit *unit; - AVBufferRef *content_ref; int err; if (position == -1) position = frag->nb_units; av_assert0(position >= 0 && position <= frag->nb_units); - if (content_buf) { - content_ref = av_buffer_ref(content_buf); - if (!content_ref) - return AVERROR(ENOMEM); - } else { - content_ref = NULL; - } - err = cbs_insert_unit(frag, position); - if (err < 0) { - av_buffer_unref(&content_ref); + if (err < 0) return err; + + if (content_ref) { + // Create our own reference out of the user-supplied one. + content_ref = ff_refstruct_ref(content_ref); } unit = &frag->units[position]; @@ -868,15 +863,14 @@ void ff_cbs_delete_unit(CodedBitstreamFragment *frag, (frag->nb_units - position) * sizeof(*frag->units)); } -static void cbs_default_free_unit_content(void *opaque, uint8_t *data) +static void cbs_default_free_unit_content(FFRefStructOpaque opaque, void *content) { - const CodedBitstreamUnitTypeDescriptor *desc = opaque; + const CodedBitstreamUnitTypeDescriptor *desc = opaque.c; for (int i = 0; i < desc->type.ref.nb_offsets; i++) { - void **ptr = (void**)(data + desc->type.ref.offsets[i]); + void **ptr = (void**)((char*)content + desc->type.ref.offsets[i]); av_buffer_unref((AVBufferRef**)(ptr + 1)); } - av_free(data); } static const CodedBitstreamUnitTypeDescriptor @@ -907,6 +901,15 @@ static const CodedBitstreamUnitTypeDescriptor return NULL; } +static void *cbs_alloc_content(const CodedBitstreamUnitTypeDescriptor *desc) +{ + return ff_refstruct_alloc_ext_c(desc->content_size, 0, + (FFRefStructOpaque){ .c = desc }, + desc->content_type == CBS_CONTENT_TYPE_COMPLEX + ? desc->type.complex.content_free + : cbs_default_free_unit_content); +} + int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit) { @@ -918,27 +921,17 @@ int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx, if (!desc) return AVERROR(ENOSYS); - unit->content = av_mallocz(desc->content_size); - if (!unit->content) + unit->content_ref = cbs_alloc_content(desc); + if (!unit->content_ref) return AVERROR(ENOMEM); - - unit->content_ref = - av_buffer_create(unit->content, desc->content_size, - desc->content_type == CBS_CONTENT_TYPE_COMPLEX - ? desc->type.complex.content_free - : cbs_default_free_unit_content, - (void*)desc, 0); - if (!unit->content_ref) { - av_freep(&unit->content); - return AVERROR(ENOMEM); - } + unit->content = unit->content_ref; return 0; } -static int cbs_clone_internal_refs_unit_content(AVBufferRef **clone_ref, - const CodedBitstreamUnit *unit, - const CodedBitstreamUnitTypeDescriptor *desc) +static int cbs_clone_noncomplex_unit_content(void **clonep, + const CodedBitstreamUnit *unit, + const CodedBitstreamUnitTypeDescriptor *desc) { const uint8_t *src; uint8_t *copy; @@ -947,9 +940,15 @@ static int cbs_clone_internal_refs_unit_content(AVBufferRef **clone_ref, av_assert0(unit->content); src = unit->content; - copy = av_memdup(src, desc->content_size); + copy = cbs_alloc_content(desc); if (!copy) return AVERROR(ENOMEM); + memcpy(copy, src, desc->content_size); + for (int i = 0; i < desc->type.ref.nb_offsets; i++) { + void **ptr = (void**)(copy + desc->type.ref.offsets[i]); + /* Zero all the AVBufferRefs as they are owned by src. */ + *(ptr + 1) = NULL; + } for (i = 0; i < desc->type.ref.nb_offsets; i++) { const uint8_t *const *src_ptr = (const uint8_t* const*)(src + desc->type.ref.offsets[i]); @@ -975,22 +974,12 @@ static int cbs_clone_internal_refs_unit_content(AVBufferRef **clone_ref, goto fail; } } - - *clone_ref = av_buffer_create(copy, desc->content_size, - cbs_default_free_unit_content, - (void*)desc, 0); - if (!*clone_ref) { - err = AVERROR(ENOMEM); - goto fail; - } + *clonep = copy; return 0; fail: - for (--i; i >= 0; i--) - av_buffer_unref((AVBufferRef**)(copy + desc->type.ref.offsets[i])); - av_freep(©); - *clone_ref = NULL; + ff_refstruct_unref(©); return err; } @@ -1003,7 +992,7 @@ static int cbs_clone_unit_content(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit) { const CodedBitstreamUnitTypeDescriptor *desc; - AVBufferRef *ref; + void *new_content; int err; desc = cbs_find_unit_type_desc(ctx, unit); @@ -1012,13 +1001,13 @@ static int cbs_clone_unit_content(CodedBitstreamContext *ctx, switch (desc->content_type) { case CBS_CONTENT_TYPE_INTERNAL_REFS: - err = cbs_clone_internal_refs_unit_content(&ref, unit, desc); + err = cbs_clone_noncomplex_unit_content(&new_content, unit, desc); break; case CBS_CONTENT_TYPE_COMPLEX: if (!desc->type.complex.content_clone) return AVERROR_PATCHWELCOME; - err = desc->type.complex.content_clone(&ref, unit); + err = desc->type.complex.content_clone(&new_content, unit); break; default: @@ -1028,8 +1017,8 @@ static int cbs_clone_unit_content(CodedBitstreamContext *ctx, if (err < 0) return err; - unit->content_ref = ref; - unit->content = ref->data; + unit->content_ref = new_content; + unit->content = new_content; return 0; } @@ -1045,17 +1034,17 @@ int ff_cbs_make_unit_refcounted(CodedBitstreamContext *ctx, int ff_cbs_make_unit_writable(CodedBitstreamContext *ctx, CodedBitstreamUnit *unit) { - AVBufferRef *ref = unit->content_ref; + void *ref = unit->content_ref; int err; av_assert0(unit->content); - if (ref && av_buffer_is_writable(ref)) + if (ref && ff_refstruct_exclusive(ref)) return 0; err = cbs_clone_unit_content(ctx, unit); if (err < 0) return err; - av_buffer_unref(&ref); + ff_refstruct_unref(&ref); return 0; } diff --git a/libavcodec/cbs.h b/libavcodec/cbs.h index b4131db5fe..68f7e4b0a9 100644 --- a/libavcodec/cbs.h +++ b/libavcodec/cbs.h @@ -106,10 +106,10 @@ typedef struct CodedBitstreamUnit { */ void *content; /** - * If content is reference counted, a reference to the buffer containing - * content. Null if content is not reference counted. + * If content is reference counted, a RefStruct reference backing content. + * NULL if content is not reference counted. */ - AVBufferRef *content_ref; + void *content_ref; } CodedBitstreamUnit; /** @@ -375,14 +375,16 @@ int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx, /** * Insert a new unit into a fragment with the given content. * + * If content_ref is supplied, it has to be a RefStruct reference + * backing content; the user keeps ownership of the supplied reference. * The content structure continues to be owned by the caller if - * content_buf is not supplied. + * content_ref is not supplied. */ int ff_cbs_insert_unit_content(CodedBitstreamFragment *frag, int position, CodedBitstreamUnitType type, void *content, - AVBufferRef *content_buf); + void *content_ref); /** * Add a new unit to a fragment with the given data bitstream. diff --git a/libavcodec/cbs_av1.c b/libavcodec/cbs_av1.c index 7fb5bd8b42..50a5c3e117 100644 --- a/libavcodec/cbs_av1.c +++ b/libavcodec/cbs_av1.c @@ -24,6 +24,7 @@ #include "cbs_internal.h" #include "cbs_av1.h" #include "defs.h" +#include "refstruct.h" static int cbs_av1_read_uvlc(CodedBitstreamContext *ctx, GetBitContext *gbc, @@ -953,12 +954,7 @@ static int cbs_av1_read_unit(CodedBitstreamContext *ctx, priv->operating_point_idc = sequence_header->operating_point_idc[priv->operating_point]; } - av_buffer_unref(&priv->sequence_header_ref); - priv->sequence_header = NULL; - - priv->sequence_header_ref = av_buffer_ref(unit->content_ref); - if (!priv->sequence_header_ref) - return AVERROR(ENOMEM); + ff_refstruct_replace(&priv->sequence_header_ref, unit->content_ref); priv->sequence_header = &obu->obu.sequence_header; } break; @@ -1077,9 +1073,7 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx, av1ctx = *priv; if (priv->sequence_header_ref) { - av1ctx.sequence_header_ref = av_buffer_ref(priv->sequence_header_ref); - if (!av1ctx.sequence_header_ref) - return AVERROR(ENOMEM); + av1ctx.sequence_header_ref = ff_refstruct_ref(priv->sequence_header_ref); } if (priv->frame_header_ref) { @@ -1112,19 +1106,14 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx, if (err < 0) goto error; - av_buffer_unref(&priv->sequence_header_ref); + ff_refstruct_unref(&priv->sequence_header_ref); priv->sequence_header = NULL; err = ff_cbs_make_unit_refcounted(ctx, unit); if (err < 0) goto error; - priv->sequence_header_ref = av_buffer_ref(unit->content_ref); - if (!priv->sequence_header_ref) { - err = AVERROR(ENOMEM); - goto error; - } - + priv->sequence_header_ref = ff_refstruct_ref(unit->content_ref); priv->sequence_header = &obu->obu.sequence_header; } break; @@ -1227,7 +1216,7 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx, av_assert0(data_pos <= start_pos); if (8 * obu->obu_size > put_bits_left(pbc)) { - av_buffer_unref(&priv->sequence_header_ref); + ff_refstruct_unref(&priv->sequence_header_ref); av_buffer_unref(&priv->frame_header_ref); *priv = av1ctx; @@ -1251,7 +1240,7 @@ static int cbs_av1_write_obu(CodedBitstreamContext *ctx, err = 0; error: - av_buffer_unref(&av1ctx.sequence_header_ref); + ff_refstruct_unref(&av1ctx.sequence_header_ref); av_buffer_unref(&av1ctx.frame_header_ref); return err; @@ -1303,13 +1292,13 @@ static void cbs_av1_close(CodedBitstreamContext *ctx) { CodedBitstreamAV1Context *priv = ctx->priv_data; - av_buffer_unref(&priv->sequence_header_ref); + ff_refstruct_unref(&priv->sequence_header_ref); av_buffer_unref(&priv->frame_header_ref); } -static void cbs_av1_free_metadata(void *unit, uint8_t *content) +static void cbs_av1_free_metadata(FFRefStructOpaque unused, void *content) { - AV1RawOBU *obu = (AV1RawOBU*)content; + AV1RawOBU *obu = content; AV1RawMetadata *md; av_assert0(obu->header.obu_type == AV1_OBU_METADATA); @@ -1327,7 +1316,6 @@ static void cbs_av1_free_metadata(void *unit, uint8_t *content) default: av_buffer_unref(&md->metadata.unknown.payload_ref); } - av_free(content); } static const CodedBitstreamUnitTypeDescriptor cbs_av1_unit_types[] = { diff --git a/libavcodec/cbs_av1.h b/libavcodec/cbs_av1.h index 64dfdce9c4..63917f2f16 100644 --- a/libavcodec/cbs_av1.h +++ b/libavcodec/cbs_av1.h @@ -437,7 +437,8 @@ typedef struct CodedBitstreamAV1Context { const AVClass *class; AV1RawSequenceHeader *sequence_header; - AVBufferRef *sequence_header_ref; + /** A RefStruct reference backing sequence_header. */ + AV1RawOBU *sequence_header_ref; int seen_frame_header; AVBufferRef *frame_header_ref; diff --git a/libavcodec/cbs_h264.h b/libavcodec/cbs_h264.h index ca9b688c05..db91231337 100644 --- a/libavcodec/cbs_h264.h +++ b/libavcodec/cbs_h264.h @@ -407,10 +407,8 @@ typedef struct CodedBitstreamH264Context { // All currently available parameter sets. These are updated when // any parameter set NAL unit is read/written with this context. - AVBufferRef *sps_ref[H264_MAX_SPS_COUNT]; - AVBufferRef *pps_ref[H264_MAX_PPS_COUNT]; - H264RawSPS *sps[H264_MAX_SPS_COUNT]; - H264RawPPS *pps[H264_MAX_PPS_COUNT]; + H264RawSPS *sps[H264_MAX_SPS_COUNT]; ///< RefStruct references + H264RawPPS *pps[H264_MAX_PPS_COUNT]; ///< RefStruct references // The currently active parameter sets. These are updated when any // NAL unit refers to the relevant parameter set. These pointers diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 318c997d94..e071442c31 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -28,6 +28,7 @@ #include "h264.h" #include "h2645_parse.h" #include "hevc.h" +#include "refstruct.h" #include "vvc.h" @@ -759,12 +760,8 @@ static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext *ctx, \ return err; \ if (priv->ps_var[id] == priv->active_ ## ps_var) \ priv->active_ ## ps_var = NULL ; \ - av_buffer_unref(&priv->ps_var ## _ref[id]); \ av_assert0(unit->content_ref); \ - priv->ps_var ## _ref[id] = av_buffer_ref(unit->content_ref); \ - if (!priv->ps_var ## _ref[id]) \ - return AVERROR(ENOMEM); \ - priv->ps_var[id] = (H26 ## h26n ## Raw ## ps_name *)priv->ps_var ## _ref[id]->data; \ + ff_refstruct_replace(&priv->ps_var[id], unit->content_ref); \ return 0; \ } @@ -784,12 +781,8 @@ static int cbs_h26 ## h26n ## _replace_ ## ps_var(CodedBitstreamContext *ctx, \ int err = ff_cbs_make_unit_refcounted(ctx, unit); \ if (err < 0) \ return err; \ - av_buffer_unref(&priv->ps_var ## _ref[id]); \ av_assert0(unit->content_ref); \ - priv->ps_var ## _ref[id] = av_buffer_ref(unit->content_ref); \ - if (!priv->ps_var ## _ref[id]) \ - return AVERROR(ENOMEM); \ - priv->ps_var[id] = (H26 ## h26n ## Raw ## ps_name *)priv->ps_var ## _ref[id]->data; \ + ff_refstruct_replace(&priv->ps_var[id], unit->content_ref); \ return 0; \ } @@ -808,9 +801,7 @@ static int cbs_h266_replace_ph(CodedBitstreamContext *ctx, if (err < 0) return err; av_assert0(unit->content_ref); - err = av_buffer_replace(&h266->ph_ref, unit->content_ref); - if (err < 0) - return err; + ff_refstruct_replace(&h266->ph_ref, unit->content_ref); h266->ph = ph; return 0; } @@ -1874,14 +1865,10 @@ static void cbs_h264_flush(CodedBitstreamContext *ctx) { CodedBitstreamH264Context *h264 = ctx->priv_data; - for (int i = 0; i < FF_ARRAY_ELEMS(h264->sps); i++) { - av_buffer_unref(&h264->sps_ref[i]); - h264->sps[i] = NULL; - } - for (int i = 0; i < FF_ARRAY_ELEMS(h264->pps); i++) { - av_buffer_unref(&h264->pps_ref[i]); - h264->pps[i] = NULL; - } + for (int i = 0; i < FF_ARRAY_ELEMS(h264->sps); i++) + ff_refstruct_unref(&h264->sps[i]); + for (int i = 0; i < FF_ARRAY_ELEMS(h264->pps); i++) + ff_refstruct_unref(&h264->pps[i]); h264->active_sps = NULL; h264->active_pps = NULL; @@ -1896,27 +1883,21 @@ static void cbs_h264_close(CodedBitstreamContext *ctx) ff_h2645_packet_uninit(&h264->common.read_packet); for (i = 0; i < FF_ARRAY_ELEMS(h264->sps); i++) - av_buffer_unref(&h264->sps_ref[i]); + ff_refstruct_unref(&h264->sps[i]); for (i = 0; i < FF_ARRAY_ELEMS(h264->pps); i++) - av_buffer_unref(&h264->pps_ref[i]); + ff_refstruct_unref(&h264->pps[i]); } static void cbs_h265_flush(CodedBitstreamContext *ctx) { CodedBitstreamH265Context *h265 = ctx->priv_data; - for (int i = 0; i < FF_ARRAY_ELEMS(h265->vps); i++) { - av_buffer_unref(&h265->vps_ref[i]); - h265->vps[i] = NULL; - } - for (int i = 0; i < FF_ARRAY_ELEMS(h265->sps); i++) { - av_buffer_unref(&h265->sps_ref[i]); - h265->sps[i] = NULL; - } - for (int i = 0; i < FF_ARRAY_ELEMS(h265->pps); i++) { - av_buffer_unref(&h265->pps_ref[i]); - h265->pps[i] = NULL; - } + for (int i = 0; i < FF_ARRAY_ELEMS(h265->vps); i++) + ff_refstruct_unref(&h265->vps[i]); + for (int i = 0; i < FF_ARRAY_ELEMS(h265->sps); i++) + ff_refstruct_unref(&h265->sps[i]); + for (int i = 0; i < FF_ARRAY_ELEMS(h265->pps); i++) + ff_refstruct_unref(&h265->pps[i]); h265->active_vps = NULL; h265->active_sps = NULL; @@ -1931,32 +1912,24 @@ static void cbs_h265_close(CodedBitstreamContext *ctx) ff_h2645_packet_uninit(&h265->common.read_packet); for (i = 0; i < FF_ARRAY_ELEMS(h265->vps); i++) - av_buffer_unref(&h265->vps_ref[i]); + ff_refstruct_unref(&h265->vps[i]); for (i = 0; i < FF_ARRAY_ELEMS(h265->sps); i++) - av_buffer_unref(&h265->sps_ref[i]); + ff_refstruct_unref(&h265->sps[i]); for (i = 0; i < FF_ARRAY_ELEMS(h265->pps); i++) - av_buffer_unref(&h265->pps_ref[i]); + ff_refstruct_unref(&h265->pps[i]); } static void cbs_h266_flush(CodedBitstreamContext *ctx) { CodedBitstreamH266Context *h266 = ctx->priv_data; - for (int i = 0; i < FF_ARRAY_ELEMS(h266->vps); i++) { - av_buffer_unref(&h266->vps_ref[i]); - h266->vps[i] = NULL; - } - - for (int i = 0; i < FF_ARRAY_ELEMS(h266->sps); i++) { - av_buffer_unref(&h266->sps_ref[i]); - h266->sps[i] = NULL; - } - for (int i = 0; i < FF_ARRAY_ELEMS(h266->pps); i++) { - av_buffer_unref(&h266->pps_ref[i]); - h266->pps[i] = NULL; - } - av_buffer_unref(&h266->ph_ref); - h266->ph = NULL; + for (int i = 0; i < FF_ARRAY_ELEMS(h266->vps); i++) + ff_refstruct_unref(&h266->vps[i]); + for (int i = 0; i < FF_ARRAY_ELEMS(h266->sps); i++) + ff_refstruct_unref(&h266->sps[i]); + for (int i = 0; i < FF_ARRAY_ELEMS(h266->pps); i++) + ff_refstruct_unref(&h266->pps[i]); + ff_refstruct_unref(&h266->ph_ref); } static void cbs_h266_close(CodedBitstreamContext *ctx) @@ -1967,11 +1940,10 @@ static void cbs_h266_close(CodedBitstreamContext *ctx) ff_h2645_packet_uninit(&h266->common.read_packet); } -static void cbs_h264_free_sei(void *opaque, uint8_t *content) +static void cbs_h264_free_sei(FFRefStructOpaque unused, void *content) { - H264RawSEI *sei = (H264RawSEI*)content; + H264RawSEI *sei = content; ff_cbs_sei_free_message_list(&sei->message_list); - av_free(content); } static const CodedBitstreamUnitTypeDescriptor cbs_h264_unit_types[] = { @@ -1994,11 +1966,10 @@ static const CodedBitstreamUnitTypeDescriptor cbs_h264_unit_types[] = { CBS_UNIT_TYPE_END_OF_LIST }; -static void cbs_h265_free_sei(void *opaque, uint8_t *content) +static void cbs_h265_free_sei(FFRefStructOpaque unused, void *content) { - H265RawSEI *sei = (H265RawSEI*)content; + H265RawSEI *sei = content; ff_cbs_sei_free_message_list(&sei->message_list); - av_free(content); } static const CodedBitstreamUnitTypeDescriptor cbs_h265_unit_types[] = { @@ -2021,11 +1992,10 @@ static const CodedBitstreamUnitTypeDescriptor cbs_h265_unit_types[] = { CBS_UNIT_TYPE_END_OF_LIST }; -static void cbs_h266_free_sei(void *opaque, uint8_t *content) +static void cbs_h266_free_sei(FFRefStructOpaque unused, void *content) { - H266RawSEI *sei = (H266RawSEI*)content; + H266RawSEI *sei = content; ff_cbs_sei_free_message_list(&sei->message_list); - av_free(content); } static const CodedBitstreamUnitTypeDescriptor cbs_h266_unit_types[] = { diff --git a/libavcodec/cbs_h265.h b/libavcodec/cbs_h265.h index f7cbd4970d..1b1195f198 100644 --- a/libavcodec/cbs_h265.h +++ b/libavcodec/cbs_h265.h @@ -681,12 +681,9 @@ typedef struct CodedBitstreamH265Context { // All currently available parameter sets. These are updated when // any parameter set NAL unit is read/written with this context. - AVBufferRef *vps_ref[HEVC_MAX_VPS_COUNT]; - AVBufferRef *sps_ref[HEVC_MAX_SPS_COUNT]; - AVBufferRef *pps_ref[HEVC_MAX_PPS_COUNT]; - H265RawVPS *vps[HEVC_MAX_VPS_COUNT]; - H265RawSPS *sps[HEVC_MAX_SPS_COUNT]; - H265RawPPS *pps[HEVC_MAX_PPS_COUNT]; + H265RawVPS *vps[HEVC_MAX_VPS_COUNT]; ///< RefStruct references + H265RawSPS *sps[HEVC_MAX_SPS_COUNT]; ///< RefStruct references + H265RawPPS *pps[HEVC_MAX_PPS_COUNT]; ///< RefStruct references // The currently active parameter sets. These are updated when any // NAL unit refers to the relevant parameter set. These pointers diff --git a/libavcodec/cbs_h266.h b/libavcodec/cbs_h266.h index 3a6f6d96b5..d2ba99f522 100644 --- a/libavcodec/cbs_h266.h +++ b/libavcodec/cbs_h266.h @@ -867,14 +867,11 @@ typedef struct CodedBitstreamH266Context { // All currently available parameter sets. These are updated when // any parameter set NAL unit is read/written with this context. - AVBufferRef *vps_ref[VVC_MAX_VPS_COUNT]; - AVBufferRef *sps_ref[VVC_MAX_SPS_COUNT]; - AVBufferRef *pps_ref[VVC_MAX_PPS_COUNT]; - AVBufferRef *ph_ref; - H266RawVPS *vps[VVC_MAX_VPS_COUNT]; - H266RawSPS *sps[VVC_MAX_SPS_COUNT]; - H266RawPPS *pps[VVC_MAX_PPS_COUNT]; + H266RawVPS *vps[VVC_MAX_VPS_COUNT]; ///< RefStruct references + H266RawSPS *sps[VVC_MAX_SPS_COUNT]; ///< RefStruct references + H266RawPPS *pps[VVC_MAX_PPS_COUNT]; ///< RefStruct references H266RawPictureHeader *ph; + void *ph_ref; ///< RefStruct reference backing ph above } CodedBitstreamH266Context; #endif /* AVCODEC_CBS_H266_H */ diff --git a/libavcodec/cbs_h266_syntax_template.c b/libavcodec/cbs_h266_syntax_template.c index 4075897b9a..a0f48a86c3 100644 --- a/libavcodec/cbs_h266_syntax_template.c +++ b/libavcodec/cbs_h266_syntax_template.c @@ -1072,17 +1072,13 @@ static int FUNC(sps)(CodedBitstreamContext *ctx, RWContext *rw, ub(4, sps_seq_parameter_set_id); ub(4, sps_video_parameter_set_id); - if (current->sps_video_parameter_set_id == 0 && !h266->vps_ref[0]) { - H266RawVPS *vps; - AVBufferRef *ref = av_buffer_allocz(sizeof(H266RawVPS)); - if (!ref) { + if (current->sps_video_parameter_set_id == 0 && !h266->vps[0]) { + H266RawVPS *vps = ff_refstruct_allocz(sizeof(*vps)); + if (!vps) return AVERROR(ENOMEM); - } - vps = (H266RawVPS *) ref->data; vps->vps_max_layers_minus1 = 0; vps->vps_independent_layer_flag[0] = 1; vps->vps_layer_id[0] = current->nal_unit_header.nuh_layer_id; - h266->vps_ref[0] = ref; h266->vps[0] = vps; } diff --git a/libavcodec/cbs_internal.h b/libavcodec/cbs_internal.h index da84697a29..10a95d7d6e 100644 --- a/libavcodec/cbs_internal.h +++ b/libavcodec/cbs_internal.h @@ -19,15 +19,16 @@ #ifndef AVCODEC_CBS_INTERNAL_H #define AVCODEC_CBS_INTERNAL_H +#include #include -#include "libavutil/buffer.h" #include "libavutil/log.h" #include "cbs.h" #include "codec_id.h" #include "get_bits.h" #include "put_bits.h" +#include "refstruct.h" enum CBSContentType { @@ -92,8 +93,8 @@ typedef const struct CodedBitstreamUnitTypeDescriptor { } ref; struct { - void (*content_free)(void *opaque, uint8_t *data); - int (*content_clone)(AVBufferRef **ref, CodedBitstreamUnit *unit); + void (*content_free)(FFRefStructOpaque opaque, void *content); + int (*content_clone)(void **new_content, CodedBitstreamUnit *unit); } complex; } type; } CodedBitstreamUnitTypeDescriptor; From patchwork Tue Sep 19 19:57:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43822 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp185920pzb; Tue, 19 Sep 2023 12:58:23 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEIM0cYG2uLnn3dfEjdGv9dQZb1w3ZL1JdiCVBNKQPkrfsBHnnIuwmORJyOVarFmLs7B1db X-Received: by 2002:a17:906:2099:b0:9a1:c812:cbb9 with SMTP id 25-20020a170906209900b009a1c812cbb9mr371903ejq.31.1695153502738; Tue, 19 Sep 2023 12:58:22 -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 lr6-20020a170906fb8600b0099d74066201si11262209ejb.415.2023.09.19.12.58.22; Tue, 19 Sep 2023 12:58:22 -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=PvPJmdw1; 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 A9B7868C966; Tue, 19 Sep 2023 22:57:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04olkn2070.outbound.protection.outlook.com [40.92.75.70]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E30BC68C960 for ; Tue, 19 Sep 2023 22:57:16 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XYLmZLheb3BjHe8EbMCeSBb0SeqWwF2rQgtgc2XFCICvXc3W2tlOMl3hTbghg6RQ1avzQUTMYPI/8Tl/deHxTNt3f3GmZcJhnfsCXj/JlUVnhK+6ncLCN7ron+snGWjJlykPb/RfrWlg6TQC0RdCF7DWG2bgLNWc/LvplVKB7EU1BKLRSO0N7yIwrJrOOfZEW7Bw2mCmn1g1oBL48YdUbm74jfzGURUJ+3kc4Y2868lICA+DL7BYiI0pC7diIGnFQbuCNfucjfGzc6mgh6CydLQOYENvbojnSQOV9tPjvdkWd/P+fWhfWrCkjgPwY1U5ILUYD04NJ9C+epB0ob3P8A== 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=PTDcofH44rhpf7wNKcBVTDqan0UmN5zTRFmJzR4Ba4k=; b=mQr8fH3nk3SoL9EOmEDys5zkvCau88aaovjPmPksXOApqynN51HVW6strJCejnbfCJ5uvVG3FDUkHF5w4P8HkzuNM8S7vY3ibM7+Ve5M02YhCy3UQ71n7Jt5g9sSZT0PtQgsCZ7aUvOGMT9lWgmrWPfhL1WYlpUf7eVRStaHf8qrcgQsKfJ74VXgyM3rI+LMvOhOBnOyMHKxSbafPAGkZqrycF3KOipm4S1bC1K4Fh2vnK3wDHUMIDVJO3eaC5+J8U9wT1fwQx+W52Wv0vIUa6G9my/264HotsT1ZsmOR3UNmaSuxa5PuW8UKxm2046FwnccK9IVMj02e/hbIdDOfg== 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=PTDcofH44rhpf7wNKcBVTDqan0UmN5zTRFmJzR4Ba4k=; b=PvPJmdw1dHUVFIfjAjamUVi8+wgLz7aUu3iJoxJloC01xD2rRgAHrG++y8delxyt++7+9PoqVPmNbI4dl1oKcF3EcfLoxBSZpP9d0tOnfVIM3DnfybxUnFtg81OiW5LAGquIc0zJIxkLS5469NE8StRA94fuPPRpUQJfJP39+LofkBhPKjAmJldQu3RLQdSpytBI/ImbkE8tWOMWOCCuJSE49A54fPNKwwxyYnK/NU05wmwGI/YGD8iaSfoff9MCIv+iKiVbciN2Rl9Yz8nc4nwk8frbJR4DbzwhP/bT48/pCr4dzkruoHpRrR4Rz9uWHbAsQiimBvef+vOwKDyL5g== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AM8P250MB0215.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:326::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:57:15 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:57:15 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:03 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [hpnGYDiy6P+8drpzW+JiX8Wl+LOjw4Um] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-11-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AM8P250MB0215:EE_ X-MS-Office365-Filtering-Correlation-Id: f5deb960-2e0d-4e0b-99a9-08dbb94a9f3c X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8DNfu/WklQCuqZpcZUic4GVLRymzQwuct50ydky3WU+uvqxUW20RfOrGMD1VP7/WteUlgpZ+lk5RmCRGfwSe2m50IQKeYWhEkefiSowMyrSGJZdWruwkrAsmKYhVbtDetE/KbQdwEMrfJECYNMsMq6w+6RHlrZDjDIWCT63TPe1lmf/m5z9ZSmlJzARcLUupN/vBL58urq4crMkCunXAs2XqNpNTZUVsiiGeQvyTiV7vrKE+ilhqcunCxmULT/RXZbkCNWoY7Z+JS6YWZef6fn3E9hCrA+4zO18aB5pgiYD4QNIWXuOTfvqB2r4gEtPVAvBf2vHFLMpo7PVo74kaXSaY9iuagqI6RO/V9ydejb+ofx56iksbBuTBzL+IL7nr2daNBjmdOb8HaXJaEiK++OmuoGDGLH2eX/mDWGWhbJDJBR+gZa0fF/SHJy/Cra4iOmDQ6jAVCP6J0KLjIMsZnhaeQrD3n6hfigLJ0h2TsJ66pe/Usutw6IF9Sn8sPLFV77pH2TlAVGzsgZ5cQfZHpEMd3JNvJJBpobeAPBVh6ER74xpplCOUysbWKN2AVJ3PjFlDzylDE6HM2DZ145r9Y+WpuvSEWIJncVLp9jRFi2jtDSkTvwU1jBrrXatvrpAn X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wnPVzeOKQ/adjkG9L11qsbQ8SVkWMnHmw7sBp8uAXFEVEqt1RnLCBGiipfCixnxS6k7VMTg/AP3t5YYB2Qm2hA16RAmp7OsTE+N8j6c3CPvXnhF3Fn7pphQvZMmwNOP1Rq5Z15IizwjD1FEyQam6u1g5OKzGijzZAIeobM3PZlDKXzEzFW7LyruBoEgcES9tG9XuGBwAqjtsnyFgtQXViq0+4tLdLB/ruU3omRd1C3jEwpqIy1Sg4yr6Zfgohc4Xf4CQapKGEoiZeSgudPXg+Bcy+s15D1BV8QF2lcVT1H8RgSa94u/tOtPlTFOA4IxWrgk7xLNhazvzEwg19hTmlsEIpIa1hlQhml9zj/7Y/o7QaA98rTJMiq6VIfIfi6y9akHofKJERYlCgcebvvw5GLhaV8IJL+EVmF4BuC8SDi7fEXPhIKsP4uLXKvFTUi0K2G/DX2dVIvLG2I55tFLd1sZbfnfG7CeFpasIElXAd8FQn+a1tVaxt91wXT2juu4eFjELJg8YHXItPzKtnD+tG8D7M12NDg+BDafBoNlKHfRuotv1eLIFTQ/badCU1UZ3qFLN8Gjp+WfzoKEHnenSy5TjclaiR2E76M6gCWL/rMXjBpB/rVV2CdkaMLlXD2Xi7sOMjTKDMhITeddOJWA0IbvqrTvZpAOITGB5Ogx4GjqICSw+VcNVjIcg4b/mD24TlYnR7SxLrI2Hk7Ao+KOgp2TKTGgZP62EP6VnVcnx9M7Fc1HomGq7c0gLGVteQI+JlBPlm0fEvd5OgNnTcOs9olNs6SvyU+k8Ne2Ctabj3x8qPawAMx3Z2G/k/O+qp30uyR36zery5ogqa5lNSk/rLpsD4QcOGi5pbQLuGvIwEuZxtH5dxwIdeFAiJPLDjjIxMgTRiIUkfQ+Te5xndlrbV6HMODcJKMG7bnAWfCuhkd/c+qwOAtnVaxSYKQ+BzWTEda8ealyrGGtxw7hfwTEquRbZIElqsNIc4iSRUK/QNkEqJl26hYmrT59iWW7imIR2cTHH66Nqj0YsotHk4xmTq7HVuhicTewXSClKohe0UnTpxvrMsscUiL9anURyleBLx6tQl3NisQGudkTHGXct8jZ9UOT7R8/BgRnxxb8K2Q0d2lWcLJwWWcmJLwU4LP8aVGn8Nl9xaj7PGNWTj4GYggXHRPtzWXVvPnCPobHC0G4OOu15232NWl9A27vinRGw3MlPyTw3BGhu2cUBqIbL3YnmFqoMHt/H0mDyTJ0d7Zoe3z6YkH+Q90Bk7OvtG8v2 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f5deb960-2e0d-4e0b-99a9-08dbb94a9f3c X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:57:15.5456 (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: AM8P250MB0215 Subject: [FFmpeg-devel] [PATCH 11/42] avcodec/cbs_sei: Use RefStruct API for SEI messages 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: TUWFV1TzWWKf The SEI message code uses the AVBuffer API for its SEI messages and contained buffers (like the extension buffer for HEVC or the user data (un)registered payload buffers). Contrary to the ordinary CBS code (where some of these contained buffer references are actually references to the provided AVPacket's data so that one can't replace them with the RefStruct API), the CBS SEI code never uses outside buffers at all and can therefore be switched entirely to the RefStruct API. This avoids the overhead inherent in the AVBuffer API (namely the separate allocations etc.). Notice that the refcounting here is actually currently unused; the refcounts are always one (or zero in case of no refcounting); its only advantage is the flexibility provided by custom free functions. Signed-off-by: Andreas Rheinhardt --- libavcodec/cbs_h2645.c | 19 +++++++-- libavcodec/cbs_sei.c | 61 ++++++++++++---------------- libavcodec/cbs_sei.h | 20 ++++----- libavcodec/cbs_sei_syntax_template.c | 5 +++ 4 files changed, 54 insertions(+), 51 deletions(-) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index e071442c31..c1f67fefb9 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -357,18 +357,31 @@ static int cbs_h2645_read_more_rbsp_data(GetBitContext *gbc) #define bit_position(rw) (get_bits_count(rw)) #define byte_alignment(rw) (get_bits_count(rw) % 8) +/* The CBS SEI code uses the refstruct API for the allocation + * of its child buffers. */ #define allocate(name, size) do { \ - name ## _ref = av_buffer_allocz(size + \ + name = ff_refstruct_allocz(size + \ AV_INPUT_BUFFER_PADDING_SIZE); \ - if (!name ## _ref) \ + if (!name) \ return AVERROR(ENOMEM); \ - name = name ## _ref->data; \ } while (0) #define FUNC(name) FUNC_SEI(name) #include "cbs_sei_syntax_template.c" #undef FUNC +#undef allocate + +/* The other code uses the refstruct API for the allocation + * of its child buffers. */ +#define allocate(name, size) do { \ + name ## _ref = av_buffer_allocz(size + \ + AV_INPUT_BUFFER_PADDING_SIZE); \ + if (!name ## _ref) \ + return AVERROR(ENOMEM); \ + name = name ## _ref->data; \ + } while (0) + #define FUNC(name) FUNC_H264(name) #include "cbs_h264_syntax_template.c" #undef FUNC diff --git a/libavcodec/cbs_sei.c b/libavcodec/cbs_sei.c index bd7f6f4938..e28c2f9093 100644 --- a/libavcodec/cbs_sei.c +++ b/libavcodec/cbs_sei.c @@ -22,25 +22,25 @@ #include "cbs_h265.h" #include "cbs_h266.h" #include "cbs_sei.h" +#include "refstruct.h" -static void cbs_free_user_data_registered(void *opaque, uint8_t *data) +static void cbs_free_user_data_registered(FFRefStructOpaque unused, void *obj) { - SEIRawUserDataRegistered *udr = (SEIRawUserDataRegistered*)data; - av_buffer_unref(&udr->data_ref); - av_free(udr); + SEIRawUserDataRegistered *udr = obj; + ff_refstruct_unref(&udr->data); } -static void cbs_free_user_data_unregistered(void *opaque, uint8_t *data) +static void cbs_free_user_data_unregistered(FFRefStructOpaque unused, void *obj) { - SEIRawUserDataUnregistered *udu = (SEIRawUserDataUnregistered*)data; - av_buffer_unref(&udu->data_ref); - av_free(udu); + SEIRawUserDataUnregistered *udu = obj; + ff_refstruct_unref(&udu->data); } int ff_cbs_sei_alloc_message_payload(SEIRawMessage *message, const SEIMessageTypeDescriptor *desc) { - void (*free_func)(void*, uint8_t*); + void (*free_func)(FFRefStructOpaque, void*); + unsigned flags = 0; av_assert0(message->payload == NULL && message->payload_ref == NULL); @@ -50,24 +50,16 @@ int ff_cbs_sei_alloc_message_payload(SEIRawMessage *message, free_func = &cbs_free_user_data_registered; else if (desc->type == SEI_TYPE_USER_DATA_UNREGISTERED) free_func = &cbs_free_user_data_unregistered; - else + else { free_func = NULL; - - if (free_func) { - message->payload = av_mallocz(desc->size); - if (!message->payload) - return AVERROR(ENOMEM); - message->payload_ref = - av_buffer_create(message->payload, desc->size, - free_func, NULL, 0); - } else { - message->payload_ref = av_buffer_alloc(desc->size); + flags = FF_REFSTRUCT_FLAG_NO_ZEROING; } - if (!message->payload_ref) { - av_freep(&message->payload); + + message->payload_ref = ff_refstruct_alloc_ext(desc->size, flags, + NULL, free_func); + if (!message->payload_ref) return AVERROR(ENOMEM); - } - message->payload = message->payload_ref->data; + message->payload = message->payload_ref; return 0; } @@ -101,8 +93,8 @@ void ff_cbs_sei_free_message_list(SEIRawMessageList *list) { for (int i = 0; i < list->nb_messages; i++) { SEIRawMessage *message = &list->messages[i]; - av_buffer_unref(&message->payload_ref); - av_buffer_unref(&message->extension_data_ref); + ff_refstruct_unref(&message->payload_ref); + ff_refstruct_unref(&message->extension_data); } av_free(list->messages); } @@ -278,13 +270,12 @@ int ff_cbs_sei_add_message(CodedBitstreamContext *ctx, int prefix, uint32_t payload_type, void *payload_data, - AVBufferRef *payload_buf) + void *payload_ref) { const SEIMessageTypeDescriptor *desc; CodedBitstreamUnit *unit; SEIRawMessageList *list; SEIRawMessage *message; - AVBufferRef *payload_ref; int err; desc = ff_cbs_sei_find_type(ctx, payload_type); @@ -306,12 +297,10 @@ int ff_cbs_sei_add_message(CodedBitstreamContext *ctx, if (err < 0) return err; - if (payload_buf) { - payload_ref = av_buffer_ref(payload_buf); - if (!payload_ref) - return AVERROR(ENOMEM); - } else { - payload_ref = NULL; + if (payload_ref) { + /* The following just increments payload_ref's refcount, + * so that payload_ref is now owned by us. */ + payload_ref = ff_refstruct_ref(payload_ref); } message = &list->messages[list->nb_messages - 1]; @@ -364,8 +353,8 @@ static void cbs_sei_delete_message(SEIRawMessageList *list, av_assert0(0 <= position && position < list->nb_messages); message = &list->messages[position]; - av_buffer_unref(&message->payload_ref); - av_buffer_unref(&message->extension_data_ref); + ff_refstruct_unref(&message->payload_ref); + ff_refstruct_unref(&message->extension_data); --list->nb_messages; diff --git a/libavcodec/cbs_sei.h b/libavcodec/cbs_sei.h index 1c327a4689..4511c506cc 100644 --- a/libavcodec/cbs_sei.h +++ b/libavcodec/cbs_sei.h @@ -22,8 +22,6 @@ #include #include -#include "libavutil/buffer.h" - #include "cbs.h" #include "sei.h" @@ -35,15 +33,13 @@ typedef struct SEIRawFillerPayload { typedef struct SEIRawUserDataRegistered { uint8_t itu_t_t35_country_code; uint8_t itu_t_t35_country_code_extension_byte; - uint8_t *data; - AVBufferRef *data_ref; + uint8_t *data; ///< RefStruct reference size_t data_length; } SEIRawUserDataRegistered; typedef struct SEIRawUserDataUnregistered { uint8_t uuid_iso_iec_11578[16]; - uint8_t *data; - AVBufferRef *data_ref; + uint8_t *data; ///< RefStruct reference size_t data_length; } SEIRawUserDataUnregistered; @@ -75,9 +71,8 @@ typedef struct SEIRawMessage { uint32_t payload_type; uint32_t payload_size; void *payload; - AVBufferRef *payload_ref; - uint8_t *extension_data; - AVBufferRef *extension_data_ref; + void *payload_ref; ///< RefStruct reference + uint8_t *extension_data; ///< RefStruct reference size_t extension_bit_length; } SEIRawMessage; @@ -174,15 +169,16 @@ void ff_cbs_sei_free_message_list(SEIRawMessageList *list); * Will add to an existing SEI NAL unit, or create a new one for the * message if there is no suitable existing one. * - * Takes a new reference to payload_buf, if set. If payload_buf is - * NULL then the new message will not be reference counted. + * If set, payload_ref must be a RefStruct reference backing payload_data. + * This function creates a new reference to payload_ref in this case. + * If payload_ref is NULL, the new message will not be reference counted. */ int ff_cbs_sei_add_message(CodedBitstreamContext *ctx, CodedBitstreamFragment *au, int prefix, uint32_t payload_type, void *payload_data, - AVBufferRef *payload_buf); + void *payload_ref); /** * Iterate over messages with the given payload type in an access unit. diff --git a/libavcodec/cbs_sei_syntax_template.c b/libavcodec/cbs_sei_syntax_template.c index 6a7cc36dda..62dd1dabaa 100644 --- a/libavcodec/cbs_sei_syntax_template.c +++ b/libavcodec/cbs_sei_syntax_template.c @@ -234,7 +234,12 @@ static int FUNC(message)(CodedBitstreamContext *ctx, RWContext *rw, } else { uint8_t *data; +#ifdef READ + allocate(current->payload_ref, current->payload_size); + current->payload = current->payload_ref; +#else allocate(current->payload, current->payload_size); +#endif data = current->payload; for (i = 0; i < current->payload_size; i++) From patchwork Tue Sep 19 19:57:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43823 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp185986pzb; Tue, 19 Sep 2023 12:58:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEeqAejDXMEDo9Z1BE9dQuvAk5tDU4ZQfLkUJlo6mUCiap/cAG14f7FPhh3wV1cQSBQpRt4 X-Received: by 2002:a2e:7405:0:b0:2c0:34f9:5a6a with SMTP id p5-20020a2e7405000000b002c034f95a6amr343119ljc.34.1695153512962; Tue, 19 Sep 2023 12:58:32 -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 y14-20020a170906470e00b009a1960b4ad9si10312497ejq.515.2023.09.19.12.58.32; Tue, 19 Sep 2023 12:58:32 -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=d2+uyNQw; 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 AE96768C946; Tue, 19 Sep 2023 22:57:21 +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-db8eur05olkn2075.outbound.protection.outlook.com [40.92.89.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 35FF968C946 for ; Tue, 19 Sep 2023 22:57:19 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Q00S+OMslPiWT0P82eQLRwdar8KKtqlA8wJML8Qj8owGFJaNPZsy8zLN9BNSU8jyDv/tRPb4lvK96RuxkdGSuhtTXSClhAM3qQXbhbWuydW1eV8sRVL88vR1wRZ232mPMOG2OGt+qp+tfVjC2GcsVZH3GloZNkGdsQf3ueGkV1TIPgM6i+XYcIPEYcZlMpm2vvFeIm0Irn/mOk1zT38/Xhc1SqSHiNl3fZWw9XszpDn1h6R+wh8yRnvEyS3lc/0gYcRW87rIE3hwifWC4tphi2GU5CF9fnmddzOCo1pUBf6A/E6HEgmAe7rG8eaztvvjNvSA4QbWq4x+EkcUG9rRKA== 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=iBbx1KRhsvBsRjnJjn74xq9OsNU3Yf9po4OiRt/InbI=; b=FsDrwJjtGfL+o8XidHA/Fgdp8E7zkMO8X2cdZhDNeKu9eu6KBIj5YYTyTr/M+dvkgryhX0gIomRdQy/8M/FDgdCRTGnYFyXvZRGf/K7Jv9PFqlgiXaEByzlu5IZnprqZIOJIP+ReWMzTc5AfaFSFzGHr52p5gjEFmVWSjEhWhrWUI8/qKRiP+wn1mqUrR6M9tQ+bidhoPTGsPNfLJ+sIASq0ZiOpJK+dgOOPAP/xibE7xdiKUbibFPUqTWs/1VBFXqLHl6hgOVrUF1X0oVCeVGQEGYBvLpCG6UvSpJYmV/6tVrXe81ASIGgEN+MpwCmTard7LABYD5XVNh6E9mEXSw== 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=iBbx1KRhsvBsRjnJjn74xq9OsNU3Yf9po4OiRt/InbI=; b=d2+uyNQwh2M2aEM0qZJckGzTpI/nAqv7T4QXcOLox8/7JGtbVlxOZSx4RiF1cBxrbjHbZOKCBu3T1IwsN2uEj6OhB6e9qSxJElo196ylGZiM3e0ymSGgjm3jaAB5ZKvXvtNbtcMXIbLUUsqKf3BzcLIK4n4TCqh/sFRd4kR/OYUs7AFW0Tbpkgm159q+ltUHROYPdqNHK03qxLvWXCCx4dHmRP6GwIaklE/w1jYO4tQKR+cdi5IYgp0orGYNLxwGocwhdkVpoLjU85IOjBZL/YBtiZkM05V00MjLE0AYSv6q+LpNlnQpBnJ91P3bwEmUiHky+9+JnFMztQCL+E66rg== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AM8P250MB0215.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:326::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:57:18 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:57:18 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:04 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [/mYq8w3S8uHMJciFSI+h7tFWuuWUKu4F] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-12-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AM8P250MB0215:EE_ X-MS-Office365-Filtering-Correlation-Id: 7686bc1f-819c-4ebe-ad83-08dbb94aa0ca X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GCwdHVN3Og/Ib9Aj11cZ+PNdxZ3bMUIBpMLpkiW8YZSBAeIWfqNR8ehu3bPBKWrhrust6h8DroV9zbko62s4vTNdbP3efoKeyvk7FX3U9liMBDxXKBoPBMdenfQzmRhK80B2W798UxZT10aF9JSQymb847QrMLHrG26aNK4q8Oi/GXXyz02EXvffr6VwkBdwcxSY+jqJmIwEu9/n4PWbnyLBOKi2tq2fWOj4nmrsBAk5aFCUiLxz44NqSrYySWUqFVjHvGw238xyP1Xt84JzsNVv8GDqss0C8guz3hLiXmzDk8dGppjWiFWlGJ1GUjAD3BGHkEmfAwXSbzYf3ARn4rP7gguzKq6RKgx3Jj9GaZ7oYU8PnGSLLm47qFxVNb9AdSYZrFkh2cLniZsk3PWfKgp0VXv0qWBaTHgiPcDt9o6qhgFqSaNweYoa54d9D6asToxjyCAc7mrd3FVAZx00xGBCR8mI07/p7hgoqII05Iiwcq8YZ1LW/uZhfOlfNX/7+8X4OylBnzTvei9NrbMvbs9z/uI5r/uYeeblHKnNWn+fi1qQGiBU1E4jXMQhccWoE1hsQK2XBXW/EDfBSuYfWNz2MfuLyUZpBLHWYABlwRNCwTToHnx8sscJe7Wst91g X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BtLGPde0VTqR46q0V6ErOTDj+L8h6SlS29uhQHZ19UBhkp5SK9OxWjLLa2fAP8U+BAtlLt6fmOOD2NAf/WxpNwHTFmrmE6pZOL22NWtFXAUX2IH66BfvOIub5hE20xjmGcA6v6/8B7bN/At9aIcgMb9+mh0wxwdZW+3DsD9ILhfdUUuE/OiYMhMQDrd6T2qnewFPrcfyVEM8SNtn3/p+FTJt4/87OrrEGK9pEYKHbxkOROYg5d86BQ/mwuVs3zfPdPOog8EjAMvA1pwe37kWPWkqH52TT2uxEZyYSRQTywK43Jmq5ZnX2Ar9EiAZnV9f7MPN+VfXcYo1ZU3EmVEUnLt6kZ57uUlglV0ZlmDZBxpce80glVg/A3OGh5OcvpJckEMp473xhb0biAUfkMeuKElK8UEydjgrB9CSdZjeDuGToN4E9QAiO8uOWZN889hWULc+XdZLBAgZ/9pGvUOrnmJFWq8uRVfbx2wi/Q5BNdObkvAyWac11LWSzIb84PyU6yg8+D7VLj2p9il8ioQmYhkMqNEynbkVvw4QOaxN4DxCHdkDlPAFErFxOrGMhX98zrRZYy6IrOSmvQcqz59gmRL3N/9IE83RaqvEqUorEJrGb5Wjodb4FlmBke5yPFm0svIgCqH3C3r1Sf0OoZTqbbiAMbPQzwW5L7HoVNIU0ROnvSiYtcXZZe7W++lmeGvF+r1o4Hb5aZVv0tSOxLkvFSO+U/R/H/mDIWM91CZK+T9PchiXy1gsz0ffwA1Aq2h8Rm+iRGZSn4d+ZG9+uqikEZjd2TnG+kTBr1UUKo3UuV4wckZVzHMb4zVQ9tM+M52p0YEDSW6jywWAMpfzTAoKI+Iy1XIz+lXKSVaSKiIPk9cEnOMSOZZp1XaYB4HwBbqDoAF9PvS04A8al+EgE0DwNTn+PNO60t+ayI3v8t7QFJJdQ8TWgPHtrOqXqNvZoEUKnhMp0eFWIOemjbAig/5OY4c1UBUf7jrbrOgdVE92mNDwm/gS4V4sMguPmDakcmAt2O25U/xY+w2meBdakj7svob/buU2LZtDf6l4wi0j/DhGc5QaOTuya8ok4ECH4KIUQICIS8w6aLMthjnZpJv7fwQ1TkEOtqHtW2fhTM/FQQ3dkT/IIHxIe5kJaXxVEBnHajObMCJ+0iMwBMbYdYseODZVvlQc099alxlyiPvQ/waiTDA0mVX8j45Y4N6W9WOg0ZLl4tqTThltzjQZKol1Y1V+wh4Qigki5Om65f3nvHhI+VwsdbfqGot8/IdpzfqS X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7686bc1f-819c-4ebe-ad83-08dbb94aa0ca X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:57:18.2065 (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: AM8P250MB0215 Subject: [FFmpeg-devel] [PATCH 12/42] avcodec/decode: Use RefStruct API for hwaccel_picture_private 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: 2QDQCcYBNKJM Avoids allocations and therefore error checks: Syncing hwaccel_picture_private across threads can't fail any more. Also gets rid of an unnecessary pointer in structures and in the parameter list of ff_hwaccel_frame_priv_alloc(). Signed-off-by: Andreas Rheinhardt --- libavcodec/av1dec.c | 15 ++++----------- libavcodec/av1dec.h | 4 +--- libavcodec/decode.c | 28 ++++++---------------------- libavcodec/decode.h | 10 +++------- libavcodec/h264_picture.c | 19 +++++-------------- libavcodec/h264_slice.c | 3 +-- libavcodec/h264dec.h | 1 - libavcodec/hevc_refs.c | 7 +++---- libavcodec/hevcdec.c | 11 ++--------- libavcodec/hevcdec.h | 3 +-- libavcodec/hwaccel_internal.h | 3 ++- libavcodec/mpegpicture.c | 18 +++++------------- libavcodec/mpegpicture.h | 1 - libavcodec/vp8.c | 14 ++++---------- libavcodec/vp8.h | 4 +--- libavcodec/vp9.c | 15 +++++---------- libavcodec/vp9shared.h | 3 +-- libavcodec/vulkan_av1.c | 9 +++------ libavcodec/vulkan_h264.c | 9 +++------ libavcodec/vulkan_hevc.c | 9 +++------ 20 files changed, 53 insertions(+), 133 deletions(-) diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c index 87056520dd..c02408548c 100644 --- a/libavcodec/av1dec.c +++ b/libavcodec/av1dec.c @@ -27,7 +27,6 @@ #include "libavutil/opt.h" #include "avcodec.h" #include "av1_parse.h" -#include "decode.h" #include "av1dec.h" #include "atsc_a53.h" #include "bytestream.h" @@ -640,8 +639,7 @@ static int get_pixel_format(AVCodecContext *avctx) static void av1_frame_unref(AVCodecContext *avctx, AV1Frame *f) { ff_thread_release_buffer(avctx, f->f); - av_buffer_unref(&f->hwaccel_priv_buf); - f->hwaccel_picture_private = NULL; + ff_refstruct_unref(&f->hwaccel_picture_private); ff_refstruct_unref(&f->header_ref); f->raw_frame_header = NULL; f->spatial_id = f->temporal_id = 0; @@ -666,12 +664,8 @@ static int av1_frame_ref(AVCodecContext *avctx, AV1Frame *dst, const AV1Frame *s if (ret < 0) goto fail; - if (src->hwaccel_picture_private) { - dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf); - if (!dst->hwaccel_priv_buf) - goto fail; - dst->hwaccel_picture_private = dst->hwaccel_priv_buf->data; - } + ff_refstruct_replace(&dst->hwaccel_picture_private, + src->hwaccel_picture_private); dst->spatial_id = src->spatial_id; dst->temporal_id = src->temporal_id; @@ -915,8 +909,7 @@ static int av1_frame_alloc(AVCodecContext *avctx, AV1Frame *f) break; } - ret = ff_hwaccel_frame_priv_alloc(avctx, &f->hwaccel_picture_private, - &f->hwaccel_priv_buf); + ret = ff_hwaccel_frame_priv_alloc(avctx, &f->hwaccel_picture_private); if (ret < 0) goto fail; diff --git a/libavcodec/av1dec.h b/libavcodec/av1dec.h index acbeec4af3..b6a0c08e48 100644 --- a/libavcodec/av1dec.h +++ b/libavcodec/av1dec.h @@ -24,7 +24,6 @@ #include #include "libavutil/fifo.h" -#include "libavutil/buffer.h" #include "libavutil/frame.h" #include "libavutil/pixfmt.h" #include "avcodec.h" @@ -35,8 +34,7 @@ typedef struct AV1Frame { AVFrame *f; - AVBufferRef *hwaccel_priv_buf; - void *hwaccel_picture_private; + void *hwaccel_picture_private; ///< RefStruct reference AV1RawOBU *header_ref; ///< RefStruct reference backing raw_frame_header. AV1RawFrameHeader *raw_frame_header; diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 169ee79acd..7abfe7f0ce 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -28,18 +28,13 @@ #endif #include "libavutil/avassert.h" -#include "libavutil/avstring.h" -#include "libavutil/bprint.h" #include "libavutil/channel_layout.h" #include "libavutil/common.h" #include "libavutil/emms.h" -#include "libavutil/fifo.h" #include "libavutil/frame.h" #include "libavutil/hwcontext.h" #include "libavutil/imgutils.h" #include "libavutil/internal.h" -#include "libavutil/intmath.h" -#include "libavutil/opt.h" #include "avcodec.h" #include "avcodec_internal.h" @@ -51,6 +46,7 @@ #include "hwconfig.h" #include "internal.h" #include "packet_internal.h" +#include "refstruct.h" #include "thread.h" typedef struct DecodeContext { @@ -1790,34 +1786,22 @@ int ff_copy_palette(void *dst, const AVPacket *src, void *logctx) return 0; } -int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private, - AVBufferRef **hwaccel_priv_buf) +int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private) { const FFHWAccel *hwaccel = ffhwaccel(avctx->hwaccel); - AVBufferRef *ref; AVHWFramesContext *frames_ctx; - uint8_t *data; if (!hwaccel || !hwaccel->frame_priv_data_size) return 0; av_assert0(!*hwaccel_picture_private); - data = av_mallocz(hwaccel->frame_priv_data_size); - if (!data) - return AVERROR(ENOMEM); frames_ctx = (AVHWFramesContext *)avctx->hw_frames_ctx->data; - - ref = av_buffer_create(data, hwaccel->frame_priv_data_size, - hwaccel->free_frame_priv, - frames_ctx->device_ctx, 0); - if (!ref) { - av_free(data); + *hwaccel_picture_private = ff_refstruct_alloc_ext(hwaccel->frame_priv_data_size, 0, + frames_ctx->device_ctx, + hwaccel->free_frame_priv); + if (!*hwaccel_picture_private) return AVERROR(ENOMEM); - } - - *hwaccel_priv_buf = ref; - *hwaccel_picture_private = ref->data; return 0; } diff --git a/libavcodec/decode.h b/libavcodec/decode.h index a52152e4a7..ce97c53933 100644 --- a/libavcodec/decode.h +++ b/libavcodec/decode.h @@ -21,7 +21,6 @@ #ifndef AVCODEC_DECODE_H #define AVCODEC_DECODE_H -#include "libavutil/buffer.h" #include "libavutil/frame.h" #include "libavutil/hwcontext.h" @@ -141,16 +140,13 @@ int ff_side_data_update_matrix_encoding(AVFrame *frame, /** * Allocate a hwaccel frame private data if the provided avctx - * uses a hwaccel method that needs it. The private data will - * be refcounted via the AVBuffer API (if allocated). + * uses a hwaccel method that needs it. The returned data is + * a RefStruct reference (if allocated). * * @param avctx The codec context * @param hwaccel_picture_private Pointer to return hwaccel_picture_private - * @param hwaccel_priv_buf Pointer to return the AVBufferRef owning - * hwaccel_picture_private * @return 0 on success, < 0 on error */ -int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private, - AVBufferRef **hwaccel_priv_buf); +int ff_hwaccel_frame_priv_alloc(AVCodecContext *avctx, void **hwaccel_picture_private); #endif /* AVCODEC_DECODE_H */ diff --git a/libavcodec/h264_picture.c b/libavcodec/h264_picture.c index 25d0d96ddb..9353e4b445 100644 --- a/libavcodec/h264_picture.c +++ b/libavcodec/h264_picture.c @@ -46,7 +46,7 @@ void ff_h264_unref_picture(H264Context *h, H264Picture *pic) ff_thread_release_ext_buffer(h->avctx, &pic->tf); ff_thread_release_buffer(h->avctx, pic->f_grain); - av_buffer_unref(&pic->hwaccel_priv_buf); + ff_refstruct_unref(&pic->hwaccel_picture_private); av_buffer_unref(&pic->qscale_table_buf); av_buffer_unref(&pic->mb_type_buf); @@ -129,14 +129,8 @@ int ff_h264_ref_picture(H264Context *h, H264Picture *dst, H264Picture *src) } } - if (src->hwaccel_picture_private) { - dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf); - if (!dst->hwaccel_priv_buf) { - ret = AVERROR(ENOMEM); - goto fail; - } - dst->hwaccel_picture_private = dst->hwaccel_priv_buf->data; - } + ff_refstruct_replace(&dst->hwaccel_picture_private, + src->hwaccel_picture_private); ret = av_buffer_replace(&dst->decode_error_flags, src->decode_error_flags); if (ret < 0) @@ -185,11 +179,8 @@ int ff_h264_replace_picture(H264Context *h, H264Picture *dst, const H264Picture goto fail; } - ret = av_buffer_replace(&dst->hwaccel_priv_buf, src->hwaccel_priv_buf); - if (ret < 0) - goto fail; - - dst->hwaccel_picture_private = src->hwaccel_picture_private; + ff_refstruct_replace(&dst->hwaccel_picture_private, + src->hwaccel_picture_private); ret = av_buffer_replace(&dst->decode_error_flags, src->decode_error_flags); if (ret < 0) diff --git a/libavcodec/h264_slice.c b/libavcodec/h264_slice.c index 632f5b23b2..6df80c9522 100644 --- a/libavcodec/h264_slice.c +++ b/libavcodec/h264_slice.c @@ -206,8 +206,7 @@ static int alloc_picture(H264Context *h, H264Picture *pic) goto fail; } - ret = ff_hwaccel_frame_priv_alloc(h->avctx, &pic->hwaccel_picture_private, - &pic->hwaccel_priv_buf); + ret = ff_hwaccel_frame_priv_alloc(h->avctx, &pic->hwaccel_picture_private); if (ret < 0) goto fail; diff --git a/libavcodec/h264dec.h b/libavcodec/h264dec.h index 513856749a..7436e0a54f 100644 --- a/libavcodec/h264dec.h +++ b/libavcodec/h264dec.h @@ -117,7 +117,6 @@ typedef struct H264Picture { AVBufferRef *mb_type_buf; uint32_t *mb_type; - AVBufferRef *hwaccel_priv_buf; void *hwaccel_picture_private; ///< hardware accelerator private data AVBufferRef *ref_index_buf[2]; diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c index c5c1203ef8..8f49704b54 100644 --- a/libavcodec/hevc_refs.c +++ b/libavcodec/hevc_refs.c @@ -27,6 +27,7 @@ #include "thread.h" #include "hevc.h" #include "hevcdec.h" +#include "refstruct.h" #include "threadframe.h" void ff_hevc_unref_frame(HEVCContext *s, HEVCFrame *frame, int flags) @@ -51,8 +52,7 @@ void ff_hevc_unref_frame(HEVCContext *s, HEVCFrame *frame, int flags) frame->collocated_ref = NULL; - av_buffer_unref(&frame->hwaccel_priv_buf); - frame->hwaccel_picture_private = NULL; + ff_refstruct_unref(&frame->hwaccel_picture_private); } } @@ -118,8 +118,7 @@ static HEVCFrame *alloc_frame(HEVCContext *s) (s->sei.picture_timing.picture_struct == AV_PICTURE_STRUCTURE_BOTTOM_FIELD)) frame->frame->flags |= AV_FRAME_FLAG_INTERLACED; - ret = ff_hwaccel_frame_priv_alloc(s->avctx, &frame->hwaccel_picture_private, - &frame->hwaccel_priv_buf); + ret = ff_hwaccel_frame_priv_alloc(s->avctx, &frame->hwaccel_picture_private); if (ret < 0) goto fail; diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 44a9680415..8316a815e7 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -28,7 +28,6 @@ #include "libavutil/attributes.h" #include "libavutil/avstring.h" #include "libavutil/common.h" -#include "libavutil/display.h" #include "libavutil/film_grain_params.h" #include "libavutil/internal.h" #include "libavutil/md5.h" @@ -37,13 +36,11 @@ #include "libavutil/timecode.h" #include "bswapdsp.h" -#include "bytestream.h" #include "cabac_functions.h" #include "codec_internal.h" #include "decode.h" #include "golomb.h" #include "hevc.h" -#include "hevc_data.h" #include "hevc_parse.h" #include "hevcdec.h" #include "hwaccel_internal.h" @@ -3416,12 +3413,8 @@ static int hevc_ref_frame(HEVCContext *s, HEVCFrame *dst, HEVCFrame *src) dst->flags = src->flags; dst->sequence = src->sequence; - if (src->hwaccel_picture_private) { - dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf); - if (!dst->hwaccel_priv_buf) - goto fail; - dst->hwaccel_picture_private = dst->hwaccel_priv_buf->data; - } + ff_refstruct_replace(&dst->hwaccel_picture_private, + src->hwaccel_picture_private); return 0; fail: diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h index 94609e4699..1d29fc24d7 100644 --- a/libavcodec/hevcdec.h +++ b/libavcodec/hevcdec.h @@ -419,8 +419,7 @@ typedef struct HEVCFrame { AVBufferRef *rpl_tab_buf; AVBufferRef *rpl_buf; - AVBufferRef *hwaccel_priv_buf; - void *hwaccel_picture_private; + void *hwaccel_picture_private; ///< RefStruct reference /** * A sequence counter, so that old frames are output first diff --git a/libavcodec/hwaccel_internal.h b/libavcodec/hwaccel_internal.h index edfe283150..057b07323d 100644 --- a/libavcodec/hwaccel_internal.h +++ b/libavcodec/hwaccel_internal.h @@ -26,6 +26,7 @@ #include #include "avcodec.h" +#include "refstruct.h" #define HWACCEL_CAP_ASYNC_SAFE (1 << 0) #define HWACCEL_CAP_THREAD_SAFE (1 << 1) @@ -154,7 +155,7 @@ typedef struct FFHWAccel { * @param hwctx a pointer to an AVHWDeviceContext. * @param data the per-frame hardware accelerator private data to be freed. */ - void (*free_frame_priv)(void *hwctx, uint8_t *data); + void (*free_frame_priv)(FFRefStructOpaque hwctx, void *data); /** * Callback to flush the hwaccel state. diff --git a/libavcodec/mpegpicture.c b/libavcodec/mpegpicture.c index b7c804c8ec..4126756e9b 100644 --- a/libavcodec/mpegpicture.c +++ b/libavcodec/mpegpicture.c @@ -27,11 +27,11 @@ #include "avcodec.h" #include "encode.h" -#include "internal.h" #include "decode.h" #include "motion_est.h" #include "mpegpicture.h" #include "mpegutils.h" +#include "refstruct.h" #include "threadframe.h" static void av_noinline free_picture_tables(Picture *pic) @@ -171,8 +171,7 @@ static int alloc_frame_buffer(AVCodecContext *avctx, Picture *pic, pic->f->height = avctx->height; } - ret = ff_hwaccel_frame_priv_alloc(avctx, &pic->hwaccel_picture_private, - &pic->hwaccel_priv_buf); + ret = ff_hwaccel_frame_priv_alloc(avctx, &pic->hwaccel_picture_private); if (ret < 0) return ret; @@ -316,12 +315,11 @@ void ff_mpeg_unref_picture(AVCodecContext *avctx, Picture *pic) else if (pic->f) av_frame_unref(pic->f); - av_buffer_unref(&pic->hwaccel_priv_buf); + ff_refstruct_unref(&pic->hwaccel_picture_private); if (pic->needs_realloc) free_picture_tables(pic); - pic->hwaccel_picture_private = NULL; pic->field_picture = 0; pic->b_frame_score = 0; pic->needs_realloc = 0; @@ -380,14 +378,8 @@ int ff_mpeg_ref_picture(AVCodecContext *avctx, Picture *dst, Picture *src) if (ret < 0) goto fail; - if (src->hwaccel_picture_private) { - dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf); - if (!dst->hwaccel_priv_buf) { - ret = AVERROR(ENOMEM); - goto fail; - } - dst->hwaccel_picture_private = dst->hwaccel_priv_buf->data; - } + ff_refstruct_replace(&dst->hwaccel_picture_private, + src->hwaccel_picture_private); dst->field_picture = src->field_picture; dst->b_frame_score = src->b_frame_score; diff --git a/libavcodec/mpegpicture.h b/libavcodec/mpegpicture.h index 7919aa402c..477b3ac535 100644 --- a/libavcodec/mpegpicture.h +++ b/libavcodec/mpegpicture.h @@ -66,7 +66,6 @@ typedef struct Picture { int alloc_mb_height; ///< mb_height used to allocate tables int alloc_mb_stride; ///< mb_stride used to allocate tables - AVBufferRef *hwaccel_priv_buf; void *hwaccel_picture_private; ///< Hardware accelerator private data int field_picture; ///< whether or not the picture was encoded in separate fields diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c index db325dc90b..4a51c551b8 100644 --- a/libavcodec/vp8.c +++ b/libavcodec/vp8.c @@ -108,8 +108,7 @@ static int vp8_alloc_frame(VP8Context *s, VP8Frame *f, int ref) return ret; if (!(f->seg_map = ff_refstruct_allocz(s->mb_width * s->mb_height))) goto fail; - ret = ff_hwaccel_frame_priv_alloc(s->avctx, &f->hwaccel_picture_private, - &f->hwaccel_priv_buf); + ret = ff_hwaccel_frame_priv_alloc(s->avctx, &f->hwaccel_picture_private); if (ret < 0) goto fail; @@ -124,8 +123,7 @@ fail: static void vp8_release_frame(VP8Context *s, VP8Frame *f) { ff_refstruct_unref(&f->seg_map); - av_buffer_unref(&f->hwaccel_priv_buf); - f->hwaccel_picture_private = NULL; + ff_refstruct_unref(&f->hwaccel_picture_private); ff_thread_release_ext_buffer(s->avctx, &f->tf); } @@ -139,12 +137,8 @@ static int vp8_ref_frame(VP8Context *s, VP8Frame *dst, const VP8Frame *src) if ((ret = ff_thread_ref_frame(&dst->tf, &src->tf)) < 0) return ret; ff_refstruct_replace(&dst->seg_map, src->seg_map); - if (src->hwaccel_picture_private) { - dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf); - if (!dst->hwaccel_priv_buf) - return AVERROR(ENOMEM); - dst->hwaccel_picture_private = dst->hwaccel_priv_buf->data; - } + ff_refstruct_replace(&dst->hwaccel_picture_private, + src->hwaccel_picture_private); return 0; } diff --git a/libavcodec/vp8.h b/libavcodec/vp8.h index cb752d4498..eb9fa2f166 100644 --- a/libavcodec/vp8.h +++ b/libavcodec/vp8.h @@ -28,7 +28,6 @@ #include -#include "libavutil/buffer.h" #include "libavutil/mem_internal.h" #include "libavutil/thread.h" @@ -154,8 +153,7 @@ typedef struct VP8Frame { ThreadFrame tf; uint8_t *seg_map; ///< RefStruct reference - AVBufferRef *hwaccel_priv_buf; - void *hwaccel_picture_private; + void *hwaccel_picture_private; ///< RefStruct reference } VP8Frame; #define MAX_THREADS 8 diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 3cc27aa812..c9cc81ec94 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -30,6 +30,7 @@ #include "hwaccel_internal.h" #include "hwconfig.h" #include "profiles.h" +#include "refstruct.h" #include "thread.h" #include "threadframe.h" #include "pthread_internal.h" @@ -100,9 +101,8 @@ static void vp9_frame_unref(AVCodecContext *avctx, VP9Frame *f) { ff_thread_release_ext_buffer(avctx, &f->tf); av_buffer_unref(&f->extradata); - av_buffer_unref(&f->hwaccel_priv_buf); + ff_refstruct_unref(&f->hwaccel_picture_private); f->segmentation_map = NULL; - f->hwaccel_picture_private = NULL; } static int vp9_frame_alloc(AVCodecContext *avctx, VP9Frame *f) @@ -135,8 +135,7 @@ static int vp9_frame_alloc(AVCodecContext *avctx, VP9Frame *f) f->segmentation_map = f->extradata->data; f->mv = (VP9mvrefPair *) (f->extradata->data + sz); - ret = ff_hwaccel_frame_priv_alloc(avctx, &f->hwaccel_picture_private, - &f->hwaccel_priv_buf); + ret = ff_hwaccel_frame_priv_alloc(avctx, &f->hwaccel_picture_private); if (ret < 0) goto fail; @@ -163,12 +162,8 @@ static int vp9_frame_ref(AVCodecContext *avctx, VP9Frame *dst, VP9Frame *src) dst->mv = src->mv; dst->uses_2pass = src->uses_2pass; - if (src->hwaccel_picture_private) { - dst->hwaccel_priv_buf = av_buffer_ref(src->hwaccel_priv_buf); - if (!dst->hwaccel_priv_buf) - goto fail; - dst->hwaccel_picture_private = dst->hwaccel_priv_buf->data; - } + ff_refstruct_replace(&dst->hwaccel_picture_private, + src->hwaccel_picture_private); return 0; diff --git a/libavcodec/vp9shared.h b/libavcodec/vp9shared.h index 543a496df8..e54f23544e 100644 --- a/libavcodec/vp9shared.h +++ b/libavcodec/vp9shared.h @@ -69,8 +69,7 @@ typedef struct VP9Frame { VP9mvrefPair *mv; int uses_2pass; - AVBufferRef *hwaccel_priv_buf; - void *hwaccel_picture_private; + void *hwaccel_picture_private; ///< RefStruct reference } VP9Frame; enum BlockLevel { diff --git a/libavcodec/vulkan_av1.c b/libavcodec/vulkan_av1.c index b1373722ef..7c8dda7798 100644 --- a/libavcodec/vulkan_av1.c +++ b/libavcodec/vulkan_av1.c @@ -536,10 +536,10 @@ static int vk_av1_end_frame(AVCodecContext *avctx) return ff_vk_decode_frame(avctx, pic->f, vp, rav, rvp); } -static void vk_av1_free_frame_priv(void *_hwctx, uint8_t *data) +static void vk_av1_free_frame_priv(FFRefStructOpaque _hwctx, void *data) { - AVHWDeviceContext *hwctx = _hwctx; - AV1VulkanDecodePicture *ap = (AV1VulkanDecodePicture *)data; + AVHWDeviceContext *hwctx = _hwctx.nc; + AV1VulkanDecodePicture *ap = data; /* Workaround for a spec issue. */ if (ap->frame_id_set) @@ -547,9 +547,6 @@ static void vk_av1_free_frame_priv(void *_hwctx, uint8_t *data) /* Free frame resources, this also destroys the session parameters. */ ff_vk_decode_free_frame(hwctx, &ap->vp); - - /* Free frame context */ - av_free(ap); } const FFHWAccel ff_av1_vulkan_hwaccel = { diff --git a/libavcodec/vulkan_h264.c b/libavcodec/vulkan_h264.c index cdc2c7fe30..2cb54bb1ff 100644 --- a/libavcodec/vulkan_h264.c +++ b/libavcodec/vulkan_h264.c @@ -530,16 +530,13 @@ static int vk_h264_end_frame(AVCodecContext *avctx) return ff_vk_decode_frame(avctx, pic->f, vp, rav, rvp); } -static void vk_h264_free_frame_priv(void *_hwctx, uint8_t *data) +static void vk_h264_free_frame_priv(FFRefStructOpaque _hwctx, void *data) { - AVHWDeviceContext *hwctx = _hwctx; - H264VulkanDecodePicture *hp = (H264VulkanDecodePicture *)data; + AVHWDeviceContext *hwctx = _hwctx.nc; + H264VulkanDecodePicture *hp = data; /* Free frame resources, this also destroys the session parameters. */ ff_vk_decode_free_frame(hwctx, &hp->vp); - - /* Free frame context */ - av_free(hp); } const FFHWAccel ff_h264_vulkan_hwaccel = { diff --git a/libavcodec/vulkan_hevc.c b/libavcodec/vulkan_hevc.c index 395cbd3008..d5116bb48c 100644 --- a/libavcodec/vulkan_hevc.c +++ b/libavcodec/vulkan_hevc.c @@ -901,16 +901,13 @@ static int vk_hevc_end_frame(AVCodecContext *avctx) return ff_vk_decode_frame(avctx, pic->frame, vp, rav, rvp); } -static void vk_hevc_free_frame_priv(void *_hwctx, uint8_t *data) +static void vk_hevc_free_frame_priv(FFRefStructOpaque _hwctx, void *data) { - AVHWDeviceContext *hwctx = _hwctx; - HEVCVulkanDecodePicture *hp = (HEVCVulkanDecodePicture *)data; + AVHWDeviceContext *hwctx = _hwctx.nc; + HEVCVulkanDecodePicture *hp = data; /* Free frame resources */ ff_vk_decode_free_frame(hwctx, &hp->vp); - - /* Free frame context */ - av_free(hp); } const FFHWAccel ff_hevc_vulkan_hwaccel = { From patchwork Tue Sep 19 19:57:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43825 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp186470pzb; Tue, 19 Sep 2023 12:59:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHKm3SDQla8FPDeXmpouuZKgYZL17lp3Vfi5/zGFso1fPSUzr4wbY9ztgPKC6Ibqd/kqoH6 X-Received: by 2002:a05:6402:88d:b0:523:102f:3cdd with SMTP id e13-20020a056402088d00b00523102f3cddmr380409edy.19.1695153584533; Tue, 19 Sep 2023 12:59:44 -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 co17-20020a0564020c1100b00530cad389besi6283083edb.408.2023.09.19.12.59.44; Tue, 19 Sep 2023 12:59:44 -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=bacA6Yzw; 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 E54BA68C98A; Tue, 19 Sep 2023 22:57:59 +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-db8eur05olkn2057.outbound.protection.outlook.com [40.92.89.57]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CA5AB68C986 for ; Tue, 19 Sep 2023 22:57:58 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mYpVOAcglBo77YcaEq5OdyO6tdgijAIqtVzG51vFYaDZAFylwpPWtEprYWmJkBGZR+s12bgcTOSOUY6/NSnmHPFfAtyLl61iZzH4ycJcni/yTJkMSRVKzwXWSDiiAGEcfHywkL4+NH7j4b2ZcKqEQ23wV04bc0iKU/k8CEWKPSKp7ib8e2GmVSrJcuhuRZOo45P+7I5wINK40y5UZTO/F7kAp5TsWOBciGlEFJGkaS/5BRjZMucxxr79vL+18YYfo++gYf8n71tNO4vjKxSKtGYg7ROutkfotf8jNYq5nvNoaIUkf8u3wID8GPLKrzhgE7SdPDmvGtg+6vwb31Dr6Q== 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=L5eyfY14GKGLZC82WvBJv2zW51ELJun4nbzlYlO2moQ=; b=b0bltRZCCB6COd9t/9tNGAtV0yOrjDG3vFG++ST0Co1gXiyGzoMuYrOQMaa3YzIGxW0sl35ZqNiscSfXTq2mSmXIv+A4SWSwfwaoxKWNK9DIg0WtO/nRm6AGua3FKUNsEEHNRoMCBVpMluA675I80qG+ayKeYpOCsGT12GIv6A1zgEzV2MY+gF6+M7ECKGD25fBzUIZetpMaj9wHMcXKZtZ9TWrkOLaWD2nrVktGzt/DON2UKXGwPkb24f1orOgfpI2ZvQeYABUHfXoGek3tXaBAuS+AW9ZBpOZH69vmb1HQx2smRXB99vp08r9gvvbJtB2an3mKfxfRhWNf5OP4Bw== 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=L5eyfY14GKGLZC82WvBJv2zW51ELJun4nbzlYlO2moQ=; b=bacA6Yzw5zHpZVYCjbMd4o6IodEfvRtT+GZI4Wk/FSHM+GukPsgxcfC4QBwVHzrj7F9Pd2LxTiYinQ9d7j3TtSrJs4uykPQdxDZVdX73w4AHTNFxAZQboSC86sjXor1NHytbEpbk12hKbEeSAPPxAHBsHWuaU4aHp4GFN1rZjJ24fOAr0VXvnfQgdfB7OB3B5m1sC6M/r4L9z/01+y84YYoUJvqNEyPDAAFid0yqOPvijyl4FNfVOxP0XiRjcK1V0g0WY6o0zbgnFwIGDIdwbpW+4Wi0Zys9Mhpnef/kpkPXod5lUbsOZTV71rbEmUQtjzNmNxUMyMTfRFCmbDF3+w== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AM8P250MB0215.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:326::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:57:56 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:57:56 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:11 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [m3vm79vp0ksMMPwJcGkWFEBisVEPYiYM] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-19-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AM8P250MB0215:EE_ X-MS-Office365-Filtering-Correlation-Id: 111e0432-3850-42a1-de2a-08dbb94ab75c X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 0LaVr+3PKDqB405LzoWmq5aOC86kAhkQ5zWi4oDKHDRICL7j/XXRhiZlr0GJ+Q97hwZ+La3Pi8m5Kyashmj+MUDUmziINPOLIsahGZ25Qm+byOOI2nezxevw6ksjBxniyoa7KuVfWrMVFCyfu7ePPkkUgjobd1+wwEvciJotecYHoYUXU5UbB7HREhDAeJuTTjw8EBJ0M3BqNcWyuvFBYjtQMXqr2/Q+NvKwMaJj2yW77tnb+EQ3KTVFoi5RzymnTPHxlLKb/FwfknO3yfC8E9gDU+WMBLyC0s8mYGIlYVSBNG+yo4gPVV97D/72DFvXSLgppg1j0B3bnvFi99R+SW23y2oKq8aYAfTXj1bCf2dqUKi7p3L4NgXn+hptu9r42RYo+QJZv9vWmUkPRR6lkxmM/nvqj/D8vIbHTJOf/kpgJHfUh2WdM85E0u5NXGXwqSjyQo/5+52gtJtAQjn1w9oBxQE2t70RXyTwwmfbqMox0WxS0rx4Awy7nTNPwFOCUc97DafmHOp2/PW5fk8JLX1vpGofU9IVfuTIM4WROv7/Nfcn1txaehfpouaVEu0G/UPo1tgGA0xmxeQ/UOu3S/hZRUvvq1z+u4JMOIEqYVB02Y7nYO1EsmC27z4llVXW X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2vUuZD+J2sfjyUaAI951AvbvDxgLdSuIhgswvgVvMuCLrMv66N0zQiCKGGSn5umLU6AA7VlnTZJloPyGShx+c85LfapQmbN0CZ6rt5rSFeoUyL+CpkVrJBgTHgh6nIX5wenguzd/vDn5QFZ4wg10MJ1J4Yzd8bKfDvVQKxiE9g8nuz1irjH+POuvNGTfar02jUOGZYmvQeiJOI6bnp7qQDS25bk4NUnTOYdWUb3QEBhBHqiDSG8aoksdpZGo6DvklIVaAmi4cEJL4pRrQ1FO47w0/cxRfj5D2aiM9RaX1fdDs9Zj27Br6Fdh4KhDujY0eOrSKpEbkFAsHTGnZ862jA3kMCPxfI8mIc5NUX0hhQEHOKPQe8TH9BJTK7QYsmqhxYnDb9GJNxT2m9U/uSKHYevzfSI4qbGezNgNoqs+XuIw3+K6g85bPTKIsdyRj5MKFh4E/2+bB3n78Hq0eqhqfBF3A/kteNt+v/wPj3PO3PEhrhVcJfzzgFckCaMMX4QaR4hzvb17HUTnf3Y2RgfFmO1n8caxe+/qSAxYvtNh6scFmK32XDJ08BbQeZvf7ZklHEdE98wcE3PZvq5eVGWyxFgiLC75HKnG6L13xbxL7+C3sAIJn43yZompOnFHdXpw4MtUK5m4MnCv+wYGCmydIcGW9Q93TtBJ9LR5sR6nnwfDeBmAam/EUkSAahm4eU570J4V6lMBXiDAENlA4z2eWocbT608UOf/0TIvGpoGEOWZsENoMdQvygB4zwTZRX6fnkvZBqFnlXFpFzEAaRcnuywvZFj2DP1bR9R8u8l1vufAsGeww/f8hrw+aZRIGrnaBc+fctv9zJ5yqQLoCNKDqg06ptUbjtZiOo1oq4TZJhG3DQL3zUFZjIMsfk3T0siKPbOZsMuRq80jbZeTHYZzl7JsUQFKM7V5xodnXFP3sgFmk8yaHYo/SKh7faAGB4hqfjTYxg/RSQtsqxa5rSwbCx44hrbV1UxCM0C7PPQS7vt+jfhydyG+JY2FzIsyOiP6YxzOY1Gufegu1WEwTGQToHHoXRQlC8MHuJsIjvxxXbyNY3UJO5eamSlyIy8bZmibVU875ETJMzNIZLM6K7ra3D2YAjDcSQQOy2ap4r1yLHuq30KuSiryLf+aVTzdHhIKYj/Bzye8hHGrcTCbuY1yfQltMbkRGWqZmry+gKxe7WGVeLQ/5jQDsjxrf5etuUNFamOUUiTRJ4uBe/eKJw+6nCBD4Mrc5k41fNLfB1dIqgAEL6TbabGpdgRYemE3Fg0S X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 111e0432-3850-42a1-de2a-08dbb94ab75c X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:57:56.0331 (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: AM8P250MB0215 Subject: [FFmpeg-devel] [PATCH 19/42] avcodec/hevcdec: Use RefStruct-pool API instead of AVBufferPool API 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: ZoQ7exStMA53 It involves less allocations and therefore has the nice property that deriving a reference from a reference can't fail, simplifying hevc_ref_frame(). Signed-off-by: Andreas Rheinhardt --- libavcodec/hevc_refs.c | 16 ++++++---------- libavcodec/hevcdec.c | 25 ++++++------------------- libavcodec/hevcdec.h | 10 ++++------ 3 files changed, 16 insertions(+), 35 deletions(-) diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c index ae464e8e6d..fa53b273c7 100644 --- a/libavcodec/hevc_refs.c +++ b/libavcodec/hevc_refs.c @@ -42,13 +42,11 @@ void ff_hevc_unref_frame(HEVCContext *s, HEVCFrame *frame, int flags) ff_thread_release_buffer(s->avctx, frame->frame_grain); frame->needs_fg = 0; - av_buffer_unref(&frame->tab_mvf_buf); - frame->tab_mvf = NULL; + ff_refstruct_unref(&frame->tab_mvf); ff_refstruct_unref(&frame->rpl); frame->nb_rpl_elems = 0; - av_buffer_unref(&frame->rpl_tab_buf); - frame->rpl_tab = NULL; + ff_refstruct_unref(&frame->rpl_tab); frame->refPicList = NULL; frame->collocated_ref = NULL; @@ -101,15 +99,13 @@ static HEVCFrame *alloc_frame(HEVCContext *s) goto fail; frame->nb_rpl_elems = s->pkt.nb_nals; - frame->tab_mvf_buf = av_buffer_pool_get(s->tab_mvf_pool); - if (!frame->tab_mvf_buf) + frame->tab_mvf = ff_refstruct_pool_get(s->tab_mvf_pool); + if (!frame->tab_mvf) goto fail; - frame->tab_mvf = (MvField *)frame->tab_mvf_buf->data; - frame->rpl_tab_buf = av_buffer_pool_get(s->rpl_tab_pool); - if (!frame->rpl_tab_buf) + frame->rpl_tab = ff_refstruct_pool_get(s->rpl_tab_pool); + if (!frame->rpl_tab) goto fail; - frame->rpl_tab = (RefPicListTab **)frame->rpl_tab_buf->data; frame->ctb_count = s->ps.sps->ctb_width * s->ps.sps->ctb_height; for (j = 0; j < frame->ctb_count; j++) frame->rpl_tab[j] = frame->rpl; diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 44561de821..23cc543f82 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -86,8 +86,8 @@ static void pic_arrays_free(HEVCContext *s) av_freep(&s->sh.size); av_freep(&s->sh.offset); - av_buffer_pool_uninit(&s->tab_mvf_pool); - av_buffer_pool_uninit(&s->rpl_tab_pool); + ff_refstruct_pool_uninit(&s->tab_mvf_pool); + ff_refstruct_pool_uninit(&s->rpl_tab_pool); } /* allocate arrays that depend on frame dimensions */ @@ -133,10 +133,8 @@ static int pic_arrays_init(HEVCContext *s, const HEVCSPS *sps) if (!s->horizontal_bs || !s->vertical_bs) goto fail; - s->tab_mvf_pool = av_buffer_pool_init(min_pu_size * sizeof(MvField), - av_buffer_allocz); - s->rpl_tab_pool = av_buffer_pool_init(ctb_count * sizeof(RefPicListTab), - av_buffer_allocz); + s->tab_mvf_pool = ff_refstruct_pool_alloc(min_pu_size * sizeof(MvField), 0); + s->rpl_tab_pool = ff_refstruct_pool_alloc(ctb_count * sizeof(RefPicListTab), 0); if (!s->tab_mvf_pool || !s->rpl_tab_pool) goto fail; @@ -3394,16 +3392,8 @@ static int hevc_ref_frame(HEVCContext *s, HEVCFrame *dst, HEVCFrame *src) dst->needs_fg = 1; } - dst->tab_mvf_buf = av_buffer_ref(src->tab_mvf_buf); - if (!dst->tab_mvf_buf) - goto fail; - dst->tab_mvf = src->tab_mvf; - - dst->rpl_tab_buf = av_buffer_ref(src->rpl_tab_buf); - if (!dst->rpl_tab_buf) - goto fail; - dst->rpl_tab = src->rpl_tab; - + dst->tab_mvf = ff_refstruct_ref(src->tab_mvf); + dst->rpl_tab = ff_refstruct_ref(src->rpl_tab); dst->rpl = ff_refstruct_ref(src->rpl); dst->nb_rpl_elems = src->nb_rpl_elems; @@ -3416,9 +3406,6 @@ static int hevc_ref_frame(HEVCContext *s, HEVCFrame *dst, HEVCFrame *src) src->hwaccel_picture_private); return 0; -fail: - ff_hevc_unref_frame(s, dst, ~0); - return AVERROR(ENOMEM); } static av_cold int hevc_decode_free(AVCodecContext *avctx) diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h index c13406f0a8..edf2f188cf 100644 --- a/libavcodec/hevcdec.h +++ b/libavcodec/hevcdec.h @@ -408,15 +408,13 @@ typedef struct HEVCFrame { AVFrame *frame_grain; ThreadFrame tf; int needs_fg; /* 1 if grain needs to be applied by the decoder */ - MvField *tab_mvf; + MvField *tab_mvf; ///< RefStruct reference RefPicList *refPicList; - RefPicListTab **rpl_tab; + RefPicListTab **rpl_tab; ///< RefStruct reference int ctb_count; int poc; struct HEVCFrame *collocated_ref; - AVBufferRef *tab_mvf_buf; - AVBufferRef *rpl_tab_buf; RefPicListTab *rpl; ///< RefStruct reference int nb_rpl_elems; @@ -517,8 +515,8 @@ typedef struct HEVCContext { HEVCSEI sei; struct AVMD5 *md5_ctx; - AVBufferPool *tab_mvf_pool; - AVBufferPool *rpl_tab_pool; + struct FFRefStructPool *tab_mvf_pool; + struct FFRefStructPool *rpl_tab_pool; ///< candidate references for the current frame RefPicList rps[5]; From patchwork Tue Sep 19 19:57:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43827 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp186557pzb; Tue, 19 Sep 2023 12:59:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFvFDOb+oRMMrD0ua1O+v9eqmx7yvEyZmQ8I08a2SlLQqqhwuJMfEYyI7ODIQvGsLY3Nt1A X-Received: by 2002:aa7:cb94:0:b0:52f:fa53:9fb6 with SMTP id r20-20020aa7cb94000000b0052ffa539fb6mr386237edt.10.1695153594181; Tue, 19 Sep 2023 12:59: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 s1-20020a056402164100b00532dfe167e2si840336edx.453.2023.09.19.12.59.53; Tue, 19 Sep 2023 12:59: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="ExK/n798"; 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 12EBB68C995; Tue, 19 Sep 2023 22:58:02 +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-db8eur05olkn2052.outbound.protection.outlook.com [40.92.89.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 846DF68C8FD for ; Tue, 19 Sep 2023 22:58:00 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MpdzB3Y5pPEfZymKKV6mvNmctIyfzMckfN06Ss1pkTrynOaKIkJObb/MueBbc4u3hIzJYtQuiI418DSAqEwrJ2AsgdSRseIzj9selgjUiHAKzhgtmT87whHz51hyBDkvnsZcMmdeEsW1WWu97IYnfRYJn3WL7prdjl+Si0j+C/d3ldAEPVUPn1F9PSlr9KMtU2U2zMf/2zc15y85H4pcqFlOkpAFOm36ARAUIaRJOy7biG9nC15j0cc6ZS6Wsz6SusrzvavYiyx6/2T08r7gnFZntdVZ0aMpDq/rCMrA128gU+dIM29IKpexgAjwLycaIAD72WT3CaTUW0f+m523vg== 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=L+yEKc1Gq3x0WgzpIi/i8ZQs+Ro4Y54nnvkzsyN5ErU=; b=Cj6lS6a3DEJSsrOZC897bPUBdjSoTDN7gbxxbjfLG29F0HyL7NtzW1uDs4Z9v59GWPc6SOgtDRb36GKoqZOifKdlNemvTCc/y5TE+PDLizEMHvprNMnQgxjMai6WAMpNyQWFLDtMATKTTc9jPUDDi6CeA/R8LL4s20E9+7Zraemep4gOXiEc6Zgb9JPUaDiPlQNOsZWNsKKlJxuVYWKIBIHAyPs9fqEuk95DvmxGvjaw84AzFMB6d5Plhepxgw5U2mLMGvgdRZxUaFsMgb2L4QA490E7qlBum3tBd0bbU21pYGkOrbcQC5APh59znZ6G1Rd68KUkERNjaLjmU+dZ8g== 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=L+yEKc1Gq3x0WgzpIi/i8ZQs+Ro4Y54nnvkzsyN5ErU=; b=ExK/n798cUzcwpGWpkCOHChwlO2nzzpFKF0dwCvJDpPbPG17u5uIzjgIhdGLatBmy0JyMDyFaxopd1lGXlR/q6kSNGThz7Yf+jvs2rjRm50lJZbmFi7kUcSzg08l4O/dLb6ZwN6N3+7oUkSbhrhMLH0DaNPOFbMkAMpuQqgJ1Tj24lwI69cpMNPEfmik4S7w8jUy6fspCHZgr/ipj9IJLf0MJyhVF4kfwKEsMRBu0Zd9cg/0M99L2NJMsjGsfqZ1pM3bLEJBO82ZRJM9BGKh6fuksGrS0RPhK/gp101R6pYlnYWA4ehNk67k0jEy5mVhRNRzVrG30S8rO0nFAuXC7w== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AM8P250MB0215.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:326::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:57:59 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:57:59 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:12 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [j0gssKUwqMr0Ugxm/ttlpzoaw9Tb/nNs] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-20-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AM8P250MB0215:EE_ X-MS-Office365-Filtering-Correlation-Id: 2684735a-6009-4259-65bc-08dbb94ab91f X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ibhIoxS5vcudspMq9bP5HKjGoxVb/NyEHMFZxvU/sbb+TzhgtC3JdcuuGA6lNfvpfyK2VXyyEagCCYHvaoU4BCZhHHy5YQ7b0OeoLo8JEaPl/BMDE0+wjqb3Stp4nTbrRrYddtih+JIujqh+azJ1DN2NVkmU0mxiA8E6ZdLK8vx9uiOVI5EE5iXEqZLat6NDxdMV8GMHJihx1CqwOce1XUTN3GSv29w7fopHmd+MbaZhxXrVGoQLVIEojBwU8T/bFjX6mTVHmmSUoCgnDijT4ybBN1sZgKDZ1JMoLUqsGGSAvm2WmvzxqH+fkBHsKUr6bly5JMNvRIMLGroW1PjSJCxhTi9YNFF68jMI25ufRmAsdbX1+CmHstBFcaNKB0IQ5/hpfoh458k53Ca9wLr2jMdGWljrE7xRekA3SLCfo+Dv/ETbO7FrwIeXauhSiIsfauBdP/1A+TTccZ4kxHjtuh0VqqVRyboEqmWJF5Gdp9eqwvRN4RJWWm09JVWV9lD8tOoiPNwU6BbMIwDvWcIPanCxl++VbGKLeRQRnULFndBbOUIPa7dSJdXPIWSHO1jPjKlrxWgKFr79S1dVCPKWopzbH2O1NFHgrBozGqdcYEmpI9fTIGsWzJmEB1UWerPG X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: AMpA0YlEC7iohOayppiEkfgCO4GrHFlCDNm/gZ/piNPRUHy0F3bpfeOrV83nWlY+4cKspgzyID+hBjjGzqi2WHX8LG3caBWMlGdYQHf2yd4vECdpMLBdCCaIunPmOvl1gdV2V7nQXY8RxK8opswzT+YWL8o53EuDkO0VC9Vcbc/xrD+Zm/gI/6J8mn/POhh7n8P5FBXKqxMbUVgS349p0TKARwunkrwBNPIOMr+iEs3YjSMSvCniTxhzjXnT2McQRlxt59aX1ziCrPLVLXTuO26UKW4PS7TXayNGzaT7cqtmkQpa8430bwlsVct8e0ebHatmD2pFwF2aVTXgum/uF1bzvj5+RJ6aMXkrjSvaxvFD8w7nbpCHb0aOJKUqJtVjM8J/xuB/MwFxbyNFS2yNpvPyHXLbU+ka1PWf9oEvsKdXeURD4/4oWsq5XZg6fVKm2URnitXqun0cH4+aJHjuJqz6pshynYiB3HHSKxqVlQQxLdvI7ntYc9u1zyonxKjGiWfKi5BgDF3ZIm11M1ep8RQP8dOeHXv3hQt6Lr9+eMKSkulW6nU01ZD7JnZAqAL3Gaj7gqUwmw2hEsk8oW+7mC0H+XfSIMDGxbxiWI5MLjYi8Z0U+5L6207KBlh12VPgjKOod4ZpiLVlqcy9aINga3LVfAHxiEORHtcKTyeFOUSP4nB77X/unsaAkDm05/EorKBYXZGSKlPBint4VbZ1839mPHqS5kEUyj2hCdZQg794YoXJtzk4s9mHMLz5n39vR5bWeZHniK+4zONPML5yyDYX7aZJP3hzPd6KbK0utMKZRE7bxhDIVxGztQxBm4ndZdXmLiTb/M0NhEijV18I8jm7yvqjxrXaeJHEo0w0yY3roZxiYsCFDhgQZVcWk2H26nwkO4YHjce/jvwAPrBb6I0RYpFnOoUJBfKVoJGsUbshcq2d6F+FbU7Yrc+yPlwhP08m7jx/xvGdZ2bWvaop7OKwpYIx2qVWqzU9MrN/7M+g7zZD5JCk6J/OsrWkzko0hcMDEE/KVZC83q1r+iB8YhXw58BpcqWBivY9ZIRN/deiyjmcoI3ndfvdCb3lazsKPHuPJcMnh/Vs0IKocISq9REsD0KNgvMIiTGk85vC70+1FQvym83fZNB89sBcJe5Is5wFkjJVSHecyt9Gw9fHgzhMeOJzwPvMtu4gM0UYo/srBwVZp6whifkOwk3iuiw3ziG4r0HySxnt5WbR9seYVFTzeGap6AgPun8pnoP25zyZ/lk672Xug9/3nZqUtn2W X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2684735a-6009-4259-65bc-08dbb94ab91f X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:57:58.9740 (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: AM8P250MB0215 Subject: [FFmpeg-devel] [PATCH 20/42] avcodec/nvdec: Use RefStruct-pool API for decoder pool 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: IkbVpKH2bdoF It involves less allocations, in particular no allocations after the entry has been created. Therefore creating a new reference from an existing one can't fail and therefore need not be checked. It also avoids indirections and casts. Also note that nvdec_decoder_frame_init() (the callback to initialize new entries from the pool) does not use atomics to read and replace the number of entries currently used by the pool. This relies on nvdec (like most other hwaccels) not being run in a truely frame-threaded way. Signed-off-by: Andreas Rheinhardt --- Notice that the AVBufferPool API serializes creating new entries as well as getting an already existing entry from the pool, so not using atomics here would be fine for it even if nvdec were run in a truely multithreaded way. libavcodec/nvdec.c | 49 +++++++++++++++++++++++----------------------- libavcodec/nvdec.h | 6 +++--- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/libavcodec/nvdec.c b/libavcodec/nvdec.c index 0ec8e896a6..27be644356 100644 --- a/libavcodec/nvdec.c +++ b/libavcodec/nvdec.c @@ -237,21 +237,22 @@ fail: return ret; } -static AVBufferRef *nvdec_decoder_frame_alloc(void *opaque, size_t size) +static int nvdec_decoder_frame_init(FFRefStructOpaque opaque, void *obj) { - NVDECFramePool *pool = opaque; - AVBufferRef *ret; + NVDECFramePool *pool = opaque.nc; + unsigned int *intp = obj; if (pool->nb_allocated >= pool->dpb_size) - return NULL; + return AVERROR(ENOMEM); - ret = av_buffer_alloc(sizeof(unsigned int)); - if (!ret) - return NULL; + *intp = pool->nb_allocated++; - *(unsigned int*)ret->data = pool->nb_allocated++; + return 0; +} - return ret; +static void nvdec_decoder_frame_pool_free(FFRefStructOpaque opaque) +{ + av_free(opaque.nc); } int ff_nvdec_decode_uninit(AVCodecContext *avctx) @@ -268,7 +269,7 @@ int ff_nvdec_decode_uninit(AVCodecContext *avctx) ctx->slice_offsets_allocated = 0; ff_refstruct_unref(&ctx->decoder); - av_buffer_pool_uninit(&ctx->decoder_pool); + ff_refstruct_pool_uninit(&ctx->decoder_pool); return 0; } @@ -424,8 +425,9 @@ int ff_nvdec_decode_init(AVCodecContext *avctx) } pool->dpb_size = frames_ctx->initial_pool_size; - ctx->decoder_pool = av_buffer_pool_init2(sizeof(int), pool, - nvdec_decoder_frame_alloc, av_free); + ctx->decoder_pool = ff_refstruct_pool_alloc_ext(sizeof(unsigned int), 0, pool, + nvdec_decoder_frame_init, + NULL, NULL, nvdec_decoder_frame_pool_free); if (!ctx->decoder_pool) { ret = AVERROR(ENOMEM); goto fail; @@ -444,8 +446,8 @@ static void nvdec_fdd_priv_free(void *priv) if (!cf) return; - av_buffer_unref(&cf->idx_ref); - av_buffer_unref(&cf->ref_idx_ref); + ff_refstruct_unref(&cf->idx_ref); + ff_refstruct_unref(&cf->ref_idx_ref); ff_refstruct_unref(&cf->decoder); av_freep(&priv); @@ -469,8 +471,8 @@ static void nvdec_unmap_mapped_frame(void *opaque, uint8_t *data) CHECK_CU(decoder->cudl->cuCtxPopCurrent(&dummy)); finish: - av_buffer_unref(&unmap_data->idx_ref); - av_buffer_unref(&unmap_data->ref_idx_ref); + ff_refstruct_unref(&unmap_data->idx_ref); + ff_refstruct_unref(&unmap_data->ref_idx_ref); ff_refstruct_unref(&unmap_data->decoder); av_free(unmap_data); } @@ -526,10 +528,7 @@ static int nvdec_retrieve_data(void *logctx, AVFrame *frame) goto copy_fail; unmap_data->idx = cf->idx; - if (!(unmap_data->idx_ref = av_buffer_ref(cf->idx_ref))) { - ret = AVERROR(ENOMEM); - goto copy_fail; - } + unmap_data->idx_ref = ff_refstruct_ref(cf->idx_ref); unmap_data->decoder = ff_refstruct_ref(cf->decoder); av_pix_fmt_get_chroma_sub_sample(hwctx->sw_format, &shift_h, &shift_v); @@ -577,13 +576,13 @@ int ff_nvdec_start_frame(AVCodecContext *avctx, AVFrame *frame) cf->decoder = ff_refstruct_ref(ctx->decoder); - cf->idx_ref = av_buffer_pool_get(ctx->decoder_pool); + cf->idx_ref = ff_refstruct_pool_get(ctx->decoder_pool); if (!cf->idx_ref) { av_log(avctx, AV_LOG_ERROR, "No decoder surfaces left\n"); ret = AVERROR(ENOMEM); goto fail; } - cf->ref_idx = cf->idx = *(unsigned int*)cf->idx_ref->data; + cf->ref_idx = cf->idx = *cf->idx_ref; fdd->hwaccel_priv = cf; fdd->hwaccel_priv_free = nvdec_fdd_priv_free; @@ -611,16 +610,16 @@ int ff_nvdec_start_frame_sep_ref(AVCodecContext *avctx, AVFrame *frame, int has_ if (has_sep_ref) { if (!cf->ref_idx_ref) { - cf->ref_idx_ref = av_buffer_pool_get(ctx->decoder_pool); + cf->ref_idx_ref = ff_refstruct_pool_get(ctx->decoder_pool); if (!cf->ref_idx_ref) { av_log(avctx, AV_LOG_ERROR, "No decoder surfaces left\n"); ret = AVERROR(ENOMEM); goto fail; } } - cf->ref_idx = *(unsigned int*)cf->ref_idx_ref->data; + cf->ref_idx = *cf->ref_idx_ref; } else { - av_buffer_unref(&cf->ref_idx_ref); + ff_refstruct_unref(&cf->ref_idx_ref); cf->ref_idx = cf->idx; } diff --git a/libavcodec/nvdec.h b/libavcodec/nvdec.h index efacb5b691..353e95bf42 100644 --- a/libavcodec/nvdec.h +++ b/libavcodec/nvdec.h @@ -44,15 +44,15 @@ typedef struct NVDECFrame { unsigned int idx; unsigned int ref_idx; - AVBufferRef *idx_ref; - AVBufferRef *ref_idx_ref; + unsigned int *idx_ref; ///< RefStruct reference + unsigned int *ref_idx_ref; ///< RefStruct reference struct NVDECDecoder *decoder; ///< RefStruct reference } NVDECFrame; typedef struct NVDECContext { CUVIDPICPARAMS pic_params; - AVBufferPool *decoder_pool; + struct FFRefStructPool *decoder_pool; struct NVDECDecoder *decoder; ///< RefStruct reference From patchwork Tue Sep 19 19:57:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43828 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp186634pzb; Tue, 19 Sep 2023 13:00:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEcAI2DzujLHtlMe/scJl9IxUG/yqSqI6RM7eQ72LAVLXEs54S0Er9l2EF1nMN+XNc/3Id2 X-Received: by 2002:aa7:c414:0:b0:530:74ed:fc85 with SMTP id j20-20020aa7c414000000b0053074edfc85mr339994edq.3.1695153603436; Tue, 19 Sep 2023 13:00:03 -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 q1-20020a056402032100b0052d214eb778si11213721edw.112.2023.09.19.13.00.02; Tue, 19 Sep 2023 13:00:03 -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=SBgdd8IN; 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 2E17C68C922; Tue, 19 Sep 2023 22:58:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2045.outbound.protection.outlook.com [40.92.91.45]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3E1D368C930 for ; Tue, 19 Sep 2023 22:58:04 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gZUOhEcXJ7PhCd2LMlEfPx2OPOzfguUUnxnfeuAU7haZKqGYoj5XpiTwkXNgPTldsEsuvHrWOy3sRCQr6AgX7JeUa2DFvqXoQepME8O8i+MJ7f2KuKGuKwkgKM5CMpGkDqcoZwZRZjBXZC3BHIEdU3h6aoz9RcaJj8lJDfu8ez8ojo0YmEqtJZgmqXU369fifOGfioa42Iw0CfuFWEEnJxorWYlqOvMWEd4ILDQ4kDV4mgx4OYhuFPT5MW6AFhTG1Z5SqkoHhisdiWgbe9K6t/y6P1bHq6B8cXaa/8qsG2dWEW0f/B/JW2Prse9Als2woKrsPmWwmhuaI343vCP03g== 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=ulDGEnRWpzkG7Qk8vCIHL2GocfvAhivlRqPx9VGI0VA=; b=C1ONCfWgZa5qpM5316jCjVTD77PI3j/Ha1XklbYdCqazCV0F6AADv0O8rglAorUx0tmvNGN4U1d0QrcqJAlu7nhhwl8eg+l2cjdE2II0HtD3LiiWcWuAki2sYYFMTeIYI6Q4OZifmEDAPMQV9AM02l6wNVlLo3xsSJweu+/eASGdVg/q59n1QWahEkHMqAKQZYvCPntRA/wSwHNXxaevQ84rHULmNgEcaxc26mcNE1s+wA/C5BjnFpHqhujUSAOK9As7+vSi150AMC4IKKhIl9bdCLzb20fsGGEnbfMrqTIIwaUsTqnEVluNrkPG5gvU2JiWje84j0flg3aUcJ55Jg== 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=ulDGEnRWpzkG7Qk8vCIHL2GocfvAhivlRqPx9VGI0VA=; b=SBgdd8IN6R1qJbqKKyzJsE1Lpz6DWl26BQwwLpo1qsciy5aV6slcuWe4Biyc4J94dPkOsws+5vOJ2kh8V8JtbEXXuLPaUGC9a+033JOv2sRpvnsS18yTMlvWRB6E7Ucix/onD5lbC4Ud7qNkZQpMwllnSVEo8K5qzNsa7W2MK70NHqmLun+IhyfbI/1INrK3k/AWxfmFnoK2vnKpfLBRgZoLxC6e9fJ0lWbgtcN9YzYSqaewlwZ2fmIvfn2LUjSW6cAH/iUr0oajTQoyNNC2zvHkP2zTxkMDJjQzWfzJzMzD6ua0HC3iQt72PM/yKMWbSDAMsLgwcw0apz77palhtg== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0303.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:27c::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:58:03 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:58:03 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:13 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [sR0Ty3mB0N3cvn6ykzAr73vJv8o8Vzjy] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-21-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0303:EE_ X-MS-Office365-Filtering-Correlation-Id: 9c74f41f-430e-4804-8416-08dbb94abbea X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SpN/jq4ZzVQCIUqNQkDtVN7mPFIQMNl0MWZjzS+86v981I5obsioFMJZeIhQjpomqSw5x+BBHOC6ugiSPe7hXIUjdH/07WAkKHXcx9tQ2P2FkPBb2EmfmTxK50IBrsdFxE88+MaASfPo2vylOiRXFBiZXwg3ny4JW5jYZ47qUaFjfsV8c7x4hxrAo6nzqocD3D+6r87pC6NO9rx3dvJaDj3Ou2udPcQbUFt0uMBU4op3q5/DiwY07T5GReM/gEuf2lV393Qlj993BLzcm4PIlKE6V9yG+7KNbTS9C1fecXM82tyAkZzQbVQYE34GxV4i+bBW20N6a0VN+Sr9aNKEKdr2p7nbRntYQb9bvDPxwb0vy8Rc8WekGcAqVlsIxPzDSdzNQLicFsLlj8AiqI+UEPdFVuJMDDPmGezN7FxDoH6hkMA8+/V6+Z+khipXR+fbwtTNeUICMUVGSBOZqA2uJGa5XfhkkVhzj6riclKJ2r7ZFDQyTJ1PiAC5tChfmMiFf6by/r2/vlajkfry7qLwEE8GMxrYpuflpCgKlEQTTm+YOB4P8w20fVIbC25iKOJzUpab4ITkoRDgC9utq6Q6BoETnz8y+U6LKkzulx6/U1cSAmlP6AsVl7h0vIo8g5yz X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: W5/DWDkd0njFOgPYeloMHoGZZvoxuiZGftfX+RWCZXXJCtVaxIL9igzWCAU+SQaENTxMjx7N5+fyIo9bmErHNDQ9WLM56pGTIZJLOc892nLM4F8it4HuXodjw9i9zOb+w/GTlRlSi3yEVdYA+uJmuNU9BDjx8Anf5KDacdpHCGBIQ2l6nvGcTz1oH6/L/By63T4XJ1N98JKBqyPcQ7mC7ZD5DoXzdk1KBuufeyhtZleKCYE62/QZnskFx3652MD+cAYFcohki7fFIeMJcFezxHBSIZyfaMnHViLgrU/CBwxEu1UbGbdE4Y52YNzxL/M3B+buCIpX0zO417wmfGz1kmR4m+vltSSe7CIP+UPKuqgMFL+Vak9FwAJ9wz1Il9yP1p0OkpPNV5RDGCjjKSi95lzlOGx6M0lj3NGAsEWg7kXKU2prnEcb+YT6lIzKRaVDFmrJPMdQX7ytSq6XYCZeihBTLA6owBoOLLCXmBigGjRjA407lkEJrTUQeuzPNXsIiFqt+bYRSRD+c3ogTlA4dBtT6DMkBj2khay3B6E+sVfdS9kIG83/CSKVtbea8fOOJPf3Ec/OQ/qXhqEpQdx6PMpgsEDLBfzAC52oX8cQ/k0L/A4CzzmvDUdvR50sPJGFU+4NcJPyaNbN5uNcGuLpKlXTDLy0jIHsO3QVIelf+Du043DqM21jbNpwzIew9lDXXZNcUu3sGjzwPkK+F0WMPPKsOZ6T1TDHdJH7gVSLiTEFIXVEFI5wJAh6DAwuxlDKC8sQ7BujphYY1JlIryILblgcX5hUGoFij7EpceaIzBUbF48uiM38sT4KGp7l+ny3Lpe6Wnym7evzB/jR9lb4Yt6GZJ0ITH6luZ9UC2LBNnWDkCiO6pXd0SCiGQ75ZbkokBoXvDAGZH5F8K8W0JsaWhF3h+IKoVutlJ7y5e0fDe8f2fxN2nt0WWj4V1khEa/yGlwrlamCok+EkuYGuDQSbhJ4CoCfLKYELohKKHi9WV0MaZ3p0nUCuORAzn21+/SR+5sY9eC9oykXSv5WeeAeY0SZEeFLM8ZHfcLkf3np/4joziLF+CWMCqndCSr25lI/CNps47OpF/PFNdZ8e80Yo2nX67juBP9/WDi1jNZRAEYJFTmQobSAfIY9JxNZTSzdyDR6N0K89qAauixDn5RlvJKGwamS7G2BEWEz+RRgz1cEIjBnMpwFM1SXmzU72i5kPQF4aqtQ2pj5PF83NRVM5Nw0a8zvrt+xqyexCxA4LUFTXcQmCo3xYGv2aOHaR69Z X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9c74f41f-430e-4804-8416-08dbb94abbea X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:58:03.6797 (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: DU2P250MB0303 Subject: [FFmpeg-devel] [PATCH 21/42] avcodec/refstruct: Allow to always return zeroed pool entries 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: qOt9hi1k2vvj This is in preparation for the following commit. Signed-off-by: Andreas Rheinhardt --- libavcodec/refstruct.c | 10 ++++++++++ libavcodec/refstruct.h | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/libavcodec/refstruct.c b/libavcodec/refstruct.c index 7539b7942e..f8d040874d 100644 --- a/libavcodec/refstruct.c +++ b/libavcodec/refstruct.c @@ -262,6 +262,10 @@ static int refstruct_pool_get_ext(void *datap, FFRefStructPool *pool) } } atomic_fetch_add_explicit(&pool->refcount, 1, memory_order_relaxed); + + if (pool->pool_flags & FF_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME) + memset(ret, 0, pool->size); + memcpy(datap, &ret, sizeof(ret)); return 0; @@ -334,6 +338,12 @@ FFRefStructPool *ff_refstruct_pool_alloc_ext_c(size_t size, unsigned flags, flags &= ~FF_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR; pool->pool_flags = flags; + if (flags & FF_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME) { + // We will zero the buffer before every use, so zeroing + // upon allocating the buffer is unnecessary. + pool->entry_flags |= FF_REFSTRUCT_FLAG_NO_ZEROING; + } + atomic_init(&pool->refcount, 1); err = pthread_mutex_init(&pool->mutex, NULL); diff --git a/libavcodec/refstruct.h b/libavcodec/refstruct.h index e2fe45e77d..ce3830977f 100644 --- a/libavcodec/refstruct.h +++ b/libavcodec/refstruct.h @@ -207,6 +207,14 @@ typedef struct FFRefStructPool FFRefStructPool; * the callbacks applied earlier (init_cb potentially followed by reset_cb). */ #define FF_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR (1 << 17) +/** + * If this flag is set, the entries will be zeroed before + * being returned to the user (after the init or reset callbacks + * have been called (if provided)). Furthermore, it also makes + * the pool behave as if the FF_REFSTRUCT_POOL_FLAG_NO_ZEROING + * flag had been provided. + */ +#define FF_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME (1 << 18) /** * Equivalent to ff_refstruct_pool_alloc(size, flags, NULL, NULL, NULL, NULL, NULL) From patchwork Tue Sep 19 19:57:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43829 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp186726pzb; Tue, 19 Sep 2023 13:00:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF2XmyDp6DOCj8QooFFv2wfEZplyljAlpKzuN673U0LVpIFQlcUOvJSWwhmLe12ol1DCHaq X-Received: by 2002:a17:906:51cc:b0:99b:c86b:1d25 with SMTP id v12-20020a17090651cc00b0099bc86b1d25mr342835ejk.26.1695153612809; Tue, 19 Sep 2023 13:00:12 -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 j24-20020a170906051800b0099315476299si10142652eja.1040.2023.09.19.13.00.12; Tue, 19 Sep 2023 13:00:12 -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=blIjA8aA; 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 67FCC68C9A1; Tue, 19 Sep 2023 22:58:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2090.outbound.protection.outlook.com [40.92.91.90]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9A6A568C90F for ; Tue, 19 Sep 2023 22:58:07 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c8rvYj5sBmv0Tm9JX/1umfAI5XbLO22Srfrvrdlv7AJNOu1+zDkSipZ/qfXLGXUfx0SQsa5fuqn8QPb4plOZ3Lg6CnOwORiDmUusXKRQx/ftO6jmnDDtRA+X+d8kHwlzoKMyJevNmE9/+xAC8/V06KEl/b1KvFEdYoItL+oMiRJ/BIw+fkIMqRpGmy2Bxs9g1Ub69ckphwj1Rakg0ZE5mZs1dpR5a/ZNwFEOW1VWoO1ZDCBOu5UMbn6Bm7NP2EhruGWwnl++JIilaOA0RKFPIyyab9lvEs0rnABwLVAYMGbRmddJ8glWbztQqeZ6QDDI5WlP7XVrTPTi0MiTcvykPw== 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=Zk9Uus9ZoVeoI1/Qly5ZEyjqTZcdPNTzyq+qV4F8dtw=; b=RM/YCf9gTXk5AaRkENeLNWcwyrNU01GUeGUvw8QiMuSrLBGTQDX25Sn7h64eepBvfv4JbdnvdRs1NDp6vy+/RYVPQ4t7lVvVK2RWVWMa8KOZMsU/T/fqF4QSC9fR/Y10blAg1ryCxXROCdGlGf0nCyLWt60ralbEk0WAMsZFd5TjzecSUdmU2zGZiW0kjqCZKUFfMPG0SJgThpmcCoDNhS5B7zmQ7hrpVxo5NPOVR8m7LWtYxS5tcyxMbvaw8z2a4iGwolUSLmOEHUwKtjqg0xk+LINB4i/OqwRJ3Kse/QL/FNxI7xl+iuRJau4SXXFe/8Ebe1625KNrM6u6pP5uSg== 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=Zk9Uus9ZoVeoI1/Qly5ZEyjqTZcdPNTzyq+qV4F8dtw=; b=blIjA8aAtmSJsWaBu5KCkwV8HjeoI735MuxhyId8v0bjFyxhXJZNPEybAGA2iDUk0UvM2FDHzM2lNursED1NjbqawOV+DUnAYJ6xcTLfZPVyVwvF3BYj16itYTCNhR2Wr6tFELmlr9PjZrHHhAjg5Cs2rKUEk2Om2L9/LP0JTAgkq82hdrT6iWN2/Ti7RUhb/7uHq+zGf5hPY1yGyEEP/FtqghEbzVI11FEOqDttyHCYvf6xsbWFDAPPiU3FrTSfKAgIVvKVYXW0jtTFKNkN6559WvQYpFFHx012JuziGfvXRMok7JJLrwKC2FyYbFwS9swSmC/T0ePN6Ee8uL3xXQ== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0303.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:27c::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:58:06 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:58:06 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:14 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [F/lhFaMOy7E8oBncab3ge4FK+8o3zYSO] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-22-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0303:EE_ X-MS-Office365-Filtering-Correlation-Id: c62f5bd9-9b4d-4995-ae89-08dbb94abd6c X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BTrapzAtd1g8ADBbBQZ+87nerBRBF92O2KZXoNEAUF3WLWsQWDdjATQnbMmYNOLVmzTpsPvM1gUQQ+XNtm0xv7WAK+4KwrktuYMFGeMdvnNybDmt0puf9eoSKaWgygzAsi4BViBjaKdOPhdF/EklCAx9gW5+++qVpedSNopc5LqFryUcH9r9nDEdNF3GEp9JmIYOOp0+fmLlyuI/wHinlxAPt/sC9vKeriLjdnM7sPaRaV+s+yI/eZxeecVgjG0KcXJpObJ/cocFmiY4xEQqLFeIXspcXYP1EQDmVWo6kX0P2MHrBLlaICFOTyNGSpp/mHs/qayU5mq9pPxmy62uB0xECvyKMAeMnU9r9ybdbzpL1Tuo235OYY5wwFx/18lPsDJl0Lisf97w/zXwZ80uRBLvY06wpSYkaYOtZWl5zRU3b2PxzozVgyzLs6ZpqcMCyLXgIBPfIuPNc+Q/o3bnrUGrzoqTJ9Z9jQPDDjm90BIyzS8GpM1HamM4QpKfNZVzRDIcYu6vumUMY4XwhKARC+Ox4mZ7qgkJoxJAlKNBA+MJnR64gXDKogo3BbaNl86iiKKRoI2Igb4FXnQ/Raj0O7GBcmKj77wrtG8IGjvbQ7ucS0A2szMdGMjzUjI/MVzf X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: U9lToHUN1TntoADZb2l5DUTGtO8OpXa9/3M9KtBb+/D23EHFY9LOY7nJoIWYi+Rby+AbvNq6XTyPUGgYEIYmOtvOscywH/zHCMbR77rydb4iwTfNMDbE3law8wgFknu3SWa+4o6+M07kWHl8wxbGxx9tFe4VMV69XEaxHyHXRdjN0fxWfQwxcZCBkxTEHZqXY3Q7BJhPWcYD4zO3fiQuR5ax7UD97Ryx67CJlQ0AXW5b5X7ajIOsuPe+Wf+LPIcc9PoNqGUlyOpGIDdyAneSSw9gXWRZQjPNmVGjokfM9ukxH4xr1MgO5tA4TAuB1fdmysPVuDmfRxoywdnbjlsYIHxTmNdVo9144GBk5CqQh+qmRac0wAF+hVr8dhxV5eQLCCfV3JsI2CIb/TPobsAuxbySqbA6ZWKpBVJa2f1koR/9I4HNjPmY63JaORbHlmuItELKF519n/MAtD9A0u15hCZQCqZkK58c0XmlRauNzF8AteUjraacsu7c6OnJ1rRJ7KcJHhtnxRSdR4QNvDqwU5tiU5us3qpAAuFbRM69NFMhcBnj26oJNa5FwmZEfitYcFs2xjQdnllkco4C7rdqL4oExoDqR6H7jC+k0oaogorEdPczd7KvP3aify7h1AOdWKqUrQqSnZbR84jSjY5fFyyjFYDb2J8KwOCX5iHJyTcvBAVEadBBCNWZMaWEV7PiJNLkyjZfO8Tt+bSOFjhS493+IhXl5tuAdObwUh/B5DhZNP1jDosqm108Wk0FKXy23ioRDU33HIAZ5RFhf1ToLjOcM+n3Ed1OEzMUxW1B5mIMMEfoQLNJzv33VH3T4QtnH1eDamD00v3JQxcH/+cYNs3Dvpa4YWX9Q5bS2BDHk96io2o3LgeGYUDNeIOpEbB+pt6CFESDuaIr+mhDamxrm9DSGopdgQ7rVjXwjuLZ4vlAZwbjP1+n/DuJqk+e05+hdX6d2LDp/Pptg73vn1KRpYcqqsQRP8RHEOrz+fYOO3onGuNIa/jLGwkX0Re4AFnM2ZmSqagt6vIqxSZ82dI3eziiLX7hY+HX0mI5YzDtIwGJ7vTfAT50IguCgVTmfgj3wjK8mOAkg3UatIorOUeiqiTNXJDP6qJJ92IzqZKZqpkPOxYQxga10syLBC4Te2piPQIGeGjHxLe2c8H1B/DjY5PW7QgMpnwl7JdJETRef3muqdyPiGRGPaZbqw8fzbKMzIpEMdcxsGM02jJdq9CrR5iVybPZvpCarU9PPngu6koxFHTocfM7OA3Kf6/HOMXA X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: c62f5bd9-9b4d-4995-ae89-08dbb94abd6c X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:58:06.2089 (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: DU2P250MB0303 Subject: [FFmpeg-devel] [PATCH 22/42] avcodec/vp9: Use RefStruct-pool API for extradata 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: slOblg+GArAv It avoids allocations and corresponding error checks. Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9.c | 24 +++++++++--------------- libavcodec/vp9dec.h | 3 +-- libavcodec/vp9shared.h | 2 +- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index c9cc81ec94..4acfca2b4f 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -100,7 +100,7 @@ static void vp9_tile_data_free(VP9TileData *td) static void vp9_frame_unref(AVCodecContext *avctx, VP9Frame *f) { ff_thread_release_ext_buffer(avctx, &f->tf); - av_buffer_unref(&f->extradata); + ff_refstruct_unref(&f->extradata); ff_refstruct_unref(&f->hwaccel_picture_private); f->segmentation_map = NULL; } @@ -116,8 +116,9 @@ static int vp9_frame_alloc(AVCodecContext *avctx, VP9Frame *f) sz = 64 * s->sb_cols * s->sb_rows; if (sz != s->frame_extradata_pool_size) { - av_buffer_pool_uninit(&s->frame_extradata_pool); - s->frame_extradata_pool = av_buffer_pool_init(sz * (1 + sizeof(VP9mvrefPair)), NULL); + ff_refstruct_pool_uninit(&s->frame_extradata_pool); + s->frame_extradata_pool = ff_refstruct_pool_alloc(sz * (1 + sizeof(VP9mvrefPair)), + FF_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME); if (!s->frame_extradata_pool) { s->frame_extradata_pool_size = 0; ret = AVERROR(ENOMEM); @@ -125,15 +126,14 @@ static int vp9_frame_alloc(AVCodecContext *avctx, VP9Frame *f) } s->frame_extradata_pool_size = sz; } - f->extradata = av_buffer_pool_get(s->frame_extradata_pool); + f->extradata = ff_refstruct_pool_get(s->frame_extradata_pool); if (!f->extradata) { ret = AVERROR(ENOMEM); goto fail; } - memset(f->extradata->data, 0, f->extradata->size); - f->segmentation_map = f->extradata->data; - f->mv = (VP9mvrefPair *) (f->extradata->data + sz); + f->segmentation_map = f->extradata; + f->mv = (VP9mvrefPair *) ((char*)f->extradata + sz); ret = ff_hwaccel_frame_priv_alloc(avctx, &f->hwaccel_picture_private); if (ret < 0) @@ -154,9 +154,7 @@ static int vp9_frame_ref(AVCodecContext *avctx, VP9Frame *dst, VP9Frame *src) if (ret < 0) return ret; - dst->extradata = av_buffer_ref(src->extradata); - if (!dst->extradata) - goto fail; + dst->extradata = ff_refstruct_ref(src->extradata); dst->segmentation_map = src->segmentation_map; dst->mv = src->mv; @@ -166,10 +164,6 @@ static int vp9_frame_ref(AVCodecContext *avctx, VP9Frame *dst, VP9Frame *src) src->hwaccel_picture_private); return 0; - -fail: - vp9_frame_unref(avctx, dst); - return AVERROR(ENOMEM); } static int update_size(AVCodecContext *avctx, int w, int h) @@ -1245,7 +1239,7 @@ static av_cold int vp9_decode_free(AVCodecContext *avctx) vp9_frame_unref(avctx, &s->s.frames[i]); av_frame_free(&s->s.frames[i].tf.f); } - av_buffer_pool_uninit(&s->frame_extradata_pool); + ff_refstruct_pool_uninit(&s->frame_extradata_pool); for (i = 0; i < 8; i++) { ff_thread_release_ext_buffer(avctx, &s->s.refs[i]); av_frame_free(&s->s.refs[i].f); diff --git a/libavcodec/vp9dec.h b/libavcodec/vp9dec.h index de7aba0458..013aac49eb 100644 --- a/libavcodec/vp9dec.h +++ b/libavcodec/vp9dec.h @@ -28,7 +28,6 @@ #include #include -#include "libavutil/buffer.h" #include "libavutil/mem_internal.h" #include "libavutil/thread.h" #include "libavutil/internal.h" @@ -161,7 +160,7 @@ typedef struct VP9Context { uint8_t mvstep[3][2]; // frame specific buffer pools - AVBufferPool *frame_extradata_pool; + struct FFRefStructPool *frame_extradata_pool; int frame_extradata_pool_size; } VP9Context; diff --git a/libavcodec/vp9shared.h b/libavcodec/vp9shared.h index e54f23544e..b445a2a746 100644 --- a/libavcodec/vp9shared.h +++ b/libavcodec/vp9shared.h @@ -64,7 +64,7 @@ typedef struct VP9mvrefPair { typedef struct VP9Frame { ThreadFrame tf; - AVBufferRef *extradata; + void *extradata; ///< RefStruct reference uint8_t *segmentation_map; VP9mvrefPair *mv; int uses_2pass; From patchwork Tue Sep 19 19:57:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43830 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp186851pzb; Tue, 19 Sep 2023 13:00:24 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFR/FyCLg8svuVZlXQf+bR5RwvCLnJFkyXzlADP412SQhSwuk78KmwVLkaDfGu2uP7E5r7Z X-Received: by 2002:a5d:438f:0:b0:321:6c90:55f7 with SMTP id i15-20020a5d438f000000b003216c9055f7mr495810wrq.18.1695153623844; Tue, 19 Sep 2023 13:00:23 -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 lf28-20020a170907175c00b0099d804da2ebsi10031709ejc.503.2023.09.19.13.00.22; Tue, 19 Sep 2023 13:00:23 -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=afb71KMd; 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 884E268C9A7; Tue, 19 Sep 2023 22:58:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01olkn2072.outbound.protection.outlook.com [40.92.65.72]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C9CAA68C9A3 for ; Tue, 19 Sep 2023 22:58:09 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OC8HgFBuuECWu+/jdoPgpvdgmG8v6BGSY1IOb4GHHP1fzF83CccEntbxSeFUMWv09sAapl7SPQ6sIcL45xDBBJ9CSfZjWnaa5rXWeH05yKgLDVj3ugeMNDxZDGcTLYhTNkpSubueAG4BQAI/XMEl605lIX8Nsn7GhcMh0oGT6G/cpyyePSvMCQHl2HBLAgcgKnMuZLmIZvzRhMlYZHLjiFsv07/hrZkb42zAIw0Ldb6cHRs1Y5Wk7lO1DPMUID9/O2vvDk1Q25e1Uzpv5CIussIHc32ghHtGDuVWcu347du9KYv8gHNReFs3E615gLLVIyhMzDFEAjkH8Q2XGVd9ow== 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=S4qlXMBvQQJbLyfSbhfP9quennPwRZLGAOa9OYNZp0U=; b=eGzbCtNtJtHbAxBD1QAcVPsp/+VRx67YkdX1Yau8m7yLcp1Ebcb1ShmITTx9DVy2VF8PMDRTirjB94DSzJwo260Gn6yipJF2J+EKLimmjZmpESnzGv8FQdhNqV036s4WTsI0oeBiq5F0aZhKo+RTxkydM8urfVaflLa0m/yvX+9wgUY8c1QpYig+Z5IsVEPSW14ExtOJ6XzyNU7wiMvfyYJEXSAODyl8YC0CUD6K8uTvTaNugzJNrJ5ZuAbXOINLt1k5au518QlyPsv1qIIP+U17Cb+UipfUZxkT6prcCN+SJ+s8Y1vOpU22xbg9yFuOueJOgsl6BBOuvJJYaTUOyA== 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=S4qlXMBvQQJbLyfSbhfP9quennPwRZLGAOa9OYNZp0U=; b=afb71KMdHB+xvXc02zhmT20GzBlsQssbSwhfb9ArppJuM8II45x3JGA/a+5zY8RX+xpQWu4nqhSAlWw7dwAsljqcVYd7xx6JyMpBp4vpX7NBHKzcTyDf7/B4TVR4HHWo/fiZK/hEKF9L7XdA8hzYrEX2bjcvSRvhSV8Sdr8G1fw0ZlMdK2OxryTg9G09UmLG7GBVhBYJVjdppks/IF0yU2+fT8CtEC0tTeogUSHNmXRy3GlygL75dYGmuP8KZ84IVUG0IDWJN6MgdHZtZLuKxA7Lxz4KdeLN3AUXdgTKop0dtlQfuK2sPCJ8HM1Uoq3v3QX7X8d4j7+FCQFoJRFhnw== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0237.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:276::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:58:08 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:58:07 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:15 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [54NHDliJayrXfUCN1TBdnoG0FHd+6xhx] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-23-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0237:EE_ X-MS-Office365-Filtering-Correlation-Id: 3e4d98bc-4693-4dd5-ac01-08dbb94abe58 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: CGZgzHFFf46f4kRjursi/vaE4sl5dEsKC+HIWgRMexiZJgPDCluJfop5x8JjOkzwMLcLntvG/8bV5+QKjTogUybrX2cxJk66/NMIawH55ZV/VIC4MXGN6qckxV9LTuoRYBqkc12c6uc5dFmrk6eGO9cFrjbIEEkQEtgx0GObG/yas4Bo/sdUsf25FMaIoGZ+fhMOORlKfhBMrwVK37GQfS9LvelSdP/nCqbG0agXWG8ebKy8s+BjZO9ehvAYLVijYDOSQqRc68JEgdRNFZwIbZZwt1SnD2WF+pLfjZ9cHPZe0tKhEh3g2NbrAJ9rvYdeeFSWTQ30l5/CdHs9GHiD1jXOknOv+6Q01QEKQtH1g+A3SzfS2TPx6nqobWZnwEOw03bMSh6rMHKMb4FtrqM2KM3nhAd/4YnTfJ62aLCVNbNtaoZieaBtO67ODV0G2wlrsDMzoQ4/8D5hKJxDFPK6JIFa379Im+VovpWHBLcFCDfQIA6EhG8UWypFe2cs2aEv6kzvB0x7NIC27A4h6hefP+N8m9kHTE9zYlNe8U2o2+FPzVARJdsedubOUoF7wImT6qUWnCXK3YIcEauYKa81edNhT3hbQrJQDIxWKUb44HL5qQFanH0Qr9RKDgLlbzPt X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: OUGXtDaIKmmz8+lL2lXEay1ZO7wKQgOyBTPtPGX9VOYsqsKwdzgsr0LyZMt4eiHbMnOAXrC0GBd0t/yyhpYNnBZlGwDF+dXWSuNhZnGjBoJQbSqFCMkB70edTd/0MZDqDTniKSHBcXeiQuPciF2x9Ho6AOjJ1E1QDM0LP2zzq3OScSqHxWnd9McCJPwWBmfN1heuXSyPkf+rxVuf1ibC3McXPt8r5kxZcKhUda3FggPVDOkG17l8PBbDSNbm5YkZsX0ETnKk2GNUOl0OMo9xvrcU+B0YjtYYiQ7BTsuNGlr9IyX8yoWHcldLjqLW6NaoJpWAsJhVjApcP/1PWFisT0DCrRKZhVBDP1CriQhSHhoTb2iXPBTtGTjpmBEotso3NQpzTPgJxvsyVs1/nhXF/s5rm9hda/3AcfWw0ko/vcAdMfs7Az7dCpIhpXzW7XfR9SByuXGp4B7Vpm0y5UTFh5PQ7mQxEoOFwkcBsWr/sEYYdjUd40hNbZmYtQGK8k58TwJXiXSZIjtjRKCFeNBjm/HI2jcz0Un5OZtXa1c9g0HgNaBUMVsZYCsdWFzFuH80+fxOw2o3bG1NHWUbIda+5OaZwL/u37C2JYVzIT1KkbG6ERJc3td+GDSownCB44cYdax4KTOCG0B8JGxdjM+KdeV5CYYov9Zk6a6c5YUFuZU7xus5eDcXLh3BAuU8FPoieNz2z5n08GmWS6Kd1qO0XUubXogu2Z74jB2fci1FavsBV0fvyGa5SI6mJSEiDqUYSwho6hmcd3mlDAJTCW+ROEMSxz2xTgFc5dJCiEmSwLHJv7XopTqKLJeB369O3XCJwvGUo6EvfwpcWjQJe9JsKIH0i7QCuoca7dzufhG9RoFfvO+lzEOFyJBajrujDx8HLYV4wV5HsP5bo6jxvYp/P6d+Xvl0YDQ+h4z+IM8pgJeeD/Cu0V0hK0HY36UjSTEkcEWe/CFWRZoMjmMqHdQJi4nXo8cRMlDjgypYkd3l6nWewM5gGNTsq7OgcCJtqWWBrSDi4B+bkCHXFurNh/w+KFjdRbpO+3vlGSKQ5iP9TKrkRaLk4mnJqogOAzmHQ8V2/MNftznQa/3fRqOLysOmC1qsbgMze71H2NqUxt7qnSn0tE56iUXSTZdmIEQ6EMoQqg94qm8JjQ3brBuYaJ8BYaztrWRRpdmAez4AiybB6i250VrNjMZ3/H/FcRf4Fu0vQbIGFC0mLJ23fMaGzzDql/6yDiczD9ojjDT+BkudOv9BabXcfNrB06txmWCj59zy X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3e4d98bc-4693-4dd5-ac01-08dbb94abe58 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:58:07.7541 (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: DU2P250MB0237 Subject: [FFmpeg-devel] [PATCH 23/42] avcodec/vaapi_encode: Use RefStruct pool API, stop abusing AVBuffer API 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: nwbdivirtcPA Up until now, the VAAPI encoder uses fake data with the AVBuffer-API: The data pointer does not point to real memory, but is instead just a VABufferID converted to a pointer. This has probably been copied from the VAAPI-hwcontext-API (which presumably does it to avoid allocations). This commit changes this without causing additional allocations by switching to the RefStruct-pool API. Signed-off-by: Andreas Rheinhardt --- libavcodec/vaapi_encode.c | 60 ++++++++++++++++----------------------- libavcodec/vaapi_encode.h | 5 ++-- 2 files changed, 28 insertions(+), 37 deletions(-) diff --git a/libavcodec/vaapi_encode.c b/libavcodec/vaapi_encode.c index 0316fe5c18..3f06d7f21e 100644 --- a/libavcodec/vaapi_encode.c +++ b/libavcodec/vaapi_encode.c @@ -16,11 +16,11 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "config_components.h" - #include #include +#include "config.h" + #include "libavutil/avassert.h" #include "libavutil/common.h" #include "libavutil/internal.h" @@ -30,6 +30,7 @@ #include "vaapi_encode.h" #include "encode.h" #include "avcodec.h" +#include "refstruct.h" const AVCodecHWConfigInternal *const ff_vaapi_encode_hw_configs[] = { HW_CONFIG_ENCODER_FRAMES(VAAPI, VAAPI), @@ -309,12 +310,12 @@ static int vaapi_encode_issue(AVCodecContext *avctx, pic->recon_surface = (VASurfaceID)(uintptr_t)pic->recon_image->data[3]; av_log(avctx, AV_LOG_DEBUG, "Recon surface is %#x.\n", pic->recon_surface); - pic->output_buffer_ref = av_buffer_pool_get(ctx->output_buffer_pool); + pic->output_buffer_ref = ff_refstruct_pool_get(ctx->output_buffer_pool); if (!pic->output_buffer_ref) { err = AVERROR(ENOMEM); goto fail; } - pic->output_buffer = (VABufferID)(uintptr_t)pic->output_buffer_ref->data; + pic->output_buffer = *pic->output_buffer_ref; av_log(avctx, AV_LOG_DEBUG, "Output buffer is %#x.\n", pic->output_buffer); @@ -645,7 +646,7 @@ fail_at_end: av_freep(&pic->slices); av_freep(&pic->roi); av_frame_free(&pic->recon_image); - av_buffer_unref(&pic->output_buffer_ref); + ff_refstruct_unref(&pic->output_buffer_ref); pic->output_buffer = VA_INVALID_ID; return err; } @@ -713,7 +714,7 @@ static int vaapi_encode_output(AVCodecContext *avctx, pic->opaque_ref = NULL; } - av_buffer_unref(&pic->output_buffer_ref); + ff_refstruct_unref(&pic->output_buffer_ref); pic->output_buffer = VA_INVALID_ID; av_log(avctx, AV_LOG_DEBUG, "Output read for pic %"PRId64"/%"PRId64".\n", @@ -723,7 +724,7 @@ static int vaapi_encode_output(AVCodecContext *avctx, fail_mapped: vaUnmapBuffer(ctx->hwctx->display, pic->output_buffer); fail: - av_buffer_unref(&pic->output_buffer_ref); + ff_refstruct_unref(&pic->output_buffer_ref); pic->output_buffer = VA_INVALID_ID; return err; } @@ -738,7 +739,7 @@ static int vaapi_encode_discard(AVCodecContext *avctx, "%"PRId64"/%"PRId64".\n", pic->display_order, pic->encode_order); - av_buffer_unref(&pic->output_buffer_ref); + ff_refstruct_unref(&pic->output_buffer_ref); pic->output_buffer = VA_INVALID_ID; } @@ -2420,28 +2421,25 @@ static av_cold int vaapi_encode_init_roi(AVCodecContext *avctx) return 0; } -static void vaapi_encode_free_output_buffer(void *opaque, - uint8_t *data) +static void vaapi_encode_free_output_buffer(FFRefStructOpaque opaque, + void *obj) { - AVCodecContext *avctx = opaque; + AVCodecContext *avctx = opaque.nc; VAAPIEncodeContext *ctx = avctx->priv_data; - VABufferID buffer_id; - - buffer_id = (VABufferID)(uintptr_t)data; + VABufferID *buffer_id_ref = obj; + VABufferID buffer_id = *buffer_id_ref; vaDestroyBuffer(ctx->hwctx->display, buffer_id); av_log(avctx, AV_LOG_DEBUG, "Freed output buffer %#x\n", buffer_id); } -static AVBufferRef *vaapi_encode_alloc_output_buffer(void *opaque, - size_t size) +static int vaapi_encode_alloc_output_buffer(FFRefStructOpaque opaque, void *obj) { - AVCodecContext *avctx = opaque; + AVCodecContext *avctx = opaque.nc; VAAPIEncodeContext *ctx = avctx->priv_data; - VABufferID buffer_id; + VABufferID *buffer_id = obj; VAStatus vas; - AVBufferRef *ref; // The output buffer size is fixed, so it needs to be large enough // to hold the largest possible compressed frame. We assume here @@ -2450,25 +2448,16 @@ static AVBufferRef *vaapi_encode_alloc_output_buffer(void *opaque, vas = vaCreateBuffer(ctx->hwctx->display, ctx->va_context, VAEncCodedBufferType, 3 * ctx->surface_width * ctx->surface_height + - (1 << 16), 1, 0, &buffer_id); + (1 << 16), 1, 0, buffer_id); if (vas != VA_STATUS_SUCCESS) { av_log(avctx, AV_LOG_ERROR, "Failed to create bitstream " "output buffer: %d (%s).\n", vas, vaErrorStr(vas)); - return NULL; + return AVERROR(ENOMEM); } - av_log(avctx, AV_LOG_DEBUG, "Allocated output buffer %#x\n", buffer_id); + av_log(avctx, AV_LOG_DEBUG, "Allocated output buffer %#x\n", *buffer_id); - ref = av_buffer_create((uint8_t*)(uintptr_t)buffer_id, - sizeof(buffer_id), - &vaapi_encode_free_output_buffer, - avctx, AV_BUFFER_FLAG_READONLY); - if (!ref) { - vaDestroyBuffer(ctx->hwctx->display, buffer_id); - return NULL; - } - - return ref; + return 0; } static av_cold int vaapi_encode_create_recon_frames(AVCodecContext *avctx) @@ -2677,8 +2666,9 @@ av_cold int ff_vaapi_encode_init(AVCodecContext *avctx) } ctx->output_buffer_pool = - av_buffer_pool_init2(sizeof(VABufferID), avctx, - &vaapi_encode_alloc_output_buffer, NULL); + ff_refstruct_pool_alloc_ext(sizeof(VABufferID), 0, avctx, + &vaapi_encode_alloc_output_buffer, NULL, + vaapi_encode_free_output_buffer, NULL); if (!ctx->output_buffer_pool) { err = AVERROR(ENOMEM); goto fail; @@ -2776,7 +2766,7 @@ av_cold int ff_vaapi_encode_close(AVCodecContext *avctx) vaapi_encode_free(avctx, pic); } - av_buffer_pool_uninit(&ctx->output_buffer_pool); + ff_refstruct_pool_uninit(&ctx->output_buffer_pool); if (ctx->va_context != VA_INVALID_ID) { vaDestroyContext(ctx->hwctx->display, ctx->va_context); diff --git a/libavcodec/vaapi_encode.h b/libavcodec/vaapi_encode.h index bd25cd5c95..741f6c6a77 100644 --- a/libavcodec/vaapi_encode.h +++ b/libavcodec/vaapi_encode.h @@ -102,7 +102,8 @@ typedef struct VAAPIEncodePicture { int nb_param_buffers; VABufferID *param_buffers; - AVBufferRef *output_buffer_ref; + /* Refcounted via the refstruct-API */ + VABufferID *output_buffer_ref; VABufferID output_buffer; void *priv_data; @@ -262,7 +263,7 @@ typedef struct VAAPIEncodeContext { AVHWFramesContext *recon_frames; // Pool of (reusable) bitstream output buffers. - AVBufferPool *output_buffer_pool; + struct FFRefStructPool *output_buffer_pool; // Global parameters which will be applied at the start of the // sequence (includes rate control parameters below). From patchwork Tue Sep 19 19:57:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43831 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp186954pzb; Tue, 19 Sep 2023 13:00:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGYqCpfdcw2Dgk7q5e4dhvwr992ecZBfRTU0+QeTuxfqkbchAe24UWwgIGzrh5oDsT/crKI X-Received: by 2002:a19:ca03:0:b0:500:b42f:1830 with SMTP id a3-20020a19ca03000000b00500b42f1830mr451622lfg.63.1695153633677; Tue, 19 Sep 2023 13:00:33 -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 d4-20020aa7d684000000b00523402ac608si9518953edr.50.2023.09.19.13.00.32; Tue, 19 Sep 2023 13:00:33 -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=jGhkGXvZ; 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 A535A68C948; Tue, 19 Sep 2023 22:58:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2061.outbound.protection.outlook.com [40.92.91.61]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 66CD468C9A3 for ; Tue, 19 Sep 2023 22:58:12 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZX83V1ZHTwO4hsFflju2TLreewnLvyFMPQ80vGRyXJlxJIlWx4y62BQBak1TBBA3XL8lVMHQTwx2H4Bw6vX41SbzMizi4EVOqviC4CEOWhrkLHlVbMhywMqETMt/u5J0ecgXbVYcAiA4Qcqf9DjHCQ7FfuPDOm/h4T0q72CH4YKbeD82A8B5eV4++8gCkq4cX96yeixA1Av+8VllthqL/OO3nEOPEgyMNUew0Lln2QJeRSe6CwiS/F8LMzmr5vtip9cwP0sCJ/DalBHXTJhJM9zgwblxMxvyfiaQkMOhYNgQ3A4RXkFXb61fShTAZl+aCn1fZD0FQj1yyTndah+9EA== 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=EzbWnTBh1vNIJhI5f27s+ZXWguCGboAdKOnZfES4Zz4=; b=Y3pJw3qNu5F3LOfLR3Ta3e5lEd16iE4q3oAwuIN5MwfgnZdQBtnYkFDTukiBCuu9vFkDwbsNWBmHu2m0jy0MTEfH3QkOlxG2wzeh+ZoCcHHqYZtEgDg2G7HKHuBESkTDeLTKrW0KSghd4gaqQwk30IeQThbfMQaiCGeHHRli93XduJ54N3fJP7CgBRoCJwAtrhuXQf5yB6F7KesYHOPOxkkGDWxwrbOHu1+LR56LmaF61lPWURv0d+wJng4PlTVPsD3VCPumiakCwRWomsLA242IGnp87fAYYVUzeADqWTgqHuDkB/r+0w7haviujwHGwFlr4d7Vckcg4zWfu4k0XQ== 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=EzbWnTBh1vNIJhI5f27s+ZXWguCGboAdKOnZfES4Zz4=; b=jGhkGXvZAYclBwprhJB82T6rgFw3ulZc0oAQlqgljQP9Pwhv2kOu+x31KVSnj1C1KvuDL30rD1Jg+/ZlRKoWrmbGvAus/zLODx9z9cjk6XDbGidLfE4puY9zYaNa+4NuZxCTFtflZWhs1qiGZXXlAIE0cVvmBtaLyKW5J3W87NVXimmsfkkVp8ELCC1GyNCwmrurbUinNi4EwMWj//mDHbGqUzldo4HQivQ0kwad6hEEDyY7d+NGksAwy0EgZfwdVcPygmdKO0Sge4jNjWWMyvBZdqoN5YMXkDPzqj2KL4ML0Ut4E2YJ+lHZfqrAE1l1eiuzmGgWvMSXjyiaOmJ+3A== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0237.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:276::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:58:10 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:58:10 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:16 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [2QFvfyrSHlxxaBXisr42HMDUvuYSPauf] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-24-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0237:EE_ X-MS-Office365-Filtering-Correlation-Id: a9ed6953-4401-4c8e-69aa-08dbb94ac035 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YrS4JbZKxFbqr2malx6WncjypxIXa1PARVxGVDM2a8SOxnZcNPBfCzgVLDI9jI5MuHYr3RSoCWQ5KljzD7lYG8aMS/+mKaC0BjITJ0ZmmPHcCUaJt3bCU/e6kEhhhVR6IIUMUxA8PekTYr2iDlPA5SpnDx5mwGHtxD7EKFTDM9aQeVijqKz6cCFXKi3/Epbx5BiQ12koqsFhrDXBL7jQHA16JblO2h1edgIA/GC24sUQmx90Pc7ksIA/ZDx0ERNxDmxd1qUg0A57593iuPlLpBkO3IL/N/JSdCRU31IURYia4hH6zGR3h7pl1zghNgOSItPhrlAQOk+0Gs41wEQisWsoFoyAYL93/NHofuKC7ig5T9wFTlYWiW2EGN7IdEUUoI4DO9V0/WVgID+NU1d4okXrxyJDl9WEPVOjNmtTud5lPHM1MXwh1vKox3bQvOKEqJj5ERD9WWPrj7P7i1McSbao8tGc6V6t/i/8yaf9DxNMimxQ4K/ViMNdDq7uJALfQb1Z+tmbZ/HDipuPoxeb/5aVv0edGh32ql+OcJrPVpF3OwmGyEbNJdvXhJtRgwkiFgJ0PnuDIOoE3Zd+0f0X/gFe2ObYnTAL7BgueNDPzIjx4bJfW8RjTA7Qs7DACpYi X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TsVD6ObARFHiRheRVzCaXVoMtVJZEDrJI6evOTCgcsVKEi9qNErBKHfmOmLkhVp/Bx80FK7ZUv4+rvFyYPgM1/xfyLyDkxY2/GIpkltylDLWr7isdh5d0OAqxeaf2F6rNawviL9hXlXC4UqF7pu3RraAIrbMUCzEke2CWNqYJXL445TinDjdnM11Hz6P0gVBXf0AY78pUhadTpuPQEaXCj08ZbSnEhQYd+gWyBs+Typ6rDrz7mBbmp3n7gSQFmuY1R2Lwf7+Wsnx+akfuYp+7X1rlCVQlZQzY9k+J55ZEuxDpRgQpC+ql3hPrbTiDWYg0YplWZG0ClCiP0LxCbyPDcFtcM2JfLwbzGLnYziRJfeuJZoguQBbOPhR6wI91qi6QRMHPab6b5pZXlvxS5JtegRbdqjjSmYlhyeX4cpSauuL49KOeL7Bj3CpCMH9tHSB5af16dx/++r6/Zlh/q5NPbkqQN4G51ZtUBHuHuRtGXlADGeMzWD6EY5Z0VSVsKmlTap7I5B2NYjW5SLSSgxBZUa6RuvjZFEYeY/7R6VbC7gCIepLKiAJw0wvevCM6T66jcayElpQUBARHzRc4JU5UqCg/llcP2aHoby4yd0xCsaOX4BDERCmlq6MuMjtXCXY5ZUTXHza0C9d+P7hoQ8zi/bnW+5exQN0uUH+zhVOj1s6ZxAh6BbcMlR7r1TNt+62lv6kRCnmXXEv1JiAVa1tqVUkW6iLulFYMWHXcjYZgLDO5cfK5hd5/TqmXdK6nl8lUANT1DuLO5Sn4Bffq/TvYt10NvyuZg9QaXLZKJHk8hhQq/R/R1tztrOCQzfGQDv3VgPFVGY5/dnxaEsfPACl7vj4eQw6FQUPEl6ij5u2HL2Lmb9qsR8YATppip9DGPcR+/HyDHaiqzE34J4ev1Pfs+30Bl0bL3Yh6/JcKW1nrhDJeJ4+Ucr5c4yaTGqY9x90sJ0iw63NZxbFh5L5Y0tZu/a+eKsZe9H6L8OyIdbTVrN8/8/ncBaq9w+JCGNTSlIE50aEQMQQuGij6cyprFMQQ1cSkT4jbODDRd060i38ppLSpky1d7sJHfvZDluAlRjSLMfxZjiiOaW/g6hFQho5eHDGwrpDX9cI8wjIPrNmeEPbnI1MPthBkvWCw/jcFxrA7oL9X/mFxAG0b6ZJjaOjcDN89tF8lOru0Xsgb3aAdEEMU9vMNz+CNhhU1Lr+5lSXMXQAY7RMjQX390xTr/nnh2a41+dubWm3j+J0TGW2ZVORjzGURcYSROxfBk7z8BHU X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a9ed6953-4401-4c8e-69aa-08dbb94ac035 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:58:10.8867 (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: DU2P250MB0237 Subject: [FFmpeg-devel] [PATCH 24/42] avcodec/refstruct: Allow to share pools 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: QeMdJowFuwsi To do this, make FFRefStructPool itself refcounted according to the RefStruct API. Signed-off-by: Andreas Rheinhardt --- libavcodec/refstruct.c | 29 ++++++++++++++++------------- libavcodec/refstruct.h | 5 ++++- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/libavcodec/refstruct.c b/libavcodec/refstruct.c index f8d040874d..2108ff8163 100644 --- a/libavcodec/refstruct.c +++ b/libavcodec/refstruct.c @@ -187,7 +187,7 @@ static void pool_free(FFRefStructPool *pool) pthread_mutex_destroy(&pool->mutex); if (pool->free_cb) pool->free_cb(pool->opaque); - av_free(pool); + av_free(get_refcount(pool)); } static void pool_free_entry(FFRefStructPool *pool, RefCount *ref) @@ -278,13 +278,17 @@ void *ff_refstruct_pool_get(FFRefStructPool *pool) return ret; } -void ff_refstruct_pool_uninit(FFRefStructPool **poolp) +static void pool_unref(void *ref) { - FFRefStructPool *pool = *poolp; - RefCount *entry; + FFRefStructPool *pool = get_userdata(ref); + if (atomic_fetch_sub_explicit(&pool->refcount, 1, memory_order_acq_rel) == 1) + pool_free(pool); +} - if (!pool) - return; +static void refstruct_pool_uninit(FFRefStructOpaque unused, void *obj) +{ + FFRefStructPool *pool = obj; + RefCount *entry; pthread_mutex_lock(&pool->mutex); av_assert1(!pool->uninited); @@ -298,11 +302,6 @@ void ff_refstruct_pool_uninit(FFRefStructPool **poolp) pool_free_entry(pool, entry); entry = next; } - - if (atomic_fetch_sub_explicit(&pool->refcount, 1, memory_order_acq_rel) == 1) - pool_free(pool); - - *poolp = NULL; } FFRefStructPool *ff_refstruct_pool_alloc(size_t size, unsigned flags) @@ -317,11 +316,13 @@ FFRefStructPool *ff_refstruct_pool_alloc_ext_c(size_t size, unsigned flags, void (*free_entry_cb)(FFRefStructOpaque opaque, void *obj), void (*free_cb)(FFRefStructOpaque opaque)) { - FFRefStructPool *pool = av_mallocz(sizeof(*pool)); + FFRefStructPool *pool = ff_refstruct_alloc_ext(sizeof(*pool), 0, NULL, + refstruct_pool_uninit); int err; if (!pool) return NULL; + get_refcount(pool)->free = pool_unref; pool->size = size; pool->opaque = opaque; @@ -348,7 +349,9 @@ FFRefStructPool *ff_refstruct_pool_alloc_ext_c(size_t size, unsigned flags, err = pthread_mutex_init(&pool->mutex, NULL); if (err) { - av_free(pool); + // Don't call ff_refstruct_uninit() on pool, as it hasn't been properly + // set up and is just a POD right now. + av_free(get_refcount(pool)); return NULL; } return pool; diff --git a/libavcodec/refstruct.h b/libavcodec/refstruct.h index ce3830977f..d525be61e8 100644 --- a/libavcodec/refstruct.h +++ b/libavcodec/refstruct.h @@ -285,6 +285,9 @@ void *ff_refstruct_pool_get(FFRefStructPool *pool); * @param poolp pointer to a pointer to either NULL or a pool to be freed. * `*poolp` will be set to NULL. */ -void ff_refstruct_pool_uninit(FFRefStructPool **poolp); +static inline void ff_refstruct_pool_uninit(FFRefStructPool **poolp) +{ + ff_refstruct_unref(poolp); +} #endif /* AVCODEC_REFSTRUCT_H */ From patchwork Tue Sep 19 19:57:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43832 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp187073pzb; Tue, 19 Sep 2023 13:00:43 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF17BzaSwvbOvW5aOAr7Nx0dvwb2kLFyWTKxIbGCaJNs2RBb2FiLHG4FlP9rR2NfnMqzcAd X-Received: by 2002:a17:907:72d1:b0:9a9:9d19:b250 with SMTP id du17-20020a17090772d100b009a99d19b250mr4972713ejc.17.1695153642969; Tue, 19 Sep 2023 13:00:42 -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 v26-20020a170906859a00b0099bd19fe601si10849962ejx.533.2023.09.19.13.00.42; Tue, 19 Sep 2023 13:00:42 -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=pggwD43j; 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 B49D068C98B; Tue, 19 Sep 2023 22:58:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2080.outbound.protection.outlook.com [40.92.91.80]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E893068C93C for ; Tue, 19 Sep 2023 22:58:15 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZEPCw6HvRpTvgLNMzqP3mkRLlRJ1PnICVuCML6hD9aOrpck9pdpwt0aoYp8fivEZcKn//VrUqvLClNb/vuW8hK5QJnQi7qrDl5hp5T8hdG8oYuIoNCgxp4c0CrAZ+/O6zY6AyR9kd7v7guMVp6cu6jHBdZTlhKCpIhQsVHKzXcDynwXmm5lKoInoUqQEKp7siEnOeH16toYnrwYr93Rh1nWq17mS19yRvMmeTTFs/6Q910bQkl/8SvNksC9i7d0G5+TL+pLR67EpP/a2pi/b8uqQ3o+r2A8tIrrNyIrRYK67EN2iRKtIFUwwSd1feIkqfkZbjgmhZouiZG8pKV2l3w== 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=0g/JXqXnPr4Un4cF2KSGZxJ1QzibLeI7EGIfeyX2ySk=; b=i2c599Ue7aknXdVAy7g9rwUnH43sV5Mc2YKya68B0m067qlYla9/aGrN9yzyocKGuhAt2FaPlDWGRytaJbC2DrPpSJToQCl+FwHKWYkgA6kmaVNOw/LgMHmmT53N6dBj5XeN1rO8bLaRdtaoyarX6KziePZRWt5a0JBygXUYfDdQPVFxAVDvvugDrV2QWA2K+HVlVxfWu0fiOQJsEZZE8EkcjSfzHPdrX66ef7NKeO/a0e7porsMbw/a5W9/vbCe1WF1c7jv8D+5fibe20Lu0WU5m3gf4s1IfVHQZZb47eagADEwQ0GOeK6xmFEfr1Rc7rdlVBHN/S9bLtrk5wkCeg== 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=0g/JXqXnPr4Un4cF2KSGZxJ1QzibLeI7EGIfeyX2ySk=; b=pggwD43j3e2mWmbbtvpXHzGy5Z+nDMqDyPKXLLe6LqaFg4M4lPgSWBYx0ufN/sGSIPkU6cVvadm0E2dsHvL6Y7B8kO6AH7sfkKGocjFf+HNXLyfx0XfHhCMFaFXHhZmWcGXXuO5F9PsywLQlzgeOCMYdwfMjHOcVWgFzRljpzNl14Si/25cUao+OBaPbwUF4jFN4dvaPZKQ2Ui3SB62HLnCe0IYdXi7xuw46HdkcfxT18msueVGdxBdjI3njHUCBv6HJtTbqaoIYpxx7u9l8/PbovmLa3n/3HLosp0BDiYfs9a5YlsO2IKZ+zMyXdeJUe1nuGK94I6dRK+OsVfWOBA== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0237.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:276::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:58:14 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:58:14 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:17 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [gvPv7yUS4dnZ9NFwSdXTf1jL0tGbMLDq] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-25-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0237:EE_ X-MS-Office365-Filtering-Correlation-Id: a1ba53d6-4f91-49e1-2348-08dbb94ac250 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3fsfQ3FbpDXfIGFuh3k2w0t0dcUl+8vkhJnodkgNg1I+9TtylrpcJ1CdYOhYDNLZL1yheW00Mo8y1iSfNpaKwSJnT4DBlhwbUd5FN912fGyH8YwvR+UPX2JPk58J+07lwwFEwennI0/Qa1gCWH/v0KwOSwUkhNKwMKk++PAEF6XYGGovJXB2I6DaTi9POO0tFru6TRRnUeYFkIJSD72lyhMN/MT5ZS4sMqD8hLkNtiYGjQ/b/5dJAM03fFICb4tR58Lw6QSKSPafss6VKVIqqYFlSsIjJ9emAeinU9AaMQ5YEC9b46/YSmtTTORujCW2n8qGpB6rD9qWcjNf1yjNaqm2NoLNizs8IeFxO2l6zoQsijts45Ek2+AGWjvn/+ljVXFyY9DrNdxjJbezwTEk/wxnte9T4T56ULR1RyTlkgmmcH/3MSY7iOfJQTQY8XRWa82ZJ2fJ4VOVoSDIP9JCH3HwmuoQ5H+ii0mfJiZo9QdtQGvIAWfREeFWTph+L3HEhpJV9ALemvHUkkLed97xGQmIiDRMRUnRnC3o0vD+uw44GIIjcLYOkTQZ6e3pHDkWJ8FsgDOtjpB6zhwe61O8H5LhPO/I+KeNUrPLnqOmYSh3PGzyr3/eRPQ4nnHtlzpo X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qyDdvZuDlKzdkROcOYSj0GZToLkE1/1HQS+ZFXqP+9dy+h1M9nGn1ZC2aD3wmGQWDsJc69XjJX4luSR/bdYqIWjv3vDmynGU3B1d3+SiMweYS39IZPvrFpNWmE31HHSw3Xg4FGVoKIMW3QM/AduqOC+rf4bCu56A2C2eXn+IFngYCvtP32zvjMa8qHAdhR9PryGeKVluVjnwr9Zg0Mmn4AKu55tzwKa4mxPVkSB/rr4kU0uW3wfr1YT7ivnUeWVabQCgSIt9Vfj/KqnnLoQFGHHk2b5kNgxcGMuiU71luCYGifiFxyh866jrjR19NgTFUblacPr25XAcVDc2RHNFkpM9NCDfjtrdSC2yew5kRM53H+0ZhMnvKuQGvny9lIIA+N6T+CKyriAHAKs5hRxlWekGKUFblpan4/MBNAVAVJOj+ZL9GGsrwlkU/c2vQMb1BTVgvE7IcAq7r/v6gYzgRouGamRULKLRTfYRpbHMEMrlLiclLg8fNhcGfsGpqfB+7vywwF2ybiDbSm93GVUUbwTe1qs+TtHWbxKqZ6y0y9UshQu536tLlIWqHQVxg7qOHAhV0k7wLink59RUO9zUavgrNVdBuy3/PGBoXfcXNQyP1Z0936NmJaAUR3zO8+/wAYpQMLccU0ZbiVMW+yXiRY8qB7q7ud217IFWKJy0pH7PI62uSp7/2/SyquIFPIA3TthY/DqFOG6Fz5CsH9ZQSIP+km24B6Nf5TWr/609gPUPZT1XIufv78YUT5eWH5+ms4XzvLV3qsbhFK41Kvw9Aw12Vmyghsr5fD53LmTl4gSDiCtRAMYqTgQSyYfr4zAb8cJipAiKJG6S6X642eaQ9K6mPnIei83CLF6UmvFEXeyXd3htrtYwxRVXbcC05VmTu/8c1rgY50EP7c8FERV9zeeskhyIIAgMlzla9ES633m4N6K5Agh1adDV3Pp/DwjQdHdt9fLTE5QfkCUzQIADMZvWmschVBzy+XYFWglD7YyPbL99eQBdQQWkAU+nh9Ts96UMUHis76MNJn8rJb1/ERB1i1EjLBOOHGorJ+UmtvGYLtlKHvTU54aVj/Ra/9uwc2LZVbWY7MMrqAc96qmA0m+NcnHSiNuYIHruYvbJiouj+Ta5IP68DshAmb7r/0OHPr7R4FmRzmFyweGO3LUiK0cZiImGtpSaXQuf1eh2eUnom3kQuA3oq+zdj/ooAP3RtsN+1qDtfU6DeHo+NNHq+UGjaPpSuA60rPGRcao6Veji2B2K3slf0JOrnl7NsZ51 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: a1ba53d6-4f91-49e1-2348-08dbb94ac250 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:58:14.4507 (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: DU2P250MB0237 Subject: [FFmpeg-devel] [PATCH 25/42] avcodec/vp9: Join extradata buffer pools 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: 2UgMdNNrVNHN Up until now each thread had its own buffer pool for extradata buffers when using frame-threading. Each thread can have at most three references to extradata and in the long run, each thread's bufferpool seems to fill up with three entries. But given that at any given time there can be at most 2 + number of threads entries used (the oldest thread can have two references to preceding frames that are not currently decoded and each thread has its own current frame, but there can be no references to any other frames), this is wasteful. This commit therefore uses a single buffer pool that is synced across threads. Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 4acfca2b4f..dac81fd712 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -1845,6 +1845,8 @@ static int vp9_decode_update_thread_context(AVCodecContext *dst, const AVCodecCo return ret; } } + ff_refstruct_replace(&s->frame_extradata_pool, ssrc->frame_extradata_pool); + s->frame_extradata_pool_size = ssrc->frame_extradata_pool_size; s->s.h.invisible = ssrc->s.h.invisible; s->s.h.keyframe = ssrc->s.h.keyframe; From patchwork Tue Sep 19 19:57:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43833 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp187206pzb; Tue, 19 Sep 2023 13:00:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEy3Uu52gs7+SrLGgJYvgV7McGApDMeI3WlJ4sZtX2XvoRac5uUV+hTyFjUz13D3eU1AhPI X-Received: by 2002:a17:906:8465:b0:9ad:8782:3d7 with SMTP id hx5-20020a170906846500b009ad878203d7mr302936ejc.51.1695153653603; Tue, 19 Sep 2023 13:00:53 -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 f15-20020a170906560f00b0099e0daaa531si11143292ejq.556.2023.09.19.13.00.52; Tue, 19 Sep 2023 13:00:53 -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=Ef0TAWl6; 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 BB50068C9CC; Tue, 19 Sep 2023 22:58:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01olkn2035.outbound.protection.outlook.com [40.92.65.35]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 14AE068C942 for ; Tue, 19 Sep 2023 22:58:18 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B/BbDeg1KCI/KA7UBwy53VQptuQvCAOQ72f4fazAZZ/dGFF6irLAVzgrdpC74E+TUNS+kDJi2sNt0f6SIeXzu2GdkdxU9YbZpJv0bhxA6wUqVmkfKzOd/rfm+WbVoaqE++DJBJJ3Xx7y6yTcxmwtRFctJkVCEBiXziZc/mpyzIEtrXNv2e4eNFzA2EOC09x+HgGW53Ee+t2CE5WpckjZRpDbRSFySRruzeootFIclLU0w6Kvj/LKx+U0Z24q/aRlOxeuoscR83awW5LZGrerdnbIUztmeZVI/Uu3DYrFjvZLcqkvy6xJ5hwuZjGDYDPGBkO+1z15D19qFJzuPMD7MA== 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=4NaURpCT/S2fr5reCtwTIglpxxdIGGmD9Pbq8StZK2k=; b=SypVDE9YiGCzKmV/e/2h5helkCyJrT2FzFdZl9XzE6rIBSL8hYUd2S+OJbZQUuF7FhhRRz8dikmpHZyK6lpfX/H3ASdfBAmi3pTFvJmtiYPdvQfbxac/Gao6hFfyng6xqADM984nNgu7fqldWIxB2SVgPyPYWC+Qcs6dDVzsyfdp0kkl2TZV2BF88kwHrRTCSrRGDZ5hjjnYq1lDUB3u7SJ56Abmua+SxuS5lKb2rN1YJ+zQxI/YAxkW4wrRkH/6H4AzNKMLd5MHid1Ol1WIRSMStCouS6HTFjU51DKZl1pbKpyu4gGU3iSFCQMp41qXIHYp2MYDbXpps0VTnRf71w== 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=4NaURpCT/S2fr5reCtwTIglpxxdIGGmD9Pbq8StZK2k=; b=Ef0TAWl65C3x1M7k2Ehn7OlwYyv8bc1GWXN0IEPVgcFR0VS4r6rHa9DQ6QuGeHo3/rgvegoxRe8m34mL/9729SZt+HX6y+rVvr/pn1tr1chVlwxNgSYSXVRVp92ULC4L5NpDYYQBs5F8246NM8t69ETcJneEFjoFIAbLebUng6W4Tep1PYaeIgLgBzMzuIPN9MjgQ2Kz5Q0iTv+dJIqpZ9R471Fc434FwhM0JNjO3QAlRUfQC7fdOnJsAmtbEWji9Cx1N7oKKeWV3UxzdV3p/UaN5Bh/plMIj9Q++kz1JUGcatHGAjUF43mlmOlFcBNW/6VQBjeXIYxFKk5Q+SjyhA== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0237.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:276::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:58:16 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:58:16 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:18 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [pKHcfx4HiFA9ObEdxMwPq1aBOrYVdzs0] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-26-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0237:EE_ X-MS-Office365-Filtering-Correlation-Id: 600a96c6-66e8-4678-0044-08dbb94ac3c4 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: gDb2TA7Rram4ik+WpqCeqr7t2DlgHDlie4IC/344ZIRKuiRo4FOZ+8HTvw0POgnuqHW7HXU7ZvjNd1OjwZ3I2RCYZufAmxvtOEjaxEBmjSghCrNioLbk0n+fmTz/RgcJN8skenietPLpBv+Hh/iD18uwL6vQ0sYybmlBiud8gmKysCSEZpU2AGT69pKUew3PzEmYb1lcXjvPJMTFBfYiZJcWapPiw3PCp0HAY4nfKjArTXATGPY+QiH73cFxvCmEdYUsaCQfVEH3I4LATb+dqPGvxK/FMVldWh719I7/5l0NjmJFLvVvL9am36QEL0hDOoNekLikXfAoYA66jBfKXQmpGyxyvk3LsGE1xQEW6jbfWZYMetGcdEpqRnOPHJeYxEPCQy93m094Jxaa5njbWSVuSd5FWmz6tJ/IAIaMyazX1EXGgYiWsglvNHEiwNHa3cv/pf82Y8FzjVXuwfa6jJGYJoHHNiFO1c/GQpF9zKnFYFjTGR8O+YKeWaohq6gKPT7cugJgl1PNpQZqRcw9xZbozYoEnSVp0J+HaKFK95icTWsA0rDHLUEP6vr/nnJmxQG38wqFB80+SR91ZwRdhUG+46I4h2sX0xamSpZap9Q= X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: LLRFmjm7Pp8SIR5xin+EAj/fpZoJdV2kWu5i0aW3nUaOkfTJ7tYvbp/81MpMCXy3K6rjpG0fBVg11Fncort/tUpxx0+edaOWMBDNZhuHKMt7ZxIfMD/7Fitd+ITxIw2s2qJ26VH3PmVvxlgPaz0WPqfr7a7+9L+N3uOJ9w5UKWn2F9n46bY0sKIlUMhrjdaqGC2B9y9h3nmlPJ5YV7TgrGsfkj3nOvFK+q76EnOOqwXR1lMux6qDkMrEecdJk+qfwNSe2O4Ec3EJehwPGMtP3G7Ifdm+4MAxCk4WMkGT9Jy5wqbhMpWAWa0W5GQ+0C8B/RMq78d0e9OLlqk60pN4NIGH5ItW0pOekATTuOdTkm3t8Ce5Ce47O6xPRoAWSMUGucAz2bdnTupPrpaSA0csFzVwOVCj1eSG9xrSbtFAwuApEJvt3Y0daDlWMQCI+L/CtH4AneGgoeVL8T3W2ZdJvGu8JpzRgihQEnB6H+ZJ9lBJNxxl6Qwef8d2zXLlpnav/FKFHSwv3sifNJU1uTjS0udYjOZZY93xUiQrEeWDSZanlxWmH1O0g24gxbRM6K+kIJmaCX7cDchaEWAUbg7oH578hVh0ZfF6MLMXwZW8f/qhfbM9QWwaPCs0IF+DN74tXlcgTV0ekVNIQL2wmd2RchYLQKsHBWjtbr+EPiqyWMltJPF+XHzC8P7iR4PhggkrgD5tXRhpvnT8DV1pE1RT0PO9C3mxXCS3xT9kUVpIkDBd4zRI4hZ/qcXbybdPjhAcrNjw0RTskPJaNgZy0Vo0NNF11TcW3YP0T0geU27pAPI1iOMeBX1RF/MTz1r7/AOwBa8D611f/RsUh+heXTVaG1nUEKAiiHWY0XOIlW92ZKDHhFwJyikubFYtxtEQmrhJuvNU9zX1yJQ57JfRqI3BPurg34TnEQTxi6OTVSDxbMXvlaba0zJ0WsjSO+nPC4Gl8QyEBHdfJlokfS56aelHPK0MGamycBZwIySiXDNDIZvQAnBBqC2p1KQrrUkgahWjTbUnGgj2f1MWk+WsSged1O6fg8VgiZkuie34iQbb9y+8jx6X+KtfbVdXp3SBD9/s3dRrPfWRe4URF2A6qTF1zBeK8ws1SHeRGuW0f99Z10a6CrwKAfbWuc1H4XPTaet8BVMJJ3AR7Oo9YEANkEyowU2Ml9r2Zk3ssLv5uwJO1xwfeqmHSIg5qi5i50d52013zrSd7kIatSwvCtyyvN268sa4Y3AKH8ZSYmsRA0RKP6umysqI26boSFuNn/disEwF X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 600a96c6-66e8-4678-0044-08dbb94ac3c4 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:58:16.9063 (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: DU2P250MB0237 Subject: [FFmpeg-devel] [PATCH 26/42] avcodec/refstruct: Allow to use a dynamic opaque 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: WaVtUWochjkO This is in preparation for a new ThreadFrame-API based around RefStruct to allow to pass the AVCodecContext* to ff_thread_release_buffer(). Signed-off-by: Andreas Rheinhardt --- Now that thread-unsafe callbacks are no more, one could also just use av_frame_unref() instead of ff_thread_release_buffer(). But this is IMO more elegant. libavcodec/cbs.c | 8 ++-- libavcodec/refstruct.c | 83 +++++++++++++++++++++++++++++++++--------- libavcodec/refstruct.h | 83 ++++++++++++++++++++++++++++++++++++++---- 3 files changed, 146 insertions(+), 28 deletions(-) diff --git a/libavcodec/cbs.c b/libavcodec/cbs.c index 00c462b09d..40235ce647 100644 --- a/libavcodec/cbs.c +++ b/libavcodec/cbs.c @@ -903,11 +903,13 @@ static const CodedBitstreamUnitTypeDescriptor static void *cbs_alloc_content(const CodedBitstreamUnitTypeDescriptor *desc) { + FFRefStructUnrefCB unref_cb; + unref_cb.unref = desc->content_type == CBS_CONTENT_TYPE_COMPLEX + ? desc->type.complex.content_free + : cbs_default_free_unit_content; return ff_refstruct_alloc_ext_c(desc->content_size, 0, (FFRefStructOpaque){ .c = desc }, - desc->content_type == CBS_CONTENT_TYPE_COMPLEX - ? desc->type.complex.content_free - : cbs_default_free_unit_content); + unref_cb); } int ff_cbs_alloc_unit_content(CodedBitstreamContext *ctx, diff --git a/libavcodec/refstruct.c b/libavcodec/refstruct.c index 2108ff8163..817a8a455a 100644 --- a/libavcodec/refstruct.c +++ b/libavcodec/refstruct.c @@ -20,6 +20,8 @@ #include #include +#include "config.h" + #include "internal.h" #include "refstruct.h" @@ -37,8 +39,11 @@ typedef struct RefCount { */ atomic_uintptr_t refcount; FFRefStructOpaque opaque; - void (*free_cb)(FFRefStructOpaque opaque, void *obj); + FFRefStructUnrefCB free_cb; void (*free)(void *ref); +#if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 1 + unsigned flags; +#endif } RefCount; #if __STDC_VERSION__ >= 201112L @@ -63,16 +68,19 @@ static void *get_userdata(void *buf) } static void refcount_init(RefCount *ref, FFRefStructOpaque opaque, - void (*free_cb)(FFRefStructOpaque opaque, void *obj)) + unsigned flags, FFRefStructUnrefCB free_cb) { atomic_init(&ref->refcount, 1); ref->opaque = opaque; ref->free_cb = free_cb; ref->free = av_free; +#if defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 1 + ref->flags = flags; +#endif } void *ff_refstruct_alloc_ext_c(size_t size, unsigned flags, FFRefStructOpaque opaque, - void (*free_cb)(FFRefStructOpaque opaque, void *obj)) + FFRefStructUnrefCB free_cb) { void *buf, *obj; @@ -81,7 +89,7 @@ void *ff_refstruct_alloc_ext_c(size_t size, unsigned flags, FFRefStructOpaque op buf = av_malloc(size + REFCOUNT_OFFSET); if (!buf) return NULL; - refcount_init(buf, opaque, free_cb); + refcount_init(buf, opaque, flags, free_cb); obj = get_userdata(buf); if (!(flags & FF_REFSTRUCT_FLAG_NO_ZEROING)) memset(obj, 0, size); @@ -105,9 +113,31 @@ void ff_refstruct_unref(void *objp) memcpy(objp, &(void *){ NULL }, sizeof(obj)); ref = get_refcount(obj); + av_assert1(!(ref->flags & FF_REFSTRUCT_FLAG_DYNAMIC_OPAQUE)); + if (atomic_fetch_sub_explicit(&ref->refcount, 1, memory_order_acq_rel) == 1) { + if (ref->free_cb.unref) + ref->free_cb.unref(ref->opaque, obj); + ref->free(ref); + } + + return; +} + +void ff_refstruct_unref_ext_c(FFRefStructOpaque opaque, void *objp) +{ + void *obj; + RefCount *ref; + + memcpy(&obj, objp, sizeof(obj)); + if (!obj) + return; + memcpy(objp, &(void *){ NULL }, sizeof(obj)); + + ref = get_refcount(obj); + av_assert1(ref->flags & FF_REFSTRUCT_FLAG_DYNAMIC_OPAQUE); if (atomic_fetch_sub_explicit(&ref->refcount, 1, memory_order_acq_rel) == 1) { - if (ref->free_cb) - ref->free_cb(ref->opaque, obj); + if (ref->free_cb.unref_ext) + ref->free_cb.unref_ext(opaque, ref->opaque, obj); ref->free(ref); } @@ -161,7 +191,7 @@ struct FFRefStructPool { size_t size; FFRefStructOpaque opaque; int (*init_cb)(FFRefStructOpaque opaque, void *obj); - void (*reset_cb)(FFRefStructOpaque opaque, void *obj); + FFRefStructUnrefCB reset_cb; void (*free_entry_cb)(FFRefStructOpaque opaque, void *obj); void (*free_cb)(FFRefStructOpaque opaque); @@ -221,14 +251,23 @@ static void pool_reset_entry(FFRefStructOpaque opaque, void *entry) { FFRefStructPool *pool = opaque.nc; - pool->reset_cb(pool->opaque, entry); + pool->reset_cb.unref(pool->opaque, entry); +} + +static void pool_reset_entry_ext(FFRefStructOpaque opaque, + FFRefStructOpaque initial_opaque, + void *entry) +{ + FFRefStructPool *pool = initial_opaque.nc; + + pool->reset_cb.unref_ext(opaque, pool->opaque, entry); } -static int refstruct_pool_get_ext(void *datap, FFRefStructPool *pool) +static int refstruct_pool_get_ext(void *objp, FFRefStructPool *pool) { void *ret = NULL; - memcpy(datap, &(void *){ NULL }, sizeof(void*)); + memcpy(objp, &(void *){ NULL }, sizeof(void*)); pthread_mutex_lock(&pool->mutex); av_assert1(!pool->uninited); @@ -243,8 +282,13 @@ static int refstruct_pool_get_ext(void *datap, FFRefStructPool *pool) if (!ret) { RefCount *ref; - ret = ff_refstruct_alloc_ext(pool->size, pool->entry_flags, pool, - pool->reset_cb ? pool_reset_entry : NULL); +#define CB_INIT(suffix) ((FFRefStructUnrefCB) { .unref ## suffix = pool->reset_cb.unref ## suffix ? \ + pool_reset_entry ## suffix : NULL }) + ret = ff_refstruct_alloc_ext_c(pool->size, pool->entry_flags, + (FFRefStructOpaque){ .nc = pool }, + (pool->pool_flags & FF_REFSTRUCT_FLAG_DYNAMIC_OPAQUE) ? + CB_INIT(_ext) : CB_INIT()); +#undef CB_INIT if (!ret) return AVERROR(ENOMEM); ref = get_refcount(ret); @@ -253,7 +297,7 @@ static int refstruct_pool_get_ext(void *datap, FFRefStructPool *pool) int err = pool->init_cb(pool->opaque, ret); if (err < 0) { if (pool->pool_flags & FF_REFSTRUCT_POOL_FLAG_RESET_ON_INIT_ERROR) - pool->reset_cb(pool->opaque, ret); + pool->reset_cb.unref(pool->opaque, ret); if (pool->pool_flags & FF_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR) pool->free_entry_cb(pool->opaque, ret); av_free(ref); @@ -266,7 +310,7 @@ static int refstruct_pool_get_ext(void *datap, FFRefStructPool *pool) if (pool->pool_flags & FF_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME) memset(ret, 0, pool->size); - memcpy(datap, &ret, sizeof(ret)); + memcpy(objp, &ret, sizeof(ret)); return 0; } @@ -312,7 +356,7 @@ FFRefStructPool *ff_refstruct_pool_alloc(size_t size, unsigned flags) FFRefStructPool *ff_refstruct_pool_alloc_ext_c(size_t size, unsigned flags, FFRefStructOpaque opaque, int (*init_cb)(FFRefStructOpaque opaque, void *obj), - void (*reset_cb)(FFRefStructOpaque opaque, void *obj), + FFRefStructUnrefCB reset_cb, void (*free_entry_cb)(FFRefStructOpaque opaque, void *obj), void (*free_cb)(FFRefStructOpaque opaque)) { @@ -330,10 +374,15 @@ FFRefStructPool *ff_refstruct_pool_alloc_ext_c(size_t size, unsigned flags, pool->reset_cb = reset_cb; pool->free_entry_cb = free_entry_cb; pool->free_cb = free_cb; -#define COMMON_FLAGS FF_REFSTRUCT_POOL_FLAG_NO_ZEROING +#define COMMON_FLAGS (FF_REFSTRUCT_POOL_FLAG_NO_ZEROING | FF_REFSTRUCT_POOL_FLAG_DYNAMIC_OPAQUE) pool->entry_flags = flags & COMMON_FLAGS; + // Dynamic opaque and resetting-on-init-error are incompatible + // (there is no dynamic opaque available in ff_refstruct_pool_get()). + av_assert1(!(flags & FF_REFSTRUCT_POOL_FLAG_DYNAMIC_OPAQUE && + flags & FF_REFSTRUCT_POOL_FLAG_RESET_ON_INIT_ERROR)); // Filter out nonsense combinations to avoid checks later. - if (!pool->reset_cb) + if (flags & FF_REFSTRUCT_POOL_FLAG_RESET_ON_INIT_ERROR && + !pool->reset_cb.unref) flags &= ~FF_REFSTRUCT_POOL_FLAG_RESET_ON_INIT_ERROR; if (!pool->free_entry_cb) flags &= ~FF_REFSTRUCT_POOL_FLAG_FREE_ON_INIT_ERROR; diff --git a/libavcodec/refstruct.h b/libavcodec/refstruct.h index d525be61e8..b0a750e2f7 100644 --- a/libavcodec/refstruct.h +++ b/libavcodec/refstruct.h @@ -53,18 +53,42 @@ * * The functions provided by this API with an FFRefStructOpaque come in pairs * named foo_c and foo. The foo function accepts void* as opaque and is just - * a wrapper around the foo_c function; "_c" means "(potentially) const". + * a wrapper around the foo_c function for the common case of a non-const + * opaque ("_c" means "(potentially) const"). For the allocation functions + * the wrappers also accept the ordinary "unref" form of FFRefStructUnrefCB; + * only the "_c" versions accept the full union to set the unref_ext variant. */ typedef union { void *nc; const void *c; } FFRefStructOpaque; +typedef union FFRefStructUnrefCB { + void (*unref)(FFRefStructOpaque opaque, void *obj); + void (*unref_ext)(FFRefStructOpaque dynamic_opaque, + FFRefStructOpaque initial_opaque, + void *obj); +} FFRefStructUnrefCB; + /** * If this flag is set in ff_refstruct_alloc_ext_c(), the object will not * be initially zeroed. */ #define FF_REFSTRUCT_FLAG_NO_ZEROING (1 << 0) +/** + * This flag being set indicates that the free_cb union is in + * the unref_ext-state. + * In this case unreferencing the object has to be done + * via ff_refstruct_unref_ext() instead of ff_refstruct_unref(). + * Using the latter is forbidden and leads to undefined behaviour. + * + * The free_ext-callback will be called when the refcount reaches zero + * with the opaque given to ff_refstruct_unref_ext() passed along as + * the callback's dynamic_opaque parameter; the argument corresponding + * to the initial_opaque parameter will be the opaque provided to + * ff_refstruct_alloc_ext_c() and obj is the object to be unreferenced. + */ +#define FF_REFSTRUCT_FLAG_DYNAMIC_OPAQUE (1 << 1) /** * Allocate a refcounted object of usable size `size` managed via @@ -76,17 +100,19 @@ typedef union { * @param size Desired usable size of the returned object. * @param flags A bitwise combination of FF_REFSTRUCT_FLAG_* flags. * @param opaque A pointer that will be passed to the free_cb callback. - * @param free_cb A callback for freeing this object's content + * @param free_cb Contains the callback for freeing this object's content * when its reference count reaches zero; * it must not free the object itself. + * The state of free_cb is indicated by the + * FF_REFSTRUCT_FLAG_DYNAMIC_OPAQUE flag. * @return A pointer to an object of the desired size or NULL on failure. */ void *ff_refstruct_alloc_ext_c(size_t size, unsigned flags, FFRefStructOpaque opaque, - void (*free_cb)(FFRefStructOpaque opaque, void *obj)); + FFRefStructUnrefCB free_cb); /** * A wrapper around ff_refstruct_alloc_ext_c() for the common case - * of a non-const qualified opaque. + * of a non-const qualified and non-dynamic opaque. * * @see ff_refstruct_alloc_ext_c() */ @@ -95,7 +121,7 @@ void *ff_refstruct_alloc_ext(size_t size, unsigned flags, void *opaque, void (*free_cb)(FFRefStructOpaque opaque, void *obj)) { return ff_refstruct_alloc_ext_c(size, flags, (FFRefStructOpaque){.nc = opaque}, - free_cb); + (FFRefStructUnrefCB){ .unref = free_cb }); } /** @@ -107,6 +133,10 @@ void *ff_refstruct_allocz(size_t size); * Decrement the reference count of the underlying object and automatically * free the object if there are no more references to it. * + * This function must not be used if the object has been created + * with the dynamic opaque flags (FF_REFSTRUCT_FLAG_DYNAMIC_OPAQUE + * or FF_REFSTRUCT_POOL_FLAG_DYNAMIC_OPAQUE for objects from pools). + * * `*objp == NULL` is legal and a no-op. * * @param objp Pointer to a pointer that is either NULL or points to an object @@ -114,6 +144,32 @@ void *ff_refstruct_allocz(size_t size); */ void ff_refstruct_unref(void *objp); +/** + * Decrement the reference count of the underlying object and automatically + * free the object if there are no more references to it. + * + * This function may only be used of the object has been created + * with the dynamic opaque flags (FF_REFSTRUCT_FLAG_DYNAMIC_OPAQUE + * or FF_REFSTRUCT_POOL_FLAG_DYNAMIC_OPAQUE for objects from pools). + * + * `*objp == NULL` is legal and a no-op. + * + * @param objp Pointer to a pointer that is either NULL or points to an object + * managed via this API. `*objp` is set to NULL on return. + */ +void ff_refstruct_unref_ext_c(FFRefStructOpaque opaque, void *objp); +/** + * A wrapper around ff_refstruct_unref_ext_c() for the common case + * of a non-const qualified dynamic opaque. + * + * @see ff_refstruct_alloc_ext_c() + */ +static inline +void ff_refstruct_unref_ext(void *opaque, void *objp) +{ + ff_refstruct_unref_ext_c((FFRefStructOpaque){ .nc = opaque }, objp); +} + /** * Create a new reference to an object managed via this API, * i.e. increment the reference count of the underlying object @@ -215,6 +271,16 @@ typedef struct FFRefStructPool FFRefStructPool; * flag had been provided. */ #define FF_REFSTRUCT_POOL_FLAG_ZERO_EVERY_TIME (1 << 18) +/** + * This flag being set indicates that the reset_cb union is in + * the unref_ext-state. The semantics of FF_REFSTRUCT_FLAG_DYNAMIC_OPAQUE + * apply with the opaque given to ff_refstruct_alloc_ext_c() + * corresponding to the opaque given to ff_refstruct_pool_alloc_ext_c(). + * + * This flag is incompatible with FF_REFSTRUCT_POOL_FLAG_RESET_ON_INIT_ERROR. + * Giving both to a pool allocation function leads to undefined behaviour. + */ +#define FF_REFSTRUCT_POOL_FLAG_DYNAMIC_OPAQUE FF_REFSTRUCT_FLAG_DYNAMIC_OPAQUE /** * Equivalent to ff_refstruct_pool_alloc(size, flags, NULL, NULL, NULL, NULL, NULL) @@ -240,13 +306,13 @@ FFRefStructPool *ff_refstruct_pool_alloc(size_t size, unsigned flags); FFRefStructPool *ff_refstruct_pool_alloc_ext_c(size_t size, unsigned flags, FFRefStructOpaque opaque, int (*init_cb)(FFRefStructOpaque opaque, void *obj), - void (*reset_cb)(FFRefStructOpaque opaque, void *obj), + FFRefStructUnrefCB reset_cb, void (*free_entry_cb)(FFRefStructOpaque opaque, void *obj), void (*free_cb)(FFRefStructOpaque opaque)); /** * A wrapper around ff_refstruct_pool_alloc_ext_c() for the common case - * of a non-const qualified opaque. + * of a non-const qualified and non-dynamic opaque. * * @see ff_refstruct_pool_alloc_ext_c() */ @@ -259,7 +325,8 @@ FFRefStructPool *ff_refstruct_pool_alloc_ext(size_t size, unsigned flags, void (*free_cb)(FFRefStructOpaque opaque)) { return ff_refstruct_pool_alloc_ext_c(size, flags, (FFRefStructOpaque){.nc = opaque}, - init_cb, reset_cb, free_entry_cb, free_cb); + init_cb, (FFRefStructUnrefCB){ .unref = reset_cb }, + free_entry_cb, free_cb); } /** From patchwork Tue Sep 19 19:57:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43834 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp187342pzb; Tue, 19 Sep 2023 13:01:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH/iX/fMz3eL9TyEtBNzmb0j5pM5pCL+YREr4cAmZ2Qbx6fVHJEEFp2cmQ5mx1KZjRBSM3Z X-Received: by 2002:aa7:cc1a:0:b0:525:442b:6068 with SMTP id q26-20020aa7cc1a000000b00525442b6068mr439189edt.13.1695153664543; Tue, 19 Sep 2023 13:01:04 -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 l15-20020a056402124f00b005234ee297e0si10470808edw.267.2023.09.19.13.01.04; Tue, 19 Sep 2023 13:01:04 -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=vGtZquXd; 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 CE59C68C9C6; Tue, 19 Sep 2023 22:58:23 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01olkn2061.outbound.protection.outlook.com [40.92.65.61]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1F3B868C9CD for ; Tue, 19 Sep 2023 22:58:21 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LcDc0DTlk1q+GuL4UBIaThmq/WB0INxkkeiUUhcCcfAxXuqVk1Vqp0KSb1seTVri5RbXiMHGcxHYO22p4HJ66bSzo4JPrr8LqLI9qKjJToWdaA1bKNN8E/TpXiVf9qcD40okamahcBs79o6Qa5q38Pxoj/uG+28efN3ypl8Ku+Tl4b6WQakpheSWBE80DAgAsW/1+pV0ru9Zz1pqppk6IGa+1YzP01wIea7+Be29ZibfZmfMLCQxNcPtEYocyZx5HXCqX54Jr/aknOpEoYWHjAGf6bFDD7liOYgardX8TM1lLJ7jeh/ldu5rP5L6avitUccbdpwDXTtA0SESUI/QLA== 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=TTkctxvM4MLPf0+EuT5LyTxsTA+BdYE7CXx/926Vue8=; b=YxhVyHhYdHHxBvUs63WnFeGGxYS7H5HUXd/lrNPDxJGzSJu+TnqVH68/81OtpZqOtyus26zHpW4OKaEoWNoqbA8jViy6CqJqxEqVEhsGbgOfzZyJMJOGglPc09oigFoQkPq6WlXW3/vD23gtRdz01Y88nB4xEMqAcwX/HHp5z1IU6yDbAUk4qLEDGF2dfRjCPvk3PCjz7E6jmgoQrUupBGobl4vfPZe7R3bjPkmhzNOE6OiakKBtB/WDX4GXd2OtNrZkg8k7CzKQfizH3+v9LwvIy3VINyHpISfd3bbp+tf+MmdBSd+jbJ0vCVZ5rHxixshJu1XAqbCMlVemYesh7w== 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=TTkctxvM4MLPf0+EuT5LyTxsTA+BdYE7CXx/926Vue8=; b=vGtZquXdFoarHlbraWYpbZPkWjMyp2CmDPOL+OvAmNXnZDiprIpWn3i664psaTDRFycLQjrCIMKJfCrGMjwmk67wftyNMlRWWV+/WFnqQZAAZeUBWW/GwYR5m4FARlHFiy7+RRC9zl3qaSsa1GFon8X933zboZWx1But8TGLJYnB3I7pZHo4y3mx/izM5ZgM7zygwuySaqZAF1kpQLzY0Ldd4K/dTytnwqIqsnBYd835LGXCvDJhUVJufLzjJTurs5TgZAO8MW6PUdVCXDsJn4Wg3V+Yfqdkd+wZVDpj89XkZBZOy/7e9REdXPIlHcYsfbp6kaz6xXQCgj36ZSpKaQ== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0237.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:276::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:58:20 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:58:20 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:19 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [+qQiAhI1LYGTyjRkRDRSB7ae28tlaNkj] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-27-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0237:EE_ X-MS-Office365-Filtering-Correlation-Id: e1167408-0961-41f6-6f77-08dbb94ac5b1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GmCDpQSoqoOm1Rd4x5ZHoe5q4y9zywrTB50rznzLK7slunKy+kIgTkXBN2ayv21byEskJ24bTVhbdA0VHATkydPdtpx9fKIwwXKNbUQcP7FQNKA4bdVfAqTS/UVeIA/gcQbESyU3PYvsAjObhZ68/wKn/+oP2xU0jACzuzpdRdwE4E54wZreAA6XZDLLKvnqs3V8dFDCNlcC2ZldyE9lURt79mAw5xFTvuKxLSk2oY4hlQ0rLSbS5Qv3Jxs5hgIR6XfFEnCXNccohz0YB/G/vZcxW5xJMM/+VaSXPp6ThFqu1R0/PW2RvKiVZMDemPdtH4LL5fbW/MdjEkB7HajisJTc+/S1ndMVnbQjnGB9znaQBzavpSs7WNs+D2I9xWuzIBDE9H8Pvkly0I0mg2twnPoOMpqKtklCxpDqiCud8za5A/99CLZNHs56M36W8BxEEiks11wBPZ2fe9bvMz2SHbB0GcFs4qYxj/hxvpwNAbfcoQstG05YeFWZ/ccim3tPrRTgqp1DlAYw+QQiZNARFpXNJ6627PTrzNc3lkw1CHFIR5r2FtkpW6zFw/p1dNrcYAommHEgGexI4h3hqw5vbwKfsYQ+r2HTL1Ihx1bYQYSKKgtp6kgMhadBZeV69Rry X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: z/VnARJ0H1RDad9MDvmuJRoReBE/l0grv0UEMaE8NfDhgx1PgA8IQ0cMZC/oDG4YEES7VVeafdGY7Mzuab+SE9HwK2XESYKq6fSCp3Gy+ofa2m5ma1Tua9eBYWpsnsYl48ojuBM15Dwdz3wRBu1fs4WlLBjRar1M239rWASp2YzH4xiAJqaua7eo4w03wGEs4yGm9b7zgyPzAcIPhf0/a/0brNxwmQBCPtyPybrewnYqR+PCwUJ/glTp2pVLBfUMEaV0NVL98w34MTKN9PVwsBXfH5/pbqE5v6cmeywPnoTh4bWHVUloT0Tujyjghrhk7ConXNQiobtZlC6U2zFM/nayzR+bprA/aWYyAHO4FKIrVDERnwJiy/fTT3PRjszmcMfAjG0M64I7gQF5Ue4l4FZtBMo2YbGoBy3Ih9Cq+MKJBJk3e77c4GpAjXfLz9RNKXUF4t9Hirw6LfM03fMUKSQVrqSlZveEL/q2nARgH71i30RHbaRFw9uswlxsDEzHJcCyqIzN+Ps3PdtdQIxq6vR7wV+k83XaCkX44eueGXaoMMxpTlq0XxClJE9tYldtIRC0QfwxN9GpP1sIpHDRK9CPXMMFjaZfdebC23hE4IEUGXUw4gV6reKdU6OoNSmwn0dB/9hCdSs4K/Nd8bfuR/sDsqUQqlIUPEcUzv750htre5gmBRSmneIkcDlI9IDcI1DmPhfeeP3e5IkaELHYUVQb7g59nIRi3OxOWAE/Ed8Zx3WQIeBLBxA8ZbI/wMWUcx0fJZiQmh57kXWQvOiM6nFqeEvbNjz4CFYhvuCyQGL9A6EQhe3lkTbHBvP4BSZvkFWB88yc6uqv4QH6q+RL4MeHHVjL5MccrSZ4JaZ+ace2S1gR2WOkeeyLSo8uv/B6Xp1Nf4s3m5J3OV3tC31MOFdskXcvivxUBdLs05dcq/KQmuQ6tqJt8mMmkCaEwL/U7aF9+Ki949ivHT4Be09ZL+olubZ4kU47Y04+S2CgTPG40B4udqP4V/vVJfGEu1/xaOMX5h9Hca8L0brDTjO8ojeoYBB4McAPLadOmfPbJ2CiwWOyV3hjm8gJBHqGet4ePaXjJ1jpinCiKPUjSlEzrVCJYdDD0mhmf0VYj8ESX8WvqeUzhZB4mDiGjV2G7PwDerPLvsd+yAdTel9FAiFGqpfoIMlXAWPuPep6yEaxvFU1GHB9uUUOvBdZ5v16eDOP6Nvv6kJwTcOZ5RoPtmJMiJYh+UdkvccDgfSFOXZ6EFW9epWDc+DbKHvc3jhPH8Zr X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e1167408-0961-41f6-6f77-08dbb94ac5b1 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:58:20.1253 (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: DU2P250MB0237 Subject: [FFmpeg-devel] [PATCH 27/42] avcodec/pthread_frame: Add new progress API 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: IfnxmPpDvegy Frame-threaded decoders with inter-frame dependencies use the ThreadFrame API for syncing. It works as follows: During init each thread allocates an AVFrame for every ThreadFrame. Thread A reads the header of its packet and allocates a buffer for an AVFrame with ff_thread_get_ext_buffer() (which also allocates a small structure that is shared with other references to this frame) and sets its fields, including side data. Then said thread calls ff_thread_finish_setup(). From that moment onward it is not allowed to change any of the AVFrame fields at all any more, but it may change fields which are an indirection away, like the content of AVFrame.data or already existing side data. After thread A has called ff_thread_finish_setup(), another thread (the user one) calls the codec's update_thread_context callback which in turn calls ff_thread_ref_frame() which calls av_frame_ref() which reads every field of A's AVFrame; hence the above restriction on modifications of the AVFrame (as any modification of the AVFrame by A after ff_thread_finish_setup() would be a data race). Of course, this av_frame_ref() also incurs allocations and therefore needs to be checked. ff_thread_ref_frame() also references the small structure used for communicating progress. This av_frame_ref() makes it awkward to propagate values that only become known during decoding to later threads (in case of frame reordering or other mechanisms of delayed output (like show-existing-frames) it's not the decoding thread, but a later thread that returns the AVFrame). E.g. for VP9 when exporting video encoding parameters as side data the number of blocks only becomes known during decoding, so one can't allocate the side data before ff_thread_finish_setup(). It is currently being done afterwards and this leads to a data race in the vp9-encparams test when using frame-threading. Returning decode_error_flags is also complicated by this. To perform this exchange a buffer shared between the references is needed (notice that simply giving the later threads a pointer to the original AVFrame does not work, because said AVFrame will be reused lateron when thread A decodes the next packet given to it). One could extend the buffer already used for progress for this or use a new one (requiring yet another allocation), yet both of these approaches have the drawback of being unnatural, ugly and requiring quite a lot of ad-hoc code. E.g. in case of the VP9 side data mentioned above one could not simply use the helper that allocates and adds the side data to an AVFrame in one go. The ProgressFrame API meanwhile offers a different solution to all of this. It is based around the idea that the most natural shared object for sharing information about an AVFrame between decoding threads is the AVFrame itself. To actually implement this the AVFrame needs to be reference counted. This is achieved by putting a (ownership) pointer into a shared (and opaque) structure that is managed by the RefStruct API and which also contains the stuff necessary for progress reporting. The users get a pointer to this AVFrame with the understanding that the owner may set all the fields until it has indicated that it has finished decoding this AVFrame; then the users are allowed to read everything. Every decoder may of course employ a different contract than the one outlined above. Given that there is no underlying av_frame_ref(), creating references to a ProgressFrame can't fail. Only ff_thread_progress_get_buffer() can fail, but given that it will replace calls to ff_thread_get_ext_buffer() it is at places where errors are already expected and properly taken care of. The ProgressFrames are empty (i.e. the AVFrame pointer is NULL and the AVFrames are not allocated during init at all) while not being in use; ff_thread_progress_get_buffer() both sets up the actual ProgressFrame and already calls ff_thread_get_buffer(). So instead of checking for ThreadFrame.f->data[0] or ThreadFrame.f->buf[0] being NULL for "this reference frame is non-existing" one should check for ProgressFrame.f. This also implies that one can only set AVFrame properties after having allocated the buffer. This restriction is not deep: if it becomes onerous for any codec, ff_thread_progress_get_buffer() can be broken up. The user would then have to get a buffer himself. In order to avoid unnecessary allocations, the shared structure is pooled, so that both the structure as well as the AVFrame itself are reused. This means that there won't be lots of unnecessary allocations in case of non-frame-threaded decoding. It might even turn out to have fewer than the current code (the current code allocates AVFrames for every DPB slot, but these are often excessively large and not completely used; the new code allocates them on demand). Pooling relies on the reset function of the RefStruct pool API, it would be impossible to implement with the AVBufferPool API. Finally, ProgressFrames store their owner in the shared, opaque structure whereas ThreadFrames share it in every instance. This makes it possible for different threads to have different opinions about ownership of a given ThreadFrame (this really happens when decoding field-based H.264), but this is not possible with ProgressFrames. Also ProgressFrames currently does not support separate ownership for the fields of an AVFrame. This could be added if the need arises. Signed-off-by: Andreas Rheinhardt --- libavcodec/avcodec.c | 1 + libavcodec/codec_internal.h | 4 + libavcodec/decode.c | 118 ++++++++++++++++++++++++ libavcodec/internal.h | 2 + libavcodec/progressframe.h | 134 ++++++++++++++++++++++++++++ libavcodec/progressframe_internal.h | 32 +++++++ libavcodec/pthread_frame.c | 43 +++++++++ libavcodec/tests/avcodec.c | 3 +- 8 files changed, 336 insertions(+), 1 deletion(-) create mode 100644 libavcodec/progressframe.h create mode 100644 libavcodec/progressframe_internal.h diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c index 6365ab87a6..a6ddc1c4e9 100644 --- a/libavcodec/avcodec.c +++ b/libavcodec/avcodec.c @@ -460,6 +460,7 @@ av_cold int avcodec_close(AVCodecContext *avctx) av_frame_free(&avci->recon_frame); ff_refstruct_unref(&avci->pool); + ff_refstruct_pool_uninit(&avci->progress_frame_pool); ff_hwaccel_uninit(avctx); diff --git a/libavcodec/codec_internal.h b/libavcodec/codec_internal.h index 130a7dc3cd..c03b64ceba 100644 --- a/libavcodec/codec_internal.h +++ b/libavcodec/codec_internal.h @@ -62,6 +62,10 @@ * Codec initializes slice-based threading with a main function */ #define FF_CODEC_CAP_SLICE_THREAD_HAS_MF (1 << 5) +/** + * The decoder might make use of the ProgressFrame API. + */ +#define FF_CODEC_CAP_USES_PROGRESSFRAMES (1 << 11) /* * The codec supports frame threading and has inter-frame dependencies, so it * uses ff_thread_report/await_progress(). diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 7abfe7f0ce..3f98eb0df4 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -46,6 +46,8 @@ #include "hwconfig.h" #include "internal.h" #include "packet_internal.h" +#include "progressframe.h" +#include "progressframe_internal.h" #include "refstruct.h" #include "thread.h" @@ -1691,6 +1693,111 @@ int ff_reget_buffer(AVCodecContext *avctx, AVFrame *frame, int flags) return ret; } +static void check_progress_consistency(const ProgressFrame *f) +{ + av_assert1(!!f->f == !!f->progress); + av_assert1(!f->progress || f->progress->f == f->f); +} + +static int thread_progress_get(AVCodecContext *avctx, ProgressFrame *f) +{ + FFRefStructPool *pool = avctx->internal->progress_frame_pool; + + av_assert1(!f->f && !f->progress); + + f->progress = ff_refstruct_pool_get(pool); + if (!f->progress) + return AVERROR(ENOMEM); + + if (avctx->active_thread_type & FF_THREAD_FRAME) { + f->progress->owner = avctx->internal->thread_ctx; + atomic_init(&f->progress->progress, -1); + } else + f->progress->owner = NULL; + f->f = f->progress->f; + return 0; +} + +int ff_thread_progress_get_buffer(AVCodecContext *avctx, ProgressFrame *f, int flags) +{ + int ret; + + ret = thread_progress_get(avctx, f); + if (ret < 0) + return ret; + + ret = ff_thread_get_buffer(avctx, f->progress->f, flags); + if (ret < 0) { + f->f = NULL; + ff_refstruct_unref_ext(avctx, &f->progress); + return ret; + } + return 0; +} + +void ff_thread_progress_ref(ProgressFrame *dst, const ProgressFrame *src) +{ + av_assert1(src->progress && src->f && src->f == src->progress->f); + av_assert1(!dst->f && !dst->progress); + dst->f = src->f; + dst->progress = ff_refstruct_ref(src->progress); +} + +void ff_thread_progress_unref(AVCodecContext *avctx, ProgressFrame *f) +{ + check_progress_consistency(f); + f->f = NULL; + ff_refstruct_unref_ext(avctx, &f->progress); +} + +void ff_thread_progress_replace(AVCodecContext *avctx, + ProgressFrame *dst, const ProgressFrame *src) +{ + if (dst == src) + return; + ff_thread_progress_unref(avctx, dst); + check_progress_consistency(src); + if (src->f) + ff_thread_progress_ref(dst, src); +} + +#if !HAVE_THREADS +void ff_thread_progress_report(ProgressFrame *f, int n) +{ +} + +void ff_thread_progress_await(const ProgressFrame *f, int n) +{ +} +#endif /* !HAVE_THREADS */ + +static int progress_frame_pool_init_cb(FFRefStructOpaque unused, void *obj) +{ + ProgressInternal *progress = obj; + + progress->f = av_frame_alloc(); + if (!progress->f) + return AVERROR(ENOMEM); + return 0; +} + +static void progress_frame_pool_reset_cb(FFRefStructOpaque dynamic_opaque, + FFRefStructOpaque unused, + void *obj) +{ + AVCodecContext *avctx = dynamic_opaque.nc; + ProgressInternal *progress = obj; + + ff_thread_release_buffer(avctx, progress->f); +} + +static void progress_frame_pool_free_entry_cb(FFRefStructOpaque opaque, void *obj) +{ + ProgressInternal *progress = obj; + + av_frame_free(&progress->f); +} + int ff_decode_preinit(AVCodecContext *avctx) { AVCodecInternal *avci = avctx->internal; @@ -1759,6 +1866,17 @@ int ff_decode_preinit(AVCodecContext *avctx) if (!avci->in_pkt || !avci->last_pkt_props) return AVERROR(ENOMEM); + if (ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_USES_PROGRESSFRAMES) { + avci->progress_frame_pool = + ff_refstruct_pool_alloc_ext_c(sizeof(ProgressInternal), + FF_REFSTRUCT_POOL_FLAG_DYNAMIC_OPAQUE, + (FFRefStructOpaque){ NULL }, + progress_frame_pool_init_cb, + (FFRefStructUnrefCB){ .unref_ext = progress_frame_pool_reset_cb }, + progress_frame_pool_free_entry_cb, NULL); + if (!avci->progress_frame_pool) + return AVERROR(ENOMEM); + } ret = decode_bsfs_init(avctx); if (ret < 0) return ret; diff --git a/libavcodec/internal.h b/libavcodec/internal.h index eb9e0d707c..04d5bbb6fc 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -64,6 +64,8 @@ typedef struct AVCodecInternal { struct FramePool *pool; + struct FFRefStructPool *progress_frame_pool; + void *thread_ctx; /** diff --git a/libavcodec/progressframe.h b/libavcodec/progressframe.h new file mode 100644 index 0000000000..bc1d8462fa --- /dev/null +++ b/libavcodec/progressframe.h @@ -0,0 +1,134 @@ +/* + * Copyright (c) 2022 Andreas Rheinhardt + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_PROGRESSFRAME_H +#define AVCODEC_PROGRESSFRAME_H + +/** + * ProgressFrame is an API to easily share frames without an underlying + * av_frame_ref(). Its main usecase is in frame-threading scenarios, + * yet it could also be used for purely single-threaded decoders that + * want to keep multiple references to the same frame. + * + * The underlying principle behind the API is that all that is needed + * to share a frame is a reference count and a contract between all parties. + * The ProgressFrame provides the reference count and the frame is unreferenced + * via ff_thread_release_buffer() when the reference count reaches zero. + * + * In order to make this API also usable for frame-threaded decoders it also + * provides a way of exchanging simple information about the state of + * decoding the frame via ff_thread_progress_report() and + * ff_thread_progress_await(). + * + * The typical contract for frame-threaded decoders is as follows: + * Thread A initializes a ProgressFrame via ff_thread_progress_get_buffer() + * (which already allocates the AVFrame's data buffers), calls + * ff_thread_finish_setup() and starts decoding the frame. Later threads + * receive a reference to this frame, which means they get a pointer + * to the AVFrame and the internal reference count gets incremented. + * Later threads whose frames use A's frame as reference as well as + * the thread that will eventually output A's frame will wait for + * progress on said frame reported by A. As soon as A has reported + * that it has finished decoding its frame, it must no longer modify it + * (neither its data nor its properties). + * + * Because creating a reference with this API does not involve reads + * from the actual AVFrame, the decoding thread may modify the properties + * (i.e. non-data fields) until it has indicated to be done with this + * frame. This is important for e.g. propagating decode_error_flags; + * it also allows to add side-data late. + */ + +struct AVCodecContext; + +typedef struct ProgressFrame { + struct AVFrame *f; + struct ProgressInternal *progress; +} ProgressFrame; + +/** + * Notify later decoding threads when part of their reference picture is ready. + * Call this when some part of the picture is finished decoding. + * Later calls with lower values of progress have no effect. + * + * @param f The picture being decoded. + * @param progress Value, in arbitrary units, of how much of the picture has decoded. + * + * @warning Calling this on a blank ProgressFrame causes undefined behaviour + */ +void ff_thread_progress_report(ProgressFrame *f, int progress); + +/** + * Wait for earlier decoding threads to finish reference pictures. + * Call this before accessing some part of a picture, with a given + * value for progress, and it will return after the responsible decoding + * thread calls ff_thread_progress_report() with the same or + * higher value for progress. + * + * @param f The picture being referenced. + * @param progress Value, in arbitrary units, to wait for. + * + * @warning Calling this on a blank ProgressFrame causes undefined behaviour + */ +void ff_thread_progress_await(const ProgressFrame *f, int progress); + +/** + * This function sets up the ProgressFrame, i.e. gets ProgressFrame.f + * and also calls ff_thread_get_buffer() on the frame. + * + * @note: This must only be called by codecs with the + * FF_CODEC_CAP_USES_PROGRESSFRAMES internal cap. + */ +int ff_thread_progress_get_buffer(struct AVCodecContext *avctx, + ProgressFrame *f, int flags); + +/** + * Give up a reference to the underlying frame contained in a ProgressFrame + * and reset the ProgressFrame, setting all pointers to NULL. + * + * @note: This implies that when using this API the check for whether + * a frame exists is by checking ProgressFrame.f and not + * ProgressFrame.f->data[0] or ProgressFrame.f->buf[0]. + */ +void ff_thread_progress_unref(struct AVCodecContext *avctx, ProgressFrame *f); + +/** + * Set dst.f to src.f and make dst a co-owner of src.f. + * dst can then be used to wait on progress of the underlying frame. + * + * @note: There is no underlying av_frame_ref() here. dst.f and src.f + * really point to the same AVFrame. Typically this means that + * the decoding thread is allowed to set all the properties of + * the AVFrame until it has indicated to have finished decoding. + * Afterwards later threads may read all of these fields. + * Access to the frame's data is governed by + * ff_thread_progress_report/await(). + */ +void ff_thread_progress_ref(ProgressFrame *dst, const ProgressFrame *src); + +/** + * Do nothing if dst and src already refer to the same AVFrame; + * otherwise unreference dst and if src is not blank, put a reference + * to src's AVFrame in its place (in case src is not blank). + */ +void ff_thread_progress_replace(struct AVCodecContext *avctx, + ProgressFrame *dst, const ProgressFrame *src); + +#endif /* AVCODEC_PROGRESSFRAME_H */ diff --git a/libavcodec/progressframe_internal.h b/libavcodec/progressframe_internal.h new file mode 100644 index 0000000000..1101207106 --- /dev/null +++ b/libavcodec/progressframe_internal.h @@ -0,0 +1,32 @@ +/* + * Copyright (c) 2022 Andreas Rheinhardt + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_PROGRESSFRAME_INTERNAL_H +#define AVCODEC_PROGRESSFRAME_INTERNAL_H + +#include + +typedef struct ProgressInternal { + atomic_int progress; + struct PerThreadContext *owner; ///< != NULL iff frame-threading is in use + struct AVFrame *f; +} ProgressInternal; + +#endif /* AVCODEC_PROGRESSFRAME_INTERNAL_H */ diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index 282f3fad58..9e827f0606 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -34,6 +34,8 @@ #include "hwaccel_internal.h" #include "hwconfig.h" #include "internal.h" +#include "progressframe.h" +#include "progressframe_internal.h" #include "pthread_internal.h" #include "refstruct.h" #include "thread.h" @@ -795,6 +797,7 @@ static av_cold int init_thread(PerThreadContext *p, int *threads_to_free, if (!copy->internal) return AVERROR(ENOMEM); copy->internal->thread_ctx = p; + copy->internal->progress_frame_pool = avctx->internal->progress_frame_pool; copy->delay = avctx->delay; @@ -1026,3 +1029,43 @@ void ff_thread_release_ext_buffer(AVCodecContext *avctx, ThreadFrame *f) f->owner[0] = f->owner[1] = NULL; ff_thread_release_buffer(avctx, f->f); } + +void ff_thread_progress_report(ProgressFrame *f, int n) +{ + ProgressInternal *pro = f->progress; + PerThreadContext *p = pro->owner; + + if (!p || + atomic_load_explicit(&pro->progress, memory_order_relaxed) >= n) + return; + + if (atomic_load_explicit(&p->debug_threads, memory_order_relaxed)) + av_log(p->avctx, AV_LOG_DEBUG, + "%p finished %d\n", (void*)pro, n); + + pthread_mutex_lock(&p->progress_mutex); + + atomic_store_explicit(&pro->progress, n, memory_order_release); + + pthread_cond_broadcast(&p->progress_cond); + pthread_mutex_unlock(&p->progress_mutex); +} + +void ff_thread_progress_await(const ProgressFrame *f, int n) +{ + ProgressInternal *pro = f->progress; + PerThreadContext *p = pro->owner; + + if (!p || + atomic_load_explicit(&pro->progress, memory_order_acquire) >= n) + return; + + if (atomic_load_explicit(&p->debug_threads, memory_order_relaxed)) + av_log(p->avctx, AV_LOG_DEBUG, + "thread awaiting %d from %p\n", n, (void*)pro); + + pthread_mutex_lock(&p->progress_mutex); + while (atomic_load_explicit(&pro->progress, memory_order_relaxed) < n) + pthread_cond_wait(&p->progress_cond, &p->progress_mutex); + pthread_mutex_unlock(&p->progress_mutex); +} diff --git a/libavcodec/tests/avcodec.c b/libavcodec/tests/avcodec.c index 08ca507bf0..f6e394c78d 100644 --- a/libavcodec/tests/avcodec.c +++ b/libavcodec/tests/avcodec.c @@ -145,7 +145,8 @@ int main(void){ FF_CODEC_CAP_SETS_PKT_DTS | FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | FF_CODEC_CAP_EXPORTS_CROPPING | - FF_CODEC_CAP_SETS_FRAME_PROPS) || + FF_CODEC_CAP_SETS_FRAME_PROPS | + FF_CODEC_CAP_USES_PROGRESSFRAMES) || codec->capabilities & (AV_CODEC_CAP_AVOID_PROBING | AV_CODEC_CAP_CHANNEL_CONF | AV_CODEC_CAP_DRAW_HORIZ_BAND)) From patchwork Tue Sep 19 19:57:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43835 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp187464pzb; Tue, 19 Sep 2023 13:01:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGmA0cfNV9rAakY5/GTWHMe4RHr6LwYugLXn1WPfayRLlnF1ufcJ9+kdN7fAiahaU6X08Zs X-Received: by 2002:a05:651c:149:b0:2bf:ee57:f18 with SMTP id c9-20020a05651c014900b002bfee570f18mr413370ljd.16.1695153675617; Tue, 19 Sep 2023 13:01:15 -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 d8-20020a170906344800b009a18a87b008si9718635ejb.146.2023.09.19.13.01.15; Tue, 19 Sep 2023 13:01:15 -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=K4bxY00p; 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 0149868C9CF; Tue, 19 Sep 2023 22:58:26 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2085.outbound.protection.outlook.com [40.92.91.85]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C328768C92F for ; Tue, 19 Sep 2023 22:58:24 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=d8P8dr+lrWahmHFL5LPg+F92L3VQC5/cQV/gDpHP+FqqYXsYa2I0bE5iG+QSdRNxeZUKLDcKCNCttxbSkj8wGIcWI7rnmm3qfatl5/VIAqMciOR9NDbetoN0TEGacA43XadVMYHXHyQnLQSi3RhOhihjmOnm29+tsvQf0RxOlTk08pXze+d10THejpsFi+E9i7LMDCpInPZgN7TBiq+f6t+B4kjAE+1u8x2EvIbKjMYS9p8xFAvtTOGAN3upgg7PF+sMjNGLpA7LwO0kV9HNcga0bpg9rc95IOmgcrNL1j3lv/22o8LwJ4EXM5UtnPIi10lhygv9eHrhfKLptGBXMA== 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=GkOu3Is1E7dXSlh08NGSjIlMhz+kB5GBneHIlqJMCXg=; b=kjc0qH/GJ8xc2ulTrDF6hoaBLmPoJ6KaL2ImalfHAnwfqqiVzs1zH9nY2J7YsRKe+i1n0A4w7oGTZlMFIamajzBDtD9jo6EE7sY5Bq99BecuN+UD2S+CxCSDyPVdK8IHVVsYzgILf6juOqV20Uy65E924YuT3fWeZPU36Mx2DXmYw5Ix95Jokk4sOy7/x6DmlAw79JkEkJuVXVYY6m6G6rtE1QwMy1PujF7OrvwdQJIopRTVgMNzf36IjdtwV4QTjr4ofTHKCBHeygLeu/Klx/vg7Sl6IUyJMjA0WN9+D8HBVR1dVsLESgLfRspcADA2l5+W0aRocU9TO1g8LdAr5g== 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=GkOu3Is1E7dXSlh08NGSjIlMhz+kB5GBneHIlqJMCXg=; b=K4bxY00plPLnULZZSCKU5yg6tGTrQdyVw6z5SWO6X4yD1Pi0LpxaRswtq6/TIqNwccTyw1CyYkjYqdCB2PWCiORhjrCACSbjZgCnIAGbSKkc00s3dVvwzCe/lXY0vo2A/NLXQTcpSPNCxvV/ff+AAi7lXZKEa7lWwGRukejexvlwcSaEaQWKsvyJVqcIJuQm4gEk5sBnAonZbY/zj2wDmb/FSxa/0fONRILU3Z02D2+FtZ+3l4Lp1MpSvzbuIs/0pGARPvB4enEyUIuJPWeHwE6fIWjrkCryt3TsgtRu6Sk/P/4tqkzieXy0wFr86kOS0n+inexYugvx+QOsTea5Hw== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0237.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:276::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:58:23 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:58:23 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:20 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [NAIytG1XnYq1ACBWYkJT8jIP704BdrPB] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-28-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0237:EE_ X-MS-Office365-Filtering-Correlation-Id: e7020ea9-63c7-43d1-5741-08dbb94ac795 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4DpeyhChY5KK/VmTmPYaTIm71hr8OPR0tyEjg018KfkdhQRBGH2L/pjN1nRhehb7Ft5mUxzpafYNqOd/Mni0tuo42A7TyNivO4Or/wXbBiNXJ8BY7/szHN8Q4aYfkvc7rTTf3iz4QqU9w/oe/t76iXLWDo6LhCAs2s8hUw+zW4gPgl9KDhh55F0waGFK4Roq0uUN5iKbOKYfu0n1CrZuT6UKPvB92ecL013HPhqzQtDkZajxxhZXCHQsJn+RFN0LvmIwlm9ACd0agV4lcCZT2BUQmfmEJSMovhZmaycqTu5fM4mtm4ths0KaYQcLk4+j+sT+R1peCAifi6KAY3ybhSv2YE95dGgGBR53PaE+d8bWNrvDC8mDvzVNjTWxqDaLcIpyWk14xsMBYysmmyiAtrazJKu3oviqlEztFuKutOvZRzlwQyQHi5bbyCwvMyIpfv+3mvwNS203ADO2luNvRZy6iiGQBgo72Ye16K09Gn8KTbPhZcFkgTAyE0J79mPOV7iJDz38dTOLlVidzWQBg7Zd5hDpWSjPrlqTEmsZT49mmYSs9r1ymcDQ+PavXRHGovYh7LocrKIK5NYYG36CRRK53Uv1+rpiICIkI4QVM/C4XKhRDKlT7kaBjDGjwJVP X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: EYXTGbDoHv6lwwDF377nh0pYuSBhGpQBCvr51bWf2zvLp8WzPkxwuMnWwRTD5j4/p/ZyzIXuUhJh2ePYhXvfZOVAPjLnjSZUj4NwQKtM9TTG4iJXVRdIV7eGRk3voYxTtEYZUlKjGeHeaphQGlEP9keBkeIUdN40FgmN0Me7xtMJbA7DR4w9uuWE1/Cq2/nE3/cFf30al+15DooDyCMRucNo2HbvKyfxE/AojzoISGIl2eBNFyBnpWkYSqLD1+JwDD+0uJWG4xJdysbG+nxxmdU78o3pZb9Qan1CNuonYcMBvE2uSrDKC5teyRhI77FBW4z/MCcJ4qIb5ClCF/I6sbhw6KgJ3MD6v46Ndc7aMDfCJg1yh+o5eI6EnMiGksfb4+phyJpR5aAlWazJczq6rGVxIYnovfPRFNKLwuMDyMilbUOGpiaQoyXlZjqNpr49gg2QBQmaaI8t602w5aBJs8e1T7I7HWfTvQ9j4spDv2bSfjlM+DB2wJ2aOHslvVaGNnP9547mQmaPKLXyrysP8sAU7FTaojCuI6z6lQXfMhQ5EzP7JNVfQ1e0MYZvugiDnlAqIbGq52E1+MNWbIaQxt7WBdnjx7TSEhlCU3GfAOVNH4l4gZG46vFKH6MM6C4/rd0EXuJGmkRadRGvls4ewPMMipEJrmN3dqjo3FqxsuzsbENhFej4STCTK2e5JQgCZN1VXKklb/LZIFUqig4cb2OPYVkzCf2OIsi5wnfj0PY6lH6XoRob7gaiON+syCE1w5vNPutSzTY+BJps4Q7AuUe/v5tX1OHYvTou6obR0+Xc5TLSrV81SjoS4cv0SE5G5sWvROdACwG//ZoMQbkoNHpZd6lPT4nl1qkOfEkua7Y5Quc90yR5Wioj92FgcN0f6y5a/ZUqZesxdzZXnnp+ivYsoDIVyLsp6aGWqWI1mUCzWVhfgadpzUmul2hoO2K/macVPRKJ9sREdu0+1l+6RvULv+w39IpWKDTGK30KeSe5Sdk9IYuPRNUcrYHSp8SPgU98fMH9AYcLx58Lu6ImMgIYpjI5qusDhmisoDeWvHOzK1Fp0lm11J4BvVCrk2lAZY0jzfREP/ZAv7a7SnmNB1NUaWNvegCFnZy1usthf08IBsgp7KwpjJDBT+lWJ6gjAA1d6d0vrnrB8MHzPILutHcyAwYnsDCAZSHsiI8uq1kM6auQBdrJV9k4Y00jwJa6WrWrKW9+N8C+Zpf/W8zfMGhX5G96Eg+hyvN4JnSTsqXGi9IKBgOBc3DAV6CKpoNU X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: e7020ea9-63c7-43d1-5741-08dbb94ac795 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:58:23.2632 (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: DU2P250MB0237 Subject: [FFmpeg-devel] [PATCH 28/42] avcodec/mimic: Switch to ProgressFrames 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: wTlsFFjA2Uwx Avoids implicit av_frame_ref() and therefore allocations and error checks. Signed-off-by: Andreas Rheinhardt --- libavcodec/mimic.c | 60 ++++++++++++++++------------------------------ 1 file changed, 21 insertions(+), 39 deletions(-) diff --git a/libavcodec/mimic.c b/libavcodec/mimic.c index a846a07a40..82da20bbf4 100644 --- a/libavcodec/mimic.c +++ b/libavcodec/mimic.c @@ -33,8 +33,8 @@ #include "bswapdsp.h" #include "hpeldsp.h" #include "idctdsp.h" +#include "progressframe.h" #include "thread.h" -#include "threadframe.h" #define MIMIC_HEADER_SIZE 20 #define MIMIC_VLC_BITS 11 @@ -51,7 +51,7 @@ typedef struct MimicContext { int cur_index; int prev_index; - ThreadFrame frames [16]; + ProgressFrame frames[16]; DECLARE_ALIGNED(32, int16_t, dct_block)[64]; @@ -104,16 +104,12 @@ static const uint8_t col_zag[64] = { static av_cold int mimic_decode_end(AVCodecContext *avctx) { MimicContext *ctx = avctx->priv_data; - int i; av_freep(&ctx->swap_buf); ctx->swap_buf_size = 0; - for (i = 0; i < FF_ARRAY_ELEMS(ctx->frames); i++) { - if (ctx->frames[i].f) - ff_thread_release_ext_buffer(avctx, &ctx->frames[i]); - av_frame_free(&ctx->frames[i].f); - } + for (int i = 0; i < FF_ARRAY_ELEMS(ctx->frames); i++) + ff_thread_progress_unref(avctx, &ctx->frames[i]); return 0; } @@ -128,7 +124,6 @@ static av_cold int mimic_decode_init(AVCodecContext *avctx) { static AVOnce init_static_once = AV_ONCE_INIT; MimicContext *ctx = avctx->priv_data; - int i; ctx->prev_index = 0; ctx->cur_index = 15; @@ -139,12 +134,6 @@ static av_cold int mimic_decode_init(AVCodecContext *avctx) ff_idctdsp_init(&ctx->idsp, avctx); ff_permute_scantable(ctx->permutated_scantable, col_zag, ctx->idsp.idct_permutation); - for (i = 0; i < FF_ARRAY_ELEMS(ctx->frames); i++) { - ctx->frames[i].f = av_frame_alloc(); - if (!ctx->frames[i].f) - return AVERROR(ENOMEM); - } - ff_thread_once(&init_static_once, mimic_init_static); return 0; @@ -154,7 +143,6 @@ static av_cold int mimic_decode_init(AVCodecContext *avctx) static int mimic_decode_update_thread_context(AVCodecContext *avctx, const AVCodecContext *avctx_from) { MimicContext *dst = avctx->priv_data, *src = avctx_from->priv_data; - int i, ret; if (avctx == avctx_from) return 0; @@ -162,13 +150,10 @@ static int mimic_decode_update_thread_context(AVCodecContext *avctx, const AVCod dst->cur_index = src->next_cur_index; dst->prev_index = src->next_prev_index; - for (i = 0; i < FF_ARRAY_ELEMS(dst->frames); i++) { - ff_thread_release_ext_buffer(avctx, &dst->frames[i]); - if (i != src->next_cur_index && src->frames[i].f->data[0]) { - ret = ff_thread_ref_frame(&dst->frames[i], &src->frames[i]); - if (ret < 0) - return ret; - } + for (int i = 0; i < FF_ARRAY_ELEMS(dst->frames); i++) { + ff_thread_progress_unref(avctx, &dst->frames[i]); + if (i != src->next_cur_index && src->frames[i].f) + ff_thread_progress_ref(&dst->frames[i], &src->frames[i]); } return 0; @@ -291,11 +276,10 @@ static int decode(MimicContext *ctx, int quality, int num_coeffs, } else { unsigned int backref = get_bits(&ctx->gb, 4); int index = (ctx->cur_index + backref) & 15; - uint8_t *p = ctx->frames[index].f->data[0]; - if (index != ctx->cur_index && p) { - ff_thread_await_progress(&ctx->frames[index], - cur_row, 0); + if (index != ctx->cur_index && ctx->frames[index].f) { + const uint8_t *p = ctx->frames[index].f->data[0]; + ff_thread_progress_await(&ctx->frames[index], cur_row); p += src - ctx->frames[ctx->prev_index].f->data[plane]; ctx->hdsp.put_pixels_tab[1][0](dst, p, stride, 8); @@ -305,8 +289,7 @@ static int decode(MimicContext *ctx, int quality, int num_coeffs, } } } else { - ff_thread_await_progress(&ctx->frames[ctx->prev_index], - cur_row, 0); + ff_thread_progress_await(&ctx->frames[ctx->prev_index], cur_row); ctx->hdsp.put_pixels_tab[1][0](dst, src, stride, 8); } src += 8; @@ -315,8 +298,7 @@ static int decode(MimicContext *ctx, int quality, int num_coeffs, src += (stride - ctx->num_hblocks[plane]) << 3; dst += (stride - ctx->num_hblocks[plane]) << 3; - ff_thread_report_progress(&ctx->frames[ctx->cur_index], - cur_row++, 0); + ff_thread_progress_report(&ctx->frames[ctx->cur_index], cur_row++); } } @@ -390,17 +372,17 @@ static int mimic_decode_frame(AVCodecContext *avctx, AVFrame *rframe, return AVERROR_PATCHWELCOME; } - if (is_pframe && !ctx->frames[ctx->prev_index].f->data[0]) { + if (is_pframe && !ctx->frames[ctx->prev_index].f) { av_log(avctx, AV_LOG_ERROR, "decoding must start with keyframe\n"); return AVERROR_INVALIDDATA; } - ff_thread_release_ext_buffer(avctx, &ctx->frames[ctx->cur_index]); + ff_thread_progress_unref(avctx, &ctx->frames[ctx->cur_index]); + if ((res = ff_thread_progress_get_buffer(avctx, &ctx->frames[ctx->cur_index], + AV_GET_BUFFER_FLAG_REF)) < 0) + return res; ctx->frames[ctx->cur_index].f->pict_type = is_pframe ? AV_PICTURE_TYPE_P : AV_PICTURE_TYPE_I; - if ((res = ff_thread_get_ext_buffer(avctx, &ctx->frames[ctx->cur_index], - AV_GET_BUFFER_FLAG_REF)) < 0) - return res; ctx->next_prev_index = ctx->cur_index; ctx->next_cur_index = (ctx->cur_index - 1) & 15; @@ -417,10 +399,10 @@ static int mimic_decode_frame(AVCodecContext *avctx, AVFrame *rframe, init_get_bits(&ctx->gb, ctx->swap_buf, swap_buf_size << 3); res = decode(ctx, quality, num_coeffs, !is_pframe); - ff_thread_report_progress(&ctx->frames[ctx->cur_index], INT_MAX, 0); + ff_thread_progress_report(&ctx->frames[ctx->cur_index], INT_MAX); if (res < 0) { if (!(avctx->active_thread_type & FF_THREAD_FRAME)) - ff_thread_release_ext_buffer(avctx, &ctx->frames[ctx->cur_index]); + ff_thread_progress_unref(avctx, &ctx->frames[ctx->cur_index]); return res; } @@ -447,6 +429,6 @@ const FFCodec ff_mimic_decoder = { FF_CODEC_DECODE_CB(mimic_decode_frame), .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS, UPDATE_THREAD_CONTEXT(mimic_decode_update_thread_context), - .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS | + .caps_internal = FF_CODEC_CAP_USES_PROGRESSFRAMES | FF_CODEC_CAP_INIT_CLEANUP, }; From patchwork Tue Sep 19 19:57:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43836 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp187588pzb; Tue, 19 Sep 2023 13:01:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHiDusJvQ9CA3UN/+TsLvi+v2xEFiU7zLlN7UYHVa9MH29Ix+6yFvtMCUjiGmGyrQ+6Ct6R X-Received: by 2002:adf:d0ca:0:b0:317:5d3d:c9df with SMTP id z10-20020adfd0ca000000b003175d3dc9dfmr540597wrh.18.1695153686002; Tue, 19 Sep 2023 13:01:26 -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 y6-20020a17090668c600b00992f1a3b9dcsi11132720ejr.845.2023.09.19.13.01.25; Tue, 19 Sep 2023 13:01:25 -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="BzF0/Xzw"; 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 2F3EA68C92F; Tue, 19 Sep 2023 22:58:28 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2070.outbound.protection.outlook.com [40.92.91.70]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id F10EF68C92F for ; Tue, 19 Sep 2023 22:58:26 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=W9kFD8NbZ+mGkluuUFLbmGF+4EJzapeqO0v1dUSsHqmrH2gNseINUlFuCCEtguif69hJLRk7ANZ6tsbQg6/k9ozw+q50NAQLl5qthsVfMc/Cw89nltzx0rMJQA2Fez71muvUeLIe3/0wEpvwzXLqVV3IQS9nm24B28zQdpTMndgQVSFUUdAu8WevpOVrhIqlUmKfQsCG0l2LA+/jr5x9f12WBm4aXsmduqSzcGsiPoEt/UOUyE1AIdQ7BS27TDKHEP34kfkVeZhIoPfkLfPTOVfP5NUgGLvd+9cTpw0aHW5lKMaEOsMlvZDaf+Ry7aqLQINJ4p5sr3mr5slqLpaNLQ== 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=NbETq0PCCer7Mc8lIxdAcPTBITgYFVCyMvoVvsskIYw=; b=Vg3IXJwJCrDkqeamoDddehESPdPZUVjKKjFlGiH6HxnPf1i+D4cdiqdUuugNUL3kEx3dhHkq8LQzPOrMdmzX5kdXAm2khkPR2lkYGDKMhwhEcvkqTcoglJ30hhcTUsrXAzDKBR+RT7BsDe7XDf0bLsNGBw4yCajQWF9GwwqdS1qPKjhS4u0IyS7vaaMToyP9eVmU/Tj4jp7/45iETsQ4f94qvi0Nfy2NieC/QC7WhLSMIiSpPOYNkkGLQ2prV+igjjy/1pWogj0PWcw1b0BtRwM/lXVDr6pDM8fUoT8fcDRJgPK7shM4EvYz+/AMB7woVcfYpq+nel6CK+RB2lKepw== 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=NbETq0PCCer7Mc8lIxdAcPTBITgYFVCyMvoVvsskIYw=; b=BzF0/Xzw85yYHXejeyFIJBKbzE6ZGeWOHLfw0D+fXvzF5GHTaum9SLO61aBWWv6EbN3PQeeKC3xqoY3Hmw0q5pF6rSnXx3fZp4yLyjb7YDNWWq2UbWV9Bl8+xt32zVgmHhOGA+Rv1eA5bW7AcIVi2ZvPu0zNFWVPHZxbLJtXo1tUNTAuytHpOk2aHLsOELbvpnZveTn2q0k1LFNbKHImYVcZWMV3cvmZM8Q/0xi1wVzrsK7eOgsfBP54PXO/9Y1d5C66ks94ri+O/HX/2eU4nuDM0ssNwch0V6u4KiV8nKXQnyh2w5fkwCSawbNMq+qvP/7cxBOaDiH/1W84fRZZ/w== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0237.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:276::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:58:25 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:58:25 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:21 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [ELoKOlxyVV9f1KDbTsXB9ONBiGmkxXxf] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-29-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0237:EE_ X-MS-Office365-Filtering-Correlation-Id: 071dc83a-a61a-4854-1139-08dbb94ac8e3 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hSrGtZDWsqZLRMoQdhdFcvuXDAViI1h+omCVQx2Svl2IJ05KNNqHHfx/a+xal0FfxJhCtapzQdYdywzLjfCEXsOzt/K3Mm/hJqypLwS0QdSvAoPElPXp3GPpz3/H9KeVhTV2lJDCi8LnvaVmjOKeC7LXzOqClJKiLn7TWa+3SKmMb6z0X6bwxv4p/FiK5gXjqJodzXWcjtxb615uBmiz+YZuwT93khVU1OD7ML+H4eCNXY5LO+yvx92Y6cG5CwCD7TMZOQIbHboBr3/HaWVbkIZpDVc+X+j9Getal3kliw4vgFaGYO3SN2JR2vQgqTcLqAdfv30ip4P5GfROlKZDJ+ZZLiBp8M3AsDg7x8hdY8SvyCwpaVdAVUv0iCT9xXpOtsdA7/8h0bFKjsiv5o0h2KfiOtaa2Fz1SrtjqwX7iZ5QhFJdWOD1MJDUOd2uy7ds6DTVD1CfNR1MeQNt6BOduOK10lac1yYtMvs1uGPf2N4MVm5m1mlxsxwePNT8cuR6nDoQHwY0AxjGgpoRxvEvM2xSP+vpuK6yW4Xgl7FLglGWji8KQbo7YYOysk422r/X9rvoWnjldwwd5k7+86hyIaLhGPFQhTKxUGehzgUIt0Y= X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: kYN8kUniI4P7oGRt/o1ec/Y4/hQfOsT4kAyfsWT9XShdq3mQfeixcgJMcEmcDlLf0s+1h+Z6mKZggwg5p7XkwGVsLRjGwszn41mdJxlgx8Y5cfN81f2yMh+HaiGqJUV8m7xX5k22PJBzsMMzs/Wjc8lTsQuWBI40U/fzBMQ9vtumDVXprjiX96Z0EBQHjW+fgEB5sEoAIk1Vztsy0AE3AaKOO8yileEkLAmcggZl1AHwrE7/c1vQzExcSUD4PDXf+OyxoPqNJu31G6J44auGXVB9qCIgaWqJGICqEF6mSRKw/wAx9pPU7IlKxPEDHK0QtET5tKnmeO8co7MjSTJ2/40JhzekuxH1/btKHeo8x+lKoKoUBM2tE+X+FqWpmYBOpHdqto6nt4O12fyRopTN8FGee3Di+LbxsypcdMv8w4u3bYUV6HXJbY+yApJHcpYO6TIlEOe5NrgY38GArs9ocF6TNahsKepxCp4asJqw9JESXBuk2kF+d9TcOlrCCZf1v9JX2MySkoY/X88dF2NJsNYouJuZR09ArzlQ5jdskAQABdOjCLDG8mvvQldL3hrKqRac0SLNc8jgVoHr/l48FYac4hhm2vp9QeoqGvNUyMfDOSytG6DE21Mx3P0C66y7oy/OrlMusPIhzX3wdICHZrCWJ7Fi2w1jor/XCbRVPOHl0fgPf8ptsJfUXYHq+qZinaPr+94HS7wr7InwTh2DsLD54SQNeOxP9TF2LdMZERSJ5YNvS/PxzE6Ykj53MdOwSalrh3FYxD53bGL40IssZ7vdy0OA/HKpx0JUL5dRMQJR3Uh8VbQoBAXYPCKQ0CUBcWcEGpmqVLxrLiClhCwjR+osF4/7tezNT3hFImOAL7jP4j6RwldI91VVDAeuRH/TtxjFRNhXHuvatgxzgCP9NvWEKhzKwMk08sOPpb0NQHOHQ9gUfubpPCbDhgDaVLCEEH8kyL4It0XjlCXwlXykFmm+E571QdZp86Zt0z86C4Q33TzQmiAUX7LCk+aqcgpN8c/IBODn1ZvgjBXDgajG2TEwpTEghD+QSFLFstTocTq+/wXL8sq5OcXCwPt095nICf52Y5oW+0nvE/3nfC75ZjNzf6yNbo8wPZoKZ8TpBWEaMCVOinFlFH+dkZMBu8Az+9PV06YgLq6GYWPCb/mzmWrDfUFmrvl5v2CZ7/O9G8c3Hyn/8cf1X8IP8ZJxTIFpwhGV6jDMnROlN4P+qe0/IHG5futXAlDnK0o5PNC0gOhxYEGgdT8iy7f9EcM+KfXD X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 071dc83a-a61a-4854-1139-08dbb94ac8e3 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:58:25.4606 (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: DU2P250MB0237 Subject: [FFmpeg-devel] [PATCH 29/42] avcodec/vp3: Switch to ProgressFrames 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: 0p+nlqc/kPk/ Avoids implicit av_frame_ref() and therefore allocations and error checks. It also avoids explicitly allocating the AVFrames (done implicitly when getting the buffer) and it also allows to reuse the flushing code for freeing the ProgressFrames. Signed-off-by: Andreas Rheinhardt --- libavcodec/vp3.c | 148 +++++++++++++++++------------------------------ 1 file changed, 54 insertions(+), 94 deletions(-) diff --git a/libavcodec/vp3.c b/libavcodec/vp3.c index 98dabfc907..e8e1ebff56 100644 --- a/libavcodec/vp3.c +++ b/libavcodec/vp3.c @@ -46,8 +46,8 @@ #include "hpeldsp.h" #include "jpegquanttables.h" #include "mathops.h" +#include "progressframe.h" #include "thread.h" -#include "threadframe.h" #include "videodsp.h" #include "vp3data.h" #include "vp4data.h" @@ -180,9 +180,9 @@ typedef struct Vp3DecodeContext { int version; int width, height; int chroma_x_shift, chroma_y_shift; - ThreadFrame golden_frame; - ThreadFrame last_frame; - ThreadFrame current_frame; + ProgressFrame golden_frame; + ProgressFrame last_frame; + ProgressFrame current_frame; int keyframe; uint8_t idct_permutation[64]; uint8_t idct_scantable[64]; @@ -336,12 +336,9 @@ static void vp3_decode_flush(AVCodecContext *avctx) { Vp3DecodeContext *s = avctx->priv_data; - if (s->golden_frame.f) - ff_thread_release_ext_buffer(avctx, &s->golden_frame); - if (s->last_frame.f) - ff_thread_release_ext_buffer(avctx, &s->last_frame); - if (s->current_frame.f) - ff_thread_release_ext_buffer(avctx, &s->current_frame); + ff_thread_progress_unref(avctx, &s->golden_frame); + ff_thread_progress_unref(avctx, &s->last_frame); + ff_thread_progress_unref(avctx, &s->current_frame); } static av_cold int vp3_decode_end(AVCodecContext *avctx) @@ -355,9 +352,6 @@ static av_cold int vp3_decode_end(AVCodecContext *avctx) /* release all frames */ vp3_decode_flush(avctx); - av_frame_free(&s->current_frame.f); - av_frame_free(&s->last_frame.f); - av_frame_free(&s->golden_frame.f); for (int i = 0; i < FF_ARRAY_ELEMS(s->coeff_vlc); i++) ff_vlc_free(&s->coeff_vlc[i]); @@ -1899,10 +1893,9 @@ static void vp3_draw_horiz_band(Vp3DecodeContext *s, int y) /* At the end of the frame, report INT_MAX instead of the height of * the frame. This makes the other threads' ff_thread_await_progress() * calls cheaper, because they don't have to clip their values. */ - ff_thread_report_progress(&s->current_frame, + ff_thread_progress_report(&s->current_frame, y_flipped == s->height ? INT_MAX - : y_flipped - 1, - 0); + : y_flipped - 1); } if (!s->avctx->draw_horiz_band) @@ -1933,7 +1926,7 @@ static void vp3_draw_horiz_band(Vp3DecodeContext *s, int y) static void await_reference_row(Vp3DecodeContext *s, const Vp3Fragment *fragment, int motion_y, int y) { - const ThreadFrame *ref_frame; + const ProgressFrame *ref_frame; int ref_row; int border = motion_y & 1; @@ -1946,7 +1939,7 @@ static void await_reference_row(Vp3DecodeContext *s, const Vp3Fragment *fragment ref_row = y + (motion_y >> 1); ref_row = FFMAX(FFABS(ref_row), ref_row + 8 + border); - ff_thread_await_progress(ref_frame, ref_row, 0); + ff_thread_progress_await(ref_frame, ref_row); } #if CONFIG_VP4_DECODER @@ -2057,12 +2050,12 @@ static void render_slice(Vp3DecodeContext *s, int slice) int16_t *block = s->block; int motion_x = 0xdeadbeef, motion_y = 0xdeadbeef; /* When decoding keyframes, the earlier frames may not be available, - * so to avoid using undefined pointer arithmetic on them we just - * use the current frame instead. Nothing is ever read from these - * frames in case of a keyframe. */ - const AVFrame *last_frame = s->last_frame.f->data[0] ? + * so we just use the current frame in this case instead; + * it also avoid using undefined pointer arithmetic. Nothing is + * ever read from these frames in case of a keyframe. */ + const AVFrame *last_frame = s->last_frame.f ? s->last_frame.f : s->current_frame.f; - const AVFrame *golden_frame = s->golden_frame.f->data[0] ? + const AVFrame *golden_frame = s->golden_frame.f ? s->golden_frame.f : s->current_frame.f; int motion_halfpel_index; int first_pixel; @@ -2302,18 +2295,6 @@ static av_cold int allocate_tables(AVCodecContext *avctx) return 0; } -static av_cold int init_frames(Vp3DecodeContext *s) -{ - s->current_frame.f = av_frame_alloc(); - s->last_frame.f = av_frame_alloc(); - s->golden_frame.f = av_frame_alloc(); - - if (!s->current_frame.f || !s->last_frame.f || !s->golden_frame.f) - return AVERROR(ENOMEM); - - return 0; -} - static av_cold int vp3_decode_init(AVCodecContext *avctx) { Vp3DecodeContext *s = avctx->priv_data; @@ -2322,10 +2303,6 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx) int c_height; int y_fragment_count, c_fragment_count; - ret = init_frames(s); - if (ret < 0) - return ret; - if (avctx->codec_tag == MKTAG('V', 'P', '4', '0')) { s->version = 3; #if !CONFIG_VP4_DECODER @@ -2493,59 +2470,43 @@ static av_cold int vp3_decode_init(AVCodecContext *avctx) } /// Release and shuffle frames after decode finishes -static int update_frames(AVCodecContext *avctx) +static void update_frames(AVCodecContext *avctx) { Vp3DecodeContext *s = avctx->priv_data; - int ret = 0; - if (s->keyframe) { - ff_thread_release_ext_buffer(avctx, &s->golden_frame); - ret = ff_thread_ref_frame(&s->golden_frame, &s->current_frame); - } - /* shuffle frames */ - ff_thread_release_ext_buffer(avctx, &s->last_frame); - FFSWAP(ThreadFrame, s->last_frame, s->current_frame); + if (s->keyframe) + ff_thread_progress_replace(avctx, &s->golden_frame, &s->current_frame); - return ret; + /* shuffle frames */ + ff_thread_progress_unref(avctx, &s->last_frame); + FFSWAP(ProgressFrame, s->last_frame, s->current_frame); } #if HAVE_THREADS -static int ref_frame(Vp3DecodeContext *s, ThreadFrame *dst, const ThreadFrame *src) -{ - ff_thread_release_ext_buffer(s->avctx, dst); - if (src->f->data[0]) - return ff_thread_ref_frame(dst, src); - return 0; -} - -static int ref_frames(Vp3DecodeContext *dst, const Vp3DecodeContext *src) +static void ref_frames(AVCodecContext *avctx, + Vp3DecodeContext *dst, const Vp3DecodeContext *src) { - int ret; - if ((ret = ref_frame(dst, &dst->current_frame, &src->current_frame)) < 0 || - (ret = ref_frame(dst, &dst->golden_frame, &src->golden_frame)) < 0 || - (ret = ref_frame(dst, &dst->last_frame, &src->last_frame)) < 0) - return ret; - return 0; + ff_thread_progress_replace(avctx, &dst->current_frame, &src->current_frame); + ff_thread_progress_replace(avctx, &dst->golden_frame, &src->golden_frame); + ff_thread_progress_replace(avctx, &dst->last_frame, &src->last_frame); } static int vp3_update_thread_context(AVCodecContext *dst, const AVCodecContext *src) { Vp3DecodeContext *s = dst->priv_data; const Vp3DecodeContext *s1 = src->priv_data; - int qps_changed = 0, err; + int qps_changed = 0; - if (!s1->current_frame.f->data[0] || + if (s != s1) { + // copy previous frame data + ref_frames(dst, s, s1); + } + if (!s1->current_frame.f || s->width != s1->width || s->height != s1->height) { - if (s != s1) - ref_frames(s, s1); return -1; } if (s != s1) { - // copy previous frame data - if ((err = ref_frames(s, s1)) < 0) - return err; - s->keyframe = s1->keyframe; // copy qscale data if necessary @@ -2567,7 +2528,8 @@ static int vp3_update_thread_context(AVCodecContext *dst, const AVCodecContext * } } - return update_frames(dst); + update_frames(dst); + return 0; } #endif @@ -2658,15 +2620,18 @@ static int vp3_decode_frame(AVCodecContext *avctx, AVFrame *frame, if (avctx->skip_frame >= AVDISCARD_NONKEY && !s->keyframe) return buf_size; + if ((ret = ff_thread_progress_get_buffer(avctx, &s->current_frame, + AV_GET_BUFFER_FLAG_REF)) < 0) { + // Don't goto error here, as one can't report progress on or + // unref a non-existent frame. + return ret; + } s->current_frame.f->pict_type = s->keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; if (s->keyframe) s->current_frame.f->flags |= AV_FRAME_FLAG_KEY; else s->current_frame.f->flags &= ~AV_FRAME_FLAG_KEY; - if ((ret = ff_thread_get_ext_buffer(avctx, &s->current_frame, - AV_GET_BUFFER_FLAG_REF)) < 0) - goto error; if (!s->edge_emu_buffer) { s->edge_emu_buffer = av_malloc(9 * FFABS(s->current_frame.f->linesize[0])); @@ -2724,19 +2689,16 @@ static int vp3_decode_frame(AVCodecContext *avctx, AVFrame *frame, #endif } } else { - if (!s->golden_frame.f->data[0]) { + if (!s->golden_frame.f) { av_log(s->avctx, AV_LOG_WARNING, "vp3: first frame not a keyframe\n"); - s->golden_frame.f->pict_type = AV_PICTURE_TYPE_I; - if ((ret = ff_thread_get_ext_buffer(avctx, &s->golden_frame, - AV_GET_BUFFER_FLAG_REF)) < 0) + if ((ret = ff_thread_progress_get_buffer(avctx, &s->golden_frame, + AV_GET_BUFFER_FLAG_REF)) < 0) goto error; - ff_thread_release_ext_buffer(avctx, &s->last_frame); - if ((ret = ff_thread_ref_frame(&s->last_frame, - &s->golden_frame)) < 0) - goto error; - ff_thread_report_progress(&s->last_frame, INT_MAX, 0); + s->golden_frame.f->pict_type = AV_PICTURE_TYPE_I; + ff_thread_progress_replace(avctx, &s->last_frame, &s->golden_frame); + ff_thread_progress_report(&s->golden_frame, INT_MAX); } } ff_thread_finish_setup(avctx); @@ -2814,16 +2776,13 @@ static int vp3_decode_frame(AVCodecContext *avctx, AVFrame *frame, *got_frame = 1; - if (!HAVE_THREADS || !(s->avctx->active_thread_type & FF_THREAD_FRAME)) { - ret = update_frames(avctx); - if (ret < 0) - return ret; - } + if (!HAVE_THREADS || !(s->avctx->active_thread_type & FF_THREAD_FRAME)) + update_frames(avctx); return buf_size; error: - ff_thread_report_progress(&s->current_frame, INT_MAX, 0); + ff_thread_progress_report(&s->current_frame, INT_MAX); if (!HAVE_THREADS || !(s->avctx->active_thread_type & FF_THREAD_FRAME)) av_frame_unref(s->current_frame.f); @@ -3173,7 +3132,8 @@ const FFCodec ff_theora_decoder = { .flush = vp3_decode_flush, UPDATE_THREAD_CONTEXT(vp3_update_thread_context), .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | - FF_CODEC_CAP_EXPORTS_CROPPING | FF_CODEC_CAP_ALLOCATE_PROGRESS, + FF_CODEC_CAP_EXPORTS_CROPPING | + FF_CODEC_CAP_USES_PROGRESSFRAMES, }; #endif @@ -3191,7 +3151,7 @@ const FFCodec ff_vp3_decoder = { .flush = vp3_decode_flush, UPDATE_THREAD_CONTEXT(vp3_update_thread_context), .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | - FF_CODEC_CAP_ALLOCATE_PROGRESS, + FF_CODEC_CAP_USES_PROGRESSFRAMES, }; #if CONFIG_VP4_DECODER @@ -3209,6 +3169,6 @@ const FFCodec ff_vp4_decoder = { .flush = vp3_decode_flush, UPDATE_THREAD_CONTEXT(vp3_update_thread_context), .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | - FF_CODEC_CAP_ALLOCATE_PROGRESS, + FF_CODEC_CAP_USES_PROGRESSFRAMES, }; #endif From patchwork Tue Sep 19 19:57:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43837 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp187713pzb; Tue, 19 Sep 2023 13:01:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGflfSj3arl0Cc1bMbnX9JH1lNQNtPxqvnmGBUkCyrq9LSk9Y8/Ti5cTwaX9Q5AHHdUwjC/ X-Received: by 2002:aa7:d48c:0:b0:52f:2bd3:6f4d with SMTP id b12-20020aa7d48c000000b0052f2bd36f4dmr434807edr.0.1695153696845; Tue, 19 Sep 2023 13:01:36 -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 b9-20020a1709062b4900b0099cc50f304csi10746512ejg.291.2023.09.19.13.01.36; Tue, 19 Sep 2023 13:01:36 -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=bSXHrDTg; 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 240BC68C9E1; Tue, 19 Sep 2023 22:58:33 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2018.outbound.protection.outlook.com [40.92.91.18]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2062768C9D5 for ; Tue, 19 Sep 2023 22:58:31 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GbRmSi2XmWCj7S7JwMGeBU2lDzoAAeV4HDE1HeJ5ZYG0Ntv+4eSgTnMUlGvPLoM/xdYeM38Tqx1gPuZ7Sa816JJutiwEX4yYJL+smlK6qEAKG8K1ZlWQ21KUsrG95evVvY1vHbOGs5yBpsqQAzE2B3AuxdjAGN0fc/fF+8MLmH8ASTleqmr8x17W6yxxHVu1sp1Jl1SnwdYCh8CDxfRDmk06wxE5xz6Z+mH8udbDrq4UDa4yM7Q0y5SoVIj5gEuSkKNNkmBSpATuXj0ifchyrbYRSDQV6fXL+Sa8vadfIL9435of3jzwHs2B8SkNm7f9i0qxLcqgzSQdo1xTl7PnNg== 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=LT131qTY3XKG8ZBL+Sx+vXXLiscl2JkpDH3VN5e3yOA=; b=ReRjQ7KbFmBwFVL9cG87bmxdAx/LwvXvIYyYa0O08ZYN93TW2YaWznr3go7pAiSVbuud7q+V1mHnX/nI/xSmhncDiw+ns+mnA+6b4g+t2AklK8U5rTNxwZZGZiheOkW0yPZSR5wxcg+VJd8pl/ZHlAOo7sBanSlEb4GmxyPHqffTCpjyjC/JcqwT1kxUZe1EFeqOhdc33WXj9NRYz2T9YRmAhqsE4gCXVMBqLAh8g8aA/PqNfalHyvVcL63NZdhZW4smIppATWaqn/vJTLQr/WqOiFjY81hBHIFOwkrY0RpAVe1TWEdI4b+MlgwKdRj1TjgNTMl1t7a35yALuAJCmQ== 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=LT131qTY3XKG8ZBL+Sx+vXXLiscl2JkpDH3VN5e3yOA=; b=bSXHrDTghUIqUoY+TJcyNqHPNGdGIviTbStdiPWZJUrd+2mvFCCUDyaweohXiOJJ0DtAf/VjLTHCEgE0QHwF0XVG3iZf3XOokR7WUQfmhFkIT2dpNvGs/t6uSymPhUjeqOjIwZhloHcIGrONl0zwjBlNkKsu7eK8hwF2oX1l8gMg5HBezEiVJnun7PaJ2eGTBX+sGxkxi/hlumi/zFfDJThnIwxzcRVmy+hIoQvHrSH5isEBvrTlUfcwHqF/Kz8QUdMq7uXMceq9Jv3bCU4isCopeqLZ9V3aUjp67R3rWmTH3BnjesB36toeP2trb2pops7268YpBM16M5enwtt6DQ== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0237.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:276::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:58:30 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:58:30 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:22 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [DRprlQu8LonEB7wTowASKNP7EmdJLcXR] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-30-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0237:EE_ X-MS-Office365-Filtering-Correlation-Id: 4c16791f-c950-4ad0-b60c-08dbb94acbd6 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fzeOpYb6OON/f5N28AHTgtcylw6qHvgokSLV8uHk/f5bkrDzrfBjX5aNwz7/xSLTLGTK84i3bTHWU7iFR89dHMl9UKiTC24VeRje3Y76r6YnEKBg/MMe8p8NtehIHWGOG75bSL98r4Z0ZeK+OSsPSQl7SqqW8P4FXXQIGB9ni1cYSQuB5rx4p43VkoltPWHm7O8gQMFxHWZtLICkcxK//APFSbQpSK17on/vMqh6CSVM2Kr3RE9EbqYzyXRb/l7CAc6mFRciNcvUQ+uyqQYsbl1TbR7UF8pkKGduVounwtsk5ONr/Ofonrjo8+M8e8c/BopKRRkkt9xvZ8BKR4FhE+IlWxf5CO7FNCJC4yRP/oNEBiA926wsI7Dhb1rb4SoSVfeUU8EgF1KNVMvsgryvBVwS9WCv5bc4B+FcLYkMHgCz4NLUWfrSAE/8lQ8QK5VyhCzmkWS66aqpas3p/teuA6miWd0bkOLfy2hxJySrabQcw9J4qqh2k1Q6qBapIe1KVk5dLYYSLzVEgIGcG1+nZHGwtr0yClvAO4YsS4ZvY0iwiBEUJ1YD8C7aSTOMpvyEezEpJPFjGIjA/H2zXfXo5OhRtSqvCBBt6KjcXdhPb2xmSI2AO0lMPbGCi/hQ8Eea X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8N7xrCGWUNj5zvF/COST4fXwXLAhKTAGCZM3J8OioggGnZJR/T7+VfQK1sutjaErbXj7DgGfDjzuMZ2wjwSCI92C7oySAyQh37uF9nYMk4vGp+R7fo4R/X8ItpuTPDpXYy4nXGAiCizQT7rPxlKVKXOk/utcXpIGRBhyWaSjEb1oJPO96EgdGTZJhPCzt/ZVjeQ6fO7KIf0bAwfWl9JY44DUdCU+R7qJ63UnXhuyi3tuxqdBqcmSc+Js0u/A7zhZfoYQ9sDbl20U8GxRnwq5OsAEEpFEvlURBuB5GoAmfLzopAg47c+lud4Xm6TrpbcIvEEt4Sal0U40vw+KWN6OMeCywCkQXOwvtSSb958scylGwz4aKyIC7yhMhng4UxHZaaOyMtYt9k0vWfmwv46sVHPVw3c+dFm5Ft/FCX0wYRBjbo/mFccD3FdRAxJR7DJRMIktUQYOkb6Rnou6TO5cH6jZqOriYgc5ceqhrxvAPX/3x7l3sXyN7KUZmkRvSIRF3gi30GYmeX4BX2LKasjI9bFt5ppfd+HepLG88CuTyfpWZPMm3YD8oHQk6n3E64Df9WGf49BBVnhRyiO8BdG7C1oNk/CCtCa6eZvgJyJilMfkEz71kVN+GOft4UFCcB63VR19Tw8LXzHIns3L7S6128DAq5R+zwkwRVG8PbM8OwbY1y4Rh/dQ14kspLZVjk1E5eqYfCuN4zDbxwHKtqc7zDnWG+ArNESgYTkAtQnuPBnJtURBaAS+cDYYvvgTvHAfKGAp+xWHJu7rSlzWG8ZrkigbcjvuDACjBCDeARqRaY7GN4tycY8dw6x5qqGIqeQuP3K0eE6XootmN0QMYFQm+8hOofMF+U3MFjT5Dw/ZGGLC20g/WWAWf4UNCOMNleEdcCDILfuRavBt42DtyAQ1mSbUAHbm9DC2F2VSzycy1PKz6TMJtYZfLjeBrP48mM1kciM8jBooE1nOru1WI9ZbQUm1lNhkupwijTcUaRytWOdrqujv0a+NxT6RfDR+JUN0yWPFgVY5634UvhNxYTWrXSNgWFID6G7g4kU/4sbpykiMmvtHqd9A1fOsdg6ydsFhx/G3vktaNmf4gsjY12kCEPafi6LNseTjVwANe7wT9fh+e8EmkWt2arV9qzBFs0+EVcMJ0yfw8u29RG5aH+1nwvWlmJaYWncP4SkU7C+JpWDjd4IFENk754jbfhTspE8WFtXbFwx/cusQAy9MSKfHROsbCxRNbNvAbRwHhlNXo+7IoOccDw+8ZEOa5NG7zOUq X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4c16791f-c950-4ad0-b60c-08dbb94acbd6 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:58:30.3953 (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: DU2P250MB0237 Subject: [FFmpeg-devel] [PATCH 30/42] avcodec/vp9: Switch to ProgressFrames 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: oS/+kLDEE0W8 This already fixes a race in the vp9-encparams test. In this test, side data is added to the current frame after having been decoded (and therefore after ff_thread_finish_setup() has been called). Yet the update_thread_context callback called ff_thread_ref_frame() and therefore av_frame_ref() with this frame as source frame and the ensuing read was unsynchronised with adding the side data, i.e. there was a data race. By switching to the ProgressFrame API the implicit av_frame_ref() is removed and the race fixed except if this frame is later reused by a show-existing-frame which uses an explicit av_frame_ref(). The vp9-encparams test does not cover this, so this commit already fixes all the races in this test. This decoder kept multiple references to the same ThreadFrames in the same context and therefore had lots of implicit av_frame_ref() even when decoding single-threaded. This incurred lots of small allocations: When decoding an ordinary 10s video in single-threaded mode the number of allocations reported by Valgrind went down from 57,814 to 20,908; for 10 threads it went down from 84,223 to 21,901. Signed-off-by: Andreas Rheinhardt --- Compare this with Anton's earlier patch [1] https://patchwork.ffmpeg.org/project/ffmpeg/patch/20220315104932.25496-2-anton@khirnov.net/ libavcodec/dxva2_vp9.c | 4 +- libavcodec/vp9.c | 137 +++++++++++------------------------ libavcodec/vp9_mc_template.c | 2 +- libavcodec/vp9block.c | 5 +- libavcodec/vp9dec.h | 4 +- libavcodec/vp9lpf.c | 1 + libavcodec/vp9mvs.c | 4 +- libavcodec/vp9recon.c | 19 ++--- libavcodec/vp9shared.h | 6 +- 9 files changed, 68 insertions(+), 114 deletions(-) diff --git a/libavcodec/dxva2_vp9.c b/libavcodec/dxva2_vp9.c index eba4df9031..1352b9b7db 100644 --- a/libavcodec/dxva2_vp9.c +++ b/libavcodec/dxva2_vp9.c @@ -80,7 +80,7 @@ static int fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *c pp->Reserved8Bits = 0; for (i = 0; i < 8; i++) { - if (h->refs[i].f->buf[0]) { + if (h->refs[i].f) { fill_picture_entry(&pp->ref_frame_map[i], ff_dxva2_get_surface_index(avctx, ctx, h->refs[i].f), 0); pp->ref_frame_coded_width[i] = h->refs[i].f->width; pp->ref_frame_coded_height[i] = h->refs[i].f->height; @@ -90,7 +90,7 @@ static int fill_picture_parameters(const AVCodecContext *avctx, AVDXVAContext *c for (i = 0; i < 3; i++) { uint8_t refidx = h->h.refidx[i]; - if (h->refs[refidx].f->buf[0]) + if (h->refs[refidx].f) fill_picture_entry(&pp->frame_refs[i], ff_dxva2_get_surface_index(avctx, ctx, h->refs[refidx].f), 0); else pp->frame_refs[i].bPicEntry = 0xFF; diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index dac81fd712..c940206b94 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -30,9 +30,9 @@ #include "hwaccel_internal.h" #include "hwconfig.h" #include "profiles.h" +#include "progressframe.h" #include "refstruct.h" #include "thread.h" -#include "threadframe.h" #include "pthread_internal.h" #include "videodsp.h" @@ -99,7 +99,7 @@ static void vp9_tile_data_free(VP9TileData *td) static void vp9_frame_unref(AVCodecContext *avctx, VP9Frame *f) { - ff_thread_release_ext_buffer(avctx, &f->tf); + ff_thread_progress_unref(avctx, &f->tf); ff_refstruct_unref(&f->extradata); ff_refstruct_unref(&f->hwaccel_picture_private); f->segmentation_map = NULL; @@ -110,7 +110,7 @@ static int vp9_frame_alloc(AVCodecContext *avctx, VP9Frame *f) VP9Context *s = avctx->priv_data; int ret, sz; - ret = ff_thread_get_ext_buffer(avctx, &f->tf, AV_GET_BUFFER_FLAG_REF); + ret = ff_thread_progress_get_buffer(avctx, &f->tf, AV_GET_BUFFER_FLAG_REF); if (ret < 0) return ret; @@ -146,13 +146,9 @@ fail: return ret; } -static int vp9_frame_ref(AVCodecContext *avctx, VP9Frame *dst, VP9Frame *src) +static void vp9_frame_ref(VP9Frame *dst, const VP9Frame *src) { - int ret; - - ret = ff_thread_ref_frame(&dst->tf, &src->tf); - if (ret < 0) - return ret; + ff_thread_progress_ref(&dst->tf, &src->tf); dst->extradata = ff_refstruct_ref(src->extradata); @@ -162,8 +158,13 @@ static int vp9_frame_ref(AVCodecContext *avctx, VP9Frame *dst, VP9Frame *src) ff_refstruct_replace(&dst->hwaccel_picture_private, src->hwaccel_picture_private); +} - return 0; +static void vp9_frame_replace(AVCodecContext *avctx, VP9Frame *dst, const VP9Frame *src) +{ + vp9_frame_unref(avctx, dst); + if (src && src->tf.f) + vp9_frame_ref(dst, src); } static int update_size(AVCodecContext *avctx, int w, int h) @@ -584,9 +585,9 @@ static int decode_frame_header(AVCodecContext *avctx, s->s.h.signbias[1] = get_bits1(&s->gb) && !s->s.h.errorres; s->s.h.refidx[2] = get_bits(&s->gb, 3); s->s.h.signbias[2] = get_bits1(&s->gb) && !s->s.h.errorres; - if (!s->s.refs[s->s.h.refidx[0]].f->buf[0] || - !s->s.refs[s->s.h.refidx[1]].f->buf[0] || - !s->s.refs[s->s.h.refidx[2]].f->buf[0]) { + if (!s->s.refs[s->s.h.refidx[0]].f || + !s->s.refs[s->s.h.refidx[1]].f || + !s->s.refs[s->s.h.refidx[2]].f) { av_log(avctx, AV_LOG_ERROR, "Not all references are available\n"); return AVERROR_INVALIDDATA; } @@ -606,7 +607,8 @@ static int decode_frame_header(AVCodecContext *avctx, // Note that in this code, "CUR_FRAME" is actually before we // have formally allocated a frame, and thus actually represents // the _last_ frame - s->s.h.use_last_frame_mvs &= s->s.frames[CUR_FRAME].tf.f->width == w && + s->s.h.use_last_frame_mvs &= s->s.frames[CUR_FRAME].tf.f && + s->s.frames[CUR_FRAME].tf.f->width == w && s->s.frames[CUR_FRAME].tf.f->height == h; if (get_bits1(&s->gb)) // display size skip_bits(&s->gb, 32); @@ -1235,16 +1237,12 @@ static av_cold int vp9_decode_free(AVCodecContext *avctx) VP9Context *s = avctx->priv_data; int i; - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) vp9_frame_unref(avctx, &s->s.frames[i]); - av_frame_free(&s->s.frames[i].tf.f); - } ff_refstruct_pool_uninit(&s->frame_extradata_pool); for (i = 0; i < 8; i++) { - ff_thread_release_ext_buffer(avctx, &s->s.refs[i]); - av_frame_free(&s->s.refs[i].f); - ff_thread_release_ext_buffer(avctx, &s->next_refs[i]); - av_frame_free(&s->next_refs[i].f); + ff_thread_progress_unref(avctx, &s->s.refs[i]); + ff_thread_progress_unref(avctx, &s->next_refs[i]); } free_buffers(s); @@ -1379,7 +1377,7 @@ static int decode_tiles(AVCodecContext *avctx, // FIXME maybe we can make this more finegrained by running the // loopfilter per-block instead of after each sbrow // In fact that would also make intra pred left preparation easier? - ff_thread_report_progress(&s->s.frames[CUR_FRAME].tf, row >> 3, 0); + ff_thread_progress_report(&s->s.frames[CUR_FRAME].tf, row >> 3); } } return 0; @@ -1556,12 +1554,13 @@ static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame, int ret, i, j, ref; int retain_segmap_ref = s->s.frames[REF_FRAME_SEGMAP].segmentation_map && (!s->s.h.segmentation.enabled || !s->s.h.segmentation.update_map); + const VP9Frame *src; AVFrame *f; if ((ret = decode_frame_header(avctx, data, size, &ref)) < 0) { return ret; } else if (ret == 0) { - if (!s->s.refs[ref].f->buf[0]) { + if (!s->s.refs[ref].f) { av_log(avctx, AV_LOG_ERROR, "Requested reference %d not available\n", ref); return AVERROR_INVALIDDATA; } @@ -1569,33 +1568,19 @@ static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame, return ret; frame->pts = pkt->pts; frame->pkt_dts = pkt->dts; - for (i = 0; i < 8; i++) { - if (s->next_refs[i].f->buf[0]) - ff_thread_release_ext_buffer(avctx, &s->next_refs[i]); - if (s->s.refs[i].f->buf[0] && - (ret = ff_thread_ref_frame(&s->next_refs[i], &s->s.refs[i])) < 0) - return ret; - } + for (int i = 0; i < 8; i++) + ff_thread_progress_replace(avctx, &s->next_refs[i], &s->s.refs[i]); *got_frame = 1; return pkt->size; } data += ret; size -= ret; - if (!retain_segmap_ref || s->s.h.keyframe || s->s.h.intraonly) { - if (s->s.frames[REF_FRAME_SEGMAP].tf.f->buf[0]) - vp9_frame_unref(avctx, &s->s.frames[REF_FRAME_SEGMAP]); - if (!s->s.h.keyframe && !s->s.h.intraonly && !s->s.h.errorres && s->s.frames[CUR_FRAME].tf.f->buf[0] && - (ret = vp9_frame_ref(avctx, &s->s.frames[REF_FRAME_SEGMAP], &s->s.frames[CUR_FRAME])) < 0) - return ret; - } - if (s->s.frames[REF_FRAME_MVPAIR].tf.f->buf[0]) - vp9_frame_unref(avctx, &s->s.frames[REF_FRAME_MVPAIR]); - if (!s->s.h.intraonly && !s->s.h.keyframe && !s->s.h.errorres && s->s.frames[CUR_FRAME].tf.f->buf[0] && - (ret = vp9_frame_ref(avctx, &s->s.frames[REF_FRAME_MVPAIR], &s->s.frames[CUR_FRAME])) < 0) - return ret; - if (s->s.frames[CUR_FRAME].tf.f->buf[0]) - vp9_frame_unref(avctx, &s->s.frames[CUR_FRAME]); + src = !s->s.h.keyframe && !s->s.h.intraonly && !s->s.h.errorres ? &s->s.frames[CUR_FRAME] : NULL; + if (!retain_segmap_ref || s->s.h.keyframe || s->s.h.intraonly) + vp9_frame_replace(avctx, &s->s.frames[REF_FRAME_SEGMAP], src); + vp9_frame_replace(avctx, &s->s.frames[REF_FRAME_MVPAIR], src); + vp9_frame_unref(avctx, &s->s.frames[CUR_FRAME]); if ((ret = vp9_frame_alloc(avctx, &s->s.frames[CUR_FRAME])) < 0) return ret; f = s->s.frames[CUR_FRAME].tf.f; @@ -1605,7 +1590,8 @@ static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame, f->flags &= ~AV_FRAME_FLAG_KEY; f->pict_type = (s->s.h.keyframe || s->s.h.intraonly) ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; - if (s->s.frames[REF_FRAME_SEGMAP].tf.f->buf[0] && + // Inexistent frames have the implicit dimension 0x0 != CUR_FRAME + if (!s->s.frames[REF_FRAME_MVPAIR].tf.f || (s->s.frames[REF_FRAME_MVPAIR].tf.f->width != s->s.frames[CUR_FRAME].tf.f->width || s->s.frames[REF_FRAME_MVPAIR].tf.f->height != s->s.frames[CUR_FRAME].tf.f->height)) { vp9_frame_unref(avctx, &s->s.frames[REF_FRAME_SEGMAP]); @@ -1613,15 +1599,9 @@ static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame, // ref frame setup for (i = 0; i < 8; i++) { - if (s->next_refs[i].f->buf[0]) - ff_thread_release_ext_buffer(avctx, &s->next_refs[i]); - if (s->s.h.refreshrefmask & (1 << i)) { - ret = ff_thread_ref_frame(&s->next_refs[i], &s->s.frames[CUR_FRAME].tf); - } else if (s->s.refs[i].f->buf[0]) { - ret = ff_thread_ref_frame(&s->next_refs[i], &s->s.refs[i]); - } - if (ret < 0) - return ret; + ff_thread_progress_replace(avctx, &s->next_refs[i], + s->s.h.refreshrefmask & (1 << i) ? + &s->s.frames[CUR_FRAME].tf : &s->s.refs[i]); } if (avctx->hwaccel) { @@ -1731,7 +1711,7 @@ static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame, { ret = decode_tiles(avctx, data, size); if (ret < 0) { - ff_thread_report_progress(&s->s.frames[CUR_FRAME].tf, INT_MAX, 0); + ff_thread_progress_report(&s->s.frames[CUR_FRAME].tf, INT_MAX); return ret; } } @@ -1747,7 +1727,7 @@ static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame, ff_thread_finish_setup(avctx); } } while (s->pass++ == 1); - ff_thread_report_progress(&s->s.frames[CUR_FRAME].tf, INT_MAX, 0); + ff_thread_progress_report(&s->s.frames[CUR_FRAME].tf, INT_MAX); if (s->td->error_info < 0) { av_log(avctx, AV_LOG_ERROR, "Failed to decode tile data\n"); @@ -1762,13 +1742,8 @@ static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame, finish: // ref frame setup - for (i = 0; i < 8; i++) { - if (s->s.refs[i].f->buf[0]) - ff_thread_release_ext_buffer(avctx, &s->s.refs[i]); - if (s->next_refs[i].f->buf[0] && - (ret = ff_thread_ref_frame(&s->s.refs[i], &s->next_refs[i])) < 0) - return ret; - } + for (int i = 0; i < 8; i++) + ff_thread_progress_replace(avctx, &s->s.refs[i], &s->next_refs[i]); if (!s->s.h.invisible) { if ((ret = av_frame_ref(frame, s->s.frames[CUR_FRAME].tf.f)) < 0) @@ -1787,7 +1762,7 @@ static void vp9_decode_flush(AVCodecContext *avctx) for (i = 0; i < 3; i++) vp9_frame_unref(avctx, &s->s.frames[i]); for (i = 0; i < 8; i++) - ff_thread_release_ext_buffer(avctx, &s->s.refs[i]); + ff_thread_progress_unref(avctx, &s->s.refs[i]); if (FF_HW_HAS_CB(avctx, flush)) FF_HW_SIMPLE_CALL(avctx, flush); @@ -1809,42 +1784,18 @@ static av_cold int vp9_decode_init(AVCodecContext *avctx) } #endif - for (int i = 0; i < 3; i++) { - s->s.frames[i].tf.f = av_frame_alloc(); - if (!s->s.frames[i].tf.f) - return AVERROR(ENOMEM); - } - for (int i = 0; i < 8; i++) { - s->s.refs[i].f = av_frame_alloc(); - s->next_refs[i].f = av_frame_alloc(); - if (!s->s.refs[i].f || !s->next_refs[i].f) - return AVERROR(ENOMEM); - } return 0; } #if HAVE_THREADS static int vp9_decode_update_thread_context(AVCodecContext *dst, const AVCodecContext *src) { - int i, ret; VP9Context *s = dst->priv_data, *ssrc = src->priv_data; - for (i = 0; i < 3; i++) { - if (s->s.frames[i].tf.f->buf[0]) - vp9_frame_unref(dst, &s->s.frames[i]); - if (ssrc->s.frames[i].tf.f->buf[0]) { - if ((ret = vp9_frame_ref(dst, &s->s.frames[i], &ssrc->s.frames[i])) < 0) - return ret; - } - } - for (i = 0; i < 8; i++) { - if (s->s.refs[i].f->buf[0]) - ff_thread_release_ext_buffer(dst, &s->s.refs[i]); - if (ssrc->next_refs[i].f->buf[0]) { - if ((ret = ff_thread_ref_frame(&s->s.refs[i], &ssrc->next_refs[i])) < 0) - return ret; - } - } + for (int i = 0; i < 3; i++) + vp9_frame_replace(dst, &s->s.frames[i], &ssrc->s.frames[i]); + for (int i = 0; i < 8; i++) + ff_thread_progress_replace(dst, &s->s.refs[i], &ssrc->next_refs[i]); ff_refstruct_replace(&s->frame_extradata_pool, ssrc->frame_extradata_pool); s->frame_extradata_pool_size = ssrc->frame_extradata_pool_size; @@ -1884,7 +1835,7 @@ const FFCodec ff_vp9_decoder = { .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS, .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_SLICE_THREAD_HAS_MF | - FF_CODEC_CAP_ALLOCATE_PROGRESS, + FF_CODEC_CAP_USES_PROGRESSFRAMES, .flush = vp9_decode_flush, UPDATE_THREAD_CONTEXT(vp9_decode_update_thread_context), .p.profiles = NULL_IF_CONFIG_SMALL(ff_vp9_profiles), diff --git a/libavcodec/vp9_mc_template.c b/libavcodec/vp9_mc_template.c index e654c0e5ed..81e4ed59c7 100644 --- a/libavcodec/vp9_mc_template.c +++ b/libavcodec/vp9_mc_template.c @@ -36,7 +36,7 @@ static void FN(inter_pred)(VP9TileData *td) const VP9Context *s = td->s; VP9Block *b = td->b; int row = td->row, col = td->col; - const ThreadFrame *tref1 = &s->s.refs[s->s.h.refidx[b->ref[0]]], *tref2; + const ProgressFrame *tref1 = &s->s.refs[s->s.h.refidx[b->ref[0]]], *tref2; const AVFrame *ref1 = tref1->f, *ref2; int w1 = ref1->width, h1 = ref1->height, w2, h2; ptrdiff_t ls_y = td->y_stride, ls_uv = td->uv_stride; diff --git a/libavcodec/vp9block.c b/libavcodec/vp9block.c index 5743f048cc..554b4caebb 100644 --- a/libavcodec/vp9block.c +++ b/libavcodec/vp9block.c @@ -22,8 +22,9 @@ */ #include "libavutil/avassert.h" +#include "libavutil/frame.h" -#include "threadframe.h" +#include "progressframe.h" #include "vp89_rac.h" #include "vp9.h" #include "vp9data.h" @@ -113,7 +114,7 @@ static void decode_mode(VP9TileData *td) uint8_t *refsegmap = s->s.frames[REF_FRAME_SEGMAP].segmentation_map; if (!s->s.frames[REF_FRAME_SEGMAP].uses_2pass) - ff_thread_await_progress(&s->s.frames[REF_FRAME_SEGMAP].tf, row >> 3, 0); + ff_thread_progress_await(&s->s.frames[REF_FRAME_SEGMAP].tf, row >> 3); for (y = 0; y < h4; y++) { int idx_base = (y + row) * 8 * s->sb_cols + col; for (x = 0; x < w4; x++) diff --git a/libavcodec/vp9dec.h b/libavcodec/vp9dec.h index 013aac49eb..cbeb0b1bea 100644 --- a/libavcodec/vp9dec.h +++ b/libavcodec/vp9dec.h @@ -120,7 +120,7 @@ typedef struct VP9Context { int w, h; enum AVPixelFormat pix_fmt, last_fmt, gf_fmt; unsigned sb_cols, sb_rows, rows, cols; - ThreadFrame next_refs[8]; + ProgressFrame next_refs[8]; struct { uint8_t lim_lut[64]; @@ -245,7 +245,7 @@ void ff_vp9_decode_block(VP9TileData *td, int row, int col, VP9Filter *lflvl, ptrdiff_t yoff, ptrdiff_t uvoff, enum BlockLevel bl, enum BlockPartition bp); -void ff_vp9_loopfilter_sb(AVCodecContext *avctx, VP9Filter *lflvl, +void ff_vp9_loopfilter_sb(struct AVCodecContext *avctx, VP9Filter *lflvl, int row, int col, ptrdiff_t yoff, ptrdiff_t uvoff); void ff_vp9_intra_recon_8bpp(VP9TileData *td, diff --git a/libavcodec/vp9lpf.c b/libavcodec/vp9lpf.c index 414cede852..afeebebf59 100644 --- a/libavcodec/vp9lpf.c +++ b/libavcodec/vp9lpf.c @@ -21,6 +21,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +#include "avcodec.h" #include "vp9dec.h" static av_always_inline void filter_plane_cols(VP9Context *s, int col, int ss_h, int ss_v, diff --git a/libavcodec/vp9mvs.c b/libavcodec/vp9mvs.c index b93d878d6f..d0016d85ca 100644 --- a/libavcodec/vp9mvs.c +++ b/libavcodec/vp9mvs.c @@ -21,7 +21,7 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "threadframe.h" +#include "progressframe.h" #include "vp89_rac.h" #include "vp9data.h" #include "vp9dec.h" @@ -175,7 +175,7 @@ static void find_ref_mvs(VP9TileData *td, VP9mvrefPair *mv = &s->s.frames[REF_FRAME_MVPAIR].mv[row * s->sb_cols * 8 + col]; if (!s->s.frames[REF_FRAME_MVPAIR].uses_2pass) - ff_thread_await_progress(&s->s.frames[REF_FRAME_MVPAIR].tf, row >> 3, 0); + ff_thread_progress_await(&s->s.frames[REF_FRAME_MVPAIR].tf, row >> 3); if (mv->ref[0] == ref) RETURN_MV(mv->mv[0]); else if (mv->ref[1] == ref) diff --git a/libavcodec/vp9recon.c b/libavcodec/vp9recon.c index 073c04b47d..4af693608e 100644 --- a/libavcodec/vp9recon.c +++ b/libavcodec/vp9recon.c @@ -22,9 +22,10 @@ */ #include "libavutil/avassert.h" +#include "libavutil/frame.h" #include "libavutil/mem_internal.h" -#include "threadframe.h" +#include "progressframe.h" #include "videodsp.h" #include "vp9data.h" #include "vp9dec.h" @@ -298,7 +299,7 @@ void ff_vp9_intra_recon_16bpp(VP9TileData *td, ptrdiff_t y_off, ptrdiff_t uv_off static av_always_inline void mc_luma_unscaled(VP9TileData *td, const vp9_mc_func (*mc)[2], uint8_t *dst, ptrdiff_t dst_stride, const uint8_t *ref, ptrdiff_t ref_stride, - const ThreadFrame *ref_frame, + const ProgressFrame *ref_frame, ptrdiff_t y, ptrdiff_t x, const VP9mv *mv, int bw, int bh, int w, int h, int bytesperpixel) { @@ -314,7 +315,7 @@ static av_always_inline void mc_luma_unscaled(VP9TileData *td, const vp9_mc_func // we use +7 because the last 7 pixels of each sbrow can be changed in // the longest loopfilter of the next sbrow th = (y + bh + 4 * !!my + 7) >> 6; - ff_thread_await_progress(ref_frame, FFMAX(th, 0), 0); + ff_thread_progress_await(ref_frame, FFMAX(th, 0)); // The arm/aarch64 _hv filters read one more row than what actually is // needed, so switch to emulated edge one pixel sooner vertically // (!!my * 5) than horizontally (!!mx * 4). @@ -336,7 +337,7 @@ static av_always_inline void mc_chroma_unscaled(VP9TileData *td, const vp9_mc_fu ptrdiff_t dst_stride, const uint8_t *ref_u, ptrdiff_t src_stride_u, const uint8_t *ref_v, ptrdiff_t src_stride_v, - const ThreadFrame *ref_frame, + const ProgressFrame *ref_frame, ptrdiff_t y, ptrdiff_t x, const VP9mv *mv, int bw, int bh, int w, int h, int bytesperpixel) { @@ -353,7 +354,7 @@ static av_always_inline void mc_chroma_unscaled(VP9TileData *td, const vp9_mc_fu // we use +7 because the last 7 pixels of each sbrow can be changed in // the longest loopfilter of the next sbrow th = (y + bh + 4 * !!my + 7) >> (6 - s->ss_v); - ff_thread_await_progress(ref_frame, FFMAX(th, 0), 0); + ff_thread_progress_await(ref_frame, FFMAX(th, 0)); // The arm/aarch64 _hv filters read one more row than what actually is // needed, so switch to emulated edge one pixel sooner vertically // (!!my * 5) than horizontally (!!mx * 4). @@ -407,7 +408,7 @@ static av_always_inline void mc_luma_scaled(VP9TileData *td, vp9_scaled_mc_func const vp9_mc_func (*mc)[2], uint8_t *dst, ptrdiff_t dst_stride, const uint8_t *ref, ptrdiff_t ref_stride, - const ThreadFrame *ref_frame, + const ProgressFrame *ref_frame, ptrdiff_t y, ptrdiff_t x, const VP9mv *in_mv, int px, int py, int pw, int ph, int bw, int bh, int w, int h, int bytesperpixel, @@ -444,7 +445,7 @@ static av_always_inline void mc_luma_scaled(VP9TileData *td, vp9_scaled_mc_func // we use +7 because the last 7 pixels of each sbrow can be changed in // the longest loopfilter of the next sbrow th = (y + refbh_m1 + 4 + 7) >> 6; - ff_thread_await_progress(ref_frame, FFMAX(th, 0), 0); + ff_thread_progress_await(ref_frame, FFMAX(th, 0)); // The arm/aarch64 _hv filters read one more row than what actually is // needed, so switch to emulated edge one pixel sooner vertically // (y + 5 >= h - refbh_m1) than horizontally (x + 4 >= w - refbw_m1). @@ -467,7 +468,7 @@ static av_always_inline void mc_chroma_scaled(VP9TileData *td, vp9_scaled_mc_fun ptrdiff_t dst_stride, const uint8_t *ref_u, ptrdiff_t src_stride_u, const uint8_t *ref_v, ptrdiff_t src_stride_v, - const ThreadFrame *ref_frame, + const ProgressFrame *ref_frame, ptrdiff_t y, ptrdiff_t x, const VP9mv *in_mv, int px, int py, int pw, int ph, int bw, int bh, int w, int h, int bytesperpixel, @@ -514,7 +515,7 @@ static av_always_inline void mc_chroma_scaled(VP9TileData *td, vp9_scaled_mc_fun // we use +7 because the last 7 pixels of each sbrow can be changed in // the longest loopfilter of the next sbrow th = (y + refbh_m1 + 4 + 7) >> (6 - s->ss_v); - ff_thread_await_progress(ref_frame, FFMAX(th, 0), 0); + ff_thread_progress_await(ref_frame, FFMAX(th, 0)); // The arm/aarch64 _hv filters read one more row than what actually is // needed, so switch to emulated edge one pixel sooner vertically // (y + 5 >= h - refbh_m1) than horizontally (x + 4 >= w - refbw_m1). diff --git a/libavcodec/vp9shared.h b/libavcodec/vp9shared.h index b445a2a746..805668416f 100644 --- a/libavcodec/vp9shared.h +++ b/libavcodec/vp9shared.h @@ -29,8 +29,8 @@ #include "libavutil/mem_internal.h" +#include "progressframe.h" #include "vp9.h" -#include "threadframe.h" enum BlockPartition { PARTITION_NONE, // [ ] <-. @@ -63,7 +63,7 @@ typedef struct VP9mvrefPair { } VP9mvrefPair; typedef struct VP9Frame { - ThreadFrame tf; + ProgressFrame tf; void *extradata; ///< RefStruct reference uint8_t *segmentation_map; VP9mvrefPair *mv; @@ -164,7 +164,7 @@ typedef struct VP9BitstreamHeader { typedef struct VP9SharedContext { VP9BitstreamHeader h; - ThreadFrame refs[8]; + ProgressFrame refs[8]; #define CUR_FRAME 0 #define REF_FRAME_MVPAIR 1 #define REF_FRAME_SEGMAP 2 From patchwork Tue Sep 19 19:57:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43826 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp187850pzb; Tue, 19 Sep 2023 13:01:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEHYS4RjXCVM2sNUsWQ5bI9NUPOIrhR0L4jVrjDfIExO8QnBtNpyyvBVoTVoABgAHxBmiyC X-Received: by 2002:a17:906:7488:b0:99c:6692:7f76 with SMTP id e8-20020a170906748800b0099c66927f76mr390634ejl.16.1695153708299; Tue, 19 Sep 2023 13:01:48 -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 ox30-20020a170907101e00b009a1aea8249fsi11109660ejb.314.2023.09.19.13.01.47; Tue, 19 Sep 2023 13:01:48 -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=EmdwF9CL; 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 1FCB968C9DF; Tue, 19 Sep 2023 22:58:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2011.outbound.protection.outlook.com [40.92.91.11]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C83A468C909 for ; Tue, 19 Sep 2023 22:58:35 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cE5PdZ23w1fh+kSmIPiMSYIuqtROiVP/KoO1HmerE/ChQMGISXqdSyZ0KvIqtM0gqKIylvdUm6KF8yhAhUN68V6EMm1SnYZQA2O/dxJqgnQIV8r93mk2IVgMN7OWGHAtuwj1bzAf5GbLJqHPFXdKuYbO0igUCU0OFDmLQI5qmTd+gDOZohUkm5ajFraCSGbHnNMwq0QdqBwMTtbGqn+GaOs79NggsZyUnx3aHBWqoOI9ezh8jd+XKHiGO6GdX2X53Uo+X1kFLLDJeGh2e63X2IATMG6x20vS9M77GpmbvO8Hn93VvxfmKs+TnZiivw5f07dQ0l4NuE39X0dKlJQ0kg== 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=zreu4ktSC7xVVnQmWJLR1J8AXNqV8+mci5K20pUIByI=; b=FuNzB+GrjPPsVRDgQlhXNXfqwBJu2HegJKzb4MDSNUKh7h+hUMZIxxJHPX/uX3gVkBxatqbdqnQvqsewfDOrifdl3oI9HoSXeC9wkxF7FZYJnDtPJQHJ5rE8oPljApOZhmxbsK7kOwi+MKHNUod4zXlH7lHE78+Vzk+2yFe5TiGQ0oym7BSs+L1/C4gr3BDypX+CCA9o9cR3B4ggplkOqf75LgtU98DyQTaIugZy34nRhD5MSsJ5b9pzqxjMPhqh2DQuZzfCnxCSzB9cX6dW1L8XkacYUINXkLrCnSxWJzICRU7bCKya1ZklCOD22po9H+RAKSXiH9/i1yR74kAIUg== 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=zreu4ktSC7xVVnQmWJLR1J8AXNqV8+mci5K20pUIByI=; b=EmdwF9CLD2gpknqI6D1W7YfYuwLEs14vUfkVcV0mDycpKi1cynN7/S5wYBnapm2V0BMSEkOKC6zVt3ZRQpZRpE7Ma5SUVKJti5H900HYSyoog7QD6HRKXmCWifibhbhSb7Y9ZgeCIze8aDnZqbj4hNJ2YDQVc2CPl6WaIGinZdmx55B5+rD35+dD2Ry+UWHJZRROKpryYE2kkuwGHwBnbz5H2Okbu9avDAYLoRZ61U9YccAdQA4Epn3ybpARYbu2p+Ipo2S/Mk5mmcfyinvVNz+GhEXXOgZ12M5/LVAXa8ju0uoGGIlcLBQgfOE1Xp4EuAKAAqBdUiSfnxE+kypTkQ== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0237.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:276::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:58:34 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:58:34 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:23 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [kQdlCWb/TKQtZo/bl0UKEP+D8s9UjPAW] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-31-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0237:EE_ X-MS-Office365-Filtering-Correlation-Id: 641a767c-e606-4fcf-4611-08dbb94ace09 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8gIPW5yYC/L6322wLz2qL//+SQ6H9kGo8o0clrDKtEPbbqx0YU4tiBK9USxnHV5lRpqWNE6MOQLDH6yVTfJRIdui1uq2w9b8o1+jUJrgma9TjVoBXEesL9TNLgrNnLH6wyFZ2n537yO84grq7QRM3JpVR1uqw6UMJXszE0cD4ouy9Smgxft+a+hAVenSRlsLfOdeqSW3SQxxsA1tJyoU6Jq+m4Qrv6BqzDDI1o2nQ1DtLdkHc5mYHwBetI3tQUFvzIVHATG8mTj2w+VG5iz43B/unCgWsTmUvO/xYoPk2PYMYQswJj5bqeU7zGtMPUxvp1infx4JsONtNx2ACCx3RzrsTAOIFHo9m5dzhDAF+IJIzjEO731x54Kw1Qa/BrcThcvKUV4QfEo8AVpLIAzuocoHZmcmVLe6YizvzjdRAbQ7UxyatO1mzgmm1GzAJ2xbRYSOLv27XWe25NbOdwGubBLFWwiGGvY61EGoghimRg8tbzdNrlMmW6+7r0Z7OdPobGkVmunncc/OoZwhm5qGrfcu6zHxe9X8tMaIqV8kgSj9Kj2UvsJagSPaCNkwMidmK0QHmoo2gt5QzBRu/VRGC6F09u/D+bSh0olA5OcsKXlpWOvF+j87z+cGRiLSkNRs X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: O72vSzWFhmJpTipWID1Ym4TyTk/Ou4uZVGK+4+kc9Abi2sjn83sa0km3dce+LlFcTk7sOqCHqvyQe90bbvYxagiKDZAE/tu+4cBADzSv56vEYABl5+BbTJRx5bdY8PglrogSIaFJLavvHHXOqBOSeeCAQMuSBjkvVYeyL3yC02HqDmlspQ4DVZvNCbhA08Hg/Wk8j+ZY/dY9zYUKl4AgyzaHA1EKfI+8Varc7d9scwuBDbsO5VgpdbsoTDTLnn83yMHUYFfUYdv/ossuEfL48JA1aL2AqvTcp94hI96N5QbtSG/abI9WgdvN3W3OY3CouwvOIRE337c06Inlyc6fXJmGrlXCp2sKdVUq0MjQ9SteiIV0hcD8hcNoC3NVIfgkSxNik3TL/nPK0lDjxgcEu1tiQ1L+pT+NibAl/s3+yt6fVJpjge+TJu/CMTikStpZQuzYndTqssnGnMm5s4hhfopCUFbCsBfPm5NWD9jHmRReDW7jzk2Nlkwgs6fJKjwOjTfNFWlKUxK7xKOHNHsprj1YeTWLp1yrIZNN7IJlIVY5U7kMTfeUNYZu1DQlKCDUyifvkxDphEm9xzODCkHSvgqjJoFVmz8d3+/EJ27S/2z8oYy0UAmnx+MhcamVAqkS5sCAq0Wgphya5lZCNWdokyUCyqUCpPmO8CTejInFvr0yo9h/dJW4HD40MtKKCJbR0zgHQE66JPabKE4if7Q1KjFo0Owb6QYkv2dD5zHTU35loLq4EzMVH4HdigT//vPC23r/R9M0Ek6/AihS3+ZEODlJlr3KaQ42W19DRqp1XQj4sKjnYcMiojLAfcODs/sTZtzPSvQ7qvurSav1EynNbBFxXiF62o8iIlnUU84xYt0QPLtO2GjqUYATscpVmln0aLOn8wAoLRr0GoCFYdVfJOrlc67vQU++2YlkL3Tk5OTdQ+XoHIWJM51Ho38+yl3lTbbH1Gkfjxhpm8pOr1JAGxEXQ9Vhi0pNlO/PSuLyLsXmJDTA68wcJvWLULBGYZdIuCrl3H9NeAlqJ4aoofeBAW4aQUrirUfncVRqT2LM98OFt/69WLkTZ/3XPWgTlYdgnJqImeyIlHIHZoVyteCFFutp6eMxUPvrTAKUIR3K6L5GWLBuz9KsN0ZrVX4wtI4vqlmTreL5qkDDFdbV/yyMLfhjy9uP5bVgEXsPNrSaqmwXANP+je7qlh+tjtDvtHKW4he1EvSlJySNC6AidXLH+l5g96h7HSzIH7nKD9TcLg4l7H0u+Tus5tdkthS5myIc X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 641a767c-e606-4fcf-4611-08dbb94ace09 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:58:34.5200 (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: DU2P250MB0237 Subject: [FFmpeg-devel] [PATCH 31/42] avcodec/vp9: Fix race when attaching side-data for show-existing frame 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: NvFUwTQjth0D When outputting a show-existing frame, the VP9 decoder simply created a reference to said frame and returned it immediately to the caller, without waiting for it to have finished decoding. In case of frame-threading it is possible for the frame to only be decoded while it was waiting to be output. This is normally benign. But there is one case where it is not: If the user wants video encoding parameters to be exported, said side data will only be attached to the src AVFrame at the end of decoding the frame that is actually being shown. Without synchronisation adding said side data in the decoder thread and the reads in av_frame_ref() in the output thread constitute a data race. This happens e.g. when using the venc_data_dump tool with vp90-2-10-show-existing-frame.webm from the FATE-suite. Fix this by actually waiting for the frame to be output. Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index c940206b94..79c4ae0205 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -1564,6 +1564,8 @@ static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame, av_log(avctx, AV_LOG_ERROR, "Requested reference %d not available\n", ref); return AVERROR_INVALIDDATA; } + ff_thread_progress_await(&s->s.refs[ref], INT_MAX); + if ((ret = av_frame_ref(frame, s->s.refs[ref].f)) < 0) return ret; frame->pts = pkt->pts; @@ -1710,10 +1712,8 @@ static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame, #endif { ret = decode_tiles(avctx, data, size); - if (ret < 0) { - ff_thread_progress_report(&s->s.frames[CUR_FRAME].tf, INT_MAX); - return ret; - } + if (ret < 0) + goto fail; } // Sum all counts fields into td[0].counts for tile threading @@ -1727,18 +1727,19 @@ static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame, ff_thread_finish_setup(avctx); } } while (s->pass++ == 1); - ff_thread_progress_report(&s->s.frames[CUR_FRAME].tf, INT_MAX); if (s->td->error_info < 0) { av_log(avctx, AV_LOG_ERROR, "Failed to decode tile data\n"); s->td->error_info = 0; - return AVERROR_INVALIDDATA; + ret = AVERROR_INVALIDDATA; + goto fail; } if (avctx->export_side_data & AV_CODEC_EXPORT_DATA_VIDEO_ENC_PARAMS) { ret = vp9_export_enc_params(s, &s->s.frames[CUR_FRAME]); if (ret < 0) - return ret; + goto fail; } + ff_thread_progress_report(&s->s.frames[CUR_FRAME].tf, INT_MAX); finish: // ref frame setup @@ -1752,6 +1753,9 @@ finish: } return pkt->size; +fail: + ff_thread_progress_report(&s->s.frames[CUR_FRAME].tf, INT_MAX); + return ret; } static void vp9_decode_flush(AVCodecContext *avctx) From patchwork Tue Sep 19 19:57:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43838 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp187987pzb; Tue, 19 Sep 2023 13:01:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH6eKkU/eQaz+tZves46ZUm9YTNBRtnhvmM0r0Wt/ZKb0uWSB8tOkMi9y2dZKpe9pE5YlMx X-Received: by 2002:a17:906:8a6b:b0:9a2:295a:9bbc with SMTP id hy11-20020a1709068a6b00b009a2295a9bbcmr676292ejc.37.1695153718958; Tue, 19 Sep 2023 13:01:58 -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 i1-20020a170906a28100b00993a7ae9f37si10306809ejz.882.2023.09.19.13.01.58; Tue, 19 Sep 2023 13:01:58 -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=rcF75I7S; 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 6B14668C9E2; Tue, 19 Sep 2023 22:58:44 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01olkn2109.outbound.protection.outlook.com [40.92.65.109]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B52A668C63B for ; Tue, 19 Sep 2023 22:58:37 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AggEMG8nBqpKqhitirVPpb7FKzkYDHEazUhbUjTkbb43BIzfnKpWFeEp/PzrpkZQ5nR1AJIn6cXmyWn32me1gAHFrGCB/8fNGxVhaiJDMp9JyI/eiLcAFPTdgD+5NUKr1kpUOhreV2lbfkygYN0t+pqwTpoGUMd88QaHfyEYvaVAiERSYOqbazRvN7iEuqjgOAcfBQGdgTf5lCiBCRygS7+dLvROQop1V/WZWW74F2tLTiNwuLMDWSOChlQApuR+QLKfeu8dFTI637V92LlYhxNSUsZlCFJg/i82ExR+/8XJKlXZA4gOBQAPceOB6OmAIbIS+pbn8Mjyz21soaljyQ== 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=qCPOGOBkbMrAfnbqzvX5c89EJIGaLdjpNWsKB38xgwA=; b=RdIOMTaQCTZIHrUTt9E+F2VEN4cMrBjIsZMXwP0NLz3QQ72EkIRLsfyorNS7pq9b+E1CBPqBXXL26zXSIuKoHWu6x6/URDZ+Ei3xn2h9CJFSCifYBF8q5NvPUlly9jR2NiyN3MlB/ybIgbdNfST3sQWEAzRXEeueMiM2uctLsFy7x3a2Xs3O8EChnUiJdyuKtR9X5Ww4l9Fz8t9JEtvXEVq/FsIiV/WtFl5VSFnPavsiCOpQjofDHV/Sh3nDdxKu1bTkwUofwxm7kUZdiwYH0EYnKPjnnGdMz6Oyg2FM7uv8ton+MzDS/QtviTFu8CpO5vo1qYpP1yJaVLzspQOn3A== 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=qCPOGOBkbMrAfnbqzvX5c89EJIGaLdjpNWsKB38xgwA=; b=rcF75I7S0V7scoU/6bBjNPValhZpPKXWysG4M0x6pyuxCyHx6VXrYoKxiX/pZgxR+Z3WdfylKDhd0av935jsVaDYnS2m1fgJ1prbHY/33T7z/mY3ixK0zV4sOJP5ItEjOGRrC9d9b5x7VmDyJJPLp+7he3i+aPCQTu2Al9yEX0r5jWUGHKg6IvcokpziCRVc6IDxqQoQcpyDXzoz/t10T/HSnHhGS32HMz5tjoxZXPWsCm9ixDVZCcApPBGUtMwlrFYRbnHw6Z+KYrHy+456T25439/IZ0tWdDQ6G9CpEipqfDH06n4eT61Xh/8qOqgmzSpKldOZjFh5CNJ8eXDRLA== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0237.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:276::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:58:36 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:58:36 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:24 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [yTWZEpfH6mm3gasXE4USyE2HlGm3vD/X] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-32-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0237:EE_ X-MS-Office365-Filtering-Correlation-Id: 72ff803e-1dd3-41e4-84d9-08dbb94acf7f X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: foS57C7p7MJvbbfjloQcXqGeXN5FQ+U588rfcpHjjuo2GACPkvAWahf8atabPtyK1X1BJaTODPoqekWYloioP6mBCkADgoK0WmRZJX59Kqhq8AHc2tigYwiCW8V4tZVO18rpOgjwXIPcV2C+xeXUAiM6GrvEZ9wD7U0qVE/Qn3xgN0S7V7h5rJvtrKjsao9j5ouWen2PgPJJSSROoTkfuhpB5MqkQRSFgDQ8JEAmYYTMc0ON8iSFsfEz0DdKQNfOND7h+V+7XLIglyyshRfilUlzdDHNv3gVJ658AVdRSXMe08oR+fhqrjS8Rw6iiORUsbvNF+3fOxrhcdZkLhVEkeif9wyUhfrfdKwhLDFRH5CO0o+L3U6+1eCUp5JVY2x0g7qQ9pcC2Hr021a9MdbBudb0N8I+iheKGCGAb0H/5HxfhwSd/Z3Uh+4TuZMYgcDX03Toe0VsgJpAKvnJ3u2oJ8mAwBq9Z7WwmEoS4sXl/+4jjZocGS6BP4nMB6diVGNvaqUgkZv1I7b6Zbgqh+H0b2Qf1Cm4Om7duOwuhIvwTuwHKMfOt2kO/IziMQHVm+SX4a6rbh50Epw35wSO9Be/X3b02ZGyfArBV1E8xkY5xY9R6S3CEfHitmCjpwL+FjK/ X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: S4Do/CO9J3b8iLtKbF9bDGcmbQ8dnfXwlgv3eviAvbJM+pitzs8AaHOmXD2If1Am2dC0cBsbtw+CqjlyLXRK00SLdeHWJ+1CYDhbIZ7+mDmrW0C3DAlolsaeRwAcuqFVbl4IFoLYKRy4AsLXd7gfgJK4/T40yUbopHQ8GWPCusuN1JpXLxFYg408TWeIGxnqX5XODG/MPzF9eLxUVAVdsKTuSmQz/GXsLVXhySqqlv/8wX0dgHj1bs2qVeYS1+GtHV6ZWry+pf5WTWaxlZK4eURz7x7WARMl1Di56hpGBv5F8ufHGAQF8uHVk3osjyegFS8yRtKsiPg1xnyG5XsV3aKnkgquYKJNriXDx8fusyO1brKEc//BlSrb2XE1NQZ7oapsKaUPExIhC1p9WyJ2RqeE22PgmMPwNO49clZqNKSdvl6qv6mFqPNraZGVou1s3yCoB7w5+8RgqY/DBeoBwSZMxZhRIhs2AGHFj3qtVd+NV/1KHQMp9QkO9/ZDN5K16dxRZ1WSkWebTRlSSgsp7oE+aReTtuwN13cCPD6+aST0K9ahIZ+XBj+mLnbcKiXLZ0eKNv4Uiqgndz5ZIVFS1W1Bccw1Z/Eoljyq76gp11He69/IEpkBt2u6rn95TUaJ3zMVlqGdoNv0291slSrakxVaDyEA0qbOIwgF3Y7pqU/NY1yUE8eT9aSEWKWsCYBi0h4UayGmyuR+lmCO+4rA1/sLYvHPEuOoLh2SNQ78R5uSnEeCa9sd9eOc4A5EoA5gFdguu0V4gW3AXspMp72+ceyhUtgkexPLbp8MxR6j6AAwcaKWC/7KXQZQbRuLcDbFyJVYoGf4qt4bJkvepl35PD2KhgzEbDZchuVwBRxrRSEzISOftaE2Y/NZTPB7PJB3+zlObaKrrD/8sGAt0fcXM4iQbEvrzxgs/e/okGWPHHRXYj/4PEP+S0nZt9SIrfV2Q4EcwPtCTw3rX+l4kw4/5bOWBXtnpdAXufAGuVKvSbeMOoXUMetg6REhSUqGWAQ7n5NZiYz2pinJXzpwd5FrnBcFgdLIIht/P8ZqJCHur0rAJCDQeggvhPHHbfisieWwusGuEnSW9GJOHYFetyK7kB06wHMCq2h9L6XF466xSNT3eH/gl3VdWM3gQs/7WXALhpBL3Ok3F0nPwkgP4ploLdbGI05NZs5QSMXYfXRrpo+P0UsqfDJqyYelbx9WhncoYrXm5yqP3Skeg8+ukOw/XF2mPHDjcb5a5kZUVoIWED2nnnQNYkTEtmcFod97IU6k X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 72ff803e-1dd3-41e4-84d9-08dbb94acf7f X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:58:36.5764 (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: DU2P250MB0237 Subject: [FFmpeg-devel] [PATCH 32/42] avcodec/vp9: Reduce wait times 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: sEnz6VljeV/q Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 79c4ae0205..87c507bb36 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -1564,14 +1564,15 @@ static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame, av_log(avctx, AV_LOG_ERROR, "Requested reference %d not available\n", ref); return AVERROR_INVALIDDATA; } + for (int i = 0; i < 8; i++) + ff_thread_progress_replace(avctx, &s->next_refs[i], &s->s.refs[i]); + ff_thread_finish_setup(avctx); ff_thread_progress_await(&s->s.refs[ref], INT_MAX); if ((ret = av_frame_ref(frame, s->s.refs[ref].f)) < 0) return ret; frame->pts = pkt->pts; frame->pkt_dts = pkt->dts; - for (int i = 0; i < 8; i++) - ff_thread_progress_replace(avctx, &s->next_refs[i], &s->s.refs[i]); *got_frame = 1; return pkt->size; } From patchwork Tue Sep 19 19:57:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43839 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp188118pzb; Tue, 19 Sep 2023 13:02:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG4jtLlQbnHtbTMe+FmKprLbREesJQqswcxdGsGidw6qGg9e80NPQqulioR8KLXvsi3Ojht X-Received: by 2002:a50:e70e:0:b0:530:f74d:f4ab with SMTP id a14-20020a50e70e000000b00530f74df4abmr423297edn.11.1695153729581; Tue, 19 Sep 2023 13:02: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 i15-20020a50fc0f000000b00532c83edd35si1300407edr.416.2023.09.19.13.02.09; Tue, 19 Sep 2023 13:02: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=IWBVmT+x; 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 3A8D268C9A6; Tue, 19 Sep 2023 22:58:46 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01olkn2109.outbound.protection.outlook.com [40.92.65.109]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2050468C63B for ; Tue, 19 Sep 2023 22:58:43 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XplFk4DD40FON9jayw/QG9qEnMc/mQ0Mz0bE15dtjm1OoJvavvupLxsUb3qE9/C1U14GxMMzi0wX/LYpALzPaIXSiScGqeq5ce0LkwVTGIxdysskfpuyYfnbSgex66ciafanR/6O5CiASO+4fcIpomsONnJikCwt+F65JHq9/Pd1arGhnjDFRmwaA1Q4jRU/OVTA/J7qXR8tKoS1ShdWoSk4gLuw1j40jC8eFpxAGcVWflx3b3KV8Gg0G4wk0goB4hqNE6NQ//srSYw+w8no9RvjTTGNpr09K8DPbbXDREUIt9OijgUiYpkQ3GqEJMxtE2d4BGetxs/W2nautWyznw== 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=+dFYx+41gVNyR4O9QOXY2l0WhK3753MNOOd4ON7uFz0=; b=a6BsU4Vpyj+ushdyciFtAjafM/PzX69OsZRTR2XBGZKawhvOOAt2rKeWHuXDu1ExElOqpxAjHGnt9oJFsirkeomUaeE82cEfgf+iK1QLYEkcjeF144N8lFnLaGv+5WYrj6mHLtM2Wg9932Z2kHgzXfCLYOPObD4lAOegj5/KxAdWIEExs6E4m288wtXxnD4H0cEnNs0RW5BK2s3wYq1X953SPr5kDZbnlD9zdEine0k0CQ2yeW78b1JF4PXnUzN5CkySwG4uCB5Bc+M73KUkfcEl/ppVx0QCnOS+sQrOC0YxwYvGv/xuiue6TkCmzEAbvcYkRNiOJ/HiZ4zK+lmkwQ== 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=+dFYx+41gVNyR4O9QOXY2l0WhK3753MNOOd4ON7uFz0=; b=IWBVmT+xzO35ORkzBYuju+pSO95phVvqkttLlZghBlGWttBplU2A3r1SsOqlf9w2zCfPS/JNm3KAyENKj0pO20SyLJhKT7JPiYOY2T+kwiOxjepbxWynh1udGoWOkI0Hh8BJEw/kXkZeL7CjjbyJ2X9ri07GmYRh+X5dHIi4huNNHGXvi8Mo28RASr2ZyKDeA1IP9AybYv2LhuCk9WMRzH0TI340z9Y4t3+JRBQRRGFbOXRI7cafkQ25/y6hIqoraa3ETn+tZUbbS/r1zMrA26PXf6fJG1N3RCbbDs118HEBHi6WmgkIBwSr1eG7UQH2AP2d8hxk9lIunT0YV8ob6w== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0237.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:276::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:58:41 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:58:41 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:25 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [rTU6QJZiJhPEIQADIxTtn5HKkmOcmF6P] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-33-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0237:EE_ X-MS-Office365-Filtering-Correlation-Id: d7b61f18-de1d-48a0-166f-08dbb94ad260 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rLMMTQ4L9sG2UiUS4p/ASRCDcW+wZjk3X7A5sFOAeVAsKP9cZGhCArhgkWkyPYGr3WXkcUeGrfl/+SS6AIBDkkEOmYamXoF4dm9Pq9a0DZPpVTRtQOfhlr2yxJEtBx36rr+gx38WkBaqY/IebLvmX1p4S8gVqWj5FpiuEVVvD9c8CCotxve58x+ROR7E+v8F/4adR6re5QetAdqLMshlS4CWZ9DmeBH5vJlfRO9XFU96nNkcWMXRupwEcNn+i0vbBEWsGALXvf3QuLlZhbYf4E2bfUHwalICipp5d76aqA97x2r77yffy9nR2gFBKXZ3mWb+bkIStjiQlxi2EMuLC3EgehGOj4UYSxbXro6PHSIgJCXE3k5p6SH6qFsmIdrD0pIPDxt3bji/XM9H4qz6tvJo2ZFv2/y14qQY8j+Kw2Ox9V6iuMJ7Vuyz+irZboEHXg8pl7dVimsVU9aI1gMmRX96XixRsLCw//OozDJNxegroDlu/LWr7lIRTIqBAJzx85QDNDvV3k2UsWhm2MFPIUdYs9SQWifmoaMtoIJtmTCi+lsWgdV9DbzLj+Zf0vGjG3ZFYGhx6CAu+/El3SW57w6sCueagF3Vp6JJt8k1cZXAGo0YcCrvYVB8DrBBYl/g X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qUcNCUW+QWX6+kGFqJqkLgmXJSeoGqlAOff4ePuvOwqENr3IejSr5XimdO11w10lviOnRPnFzim8CB20nsoeFbg3u8bDsAuT1Nz3Zv7IjyTf8MHetHn0zG9DC4MSxYzFQCQkjr2MZ7B+hnepfGnq5y3yTdGqmk4gzCVyK+tfTJclaS7kKAty4S1UVrd0UqsTD2Mo/wauq+cxHDaE8HeR0I+ZLzInaMZtySQsomkOGx8HzLkyOfAlga91VAcm/tiH1QyOcKjEvjfUI5zsolxX7L/IzrylYdMFPk5OArQDrkVkIzcZJeFjycAaNh8ic8bajA2kz/UQycqFw2HjMsvBA9g4/z+ngvUn6Cf3LmG6B+2cl6budhN2dwXjk6540R/BmYGWhUQXKAaOSHg7o18DvypdfFWhINUYeXRX/U0Th86d/2DpuBH6+yK89JQCWOAjYydM+52ktfrzel4Z+eae4+KxbID6k3F6SQZPBId7OCrLxJCVyqoJF2KQQKWltoZUZkI3w+nohI+UWDUvRO/Kovb6oOFc6PBFM5h1Mobt/nCH6abxdtr8tX5hVGDBI28BPBigJZN099LWrxGxhCN5m2tUTgLcb54MJlAvxA1JRQALz3G8pym/97v/AmNKCTPbJBgId7jSQ6Iygo0uriWp3kVV57Ub31yAbpGvKBaRqApQLJzU0nspSrf6V/7/gefKq3v8djxOHzLpZ00S/5fHy4FY6py3tzgQK6ymHUxQuhCPAIdlP+CgmuKT3rzcIyjGaSZeO6gMa3I9lhVbh33MWhr6guXjXvVU5LWVGou6Gxv9s3qmwYsJCQDWWka5TVZhghBHBN0LjvAQf+AQngQJ/Py15uQyFaTBhztp/XNdD3KqVyA3CLVr+nLvTJJ+PCxKKfWSNEwlRWqiy1+PRWV3rpD2fXNKTCtcRW/XHrXuZQMvdZuSF1vvx9NCuIAnZpTnJmampNH7zdkqK0Pn/jQ90/XyyxcTw+HejuTKKMRqeOnXsTAv7DN8TdueXo8ZrUgzH4SmvVgpDy2thcoGgD1uPbNqoNrqr2xNaEocoIsgdC4XC9vZYUhBzo9VT3PasaL7u/+VhTFvPkbmScrNB81JlYCC/6QcK6o0sCgXwUvaAAmSYXhPtsnaln62xlHLk+wTaf1JJmkH4ivMulFaNvKB5WTNM8nnVktotB6MH6Yy2DeUG46Gi1bdMi0a6qLADoWGEffIJXpK3vDsw0YJosqlKctW/C/uJ/8CYPFSeAHfFmSmcNHgw/Pc5TP8XHKTakoR X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: d7b61f18-de1d-48a0-166f-08dbb94ad260 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:58:41.3456 (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: DU2P250MB0237 Subject: [FFmpeg-devel] [PATCH 33/42] avcodec/vp9: Simplify replacing VP9Frame 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: bP77i3pPGgYx ff_thread_progress_replace() can handle a blank ProgressFrame as src (in which case it simply unreferences dst), but not a NULL one. So add a blank frame to be used as source for this case, so that we can use the replace functions to simplify vp9_frame_replace(). Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9.c | 16 +++++----------- libavcodec/vp9shared.h | 3 ++- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 87c507bb36..8eba56b720 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -146,11 +146,11 @@ fail: return ret; } -static void vp9_frame_ref(VP9Frame *dst, const VP9Frame *src) +static void vp9_frame_replace(AVCodecContext *avctx, VP9Frame *dst, const VP9Frame *src) { - ff_thread_progress_ref(&dst->tf, &src->tf); + ff_thread_progress_replace(avctx, &dst->tf, &src->tf); - dst->extradata = ff_refstruct_ref(src->extradata); + ff_refstruct_replace(&dst->extradata, src->extradata); dst->segmentation_map = src->segmentation_map; dst->mv = src->mv; @@ -160,13 +160,6 @@ static void vp9_frame_ref(VP9Frame *dst, const VP9Frame *src) src->hwaccel_picture_private); } -static void vp9_frame_replace(AVCodecContext *avctx, VP9Frame *dst, const VP9Frame *src) -{ - vp9_frame_unref(avctx, dst); - if (src && src->tf.f) - vp9_frame_ref(dst, src); -} - static int update_size(AVCodecContext *avctx, int w, int h) { #define HWACCEL_MAX (CONFIG_VP9_DXVA2_HWACCEL + \ @@ -1579,7 +1572,8 @@ static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame, data += ret; size -= ret; - src = !s->s.h.keyframe && !s->s.h.intraonly && !s->s.h.errorres ? &s->s.frames[CUR_FRAME] : NULL; + src = !s->s.h.keyframe && !s->s.h.intraonly && !s->s.h.errorres ? + &s->s.frames[CUR_FRAME] : &s->s.frames[BLANK_FRAME]; if (!retain_segmap_ref || s->s.h.keyframe || s->s.h.intraonly) vp9_frame_replace(avctx, &s->s.frames[REF_FRAME_SEGMAP], src); vp9_frame_replace(avctx, &s->s.frames[REF_FRAME_MVPAIR], src); diff --git a/libavcodec/vp9shared.h b/libavcodec/vp9shared.h index 805668416f..8a450c26a6 100644 --- a/libavcodec/vp9shared.h +++ b/libavcodec/vp9shared.h @@ -168,7 +168,8 @@ typedef struct VP9SharedContext { #define CUR_FRAME 0 #define REF_FRAME_MVPAIR 1 #define REF_FRAME_SEGMAP 2 - VP9Frame frames[3]; +#define BLANK_FRAME 3 + VP9Frame frames[4]; } VP9SharedContext; #endif /* AVCODEC_VP9SHARED_H */ From patchwork Tue Sep 19 19:57:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43840 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp188244pzb; Tue, 19 Sep 2023 13:02:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGHJVlibnseycJ8Eu+oKkNe7/CYgjbOJIq8KGE5JzW+9msEEJIBqErfzS++cQuQFN5B2h9S X-Received: by 2002:a17:907:7783:b0:9ae:42da:8038 with SMTP id ky3-20020a170907778300b009ae42da8038mr298417ejc.74.1695153740725; Tue, 19 Sep 2023 13:02:20 -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 o15-20020a1709061d4f00b0098859d239dfsi11105010ejh.796.2023.09.19.13.02.19; Tue, 19 Sep 2023 13:02:20 -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=jkL91aTC; 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 4F3D668C9E5; Tue, 19 Sep 2023 22:58:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01olkn2077.outbound.protection.outlook.com [40.92.65.77]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 07A8D68C9DA for ; Tue, 19 Sep 2023 22:58:49 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TPwrZweg8Dc6XNff2dZ6aDchxfmzlGvbuDPF3SYUuO3YIE/GLyz2Zri1KZxU9x7KqQQOK1mnrML/Ir3X5J7HuQ6DB5GbsPPVGOrgfntBHuI0+JCcXmyd6pMQ8jljMLBg3J5yLjh8WqgM4WKOvqSP/trByPGYnv0cIEbvUVa1QW2sfO81uLgM3saU5kjwC2P+53q6a3sOf2Fq0FRNSKhaQJAs7w7o7z78rbLyjm26fRTPUKWv/XO2c1UgQWV2b7pbStK3mp9iAHTxhAaZ1R2vNJ2m1hwm/sDJ9sKjhapWe4jPR4T9xRvAlJ1rpLkQNVjho/pLrmDVsxQBSuKhEIDz7A== 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=e6kPem3EDVO+WmqcTjUIyiAAxdzuAq03ygf+MiAYJSU=; b=kIoE+weceedTHXYq91sd9p4699T0W5V3OfhGVwQVAcu2P80pdYB/6AAaRo1U9H+3hhCXp6qriR0zMiKeljwHb146C+Yaflo4/ivf2el57b0uhwUt7olrcK2qN5Y3HwR3+6RrHNFCJq2l/9drRxKc64+xodU/uGd/sxQwsBnFPjy5X/J7+eMSf6T9xkpjXh0MRLFgc+qeOvP49S/rNxqsoOKfZzGnZEWJpz6aCkKZy8APcYfw/02d1fKe6Y8vG6jYmytziQSd82OgaIh/Fe5NHmo3gfLWwlfksTezd2OqyNeonl5ps81/s2TLVilenIaBVBPbAI0LmnQimpOp9ARD5Q== 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=e6kPem3EDVO+WmqcTjUIyiAAxdzuAq03ygf+MiAYJSU=; b=jkL91aTCd93EFzQylHkrB/dd+i/Cxw/oyeoGklO9ggodGH1baf8G7rEzdBccU6ZVyATXIbt4eSBnDopSQM3HvfX5kj91eqWc0EO26yQVo9jsgqVVRBMzmxR44lmp/l97xHAWE4Omzn/if7Azxh1/T5P4jguBgJWnbRH33TpNEJPKS3yuz/7GbHOnzGfOUBF8PrDvWG2by7Uk+o1l0BHhdPLqOvGKF1e6aSTc5HmWFOUnrI1n52apJ0K0Fkpdfl35GRnhuvLBq+4tUp79XIOBIo3p1D7ZJUNO8XQTgP6DjaakS3BCm161qv2FqaojfFxSK6oZJeLu/a3mJfXZz43FMw== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0237.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:276::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:58:48 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:58:48 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:26 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [JIBmF8ZqctjCcnxhL3T5JxFiSsrvJGLe] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-34-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0237:EE_ X-MS-Office365-Filtering-Correlation-Id: 99d6cc95-5224-4d79-dcef-08dbb94ad665 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LfFoizRCAHaoNKSgyZrqAJbpLluQqk5RjaDo6AGx2WbxfL36RYPVdQ809qzc9KesOTDFixHaSqbQT9R5eSyFtkh6Z4kH4Gjr3aHXl/d9LsI1Yi0Di9KRuX7SN+hHDLtKbDvtovIpdwZpeRLsH/EeRPg7AVH9DLi6XP4741j5MuLGOCQz5DgkURl8LvWc8aEFrSm0zCCPqcnQABDiC257uAaMKbpTNeAEZOwDd0MZd0GoCjbag8Jcv5XhKA+1zNjFdly73tT+BjbVp0Jin/H1fLT7/5h/fq1qmuI9PlIv2/MjZSLf53KKdmGcdF5zxET1Zoj/l7aJMtEEgLCcNn4fQX1abzliwyM5vzGs2AjPqbbyo2Cbtr6yONS3vwC//xgdhTPVnDMO/9m6pkJZ4dFi7nLUmgmeXR/uL/jb27G8ySs1sGt7DJrXn+Psunml3C2h3TpLI/dBFAYbUDA1Ejp37IwT1wdfFGvbh0gcBBk5em26LerYifjLRS5aByMjzUwKLFxwNgAMJ/Y2OwCbWXOR2/CgNCiAXOLQ4SepRoW+iU+nTSvCtCAVZKyGKAMeFILnH6kCDE+axsGGFJbvEy9TkKtmpvTphnj1wtUzzd8Qa/o4ehN3EkzFuwyD2Anr+mNW X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: r6juxohu2wfSOBd9yT7GWIff57j7N/oyidz0Vc04qy5o5mRQ8J013eg+9w9LX+ODOdaWvyceTvuzMOEDyudpvxiEWpZ5HIrZpcgOjC7Ff0x5dWsmU63cp+9I3ElUzIpSuD904stIjUQGZbgSdd8ObgJOHolJGVanbS0CFTahM57nPSZsTXYvsYPv4ZxXVV0h8bLjwShfyvYkGov4T4Vm1EwnLCjdbRWYlWPKbBelwTUiVGtTGYFIM0sLYOgJypMdGbWI93J/O12uQf3N5M4JFXtJhFa2UhV3bwTo2g4JxD2oCm+7IXYkvjWHxhqr/I+6pr3ffbYUr4HSCiNN27prE5ErneushxEoTbNJ8SbFw7fo+5OsAjj6dWZZf2zPpyygxBi9atf8ZGfStE29uCYEtfQcjWMh5In9YMathqaAObQR/9Ih4ZaYCkkfWg8riN07i5zhIgEJGx6zTeiicKaGQlGaKs4vuHySV0UGbPgmbXeTmGWyfxZr1RkIa7ELaoNHkxhOGig3XYwypBb5pjHsotKjGLK6O0UA2CVUEyToshZ6J4Ii64J4QSMCsP2ikHRDttP4Eo5ogLABPuH5PGhNNI+8vBeMWG61SGRilGeVOeSQKxY6gzFUvdduskG/lnuyabk3NQDhb3Ut5ctzAber0qaqGdcab5qvx5UFJDprZ04v1YywsK7itqzO9+mlkaK4Oi7V8oqJMk60DEmZUv61VZJIMxgQ0eLCgHVbDerRMHOoMgS5y0uq9BbyAilDzQuDRDt23mEmaYCl2vCTa22fPU8CXB1xpcC5K/d4qNRO3PJ4p/di3KjyJymB116f/x1xhbTcITu89TbtpashUDs9+8qfPT6j4dUgltaN1oZAoTTmXKMNKJtuEctGPX5+tacb6urmc6ViYH+XzuuSDMcSngNOKCcS4EmV0gfDH0WD5gFSyQI6WxRhfURjfPRPW61dy+wwC6djSB5Hz40Hdv2HtP6aVE5+1jb93R2b53TMA/gYp+7RTDbbUgGQhVs0vxQ+X3MSWiQRK5z/bjbVmgq7r1TRx1rfUFrYaCnJ/qQXOWJENd/PmqxCOu3pAF88wg4lhAmdB+vzwPEZa4AI0+aqxK51aij6n4pLKUid4f36d7s4IrRtHEyQEN+cPbVO7jDa0ifkgShs4wHmi657+R0FzA2ol+7beEWYVl4X4UhwfOzey6z6GQqlAowaFNeTzwd/dtbsCAI8PNmCSsvFPHFo8m3mC7SOGPTU+3Gsxnh6jUAJ5B1aKmi0+oo5rYIgqNlj X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 99d6cc95-5224-4d79-dcef-08dbb94ad665 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:58:48.1344 (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: DU2P250MB0237 Subject: [FFmpeg-devel] [PATCH 34/42] avcodec/vp9: Replace atomic_store() by atomic_init() 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: r4FKX8wLnjc2 This part of the code is not slice-threaded and they are semantically an initialization, so use atomic_init() instead of the potentially expensive atomic_store() (which uses sequentially consistent memory ordering). Also remove the initial initialization directly after allocating this array. Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 8eba56b720..62ae0f5882 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -54,7 +54,6 @@ DEFINE_OFFSET_ARRAY(VP9Context, vp9_context, pthread_init_cnt, static int vp9_alloc_entries(AVCodecContext *avctx, int n) { VP9Context *s = avctx->priv_data; - int i; if (avctx->active_thread_type & FF_THREAD_SLICE) { if (s->entries) @@ -63,9 +62,6 @@ static int vp9_alloc_entries(AVCodecContext *avctx, int n) { s->entries = av_malloc_array(n, sizeof(atomic_int)); if (!s->entries) return AVERROR(ENOMEM); - - for (i = 0; i < n; i++) - atomic_init(&s->entries[i], 0); } return 0; } @@ -1656,7 +1652,7 @@ static int vp9_decode_frame(AVCodecContext *avctx, AVFrame *frame, #if HAVE_THREADS if (avctx->active_thread_type & FF_THREAD_SLICE) { for (i = 0; i < s->sb_rows; i++) - atomic_store(&s->entries[i], 0); + atomic_init(&s->entries[i], 0); } #endif From patchwork Tue Sep 19 19:57:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43841 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp188356pzb; Tue, 19 Sep 2023 13:02:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEf5aeled2XNoE0qFrLlID1eWbQYlwaOR+WC9W3lHtv1ynA9IJc+vkv+mm6LOfLAwAF4jA9 X-Received: by 2002:a2e:8059:0:b0:2c0:a99:68dd with SMTP id p25-20020a2e8059000000b002c00a9968ddmr405499ljg.4.1695153750170; Tue, 19 Sep 2023 13:02:30 -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 gg17-20020a170906e29100b009a9f00bdf87si10776176ejb.775.2023.09.19.13.02.29; Tue, 19 Sep 2023 13:02:30 -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=OASFrdWF; 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 71FFD68C9EF; Tue, 19 Sep 2023 22:58:55 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01olkn2109.outbound.protection.outlook.com [40.92.65.109]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E004568C949 for ; Tue, 19 Sep 2023 22:58:53 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KZLAVDEb+y9+YNDGS1IIOjhtTJwJq2Q7zZ4BP5OfTpoGEeqnHKBayf33KY/RmPeIRvRf1LxUQ4khD3SK4vYgHG8WNdrxZ4pFCMIGaFsTJakojWXcqfQSgK1KwU8upNqbuNWVwlUOethc3dcnIeSayEmEhRd7kl8/zBZT3s7aq+QPBujbcGfNEQK58jlnxEPSZgXq5RjlOOVIrv73Ppp52KIIuvYYCN1RLNwMwKf4c2w0y4PZfGkSAg8iiWbIvGQ6HbC5pHrANF4o8djAfvbdMfcHThWKCuPX0AwJC+DVaFvl+aaS0kHoDGVZqJCcm1i9JbGwWuNr0aXh5IKgEulEtQ== 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=amljfjucEvKWKb+Nr5djzkaNLwaHHz9oKK0P5VgEO4s=; b=fP8j5LFwLIxs7Uiip2D3pk8g17uFSQxI32pUDCxE8qCCPDDKpSv79pay4mYjrwVQKs0kzZ+P0tb7xXy4Opt9926thCiPPuCUQWEvNyTBnao0yPCZ55fSmFOxIyVSgzKbmSVVQO9W9lBr0qjbmw5b2DeVAmENRxbe2cirbS8NFeOrvAVXPDbOWIXL5bXSYDPaIAjXRksZHfLZFm0w56qD3fAE2GMHbAp7j0IyVvZMborM3cpaJUuoKYKEOEHP0cRt0UoNP6cisviCmlbAZxRL+/wOJpakmWbRrwCvazNI8KTdc/BXI8qU1ZKyVCKs8FthOvwyMX20wpvBsM6E5ZFpnQ== 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=amljfjucEvKWKb+Nr5djzkaNLwaHHz9oKK0P5VgEO4s=; b=OASFrdWFV4koZlHDQ5X9H7aFbCzaqDqkCscWxBFss2sYIWJ83zCdt4x+VO0cUWASne6SpsqjUHF8zc8mwQpB3Wq/GubuOoAzW0bzhvG9qyxp563iVx9L9kpVy6N6TqAsNwHobHIS+AvA0pdag7FhqaOZvpSWw0MhN9IDDIbiEro7RvQ41otG54AWe/WQg+1wJpQx0wJ9h9XVat5n/wLICnaIMngPr+T98zWbm9vn/SJMUfVaA+AT/AVLGcqN8VaZtB7k21KUN8APLm/CnjE584rmnqzHIWzWzLGdPtESqv+pXXmb6pkwBfMw2hOjvv75jdk8M62ZEAxzMl4lM/6J2w== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0237.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:276::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:58:52 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:58:52 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:27 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [uAFkaeTailZJmZq3NfqMs3sFlM6qk5d7] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-35-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0237:EE_ X-MS-Office365-Filtering-Correlation-Id: cd9388dc-61d3-43e6-7306-08dbb94ad927 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lBAMhzeu3PfW+3VM0JSqXI92mXj6TDCKUmJ46XbtGXIc25KXtc2ZUjhQJVsgmoLvm5N5mBhR1IOt03AEz1v+qjkWRwytMK0Q1HXZkW+AM42jENIdp47jnowZ6calJsGM+wj7OZdThVHEHHVgg95Iir44PS5OcIU8tNcOEAz/CByJDCKOnstM2A+dFYY6QAOn3fx0xkmvHqgXUijwUo8XKo3AjZCDO0G/X3eg0+ayMVKFKF2hDZosXCOnrwIenA3cQjNwzZL7DtUQLCQv/ZtPTZ6ZDq1azbDgVNenBv88t1UXTzHCPcZhR10IGMnvFegtKo8S6vBL6IXtHGylQ74JjleG4EyQdHk/1T+A2Sy+By7DCD5uWTVa2KcavH/hr+1TozX4VoTTUJv1flxxpNxnibL8jLuZwkDkzQlf0EpHqo0F9vErK3BtEbzEUDMWM3VYlGLpCuxV4nbetvyFV2vpvLcuyW7aka6IzlfX++dRCX0h49sNQEAaQg6HbZcBW7VEgTWiugLyNu67LShT+EhPL2uzbHfXeFQGawnXJcpmmmvbPMs+GRc3Z9XKKnrkRpFM1QeEk+PSJttoLo201CSMzhp96NFiyYRggB+j+Ytw6ds= X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Vc6khqZuUje2EfH9ahOX7yhRFzw4HZV5ulkEqbXBMwx4+/4OBd1TrRI9vLiHGLfYhNyq1Eb4s+aLQUzT47X3di4LCGKnKOJSBn0z5wxKHxQ1mMWITTo1POABm36QGRKEzndmpx5fs16Su18hNLGpF7YpZDSW041uIqtRq86GwykB6IlFeyI6bdcGji7iFKmGIvd7+ZhhVqj5FzgNstUtLmcRRCDkt2g4jz/jtz+R6SsH7eijO7sTArwmhgu3lsyssW2Vb9+VXEZIGsGcFYY/LztLAB0oVd1VdU2u9bQXoKL9/KDTvHNhwfjvy7MXNZuiM2K2q73h3WuwSSstSPcutFrogiJgpaHOHnYZh3NICdB/BC9MGqckKEMAnCYuBCbHBRvl53ptUQq2HKuQmrdksG5fIIZIh+beH4u+1B7I/6dhbfpyR80FC8YPNnNl06n6kYFBDQVedIAj+6k4+JYmo2PM6A+LXu9wgZNigss2qIOlsE6TjOGFjV1PdxXUgL2HzhV7KtEuvLGmfev+rhyrOzZZwi7rBVjIpCc/81goK3upnup4lpYAJZvMlWIxhfDvg1xhrFT2AG5PNtYOugWociS/iFyW8fyAKoftxoJNG9jHTQjOE+4rbG3TGlFlzJrnWntTpPXcS/xlO1UqGstwZfOIl3hYSFAv48uv8hQN+eHRHrf7h6aBD9vbronQTsnBsf0WLlc8bzHog+DUC0xrQLord7E41iI7N3OEmesIG1SMqlKlk5fjbFbN69Hwy9mYTv1AC7TXh6dN/DLtlkH/dqMMElodJlUt59UCLRu/KVrViYw+9BtJ1QkzLYaYGonARXDY1eXJ2FapC3NPuaj487NK8TklTHTOHZ8P/D/FIGAMYMBKTbVGjatj+b4L/f1Ab8tZfJCFkpfL113w+hRrt1wN/MySBBRtS93R6G2dRwVffMy0SHDklp0IHHwnVBCUYpLQTywZi2KsbNAe0HAr9aT9rNSFmynvh4J6vlRD+YqkFmSblsfU6sMoT38B7aFoRJy0tH89T8ufi9pf3LOY/qdLoIbe/XcG+mQ/V0GJ/z65T3B3eykQk0cxFtj7ZOAoOlhPinlDM4KLtMS9IeqsWBl3T2drMUXj5TQKQCKuArRnx+SKRR7Zs8TMuo0jmGaUZnpt7bRsVzbAj4xP9A0ojfbHyMwaW30/p9jpNefC1qOKFmgFrVCYeVwzRwBSYkY1ZAMrQ50lVg74nzXuU1VH46RiYAZKzTv/Lw/QMuIeZD/jSj+Bqk+h/xrjv2x9+PDL X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: cd9388dc-61d3-43e6-7306-08dbb94ad927 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:58:52.7116 (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: DU2P250MB0237 Subject: [FFmpeg-devel] [PATCH 35/42] avcodec/threadprogress: Add new API for frame-threaded progress 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: Vvls7X6e73wp The API is very similar by the ProgressFrame API, with the exception that it no longer has an included AVFrame. Instead one can wait on anything via a ThreadProgress. One just has to ensure that the lifetime of the object containing the ThreadProgress is long enough (the corresponding problem for ProgressFrames is solved by allocating the progress and giving each thread a reference to it). This will typically be solved by putting a ThreadProgress in a refcounted structure that is shared between threads. It will be put to the test in the following commits. An alternative to the check for whether the owner exists (meaning "do we use frame-threading?") would be to initialize the progress to INT_MAX in case frame threading is not in use. This would probably be preferable on arches where atomic reads are cheap (like x86), but are there ones where it is not? One could also (guarded by e.g. an ASSERT_LEVEL check) actually track the progress for non-framethreading, too, in order to track errors even in single-threaded mode. Signed-off-by: Andreas Rheinhardt --- libavcodec/pthread_frame.c | 50 +++++++++++++++++++++++++++++++++++++ libavcodec/threadprogress.h | 37 +++++++++++++++++++++++++++ 2 files changed, 87 insertions(+) create mode 100644 libavcodec/threadprogress.h diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index 9e827f0606..219ab16ccd 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -40,6 +40,7 @@ #include "refstruct.h" #include "thread.h" #include "threadframe.h" +#include "threadprogress.h" #include "version_major.h" #include "libavutil/avassert.h" @@ -1069,3 +1070,52 @@ void ff_thread_progress_await(const ProgressFrame *f, int n) pthread_cond_wait(&p->progress_cond, &p->progress_mutex); pthread_mutex_unlock(&p->progress_mutex); } + +void ff_thread_progress_init(ThreadProgress *pro, AVCodecContext *owner) +{ + PerThreadContext *p = pro->owner = owner->active_thread_type & FF_THREAD_FRAME ? + owner->internal->thread_ctx : NULL; + if (!p) + return; + atomic_init(&pro->progress, -1); + if (atomic_load_explicit(&p->debug_threads, memory_order_relaxed)) + av_log(owner, AV_LOG_DEBUG, "Initializing ThreadProgress %p\n", (void*)pro); +} + +void ff_thread_progress_report2(ThreadProgress *pro, int n) +{ + PerThreadContext *p = pro->owner; + + if (!p || + atomic_load_explicit(&pro->progress, memory_order_relaxed) >= n) + return; + + if (atomic_load_explicit(&p->debug_threads, memory_order_relaxed)) + av_log(p->avctx, AV_LOG_DEBUG, + "%p finished %d\n", (void*)pro, n); + + pthread_mutex_lock(&p->progress_mutex); + + atomic_store_explicit(&pro->progress, n, memory_order_release); + + pthread_cond_broadcast(&p->progress_cond); + pthread_mutex_unlock(&p->progress_mutex); +} + +void ff_thread_progress_await2(const ThreadProgress *pro, int n) +{ + PerThreadContext *p = pro->owner; + + if (!p || + atomic_load_explicit(&pro->progress, memory_order_acquire) >= n) + return; + + if (atomic_load_explicit(&p->debug_threads, memory_order_relaxed)) + av_log(p->avctx, AV_LOG_DEBUG, + "thread awaiting %d from %p\n", n, (void*)pro); + + pthread_mutex_lock(&p->progress_mutex); + while (atomic_load_explicit(&pro->progress, memory_order_relaxed) < n) + pthread_cond_wait(&p->progress_cond, &p->progress_mutex); + pthread_mutex_unlock(&p->progress_mutex); +} diff --git a/libavcodec/threadprogress.h b/libavcodec/threadprogress.h new file mode 100644 index 0000000000..4f65e7da4d --- /dev/null +++ b/libavcodec/threadprogress.h @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2022 Andreas Rheinhardt + * + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVCODEC_THREADPROGRESS_H +#define AVCODEC_THREADPROGRESS_H + +#include + +struct AVCodecContext; + +typedef struct ThreadProgress { + atomic_int progress; + struct PerThreadContext *owner; +} ThreadProgress; + +void ff_thread_progress_init(ThreadProgress *pro, struct AVCodecContext *owner); +void ff_thread_progress_report2(ThreadProgress *pro, int progress); +void ff_thread_progress_await2(const ThreadProgress *pro, int progress); + +#endif /* AVCODEC_THREADPROGRESS_H */ From patchwork Tue Sep 19 19:57:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43842 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp188481pzb; Tue, 19 Sep 2023 13:02:41 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHbMRj8I50Ne2m7eNo4hpY7WwQ1w6aqyPmC4GH85lvAY3fBEu3oOUEhLHCo7iSQ54Xi1L9y X-Received: by 2002:a17:906:4ca:b0:9ae:3a68:93e7 with SMTP id g10-20020a17090604ca00b009ae3a6893e7mr302802eja.74.1695153760961; Tue, 19 Sep 2023 13:02:40 -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 p12-20020a1709060e8c00b009ae09378e30si4749548ejf.859.2023.09.19.13.02.40; Tue, 19 Sep 2023 13:02:40 -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=CmtW4M6u; 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 7930168C9F6; Tue, 19 Sep 2023 22:59:04 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01olkn2065.outbound.protection.outlook.com [40.92.65.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7964768C9ED for ; Tue, 19 Sep 2023 22:59:02 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cNHbSR5PReLQl1hE2TrcQWpGLZrRooT06eWgo+yLX2bDgDnaqTeMzdxeCUMPenpHtmePhs2UFw54JbdSEfa0gCSLe0I7nVHunsoBvbIHBi94JpYbmjdnUQ5CK6VNYJdwJcY4gGIvUSAp1rK2xobThOc7AiaMFIE7fccQyoNZIenUHMUSo/U/TIlzTyTx+8ripFY2moSHwT724UWwo/1q8QkFU4UaZ5dluFuXkQf8eyigxPj+EU+XcHmQRMB+mHfhhBp6JoWb4gAUpR9+YdQQbYcpffq1GS5xYjyjFqdSTlxp8JaQAP22tQTxM/Vae3hGxYWMb1qVNAzREXd9n+NYkw== 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=gTNXLm1yWQSkWPKrjNIPdYJ/HWrCj1ZQN3TFl3q2RWw=; b=lvyb2WrhXVVC17tZh7MzXIoxwIocZfHGFttK6hL1NvWP5yQyMuGoOJmmIHO0KtBuqW5+/qOwskjq0bEvBXSPfVye9elqO9pAzZm74S2hPps/N+/y+D0zG3XR77GXLctGKU1M7BWx51PLJsHkUaxD1QPUpYGaY65qe/bwelKN6uV0FsZTdWAWTGFYxF2cWVrjV6wG7dLHG/A2si75ZzEgdvDrgv0vxJ8eelXtmvm5HJv1NrNT9ZvkMiXNzF89Xs7sb1RSrT9MYRUuS2+jYf3AqZiShhGBQor+hiFbKHVGOpRwNqbIQ3WBmYTYaLwumG8QvZEfmamif/HJZukwObBzxg== 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=gTNXLm1yWQSkWPKrjNIPdYJ/HWrCj1ZQN3TFl3q2RWw=; b=CmtW4M6u4rTl07nZkMLVb6cpTnAGkWZJ/a3Mw/6daFTAHES0TmC0/QEbVWJ/pErBJZrz9etbxCX/CqC6iYb84hkZYQ4W1QnGBNgIKYVSWFqUUmFOlJIURYl2GMbeNToxgEwEDmiSOQgnPjG+c9WXvVw3W8XjXzNss22gQaADLQVLQKKqmkIm8fHlpGkvRs+uQdC9q3mXjdS42gzWpDUoGkYVpbUunNkeAyZC66EXZVJ+smW8PqwrmBUatWYZnYjTlR32RPHBky58j2hy0pwxS9KtpPqIuGxLX5KaalI9CPhdGxX4ZWWGLlvDB/xdlas3WHAqVM0+RyOBeNMGlhX59g== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0237.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:276::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:59:01 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:59:00 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:28 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [Hryj1kHZfsJ7+QkSscCAnFSdCMDAH8FP] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-36-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0237:EE_ X-MS-Office365-Filtering-Correlation-Id: 81ff7c41-54e8-45b9-8a91-08dbb94ade08 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DwZVVfJoUN1A3+xUkl/Xf4jkAvQqBJPBZPk4G0U71dkd0lRl5BbnJnSDys3FEB+lYt50cY/7fIgs0lyVu0ZSU4PjggTr3cmwf0FlaergIVdovo+BCd7dOD9X+gjCzp284DjHg9MXgM2ZNbEMcax0nCUuAEv10doz1vbX5lE52sjdmLImo1XgmiA++2dCHImaIWyExS6RXCD9Pmyu9wwiq+NvVQSRenlWcY1TDH78eHcoBoA3aQoOKJrNBNCarqnsPlqBNznlPQKW3oB+sRwWtMJChwTd5gOcxx/nSbveJdjDz2k53dIcf9iiiUw6p/+IrX7DTnuvhzGxYnctD75AFdO0yYulcIkzSwy/NWCBJE3hSG+x2gGDW6mLzxQnRBGy2lbIIycVfHmq5SumwpEwQ6j7VzOJ8ytRLlHsO1Fp655K92OU1n+YnlNuf3rvcwku/AaKXk8Zn8CAJy83OaTiXPowo4s36bbKfeTxh3gORNH6uJSoXD7XRYvseuLsB09CUOlgODVPJ+VkQZzZRrlI6bR9fh3f6/0P6w+pcXgl9ZN3Ozis0QB9eikOtole7z5dio03rZ9VwoFRqd4ILwEUT45De/u+Y7B2NBUPM6kNTEu+RozC8+gqK4dPeNnByjI6 X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XeVpngHNPLZSD9x1mnFEecrWIxvPY8CBESrEguBihLHd4MOV544CyTm9EGcgqFWGkVxDRgoRoIHvTGnnQawCBp1EIH1dBujdLrVJ1e6sPmmrqgF5+CKYI2cEKLiD6UT602wxNFF2KV3UTo/ZdBoEJAebQJKq7UCPm2SBChfw7piv6byWxPZJd8mQqMUwAqhJjHomdFr94jKWXT/hlceZSvCzPADrkzYssm9eJ4uydMB+N3NbRPgP4/AXwUzLo9rJQTjeO5oRkcFpGz5FT+dxZHw3csl46JnKTrWiS/bpd2F6rIT+Vq1B4Z7qIHfzAKBWQGWX+7Jl/xM5HnoCmvv3xwZB5/0hTKVWgDEwLrnqgpxbsHZ1tmahV+PP5keKxcwPx+8uK6n+icolQWVO8oU6SpV26TAT3gkMfP6jVC+/kFmKEVwK7naxTMHmX1ypSSHoxxyEoKuyIchnNQyilqjHgQZauUqxB6NXf13zghQn7Li/kufKcwaSzV/a2hLpdBO9chu8tu2lE4ZJ+1DN9q0xwoPwwrzMS3WDrCPqHHHiHjTyuYACk2rD6CvQgv5I0yd/4pPYoPfPWdv5pqNoykPgZtOH82O6/+6rSOohTgwA+MXCDqDS1nn5M5iIB6/TT79oX19IFKuR82tldTIdScQfMwDHsAZeMVz+1xkuz6F7bRNoZU2oVl/uOk9Sz1fcoePt+2b+IIo+/N/z6iXX/AAkHZTl+H2gCscgPmalaiYs2O6FkKAStLQSTYPZBnsaI99o5Dr7pnO63obDiKLG8zGphmBqkhNacKWmqxlZL0UO9ZjkYmFrdZ5dNw3c15EDbe3r2E5yU8ebYIDemLBtYiz+RqltrmKvN++eisLkCf/6QJMq0nnPt9DqmImTWixnNhw4fZevXW6cBKe5j8sdZBhFdyd0p3qWy56FP5BuVJeBSlAy3C1krWDqf8CVjT1sWd7tulMB6Vs+fDN9zN3mJqOv41tQFDFb8FARda2qnGg8HNpA0PfV45NFpbGPyAYQusegVTQrUXaAcaxbLO3uQqnKveHSZhRdkVn9N49isUcJpxw26l6GnpV4Rsmm0YanCkkE/q8iwInsGDoDfr5oKMIC35KM7ztK3nSK28A2FFurNi8PWILkrr9+bvIxiuQv3JWeZQebQkxER8RJZX2tEsBLm8gJftj9M0Zme6YHqZGFf1w9JMU2fAZx+4RdPHp7ZOCqbD2w8ozwsZ54bFaHfm9XBAsdNGNaGm3dupVkGsckAgivjPC84YRQX2CLnszHSx0N X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 81ff7c41-54e8-45b9-8a91-08dbb94ade08 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:59:00.9120 (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: DU2P250MB0237 Subject: [FFmpeg-devel] [PATCH 36/42] avcodec/wavpack: Use ThreadProgress API 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: BCJpB5gdz/K/ It is more natural given that WavPack doesn't need the data of the previous frame at all; it just needs the DSD context. Signed-off-by: Andreas Rheinhardt --- libavcodec/wavpack.c | 100 +++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 56 deletions(-) diff --git a/libavcodec/wavpack.c b/libavcodec/wavpack.c index 97705c8854..acb23ab8fe 100644 --- a/libavcodec/wavpack.c +++ b/libavcodec/wavpack.c @@ -30,7 +30,7 @@ #include "get_bits.h" #include "refstruct.h" #include "thread.h" -#include "threadframe.h" +#include "threadprogress.h" #include "unary.h" #include "wavpack.h" #include "dsd.h" @@ -107,11 +107,11 @@ typedef struct WavpackContext { int samples; int ch_offset; - AVFrame *frame; - ThreadFrame curr_frame, prev_frame; Modulation modulation; DSDContext *dsdctx; ///< RefStruct reference + ThreadProgress *curr_progress, *prev_progress; ///< RefStruct references + FFRefStructPool *progress_pool; ///< RefStruct reference int dsd_channels; } WavpackContext; @@ -992,10 +992,18 @@ static int wv_dsd_reset(WavpackContext *s, int channels) s->dsd_channels = 0; ff_refstruct_unref(&s->dsdctx); + ff_refstruct_unref(&s->curr_progress); + ff_refstruct_unref(&s->prev_progress); if (!channels) return 0; + if (!s->progress_pool) { + s->progress_pool = ff_refstruct_pool_alloc(sizeof(*s->curr_progress), 0); + if (!s->progress_pool) + return AVERROR(ENOMEM); + } + if (channels > INT_MAX / sizeof(*s->dsdctx)) return AVERROR(EINVAL); @@ -1015,17 +1023,9 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) { WavpackContext *fsrc = src->priv_data; WavpackContext *fdst = dst->priv_data; - int ret; - - if (dst == src) - return 0; - - ff_thread_release_ext_buffer(dst, &fdst->curr_frame); - if (fsrc->curr_frame.f->data[0]) { - if ((ret = ff_thread_ref_frame(&fdst->curr_frame, &fsrc->curr_frame)) < 0) - return ret; - } + ff_refstruct_replace(&fdst->progress_pool, fsrc->progress_pool); + ff_refstruct_replace(&fdst->curr_progress, fsrc->curr_progress); ff_refstruct_replace(&fdst->dsdctx, fsrc->dsdctx); fdst->dsd_channels = fsrc->dsd_channels; @@ -1041,12 +1041,6 @@ static av_cold int wavpack_decode_init(AVCodecContext *avctx) s->fdec_num = 0; - s->curr_frame.f = av_frame_alloc(); - s->prev_frame.f = av_frame_alloc(); - - if (!s->curr_frame.f || !s->prev_frame.f) - return AVERROR(ENOMEM); - ff_init_dsd_data(); return 0; @@ -1061,18 +1055,15 @@ static av_cold int wavpack_decode_end(AVCodecContext *avctx) av_freep(&s->fdec); s->fdec_num = 0; - ff_thread_release_ext_buffer(avctx, &s->curr_frame); - av_frame_free(&s->curr_frame.f); - - ff_thread_release_ext_buffer(avctx, &s->prev_frame); - av_frame_free(&s->prev_frame.f); - ff_refstruct_unref(&s->dsdctx); + ff_refstruct_unref(&s->curr_progress); + ff_refstruct_unref(&s->prev_progress); + ff_refstruct_pool_uninit(&s->progress_pool); return 0; } -static int wavpack_decode_block(AVCodecContext *avctx, int block_no, +static int wavpack_decode_block(AVCodecContext *avctx, AVFrame *frame, int block_no, const uint8_t *buf, int buf_size) { WavpackContext *wc = avctx->priv_data; @@ -1526,24 +1517,27 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no, av_log(avctx, AV_LOG_ERROR, "Error reinitializing the DSD context\n"); return ret; } - ff_thread_release_ext_buffer(avctx, &wc->curr_frame); } av_channel_layout_copy(&avctx->ch_layout, &new_ch_layout); avctx->sample_rate = new_samplerate; avctx->sample_fmt = sample_fmt; avctx->bits_per_raw_sample = orig_bpp; - ff_thread_release_ext_buffer(avctx, &wc->prev_frame); - FFSWAP(ThreadFrame, wc->curr_frame, wc->prev_frame); - /* get output buffer */ - wc->curr_frame.f->nb_samples = s->samples; - ret = ff_thread_get_ext_buffer(avctx, &wc->curr_frame, - AV_GET_BUFFER_FLAG_REF); + frame->nb_samples = s->samples; + ret = ff_thread_get_buffer(avctx, frame, 0); if (ret < 0) return ret; - wc->frame = wc->curr_frame.f; + ff_refstruct_unref(&wc->prev_progress); + if (wc->dsdctx) { + wc->prev_progress = ff_refstruct_pool_get(wc->progress_pool); + if (!wc->prev_progress) + return AVERROR(ENOMEM); + ff_thread_progress_init(wc->prev_progress, avctx); + } + FFSWAP(ThreadProgress*, wc->prev_progress, wc->curr_progress); + av_assert1(!!wc->dsdctx == !!wc->curr_progress); ff_thread_finish_setup(avctx); } @@ -1552,9 +1546,9 @@ static int wavpack_decode_block(AVCodecContext *avctx, int block_no, return ((avctx->err_recognition & AV_EF_EXPLODE) || !wc->ch_offset) ? AVERROR_INVALIDDATA : 0; } - samples_l = wc->frame->extended_data[wc->ch_offset]; + samples_l = frame->extended_data[wc->ch_offset]; if (s->stereo) - samples_r = wc->frame->extended_data[wc->ch_offset + 1]; + samples_r = frame->extended_data[wc->ch_offset + 1]; wc->ch_offset += 1 + s->stereo; @@ -1606,14 +1600,14 @@ static int dsd_channel(AVCodecContext *avctx, void *frmptr, int jobnr, int threa const WavpackContext *s = avctx->priv_data; AVFrame *frame = frmptr; - ff_dsd2pcm_translate (&s->dsdctx [jobnr], s->samples, 0, + ff_dsd2pcm_translate(&s->dsdctx[jobnr], s->samples, 0, (uint8_t *)frame->extended_data[jobnr], 4, (float *)frame->extended_data[jobnr], 1); return 0; } -static int wavpack_decode_frame(AVCodecContext *avctx, AVFrame *rframe, +static int wavpack_decode_frame(AVCodecContext *avctx, AVFrame *frame, int *got_frame_ptr, AVPacket *avpkt) { WavpackContext *s = avctx->priv_data; @@ -1624,7 +1618,6 @@ static int wavpack_decode_frame(AVCodecContext *avctx, AVFrame *rframe, if (avpkt->size <= WV_HEADER_SIZE) return AVERROR_INVALIDDATA; - s->frame = NULL; s->block = 0; s->ch_offset = 0; @@ -1650,7 +1643,8 @@ static int wavpack_decode_frame(AVCodecContext *avctx, AVFrame *rframe, ret = AVERROR_INVALIDDATA; goto error; } - if ((ret = wavpack_decode_block(avctx, s->block, buf, frame_size)) < 0) + ret = wavpack_decode_block(avctx, frame, s->block, buf, frame_size); + if (ret < 0) goto error; s->block++; buf += frame_size; @@ -1663,26 +1657,22 @@ static int wavpack_decode_frame(AVCodecContext *avctx, AVFrame *rframe, goto error; } - ff_thread_await_progress(&s->prev_frame, INT_MAX, 0); - ff_thread_release_ext_buffer(avctx, &s->prev_frame); - - if (s->modulation == MODULATION_DSD) - avctx->execute2(avctx, dsd_channel, s->frame, NULL, avctx->ch_layout.nb_channels); - - ff_thread_report_progress(&s->curr_frame, INT_MAX, 0); - - if ((ret = av_frame_ref(rframe, s->frame)) < 0) - return ret; + if (s->dsdctx) { + if (s->prev_progress) + ff_thread_progress_await2(s->prev_progress, INT_MAX); + avctx->execute2(avctx, dsd_channel, frame, NULL, avctx->ch_layout.nb_channels); + ff_thread_progress_report2(s->curr_progress, INT_MAX); + } *got_frame_ptr = 1; return avpkt->size; error: - if (s->frame) { - ff_thread_await_progress(&s->prev_frame, INT_MAX, 0); - ff_thread_release_ext_buffer(avctx, &s->prev_frame); - ff_thread_report_progress(&s->curr_frame, INT_MAX, 0); + if (s->curr_progress) { + if (s->prev_progress) + ff_thread_progress_await2(s->prev_progress, INT_MAX); + ff_thread_progress_report2(s->curr_progress, INT_MAX); } return ret; @@ -1701,6 +1691,4 @@ const FFCodec ff_wavpack_decoder = { UPDATE_THREAD_CONTEXT(update_thread_context), .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_CHANNEL_CONF, - .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | - FF_CODEC_CAP_ALLOCATE_PROGRESS, }; From patchwork Tue Sep 19 19:57:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43824 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp188594pzb; Tue, 19 Sep 2023 13:02:53 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFlV9cKyO4697fZnwIHx6Dg/2PLWPw4cXymgsG/oGPcNhsD+Nxl/xKgWMZ5VC/TWgUN2arM X-Received: by 2002:a05:6512:3b89:b0:502:fdca:2eab with SMTP id g9-20020a0565123b8900b00502fdca2eabmr663705lfv.37.1695153772817; Tue, 19 Sep 2023 13:02:52 -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 q2-20020aa7d442000000b005310cf8bf91si4249287edr.422.2023.09.19.13.02.52; Tue, 19 Sep 2023 13:02:52 -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=faZSzGzT; 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 B6AEB68C9F5; Tue, 19 Sep 2023 22:59:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2086.outbound.protection.outlook.com [40.92.91.86]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 492F668C9F2 for ; Tue, 19 Sep 2023 22:59:03 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BJ/LSVh2GiLgIU1Fl+SUJ80jb7/jyuDOZ4cDuZdkAFZaYMoQg0w3UPXTm7sKz4xYrj+hn2Yqb+WEWBAJRsiM7IbW5dpdKoBv2qxn8i+s4ws0Yh8sSE4F8Sy6CtZdGwvO620rKy5LKt+SUHYQj5FPRnDokyppKqj3Af9jC8PZhtMAPEnfqyPtbjykHSaxkskwvxwWMjFsBuys+2P+1SvyZnYEeeAXruucmAGa8L9FJgbuhlbZNq/Dviv5a7xKAJ1hyt1PhJqXBgk5qE0oQkwCGlWSK06uWoD/fVIjif0P0ILMInwzmNkeWPfLHJc/e7uVpohyyohb6gdZ+L8iqb3HaA== 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=7+0t7X1jkqIhxtO84tpk/P0+kKjp5KYi3hnBaI6NfnE=; b=mpZkkmGTZ+k/IHqgbcGZkV5+NbzIDy6r0KiQw9+cfdC9R3jjVrRZ1BMs6yrTIaJCvG4+uFXznLaBQaaTUF7appyTZbrTfyKQ0sSgSVazLcZyWj1meVaPN/opeg2Pfpvbi2rvpm73Zn0aa7DhpqUBvsaaFdCVl/FbFHzGx5Lhu3Y6HnckqC8W/TLSgUdITZ9qH81JEJtBJZUKk1h721Rzb/aoSQMA3YRtyVYQDxJkwn5s4qass4zUWueSNcsXMTomxq0ok6boj2bwUQ3ksL6J0kOFgV/QYYHYZ1DgkDBTKehfp8ovpBspSMHaDhtnuOPwPMAwRedkrEpf+GzaFHOveg== 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=7+0t7X1jkqIhxtO84tpk/P0+kKjp5KYi3hnBaI6NfnE=; b=faZSzGzTtPTIfKnV3It22YA9v+v9HIsK+eOba9hAuwW4+n7l3TvXR8r1lsJ9men3K69FNHYuYhmM8ZHxVe/CcsUtPVmojj9cNZrjBRuO0z7Uttxz/XYmyxO4KMJGHvPhxBC6P84EhpVjUFqhGrf0MHVmXxFc8GPD7qgDm9oymRWZgJNmGNeyGikAPel4H0xzUcGkdoqZ8GjQRumZeRyU3SmqULDFYeiVr2XzlO/58FciaDfZiZT9RcOP9t+eNvHpFZ6yEsidK38qo5s9ytIhHwVURWdEHgLMb9ppnLy4W5Di8/48qPibHgcBW3oLAbVlxl2OfSi0xT65H30npsaobw== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0237.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:276::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:59:02 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:59:02 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:29 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [Yb6YdOJXHmhweDVxQt/1ZqjJYHHBMuLN] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-37-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0237:EE_ X-MS-Office365-Filtering-Correlation-Id: b6a85462-33b2-461c-cf4b-08dbb94adf21 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: uz20hHRLtIIvzD4JtN+DFbIW+z+2P5LwyTEA/FHM3vyxhS2l5MpWmbNrJ6SSAg8cHMKptn4I9LdVECWTiVOXn9GryVjIgu5On3NFPVg5Bcmk9vBlgAiuOiOiOTsKLKju239uQ84SAn1cDAdgK+SSszbCjN2Pr3qLOK5Gotbwy16DmMuQDUTTZXzNqBjD41jlSMLsWK/R+76t7zXRU9ncDogEwwNkM3rCrrqQ/mSYWQCCENWW5y4e72/ULPL0CahM6XWW797xFxoaDbuw09NCzUmcvy43MkIav+KSIHzHDpIQ4inpuII/6oPlj4TaT8MPelpAaUHbTVSReTbZ0J7n184MyCpxWzL9UxnKv/eheXIgzIKzK1VChFqAyw6J2i1V1faZLlAEvDUofYu1ud+xsai/SRa1uSuXU5v11q+FvyPemPG4kj9Qe0D0hgUo7BgTsVJAWA0nA3SNXey26mq5b/SuohKUjaR0UaKwbbaRHCxRqhs+YGKiYaYFGnjueVSjd/as1xyeToRAReClQQPAskdmQ6ixL0BRc4OQGUjHdhY2fEwKBCJJ/OY/1+0eJvM4n0vrVfAj6EQnnGIanxfrnI/o5NsWUS1PA+p3D6Rp38Bs6l3pduprEhkFSw51I1Qk X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tSJKso2L/sGrQfMbJUrQ+txsQJXX4ONszPY/kHS+7AHt9EP3E2+M5LaB4DlpyPb//0CpDjvDyPePBnNQWb64TwWOddSYdAcLjAtQTyJKa8wZbC4iyPEOAAWvWmh6i744FdtMbdaKTNinuIYa1Ih+SyszhCeNK56tBJoYRg4AiGdI+bONd2UKn1vmQwNZniNbnWmfNLcezGs4rKyMhq9q3g8DYkwAyVgm0fFtAy+tmKBh5ni8BDvrchmcoWzcaY+qIvJn879YO6D0ffJAg7a0Lsr3n1Tg2R3idkKnWGZ73bCD6KnA7jme2TKn5ab4R/VaqkSgx2ja2C+xJdV3+m9iIFpT3LlOpBYzrkzpA4K0F9hzL9NSR3/E93RhRQeqxmGBfOQxb4lj8gFObfAqrEhEX6QkJucspqAf4dmbw/jRLLVxw48ODpseYYvmVfrVQgm/iVLMfCRqEkKft6YXJozpopz67IodKQXDn2ZZGirQ1cJ+GEjj6YGdExwRWTd090Uajq6bG3RgGPTvr9Di9pENl+yy18b8P/qaerYt8c+nz7GSpE3uAAC4h/mYhA/sTzTJIzQcaQwALunyXA/6DoMKUEa4lsgk6pqN+MzybhFIdfWLFx9tuqA4Ei9tE3biIPjByZtYTNnCXVRXdx1VI7PfxxEVjfhUAPLXBturfrS+GeKRjUhgIivPpzvw8ENigBM1UXE+/xW0M02LdAgrGRtsZ7HcMxx74WseDnhchJm0aETKxVnuQ2ABOLRVzFf93nWogPW9we1ARs8JeOICGcH1gxBU52UO5QMfp9ze3BL1Wt/2zyEousXabRCZyOUczQPwVuC6xxDSBT+Pe5D/FQsC2QifPpBW5Kxc6NLq1UJm5og/xc868PkgiXwb/e97EoUrSL5LTGaaUl78yuOAN5FKa8wPktqEL9eOwuyCo2vJo8L6ABmtZT3B2DMIcIfQedVMYoErcY3wVvFvxgRzogyDXWqN7FLzC6PzMUhOlzfzfPVoq8Da5UiO+Qb+BvNQVFtKy5kDoh9c6uBEQUdKuvo6e2JL789Ova21Trafuc64auUBSn3qjVgpQr5VgzYGm14/IkLXt1HyP4Vpyl3al6KA2e7adjDty0TagPfCP5hwrogH42hkxSPlIQbJrULBh25eL/YuAP+bD83ld2WlGUEKA0KJWfhkUJPx5Gni8NU9pTeDuByuT8hUlWrIySaN7bSPYtm1IfziNj5PyQuJJzWe29cW5EHQTtrr1vCNjNMHPWGdblaayyfSiPX+wEJaug2O X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b6a85462-33b2-461c-cf4b-08dbb94adf21 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:59:02.7569 (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: DU2P250MB0237 Subject: [FFmpeg-devel] [PATCH 37/42] avcodec/vp8: Convert to ProgressFrame API 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: /ACZF5TMuuI3 Signed-off-by: Andreas Rheinhardt --- libavcodec/vp8.c | 90 +++++++++++++++-------------------------------- libavcodec/vp8.h | 5 +-- libavcodec/webp.c | 3 +- 3 files changed, 33 insertions(+), 65 deletions(-) diff --git a/libavcodec/vp8.c b/libavcodec/vp8.c index 4a51c551b8..30d22016f5 100644 --- a/libavcodec/vp8.c +++ b/libavcodec/vp8.c @@ -34,9 +34,9 @@ #include "hwaccel_internal.h" #include "hwconfig.h" #include "mathops.h" +#include "progressframe.h" #include "refstruct.h" #include "thread.h" -#include "threadframe.h" #include "vp8.h" #include "vp89_rac.h" #include "vp8data.h" @@ -102,9 +102,9 @@ static void free_buffers(VP8Context *s) static int vp8_alloc_frame(VP8Context *s, VP8Frame *f, int ref) { - int ret; - if ((ret = ff_thread_get_ext_buffer(s->avctx, &f->tf, - ref ? AV_GET_BUFFER_FLAG_REF : 0)) < 0) + int ret = ff_thread_progress_get_buffer(s->avctx, &f->tf, + ref ? AV_GET_BUFFER_FLAG_REF : 0); + if (ret < 0) return ret; if (!(f->seg_map = ff_refstruct_allocz(s->mb_width * s->mb_height))) goto fail; @@ -116,7 +116,7 @@ static int vp8_alloc_frame(VP8Context *s, VP8Frame *f, int ref) fail: ff_refstruct_unref(&f->seg_map); - ff_thread_release_ext_buffer(s->avctx, &f->tf); + ff_thread_progress_unref(s->avctx, &f->tf); return ret; } @@ -124,23 +124,16 @@ static void vp8_release_frame(VP8Context *s, VP8Frame *f) { ff_refstruct_unref(&f->seg_map); ff_refstruct_unref(&f->hwaccel_picture_private); - ff_thread_release_ext_buffer(s->avctx, &f->tf); + ff_thread_progress_unref(s->avctx, &f->tf); } #if CONFIG_VP8_DECODER -static int vp8_ref_frame(VP8Context *s, VP8Frame *dst, const VP8Frame *src) +static void vp8_replace_frame(VP8Context *s, VP8Frame *dst, const VP8Frame *src) { - int ret; - - vp8_release_frame(s, dst); - - if ((ret = ff_thread_ref_frame(&dst->tf, &src->tf)) < 0) - return ret; + ff_thread_progress_replace(s->avctx, &dst->tf, &src->tf); ff_refstruct_replace(&dst->seg_map, src->seg_map); ff_refstruct_replace(&dst->hwaccel_picture_private, src->hwaccel_picture_private); - - return 0; } #endif /* CONFIG_VP8_DECODER */ @@ -183,7 +176,7 @@ static VP8Frame *vp8_find_free_buffer(VP8Context *s) av_log(s->avctx, AV_LOG_FATAL, "Ran out of free frames!\n"); abort(); } - if (frame->tf.f->buf[0]) + if (frame->tf.f) vp8_release_frame(s, frame); return frame; @@ -1829,7 +1822,7 @@ static const uint8_t subpel_idx[3][8] = { */ static av_always_inline void vp8_mc_luma(VP8Context *s, VP8ThreadData *td, uint8_t *dst, - const ThreadFrame *ref, const VP8mv *mv, + const ProgressFrame *ref, const VP8mv *mv, int x_off, int y_off, int block_w, int block_h, int width, int height, ptrdiff_t linesize, vp8_mc_func mc_func[3][3]) @@ -1846,7 +1839,7 @@ void vp8_mc_luma(VP8Context *s, VP8ThreadData *td, uint8_t *dst, y_off += mv->y >> 2; // edge emulation - ff_thread_await_progress(ref, (3 + y_off + block_h + subpel_idx[2][my]) >> 4, 0); + ff_thread_progress_await(ref, (3 + y_off + block_h + subpel_idx[2][my]) >> 4); src += y_off * linesize + x_off; if (x_off < mx_idx || x_off >= width - block_w - subpel_idx[2][mx] || y_off < my_idx || y_off >= height - block_h - subpel_idx[2][my]) { @@ -1862,7 +1855,7 @@ void vp8_mc_luma(VP8Context *s, VP8ThreadData *td, uint8_t *dst, } mc_func[my_idx][mx_idx](dst, linesize, src, src_linesize, block_h, mx, my); } else { - ff_thread_await_progress(ref, (3 + y_off + block_h) >> 4, 0); + ff_thread_progress_await(ref, (3 + y_off + block_h) >> 4); mc_func[0][0](dst, linesize, src + y_off * linesize + x_off, linesize, block_h, 0, 0); } @@ -1887,7 +1880,7 @@ void vp8_mc_luma(VP8Context *s, VP8ThreadData *td, uint8_t *dst, */ static av_always_inline void vp8_mc_chroma(VP8Context *s, VP8ThreadData *td, uint8_t *dst1, - uint8_t *dst2, const ThreadFrame *ref, const VP8mv *mv, + uint8_t *dst2, const ProgressFrame *ref, const VP8mv *mv, int x_off, int y_off, int block_w, int block_h, int width, int height, ptrdiff_t linesize, vp8_mc_func mc_func[3][3]) @@ -1904,7 +1897,7 @@ void vp8_mc_chroma(VP8Context *s, VP8ThreadData *td, uint8_t *dst1, // edge emulation src1 += y_off * linesize + x_off; src2 += y_off * linesize + x_off; - ff_thread_await_progress(ref, (3 + y_off + block_h + subpel_idx[2][my]) >> 3, 0); + ff_thread_progress_await(ref, (3 + y_off + block_h + subpel_idx[2][my]) >> 3); if (x_off < mx_idx || x_off >= width - block_w - subpel_idx[2][mx] || y_off < my_idx || y_off >= height - block_h - subpel_idx[2][my]) { s->vdsp.emulated_edge_mc(td->edge_emu_buffer, @@ -1929,7 +1922,7 @@ void vp8_mc_chroma(VP8Context *s, VP8ThreadData *td, uint8_t *dst1, mc_func[my_idx][mx_idx](dst2, linesize, src2, linesize, block_h, mx, my); } } else { - ff_thread_await_progress(ref, (3 + y_off + block_h) >> 3, 0); + ff_thread_progress_await(ref, (3 + y_off + block_h) >> 3); mc_func[0][0](dst1, linesize, src1 + y_off * linesize + x_off, linesize, block_h, 0, 0); mc_func[0][0](dst2, linesize, src2 + y_off * linesize + x_off, linesize, block_h, 0, 0); } @@ -1937,7 +1930,7 @@ void vp8_mc_chroma(VP8Context *s, VP8ThreadData *td, uint8_t *dst1, static av_always_inline void vp8_mc_part(VP8Context *s, VP8ThreadData *td, uint8_t *const dst[3], - const ThreadFrame *ref_frame, int x_off, int y_off, + const ProgressFrame *ref_frame, int x_off, int y_off, int bx_off, int by_off, int block_w, int block_h, int width, int height, const VP8mv *mv) { @@ -2002,7 +1995,7 @@ void inter_predict(VP8Context *s, VP8ThreadData *td, uint8_t *const dst[3], { int x_off = mb_x << 4, y_off = mb_y << 4; int width = 16 * s->mb_width, height = 16 * s->mb_height; - const ThreadFrame *ref = &s->framep[mb->ref_frame]->tf; + const ProgressFrame *ref = &s->framep[mb->ref_frame]->tf; const VP8mv *bmv = mb->bmv; switch (mb->partitioning) { @@ -2422,7 +2415,7 @@ static av_always_inline int decode_mb_row_no_filter(AVCodecContext *avctx, void // if we re-use the same map. if (prev_frame && s->segmentation.enabled && !s->segmentation.update_map) - ff_thread_await_progress(&prev_frame->tf, mb_y, 0); + ff_thread_progress_await(&prev_frame->tf, mb_y); mb = s->macroblocks + (s->mb_height - mb_y - 1) * 2; memset(mb - 1, 0, sizeof(*mb)); // zero left macroblock AV_WN32A(s->intra4x4_pred_mode_left, DC_PRED * 0x01010101); @@ -2630,7 +2623,7 @@ int vp78_decode_mb_row_sliced(AVCodecContext *avctx, void *tdata, int jobnr, td->mv_bounds.mv_max.y -= 64 * num_jobs; if (avctx->active_thread_type == FF_THREAD_FRAME) - ff_thread_report_progress(&curframe->tf, mb_y, 0); + ff_thread_progress_report(&curframe->tf, mb_y); } return 0; @@ -2694,7 +2687,7 @@ int vp78_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, // release no longer referenced frames for (i = 0; i < 5; i++) - if (s->frames[i].tf.f->buf[0] && + if (s->frames[i].tf.f && &s->frames[i] != prev_frame && &s->frames[i] != s->framep[VP8_FRAME_PREVIOUS] && &s->frames[i] != s->framep[VP8_FRAME_GOLDEN] && @@ -2723,14 +2716,14 @@ int vp78_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, goto err; } + if ((ret = vp8_alloc_frame(s, curframe, referenced)) < 0) + goto err; if (s->keyframe) curframe->tf.f->flags |= AV_FRAME_FLAG_KEY; else curframe->tf.f->flags &= ~AV_FRAME_FLAG_KEY; curframe->tf.f->pict_type = s->keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P; - if ((ret = vp8_alloc_frame(s, curframe, referenced)) < 0) - goto err; // check if golden and altref are swapped if (s->update_altref != VP8_FRAME_NONE) @@ -2787,7 +2780,7 @@ int vp78_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, // if we re-use the same map. if (prev_frame && s->segmentation.enabled && !s->segmentation.update_map) - ff_thread_await_progress(&prev_frame->tf, 1, 0); + ff_thread_progress_await(&prev_frame->tf, 1); if (is_vp7) ret = vp7_decode_mv_mb_modes(avctx, curframe, prev_frame); else @@ -2818,7 +2811,7 @@ int vp78_decode_frame(AVCodecContext *avctx, AVFrame *rframe, int *got_frame, num_jobs); } - ff_thread_report_progress(&curframe->tf, INT_MAX, 0); + ff_thread_progress_report(&curframe->tf, INT_MAX); memcpy(&s->framep[0], &s->next_framep[0], sizeof(s->framep[0]) * 4); skip_decode: @@ -2855,32 +2848,15 @@ static int vp7_decode_frame(AVCodecContext *avctx, AVFrame *frame, av_cold int ff_vp8_decode_free(AVCodecContext *avctx) { - VP8Context *s = avctx->priv_data; - int i; - vp8_decode_flush_impl(avctx, 1); - for (i = 0; i < FF_ARRAY_ELEMS(s->frames); i++) - av_frame_free(&s->frames[i].tf.f); return 0; } -static av_cold int vp8_init_frames(VP8Context *s) -{ - int i; - for (i = 0; i < FF_ARRAY_ELEMS(s->frames); i++) { - s->frames[i].tf.f = av_frame_alloc(); - if (!s->frames[i].tf.f) - return AVERROR(ENOMEM); - } - return 0; -} - static av_always_inline int vp78_decode_init(AVCodecContext *avctx, int is_vp7) { VP8Context *s = avctx->priv_data; - int ret; s->avctx = avctx; s->vp7 = avctx->codec->id == AV_CODEC_ID_VP7; @@ -2905,11 +2881,6 @@ int vp78_decode_init(AVCodecContext *avctx, int is_vp7) /* does not change for VP8 */ memcpy(s->prob[0].scan, ff_zigzag_scan, sizeof(s->prob[0].scan)); - if ((ret = vp8_init_frames(s)) < 0) { - ff_vp8_decode_free(avctx); - return ret; - } - return 0; } @@ -2933,7 +2904,6 @@ static int vp8_decode_update_thread_context(AVCodecContext *dst, const AVCodecContext *src) { VP8Context *s = dst->priv_data, *s_src = src->priv_data; - int i; if (s->macroblocks_base && (s_src->mb_width != s->mb_width || s_src->mb_height != s->mb_height)) { @@ -2948,13 +2918,8 @@ static int vp8_decode_update_thread_context(AVCodecContext *dst, s->lf_delta = s_src->lf_delta; memcpy(s->sign_bias, s_src->sign_bias, sizeof(s->sign_bias)); - for (i = 0; i < FF_ARRAY_ELEMS(s_src->frames); i++) { - if (s_src->frames[i].tf.f->buf[0]) { - int ret = vp8_ref_frame(s, &s->frames[i], &s_src->frames[i]); - if (ret < 0) - return ret; - } - } + for (int i = 0; i < FF_ARRAY_ELEMS(s_src->frames); i++) + vp8_replace_frame(s, &s->frames[i], &s_src->frames[i]); s->framep[0] = REBASE(s_src->next_framep[0]); s->framep[1] = REBASE(s_src->next_framep[1]); @@ -2978,6 +2943,7 @@ const FFCodec ff_vp7_decoder = { FF_CODEC_DECODE_CB(vp7_decode_frame), .p.capabilities = AV_CODEC_CAP_DR1, .flush = vp8_decode_flush, + .caps_internal = FF_CODEC_CAP_USES_PROGRESSFRAMES, }; #endif /* CONFIG_VP7_DECODER */ @@ -2993,7 +2959,7 @@ const FFCodec ff_vp8_decoder = { FF_CODEC_DECODE_CB(ff_vp8_decode_frame), .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS, - .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS, + .caps_internal = FF_CODEC_CAP_USES_PROGRESSFRAMES, .flush = vp8_decode_flush, UPDATE_THREAD_CONTEXT(vp8_decode_update_thread_context), .hw_configs = (const AVCodecHWConfigInternal *const []) { diff --git a/libavcodec/vp8.h b/libavcodec/vp8.h index eb9fa2f166..e38b92f0fe 100644 --- a/libavcodec/vp8.h +++ b/libavcodec/vp8.h @@ -31,8 +31,9 @@ #include "libavutil/mem_internal.h" #include "libavutil/thread.h" +#include "avcodec.h" #include "h264pred.h" -#include "threadframe.h" +#include "progressframe.h" #include "videodsp.h" #include "vp8dsp.h" #include "vpx_rac.h" @@ -150,7 +151,7 @@ typedef struct VP8ThreadData { } VP8ThreadData; typedef struct VP8Frame { - ThreadFrame tf; + ProgressFrame tf; uint8_t *seg_map; ///< RefStruct reference void *hwaccel_picture_private; ///< RefStruct reference diff --git a/libavcodec/webp.c b/libavcodec/webp.c index 54b3fde6dc..85cb884153 100644 --- a/libavcodec/webp.c +++ b/libavcodec/webp.c @@ -1565,5 +1565,6 @@ const FFCodec ff_webp_decoder = { FF_CODEC_DECODE_CB(webp_decode_frame), .close = webp_decode_close, .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS, - .caps_internal = FF_CODEC_CAP_ICC_PROFILES, + .caps_internal = FF_CODEC_CAP_ICC_PROFILES | + FF_CODEC_CAP_USES_PROGRESSFRAMES, }; From patchwork Tue Sep 19 19:57:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43843 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp188701pzb; Tue, 19 Sep 2023 13:03:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHpTJM9Onx+nvW9J6PApdkunIitDEy0ND1iKhdTNm0rYKI4BZ28/tVbcde4yyqNqmSUOUfD X-Received: by 2002:a17:906:158:b0:9ae:3d7b:6f46 with SMTP id 24-20020a170906015800b009ae3d7b6f46mr319951ejh.46.1695153784320; Tue, 19 Sep 2023 13:03:04 -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 l14-20020a1709066b8e00b0099d97c61f8fsi10110403ejr.263.2023.09.19.13.03.03; Tue, 19 Sep 2023 13:03:04 -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=bxGTKP5B; 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 08D9A68C9F3; Tue, 19 Sep 2023 22:59:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01olkn2090.outbound.protection.outlook.com [40.92.65.90]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 31F8D68C9FA for ; Tue, 19 Sep 2023 22:59:14 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=aza4Rrl6Ayg4YjRbofn8B0my0fK5rak2QPWtvZ32BaVr4o5N0fLhFiT272PpJJ32jncMUd1lbJMdH9Sm1476xwEy5j6BAj22HA4x8K9l0hT/Uc2oqmvANdF5Uc9EYybF2oTCN3dK5FVQBzu786N5gXs0FdYwTydTSO0ij3tdyt5hjIptv2SHNp4ZVe6Mm2AKB+ox45u1ddK700YcTFkwj0OFLKGnykb9PxrBKHUXCHHSChXajBz7Rr9Aqo1AeOtwEil8nDKvBDxS+/cXiTRIMm1Axf9uSJaP5PXDVZ+ygSMG/KcpNXHRqMZnvLs3F9/3suX5ZaMCgycnwS7YiA1tGg== 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=/FWfZsPVtfWhkUtuU4IbkbSYsnnsXSA8kCsXx1YlagQ=; b=bwtFr4a9PSDDZs7m8sGblfVPQAjRCc0sJg5z/UzGPX0U3Bl1kXv29vebbFgRctLiAr8fIjRJDORsrZ6bLSUZBXlY7c2kADnpsH+TzPQWTvfj6TW+6U5N+1MF20KNImxPHZC0Jv0823Tx9ePAoxxieG4t79hQbPUp8VXUgsuNdtgbGUNvhhXtBcAIjP2FQ9DkrAiktV5sgXczdF6RJRbsyUqMRPYTTqGS2Hinzf/kIk18lHjY1dR499X8EvXHCszhNSyImB/zID9ocKxrkCCTBSVYdU4UbvoFun0gbuLM6dneDkvBUlonmlaDeJ58xiGqy9vI284McEeuslAFlclQoA== 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=/FWfZsPVtfWhkUtuU4IbkbSYsnnsXSA8kCsXx1YlagQ=; b=bxGTKP5B4rgQzfTUgXLiPOG/L2xtDfb4HJAriasPpFlnOF5C0JXlS1OwyE5Lv2ar13B01h8jcw5bktmuqvX/mnzeFR77HZX9L5nB/RNXjBPiDyAtJuYWZ9x+7N2kUjnwtOCyOUUoXnBqM49cLjnv0BZWldzCAjLZIhAwqIJC0cX2/4qWUjXkudQ3fuiD9lFMIS2rBJ1qs0IxdBVe+Jjh7WAppFkavk2B4H6p4gjXzS7yNR+1yns1h1kiuKZkXw1g8DMdJs+/l2kAmsLnGUHMSqlA2w0VdK1639K4WR8RxdjPsMBh63ddnY52BtAm7xXuli1GB9DbsVdcMFwkBk5n6A== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0237.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:276::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:59:13 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:59:13 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:30 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [q7Uds179D5q2qWHOa7m7XiAQFYV1P8nw] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-38-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0237:EE_ X-MS-Office365-Filtering-Correlation-Id: 954e72f7-fe01-42f8-fada-08dbb94ae590 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: C1FVXPbtnA+7QTAXXIUwQrmEOMn8biTx5CvlsatoYfsmUUgqtKoKbukzLsoeZ6enD2eU7eaGVFdXzPSTTEdoRfjJNkXqsfuB9X5zX9T3qA5B0iEbw8PraIAFqXDHuZRFnnJY79j8wj6QYTGanfp8K/5seW42U28wFqD6WVpNA200ZByj862HTl6/4ZmQroncYeYQa1/5kXt+x6s9VMsWFHf/83pYfxfegEyf4IRenEI+rgGAWoJnx8xwwmkBGsnCf66gSfpaoOcOoJKgoLyHLxERh+TyUBBNGgLdn5EQcdgJTVWkgJ1fPx4Z0cuAsIQfejvrUu+xTCYXaSz6CBeE5/jF9lHd/beFyKIQoDMh1Q0+7wFanFev3MLBQCEShgjJOlGytfRLN1eTWvpfcVRZC9S5Ulr3ukffocP8uwEtqb2K34BMTjpG+/Lh6s/0f1+fjbfq70LlJ/nXpfHrG4xTzn22Emh1YLs0d5OEBI0u434ex8CFhUs5LNyOEUw4werNmBa1mEy12iAcBOeBox9HkSCTnH9eNCent49qtO9gKbUMxbQezXroEpPv6knhaMmc9ZTK8dMLsCRq3470e9bUf04vv8qvqe4pESQjkQEiLMSMoqmLORERsafpNAxf9ZCc X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XarfSgoIiFUnvJ11MKLWWjnZQodtkAzOy1TV1hqQ0b7mi/tIDBAIqsMP6NuEz9EXqPivov4R6KpPZXKAopvLkEOjIyzf6nckYAVGfsd+Z/0CwpDXg99vg5ygfCKNk5+sslMWkwIbmpEF7W4Upn5qZWwFTdm1cO23VJEKfT1ys++gBR9jff6e3aZFKzUWmEAzm5wQs+35drIciEJI7qESN8c7UqaYMagnO8qAAbnpWNFI9iloPUhZk+SYMF84b2gEZAu8TLEsvanQGRyr/K/EHKsWOQk9Cjz+5Wt+4UDy3v17h+JINdqy3bRRy5jZpLyBKLXc8HdP3FEoKTAbpEcEhhYAqno+Sp2oxg25qhSVEkMsW+RYgS8NeYAzfTUXL2pG0ruUVUqFVXE6D1fteNDEWBkO3BH53Inf4BmnUEf44G8Ehodhkti/Rz0kCsfI66VNcXyuZ6+1q4j3hv3pX1gwpzLKubCUFkkXkkgON6ukCBsIDLIE4JhjM5Y+V+bbBF+pUfJG6G95HrsGxgpT9/mTuRbLcQp9yNmpbaRzH+obi7XEZzyHGnPKo97YRKhU/TR8BAi2wsg0REwpq4LYtXOZN8Y8+ZHMjV8cW23daDH/V9PHaMJVAWF8MiUGX8KRT+QWupJvoqmmg58WHFZCzT+Y40QN0Jshv/Ng8y7Hxkop6r77ypDqUD8Pqr+hwlwcMOwF4UyISgrUa3hueBny4cwx/tNCfN7WOiqaFNwu+OntQuVGCXKRlQ0upQDrBuRa2ZyseXkzZgcp7g+4zMTX9Tuh5ehUkOUFrtv5RcffG+6vSsey5A5xSUuJQ6WOXoU+kVGXjs31lbTT97ydATS5BnEcwycg1c6dVea4pzAk9yQP32ls1i5tcHatpaxd3pDwcEN55aSTvR/0UjTRq6wvPhAf0G7BtR1T+4mAWwPPYzG6Bof2VFeZN+zHR9irZ0OojpB88/TF1jdhT2amk1qdq/GYsAZYkHVAbiLDfaII/3mkCu70vGAlZEycvOCSzYqP65RkxuED1BPwB7lbMRPMPjjn62KOFdOd7xo2Rfl1P1UXj0h561rIotNTPCixMh0b8UeWl898Y6Vf+h8UwMzHb7Kr8DkSAkDXUuctzC7Mww9KKa060S2XKf0t5ACncaXtgsPel+1BZEBbZm7Ao0lntAwDdbHu2Va00sKK5TJ606QOIzYeYFc1QE/m4HcB+jsi66rO+iVlAGaNooPATQyx232+1SbOT3jbqINRE9WOBbTT05RulejqcaAgQ7nuqmCx5tgZ X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 954e72f7-fe01-42f8-fada-08dbb94ae590 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:59:13.5557 (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: DU2P250MB0237 Subject: [FFmpeg-devel] [PATCH 38/42] avcodec/codec_internal: Remove FF_CODEC_CAP_ALLOCATE_PROGRESS 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: wc8viFb1CNTK Before commit f025b8e110b36c1cdb4fb56c4cd57aeca1767b5b, every frame-threaded decoder used ThreadFrames, even when they did not have any inter-frame dependencies at all. In order to distinguish those decoders that need the AVBuffer for progress communication from those that do not (to avoid the allocation for the latter), the former decoders were marked with the FF_CODEC_CAP_ALLOCATE_PROGRESS internal codec cap. Yet distinguishing these two can be done in a more natural way: Don't use ThreadFrames when not needed and split ff_thread_get_buffer() into a core function that calls the user's get_buffer2 callback and a wrapper around it that also allocates the progress AVBuffer. This has been done in 02220b88fc38ef9dd4f2d519f5d3e4151258b60c and since that commit the ALLOCATE_PROGRESS cap was nearly redundant. The only exception was WebP and VP8. WebP can contain VP8 and uses the VP8 decoder directly (i.e. they share the same AVCodecContext). Both decoders are frame-threaded and VP8 has inter-frame dependencies (in general, not in valid WebP) and therefore the ALLOCATE_PROGRESS cap. In order to avoid allocating progress in case of a frame-threaded WebP decoder the cap and the check for the cap has been kept in place. Yet now the VP8 decoder has been switched to use ProgressFrames and therefore there is just no reason any more for this check and the cap. This commit therefore removes both. Also change the value of FF_CODEC_CAP_USES_PROGRESSFRAMES to leave no gaps. Signed-off-by: Andreas Rheinhardt --- doc/multithreading.txt | 8 ++++---- libavcodec/codec_internal.h | 7 +------ libavcodec/ffv1dec.c | 3 +-- libavcodec/h264dec.c | 2 +- libavcodec/hevcdec.c | 2 +- libavcodec/mpeg4videodec.c | 3 +-- libavcodec/pngdec.c | 3 +-- libavcodec/pthread_frame.c | 12 +++++------- libavcodec/rv30.c | 1 - libavcodec/rv40.c | 1 - libavcodec/tests/avcodec.c | 7 +------ 11 files changed, 16 insertions(+), 33 deletions(-) diff --git a/doc/multithreading.txt b/doc/multithreading.txt index 470194ff85..0fb467392d 100644 --- a/doc/multithreading.txt +++ b/doc/multithreading.txt @@ -53,10 +53,10 @@ thread. Add AV_CODEC_CAP_FRAME_THREADS to the codec capabilities. There will be very little speed gain at this point but it should work. -If there are inter-frame dependencies, so the codec calls -ff_thread_report/await_progress(), set FF_CODEC_CAP_ALLOCATE_PROGRESS in -AVCodec.caps_internal and use ff_thread_get_buffer() to allocate frames. The -frames must then be freed with ff_thread_release_buffer(). +Use ff_thread_get_buffer() (or ff_thread_get_ext_buffer() or +ff_thread_progress_get_buffer() in case you have inter-frame dependencies) +to allocate frames. The frames must then be freed with ff_thread_release_buffer() +(or ff_thread_release_ext_buffer() or ff_thread_progress_unref()). Otherwise decode directly into the user-supplied frames. Call ff_thread_report_progress() after some part of the current picture has decoded. diff --git a/libavcodec/codec_internal.h b/libavcodec/codec_internal.h index c03b64ceba..4ddf394c0b 100644 --- a/libavcodec/codec_internal.h +++ b/libavcodec/codec_internal.h @@ -65,12 +65,7 @@ /** * The decoder might make use of the ProgressFrame API. */ -#define FF_CODEC_CAP_USES_PROGRESSFRAMES (1 << 11) -/* - * The codec supports frame threading and has inter-frame dependencies, so it - * uses ff_thread_report/await_progress(). - */ -#define FF_CODEC_CAP_ALLOCATE_PROGRESS (1 << 6) +#define FF_CODEC_CAP_USES_PROGRESSFRAMES (1 << 6) /** * Codec handles avctx->thread_count == 0 (auto) internally. */ diff --git a/libavcodec/ffv1dec.c b/libavcodec/ffv1dec.c index 54cf075b8f..20cc345780 100644 --- a/libavcodec/ffv1dec.c +++ b/libavcodec/ffv1dec.c @@ -1125,6 +1125,5 @@ const FFCodec ff_ffv1_decoder = { UPDATE_THREAD_CONTEXT(update_thread_context), .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS | AV_CODEC_CAP_SLICE_THREADS, - .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | - FF_CODEC_CAP_ALLOCATE_PROGRESS, + .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, }; diff --git a/libavcodec/h264dec.c b/libavcodec/h264dec.c index 8578d3b346..39666faace 100644 --- a/libavcodec/h264dec.c +++ b/libavcodec/h264dec.c @@ -1140,7 +1140,7 @@ const FFCodec ff_h264_decoder = { NULL }, .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING | - FF_CODEC_CAP_ALLOCATE_PROGRESS | FF_CODEC_CAP_INIT_CLEANUP, + FF_CODEC_CAP_INIT_CLEANUP, .flush = h264_decode_flush, UPDATE_THREAD_CONTEXT(ff_h264_update_thread_context), UPDATE_THREAD_CONTEXT_FOR_USER(ff_h264_update_thread_context_for_user), diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index 23cc543f82..c8067a736e 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -3671,7 +3671,7 @@ const FFCodec ff_hevc_decoder = { .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS, .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING | - FF_CODEC_CAP_ALLOCATE_PROGRESS | FF_CODEC_CAP_INIT_CLEANUP, + FF_CODEC_CAP_INIT_CLEANUP, .p.profiles = NULL_IF_CONFIG_SMALL(ff_hevc_profiles), .hw_configs = (const AVCodecHWConfigInternal *const []) { #if CONFIG_HEVC_DXVA2_HWACCEL diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c index a8dd57bf6b..e0b0e1e08c 100644 --- a/libavcodec/mpeg4videodec.c +++ b/libavcodec/mpeg4videodec.c @@ -3860,8 +3860,7 @@ const FFCodec ff_mpeg4_decoder = { FF_CODEC_DECODE_CB(ff_h263_decode_frame), .p.capabilities = AV_CODEC_CAP_DRAW_HORIZ_BAND | AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_FRAME_THREADS, - .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | - FF_CODEC_CAP_ALLOCATE_PROGRESS, + .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM, .flush = ff_mpeg_flush, .p.max_lowres = 3, .p.pix_fmts = ff_h263_hwaccel_pixfmt_list_420, diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index 0369d1c449..c011ca386e 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -1862,7 +1862,6 @@ const FFCodec ff_apng_decoder = { UPDATE_THREAD_CONTEXT(update_thread_context), .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS, .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | - FF_CODEC_CAP_ALLOCATE_PROGRESS | FF_CODEC_CAP_ICC_PROFILES, }; #endif @@ -1880,7 +1879,7 @@ const FFCodec ff_png_decoder = { UPDATE_THREAD_CONTEXT(update_thread_context), .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS, .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | - FF_CODEC_CAP_ALLOCATE_PROGRESS | FF_CODEC_CAP_INIT_CLEANUP | + FF_CODEC_CAP_INIT_CLEANUP | FF_CODEC_CAP_ICC_PROFILES, }; #endif diff --git a/libavcodec/pthread_frame.c b/libavcodec/pthread_frame.c index 219ab16ccd..28b727dec9 100644 --- a/libavcodec/pthread_frame.c +++ b/libavcodec/pthread_frame.c @@ -998,14 +998,12 @@ int ff_thread_get_ext_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags) if (!(avctx->active_thread_type & FF_THREAD_FRAME)) return ff_get_buffer(avctx, f->f, flags); - if (ffcodec(avctx->codec)->caps_internal & FF_CODEC_CAP_ALLOCATE_PROGRESS) { - f->progress = ff_refstruct_allocz(sizeof(*f->progress)); - if (!f->progress) - return AVERROR(ENOMEM); + f->progress = ff_refstruct_allocz(sizeof(*f->progress)); + if (!f->progress) + return AVERROR(ENOMEM); - atomic_init(&f->progress->progress[0], -1); - atomic_init(&f->progress->progress[1], -1); - } + atomic_init(&f->progress->progress[0], -1); + atomic_init(&f->progress->progress[1], -1); ret = ff_thread_get_buffer(avctx, f->f, flags); if (ret) diff --git a/libavcodec/rv30.c b/libavcodec/rv30.c index be62577f99..d0e10722cd 100644 --- a/libavcodec/rv30.c +++ b/libavcodec/rv30.c @@ -308,5 +308,4 @@ const FFCodec ff_rv30_decoder = { AV_PIX_FMT_NONE }, UPDATE_THREAD_CONTEXT(ff_rv34_decode_update_thread_context), - .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS, }; diff --git a/libavcodec/rv40.c b/libavcodec/rv40.c index d2f8ef9f5a..689432b4bb 100644 --- a/libavcodec/rv40.c +++ b/libavcodec/rv40.c @@ -591,5 +591,4 @@ const FFCodec ff_rv40_decoder = { AV_PIX_FMT_NONE }, UPDATE_THREAD_CONTEXT(ff_rv34_decode_update_thread_context), - .caps_internal = FF_CODEC_CAP_ALLOCATE_PROGRESS, }; diff --git a/libavcodec/tests/avcodec.c b/libavcodec/tests/avcodec.c index f6e394c78d..d65f682c76 100644 --- a/libavcodec/tests/avcodec.c +++ b/libavcodec/tests/avcodec.c @@ -141,8 +141,7 @@ int main(void){ ret = 1; } } - if (codec2->caps_internal & (FF_CODEC_CAP_ALLOCATE_PROGRESS | - FF_CODEC_CAP_SETS_PKT_DTS | + if (codec2->caps_internal & (FF_CODEC_CAP_SETS_PKT_DTS | FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | FF_CODEC_CAP_EXPORTS_CROPPING | FF_CODEC_CAP_SETS_FRAME_PROPS | @@ -172,10 +171,6 @@ int main(void){ AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE | AV_CODEC_CAP_ENCODER_FLUSH)) ERR("Decoder %s has encoder-only capabilities\n"); - if (codec2->caps_internal & FF_CODEC_CAP_ALLOCATE_PROGRESS && - !(codec->capabilities & AV_CODEC_CAP_FRAME_THREADS)) - ERR("Decoder %s wants allocated progress without supporting" - "frame threads\n"); if (codec2->cb_type != FF_CODEC_CB_TYPE_DECODE && codec2->caps_internal & FF_CODEC_CAP_SETS_PKT_DTS) ERR("Decoder %s is marked as setting pkt_dts when it doesn't have" From patchwork Tue Sep 19 19:57:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43844 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp188822pzb; Tue, 19 Sep 2023 13:03:15 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF7jYplQ4hOpmWUkIxMnHmvtPaXlRu5duEEIGNuObsizJb5CoY0mpp5XFbWAQNkTE2b4f+4 X-Received: by 2002:a17:906:5dce:b0:9ae:406c:3425 with SMTP id p14-20020a1709065dce00b009ae406c3425mr366275ejv.0.1695153795145; Tue, 19 Sep 2023 13:03:15 -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 g11-20020a170906198b00b00997c44fb391si10976199ejd.401.2023.09.19.13.03.14; Tue, 19 Sep 2023 13:03:15 -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=avwa2+Aa; 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 34B8168CA05; Tue, 19 Sep 2023 22:59:22 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01olkn2042.outbound.protection.outlook.com [40.92.65.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5861368C9FF for ; Tue, 19 Sep 2023 22:59:21 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e1a6e3Zrhj/NzO/CIjDjdEiBvazEnZQY7EWud1DBC6AMay3765xdLlIciFp138ZdZCrIxcMHpUCkpbFA4ACiemcGtigJzB6vecVkJuraLo4Rx2hMzTkr7ml6M6r4eh1AtnMsorkXjwVIIhiX8XC/6CRCFHHwgOYgVZc+nnAKQHp6h5dJIRAdGiPlNAjsYfjp1tK6Yg9SdXrN87FRyO9clVpgyKJNEwlZPLnicTLSd0d+fMFX+ls6+KuSeiM+/eDsDbQP280BJNmjDca6hmPfJBc9LsKX//maTKVi6OKzAGe1w3/1PXn2GFtIaltrlcVEkQ6UQJH+KQojGJIgicqYSQ== 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=IXG/RcVkdoPVXd183wHHga6F35BDW8CMsY6332TZoss=; b=T9FaA8X2R16UFqGJBTNBJbW6HhK7elUb8l3QyJ8QsutrpHuKho5iB6fibPbyebpjjFdq6R/G78XOhwlLMoxvq1yFhBU3/MlznB7BNp8ctjkigUW7k2F9tWLmom7c63yGfAf7vKZzchcsfymO16u1td9X/NNP13FXTaBvLf0YbF3yIV0TUQhohtAoVcb8DlaPDKSTQU5sh1JGlJiB4RxFWNVrvS23YDb5BQmVcca0bAyobSzks6/kXHwhKBJ9hrdD0oryui5yIb7TNoB56jnnItda2Jmlm6QB5fOlVIDSRN47aASa1TFde2MSnFH3PJyfi//kZhiGkhoK2aLpo9hdWQ== 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=IXG/RcVkdoPVXd183wHHga6F35BDW8CMsY6332TZoss=; b=avwa2+Aan/rraXBVGN+LbRJEB1GLTE9ad6OCvztTUDjEgGxYaxle8eR+2mig8mjVl6GWfflv3OkTUbwXtdRimsQ5MOYEK46ZSjnscWMcm80uJTs9YomVC/Q5rxyVhh7vp5lWNy9GSVzlV1mfOlPglZ4YKWQ3rWZqPOuUF8gvr10/t/I2E7Y3oblb8lx4Ha4GREnJpo81L/GgZ5gBL8jcrJvZrbV3DO4xojCoxIPhS7pwGNdcju0z8UixO4YuBs+jFRGc6sajnN0j2YYXsH5cmtYN5GlzauENQMb9/vaXAX4ZZZun+0MAHmEXjmnjgo71nSLYyleGV2Lt3NI4Jd4tgA== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0237.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:276::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:59:19 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:59:19 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:31 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [vmPZBXUhZxYKiuVfre1GuBFt4UJxM6xm] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-39-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0237:EE_ X-MS-Office365-Filtering-Correlation-Id: 8d8908f0-c232-4935-6632-08dbb94ae937 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: W02OrYe6643+IXGvsGLxQMHiXhsIKsuf7GyHa7rP5nnKWCKYQgENWfyvD3BO/RQG6pyC/zqvOw/gRHG8jEihZ4aDstd17Ki4qerUfRnSqgGfLtin9aeUKZ7lqaeKqoNtvBh9iLbo0rdPN0mVENquwsmOcAypY+xcqlTv0F9guKNu3bpqfnsl8Q0xIc7KisMqHuDHx6jRAWJXhbnCVGDLGi3Hj0nz6v4wSAShtqGjEsxKwmkOKtPHWStxv35EBDfIYwcCsHzVS4l81fpxXx5Yzmhceo61qTtFqyOEDm2QO6Y3d7Xw9yJ6DwBdCzaUGQfA6uUlXAnQbw+4nO2XVcanF5OQjupfIsuwqR5E2zeuwmiN3TvR/9j/J/tH6U9ayuecbUvTKasvhI8uStdPKOfrGJcCBaYJ7y7jgvZ5eEu/5Go3NZghpFV38JFABzGW5sNYWP6Ngw8FYYkmZ6Yk6wXLYMWXKi/zy1LZ0K+MaCjw3lpM9mLRu6/5pTk39IU/6Rbds9Od4EqIkuXTBMOW/Plf2tmaNNHm3ajqLVknd+t8cA5jyR0IR9cWI6nJtj1ZiwA0Gz6w2PNv/1YUsQxwFYKlo0cMwXUcyrtroVyrScChFbfxZyMX+aNfuOXCKwZfY5vD X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: TIdexnT22soIW+l0O4dD5B4pt+KqAku9HyKwgUOEw1SlTEm4XAHmmetROJlvXljg3jPYZIrXS/97llqyF64uax3VwF8ISJUaRlri5GAi6nvVMHDBzrgsqwm/F8br+1BvgBWnXTNqco0AW7oeZV3AuGT6caQWhLqD6QT4ZYdgL1ZBcYxJVkQtfqXZPt2RXHxvFagZI6HYkA/ZqxqCh0+A+cTKb9sbgILfJ6Q6DcazGsim5sxbh5F0eaPPwQzWGR5aQ2m+9l9q8MSiC0merS1/CUPbjQDR9O0cb4+4bTl5N6kf4xaczQJhgZNht07ARcVplFLlMlwOBYqOVwZ3SLmUqi/lureDwc9WyMYJlBnR9MF/Ao2rSICTTg9DzCDkenqLZ8QQNtrKGcFA/OaJz09xGYeFD7fHhIuJBOZwxYZz1nW3rzP5oXs2V0Y3pDHtzA4EhcHYdzUflFg1d/OHcT08mJZRWT8NeEtIfrKGTOdMYPcrf9u4zDPxiRsMTNWyj3ZLZq+rULW0P0z3aDoHr54ZSd2TlhoTubH3mOGPe/4uNhT7p1/LF1IIKnKQEzJULkICMUPnjcXzyPyUhRoPc4SKCfv2RoL1J8L5T8gF1SmieQeIJBjMv7DDaEZ9d90tFvjq2KC5yMI/7xaU83Mat4Gv2Tz/UBqVg5kpQNDCOqLs6DifhSo584oWLkO3t8tHEypN7furBmsL8zI6xLSKc13QVtdyezDtr2yvVRWzJMnMOk/TsjStLZaFOlmfeXvdk3Q0nW88+thHqG6J3WxTX3d11HaGMQ9aztudTCzTyc2btBUaSJTYFbUpTvdqqL/p15Rm580UNjelJYEyrORO03aBUxrGk7kBZhHCbfqsyoWHiP07HxDk1GJdQ/knuw0yk9/YLOHmwMqdbgoLSrtjNszgXYeTxDcJzvrF84zFAkQoTezifKoMiqXtCTQlrpk6KjgBM8N3gLoQ5gd/RQsbr41xQtxFTIPXzT/iQPRqCGqTyB0t8AL/4jXj2sFDrtza5jowuoHb1MrCpUGVhUPTQ7lGob68b6YZF6l/IEDdY39rZ72XdpPAHEnR/o4bi/ejOYL40LhvwtVFd5avk0FcIhnwv2gOD12VCQl6GhyI7DD4P94w0TkhFKnlAZkvZ10/XpyGYz4922r3HjPFrjLqCMsQS147TaEzFkjjPzocO94W1aM2POWIqc+CcYukvaUEhDjGJw6NrM8r+0b9D/Y3Xd9DMm8ksj7TmXoUMM+LMoUnm8aIfbq3rMnNVnW5pehR+VUb X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8d8908f0-c232-4935-6632-08dbb94ae937 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:59:19.6678 (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: DU2P250MB0237 Subject: [FFmpeg-devel] [PATCH 39/42] avcodec/hevcdec: Move collocated_ref to HEVCContext 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: LHKiqzTI2shn Only the collocated_ref of the current frame (i.e. HEVCContext.ref) is ever used*, so move it to HEVCContext directly after ref. *: This goes so far that collocated_ref was not even synced across threads in case of frame-threading. Signed-off-by: Andreas Rheinhardt --- libavcodec/hevc_mvs.c | 2 +- libavcodec/hevc_refs.c | 5 ++--- libavcodec/hevcdec.c | 6 +++--- libavcodec/hevcdec.h | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/libavcodec/hevc_mvs.c b/libavcodec/hevc_mvs.c index c231797a57..0a8cc2c43d 100644 --- a/libavcodec/hevc_mvs.c +++ b/libavcodec/hevc_mvs.c @@ -227,7 +227,7 @@ static int temporal_luma_motion_vector(const HEVCContext *s, int x0, int y0, int availableFlagLXCol = 0; int colPic; - const HEVCFrame *ref = s->ref->collocated_ref; + const HEVCFrame *ref = s->collocated_ref; if (!ref) { memset(mvLXCol, 0, sizeof(*mvLXCol)); diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c index fa53b273c7..9cdc4233df 100644 --- a/libavcodec/hevc_refs.c +++ b/libavcodec/hevc_refs.c @@ -49,8 +49,6 @@ void ff_hevc_unref_frame(HEVCContext *s, HEVCFrame *frame, int flags) ff_refstruct_unref(&frame->rpl_tab); frame->refPicList = NULL; - frame->collocated_ref = NULL; - ff_refstruct_unref(&frame->hwaccel_picture_private); } } @@ -152,6 +150,7 @@ int ff_hevc_set_new_ref(HEVCContext *s, AVFrame **frame, int poc) *frame = ref->frame; s->ref = ref; + s->collocated_ref = NULL; if (s->sh.pic_output_flag) ref->flags = HEVC_FRAME_FLAG_OUTPUT | HEVC_FRAME_FLAG_SHORT_REF; @@ -383,7 +382,7 @@ int ff_hevc_slice_rpl(HEVCContext *s) if (sh->collocated_list == list_idx && sh->collocated_ref_idx < rpl->nb_refs) - s->ref->collocated_ref = rpl->ref[sh->collocated_ref_idx]; + s->collocated_ref = rpl->ref[sh->collocated_ref_idx]; } return 0; diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index c8067a736e..a476a7c7ce 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -2910,7 +2910,7 @@ static int hevc_frame_start(HEVCContext *s) fail: if (s->ref) ff_hevc_unref_frame(s, s->ref, ~0); - s->ref = NULL; + s->ref = s->collocated_ref = NULL; return ret; } @@ -3131,7 +3131,7 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length) int i, ret = 0; int eos_at_start = 1; - s->ref = NULL; + s->ref = s->collocated_ref = NULL; s->last_eos = s->eos; s->eos = 0; s->overlap = 0; @@ -3339,7 +3339,7 @@ static int hevc_decode_frame(AVCodecContext *avctx, AVFrame *rframe, if (sd && sd_size > 0) ff_dovi_update_cfg(&s->dovi_ctx, (AVDOVIDecoderConfigurationRecord *) sd); - s->ref = NULL; + s->ref = s->collocated_ref = NULL; ret = decode_nal_units(s, avpkt->data, avpkt->size); if (ret < 0) return ret; diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h index edf2f188cf..bed8716f99 100644 --- a/libavcodec/hevcdec.h +++ b/libavcodec/hevcdec.h @@ -413,7 +413,6 @@ typedef struct HEVCFrame { RefPicListTab **rpl_tab; ///< RefStruct reference int ctb_count; int poc; - struct HEVCFrame *collocated_ref; RefPicListTab *rpl; ///< RefStruct reference int nb_rpl_elems; @@ -527,6 +526,7 @@ typedef struct HEVCContext { enum HEVCNALUnitType nal_unit_type; int temporal_id; ///< temporal_id_plus1 - 1 HEVCFrame *ref; + HEVCFrame *collocated_ref; HEVCFrame DPB[32]; int poc; int pocTid0; From patchwork Tue Sep 19 19:57:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43845 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp188959pzb; Tue, 19 Sep 2023 13:03:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFG3+wK+jzE+5AY7nVc4QO8s4Meeq6mdYV83FuEw3hdKCXpAuvVwIbsZOnAvv07J+rHVLN+ X-Received: by 2002:a17:906:3007:b0:9a1:ea01:35b1 with SMTP id 7-20020a170906300700b009a1ea0135b1mr276971ejz.62.1695153806340; Tue, 19 Sep 2023 13:03:26 -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 l8-20020a1709060e0800b009930d1379a0si9781514eji.885.2023.09.19.13.03.25; Tue, 19 Sep 2023 13:03:26 -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=KJzLMwrV; 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 497B368CA0A; Tue, 19 Sep 2023 22:59:31 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01olkn2023.outbound.protection.outlook.com [40.92.65.23]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E4AEF68C95D for ; Tue, 19 Sep 2023 22:59:29 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lgsXeuY1b2er/bEiuQQQJ6ubY3jbXl2imyNxGdWsMN+6ZF3X45jFYGrGVq9tXXY7VhNhcElzrQxDsbLRBDzctvpMwYDjWxkLETkYHCU6z5r9tw3hH4DJx0fs1LlF0UFJ0UXo2BjPVQJfpyLMUP49HKb7VfwNIubR74Y+cHMICxTXuRjWVJOG2IUgsxbTerPSWQUU7v/SxsMAbW5d3nvP1vLZbJHM7pGqFBaWZyphWdXuqeHiTCn/vcUYNQtBBrVZ76DzbFSUDIs1e1Vg3Mtu89UQDOAirXyEaQLjHGeki5+1SIax8t5rruD0aFL1S1mKixaksS89CGm+WgQae03akw== 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=9fddjZypzk/iheDtFq8U0C9ogryYZB1A5GMH7zE5+jo=; b=GvlwnLLxpDLMjcDAaqXtDlFx5IGTV7nETgNzDF5ABgd3EEYluDiN4ZrNorHBdiKVQ+owyFkb2hyPIYwyqQojdaQNgCJ3Xox5ZGyGUKz+Fqdct6W7hpWZ4ZpPpHbGi7yQg5iEGjB5MTMpR1U3D4vCrRVBW++bnZRJTcxDg8C9Zrr1LthTqXF0q2pX+t60/J/v2QAWUHI8N6jUfJE3q76wJpmnbtOnYqA4Fh+eHTNYsRlqKHx4vBaB6UDFOkS0621rROTRclMmrUoYAGYFhKWxttUfpLSD9zPjTB0nhw6CQFbcu+eHUio5Z8zDkL6j8oZ6ruhaX4u71MQAHITgVMy/+A== 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=9fddjZypzk/iheDtFq8U0C9ogryYZB1A5GMH7zE5+jo=; b=KJzLMwrV6NjBkkt99Dldx17pEW4wmWqs7r56phEzio/ZMwGGNCBWQMY8KNsPmNWrW/5UVXTnGSPladu2Rnwk0cbSfIIyLKNo9WOAn2IjlnBAhJcckHjh1JKxqLHeHiKlHkFef5l+tv5MK+6E7PBw8z3+cuZQWx74F5KdYIo8ZtugDjlFUehpcdDBwOgdMxI2Ifj0qQ2HTa3KX2KyN3XPwL63Xzpfy05aM7awaX0NGkZVHX6/RzM0TXfipLPpXdM469ztdMzCdiZfi1BAy1JXaDrDV4z/2sjuIuDDqko4YcKRn+7/rJBqa4gIOSYo+C3Rp7NaKKfCwHbABNvIk39RJw== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by DU2P250MB0237.EURP250.PROD.OUTLOOK.COM (2603:10a6:10:276::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.26; Tue, 19 Sep 2023 19:59:28 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:59:28 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:32 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [wnrRSBuc7pFPR+oDf4LZ6+fvOzINz8BR] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-40-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|DU2P250MB0237:EE_ X-MS-Office365-Filtering-Correlation-Id: b7a73f6a-f943-4928-9e49-08dbb94aee3e X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5S1I1qr9rwSLU/6Qu644Hd6sAQxtwu8NVjGySZkC/IDQumoti4U3rj87pMQ+FGkMF2TI/YrjwfTM1+sDQBW2nJVO+ni61x3GDBPqlW8ZQ9LvTlYnJFTuADoVfhaHiF3q5amRWUGhzd0nljafJfY5CIqkKhCzzh4EQQu9sOotmqVhc2BNvEGNRAcFJjhoVfCrkZyMlv5JMSrpqpYB9tzoH4+ut4uejqiSpqeuNKvJPqkfupEzeseXHLfhty/okYUE8EiQ81N0ODYk1kcVCRvA5abnseqdhFxyhy+nrp3enky4j71HxMMolbeHgo+pmZJLpfEnHSxaKa3GkkLW/R7FsRarxUvFHFrIcZRhTxdL8XLCU/ZmzPItA26PQfI49XdyHotzsvbPOp927w3AjFyKINPAG7JwlOUoUHcgT8KbkcPPJDpD/h0OU8sL17X0JiNP+GuJyVbbieOdR4KxfzfKzf7MRPn01M0ByfmR+++Z5JhjY/76c1oFeLsCnvXDIq0EQ7gDekx+uUlx4RuVlB78jcBgf+IpvYd9vNDLLZO7+59EiqUS+oPrQNBpFU5hOdgkZMLaO3/oqCol6JWxI0YLdh/l+U3+6FN5lVO9BFD4Uln7mYm+xdbZd5nbKoTd681o X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: WfRgQpL68BoHVg5GR1IF5gW+01F8UCPH6IDXKoazCdMjSvIhqUajbcwIZIw6ggOddDElLXKen0oXYz571dqhngWILLAaCFHZRN1MUphXlRe1h8FgTrr+q6ke/Cn0GiUJoYWiDRweOwy28SGkPRxs/6oqAepa6uzB2hkiAZg10Z4K1KTZxwXvIlJrZOVu5K3Evq70i9hvD9JRTYB+ZLAGP/o7xcoo47EIP6xUsVDijrWErIrAn5uPHBK7XAQxjiy/knE/s2UqrzA/O/jpWUqPjRNdsxDgzFC7JBio+p2tJRgMOIQozJ5zPUBNYIhKJ+3nVpSlPAd7fQj+NKgDdO3LwiQNHc97s2TvGJR+1gZcNSpDfp6OXmf+ogFJwHIZP+ZqR24r+ABg70QHiL3/5lBGDveFYuyEG+ZT5x9mofxHrAS6iXP2tagvsBdTI6fjg5gRhdvopnMuvKmdusKFVsTyCyE6mwPHXf0xC7Ns2VgMOfQaMIEp0O1H/M/ef1i2K6dg1WFwyePKUotofR3eDDr/qlqwDhgrFQ32VqF6Ycc2szwu0KjYhKRgSqCpQCet7zBCw+fJJA8+QSBNCE4FGEVr0o+3LHdXH0PE99Cw4ZRZvZM9fR+n8xOmoNSfM/vYYxeK+nxh+8dE8PbZdrKTJrA9d8R10/9nGd7LhRypQxJH2qQZ7/onqyTYZJbEgfPluJMMra1cenYSC0B7E9wXUPatTiRWusEE1ZMdexIcy5bVssCzBHygQKqfcV7J6H+datD+jR/v6a6xY9YsXc+Hlaxxf9eV+kbKqEZLrUzqDLjQ6fzBctlQsVBXGny+BZqNQmD6RBSmb4VvOUlM3xsOxGsT2tHEE/scjehIrtw4Gky+OuPoWy18AJxeMjW/AjmeLyeyDMp8OeoKtJ/i9cwBrUYS8Xgslq8v3NdNDbrGzjlVpbG/17C44BvnCE+OCH0ObxjZB40qlBUXJP1f3U3u5poaLbtCeX1+KAYNz1rACnJvpjk1eMOijtD13HmQCpsPJqGJqe4i/sBvgs66pfOLkbonznR5xXr0NOKFc59Ad1X33ftgzUYWy4BD/mb+JYQb6F6LZgtHoXD1Nlww4k1entJ3w7Eq3lsVMKDfQ+D0s/MorqnKj/DNXCErh3ZDzkEJZ5a8vpbfYHt3J3PxlltZ9O+qX7to8admDL9GyEHjkFAYL3wJy5slN4JTyaypCp/PTo5iuu4Dpujii7L9wtlyAYShGd7II8877eStNLYqUSykmzTHODY555EkkJJrCf/IJ+NB X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: b7a73f6a-f943-4928-9e49-08dbb94aee3e X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:59:28.1026 (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: DU2P250MB0237 Subject: [FFmpeg-devel] [PATCH 40/42] avcodec/hevcdec: Switch to ProgressFrames 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: m34koRYxy7GD Avoids implicit av_frame_ref() and therefore allocations and error checks. It also avoids explicitly allocating the AVFrames (done implicitly when getting the buffer). Signed-off-by: Andreas Rheinhardt --- libavcodec/hevc_filter.c | 8 ++++---- libavcodec/hevc_mvs.c | 6 +++--- libavcodec/hevc_refs.c | 22 ++++++++++------------ libavcodec/hevcdec.c | 24 ++++++++++-------------- libavcodec/hevcdec.h | 4 ++-- 5 files changed, 29 insertions(+), 35 deletions(-) diff --git a/libavcodec/hevc_filter.c b/libavcodec/hevc_filter.c index 0c45310ea6..07bae34782 100644 --- a/libavcodec/hevc_filter.c +++ b/libavcodec/hevc_filter.c @@ -26,7 +26,7 @@ #include "libavutil/internal.h" #include "hevcdec.h" -#include "threadframe.h" +#include "progressframe.h" #define LUMA 0 #define CB 1 @@ -874,15 +874,15 @@ void ff_hevc_hls_filter(HEVCLocalContext *lc, int x, int y, int ctb_size) if (y && x_end) { sao_filter_CTB(lc, s, x, y - ctb_size); if (s->threads_type & FF_THREAD_FRAME ) - ff_thread_report_progress(&s->ref->tf, y, 0); + ff_thread_progress_report(&s->ref->tf, y); } if (x_end && y_end) { sao_filter_CTB(lc, s, x , y); if (s->threads_type & FF_THREAD_FRAME ) - ff_thread_report_progress(&s->ref->tf, y + ctb_size, 0); + ff_thread_progress_report(&s->ref->tf, y + ctb_size); } } else if (s->threads_type & FF_THREAD_FRAME && x_end) - ff_thread_report_progress(&s->ref->tf, y + ctb_size - 4, 0); + ff_thread_progress_report(&s->ref->tf, y + ctb_size - 4); } void ff_hevc_hls_filters(HEVCLocalContext *lc, int x_ctb, int y_ctb, int ctb_size) diff --git a/libavcodec/hevc_mvs.c b/libavcodec/hevc_mvs.c index 0a8cc2c43d..be02d52b3e 100644 --- a/libavcodec/hevc_mvs.c +++ b/libavcodec/hevc_mvs.c @@ -23,7 +23,7 @@ #include "hevc.h" #include "hevcdec.h" -#include "threadframe.h" +#include "progressframe.h" static const uint8_t l0_l1_cand_idx[12][2] = { { 0, 1, }, @@ -248,7 +248,7 @@ static int temporal_luma_motion_vector(const HEVCContext *s, int x0, int y0, x &= ~15; y &= ~15; if (s->threads_type == FF_THREAD_FRAME) - ff_thread_await_progress(&ref->tf, y, 0); + ff_thread_progress_await(&ref->tf, y); x_pu = x >> s->ps.sps->log2_min_pu_size; y_pu = y >> s->ps.sps->log2_min_pu_size; temp_col = TAB_MVF(x_pu, y_pu); @@ -262,7 +262,7 @@ static int temporal_luma_motion_vector(const HEVCContext *s, int x0, int y0, x &= ~15; y &= ~15; if (s->threads_type == FF_THREAD_FRAME) - ff_thread_await_progress(&ref->tf, y, 0); + ff_thread_progress_await(&ref->tf, y); x_pu = x >> s->ps.sps->log2_min_pu_size; y_pu = y >> s->ps.sps->log2_min_pu_size; temp_col = TAB_MVF(x_pu, y_pu); diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c index 9cdc4233df..afb9ff0cc0 100644 --- a/libavcodec/hevc_refs.c +++ b/libavcodec/hevc_refs.c @@ -27,18 +27,15 @@ #include "thread.h" #include "hevc.h" #include "hevcdec.h" +#include "progressframe.h" #include "refstruct.h" -#include "threadframe.h" void ff_hevc_unref_frame(HEVCContext *s, HEVCFrame *frame, int flags) { - /* frame->frame can be NULL if context init failed */ - if (!frame->frame || !frame->frame->buf[0]) - return; - frame->flags &= ~flags; if (!frame->flags) { - ff_thread_release_ext_buffer(s->avctx, &frame->tf); + ff_thread_progress_unref(s->avctx, &frame->tf); + frame->frame = NULL; ff_thread_release_buffer(s->avctx, frame->frame_grain); frame->needs_fg = 0; @@ -84,13 +81,14 @@ static HEVCFrame *alloc_frame(HEVCContext *s) int i, j, ret; for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { HEVCFrame *frame = &s->DPB[i]; - if (frame->frame->buf[0]) + if (frame->frame) continue; - ret = ff_thread_get_ext_buffer(s->avctx, &frame->tf, - AV_GET_BUFFER_FLAG_REF); + ret = ff_thread_progress_get_buffer(s->avctx, &frame->tf, + AV_GET_BUFFER_FLAG_REF); if (ret < 0) return NULL; + frame->frame = frame->tf.f; frame->rpl = ff_refstruct_allocz(s->pkt.nb_nals * sizeof(*frame->rpl)); if (!frame->rpl) @@ -136,7 +134,7 @@ int ff_hevc_set_new_ref(HEVCContext *s, AVFrame **frame, int poc) for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { HEVCFrame *frame = &s->DPB[i]; - if (frame->frame->buf[0] && frame->sequence == s->seq_decode && + if (frame->frame && frame->sequence == s->seq_decode && frame->poc == poc) { av_log(s->avctx, AV_LOG_ERROR, "Duplicate POC in a sequence: %d.\n", poc); @@ -395,7 +393,7 @@ static HEVCFrame *find_ref_idx(HEVCContext *s, int poc, uint8_t use_msb) for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { HEVCFrame *ref = &s->DPB[i]; - if (ref->frame->buf[0] && ref->sequence == s->seq_decode) { + if (ref->frame && ref->sequence == s->seq_decode) { if ((ref->poc & mask) == poc && (use_msb || ref->poc != s->poc)) return ref; } @@ -442,7 +440,7 @@ static HEVCFrame *generate_missing_ref(HEVCContext *s, int poc) frame->flags = 0; if (s->threads_type == FF_THREAD_FRAME) - ff_thread_report_progress(&frame->tf, INT_MAX, 0); + ff_thread_progress_report(&frame->tf, INT_MAX); return frame; } diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c index a476a7c7ce..355604a46f 100644 --- a/libavcodec/hevcdec.c +++ b/libavcodec/hevcdec.c @@ -47,9 +47,9 @@ #include "hwconfig.h" #include "internal.h" #include "profiles.h" +#include "progressframe.h" #include "refstruct.h" #include "thread.h" -#include "threadframe.h" static const uint8_t hevc_pel_weight[65] = { [2] = 0, [4] = 1, [6] = 2, [8] = 3, [12] = 4, [16] = 5, [24] = 6, [32] = 7, [48] = 8, [64] = 9 }; @@ -1857,7 +1857,7 @@ static void hevc_await_progress(const HEVCContext *s, const HEVCFrame *ref, if (s->threads_type == FF_THREAD_FRAME ) { int y = FFMAX(0, (mv->y >> 2) + y0 + height + 9); - ff_thread_await_progress(&ref->tf, y, 0); + ff_thread_progress_await(&ref->tf, y); } } @@ -3210,7 +3210,7 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length) fail: if (s->ref && s->threads_type == FF_THREAD_FRAME) - ff_thread_report_progress(&s->ref->tf, INT_MAX, 0); + ff_thread_progress_report(&s->ref->tf, INT_MAX); return ret; } @@ -3381,14 +3381,15 @@ static int hevc_ref_frame(HEVCContext *s, HEVCFrame *dst, HEVCFrame *src) { int ret; - ret = ff_thread_ref_frame(&dst->tf, &src->tf); - if (ret < 0) - return ret; + ff_thread_progress_ref(&dst->tf, &src->tf); + dst->frame = dst->tf.f; if (src->needs_fg) { ret = av_frame_ref(dst->frame_grain, src->frame_grain); - if (ret < 0) + if (ret < 0) { + ff_hevc_unref_frame(s, dst, ~0); return ret; + } dst->needs_fg = 1; } @@ -3428,7 +3429,6 @@ static av_cold int hevc_decode_free(AVCodecContext *avctx) for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { ff_hevc_unref_frame(s, &s->DPB[i], ~0); - av_frame_free(&s->DPB[i].frame); av_frame_free(&s->DPB[i].frame_grain); } @@ -3474,11 +3474,6 @@ static av_cold int hevc_init_context(AVCodecContext *avctx) return AVERROR(ENOMEM); for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { - s->DPB[i].frame = av_frame_alloc(); - if (!s->DPB[i].frame) - return AVERROR(ENOMEM); - s->DPB[i].tf.f = s->DPB[i].frame; - s->DPB[i].frame_grain = av_frame_alloc(); if (!s->DPB[i].frame_grain) return AVERROR(ENOMEM); @@ -3510,7 +3505,7 @@ static int hevc_update_thread_context(AVCodecContext *dst, for (i = 0; i < FF_ARRAY_ELEMS(s->DPB); i++) { ff_hevc_unref_frame(s, &s->DPB[i], ~0); - if (s0->DPB[i].frame->buf[0]) { + if (s0->DPB[i].frame) { ret = hevc_ref_frame(s, &s->DPB[i], &s0->DPB[i]); if (ret < 0) return ret; @@ -3671,6 +3666,7 @@ const FFCodec ff_hevc_decoder = { .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SLICE_THREADS | AV_CODEC_CAP_FRAME_THREADS, .caps_internal = FF_CODEC_CAP_EXPORTS_CROPPING | + FF_CODEC_CAP_USES_PROGRESSFRAMES | FF_CODEC_CAP_INIT_CLEANUP, .p.profiles = NULL_IF_CONFIG_SMALL(ff_hevc_profiles), .hw_configs = (const AVCodecHWConfigInternal *const []) { diff --git a/libavcodec/hevcdec.h b/libavcodec/hevcdec.h index bed8716f99..827a26c536 100644 --- a/libavcodec/hevcdec.h +++ b/libavcodec/hevcdec.h @@ -40,7 +40,7 @@ #include "hevc_sei.h" #include "hevcdsp.h" #include "h274.h" -#include "threadframe.h" +#include "progressframe.h" #include "videodsp.h" #define SHIFT_CTB_WPP 2 @@ -406,7 +406,7 @@ typedef struct DBParams { typedef struct HEVCFrame { AVFrame *frame; AVFrame *frame_grain; - ThreadFrame tf; + ProgressFrame tf; int needs_fg; /* 1 if grain needs to be applied by the decoder */ MvField *tab_mvf; ///< RefStruct reference RefPicList *refPicList; From patchwork Tue Sep 19 19:57:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 43846 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:a886:b0:149:dfde:5c0a with SMTP id ca6csp189097pzb; Tue, 19 Sep 2023 13:03:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEebN47QyyKtHyYWrshVc7Wms6BmC0lOl5Bu17jPl701OuFSmtKN0YFgDNDoTEJdCXoRxg4 X-Received: by 2002:aa7:c995:0:b0:530:74ed:fc8a with SMTP id c21-20020aa7c995000000b0053074edfc8amr340842edt.41.1695153817531; Tue, 19 Sep 2023 13:03:37 -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 y3-20020a50e603000000b0052a17658cb0si11595163edm.677.2023.09.19.13.03.37; Tue, 19 Sep 2023 13:03:37 -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=UN71z5dX; 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 8014968C919; Tue, 19 Sep 2023 22:59:38 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05olkn2098.outbound.protection.outlook.com [40.92.91.98]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id AAAF568C919 for ; Tue, 19 Sep 2023 22:59:36 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dDvBY4V9+6DAJjA1pf/GPWdWF0X94beTAvpTy9L7gc4+Z23qUmXHp/j8PI83kz3G6TZp3ub1OE8eUdEhkA1i95FDAhIiuHYTwPQXa2eGwojwx9cJ4CUPaUqPf0fs9dylPXvVEp6jBks6c/Dm6dtBxJRgVTsuOs9JJko10DHxd/V39PceuKDmczNBCZ2CC0dVxToLZXXSdvL76OswFPqeU2gBeBXIlomdHtR7q6W+i0QHK3qB2AD5flGy3FQ2syKLwR2BXA7GoXmxqlq3U4ADg1ag6VxPuuDQbt+SsZ9UuoeIiCCH2t/2VZFNdbRBgW445d8HuRSaJtDury24BxZnHA== 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=XCG+0qTYbUcBadOcBhSe8rz9xvldkMpllWHpTg0cNX4=; b=lALVbqCWYE1oHAmzVqXXnwQgXJUaF9qKM4rmCFSEXLf+bJ0osm3gHkoSAV735M1+IWQ4ye0Z6i1NN6syICrvn9jcTGlANxZvrDydFV9bs+BPloNeC+AbrNMfvdu8O3dUfy2xcWvZk8B65tXzZiYp+XsztldKI0JeJWmjmO0VAn2P2rWdNnPHPsBYjC0LlJOv6X6Z2D4/lp3KWAB2O7dAHgbhBJhadphNFxBhIpMsodT+HJrPMNQDVVxC2hWu09FOFxHvMjnEP9wgPKukhbET5tDn85uN15VLbiiXtkmbNvY8kNQHIU9ULlX4t3r4j5kRZFym3YsROBC/UZ4XiAOQng== 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=XCG+0qTYbUcBadOcBhSe8rz9xvldkMpllWHpTg0cNX4=; b=UN71z5dXoG0s2LTqTWv/oRt3DhhSLEZ11X+/btIjkFLOykFp5+L/6ft7I7WLavm6VzZZnfsWQNQYFKKuAlMBHCjY6emaLahVPVEiJj32UJsTKpVwT32hyjtwEGajxWRXrUHV1VatYYZTKvLoO1nBQCkvWuGfrrWoHXWUhKHpCtnLddhxnvPteSlJTVXf6eAeYsvmmhLr+wlMzPhITXpwO4dGMugY5T9n8mWdATL8xn23EiiiRWFps/TCIIA5qyvjNiAA7789RfubfFHplGUPD85g9+Xh3Jb5BMSpAcAtEzKjZK34ZwtTV31Z16+RMYJm9k7jczEyTIPBTdRfPUlNYg== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AM8P250MB0295.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:32a::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.27; Tue, 19 Sep 2023 19:59:35 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Tue, 19 Sep 2023 19:59:35 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 19 Sep 2023 21:57:33 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [7ihbt65gFiiHvgYvvtFcN9vVf2BZ1Gmm] X-ClientProxiedBy: ZR0P278CA0086.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::19) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20230919195734.1005750-41-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AM8P250MB0295:EE_ X-MS-Office365-Filtering-Correlation-Id: de09965a-aa50-46bc-76a8-08dbb94af257 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aHd8P6bLfibhPZVE6k/0rzc+ZoaohG4rskCIDQswk8oxMUZTIx202y6J8njAE7B3pDKsKWarFS614Pp7Ah1B7EzsH/Q8FZV2evWBR1NV5u4Uygwn+mzXrmhxejMDEDkGndQy6sIl6H//NOUE+AV6msi56M5Dnj783FfOfWV+zUIkMYP5PMvAX0OGn5H9szHL9wXhD+Ursr52hu1bMKZiF1DuTMArjZqyNpXXSYJp3McDi58otVTd/4Pf0+8rJHZNJq3+ru4VwEabEQh68SSpBrUBBwQr1jKvFjDuwCooxnvrkKCoT8k4c8BLtBUfCyKx2U/RPr96hQfdWXnIiaO3lx3qdxr5ICMKSS7ozZttqODGNwRzHobKM6K0RfdMBT40Vwc+nUvzY6mK+7JPPcMOC44lwr8CveFMXqfJNt6KEaRmufAhAcaATQEvwxOx6JoEGTYch3qrLF10iaBryzyAwsKGwTdjT/846YTVcICiomV5rmc933PYA9olXjv23iUKdyPuTZtzizDnfEFBePqX5h6WO0LUBKTFkmawuA8E5mWETd3jTU7XwdxTgBQktIonHwOw1bVhPCUKCPOQV6OOwvd8X1QTglcEfa+yJ5dZHgyri5zZJgtq2XI27hte5YPp X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 20FtpT3juxa4U5xr3PhprY+52zOpwEmnC1lAn3xgzZV3UPh8vG0vEAZkJVdYq/Fvh6c81I3Gg27YhIMz0j19TJW9eBsn+kj/tvcjW57nU1bdxgUx8/4R6KlfbZOlU2YZ3pL6SeLu6RHfAfGBe1eFIfZSFQkXQ7vg8sm7jaXuBeKHhGGtf9Gtddt/cIf8lCfRXF4j0lpbghLCZof2tKy855ZtqpaZlpd8U4lN0TRcTRR76jdwWwNgYTXXYs5lAINH8jScdJadcv5h+qrhteU50jO2l6eYAJWQSf1dVfj3VpHFBoQ7jTrXypakuGt+7o9j7TOJcr5KVojjrTKTG8ToaWbwx9ylutlKF9C9mk6L/IkeaosfPdeH7YDDIm74DYykoxECVx+Q9Twb2ug2tns2W7FrKGh8TkH2qZf0eh5n/NN2yKY0px/h9jTBgr0NAROd8N+AQBtHTYJ25YDL1Wn1AEE1owvUKH/n7a/Cj8tf4GPnkuwYhaUk16OhGaYLHMKsKskginJqf3nYRKoSzyDT1pvTFATgPWNCOGfR2HS6COO4B+pQ6p8bUPP9SebnJN1P2xybmPSqhbMoZqMWYvAqtyT+CnBi9FK3axw8yEcGlelU2IJHXh/s9Gqq1deuie7obctB+qBtvBylTvuZcZ0xaVh42W1KxnL3FTbgkhfiSbT+Pdb9+3gS8r0IbLq7raAfv+c8KYdeV9WyZ75fg5KkAaS5q2hHRiXWB4Wb4yZgQdmtM8Q2DohzLjCM+o2KNwwfwg7bF6fB1uKfVVIixIb9Zyrb3XCIA4NCiAjeLEwArY10MA9sIAtYqKnuYEW0n13ptWBy1YdhxrVIyCbXyZRJAK2ro7Aj34g8GSteiugNDd20y7Jb/Et6eilfdU/Y962e91UFU4vmPOouRsEdB0xQBAeqT1MKPsjxUG+su/K6cqDizTlJv328/WvbWVfV8BqfqfKrQ615OMVFO2Nzokoc4P0ZygLDXD/6Th08sIQodf3OXxrZD8bWBHFt40lHfjUe2R1HgFSRMfVDrS2qYfqk1Gwoauk9kcJomCTZMsbXli46M1tEczq8vmHdJCpdHAqUDzHRODGOf2CgP/Y3hrfHwl+mAG+qMKhPN/nmbMbAKT2NZyvgoSvVWlLUuW9RzxbCKFMcbaLV1ziJOtxYz/rVL59i9oOp9FXXoQe5mzubiPGCaSouP7xAeXoyMFxd6PDTZ/qxdVvvDbX97muTKUP0nAvhO8Jm64FsWa+Stch+JOmM+4bmqrcNq+CGAGdDSpK6 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: de09965a-aa50-46bc-76a8-08dbb94af257 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Sep 2023 19:59:35.0104 (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: AM8P250MB0295 Subject: [FFmpeg-devel] [PATCH 41/42] avcodec/pngdec: Switch to ProgressFrames 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: M2ab4fJ7BVfs Avoids implicit av_frame_ref() and therefore allocations and error checks. It also avoids explicitly allocating the AVFrames (done implicitly when getting the buffer). Signed-off-by: Andreas Rheinhardt --- libavcodec/pngdec.c | 64 +++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 37 deletions(-) diff --git a/libavcodec/pngdec.c b/libavcodec/pngdec.c index c011ca386e..8576ccb3b1 100644 --- a/libavcodec/pngdec.c +++ b/libavcodec/pngdec.c @@ -40,8 +40,8 @@ #include "apng.h" #include "png.h" #include "pngdsp.h" +#include "progressframe.h" #include "thread.h" -#include "threadframe.h" #include "zlib_wrapper.h" #include @@ -61,8 +61,8 @@ typedef struct PNGDecContext { AVCodecContext *avctx; GetByteContext gb; - ThreadFrame last_picture; - ThreadFrame picture; + ProgressFrame last_picture; + ProgressFrame picture; AVDictionary *frame_metadata; @@ -815,7 +815,7 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, s->bpp += byte_depth; } - ff_thread_release_ext_buffer(avctx, &s->picture); + ff_thread_progress_unref(avctx, &s->picture); if (s->dispose_op == APNG_DISPOSE_OP_PREVIOUS) { /* We only need a buffer for the current picture. */ ret = ff_thread_get_buffer(avctx, p, 0); @@ -824,8 +824,8 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, } else if (s->dispose_op == APNG_DISPOSE_OP_BACKGROUND) { /* We need a buffer for the current picture as well as * a buffer for the reference to retain. */ - ret = ff_thread_get_ext_buffer(avctx, &s->picture, - AV_GET_BUFFER_FLAG_REF); + ret = ff_thread_progress_get_buffer(avctx, &s->picture, + AV_GET_BUFFER_FLAG_REF); if (ret < 0) return ret; ret = ff_thread_get_buffer(avctx, p, 0); @@ -833,8 +833,9 @@ static int decode_idat_chunk(AVCodecContext *avctx, PNGDecContext *s, return ret; } else { /* The picture output this time and the reference to retain coincide. */ - if ((ret = ff_thread_get_ext_buffer(avctx, &s->picture, - AV_GET_BUFFER_FLAG_REF)) < 0) + ret = ff_thread_progress_get_buffer(avctx, &s->picture, + AV_GET_BUFFER_FLAG_REF); + if (ret < 0) return ret; ret = av_frame_ref(p, s->picture.f); if (ret < 0) @@ -1195,7 +1196,7 @@ static void handle_p_frame_png(PNGDecContext *s, AVFrame *p) ls = FFMIN(ls, s->width * s->bpp); - ff_thread_await_progress(&s->last_picture, INT_MAX, 0); + ff_thread_progress_await(&s->last_picture, INT_MAX); for (j = 0; j < s->height; j++) { for (i = 0; i < ls; i++) pd[i] += pd_last[i]; @@ -1227,7 +1228,7 @@ static int handle_p_frame_apng(AVCodecContext *avctx, PNGDecContext *s, return AVERROR_PATCHWELCOME; } - ff_thread_await_progress(&s->last_picture, INT_MAX, 0); + ff_thread_progress_await(&s->last_picture, INT_MAX); // copy unchanged rectangles from the last frame for (y = 0; y < s->y_offset; y++) @@ -1594,7 +1595,7 @@ exit_loop: } /* handle P-frames only if a predecessor frame is available */ - if (s->last_picture.f->data[0]) { + if (s->last_picture.f) { if ( !(avpkt->flags & AV_PKT_FLAG_KEY) && avctx->codec_tag != AV_RL32("MPNG") && s->last_picture.f->width == p->width && s->last_picture.f->height== p->height @@ -1611,12 +1612,11 @@ exit_loop: if (CONFIG_APNG_DECODER && s->dispose_op == APNG_DISPOSE_OP_BACKGROUND) apng_reset_background(s, p); - ff_thread_report_progress(&s->picture, INT_MAX, 0); - - return 0; - + ret = 0; fail: - ff_thread_report_progress(&s->picture, INT_MAX, 0); + if (s->picture.f) + ff_thread_progress_report(&s->picture, INT_MAX); + return ret; } @@ -1703,8 +1703,8 @@ static int decode_frame_png(AVCodecContext *avctx, AVFrame *p, goto the_end; if (!(avctx->active_thread_type & FF_THREAD_FRAME)) { - ff_thread_release_ext_buffer(avctx, &s->last_picture); - FFSWAP(ThreadFrame, s->picture, s->last_picture); + ff_thread_progress_unref(avctx, &s->last_picture); + FFSWAP(ProgressFrame, s->picture, s->last_picture); } *got_frame = 1; @@ -1756,10 +1756,10 @@ static int decode_frame_apng(AVCodecContext *avctx, AVFrame *p, if (!(avctx->active_thread_type & FF_THREAD_FRAME)) { if (s->dispose_op == APNG_DISPOSE_OP_PREVIOUS) { - ff_thread_release_ext_buffer(avctx, &s->picture); + ff_thread_progress_unref(avctx, &s->picture); } else { - ff_thread_release_ext_buffer(avctx, &s->last_picture); - FFSWAP(ThreadFrame, s->picture, s->last_picture); + ff_thread_progress_unref(avctx, &s->last_picture); + FFSWAP(ProgressFrame, s->picture, s->last_picture); } } @@ -1773,8 +1773,7 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) { PNGDecContext *psrc = src->priv_data; PNGDecContext *pdst = dst->priv_data; - ThreadFrame *src_frame = NULL; - int ret; + const ProgressFrame *src_frame; if (dst == src) return 0; @@ -1799,12 +1798,7 @@ static int update_thread_context(AVCodecContext *dst, const AVCodecContext *src) src_frame = psrc->dispose_op == APNG_DISPOSE_OP_PREVIOUS ? &psrc->last_picture : &psrc->picture; - ff_thread_release_ext_buffer(dst, &pdst->last_picture); - if (src_frame && src_frame->f->data[0]) { - ret = ff_thread_ref_frame(&pdst->last_picture, src_frame); - if (ret < 0) - return ret; - } + ff_thread_progress_replace(dst, &pdst->last_picture, src_frame); return 0; } @@ -1817,10 +1811,6 @@ static av_cold int png_dec_init(AVCodecContext *avctx) avctx->color_range = AVCOL_RANGE_JPEG; s->avctx = avctx; - s->last_picture.f = av_frame_alloc(); - s->picture.f = av_frame_alloc(); - if (!s->last_picture.f || !s->picture.f) - return AVERROR(ENOMEM); ff_pngdsp_init(&s->dsp); @@ -1831,10 +1821,8 @@ static av_cold int png_dec_end(AVCodecContext *avctx) { PNGDecContext *s = avctx->priv_data; - ff_thread_release_ext_buffer(avctx, &s->last_picture); - av_frame_free(&s->last_picture.f); - ff_thread_release_ext_buffer(avctx, &s->picture); - av_frame_free(&s->picture.f); + ff_thread_progress_unref(avctx, &s->last_picture); + ff_thread_progress_unref(avctx, &s->picture); av_freep(&s->buffer); s->buffer_size = 0; av_freep(&s->last_row); @@ -1862,6 +1850,7 @@ const FFCodec ff_apng_decoder = { UPDATE_THREAD_CONTEXT(update_thread_context), .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS, .caps_internal = FF_CODEC_CAP_INIT_CLEANUP | + FF_CODEC_CAP_USES_PROGRESSFRAMES | FF_CODEC_CAP_ICC_PROFILES, }; #endif @@ -1880,6 +1869,7 @@ const FFCodec ff_png_decoder = { .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_FRAME_THREADS, .caps_internal = FF_CODEC_CAP_SKIP_FRAME_FILL_PARAM | FF_CODEC_CAP_INIT_CLEANUP | + FF_CODEC_CAP_USES_PROGRESSFRAMES | FF_CODEC_CAP_ICC_PROFILES, }; #endif From patchwork Mon Oct 2 18:13:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 44102 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1204:b0:15d:8365:d4b8 with SMTP id v4csp1574306pzf; Mon, 2 Oct 2023 11:12:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IERyn79jZry6ALU4DR/Ub1yvTt5AscwNDcCuvrM5YN9OnaF7MGepeR2wZdlkWl5eJi206sk X-Received: by 2002:a05:6402:17d3:b0:530:c536:443 with SMTP id s19-20020a05640217d300b00530c5360443mr10932559edy.1.1696270364582; Mon, 02 Oct 2023 11:12:44 -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 f8-20020aa7d848000000b0053635d33580si4287461eds.114.2023.10.02.11.12.42; Mon, 02 Oct 2023 11:12:44 -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=tx1Ckmh7; 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 D9A0068CAE4; Mon, 2 Oct 2023 21:12:38 +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-db3eur04olkn2095.outbound.protection.outlook.com [40.92.74.95]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E742168CAE4 for ; Mon, 2 Oct 2023 21:12:32 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ahwdeRMA/1tY1miyqDzUYzdJYJ2tktRwLescsW6scJBjn/tQX94xtbAafGAilj3Hrj1JTOnd8v1rKXOX29d+/eGm4tpH89sy8yMdCI2pX5dp0YukgC/6yXoaJxu1P5NrKy4OBvxcf+b1bI47b/rFxbaPu8hJ7LwzxnWSGLwHKnjia6/pN0E4SI+u4txyDVxtXKwvc4xal1YtQp/yO7v+9rk32yO0OUTXHZ8SpMNpINTAqx0NQLbV0xzUpcYIqsZE7VLdXTDdcWCNbdYUh6NBeYkCLV2FS/13AQmyVEHaAIOaZnLgo9USA06zN9NsfLbh9hKllfXRLg/+Rst5Kbh59A== 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=DlNi9IFBGKrPKsL1c067RasDnsZYgS8xQw5L89IqdPw=; b=Nfxe3moSJGg3O52NemLbLkanKxOKQgWqb+1DDtPYv56U5iDBGbXcz30ZTQm8CcLzpFekFxFol1CYJSogMCINfMg3mmE44b0gLay10G/5yMpia/mEh/4L8GKkRhQYWqyENYBfEaqmGmvhcJeXtPztYDU/CThJRRwcNXjr3PJnnGjmJtfybhXtk/oBP69SuC/qh5iM7HV975b3zglFz+aM+b43/8kZQrR5G6INeZ7xFduNOs/yNLiy0tvnl+ddrspTOfuW6DVFxQfjwCaJNymuTNtjRPl3j7d7OQkwQbf7tizGYYRxCAY/pPRezbVrGiBaPzEvriynMlePTavFP4MI6Q== 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=DlNi9IFBGKrPKsL1c067RasDnsZYgS8xQw5L89IqdPw=; b=tx1Ckmh7BTGofLkzjcBk9SwQlPjM5d2AkiotCeFx5lMuomO7ap+ioKEe5kAb7Gfs6TjvbRkZAzL4DeYj4mQPU6V9ze7hov0hdW/u+iHNawWFCtawz7RMUIaE6mkTlstfEErppUY7wSFGbJu0pyeSRkh4XeOxyuhUtbnNT5DA8OlaM+nWwGJc4Q7f0CTbdpEwQ29mgfo6r+ddhjpmVROGGreKmMusSf9flJ00YK7fZVlJqfGt3KwN5sXUzet8eZWHKWYSZ3W33OtNJwtivtKj5npqeGKOUS5AOd3vbI/6tFicJOhvINt1F+eOz+Hw3X5IxLyvJG3HhcBfdIEgRpXVZA== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AS8P250MB0218.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:379::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.27; Mon, 2 Oct 2023 18:12:29 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Mon, 2 Oct 2023 18:12:29 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 2 Oct 2023 20:13:32 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [3JNJXFmlr7VIRpiTGJIJKWxoJqN9lbwf] X-ClientProxiedBy: ZR0P278CA0087.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::20) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20231002181338.1030463-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AS8P250MB0218:EE_ X-MS-Office365-Filtering-Correlation-Id: f3dba30d-4b8c-4fad-465a-08dbc37323a6 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 53+BQ6icOc5UZi++WFUTQZHDBN3t6WNVItqtySD/nBIhIyMbSqInTrkek+A+R8X88ND4SgHhUyCcOI9/i0D3+3AtrHIbmpody84o1qVgzV7pP07sKG+kZp8jfsN9MrtUNSyr9bAd+jbyFu6TWKENUAiA2MHRkcwyiBa9hPl4M1VBB2VdXO5ngrVPACf6VQwo+fxVZKqikzlCnpQN0bbnruxA0SgV6VW4kaA6+sEsLYmPPW9fl9MGi/JvWMUkApbimKrugrtI9IRkpvSQ7i2Yj0qxDWkiHPAMNsjdNSYfUOO8LrZrydOI/xuc1ZNWKEgHRn4b5rx3Vu/RnKtlWDVPLZIUNi4aG88MML8drLFOyqrUtPS62biSANIeiBI8KA7L2dpvsN/Ehf/f0lcxeazK31J3Bs1NbTT6H1bp0a/AOC3Ob8Xpx9r94KOXiu5WP09aArxkD+6e4DAiJSk2Zgdmwiw3+BTmPm46v/xCbeiVH7JFiUmpf1nKk5WY7b1/dkxL4nALO/vWzhP/whJltoAJh7ku3XLXBHPDk86Lgwh718xaYvec+xMnpb4GgqF8W70ilBHpBchefnG1v8jUlwrpCNVuyic52UYi5lEiYy83zNV3aCZ1JUebuimqaElh5kEC X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VKSK+Tysws8W9YuB8EGskJr8sk/ZYQJdYI5gQ4vd4ZdM/FGERHiB/16Hg0EiWNh5nGnICeOaxVMSSpKzM/EZmD7f5hgEn5y68pFmLtK2WsYhAI23utqBFJqaYeWufvffLnuToaI5+Iw3THH95VJLhIu6QIYbXUlaYFpO1eWYti/VwyM+igoHXx4S591gQoFNn3hjBdRF/pFfSmqeSi62ImKUbqOMuj/HUnTgbEgDQsKdlJHW38W9TO0O25o80uxtLCqZPSFV1/GNlG8dO/J53Wz7YQt8PKghE8vJyOToznFphIF4XhU9o0XV3yNXu4J/JV2cOTsVSa3NBw06savvGx/xzZhE6hmyZ2PLKN2wHZNFSbQFR+OPZ24t0qpkVdayYRqg+KB4uxRe+Ul1pFSlexp7IX0VIpnpAsOccwM2JB7m4UNHyqfXVgdVNke3momKh5l8AcBYFfediwa8f0t1HFqswV02yBul6Hfv8PHUiOxKUZno+71FZuWCm0JEA3NNIVQdQvr3+QsV8JRJAq8fgRDn+pLlczXwxxMoWnVPDva5SEkfl0FCuH5EqTL3yiWkUANMZ2ReRUlc1iiKg3pOwtsmhqjLNM63WwsN5tRfJUYL0OKUJe47wpk4w/NcHmuWf5OlpWV+Co7b9FmMYQNOEet2C9Ac6wrbiVdPD/Q3KZjB2DGj3pSKu9LM4D5npYkgshGDhvzkHQWDH0UupVQqSEAhSy6gyLmIVN+e2smSzc2ooQ8D2OpEtzscAAdiph+mp8x2vO5pqjaI4+/7Ro5KhU0PL3qSP1LYLPwQ5AH2Du4fUShRFFEHCgIV1knVGRp0/KWlDrm3gWcJI4EYJbcuNbwmkMI0ZlNWCi2J3JWWry5NgwW5tKIoHp1lNY5zXtVRpYhz5AXN3Mncc83yyPs4Qe+wWJ4wvsR/iGgzOdzkU59305atNQeoj01Tu7aSLpoOrFt8In7yLmFT3HaG5iOXeUCkvoX/9jVadTwyYImDkEXWE90oAw/7+GboyIBRQzry/NJJI1l/5d1LPtAAKWshoNZ6X290400jyEqIbmAqNbuUwfdUQei4dmY+s/EAAE1+EuBjR5dgd7QCoYyOndNHCHAgA2gA4OqodChcrcn5E6iccNZEwjUAxhhR/5kV7+i0V9yctnMVhRBp0YzE4084h0jchz+TrID/CZ2WnRQ/h5lbSF3FxfWfwXdDwORyllqJJjijlCr+Rk3LulEdfR3hmbTBw3SJyNOvfiHvJcF/Ajswpz8vUALCK47d0FhaeXjg X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f3dba30d-4b8c-4fad-465a-08dbc37323a6 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2023 18:12:29.3160 (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: AS8P250MB0218 Subject: [FFmpeg-devel] [PATCH 43/49] avcodec/qsv: Use RefStruct API for memory id (mids) array 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: Re1Hu8mVdWAu Avoids allocations and therefore error checks and cleanup code; also avoids indirections. Signed-off-by: Andreas Rheinhardt --- Would be nice if someone could test these additional patches; I only ensured that they compile properly. Here is current branch (there will be merge conflicts with vaapi_encode.c and ffv1dec.c when using the patches sent to the ML): https://github.com/mkver/FFmpeg/commits/refstruct9 libavcodec/qsv.c | 55 +++++++++++++++------------------------ libavcodec/qsv_internal.h | 11 ++++---- libavcodec/qsvdec.c | 3 ++- libavcodec/qsvenc.c | 3 ++- 4 files changed, 31 insertions(+), 41 deletions(-) diff --git a/libavcodec/qsv.c b/libavcodec/qsv.c index 7563625627..4f639e33f5 100644 --- a/libavcodec/qsv.c +++ b/libavcodec/qsv.c @@ -34,6 +34,7 @@ #include "avcodec.h" #include "qsv_internal.h" +#include "refstruct.h" #define MFX_IMPL_VIA_MASK(impl) (0x0f00 & (impl)) #define QSV_HAVE_USER_PLUGIN !QSV_ONEVPL @@ -741,20 +742,19 @@ int ff_qsv_init_internal_session(AVCodecContext *avctx, QSVSession *qs, return 0; } -static void mids_buf_free(void *opaque, uint8_t *data) +static void mids_buf_free(FFRefStructOpaque opaque, void *obj) { - AVBufferRef *hw_frames_ref = opaque; + AVBufferRef *hw_frames_ref = opaque.nc; av_buffer_unref(&hw_frames_ref); - av_freep(&data); } -static AVBufferRef *qsv_create_mids(AVBufferRef *hw_frames_ref) +static QSVMid *qsv_create_mids(AVBufferRef *hw_frames_ref) { AVHWFramesContext *frames_ctx = (AVHWFramesContext*)hw_frames_ref->data; AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx; int nb_surfaces = frames_hwctx->nb_surfaces; - AVBufferRef *mids_buf, *hw_frames_ref1; + AVBufferRef *hw_frames_ref1; QSVMid *mids; int i; @@ -762,35 +762,27 @@ static AVBufferRef *qsv_create_mids(AVBufferRef *hw_frames_ref) if (!hw_frames_ref1) return NULL; - mids = av_calloc(nb_surfaces, sizeof(*mids)); + mids = ff_refstruct_alloc_ext(nb_surfaces * sizeof(*mids), 0, + hw_frames_ref1, mids_buf_free); if (!mids) { av_buffer_unref(&hw_frames_ref1); return NULL; } - mids_buf = av_buffer_create((uint8_t*)mids, nb_surfaces * sizeof(*mids), - mids_buf_free, hw_frames_ref1, 0); - if (!mids_buf) { - av_buffer_unref(&hw_frames_ref1); - av_freep(&mids); - return NULL; - } - for (i = 0; i < nb_surfaces; i++) { QSVMid *mid = &mids[i]; mid->handle_pair = (mfxHDLPair*)frames_hwctx->surfaces[i].Data.MemId; mid->hw_frames_ref = hw_frames_ref1; } - return mids_buf; + return mids; } static int qsv_setup_mids(mfxFrameAllocResponse *resp, AVBufferRef *hw_frames_ref, - AVBufferRef *mids_buf) + QSVMid *mids) { AVHWFramesContext *frames_ctx = (AVHWFramesContext*)hw_frames_ref->data; AVQSVFramesContext *frames_hwctx = frames_ctx->hwctx; - QSVMid *mids = (QSVMid*)mids_buf->data; int nb_surfaces = frames_hwctx->nb_surfaces; int i; @@ -811,12 +803,7 @@ static int qsv_setup_mids(mfxFrameAllocResponse *resp, AVBufferRef *hw_frames_re return AVERROR(ENOMEM); } - resp->mids[resp->NumFrameActual + 1] = av_buffer_ref(mids_buf); - if (!resp->mids[resp->NumFrameActual + 1]) { - av_buffer_unref((AVBufferRef**)&resp->mids[resp->NumFrameActual]); - av_freep(&resp->mids); - return AVERROR(ENOMEM); - } + resp->mids[resp->NumFrameActual + 1] = ff_refstruct_ref(mids); return 0; } @@ -850,7 +837,7 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, return MFX_ERR_UNSUPPORTED; } - ret = qsv_setup_mids(resp, ctx->hw_frames_ctx, ctx->mids_buf); + ret = qsv_setup_mids(resp, ctx->hw_frames_ctx, ctx->mids); if (ret < 0) { av_log(ctx->logctx, AV_LOG_ERROR, "Error filling an external frame allocation request\n"); @@ -861,7 +848,8 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, AVHWFramesContext *ext_frames_ctx = (AVHWFramesContext*)ctx->hw_frames_ctx->data; mfxFrameInfo *i = &req->Info; - AVBufferRef *frames_ref, *mids_buf; + AVBufferRef *frames_ref; + QSVMid *mids; AVHWFramesContext *frames_ctx; AVQSVFramesContext *frames_hwctx; @@ -889,14 +877,14 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, return MFX_ERR_MEMORY_ALLOC; } - mids_buf = qsv_create_mids(frames_ref); - if (!mids_buf) { + mids = qsv_create_mids(frames_ref); + if (!mids) { av_buffer_unref(&frames_ref); return MFX_ERR_MEMORY_ALLOC; } - ret = qsv_setup_mids(resp, frames_ref, mids_buf); - av_buffer_unref(&mids_buf); + ret = qsv_setup_mids(resp, frames_ref, mids); + ff_refstruct_unref(&mids); av_buffer_unref(&frames_ref); if (ret < 0) { av_log(ctx->logctx, AV_LOG_ERROR, @@ -913,7 +901,7 @@ static mfxStatus qsv_frame_alloc(mfxHDL pthis, mfxFrameAllocRequest *req, static mfxStatus qsv_frame_free(mfxHDL pthis, mfxFrameAllocResponse *resp) { av_buffer_unref((AVBufferRef**)&resp->mids[resp->NumFrameActual]); - av_buffer_unref((AVBufferRef**)&resp->mids[resp->NumFrameActual + 1]); + ff_refstruct_unref(&resp->mids[resp->NumFrameActual + 1]); av_freep(&resp->mids); return MFX_ERR_NONE; } @@ -1105,11 +1093,10 @@ int ff_qsv_init_session_frames(AVCodecContext *avctx, mfxSession *psession, qsv_frames_ctx->logctx = avctx; /* allocate the memory ids for the external frames */ - av_buffer_unref(&qsv_frames_ctx->mids_buf); - qsv_frames_ctx->mids_buf = qsv_create_mids(qsv_frames_ctx->hw_frames_ctx); - if (!qsv_frames_ctx->mids_buf) + ff_refstruct_unref(&qsv_frames_ctx->mids); + qsv_frames_ctx->mids = qsv_create_mids(qsv_frames_ctx->hw_frames_ctx); + if (!qsv_frames_ctx->mids) return AVERROR(ENOMEM); - qsv_frames_ctx->mids = (QSVMid*)qsv_frames_ctx->mids_buf->data; qsv_frames_ctx->nb_mids = frames_hwctx->nb_surfaces; err = MFXVideoCORE_SetFrameAllocator(session, &frame_allocator); diff --git a/libavcodec/qsv_internal.h b/libavcodec/qsv_internal.h index c2d301b4a2..d970cd20f0 100644 --- a/libavcodec/qsv_internal.h +++ b/libavcodec/qsv_internal.h @@ -115,11 +115,12 @@ typedef struct QSVFramesContext { AVBufferRef *hw_frames_ctx; void *logctx; - /* The memory ids for the external frames. - * Refcounted, since we need one reference owned by the QSVFramesContext - * (i.e. by the encoder/decoder) and another one given to the MFX session - * from the frame allocator. */ - AVBufferRef *mids_buf; + /** + * The memory ids for the external frames. + * Refcounted (via the RefStruct API), since we need one reference + * owned by the QSVFramesContext (i.e. by the encoder/decoder) and + * another one given to the MFX session from the frame allocator. + */ QSVMid *mids; int nb_mids; } QSVFramesContext; diff --git a/libavcodec/qsvdec.c b/libavcodec/qsvdec.c index da700f25e9..e53d320d0d 100644 --- a/libavcodec/qsvdec.c +++ b/libavcodec/qsvdec.c @@ -50,6 +50,7 @@ #include "hwconfig.h" #include "qsv.h" #include "qsv_internal.h" +#include "refstruct.h" #if QSV_ONEVPL #include @@ -875,7 +876,7 @@ static void qsv_decode_close_qsvcontext(QSVContext *q) ff_qsv_close_internal_session(&q->internal_qs); av_buffer_unref(&q->frames_ctx.hw_frames_ctx); - av_buffer_unref(&q->frames_ctx.mids_buf); + ff_refstruct_unref(&q->frames_ctx.mids); av_buffer_pool_uninit(&q->pool); } diff --git a/libavcodec/qsvenc.c b/libavcodec/qsvenc.c index a0144b0760..8a607ee5e7 100644 --- a/libavcodec/qsvenc.c +++ b/libavcodec/qsvenc.c @@ -41,6 +41,7 @@ #include "qsv.h" #include "qsv_internal.h" #include "qsvenc.h" +#include "refstruct.h" struct profile_names { mfxU16 profile; @@ -2622,7 +2623,7 @@ int ff_qsv_enc_close(AVCodecContext *avctx, QSVEncContext *q) ff_qsv_close_internal_session(&q->internal_qs); av_buffer_unref(&q->frames_ctx.hw_frames_ctx); - av_buffer_unref(&q->frames_ctx.mids_buf); + ff_refstruct_unref(&q->frames_ctx.mids); cur = q->work_frames; while (cur) { From patchwork Mon Oct 2 18:13:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 44103 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1204:b0:15d:8365:d4b8 with SMTP id v4csp1574402pzf; Mon, 2 Oct 2023 11:12:54 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFbhBKvvQJDvqrL2cWaFkfJ7KMJmIVooYs0gvsxL18c3EbqWUr1xDN6EiEVCrgNQjQGVnb7 X-Received: by 2002:a05:6402:51d2:b0:533:5d3d:7efe with SMTP id r18-20020a05640251d200b005335d3d7efemr424439edd.6.1696270374027; Mon, 02 Oct 2023 11:12: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 t35-20020a056402242300b00533e6b4a33dsi15990000eda.353.2023.10.02.11.12.53; Mon, 02 Oct 2023 11:12: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=KtqPjkyM; 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 0FCAA68CBD3; Mon, 2 Oct 2023 21:12:47 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03olkn2081.outbound.protection.outlook.com [40.92.59.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9B42F68CBFB for ; Mon, 2 Oct 2023 21:12:40 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gZZq+tP9yuDs8iF7V6OZ+9nh1tvuswnIkNV97+Z8O7xVxPO4NZOnAhvQODcxSbD/0CHyLlrk9uXJr6GHuh9vechF1B3BMYi1M+nZDnRgjQdK7AQVKAM9aS9W/Wt7gv1NCkiGd7L2VXXCPcd5fdXNLMf0szTaXKEXQcBW23vVoBdOoV9j10WLK0gHdH+tBpFQ20Z73hrmFeN04lUqgYSZcOrkQ383Q0MQFoU/TvAqQMdGW0FU1/6pXqeiW/p3CfwmpQEbUwnYS+WFITyqkz1Sm/YuZV6w2+ztq4YqGpuuyWW932XKOZOLODE6C2v30/dhGfQQT2GnfyODf3lNac6anA== 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=TyTwDrBkaLYOdlsHrQPSQpexkurk0Q1EZrX4pQGOGZI=; b=c5qYPhefnYUDbsx2aluyrD6XuJy7g37w02nlRGYSxROxmWB00sRuJi3NohtXCnq/dcfXt3gUl4rzKQjqf5afae4N4rnu3DnNMCFqBGp1vaBwVO9dIEBGWrAHs861z1nmiQmlSco8kpQNSt0jTi0OzWymu2iMnYusCfMq1MKpvJjecjc0wFOkNTpDIFCgFHiryTVl0XjClAUhSROk5U2je4NGNepdDX4cZ4cE0I+GHV+qLSr2PZEJ1VLBYK6kWGiRreEIM1jZDXvzZb7scsDrW/2iYDVsn79ULpDItUdSyZLKkYwVALmubQyGkXG83IvF90zn8uyHfGHG+u/XP5rzcw== 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=TyTwDrBkaLYOdlsHrQPSQpexkurk0Q1EZrX4pQGOGZI=; b=KtqPjkyMu2bNEWZ0bhme/3iKJGoanmdi1FQDTjmYrJhVhDh7b6QCppSKgIMiAgfU07R7JXTT0JBFLClgFhsrzR23J9foyZrNWOYd7+wtKB8xvO5giI2y42WE5y5FbCyGKfwPPjrwjXud3KPDiinEZZMMgNdYwRuEsCAcJNgKrVUKuBkI/zUgZCawY+8+QIcYmYGAe5hJnpzMFES+NHeMsRMK3Gw4cziRI7HZRnikDGLgnM49867TEv5Kqr2+607LcYRMYpRuqK8RVOb/PZyZbxJyWhuGqwdBqJvHBSo3LAkElkgRl9T3P3BoGpgGgnrsJQgpHy5u5eRZ+v2DYIyicQ== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AS8P250MB0218.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:379::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.27; Mon, 2 Oct 2023 18:12:39 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Mon, 2 Oct 2023 18:12:39 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 2 Oct 2023 20:13:33 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [17cBhuBmRndoy5NEwGv04XFDNd6JGjMJ] X-ClientProxiedBy: ZR0P278CA0087.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::20) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20231002181338.1030463-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AS8P250MB0218:EE_ X-MS-Office365-Filtering-Correlation-Id: 6003bf90-52c5-4e5e-c9f9-08dbc37329a7 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7+tYbk40SFU0UGwvqyguZwP4FtmEoHKK2BujEEf+cYc1xlTxHjFlOznyRG/p1RPGNLJqm0P0CraZJA8RNkAnLeadCQpu995iop7NN1183vzzaPJXXbNyzs9mHy0R4vEhUdJzPYOk2BfBgOxhb2FIY+U8IUxLU+VUGebskkt+N62y/h0zVcNSXVskF1tWYshnenv48U7E8/QMFkPIBZg98e44tclf7NUEx/3hbiEA2/WoDuEwXejO5Ms1twnQc1qUzxj5aVX8fRQy9DL9TyM3Q2G8WbiuIsbW5lWZzjik+ulsoaOCp5kcZgNfR2qqOSMm66cZAIUHBQemilaESajz20ce6VijOPG6xN708CaGjPvqbVDWdznamx66DT0Q8iQPhEk2d7J37FrsAjeS4XxkLpxQu7UUcdpogYa0IWVSAn4VGYBLs5sJKbeapFnB7uP97eALXdXrSjirOGIVN05gktXNhsa5EiOYvMiEY1NSGs2tyeF3kzfIsMU8+ciWY4Ia3vxnsZMuX5GvgG/mkkKqH/yuc8NIMXFzxil8lmW6XtvEuNZALLroToDY02i96n0qf1QUzNvJv1YF0Of18HA9UtFJeOv1JOFBoNK6rEJJGKfRfhm3UAB5U7DJKhJYyUYY X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ztdB1S2Lczig+PoMZAoovY+Z4ct8+29UmfDncdQqk7SxcPM/dWkKNo2zKMq9EwZv2MaGSZOrChHb7WiPhFpBRvLOTqqoGLuYkLXSGD0mUDcAToOrwJ+5KGx++UNNCPVgzy0KzL9Ic1kvKrJvMYrii9Req/583g3Ee7mP7raMT2vun2aM8TqkQ0OFL2cmSvfc1iAz3yKYRxWER5LLlJcviaAhC/6cTIyIPT4AFFbsrSgzldCAXtLjtp1q6V2mE/ERzPzNMFegkC3grSt4ROX/uAZtKQaRZ4Z0Yo2MTAHp4cPgL6GEj4qhbYCCmjvPxzg/k19SagINoKgQNLGB3N2Tjd/BRkIQ/rqkM8DN1RVK/oLwUGbSnsHFusQA7XjhsYmDNDKmL1MESVajWDF8mDyoCWmCWyUTsSlXG7mZpi//lDMX4tzx9hvzBiThH+ZfAVvBQvkXpKDvmYBIE9b40KU7aN94Y9QOBif2wagE5GE1mb3pUx+5thZh+JMJtkFPJvTagorE1rLxMw3pypalVo3fDsOJfWvlfIz7jQ3R4SwxCjeZjTkXlIEw8BMlFxTLpw2OUs+LGe5hNacqBc275EasDIJDsAAnE4FVKp2nihuVEWbT10DQubOCpG30IQd/XKKDZq7pkKJh3iMVnZSTRxGWmuXCDQa0DczwBGKaBAdjRr6ibqvgHu4YJjqzNbmCQH7txPWU45P9t8do7jzsbNUs5usNJvtUIC4OzlDJ24rJzMF9pYcNonYP9jrH5+rTEZSaY2Lf7xi3b6Gqvv82oL7OXyOnJHR57jgJCPxYJmXG96HY1FkgbcMN8Rm8LCwVmy+LgM6du20l+xtIoZgiBowIpru04aOgHElA5HtwSAX8g4R5tCvptrgJQ9RN7mw6sf6o3Ju4ng9VY/gYb/f8q/LM8gaWhX2TeHfdE48pQOS849p8yJ9ZJR/LC9H2C/uze/Ci/sGmL0hTR1hsVdRTjt1xdcnR4UofPVEJiFbCfmuCa9HdggQHNccAsDba9dsDYsd/v86eoLGxtPU0Gno1vKqFAXZMGx4DzO9gBTU9OlFnLWK3Agy4i4KxA0z/F/HXaqy5ixDy8WgKzNr2E4OK5cpo7PowiuhEZnrV/O5aroeBfZlRGv+OxnmOF/zv0+h41PuDlrIooGAhR69fR7Ok8sz/Ad8lkJb37+/Niq/TaXPAaXwtVIDtLXpqe6gS690ruygcvo4xjcO/DByg3I32gPnFYKVnkuF44tNNroaHw3gDR8Tt7HU3qrcUsSFZ6LdFrX5y X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6003bf90-52c5-4e5e-c9f9-08dbc37329a7 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2023 18:12:39.3650 (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: AS8P250MB0218 Subject: [FFmpeg-devel] [PATCH 44/49] avcodec/rkmppdec: Fix double-free on error 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: qc8Mn+HX13Li After having created the AVBuffer that is put into frame->buf[0], ownership of several objects (namely an AVDRMFrameDescriptor, an MppFrame and some AVBufferRefs framecontextref and decoder_ref) has passed to the AVBuffer and therefore to the frame. Yet it has nevertheless been freed manually on error afterwards, which would lead to a double-free as soon as the AVFrame is unreferenced. Signed-off-by: Andreas Rheinhardt --- I hope we have a maintainer (or anyone else) for this who can test these patches. libavcodec/rkmppdec.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/rkmppdec.c b/libavcodec/rkmppdec.c index 5768568b00..2ca368e0a9 100644 --- a/libavcodec/rkmppdec.c +++ b/libavcodec/rkmppdec.c @@ -462,8 +462,8 @@ static int rkmpp_retrieve_frame(AVCodecContext *avctx, AVFrame *frame) frame->hw_frames_ctx = av_buffer_ref(decoder->frames_ref); if (!frame->hw_frames_ctx) { - ret = AVERROR(ENOMEM); - goto fail; + av_frame_unref(frame); + return AVERROR(ENOMEM); } return 0; From patchwork Mon Oct 2 18:13:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 44104 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1204:b0:15d:8365:d4b8 with SMTP id v4csp1574498pzf; Mon, 2 Oct 2023 11:13:03 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGliUF+HXajPO9nizhJAu1lJjaN2Mhy4yvVzAZnoknpTlAfz8uxJdvtnfkVkBqcVbPYtDbl X-Received: by 2002:aa7:d3c4:0:b0:532:e39b:8c05 with SMTP id o4-20020aa7d3c4000000b00532e39b8c05mr8470941edr.42.1696270383009; Mon, 02 Oct 2023 11:13:03 -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 f13-20020a056402160d00b00533470248casi3752106edv.53.2023.10.02.11.13.02; Mon, 02 Oct 2023 11:13:02 -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=rk5ARh1P; 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 39B6668CC48; Mon, 2 Oct 2023 21:12:52 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03olkn2081.outbound.protection.outlook.com [40.92.59.81]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B113068CC11 for ; Mon, 2 Oct 2023 21:12:45 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HAZ2RoME3lZ3+14oyrpf85iqa5gCu223CEjqwtYYhG+vDZfB9mr6L27NgNJRYMBXNLIbOoAvdlubG/nGjajMwfTlPQlvIYjMiK8nBSvcWKbe0dxb99ROqUqTfYiu1K2UGpF0e7xJlVIHUnxP6I0dfvGG162pO7aDDHuz8cK9yWiywWtWe6psmo5xos0oAicEqF6Z5fa1cZzOXAfGsZZIzn2JXiJTjEQgxwjpraKT7KR49dS6Qsv4VixIjefGON0p+yrGV9ictJjjQMPMNL57Juw39Llqq0gd5YkZlSQoi5FkUCfbErXywP5AzgGKn49cSPrnnTBJZfuzZwWBb4a/Tg== 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=QhxOcT3kaNhCiAz/wihMAuSAxd4wjwqXWtkS42AgGYY=; b=gG1QV6U2TuuLZmos57mLe3s9XQwTkh70pIZfB/MohBP5oPJzqHYh6x5V6xZy329ns/Etu4w3x2NO/XFLGEwZhHQUjpdq+FUA1/PxcnSUsj9viFYm2Ur8chCVeJCcrtYnVXxC1UU57ufA6lAC9lMjsXNoTzb2SVC593mLY+8+4wBNaFIriUF0dO2EnhdxIpRphAdIKu2d+IY0wTpQSkhfU4IKugbw00h3+NO9B+eWglADn8Z782WJ8tABXPcF1z2Tqfi12FrsVWGR0K+80Diepz/oU7OIt5ug28r7gkB1Rn6mcnmnF2npoh2sPclMxz28eIzUfDWtpWbz0cq88Jk1gA== 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=QhxOcT3kaNhCiAz/wihMAuSAxd4wjwqXWtkS42AgGYY=; b=rk5ARh1PaAKpYh04bimvHqzyHXnG6pGYLdqslozbee3lOqdYogJMD+mLqd7EArbZk/trlrXjaZRaWCOwq0kIg0Sfr152nFigH0lFscfCTMVECoV9zzHJWgPFafzusfWF/h91Iw/we5gF3wMuDzespeUZHEKrijI8EJa62UOWoVmiF3jUwkg85ZTCBXSrnbTNd8nZO9pks4Q0QWf8+pFXD7cBJ+D4SugMY1WUJndABfhZ1/Wtg8RlepEdgzlhlQ5TAmCItBEVapsQt2gJnUhEAoi3PpKlwZdlCP6y19LF7vKeLbiiGnmaJ1o+L76DxIGf2DhX7zc7k99FArW/vF3xrA== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AS8P250MB0218.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:379::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.27; Mon, 2 Oct 2023 18:12:43 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Mon, 2 Oct 2023 18:12:43 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 2 Oct 2023 20:13:34 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [Il7cO0u6f+CfIPDsXupzKzhTqH8eKz8+] X-ClientProxiedBy: ZR0P278CA0087.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::20) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20231002181338.1030463-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AS8P250MB0218:EE_ X-MS-Office365-Filtering-Correlation-Id: 4a2722ef-d07c-4965-9f53-08dbc3732c26 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kvi2XTINHUcDhr/DfZImVEJfm9k7tDI30Y0rmh/CKCcNDm21tFnq1KXZLxE3HGMyCcbJ9P/I8DGWJMfxXxe/co61xM9kum0oWQ2GpV21rI5Ed2XLAmGRI2QfWBA2iMCjFgn9XRDQeIsZTN/OmS8hBzSJ26DFeQo7tHnZuwKR6BCh2V5THjuob2z8pUNMu/2CigRWdvESGF6LS6PnD4zQWbFq+a5L5meFqLtzPOd71znI8iVmuPiVJSaxO6zhQBTuddk0LuJp2VH+BcuSsJllLnf77h1v+/DGqoqZFZMK0rOcZ6/9VJjlZYcJ19JOr2/U2VveSST32JZHqvy8+8IYBZXX2hlXYxYKDIKodBaBN4+ueYisiH2xOW10CkOT/YN90aeFyGQCJ88dOcszUxGLzjXOsUEd0Kw/VLlY5PxVLu/ewVs7BQ+RBZ1xpluDVJFZNWJXyQYAQe/ojkp7oVxV7oEBpmGtrOZQwNb7Duz0i7hsVQpTzNUB8AF2xrj0mjwzho+r2vW1rAGm2apPf/nvptSC5O0d9PN3y3IEvh0oB23mhIaP98NV/oysipiqJm0mgFWFPUH8MKZSB3J4EutRVeveo8wa3IGkkTyBZc6vN1fpOfN3ajzI7qawWwO2hgin X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: g70zT13hSqQbkkSR2hI0D6/BznJg/KWW6xfVapali1fZMazyPHmfbdcltSWpuPtDBjr4oP9g31aRBGpBwXCVDD2BgWQPwElpPf9hEMYTnsp2KDZVUWm8ro+p4W8tfnNLyMAua4csvNeIUv3ZogXqCkPhwiehzwmx2+5LNWz842PrALQ3AFHq61v3ttNyoEu1V08BMM7szNO8NQR6uQE2KllT83PNOWr63OOxNZPuxGluCZmfSJgeJJsJ4l1XBLITAWFj/m5+Vv02IbTY831soDw+xNrKiHwN3QLzo+1K/MtsVfPKM8j/146wt9KnaScSavmjeF9qm0/a0uwnlKVatOGM1fofn1n/zr6K35prHMedR+YY0VAxdV+pYClM1FQ0MU1YM/Ur7AwfsyWCdlzW72a8s/lQINMDJWCIByQc6+fCspRVr5X4DPFdfWCLCow2RJNcyM8M9FwZB+U31K0ZOnYwGU86A/CTFQx1Pn390/qpC1jEO4DkjYWDQVw/SUy7yHW1bTwYk0NS5XqVqN2WLIxCoBmfTghZwqWf7tAlQf5HU1qiFkohNA67zAEhV+t0Zq+jqeDgqm9V/C5vsxLPgag7et8U4vvcT/0a1A7dgOKVXepcP3ozOMdUIetYXG9NTBKdCduhN0Yi7nixYfrH/JIFDovPvaAOCrVRweAcLo//BLKmF9LQKY74V8di8HhCyQZbjulfoo2og+QoggcELauVX6l38PvhceGbayx7vYPP8Xm2OQUh5SM8apmbUt6YdZ8kEMIvLfgj3WjuHcH1/y3pJJZCOUzlBZzUtsLlRp0xAsdc9Y9McKQIfyk2xwk7QfY3gdDk1j6soEuZ0rgOAUBKnXlmKOGZme5qK+bs+fSQvR3ThqVK9KFNLbpynPu3PcRqhkTjs/fhPJHqSGh/aEKoP235Zev9rVbCpMV/CY9D8VFnlRhJroCIKdHIA1fVjEqwaBq5RmQIPs+hdE7P3AkZPdIS9rBq914joR6XNN+bBYpHtiaNiPiFUBesO870VGSdUjQmmv7hACkbYbdD4+VLFYuCMq4mxvN/pHBipPMXJexIfBnyio64qqQIj57ouChGB4dsZzP7VIKNswfFJRnoOFsmKzVaoEwr0B7nsqOi89B6riKvPoIxer9HGiGVR8vijiv4KF3/QPcuGV1YHHV0c98xR3D3yrQ/WmkiDPFdkVM36hkCNb8SkjV5hihGXNoyf4xgPWR22jpZPCDNRUUVA8OqReKH3a64rHLSJcJcy+p1xnA9POg847JAOwpJ X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4a2722ef-d07c-4965-9f53-08dbc3732c26 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2023 18:12:43.6063 (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: AS8P250MB0218 Subject: [FFmpeg-devel] [PATCH 45/49] avcodec/rkmppdec: Check av_buffer_ref() 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: CW++QmnXtygJ Signed-off-by: Andreas Rheinhardt --- libavcodec/rkmppdec.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/libavcodec/rkmppdec.c b/libavcodec/rkmppdec.c index 2ca368e0a9..4cca65d8fb 100644 --- a/libavcodec/rkmppdec.c +++ b/libavcodec/rkmppdec.c @@ -449,6 +449,10 @@ static int rkmpp_retrieve_frame(AVCodecContext *avctx, AVFrame *frame) // MPP decoder needs to be closed only when all frames have been released. framecontext = (RKMPPFrameContext *)framecontextref->data; framecontext->decoder_ref = av_buffer_ref(rk_context->decoder_ref); + if (!framecontext->decoder_ref) { + ret = AVERROR(ENOMEM); + goto fail; + } framecontext->frame = mppframe; frame->data[0] = (uint8_t *)desc; From patchwork Mon Oct 2 18:13:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 44107 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1204:b0:15d:8365:d4b8 with SMTP id v4csp1574733pzf; Mon, 2 Oct 2023 11:13:30 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG9qWNshVW6FrTEYG8mrm6u6uE1/FMyqlAOpT1M49lrKIMNtQCwFWAv4PWANCo3sj7OsR2k X-Received: by 2002:a17:906:c14b:b0:9a5:962c:cb6c with SMTP id dp11-20020a170906c14b00b009a5962ccb6cmr332561ejc.31.1696270410124; Mon, 02 Oct 2023 11:13:30 -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 pv7-20020a170907208700b00991ece4c95esi18988937ejb.487.2023.10.02.11.13.28; Mon, 02 Oct 2023 11:13:30 -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=lSaOc41L; 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 5D08168CC44; Mon, 2 Oct 2023 21:12:55 +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-db3eur04olkn2057.outbound.protection.outlook.com [40.92.74.57]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 6D2F468CC34 for ; Mon, 2 Oct 2023 21:12:52 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R6RI8QRHZ/OmOMvJWpLRUKOWvW9pN8nX9EoI03ciYzh6DMfobou2WLE8iFcHJXTplPAASPl/bqU801F/uQ7htbVspXaZwpqzBo7GI3zoyIVgphsrARn5GTM2O4h+t+eGdy4NAoYLS+EEX/4rLe7+4nojOxuHabQLVgWOetsCV1NulmG1sIzUwT1Oix28ePwF6E3IKNHnrV9trrURWFeXtMhupSDvCxyWK5Y+gnhQ47RhZvZ1Xsu5ZKi3eW98lHPVqLuoVvojPoDVzOZm/UxXIBP0IJDA4EGUFKRfinfPApq2SuxqPMFt1DUcjksCvNOONoZH9bG6LORTcn1a7ekX/w== 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=RLgkNl9SMKz/78x+4gs3unWIF4ICXCa/TUPMYVRJnHA=; b=caErYu0Dwi9L3T4XlNdlALVeYl55tCBlGQvO+3Q/XLo7aApY/MzjlxMVllSCtsXZ6rf6HDj1CcJiMIoslPIetwXStf8L8QjUgiIZOiOXz9cf/BGUwkV9Y0077mkifrWYCt2+I3tJZWFwGkpPxED0mY1F4I28HIfmbKHKVTMzXnMArz8E3IFJJvmHYnhv4t3NT8DOFlLngnHAcnhT10bhl4Bww++v1ZZqi3idCYN7bX7LE3DGaF82eEzMVCgxAOK8auvqYoEp3HyK3GdraauPFrGV2XLDmrJpu/5z60/A4vNMwWJ9/d3MPUHbNKGA4lwmjt1syRp5W+JsmNx0BTy9mQ== 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=RLgkNl9SMKz/78x+4gs3unWIF4ICXCa/TUPMYVRJnHA=; b=lSaOc41LfKKe/im2y82IPFyPR/gqlKdn+jhqkqMGCmWVwTvlARgk33v27GV0vPRt7MMJsAtK1HnrMnWIOCoF9huw4WByPoHdCTse7IAUXsaz/Kd099mx1D3ForVBE/aGrQi/vKh9GV5TM/vgF39e4IbkEnvvvAykvMiwwSezWgCrP2bYGneNBfOTBVLpFhQFLUF4s0uTA+0QtEuE3PxlzV5b4QxgLyPZBkL3ITV8QvQc+0kTErGTM3uLQxtXJvp9268ceOP8uGjx1a/WYqwrb4rA92etx1DXezN78IsEn1bZCjsrJTkX2IuYsA4CVgcftymyxNze3YuswT0hKcAYlw== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AS8P250MB0218.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:379::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.27; Mon, 2 Oct 2023 18:12:45 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Mon, 2 Oct 2023 18:12:45 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 2 Oct 2023 20:13:35 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [ZBAXo1rT9xX7Ljd7n/4liplEunT1dsSX] X-ClientProxiedBy: ZR0P278CA0087.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::20) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20231002181338.1030463-4-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AS8P250MB0218:EE_ X-MS-Office365-Filtering-Correlation-Id: 1d55ca4b-7963-4658-1106-08dbc3732d28 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zmCobcP2lB+i6y670tPMKnt9cGPO/q7j2IaukJugcxrEtCdMLH91dewBARlGWgj2oBgxw7DAd9x1sy1lUJ/fdIt2DjEdFRba6Uqarw4L88vGtHzo78NhNVPI3Jqw8j2qheXOND3u3rKqp+/Sby23HlUfQDaOrXnrhDRSs74TKcA5OSa2077x40K6Dv6xylb6PP4QZTRRae3q4wHGknzTt+91xvvt9r35QHsdHyru26gwUZmcWLlb+vStWmXACSTk9CYbfN3UzrJsXC2+Ki2I4ChR8RoZtFDj6Lsq7wghQiyb8pJS5KJp7NXiD5nAwmokwgxX51Yan46cni6hDzx3hCxvla5d4IyRkTTO6vzIxvVshXvlclEibx+50AU49DOl21zw4FUmPVyqAcYaBekHyR91qg9h58QqngKCBuFhKI450bDOuPQ71WjCoTj14l4RpO/QDhhahJScY/GodnQe8YdF5TBbBn0KZX8Cbkr7D/JwA316hD1JZFUEQLgC2c31FXukpVrOrsBHPCJFIOApVu6W9xQXaxHxdwODRJlXQZ6pED7iOTnWKFuVV8HBbZ8QSg7i+S/t4aAUqiUdymUBSKeGBmiZAphwk8IihrEhlk2375WbUItlmttamMb8KUpe X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xnOv3Q0OFvHy3a/UwshTIozOXOdCuYdP5pvWAexTPrcaVRcAsb9sMxdqEtPHKhGyH9iTDJRYHTlhZQ2adwNVjbUs4B8NQFXhsBIq4DARlt0SbWAt2zl62dBYFbpp0NpL6c3Yi0ZYG5VjUKK2s58bFVIxSklvpKM8EZjQ+xaBVwy53eu1+ajoYC5HirQCTCuoBXJHADg5oUjWdGsU9sGVFb5tsg55AxhAxLUR0c1vUq9kqiQueariB0MKd26qJfrr4BgblRHmbfa3+V9ewz7uYuPZmYiOqF+vJxH7hJ4uk8GPWMwfURV0XI1g1MDufqS6igOTRsygfmFljb1qvEvqNUuMkbdMucrjmaGEPPmUvbNjJdC8kuJqaG0NkVAcWO256B7c3XRB6SAhwyday03rd4BGjRBloHW8n1bqyXZnBg4GRppQfLWy3Q+IjSo2s43EM+5GtU+hM7u8x+Fkq8hg/o2AAeyHMW5vrOVNCWRpE8e4ZYvO1XRT2L2GPDYmu9tazQ/+PAv+Y9JgBnh0LbEOYb/ZW7cJXPzfWq5Luzlb3l7f9vB7pcT14cagEdbm84vtzG9wYXyDKNGB2EoDuvtFEAFFMUbB5JfOCk0lhsKO2sKDwTx/PMIABcarIxPCEZ7N3qJiM+q5w/BOX1ns5fKrF/nKtq18VxE8ZCTSFNr8nvnGryeS0Ex79PEp1gxcz7W1iftG2g1KMQuW+/2FB9SxuIFg1Csw+92muheyRVxUPLPUCnXq1wsAIBJqP8AaDXbkIxhFZaqrSvrDs1a1YUHPen2KQov8vIv3vF4Sx+veOo/9Yh1OsbzyfuT+GtVwcAtX7voPPuUpCpGFDjPubCZcLSgEQpynlJYk+A1wZM5SoEV4NiFupaOgYwgbwUld4hovsRXV0Jlmjdi4itC8oR5f25/tiBJioZc8bPRNODR0Ja5DT0ep5D2LEVNGsN8gjMLmtZoyWinyLAemN3ic/zor9yfl78PUeT1dAWWy2LgtHhikXb07UmaXM+hIon9dM32vHHr4uDUroYsNJGbDSNNP00cleA2m2M1QgPiC99mQ3I5CGQMtH6hU01DIv8KZg3HEsxeITAJC6w234FjMgS0DyraAJMsVxfVIkOzfivOlgsWh8dMyzdrHHrN3DOgJMeVc56CdskWK1j2aLB24F7HtDqJMjBp8nz8f2KAQ6IPtElrNiIdmsqGio/FfW4cxCLgfSjaAqaewVy7nh435c/GJ/hcARb5qzUOUKohMrHgq0DSIV2oqCp/IQ2LUB/TM7JsY X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d55ca4b-7963-4658-1106-08dbc3732d28 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2023 18:12:45.2647 (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: AS8P250MB0218 Subject: [FFmpeg-devel] [PATCH 46/49] avcodec/rkmppdec: Use RefStruct API for references to decoder itself 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: pI/sozP+dLOg Avoids boilerplate code when creating the context and avoids allocations and therefore whole error paths when creating references to it. Also avoids an indirection and improves type-safety. Signed-off-by: Andreas Rheinhardt --- libavcodec/rkmppdec.c | 46 +++++++++++++++---------------------------- 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/libavcodec/rkmppdec.c b/libavcodec/rkmppdec.c index 4cca65d8fb..dd0b9c5a4d 100644 --- a/libavcodec/rkmppdec.c +++ b/libavcodec/rkmppdec.c @@ -30,6 +30,7 @@ #include "codec_internal.h" #include "decode.h" #include "hwconfig.h" +#include "refstruct.h" #include "libavutil/buffer.h" #include "libavutil/common.h" #include "libavutil/frame.h" @@ -56,12 +57,12 @@ typedef struct { typedef struct { AVClass *av_class; - AVBufferRef *decoder_ref; + RKMPPDecoder *decoder; ///< RefStruct reference } RKMPPDecodeContext; typedef struct { MppFrame frame; - AVBufferRef *decoder_ref; + const RKMPPDecoder *decoder_ref; ///< RefStruct reference } RKMPPFrameContext; static MppCodingType rkmpp_get_codingtype(AVCodecContext *avctx) @@ -89,7 +90,7 @@ static uint32_t rkmpp_get_frameformat(MppFrameFormat mppformat) static int rkmpp_write_data(AVCodecContext *avctx, uint8_t *buffer, int size, int64_t pts) { RKMPPDecodeContext *rk_context = avctx->priv_data; - RKMPPDecoder *decoder = (RKMPPDecoder *)rk_context->decoder_ref->data; + RKMPPDecoder *decoder = rk_context->decoder; int ret; MppPacket packet; @@ -124,13 +125,13 @@ static int rkmpp_write_data(AVCodecContext *avctx, uint8_t *buffer, int size, in static int rkmpp_close_decoder(AVCodecContext *avctx) { RKMPPDecodeContext *rk_context = avctx->priv_data; - av_buffer_unref(&rk_context->decoder_ref); + ff_refstruct_unref(&rk_context->decoder); return 0; } -static void rkmpp_release_decoder(void *opaque, uint8_t *data) +static void rkmpp_release_decoder(FFRefStructOpaque unused, void *obj) { - RKMPPDecoder *decoder = (RKMPPDecoder *)data; + RKMPPDecoder *decoder = obj; if (decoder->mpi) { decoder->mpi->reset(decoder->ctx); @@ -145,8 +146,6 @@ static void rkmpp_release_decoder(void *opaque, uint8_t *data) av_buffer_unref(&decoder->frames_ref); av_buffer_unref(&decoder->device_ref); - - av_free(decoder); } static int rkmpp_init_decoder(AVCodecContext *avctx) @@ -161,19 +160,13 @@ static int rkmpp_init_decoder(AVCodecContext *avctx) avctx->pix_fmt = AV_PIX_FMT_DRM_PRIME; // create a decoder and a ref to it - decoder = av_mallocz(sizeof(RKMPPDecoder)); + decoder = ff_refstruct_alloc_ext(sizeof(*decoder), 0, + NULL, rkmpp_release_decoder); if (!decoder) { ret = AVERROR(ENOMEM); goto fail; } - - rk_context->decoder_ref = av_buffer_create((uint8_t *)decoder, sizeof(*decoder), rkmpp_release_decoder, - NULL, AV_BUFFER_FLAG_READONLY); - if (!rk_context->decoder_ref) { - av_free(decoder); - ret = AVERROR(ENOMEM); - goto fail; - } + rk_context->decoder = decoder; av_log(avctx, AV_LOG_DEBUG, "Initializing RKMPP decoder.\n"); @@ -269,7 +262,7 @@ fail: static int rkmpp_send_packet(AVCodecContext *avctx, const AVPacket *avpkt) { RKMPPDecodeContext *rk_context = avctx->priv_data; - RKMPPDecoder *decoder = (RKMPPDecoder *)rk_context->decoder_ref->data; + RKMPPDecoder *decoder = rk_context->decoder; int ret; // handle EOF @@ -311,7 +304,7 @@ static void rkmpp_release_frame(void *opaque, uint8_t *data) RKMPPFrameContext *framecontext = (RKMPPFrameContext *)framecontextref->data; mpp_frame_deinit(&framecontext->frame); - av_buffer_unref(&framecontext->decoder_ref); + ff_refstruct_unref(&framecontext->decoder_ref); av_buffer_unref(&framecontextref); av_free(desc); @@ -320,7 +313,7 @@ static void rkmpp_release_frame(void *opaque, uint8_t *data) static int rkmpp_retrieve_frame(AVCodecContext *avctx, AVFrame *frame) { RKMPPDecodeContext *rk_context = avctx->priv_data; - RKMPPDecoder *decoder = (RKMPPDecoder *)rk_context->decoder_ref->data; + RKMPPDecoder *decoder = rk_context->decoder; RKMPPFrameContext *framecontext = NULL; AVBufferRef *framecontextref = NULL; int ret; @@ -448,11 +441,6 @@ static int rkmpp_retrieve_frame(AVCodecContext *avctx, AVFrame *frame) // MPP decoder needs to be closed only when all frames have been released. framecontext = (RKMPPFrameContext *)framecontextref->data; - framecontext->decoder_ref = av_buffer_ref(rk_context->decoder_ref); - if (!framecontext->decoder_ref) { - ret = AVERROR(ENOMEM); - goto fail; - } framecontext->frame = mppframe; frame->data[0] = (uint8_t *)desc; @@ -463,6 +451,7 @@ static int rkmpp_retrieve_frame(AVCodecContext *avctx, AVFrame *frame) ret = AVERROR(ENOMEM); goto fail; } + framecontext->decoder_ref = ff_refstruct_ref(rk_context->decoder); frame->hw_frames_ctx = av_buffer_ref(decoder->frames_ref); if (!frame->hw_frames_ctx) { @@ -487,9 +476,6 @@ fail: if (mppframe) mpp_frame_deinit(&mppframe); - if (framecontext) - av_buffer_unref(&framecontext->decoder_ref); - if (framecontextref) av_buffer_unref(&framecontextref); @@ -502,7 +488,7 @@ fail: static int rkmpp_receive_frame(AVCodecContext *avctx, AVFrame *frame) { RKMPPDecodeContext *rk_context = avctx->priv_data; - RKMPPDecoder *decoder = (RKMPPDecoder *)rk_context->decoder_ref->data; + RKMPPDecoder *decoder = rk_context->decoder; int ret = MPP_NOK; AVPacket pkt = {0}; RK_S32 usedslots, freeslots; @@ -542,7 +528,7 @@ static int rkmpp_receive_frame(AVCodecContext *avctx, AVFrame *frame) static void rkmpp_flush(AVCodecContext *avctx) { RKMPPDecodeContext *rk_context = avctx->priv_data; - RKMPPDecoder *decoder = (RKMPPDecoder *)rk_context->decoder_ref->data; + RKMPPDecoder *decoder = rk_context->decoder; int ret = MPP_NOK; av_log(avctx, AV_LOG_DEBUG, "Flush.\n"); From patchwork Mon Oct 2 18:13:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 44105 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1204:b0:15d:8365:d4b8 with SMTP id v4csp1574574pzf; Mon, 2 Oct 2023 11:13:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGrRx9qmzPxHunHc/5xxLrxKbwHz038C4yMbwN0SlhyB+yyDtlLHRbWYZRRGS16Mepr6d+t X-Received: by 2002:a17:906:530b:b0:9a9:9c6c:c4ef with SMTP id h11-20020a170906530b00b009a99c6cc4efmr11294275ejo.23.1696270391403; Mon, 02 Oct 2023 11:13:11 -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 u22-20020a1709064ad600b00997c7157a03si19009039ejt.642.2023.10.02.11.13.10; Mon, 02 Oct 2023 11:13:11 -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="gDdE+/Y8"; 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 429D868CC50; Mon, 2 Oct 2023 21:12:53 +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-db3eur04olkn2057.outbound.protection.outlook.com [40.92.74.57]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1342B68CC11 for ; Mon, 2 Oct 2023 21:12:51 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YQjDwlZGPUDMkAe9jhhpjwThFOmHe1itn5TBVfCRTbGrrQLneCruPctSESljovsTS+duJvW3IteCa+Kh+C+y0hQX+klOIabAC50OBEGwwpw4Eer2ub5SmJPKcOb3NypFg9A4QN+5V+gNg/adLn1BNfsXqAr2KFc7PYdOP1tMcXCFFvm/tpvmnRczA7Sccs+1QLPWxr5VfRk5I2HTdCMX7xVcCSdoVhzIU44ze+F+QYGvKK5l1Qn4jziAzdPWUCFgsU/bZluzo5xCn2ww3qIR9j1XKWRXMlH6BLA97EXvyUaBE1NNF2sNHgcK0T+/X7X14P0vPC57Pb0BaQLFFNi5Fw== 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=7ZZy0ePMHTBKhTnUf1MoL0sX0RJtMXtTzOAztJrlNeE=; b=eVHdzChQbvEAfNfoO73DI3QyqNWc6EY678nc97/3Zw+L8FuiFsQsbJm50vdJuf33agLd18vTcqfvOl/XlcDS4MMMoPOZKXkCNw0Q7REKxfoTHnAkbfHCB7clU6DX/A2CM7m12RRL7a7F9TZ6w5r6kIN/sfW4GTFOnLu5GIcMN5Z0au82qiqgiT3sCWV88KBuyOFtn3eDPlRvyby6YgLuUJppKXsM57GML5TQ5oTVHgRdX2hBXeazA9J/ng3zwE3imZFJHS4ujh4NaVTsCInkLoEP7HZjCCbqRg8ZcqJfYbOKPZqeEqaNoY/XHgRFHtPjaj3hCRDNet6NNjh0tToKtg== 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=7ZZy0ePMHTBKhTnUf1MoL0sX0RJtMXtTzOAztJrlNeE=; b=gDdE+/Y8WOf1BDuDrxsjavkRfDD0fZryThU+RM9CfOs3i2btN0mvNPqZMyVJnoIqVVVihbWxRNvQu/mVx1oimxfFPDj2OUhaTgKgKYLUlCCOAu8ZtP+GIC6Uk1evN7Ftupd0wSu9MO4wU4v1n3BLxDpmsfAE4j4GIt7rb8dO1ZPBmD/ODsR6BZfHip3vh1f9eYkf4nUtMGrID+1tui6XsCh9LIlkWBcDVdCLMB1zNZi3UUuuUPWe9u7l7TscjHCHfOuxugkRPlH+erij6o0d+d9oKczs6cGoWH2nuTsmQwv/NAMWnbt5c67G1xctR6lBIMRXz/9vAZKAVgLdFZA9iw== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AS8P250MB0218.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:379::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.27; Mon, 2 Oct 2023 18:12:47 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Mon, 2 Oct 2023 18:12:47 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 2 Oct 2023 20:13:36 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [fElPifHaNBjx3rL/cMNcycg0hsClcrF7] X-ClientProxiedBy: ZR0P278CA0087.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::20) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20231002181338.1030463-5-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AS8P250MB0218:EE_ X-MS-Office365-Filtering-Correlation-Id: 170ec70c-b993-4625-4016-08dbc3732e8b X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Cos/6ow5haDVRTNGba1x7jdDQgSuYP0fAhJfWlK78fv70pc1SpjJQB8s0sf5IMQP3LcManKKvlyCXXmAZFbjnxUMfHktmv7cQps2K/bTTGvdkpSUKTGSEQfmaYoAGCevpo9vq7LjxgMR1WNM+RyTC/jCWE+EqTtpGG6ryVRNtT5FNUMCjnKiWRX7xyP+RqDx5lD93AIPZx8nJaU4lO7LNKvWeBsMGP0Hn1N4BS105FSp9Z47lEonhYTDmARrsxVxJ7L2CEyAzvjdBbWnPMXZXCoXtHE3i8997Pl7sLmSRK8wNusSU3SpkrSchU0Yt7nNr2dItF2PmBg8ea3T5cbT//lzXaSGZeUbvSSnlycvjvTviLIA6iYofaZ89wqY6B2BHNZgZzXjCnet1hLRL/T+CAzYhOB4///4bNJG9rkO+MDG1AxwMomHT8nQ85XQvSqbYNay4ECvddUdLOFIsxZrq4xRYJWsHcDWhCR04i37rkKDX43QidtZ3BWeN9OrgscKrRX/5nQTs0eSFPHdDZdIW42wQAQJT8YrpH6t2KB/uXL1VRSgTWjX6Bf00gBlFXrGOY9haPJvuQT3zj/Dt++gXVuyNxNAHDV/s4pcs3VQ/rsscxpERJLuEE94Cdv3/VU/ X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Why+WHoSprhDnaNidplMSRPnDQDN7x1pCZmAm2I+W6vqyaAWur83RbjIUSnrRWLjr7kLmCScjvLlgOlVSmY6jJeXDC+EmG8VZn4fOFylMVFNxd40PQB31Z6ZxlXmvQ9bSKK1UXkKWvtAelLbCiA7yWAWLLftkobO9O45dfCpxs89lpueIHcZWpeVJZJNL9ZxIZRQJercB2QoaYTiy/okrXm0G4WgH2jrBOAO1D/axNko4rQFwibkNIcxF2fN/adAbZVfAztUNecVsynyQYPn4kaAzDx86cBUgm3Z9yutKd4nzFgM0+UoUovrUrMn6iqJpM0QT4FsXXCb9Pn5DH+DoKhIHGe87dyPA5UeDhWiEFPsteDUZAuNV/E9p1RsnogSNRBXqG0dny1coicaKw4qrRFddg0BOrFaVK7obRVtzv4fN+US2Ks08yOHFAfTxEeiYMSbhk1WKaac19EMCd20pS4RLw4ZDBmFVYdQqR0V2aiAT4tFj1Z1yITLXccpDzBZ3/Ha4zOjsd396rKeT1sgrLMGL0ZhPbQ4QFGHBet0uvzSKiPw3RaFXEF0CbeSA1opR7MGcwtPHe4LL2dmaCE4OATmGkm3b+IdYrknJQj4c6e65delyhsHu7i2vjeu9T/mGNoN/ttKI7ZDgHS5IltERLUfv8LdbAt4a0j+wF2gI+2MHHoX3T8fkDLeChOBjZ3aui7p89S7lgWfpNUiRdMheFD/lJTgoEGPtV9cK13nv/wmW4k/e6yTD83EDoSrZWj9zLjgKTZG6URSgkacZfV2nIYGXcTTkvVnLqzXEThzyIIZkJv+aWmWlFKJsfln8+LfENnSbNnP5VPCom87X5RLwOgvZlvBqZisZMm/MfTRirHeWtPoDaILxZnf2pRx2dsI0CG/Mz1nHp/pt7dkqoCEbG3ouULJdIb5YX3mzqDMNnj07d0bxAojKY+PVo/e5626jhQoF62q5jGelw5/dCxekDa8VGY6IB/k/GqGm+NzxVPy0IakNyVlnORTo62lPr7ubQlO6oA9YQH71ySxDBa6pTh+oGCwkw5SW6nKc2z64FghhiOZ78Eq06QmlTBbtfoTJOwz9Cs3GProzGQ2M/VGKbVeqJkdr/igQ9OZsA3c1xMxFl+o7l+Cxu1vn139UW/hkyn330mTiFFR9Kzp53mfmiAnam0LNF7egk1tEZyf0PV4m8SGRufuJB2NOhcwWockGrmIrFV+WfO0XDqotpE3PbWaTay4E7CJwEorEIOtCVZsxkpnYRpnGrg4pS7r8QeR X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 170ec70c-b993-4625-4016-08dbc3732e8b X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2023 18:12:47.5179 (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: AS8P250MB0218 Subject: [FFmpeg-devel] [PATCH 47/49] avcodec/rkmppdec: Allocate AVDRMFrameDescriptor and frame ctx jointly 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: u4dHZELSGcxZ Avoids an allocation and therefore one error path. Signed-off-by: Andreas Rheinhardt --- libavcodec/rkmppdec.c | 39 +++++++++++++++------------------------ 1 file changed, 15 insertions(+), 24 deletions(-) diff --git a/libavcodec/rkmppdec.c b/libavcodec/rkmppdec.c index dd0b9c5a4d..5998b6edef 100644 --- a/libavcodec/rkmppdec.c +++ b/libavcodec/rkmppdec.c @@ -300,12 +300,10 @@ static int rkmpp_send_packet(AVCodecContext *avctx, const AVPacket *avpkt) static void rkmpp_release_frame(void *opaque, uint8_t *data) { AVDRMFrameDescriptor *desc = (AVDRMFrameDescriptor *)data; - AVBufferRef *framecontextref = (AVBufferRef *)opaque; - RKMPPFrameContext *framecontext = (RKMPPFrameContext *)framecontextref->data; + RKMPPFrameContext *framecontext = opaque; mpp_frame_deinit(&framecontext->frame); ff_refstruct_unref(&framecontext->decoder_ref); - av_buffer_unref(&framecontextref); av_free(desc); } @@ -314,12 +312,9 @@ static int rkmpp_retrieve_frame(AVCodecContext *avctx, AVFrame *frame) { RKMPPDecodeContext *rk_context = avctx->priv_data; RKMPPDecoder *decoder = rk_context->decoder; - RKMPPFrameContext *framecontext = NULL; - AVBufferRef *framecontextref = NULL; int ret; MppFrame mppframe = NULL; MppBuffer buffer = NULL; - AVDRMFrameDescriptor *desc = NULL; AVDRMLayerDescriptor *layer = NULL; int mode; MppFrameFormat mppformat; @@ -408,11 +403,21 @@ static int rkmpp_retrieve_frame(AVCodecContext *avctx, AVFrame *frame) // now setup the frame buffer info buffer = mpp_frame_get_buffer(mppframe); if (buffer) { - desc = av_mallocz(sizeof(AVDRMFrameDescriptor)); - if (!desc) { + RKMPPFrameContext *framecontext; + AVDRMFrameDescriptor *desc; + // We allocate the descriptor in buf[0] jointly with a structure + // that will allow to hold additional information + // for properly releasing MPP frames and decoder. + struct { + AVDRMFrameDescriptor desc; + RKMPPFrameContext framecontext; + } *combined_desc = av_mallocz(sizeof(*combined_desc)); + if (!combined_desc) { ret = AVERROR(ENOMEM); goto fail; } + desc = &combined_desc->desc; + framecontext = &combined_desc->framecontext; desc->nb_objects = 1; desc->objects[0].fd = mpp_buffer_get_fd(buffer); @@ -431,23 +436,15 @@ static int rkmpp_retrieve_frame(AVCodecContext *avctx, AVFrame *frame) layer->planes[1].offset = layer->planes[0].pitch * mpp_frame_get_ver_stride(mppframe); layer->planes[1].pitch = layer->planes[0].pitch; - // we also allocate a struct in buf[0] that will allow to hold additionnal information - // for releasing properly MPP frames and decoder - framecontextref = av_buffer_allocz(sizeof(*framecontext)); - if (!framecontextref) { - ret = AVERROR(ENOMEM); - goto fail; - } - // MPP decoder needs to be closed only when all frames have been released. - framecontext = (RKMPPFrameContext *)framecontextref->data; framecontext->frame = mppframe; frame->data[0] = (uint8_t *)desc; frame->buf[0] = av_buffer_create((uint8_t *)desc, sizeof(*desc), rkmpp_release_frame, - framecontextref, AV_BUFFER_FLAG_READONLY); + framecontext, AV_BUFFER_FLAG_READONLY); if (!frame->buf[0]) { + av_free(combined_desc); ret = AVERROR(ENOMEM); goto fail; } @@ -476,12 +473,6 @@ fail: if (mppframe) mpp_frame_deinit(&mppframe); - if (framecontextref) - av_buffer_unref(&framecontextref); - - if (desc) - av_free(desc); - return ret; } From patchwork Mon Oct 2 18:13:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 44106 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1204:b0:15d:8365:d4b8 with SMTP id v4csp1574706pzf; Mon, 2 Oct 2023 11:13:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEKCVtJg9Hch77LledqapYhSNwGcxlx3u/R9LlEzVf2WZDSyPLxm/bGeH4HWlOzpGqNoSIi X-Received: by 2002:a05:6402:1859:b0:530:8a17:39e0 with SMTP id v25-20020a056402185900b005308a1739e0mr11037011edy.13.1696270406530; Mon, 02 Oct 2023 11:13:26 -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 o24-20020a056402039800b005312692eebfsi13195644edv.150.2023.10.02.11.13.19; Mon, 02 Oct 2023 11:13:26 -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=E1D7+hzP; 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 5150F68CCA0; Mon, 2 Oct 2023 21:12:54 +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-db3eur04olkn2057.outbound.protection.outlook.com [40.92.74.57]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 488DB68CC11 for ; Mon, 2 Oct 2023 21:12:52 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Pj8ePjfXtpfVUS18B7smksKIuUyEsJaptxQAUehydnyB0Bz1+3kZsky36I4KkNB1A13Flj8whIi4/Ac5wG4ErtbdXSTEdVLigmDJ21PMY+oM6UrhS+Db7y0AxrpIG++Zybxn3IBatAGpi9SEz4uq8naR1Hwqz3QEk6E+i/Hh3rkDybpkozSkl4BM6PdbepoqYM/HnTxCCi8ycLSa2j9ntY4OVzYA9aQiwG7jcMcs2BDHVyiH6xRSIdsgVN4hNFZ1dNhtgKOkSsakWSaPo7nmN4mRZ/eoKZho8XuDfFCUvoHHe5BDSwbx58cjPXjTmIJ0VTG3lZz6Uu0b9IgkAkrrDw== 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=zFssATrAQwtdFdDeFxoDt2233ZJt7hm9j26gmVEc7Dg=; b=e0YCBDGPsmbi0bn6BVahL8ts5+kuDvr2BPRNvnVWJo2asCAXtuXg5doHrNOCyXl4+D8n8hwEGG9+Cb+rJloPUuQ7QmMWT+/76vw2VebJnliLIXg1r99TKTg58UBgkhOsrbu2MysiJA6bqzMLOKIZ271hjrNmNa2RUxq8BM6pr+U3P3jUdGBBnnRIMSBFL+oeQIXX1af+85mxN2Rpc731XRIQdkG89/euCzMZVC0j7fFmZ6alGEbHnsXNSoLvYORLcIPv9UcMReMmd0uZCcIoYCGvmt2CJPWIG9ais10AzKNelrzVyi4ayxxT27HbM3U7CahtYSthaOYZnbDCO6ReqQ== 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=zFssATrAQwtdFdDeFxoDt2233ZJt7hm9j26gmVEc7Dg=; b=E1D7+hzP9qszKHhQMxYzev9SO8dILwbIuK5Jl1Egt+h76s8jk9gPTkF2a4B3Dl2OygPyRgb0bCbUri3vBZwOq5y33dq8XqH0OeX/OkPkfukz+gotafYY0EtyAvyLjB5RO+kI7g/PJ00aPXYZdYpyzlnPSDkZIt+S5PPwtXkRHLnkyXg6+1Y0AeA8t2xTcJGvoIFomF6CPuLZ1z5SfKxeg/Q5rFf59OPtJPmJXgViF7Kci2nShN63Y3+d5Abh2Kfos6aJaKqtH968lmjjLUbsy/XApy6cruLPR0B+DCki+w19k5p0SOOK2o5qhhpan1rUoZU2mQkua0j960zbCldh5w== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AS8P250MB0218.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:379::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.27; Mon, 2 Oct 2023 18:12:49 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Mon, 2 Oct 2023 18:12:49 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 2 Oct 2023 20:13:37 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [8ZucKfMuGm8JFqqGlVB3tY51/0DWyNjE] X-ClientProxiedBy: ZR0P278CA0087.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::20) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20231002181338.1030463-6-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AS8P250MB0218:EE_ X-MS-Office365-Filtering-Correlation-Id: 066a5e3d-38d8-460e-f054-08dbc3732f68 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fV2IpUPvUqXYvm/j1tFEaGZRB7w2REUQhW2xYUHAN5X6Trzxzc02KPPMqpjkMNXRpdr3kpSgKTboNXicTKYqhxQr+WwlIn9Giq812+bW5gRbFqtVPaAPzspkx2flzYaHZLBTgH9REIBkYj2jCuy9AbMw+yVzmCThumKvSy6rPXxZ0rB5zDuv1WeNTr7gcIj53sBan08lno8BHWdMwpfLSJlAl9ZZ9dB84tZV8+qlF+VUZafbAmXcrO0LBfHzR8igbVmcJB3XCy19bhAg1RFMv9xtnN47C2+1G5PDgqpaOn4hWmsQp7qErslvuLDNj1XYAtsqBdiCW5JG0L6qN8jLvpaEvIgEfRjh7D66NgovMbfLRR2ciIi4N5bImT/iWCW1+ae41kwq/nTFffAeEDrgihFUb65P1d8gRZF7sAG8qBX1ejd7Kb9CwbAxRV8XI8+H0EFPmF1R7qWwjivLOIN0xgBWM8ui03VGflQRs05AsdD8nmXKnfuD/BjVrgtyAyxoJqwto63gaQYy0jdKXXj7zsdC+P/PYxhnPlTffFjLGT2QbFxbqoV5E4cb+gCiL8IvfYcIUfnErbOARI/baC5oJQxBZeSxH5R0Us09DWcK4BaIryVn5yA7PNRok54lSAdb X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: RBvVBBVWZdokj5FZZdAI+dAVZ7UNM7/l51Z4dPSpM36mbVwQZ6FfPPNhQYz1avIOS//wQeKJpjIoNlVMqon/7dFcM3HYe1rImNrQ/PHlJ/PaZAYwasXGVe1leV7dTZFudJxPfHnzWEj8V5Mr7iajP8O4O/Ta00jVb9umgtTgT9G7nDIRgXAFpDBNGipdjDw6hGKhgWyC605Tfg7ZIYNdtb5TjmbVfc8Jl+eWGMaxleO1/yIgAgBVA3qAerhTDCX4+UwSpaKRpmjnHZwCz3KsGeCJ3RYwJcFinPAsIJDpV6A4/qQVF8AziYzQKoQY6wX3XnQiKfNBwW2Gx9maMvuZU3pzNLte+7x9ooF4i+LvgQc5uIjXRlIDNwcLU2IF7fPCNlskPrpq0SiMjsmQVpEPOShgvzll4H2TlyMKPGg6LE+vKNKYzTDzFuO26DtPbCqNDXoK2ictKyYlB88jFIyVAUD3EfiLGHwNw63vljIxCgx0g3pGmMlES/OwYcmacdDhYcEfZk2gIuxcbAbZ/KsHYnyptNdBIpF0e1dPxdt3fSSKHRxtnEfhdPkjmTR7lkfU5a53x1EGPsuVVx6bs6ynMGdLQODmAEpdyAG9oQ7Hlk9xB8P5X91G9lrUFfmSmyFA9Vy0utNnQZ0lKPDdlfTlOQV9Xk/mCa9OezDx7/rPUVT+yY7lAZFSrdp2WaRJjyi+hjo6i7UMkX7IWdQCX+WWOupO/XL5ZA7my7yxSr1mU8ncLaijaPE5/nJMcoSEzegp3PIr8aGg6Tu/nIi8U27YEYkKR8yG+PIrBiSQ059YSrmqFl6TaAqbCkvAGn8VPYQnwT3JY4jwnZqfds+0rkUCeRo1ljAeaBNuDRWCNGWoZ0Y8hK69bwrWQMXMT2YJ+/oX6xAkGzrdLjVAUFTeYvdrHeHSzfTMxvd81ZvobjGkkz5Zqwvcnv/fSlgelHEN+VzSUqMQi5fw6eQokhowSWQlnl4dhYy6HZ7Jung/VMMk6WRGjDiIfl02+2735aPrY4M1ODpxR397TB6q0D7cE1+gfRvwdT6yjFE7eyr/W9U1Yq+dh75Tnl3/GW46XbzhKGl0zZ+rvN2wPofU/5/SsFzIMuvUvmIRK/WP4yBicck/yX/3v8OaV0+LMiyfTlB53GEFv7AONPRyGwnq3Ye8sDnur6y4rORQKG5MIfOvynHqjUgXRYRFvSPJS1qrsyP4XRo77MKziQ+FSj69BNh6Adwr2iJLPZAefpbPajTZ37tdJS0ZWM9iPreqRz5mTxbTVrCo X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 066a5e3d-38d8-460e-f054-08dbc3732f68 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2023 18:12:49.0617 (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: AS8P250MB0218 Subject: [FFmpeg-devel] [PATCH 48/49] avcodec/v4l2_m2m: Remove redundant av_frame_unref() 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: b2K+BA/2NjHO This frame will be freed in the next line. Signed-off-by: Andreas Rheinhardt --- libavcodec/v4l2_m2m.c | 1 - 1 file changed, 1 deletion(-) diff --git a/libavcodec/v4l2_m2m.c b/libavcodec/v4l2_m2m.c index 602efb7a16..bac3eb0588 100644 --- a/libavcodec/v4l2_m2m.c +++ b/libavcodec/v4l2_m2m.c @@ -255,7 +255,6 @@ static void v4l2_m2m_destroy_context(void *opaque, uint8_t *context) if (s->fd >= 0) close(s->fd); - av_frame_unref(s->frame); av_frame_free(&s->frame); av_packet_unref(&s->buf_pkt); From patchwork Mon Oct 2 18:13:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 44108 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1204:b0:15d:8365:d4b8 with SMTP id v4csp1574839pzf; Mon, 2 Oct 2023 11:13:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHFc4pF5cznNiiPOZh6j9zmMzlvCIihS+V5MBO6Tr25KwxOULcTV6/1CAIXFyChVClOrbYV X-Received: by 2002:aa7:c582:0:b0:532:c08a:eac0 with SMTP id g2-20020aa7c582000000b00532c08aeac0mr10057974edq.26.1696270422158; Mon, 02 Oct 2023 11:13:42 -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 q18-20020aa7d452000000b0053119ab8821si13114628edr.293.2023.10.02.11.13.37; Mon, 02 Oct 2023 11:13:42 -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=vN+ckseU; 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 6E9C568CCA2; Mon, 2 Oct 2023 21:12:56 +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-db3eur04olkn2057.outbound.protection.outlook.com [40.92.74.57]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A0A1568CC56 for ; Mon, 2 Oct 2023 21:12:52 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IrTK0NwFTcow+Bw7muKIDAQ19zuaG0n54KGE6MocbWzg4kXPU0xh4MDaadcmGJx68HGflZGqaax4UiVeky3IY/rGmH/5mgHjBxVcv3kIkg04RBUzcmhauJV6kJ4OC9aMsphK32Z95imjQMlcA3sGt58E74C+1ltfQ7jk+/Zah02wui7KdwUiVjrgZTwTClaw6Vd/APbXW+9ph/CR+U+Od7Z0/ybz7tKDXWEbGJMo5HiGVcpUn2Y0TnVWraMNjNUsNbp9Q/aiBBH1znofbJIZRqRSA6JMLwGJVDAhDgTZsUacmnXBMp4f+fAN3TlGeu6ZHXqEYFJa3z5wyifZigFyMg== 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=C/rTKzk/NOaUOn/K8f5OCZj/Msyz1HPunecJLj3pMKg=; b=Eic27uqxOUlXcrHS/F9HQFwNpVQIlE0qEc2WBOdRHLa7kiaKdRnLn4Eh12nKeIPP4n3k44NGd7svL6/I2TaYy0Q7eXB7W9OnYBNJibFQ29PV5kvMyMwSK/ofdetu5r+28SoSAidTzyIhQ/ztDnVz0Oyrz1lE5GCMc7++iSzfrtohypKqqPJOWU7oNj0MaQu9FksXFasSCFzsL1E0k/C5FHj9cTodl//Ei1v2SEqmWi30sNAtiB5ceg4LsoH2ZdLMisy52pIebUACf/1D0k/DJMlnvhyR4KBSfKmn1ZqELBpJAKvSa5YagzB1Ip27rTwL6BvbKsCm4yoT8WPIA0AiZA== 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=C/rTKzk/NOaUOn/K8f5OCZj/Msyz1HPunecJLj3pMKg=; b=vN+ckseUpf4S4tMc9Jls8Ba4wSElaQ5E8bDGshTE5RMVfOQs8+EzFQ71mCvNaCmSw/P46OBTAk61UMn+yqPeZyTPkAgjd6iLgmwzHyY4Vb305aZjGpg75e9o6qK30eweCIWHPj6n3a1cbfpSZbVa3mQDdd8l9xGjooVv4NrFnu7OlxwzQ0TQbNWY1bcOn5VD04qAqYmQaH7pZZwtEIWarQyGuye06E7neyv6wH2tID+VdUE3hyiWpQJIDwvkxXIwq/q2m3aIfKdEovG1x98E0SygkGTtMSppR6TTyLRqlXhGNDTxkskoSDjgJ21BdanfWPfIfQcgTa69OWSLKXAOtQ== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AS8P250MB0218.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:379::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6792.27; Mon, 2 Oct 2023 18:12:51 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::5e01:aea5:d3a8:cafa%3]) with mapi id 15.20.6792.026; Mon, 2 Oct 2023 18:12:51 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Mon, 2 Oct 2023 20:13:38 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [pkhNUR/1o+wN7v9xJ9iCKsrGCcrmf+ro] X-ClientProxiedBy: ZR0P278CA0087.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::20) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20231002181338.1030463-7-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AS8P250MB0218:EE_ X-MS-Office365-Filtering-Correlation-Id: 03abf2c4-6dfc-401c-0a00-08dbc37330b9 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FBLvqj76kt34eWAh6ce8d84mmyy3Vpcqf3JhcgJdXVHBPXIwzXmqvh31EBp2nG4XBvrUmMxlIsDcTcyVMJi4O5RVfajQKU9v6bP4MbCWkuGyTmLB6YScVH3MuDt8PDcrY01J4rmCdcPLvmg1wzSz7JvLJk32tWQ3WtwaFhbb8p6/ixvTIfaGRWAAtdcRDXdmEJ3ldSct90eVZVshV3mjS3dNiEl9X+Yr1yhGto9LjqgZIRO2QrIJ5bWTTCyk2MbvtqBf5e7yhGyQ3v4q6eUsqFFeitKtaTbAasUnlKds/wxyq0UnAre1rHE2J46aC7bJeAcAT3lhYi/pzrDyYzn9DQ8Vq593goMalqjPQ+1Dsv/y4gnloQtMt7AbJ/7ag4Ah65jXrrwRdz9wNa0HT9YKpRWq1M9MNrwJ5aoXe/KQa7w9ClbZrWmzolQ5M4OwcMBPj+38ldOXxJOORNDIZONY3ppbMPoFvVHW5rINmLSf3EhgI44DYyrSmjza+zNAEAqpC2IB5TmdurtvPbSwnklBKkiRPAkzTOlGhMmrHvo2iAUjikustVj4fULtgcoBHDQcOlr3XdH7oBknHcLaNJI3wX9JYiOaq6JVJ7KwfmJ8m9nRMPvKJyn1YIYwt+UxYi4U X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: i3aNAbCfGzxBBAKPk4Hn1qXCPiZdkhnFUtRxLCWlaviU7/SBz60zkseM0bB8lJa2WCkh6Ln2HDl+FDYYohtjMS8tcx3S2m76Vlz+1+U3K5xwLtTBupcsTY4BnX3fPy03lqlWBq6W8jpLCDjRWzFWS7HVf8ZxUzE01xhBn8p4JWcJ/RlFNI22juicyCTSqT6kq2azSbPEwe8UIVuO7gGs/4Pd7S6SWDhW6N3OWx/Ul+HFfzV1ZLlT8jhts3L+IWeAUKbFCkGeA1yRbCFJ+7P/5hLLT07ZY2z5XNN16QpIYFO9Ea917UHv1irEWAafo6URAgzoWBKo9zSBRXGkjlkciVBwfNL20gSDm1b7Xg5wAc8DP7vtP33IvJ8X0XM4gPRtcP2CYi0CNK07BILa1rFQHozwTdbve1cIJf6g/r1BHfuIXxIOCF7tpLufBv3RVbvJvElfLJBoAyHF3R7dVOYpR/MZq3O6LxDKJlFHPfi1vdFs7LW1lJB+gPMQImb73MMEObsmmjwJ65uyc/C/pw4Y6vuATkrmZa1OtjnoFyDv4vY4UieEUIrYt3MdkoKtDctsUDh1E/cBwNbbbXEti+1mmXV3wbzJQ+deRA0M4bV51/w8s2Aaptuq/BR1VgeHOJXVF3eB/OquHmXuPh86PTJBXAPdHypED3i/FdCRBNzj9TZLx1+H4c+UjerMjmevvrpH6sOvXaM5kkhnWPRzraHg23nTfClHD/cTQRLCvZXuru/ZB1aSsTo+7MOFLB92mp3pTj78/Rum1VLeKHB5U+qpvgrB4C6Ba+gL60dQ/aQ3QNwXHUieirYqncFhOGejQSENnR9KFG4oDmd7IkhotqwsjRE0WpVRJYnyyrGA7GNMtGa6hVyl/k4FcJsLo5XrvAKnoZ89OjuyRvJr4nZAaIfYWAeCrj4TMuDgPjWjxZZz6XMHQ2n/Iw2aKitGEL0klNzMc0tg39mIoZPJeGiIQd3CdlHmo9SijT9vP9nCvAdTqglOMbdN+feS1o033zWZ2RzHH6VGB9+DGlSjoqW/+dTkol3zfZ+C2h0We7vC6/QYpQlJI8U/jcQLRWh/GwC8ivUVVy3J1ZVnM2EcUE45T8nLasb+QCR4ojIziJGzQ1d/OClLZt3hcW/WYyk7tdaSArrpfbDcQpdCPH49gwdI2TX4VyAMF7GPBGa2/GzkFLceL1aP4fsWogKiLD7knUjPf6YVLH+3nZ3OJcOOf25LbS/ZEXPXB/Uix7JEazQDVvj5TTUw7tHo+iOHq/n4mIi7ayf3 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 03abf2c4-6dfc-401c-0a00-08dbc37330b9 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Oct 2023 18:12:51.2167 (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: AS8P250MB0218 Subject: [FFmpeg-devel] [PATCH 49/49] avcodec/v4l2_(m2m|buffers): Use RefStruct API for context references 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: f4RVvSc87JjA Avoids allocations and therefore error checks; also avoids indirections and allows to remove the boilerplate code for creating an object with a dedicated free function. Signed-off-by: Andreas Rheinhardt --- libavcodec/v4l2_buffers.c | 7 +++---- libavcodec/v4l2_buffers.h | 6 +++--- libavcodec/v4l2_m2m.c | 25 +++++++++---------------- libavcodec/v4l2_m2m.h | 5 ++--- 4 files changed, 17 insertions(+), 26 deletions(-) diff --git a/libavcodec/v4l2_buffers.c b/libavcodec/v4l2_buffers.c index 2277135699..23474ee143 100644 --- a/libavcodec/v4l2_buffers.c +++ b/libavcodec/v4l2_buffers.c @@ -29,6 +29,7 @@ #include #include "libavcodec/avcodec.h" #include "libavutil/pixdesc.h" +#include "refstruct.h" #include "v4l2_context.h" #include "v4l2_buffers.h" #include "v4l2_m2m.h" @@ -229,7 +230,7 @@ static void v4l2_free_buffer(void *opaque, uint8_t *unused) ff_v4l2_buffer_enqueue(avbuf); } - av_buffer_unref(&avbuf->context_ref); + ff_refstruct_unref(&avbuf->context_ref); } } @@ -240,9 +241,7 @@ static int v4l2_buf_increase_ref(V4L2Buffer *in) if (in->context_ref) atomic_fetch_add(&in->context_refcount, 1); else { - in->context_ref = av_buffer_ref(s->self_ref); - if (!in->context_ref) - return AVERROR(ENOMEM); + in->context_ref = ff_refstruct_ref(s->self_ref); in->context_refcount = 1; } diff --git a/libavcodec/v4l2_buffers.h b/libavcodec/v4l2_buffers.h index 3d2ff1b9a5..e35b161309 100644 --- a/libavcodec/v4l2_buffers.h +++ b/libavcodec/v4l2_buffers.h @@ -28,7 +28,6 @@ #include #include -#include "libavutil/buffer.h" #include "libavutil/frame.h" #include "packet.h" @@ -46,8 +45,9 @@ typedef struct V4L2Buffer { struct V4L2Context *context; /* This object is refcounted per-plane, so we need to keep track - * of how many context-refs we are holding. */ - AVBufferRef *context_ref; + * of how many context-refs we are holding. + * This pointer is a RefStruct reference. */ + const struct V4L2m2mContext *context_ref; atomic_uint context_refcount; /* keep track of the mmap address and mmap length */ diff --git a/libavcodec/v4l2_m2m.c b/libavcodec/v4l2_m2m.c index bac3eb0588..007e725b70 100644 --- a/libavcodec/v4l2_m2m.c +++ b/libavcodec/v4l2_m2m.c @@ -31,6 +31,7 @@ #include "libavutil/pixdesc.h" #include "libavutil/imgutils.h" #include "libavutil/pixfmt.h" +#include "refstruct.h" #include "v4l2_context.h" #include "v4l2_fmt.h" #include "v4l2_m2m.h" @@ -246,9 +247,9 @@ int ff_v4l2_m2m_codec_reinit(V4L2m2mContext *s) return 0; } -static void v4l2_m2m_destroy_context(void *opaque, uint8_t *context) +static void v4l2_m2m_destroy_context(FFRefStructOpaque unused, void *context) { - V4L2m2mContext *s = (V4L2m2mContext*)context; + V4L2m2mContext *s = context; ff_v4l2_context_release(&s->capture); sem_destroy(&s->refsync); @@ -257,8 +258,6 @@ static void v4l2_m2m_destroy_context(void *opaque, uint8_t *context) close(s->fd); av_frame_free(&s->frame); av_packet_unref(&s->buf_pkt); - - av_free(s); } int ff_v4l2_m2m_codec_end(V4L2m2mPriv *priv) @@ -282,7 +281,7 @@ int ff_v4l2_m2m_codec_end(V4L2m2mPriv *priv) ff_v4l2_context_release(&s->output); s->self_ref = NULL; - av_buffer_unref(&priv->context_ref); + ff_refstruct_unref(&priv->context); return 0; } @@ -327,17 +326,11 @@ int ff_v4l2_m2m_codec_init(V4L2m2mPriv *priv) int ff_v4l2_m2m_create_context(V4L2m2mPriv *priv, V4L2m2mContext **s) { - *s = av_mallocz(sizeof(V4L2m2mContext)); + *s = ff_refstruct_alloc_ext(sizeof(**s), 0, NULL, + &v4l2_m2m_destroy_context); if (!*s) return AVERROR(ENOMEM); - priv->context_ref = av_buffer_create((uint8_t *) *s, sizeof(V4L2m2mContext), - &v4l2_m2m_destroy_context, NULL, 0); - if (!priv->context_ref) { - av_freep(s); - return AVERROR(ENOMEM); - } - /* assign the context */ priv->context = *s; (*s)->priv = priv; @@ -345,13 +338,13 @@ int ff_v4l2_m2m_create_context(V4L2m2mPriv *priv, V4L2m2mContext **s) /* populate it */ priv->context->capture.num_buffers = priv->num_capture_buffers; priv->context->output.num_buffers = priv->num_output_buffers; - priv->context->self_ref = priv->context_ref; + priv->context->self_ref = priv->context; priv->context->fd = -1; priv->context->frame = av_frame_alloc(); if (!priv->context->frame) { - av_buffer_unref(&priv->context_ref); - *s = NULL; /* freed when unreferencing context_ref */ + ff_refstruct_unref(&priv->context); + *s = NULL; /* freed when unreferencing context */ return AVERROR(ENOMEM); } diff --git a/libavcodec/v4l2_m2m.h b/libavcodec/v4l2_m2m.h index 04d86d7b92..4ba33dc335 100644 --- a/libavcodec/v4l2_m2m.h +++ b/libavcodec/v4l2_m2m.h @@ -62,7 +62,7 @@ typedef struct V4L2m2mContext { AVFrame *frame; /* Reference to self; only valid while codec is active. */ - AVBufferRef *self_ref; + struct V4L2m2mContext *self_ref; /* reference back to V4L2m2mPriv */ void *priv; @@ -71,8 +71,7 @@ typedef struct V4L2m2mContext { typedef struct V4L2m2mPriv { AVClass *class; - V4L2m2mContext *context; - AVBufferRef *context_ref; + V4L2m2mContext *context; ///< RefStruct reference int num_output_buffers; int num_capture_buffers;