From patchwork Fri May 17 15:23:05 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 48957 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:3a48:b0:1af:fc2d:ff5a with SMTP id zu8csp2957412pzb; Fri, 17 May 2024 08:37:52 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWC7CtImKicwOHJNPcl436VLuEF4XgdeFvdJg10IKsbN0hPU9N11sdGbP7V2nAsC34j9R7SIAt7dhMJMLKWkwSDdWOAJ1WgvJeB0w== X-Google-Smtp-Source: AGHT+IGWYZhoN7Oq2FmWEMKozJeqI5n2IrTEMOxhfwulPqMxhdULRsAw2jiQX6YMsyNPEGbaEzdQ X-Received: by 2002:a50:a6dc:0:b0:574:ebfb:6d8d with SMTP id 4fb4d7f45d1cf-574ebfb6dcbmr7570808a12.2.1715960272517; Fri, 17 May 2024 08:37: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 4fb4d7f45d1cf-57509572b40si2187666a12.357.2024.05.17.08.37.51; Fri, 17 May 2024 08:37: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=eGU0erGP; 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 B309468D280; Fri, 17 May 2024 18:37:48 +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-db8eur05olkn2101.outbound.protection.outlook.com [40.92.89.101]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7AF2168CC49 for ; Fri, 17 May 2024 18:37:41 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SKg6HXEqWq5ThJcd9vSyO2ub0bjNbaidCbU8lTPpJIaduDbCaxjj8i5CFh0rXhHPp2Re2DMvO6FeY8xYQVANqyk5c1IPS9TC6pfAiLktokN+HMZ0FnzKtyF5itvtnJn3BmbH7c6iY88JSlESTqCnlmGmgF41W2q8it0d2tJPWVVdkmrRnb6nJQcmQeNZ/rhlMFl/vfVV1/rNZnKG264OddvK2LDeLWLpIgvSgxNMaP+k0bbIONrZ4aDgy9O6krwhx2OVPb1x9NXpyuGguOJ+8HxfexvujqZaoR7NxIYSQnPgIy/giOMgHr/JhnLZAYi3+N0h1wovLOt8Ib1VETwWQA== 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=BHW/P/7NqmV9DWvpoUy4p2iLFY3C7twvYyXRGQS/Myw=; b=EHZM4riroPqvwDgW4QxTbdEO2aIsae1aLxRAN4WNr3xAwvoci924L57EpONqE5lcetGvcRALsDTmjYZL/UL7rB6Aog2w7RrQnf00G+3KnVukSOuIwHTdDwmtspOANyS2E+278ziau8NlYuZffTaaoK9Wuj63JgtefkOpogdFaL7yl8g0C8b4GbREBC9DFQzXA0oJ0sWi+rJeSFAghvf3MU2qWes3Fmnbs7Cx56oYUCYVJ67SUnjoyOlfkafQAAqj31VxK0LsCCqkdYY+6O4ZKtInRaexwtXETeugKNOyY2mBMY85ObrXb2ZHDfrzTmSxT5piRvwBT8+5a7lCGRn/3w== 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=BHW/P/7NqmV9DWvpoUy4p2iLFY3C7twvYyXRGQS/Myw=; b=eGU0erGP4rOyXvAHPnagTyd9AhkdPYTYT27EdV9ugz7PdN8uGjXHqhjGNFqgZ/DDQyGkdPA4Ar2DX/hQN8TmvBTN5T80ZdUrPACbXNl+f0q6z7jk9QozFyVa7dN6HBMhyCPccw0h7QYygFCVkDqmlhfU5cRzybTCWEHesrZyQa3/L76gtFvGpN1cYFsF3LwPjctB6b1ScCFoApOyEhNEl3R6XnqGMPA7ibeCr7eB0N8T+H7dA5qw8C5ZPoRwHQyzLEbu+ywJdbWCNYafU+ex4LTeK0/OHQURMrmMwbfhdfUpSTxdpnt4IAVe8UadUL1y6BRxtRHlvIUZDf7ZDO8+Gg== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by PRAP250MB0490.EURP250.PROD.OUTLOOK.COM (2603:10a6:102:290::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7544.55; Fri, 17 May 2024 15:23:17 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::384d:40d4:ecb7:1c9]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::384d:40d4:ecb7:1c9%4]) with mapi id 15.20.7544.052; Fri, 17 May 2024 15:23:17 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Fri, 17 May 2024 17:23:05 +0200 Message-ID: X-Mailer: git-send-email 2.40.1 X-TMN: [iBT37rdTyvBvqeqDOBYaOsoB05yKZdyQa5q2/Bgstz8=] X-ClientProxiedBy: ZR0P278CA0084.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:22::17) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20240517152310.3794014-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|PRAP250MB0490:EE_ X-MS-Office365-Filtering-Correlation-Id: 121a85d3-151c-4392-73a0-08dc768546d8 X-Microsoft-Antispam: BCL:0; ARA:14566002|461199019|440099019|3412199016|1710799017; X-Microsoft-Antispam-Message-Info: Gguv6NE+i4AxUGpIBSgTRIzHrGcMeFeynXsTLmcSCv64UuGn+eo2k8i6XtwuNFrWWdbHkC6vv++eUgPwAkVcAnPIXDwPAR1PbMQeLjLTBRzQPTT5OzDtp9tL5eBq0JFdB+wFSuMWgB3PTO/CNmSJSexWleB/yFFshTbeferHoy9gcg384K2fmRlrWdSlkjdzkVXj1r5iWnxG/35fnZ+ChenPFTZ1Hm+6f6ykzXl3Tdzc/dfUzGIH3+HWBPn9qLk7QMn5cUqzNIrFphD2nAqadsgOURPYW4qBFEcxBdJhZQdzcaBnxMkpKb0vWR0Ez0Pzs2pDIIMHVmC8nWhfdchJIH9UGTioVCvYNzYaBdsj/tD69Qgk6bWNjSSE3y/vRDXt+jDWRzbpS64g9W1IkCxZ5nUzCNKwwOT96tYvbZnrgGlJSueAPzJh/8NSvgK2LIvNm42QvgcjC3edfD1HvhzC2nCOpHJm1GZEnMq9ZSH6KNG9KfG8KeYgkfQjQPzXbB6GNw9zAuy0pLxv9hWNGyDDag5vW/paoovTWtWG8AmJHR31YfEZklhc8r1ROhGdM6+/EGBa9URpqwotdMvz0PMDx/EdrlufeVQesQBp87ZO5g4e/gLb8tL2ud9cypquX2Nj X-MS-Exchange-Anti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qtUw3NZdB0v7dXq20q20ka+w5/TyfpP25uBsZBI8/uSvHLba3Jjs2kOJUo0gUbbjDmCmR+uTJ+oa707XyMXNEjMlF9PNpIDaYpegYfabg3nBiuUKWHg65EcvuJpOt87LvIy4+kof+EOFoKxLTmE8/IcwUzBFwLlJqnpCONizPn8UccZQnH77DniETqsno2BOt8LGly9Quh63G8qkERWWapaIPEr3AFXfMMShoXUpsiLvPILe286JeIKQLNr/V4Zehv26Zh3d2oKW8WwQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 121a85d3-151c-4392-73a0-08dc768546d8 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 May 2024 15:23:17.4213 (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: PRAP250MB0490 Subject: [FFmpeg-devel] [PATCH 1/6] avformat/utils: Use static mutexes instead of ff_lock_avformat() 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: ui2n6PIMlmcV Its existence is a remnant of (libavcodec's) lock-manager API which has been removed in a04c2c707de2ce850f79870e84ac9d7ec7aa9143. There is no need to use the same lock for avisynth, chromaprint or tls, so switch to ordinary static mutexes instead. Signed-off-by: Andreas Rheinhardt --- libavformat/avisynth.c | 15 +++++++++------ libavformat/chromaprint.c | 12 +++++++----- libavformat/internal.h | 3 --- libavformat/tls_gnutls.c | 16 +++++++--------- libavformat/tls_openssl.c | 17 +++++++---------- libavformat/utils.c | 13 ------------- 6 files changed, 30 insertions(+), 46 deletions(-) diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c index 1709bf4051..625bdf7e3a 100644 --- a/libavformat/avisynth.c +++ b/libavformat/avisynth.c @@ -23,6 +23,7 @@ #include "libavutil/internal.h" #include "libavutil/mem.h" #include "libavutil/opt.h" +#include "libavutil/thread.h" #include "avformat.h" #include "demux.h" @@ -130,6 +131,8 @@ static const int avs_planes_yuva[4] = { AVS_PLANAR_Y, AVS_PLANAR_U, static const int avs_planes_rgba[4] = { AVS_PLANAR_G, AVS_PLANAR_B, AVS_PLANAR_R, AVS_PLANAR_A }; +static AVMutex avisynth_mutex = AV_MUTEX_INITIALIZER; + /* A conflict between C++ global objects, atexit, and dynamic loading requires * us to register our own atexit handler to prevent double freeing. */ static AviSynthLibrary avs_library; @@ -1083,15 +1086,15 @@ static av_cold int avisynth_read_header(AVFormatContext *s) int ret; // Calling library must implement a lock for thread-safe opens. - if (ret = ff_lock_avformat()) - return ret; + if (ff_mutex_lock(&avisynth_mutex)) + return AVERROR_UNKNOWN; if (ret = avisynth_open_file(s)) { - ff_unlock_avformat(); + ff_mutex_unlock(&avisynth_mutex); return ret; } - ff_unlock_avformat(); + ff_mutex_unlock(&avisynth_mutex); return 0; } @@ -1127,11 +1130,11 @@ static int avisynth_read_packet(AVFormatContext *s, AVPacket *pkt) static av_cold int avisynth_read_close(AVFormatContext *s) { - if (ff_lock_avformat()) + if (ff_mutex_lock(&avisynth_mutex)) return AVERROR_UNKNOWN; avisynth_context_destroy(s->priv_data); - ff_unlock_avformat(); + ff_mutex_unlock(&avisynth_mutex); return 0; } diff --git a/libavformat/chromaprint.c b/libavformat/chromaprint.c index 1cdca47ea5..eae233a651 100644 --- a/libavformat/chromaprint.c +++ b/libavformat/chromaprint.c @@ -20,15 +20,17 @@ */ #include "avformat.h" -#include "internal.h" #include "mux.h" #include "libavutil/opt.h" +#include "libavutil/thread.h" #include #define CPR_VERSION_INT AV_VERSION_INT(CHROMAPRINT_VERSION_MAJOR, \ CHROMAPRINT_VERSION_MINOR, \ CHROMAPRINT_VERSION_PATCH) +static AVMutex chromaprint_mutex = AV_MUTEX_INITIALIZER; + typedef enum FingerprintFormat { FINGERPRINT_RAW, FINGERPRINT_COMPRESSED, @@ -52,9 +54,9 @@ static void deinit(AVFormatContext *s) ChromaprintMuxContext *const cpr = s->priv_data; if (cpr->ctx) { - ff_lock_avformat(); + ff_mutex_lock(&chromaprint_mutex); chromaprint_free(cpr->ctx); - ff_unlock_avformat(); + ff_mutex_unlock(&chromaprint_mutex); } } @@ -63,9 +65,9 @@ static av_cold int init(AVFormatContext *s) ChromaprintMuxContext *cpr = s->priv_data; AVStream *st; - ff_lock_avformat(); + ff_mutex_lock(&chromaprint_mutex); cpr->ctx = chromaprint_new(cpr->algorithm); - ff_unlock_avformat(); + ff_mutex_unlock(&chromaprint_mutex); if (!cpr->ctx) { av_log(s, AV_LOG_ERROR, "Failed to create chromaprint context.\n"); diff --git a/libavformat/internal.h b/libavformat/internal.h index 7f3d1c0086..6bad4fd119 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -727,9 +727,6 @@ struct AVBPrint; */ int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf); -int ff_lock_avformat(void); -int ff_unlock_avformat(void); - /** * Set AVFormatContext url field to the provided pointer. The pointer must * point to a valid string. The existing url field is freed if necessary. Also diff --git a/libavformat/tls_gnutls.c b/libavformat/tls_gnutls.c index 2ab38a199b..df251ad79c 100644 --- a/libavformat/tls_gnutls.c +++ b/libavformat/tls_gnutls.c @@ -25,15 +25,12 @@ #include #include "avformat.h" -#include "internal.h" #include "network.h" #include "os_support.h" #include "url.h" #include "tls.h" -#include "libavcodec/internal.h" -#include "libavutil/avstring.h" #include "libavutil/opt.h" -#include "libavutil/parseutils.h" +#include "libavutil/thread.h" #ifndef GNUTLS_VERSION_NUMBER #define GNUTLS_VERSION_NUMBER LIBGNUTLS_VERSION_NUMBER @@ -41,7 +38,6 @@ #if HAVE_THREADS && GNUTLS_VERSION_NUMBER <= 0x020b00 #include -#include "libavutil/thread.h" GCRY_THREAD_OPTION_PTHREAD_IMPL; #endif @@ -54,22 +50,24 @@ typedef struct TLSContext { int io_err; } TLSContext; +static AVMutex gnutls_mutex = AV_MUTEX_INITIALIZER; + void ff_gnutls_init(void) { - ff_lock_avformat(); + ff_mutex_lock(&gnutls_mutex); #if HAVE_THREADS && GNUTLS_VERSION_NUMBER < 0x020b00 if (gcry_control(GCRYCTL_ANY_INITIALIZATION_P) == 0) gcry_control(GCRYCTL_SET_THREAD_CBS, &gcry_threads_pthread); #endif gnutls_global_init(); - ff_unlock_avformat(); + ff_mutex_unlock(&gnutls_mutex); } void ff_gnutls_deinit(void) { - ff_lock_avformat(); + ff_mutex_lock(&gnutls_mutex); gnutls_global_deinit(); - ff_unlock_avformat(); + ff_mutex_unlock(&gnutls_mutex); } static int print_tls_error(URLContext *h, int ret) diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c index b875be32f0..89d7c6e1ea 100644 --- a/libavformat/tls_openssl.c +++ b/libavformat/tls_openssl.c @@ -19,17 +19,12 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "avformat.h" -#include "internal.h" #include "network.h" #include "os_support.h" #include "url.h" #include "tls.h" -#include "libavutil/avstring.h" -#include "libavutil/avutil.h" #include "libavutil/mem.h" #include "libavutil/opt.h" -#include "libavutil/parseutils.h" #include "libavutil/thread.h" #include @@ -49,6 +44,8 @@ typedef struct TLSContext { int io_err; } TLSContext; +static AVMutex openssl_mutex = AV_MUTEX_INITIALIZER; + #if HAVE_THREADS && OPENSSL_VERSION_NUMBER < 0x10100000L #include pthread_mutex_t *openssl_mutexes; @@ -69,7 +66,7 @@ static unsigned long openssl_thread_id(void) int ff_openssl_init(void) { - ff_lock_avformat(); + ff_mutex_lock(&openssl_mutex); if (!openssl_init) { /* OpenSSL 1.0.2 or below, then you would use SSL_library_init. If you are * using OpenSSL 1.1.0 or above, then the library will initialize @@ -85,7 +82,7 @@ int ff_openssl_init(void) int i; openssl_mutexes = av_malloc_array(sizeof(pthread_mutex_t), CRYPTO_num_locks()); if (!openssl_mutexes) { - ff_unlock_avformat(); + ff_mutex_unlock(&openssl_mutex); return AVERROR(ENOMEM); } @@ -99,14 +96,14 @@ int ff_openssl_init(void) #endif } openssl_init++; - ff_unlock_avformat(); + ff_mutex_unlock(&openssl_mutex); return 0; } void ff_openssl_deinit(void) { - ff_lock_avformat(); + ff_mutex_lock(&openssl_mutex); openssl_init--; if (!openssl_init) { #if HAVE_THREADS && OPENSSL_VERSION_NUMBER < 0x10100000L @@ -119,7 +116,7 @@ void ff_openssl_deinit(void) } #endif } - ff_unlock_avformat(); + ff_mutex_unlock(&openssl_mutex); } static int print_tls_error(URLContext *h, int ret) diff --git a/libavformat/utils.c b/libavformat/utils.c index 4dded7aea4..e9ded627ad 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -27,7 +27,6 @@ #include "libavutil/bprint.h" #include "libavutil/internal.h" #include "libavutil/mem.h" -#include "libavutil/thread.h" #include "libavutil/time.h" #include "libavcodec/internal.h" @@ -40,23 +39,11 @@ #endif #include "os_support.h" -static AVMutex avformat_mutex = AV_MUTEX_INITIALIZER; - /** * @file * various utility functions for use within FFmpeg */ -int ff_lock_avformat(void) -{ - return ff_mutex_lock(&avformat_mutex) ? -1 : 0; -} - -int ff_unlock_avformat(void) -{ - return ff_mutex_unlock(&avformat_mutex) ? -1 : 0; -} - /* an arbitrarily chosen "sane" max packet size -- 50M */ #define SANE_CHUNK_SIZE (50000000)