From patchwork Thu Sep 2 15:41:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 29958 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6602:2a4a:0:0:0:0 with SMTP id k10csp400042iov; Thu, 2 Sep 2021 08:42:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxSqTfsTxLr6vFoqa0QN7cGIngoLMKxlHV/nXcgHSGxzWXNFuQj0cpSv57fs8fSffRkYoBV X-Received: by 2002:a05:6402:493:: with SMTP id k19mr4079397edv.386.1630597331012; Thu, 02 Sep 2021 08:42: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 u18si2010676ejk.196.2021.09.02.08.42.10; Thu, 02 Sep 2021 08:42: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=L0rftxi8; 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 BC06668A5F8; Thu, 2 Sep 2021 18:41:57 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-oln040092070098.outbound.protection.outlook.com [40.92.70.98]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D1C8E68A5F3 for ; Thu, 2 Sep 2021 18:41:50 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NqYNQJRz9/qVnpdcsX5ZTCsVGoAp/+AEOgvg244uujDDv+TartLsYAk6yXR93xGp45sKjKAlCzgUNxyqhH9lPj5pyOiX1PR6zRdEiOGF/+DUFtB99CuneGO4O/oPHdRBPjwFxLs6nQKVrN6ACHleI58TXpMI+Qr199yaDhiNCUhyMabh+IdsDbjm0ZyoYGgNymCMcCm2N6U1pyJbb/8Iz4V6KT5xF785VqlN/kRyYGtROIYA4EIW4YYby05bSABTD/Oqsj+Q5cwgZch/gw3s9x+DerrVOKSGyIDhdgZ/y4LHyUryiiDalUQWie/JQY8tTAdRahBLtyMLuusodD5F+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-SenderADCheck; bh=HdE7SEhy59XD2Gw02WbMYmrBid89rpgJCqXrKfKlAbM=; b=Wft4Kerr2uTz5tfZMC90JQfz0cLYj8tKdtJPkejnvaubU9ZlKWXbe7Xykb6I2AgMb07c/rtKQMLuJOXc5807KvS2jw/NydhPWI3wJMo7yWyoWZJCmfs0oTliRFtt2Pj0p9OVsdvH38Dy9YyUK/ZGQvl0O0NQf2ArKxr8qucLQ1NJNFm5hvx24qao4cZlTncckxN5knV/3yJJoCdxl36EZ41l+VHRc6/iCd4ORyoYbRoqpVISZiDvhCfVsB6BKVk/ewrvEzEk+u3L7N9ZwXrQVAlv+8zUFdiTXSKxu3cXyr5m3y4QMLvtIqBA4B/BbhU33bqHchCHbJAGHqJu8EUiXA== 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=HdE7SEhy59XD2Gw02WbMYmrBid89rpgJCqXrKfKlAbM=; b=L0rftxi8Ty8aZwRt5LWGgN4vMbf0ksDEjQQPBpu0LLAqoVSdz9U/nYYMJ5NSoK9TSQZhzUGztur7iFF3mmGuYljD/xj8RGiN5CoL67LxExfUt56uEpKKAGQhHk8QcvMzSsq3egIAyr+caGdCY43uLeyj+8/K/R1D99D9jEsaebiWUQownzv8GXe08/mrLBAWmxuMcWg3OkAA/kHV/hvp3L04Xh1FIm0fPdYTps9blZXj8ps5EiZ2wQfuuvQfmw50GKKsH0wHwsufGfSWjvhhle/irbwF4VRJzNi40mGFUgAut7OleQyw0q/LikHs2ATPrZoUo0nFZZVCXqHGAPeJLw== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM7PR03MB6532.eurprd03.prod.outlook.com (2603:10a6:20b:1c3::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4457.17; Thu, 2 Sep 2021 15:41:43 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f8b5:1ef2:89b2:f8c5]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::f8b5:1ef2:89b2:f8c5%7]) with mapi id 15.20.4457.024; Thu, 2 Sep 2021 15:41:43 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Thu, 2 Sep 2021 17:41:17 +0200 Message-ID: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: X-TMN: [fhcN/eBWkZXzvHoXwdfXg4I0+pbv5w1K] X-ClientProxiedBy: PR1P264CA0031.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:19f::18) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20210902154127.2571616-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.142.38) by PR1P264CA0031.FRAP264.PROD.OUTLOOK.COM (2603:10a6:102:19f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.20 via Frontend Transport; Thu, 2 Sep 2021 15:41:42 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0b540bd2-e0e0-4537-ed7d-08d96e2829ea X-MS-Exchange-SLBlob-MailProps: gjx25WM8ZNW7ZO6S4gJQgEvgNWj+v++jzsKubHpuI4RVruu56IovEWtHkmHehM50nDb+h2hHWrmqTkosxAE6rVJ09TLIdYjgmGFrTk/ywbprer9UrcNV/FuyEZahbWMhCW7Sfm9AK/CMWV9hNBs0slma5Tgtko8mkhCKdZHixQv9F3MNcaP1wmSvnfHn00hRI2wCvSi7zh26ezEIZVES5kn7iyObH/6jdVmOQNbSKq12RVS9YJBC/DhMKlrdIHy1AiT27Zzxjk501VDlGdP8JBreVYHuCr3JW+d119GqVXMjrgychzrhWJIQVc2HjRKVp1lLAOIXw8gQxDZKwZBqkYAfoiAWLoQEfxHYTdR7ieBfx8PwHwrNUlI2QYprWYplBlA88dc+9qc+wWHLYwdgPz016OJLz+HZCdMQhuaKqW9q8twVyVAPKmgJek+geN217bhses+MzJWto3y8iTaPu9ODWufS2byKG52k5kreZHNEKG5mkoEIZqTjztdaM/x8p5vH1VO4YFpqhDdiTEoOKZtcpjd0wi+n0Zcv21C0gnp3vni2WnKQl0e+0BCS3WpCh22nLPd0FPPwpRDKprNevXkNhCIXUxmkp116XfrlP6BOAvIVRMYDE/0YoS2Kcymg5FySHC5sRcwnYrpwX+4L+KTx39DqrRnN2kzv+XF1cC1n4SlZgPswxbpb2eYWo6v4BXnZ7CQtQPpmWUJngGfJP3NkTFIIHzIn8sUj4o6IyXU= X-MS-TrafficTypeDiagnostic: AM7PR03MB6532: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KVKOaiMGodivRP74mDel0IcpMpy4bkjnIN1efzXkZFP9skM0WLLvcQxQKr+CJYrmTjVETaiFs5X0D6wURTRJ4SPDb9SthD2NNG6IdoQQUKobTNG2+zx3kDAUK2AVY2wGvCf0jmTXeYf9JdAVMs3TNElmoiikqeTdPvtJbyygo3dZKsJxRSlblj76+vCbxzeSgJlz1acYLjgwkhz5MD6sWkdx7TkUIVR2pJwgDLRS7VgpaJzA0aunsGPA4QXIcqeblnpXtPxBxs75DA5pl4TnQVXBkFsxgZ1WkwyLuYpc2evfddlnk1UUO656dilfwPw81qY0cozqZGnpDWlVNN9+++YqRkBudgsWKuVErWUTceoQumuoqmjKxDz/XeIbWS/38Yl2Of5K2nnXnFVAQJrfSxRgb0Tdj7U0ibOa3Q5Uvna8mnXjLr1MOtKVR52Zo6yf X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XHGszzeu9z5CtWOXtCNbBO9h1YDGlV15utLI0TGHtlvuC2HLDhT/AclbU9+09id4CJO1sWjUw9TNwU7B6O76/O9jWn9JTmv1YJsE8G69N4RfH1FqiYpLAy4ykAhXu1cHHT/cEeHQsPHaGU583lUPLA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0b540bd2-e0e0-4537-ed7d-08d96e2829ea X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Sep 2021 15:41:43.3014 (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: AM7PR03MB6532 Subject: [FFmpeg-devel] [PATCH 03/13] avcodec/vp9: Check initializing conditions/mutexes 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: 7S1Ceh8ZQIFn Also don't destroy uninitialized conditions/mutexes. Signed-off-by: Andreas Rheinhardt --- libavcodec/vp9.c | 17 +++++++++++------ libavcodec/vp9dec.h | 1 + 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c index 5c20a7ec5d..239475cdbe 100644 --- a/libavcodec/vp9.c +++ b/libavcodec/vp9.c @@ -27,6 +27,8 @@ #include "internal.h" #include "profiles.h" #include "thread.h" +#include "pthread_internal.h" + #include "videodsp.h" #include "vp56.h" #include "vp9.h" @@ -39,6 +41,10 @@ #define VP9_SYNCCODE 0x498342 #if HAVE_THREADS +DEFINE_OFFSET_ARRAY(VP9Context, vp9_context, pthread_init_cnt, + (offsetof(VP9Context, progress_mutex)), + (offsetof(VP9Context, progress_cond))); + static void vp9_free_entries(AVCodecContext *avctx) { VP9Context *s = avctx->priv_data; @@ -1248,10 +1254,7 @@ static av_cold int vp9_decode_free(AVCodecContext *avctx) free_buffers(s); vp9_free_entries(avctx); #if HAVE_THREADS - if (avctx->active_thread_type & FF_THREAD_SLICE) { - pthread_mutex_destroy(&s->progress_mutex); - pthread_cond_destroy(&s->progress_cond); - } + ff_pthread_free(s, vp9_context_offsets); #endif av_freep(&s->td); return 0; @@ -1794,14 +1797,16 @@ static void vp9_decode_flush(AVCodecContext *avctx) static av_cold int vp9_decode_init(AVCodecContext *avctx) { VP9Context *s = avctx->priv_data; + int ret; s->last_bpp = 0; s->s.h.filter.sharpness = -1; #if HAVE_THREADS if (avctx->active_thread_type & FF_THREAD_SLICE) { - pthread_mutex_init(&s->progress_mutex, NULL); - pthread_cond_init(&s->progress_cond, NULL); + ret = ff_pthread_init(s, vp9_context_offsets); + if (ret < 0) + return ret; } #endif diff --git a/libavcodec/vp9dec.h b/libavcodec/vp9dec.h index d82b258a3d..9cbd5839a8 100644 --- a/libavcodec/vp9dec.h +++ b/libavcodec/vp9dec.h @@ -105,6 +105,7 @@ typedef struct VP9Context { pthread_mutex_t progress_mutex; pthread_cond_t progress_cond; atomic_int *entries; + unsigned pthread_init_cnt; #endif uint8_t ss_h, ss_v;