summaryrefslogtreecommitdiffstats
path: root/libavcodec/utils.c
diff options
context:
space:
mode:
authorDerek Buitenhuis <derek.buitenhuis@gmail.com>2015-10-01 15:38:15 +0100
committerDerek Buitenhuis <derek.buitenhuis@gmail.com>2015-10-02 14:07:14 +0100
commitabaa12263e08ae7b2099f00fa4597ae6a86d7a9c (patch)
tree292b847c83ddaad0920afbe93cb3e60a62c6276d /libavcodec/utils.c
parent1d7d8244943cfbfce21049453f56e0d72f2c6d8a (diff)
downloadffmpeg-streaming-abaa12263e08ae7b2099f00fa4597ae6a86d7a9c.zip
ffmpeg-streaming-abaa12263e08ae7b2099f00fa4597ae6a86d7a9c.tar.gz
avcodec: Don't lock during open if the codec has threadsafe init
Signed-off-by: Derek Buitenhuis <derek.buitenhuis@gmail.com>
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r--libavcodec/utils.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index c2ded45..7bfd760 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -1145,7 +1145,7 @@ int attribute_align_arg ff_codec_open2_recursive(AVCodecContext *avctx, const AV
{
int ret = 0;
- ff_unlock_avcodec();
+ ff_unlock_avcodec(codec);
ret = avcodec_open2(avctx, codec, options);
@@ -1306,7 +1306,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
av_log(avctx, AV_LOG_WARNING, "Warning: not compiled with thread support, using thread emulation\n");
if (CONFIG_FRAME_THREAD_ENCODER) {
- ff_unlock_avcodec(); //we will instanciate a few encoders thus kick the counter to prevent false detection of a problem
+ ff_unlock_avcodec(codec); //we will instanciate a few encoders thus kick the counter to prevent false detection of a problem
ret = ff_frame_thread_encoder_init(avctx, options ? *options : NULL);
ff_lock_avcodec(avctx, codec);
if (ret < 0)
@@ -1553,7 +1553,7 @@ FF_ENABLE_DEPRECATION_WARNINGS
}
end:
- ff_unlock_avcodec();
+ ff_unlock_avcodec(codec);
if (options) {
av_dict_free(options);
*options = tmp;
@@ -3266,13 +3266,15 @@ int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
int ff_lock_avcodec(AVCodecContext *log_ctx, const AVCodec *codec)
{
+ if (codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE)
+ return 0;
+
if (lockmgr_cb) {
if ((*lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
return -1;
}
- if (avpriv_atomic_int_add_and_fetch(&entangled_thread_counter, 1) != 1 &&
- !(codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE)) {
+ if (avpriv_atomic_int_add_and_fetch(&entangled_thread_counter, 1) != 1) {
av_log(log_ctx, AV_LOG_ERROR,
"Insufficient thread locking. At least %d threads are "
"calling avcodec_open2() at the same time right now.\n",
@@ -3280,7 +3282,7 @@ int ff_lock_avcodec(AVCodecContext *log_ctx, const AVCodec *codec)
if (!lockmgr_cb)
av_log(log_ctx, AV_LOG_ERROR, "No lock manager is set, please see av_lockmgr_register()\n");
ff_avcodec_locked = 1;
- ff_unlock_avcodec();
+ ff_unlock_avcodec(codec);
return AVERROR(EINVAL);
}
av_assert0(!ff_avcodec_locked);
@@ -3288,8 +3290,11 @@ int ff_lock_avcodec(AVCodecContext *log_ctx, const AVCodec *codec)
return 0;
}
-int ff_unlock_avcodec(void)
+int ff_unlock_avcodec(const AVCodec *codec)
{
+ if (codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE)
+ return 0;
+
av_assert0(ff_avcodec_locked);
ff_avcodec_locked = 0;
avpriv_atomic_int_add_and_fetch(&entangled_thread_counter, -1);
OpenPOWER on IntegriCloud