mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2024-12-23 12:43:46 +02:00
lavc, lavf: move avformat static mutex from avcodec to avformat
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.
This commit is contained in:
parent
e24f192a9f
commit
86a13bf2ff
@ -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
|
||||
|
@ -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) +
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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");
|
||||
|
@ -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 */
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user