From patchwork Thu Dec 21 22:22:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wm4 X-Patchwork-Id: 6898 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.79.195 with SMTP id r64csp1509419jad; Thu, 21 Dec 2017 14:23:10 -0800 (PST) X-Google-Smtp-Source: ACJfBotQ9XawRqAK52OYUiiBqBJdjoDdXfrZqLp+2LJvqa8DSevyGDP+V7vJ3E4W91t43C/d/50t X-Received: by 10.223.166.130 with SMTP id t2mr6602619wrc.244.1513894990503; Thu, 21 Dec 2017 14:23:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1513894990; cv=none; d=google.com; s=arc-20160816; b=BXW3Aksn5dL0dkbGIVaSqZoN6yli45ZO+Bw0VrZ+E0gOk4toznTGHVrVF6War0yjJo Vuq0G9ikCc5uVih2yg3a9R2ZG6zsVA4VlKv015a6lMVXijJJ234CX7NwctrWxu5ER+Cc yvUPs89o4ED0oKEa7uCnqYN86CYoeeXbOEsHnfJpllUVuoUuuMiWZh0lgn2UoSWNkyjX 37sVUCDYnNgOBj1LGoW0unvIlELGu4sRVhN/l1kN1KheDIiiApNslx1gWYA2l3IXQE4K kwqGsDEEsKysKl6TLsggdcgVDXaxuk33BqKcBKY7WMQeCwVzPxyUlh7ctqsL5Py3JCw/ HiaA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=lrbqh3NgC4/OxHlsaYnkrlwPL8UVCVwEiL06LhOl3+8=; b=XI/A7ftkaTg6hvZZDrI5aP4G2NVjg2W+CQWa64kDGAXkGyC2l7KRWP3vSOhXm/0RNH mnqIjLkJsvIyxNc+iWxq/6HMlW32X0+w9YGgxisT1OwSmR3eazcHOyId29+WXPrqVdsE VrsdaP+aXnBkhWkB7I6qhx8HkA7KfwFMWpIcM7nKCSk+Jb0TdTrVa/pMbDtfXm3HJ7JT qL2gMTbBeGkfwvtfC1lFo44SMgtqLvCZ1sE+9w6jrzGtRhsAmI9muPVwja9V2L8H+ULW I41FAa/VtsDBrwDaT81fZna7Jymc59iOpLrNHJ99zOka2+MxfMTRVj58Sr217+B84vCT byXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@googlemail.com header.s=20161025 header.b=FYhPVjO1; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id z110si10393791wrc.232.2017.12.21.14.23.10; Thu, 21 Dec 2017 14:23:10 -0800 (PST) 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=@googlemail.com header.s=20161025 header.b=FYhPVjO1; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7DFF1680877; Fri, 22 Dec 2017 00:22:31 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm0-f43.google.com (mail-wm0-f43.google.com [74.125.82.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 563DD680439 for ; Fri, 22 Dec 2017 00:22:25 +0200 (EET) Received: by mail-wm0-f43.google.com with SMTP id f140so18491226wmd.2 for ; Thu, 21 Dec 2017 14:22:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=zLvT3196xezrVwhHiTCdPg/PYkVGcbjzJvm+T/ITAy0=; b=FYhPVjO1FOU8VQ1BFNIObrZjj222X36eErOI1jcyXS/ETSrFBIafmhZQguA1Hu4Jtd 4n1nAuQzWLREaTPee8t5Y2KbWL0+jqHtk1pehVWmDq1H3etkHI1oR+zRDGKsL8XtvNpp s3k2DPbFasytaIyFsvjQAr/Lcqf042rawzg2Bs27y3SuUe26Cia+4GQIW1uoxltXzqX2 i25W4m01pKzCNIIBkQP80su+g6Oo5afW+0pPXLeyT6rDZXKVE7QEaX1H25TnYZzYfl3y 493n4SOIOkqmf3iUss+M+KKD4Bbi7R1EqutEJskHoza+XSj4QZB17G8yKarWvXZmN8k/ f8Hg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=zLvT3196xezrVwhHiTCdPg/PYkVGcbjzJvm+T/ITAy0=; b=nvAJYV/d0OAsZ+jeGDwBISY5FEqxkIMk9zpES3+d22FAXiILnR+zY9CRmUfPFh8jil 88tpnpCI61OFxR1Q14K+gpEfvJ2HdlQuZuKIs67whNuNmaUW+xBXQdt95BztYbwT82zj WM6niKd7PwHFVzcbrhoNbDvL7rsMttmICeUS0tdRV60S91Kl7F0ZHaF1WRWVyDBFwoJf LUasOHseKf8B00PQhbXmhfwEQGP56TlCrCj/E/7uKBBq56I6bPFBb/Hl7iDdFZkeJhPA 8OQ0LdcYvd19tCZsLVJL79LdJET6nhJ5FQR9yHgEv5nze65nk6zco3NxS5ExvRYJmhzw llBA== X-Gm-Message-State: AKGB3mJ2csEIx3E8bd+olOFlshGeYvduf8+g5ctnMDqeVdsoz8mNqsd7 FdwPPluG5PRKqBSQAaqz6qbEAQ== X-Received: by 10.80.158.194 with SMTP id a60mr11884828edf.228.1513894956080; Thu, 21 Dec 2017 14:22:36 -0800 (PST) Received: from debian.speedport.ip (p2003006CCD4EDC713C06725800124D49.dip0.t-ipconnect.de. [2003:6c:cd4e:dc71:3c06:7258:12:4d49]) by smtp.googlemail.com with ESMTPSA id p47sm19834538edc.30.2017.12.21.14.22.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Dec 2017 14:22:35 -0800 (PST) From: wm4 To: ffmpeg-devel@ffmpeg.org Date: Thu, 21 Dec 2017 23:22:23 +0100 Message-Id: <20171221222224.18577-4-nfxjfg@googlemail.com> X-Mailer: git-send-email 2.15.1 In-Reply-To: <20171221222224.18577-1-nfxjfg@googlemail.com> References: <20171221222224.18577-1-nfxjfg@googlemail.com> Subject: [FFmpeg-devel] [PATCH 4/5] lavc, lavf: move avformat static mutex from avcodec to avformat X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: wm4 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" It's completely absurd that libavcodec would care about libavformat locking, but it was there because the lock manager was in libavcodec. This is more stright forward. Changes ABI, but we don't require ABI compatibility currently. --- openssl, avisynth, chromaprint build untested --- libavcodec/internal.h | 3 --- libavcodec/utils.c | 11 ----------- libavformat/avisynth.c | 10 +++++----- libavformat/chromaprint.c | 9 +++++---- libavformat/internal.h | 4 ++++ libavformat/tls_gnutls.c | 8 ++++---- libavformat/tls_openssl.c | 10 +++++----- libavformat/utils.c | 13 +++++++++++++ 8 files changed, 36 insertions(+), 32 deletions(-) diff --git a/libavcodec/internal.h b/libavcodec/internal.h index 30cb9a0de1..bf58f36ad3 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -245,9 +245,6 @@ extern volatile int ff_avcodec_locked; int ff_lock_avcodec(AVCodecContext *log_ctx, const AVCodec *codec); int ff_unlock_avcodec(const AVCodec *codec); -int avpriv_lock_avformat(void); -int avpriv_unlock_avformat(void); - /** * Maximum size in bytes of extradata. * This value was chosen such that every bit of the buffer is diff --git a/libavcodec/utils.c b/libavcodec/utils.c index c7f8cdf08f..718063f1a1 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -70,7 +70,6 @@ const char av_codec_ffversion[] = "FFmpeg version " FFMPEG_VERSION; volatile int ff_avcodec_locked; static atomic_int entangled_thread_counter = ATOMIC_VAR_INIT(0); static pthread_mutex_t codec_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t avformat_mutex = PTHREAD_MUTEX_INITIALIZER; void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size) { @@ -1904,16 +1903,6 @@ int ff_unlock_avcodec(const AVCodec *codec) return 0; } -int avpriv_lock_avformat(void) -{ - return pthread_mutex_lock(&avformat_mutex) ? -1 : 0; -} - -int avpriv_unlock_avformat(void) -{ - return pthread_mutex_unlock(&avformat_mutex) ? -1 : 0; -} - unsigned int avpriv_toupper4(unsigned int x) { return av_toupper(x & 0xFF) + diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c index 56700288f7..250a489321 100644 --- a/libavformat/avisynth.c +++ b/libavformat/avisynth.c @@ -774,15 +774,15 @@ static av_cold int avisynth_read_header(AVFormatContext *s) int ret; // Calling library must implement a lock for thread-safe opens. - if (ret = avpriv_lock_avformat()) + if (ret = ff_lock_avformat()) return ret; if (ret = avisynth_open_file(s)) { - avpriv_unlock_avformat(); + ff_unlock_avformat(); return ret; } - avpriv_unlock_avformat(); + ff_unlock_avformat(); return 0; } @@ -818,11 +818,11 @@ static int avisynth_read_packet(AVFormatContext *s, AVPacket *pkt) static av_cold int avisynth_read_close(AVFormatContext *s) { - if (avpriv_lock_avformat()) + if (ff_lock_avformat()) return AVERROR_UNKNOWN; avisynth_context_destroy(s->priv_data); - avpriv_unlock_avformat(); + ff_unlock_avformat(); return 0; } diff --git a/libavformat/chromaprint.c b/libavformat/chromaprint.c index 4da02bef76..f39c09ddb9 100644 --- a/libavformat/chromaprint.c +++ b/libavformat/chromaprint.c @@ -20,6 +20,7 @@ */ #include "avformat.h" +#include "internal.h" #include "libavutil/opt.h" #include "libavcodec/internal.h" #include @@ -49,9 +50,9 @@ typedef struct ChromaprintMuxContext { static void cleanup(ChromaprintMuxContext *cpr) { if (cpr->ctx) { - avpriv_lock_avformat(); + ff_lock_avformat(); chromaprint_free(cpr->ctx); - avpriv_unlock_avformat(); + ff_unlock_avformat(); } } @@ -60,9 +61,9 @@ static int write_header(AVFormatContext *s) ChromaprintMuxContext *cpr = s->priv_data; AVStream *st; - avpriv_lock_avformat(); + ff_lock_avformat(); cpr->ctx = chromaprint_new(cpr->algorithm); - avpriv_unlock_avformat(); + ff_unlock_avformat(); 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 36a57214ce..26738f80e2 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -681,4 +681,8 @@ int ff_bprint_to_codecpar_extradata(AVCodecParameters *par, struct AVBPrint *buf int ff_interleaved_peek(AVFormatContext *s, int stream, AVPacket *pkt, int add_offset); + +int ff_lock_avformat(void); +int ff_unlock_avformat(void); + #endif /* AVFORMAT_INTERNAL_H */ diff --git a/libavformat/tls_gnutls.c b/libavformat/tls_gnutls.c index 0cef9575ec..e3c43683be 100644 --- a/libavformat/tls_gnutls.c +++ b/libavformat/tls_gnutls.c @@ -55,20 +55,20 @@ typedef struct TLSContext { void ff_gnutls_init(void) { - avpriv_lock_avformat(); + ff_lock_avformat(); #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(); - avpriv_unlock_avformat(); + ff_unlock_avformat(); } void ff_gnutls_deinit(void) { - avpriv_lock_avformat(); + ff_lock_avformat(); gnutls_global_deinit(); - avpriv_unlock_avformat(); + ff_unlock_avformat(); } static int print_tls_error(URLContext *h, int ret) diff --git a/libavformat/tls_openssl.c b/libavformat/tls_openssl.c index 1443e9025a..59a86150a7 100644 --- a/libavformat/tls_openssl.c +++ b/libavformat/tls_openssl.c @@ -68,7 +68,7 @@ static unsigned long openssl_thread_id(void) int ff_openssl_init(void) { - avpriv_lock_avformat(); + ff_lock_avformat(); if (!openssl_init) { SSL_library_init(); SSL_load_error_strings(); @@ -77,7 +77,7 @@ int ff_openssl_init(void) int i; openssl_mutexes = av_malloc_array(sizeof(pthread_mutex_t), CRYPTO_num_locks()); if (!openssl_mutexes) { - avpriv_unlock_avformat(); + ff_unlock_avformat(); return AVERROR(ENOMEM); } @@ -91,14 +91,14 @@ int ff_openssl_init(void) #endif } openssl_init++; - avpriv_unlock_avformat(); + ff_unlock_avformat(); return 0; } void ff_openssl_deinit(void) { - avpriv_lock_avformat(); + ff_lock_avformat(); openssl_init--; if (!openssl_init) { #if HAVE_THREADS @@ -111,7 +111,7 @@ void ff_openssl_deinit(void) } #endif } - avpriv_unlock_avformat(); + ff_unlock_avformat(); } static int print_tls_error(URLContext *h, int ret) diff --git a/libavformat/utils.c b/libavformat/utils.c index 84e49208b8..95ab073f78 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -32,6 +32,7 @@ #include "libavutil/opt.h" #include "libavutil/parseutils.h" #include "libavutil/pixdesc.h" +#include "libavutil/thread.h" #include "libavutil/time.h" #include "libavutil/time_internal.h" #include "libavutil/timestamp.h" @@ -55,6 +56,8 @@ #include "libavutil/ffversion.h" const char av_format_ffversion[] = "FFmpeg version " FFMPEG_VERSION; +static pthread_mutex_t avformat_mutex = PTHREAD_MUTEX_INITIALIZER; + /** * @file * various utility functions for use within FFmpeg @@ -77,6 +80,16 @@ const char *avformat_license(void) return LICENSE_PREFIX FFMPEG_LICENSE + sizeof(LICENSE_PREFIX) - 1; } +int ff_lock_avformat(void) +{ + return pthread_mutex_lock(&avformat_mutex) ? -1 : 0; +} + +int ff_unlock_avformat(void) +{ + return pthread_mutex_unlock(&avformat_mutex) ? -1 : 0; +} + #define RELATIVE_TS_BASE (INT64_MAX - (1LL<<48)) static int is_relative(int64_t ts) {