]> git.sesse.net Git - ffmpeg/commitdiff
lavc, lavf: move avformat static mutex from avcodec to avformat
authorwm4 <nfxjfg@googlemail.com>
Thu, 21 Dec 2017 21:54:06 +0000 (22:54 +0100)
committerwm4 <nfxjfg@googlemail.com>
Tue, 26 Dec 2017 01:50:00 +0000 (02:50 +0100)
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.

libavcodec/internal.h
libavcodec/utils.c
libavformat/avisynth.c
libavformat/chromaprint.c
libavformat/internal.h
libavformat/tls_gnutls.c
libavformat/tls_openssl.c
libavformat/utils.c

index fcbdb6c04d61ed3984f6fca5e69256184a31b22b..30614bb2b177e044d7110f7892ac1530577c40eb 100644 (file)
@@ -247,9 +247,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
index eec4437693563ca12b05095436c51ce78d53f766..9c631c4fb03da33fe20e7ed4174f9a06a187747a 100644 (file)
@@ -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 AVMutex codec_mutex = AV_MUTEX_INITIALIZER;
-static AVMutex avformat_mutex = AV_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 ff_mutex_lock(&avformat_mutex) ? -1 : 0;
-}
-
-int avpriv_unlock_avformat(void)
-{
-    return ff_mutex_unlock(&avformat_mutex) ? -1 : 0;
-}
-
 unsigned int avpriv_toupper4(unsigned int x)
 {
     return av_toupper(x & 0xFF) +
index 56700288f77becbe58e6a53f6ca8fb580130fd57..250a489321edc6b150e079d2c960c47be48f6b37 100644 (file)
@@ -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;
 }
 
index 4da02bef7622e567d8d8190a24abbadf6da2d46f..f39c09ddb92b92f81081f75eed58347bbc689e7d 100644 (file)
@@ -20,6 +20,7 @@
  */
 
 #include "avformat.h"
+#include "internal.h"
 #include "libavutil/opt.h"
 #include "libavcodec/internal.h"
 #include <chromaprint.h>
@@ -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");
index e76ac12371d780f5078a978097984d30059117c1..30715b3f500eb4987adb0b9cdfcb1037c5f2f885 100644 (file)
@@ -684,4 +684,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 */
index 0cef9575ec454e5119188b092a9c095b5b652115..e3c43683be57a9b9a31062227946c6d7e2ee592e 100644 (file)
@@ -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)
index 1443e9025aa8326b8a772f749aa888c440378064..59a86150a793dbc18c34f56578f6839c8fd7fb1a 100644 (file)
@@ -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)
index 84e49208b84ebd9f0fe094bc2198d20ed2545ed0..9b46bd673731082458f72756cd651658440200bc 100644 (file)
@@ -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 AVMutex avformat_mutex = AV_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 ff_mutex_lock(&avformat_mutex) ? -1 : 0;
+}
+
+int ff_unlock_avformat(void)
+{
+    return ff_mutex_unlock(&avformat_mutex) ? -1 : 0;
+}
+
 #define RELATIVE_TS_BASE (INT64_MAX - (1LL<<48))
 
 static int is_relative(int64_t ts) {