diff --git a/libavcodec/internal.h b/libavcodec/internal.h index fcbdb6c04d..30614bb2b1 100644 --- a/libavcodec/internal.h +++ b/libavcodec/internal.h @@ -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 diff --git a/libavcodec/utils.c b/libavcodec/utils.c index eec4437693..9c631c4fb0 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 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) + 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 e76ac12371..30715b3f50 100644 --- a/libavformat/internal.h +++ b/libavformat/internal.h @@ -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 */ 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..9b46bd6737 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 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) {