Commit eae58428 authored by Derek Buitenhuis's avatar Derek Buitenhuis Committed by Luca Barbato

avcodec: Do not lock during open for codecs marked as having threadsafe init

Signed-off-by: 's avatarDerek Buitenhuis <derek.buitenhuis@gmail.com>
Signed-off-by: 's avatarLuca Barbato <lu_zero@gentoo.org>
parent abe9adfb
...@@ -845,14 +845,14 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code ...@@ -845,14 +845,14 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
av_dict_copy(&tmp, *options, 0); av_dict_copy(&tmp, *options, 0);
/* If there is a user-supplied mutex locking routine, call it. */ /* If there is a user-supplied mutex locking routine, call it. */
if (!(codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE)) {
if (lockmgr_cb) { if (lockmgr_cb) {
if ((*lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN)) if ((*lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
return -1; return -1;
} }
entangled_thread_counter++; entangled_thread_counter++;
if (entangled_thread_counter != 1 && if (entangled_thread_counter != 1) {
!(codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE)) {
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,
"Insufficient thread locking. At least %d threads are " "Insufficient thread locking. At least %d threads are "
"calling avcodec_open2() at the same time right now.\n", "calling avcodec_open2() at the same time right now.\n",
...@@ -860,6 +860,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code ...@@ -860,6 +860,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
ret = -1; ret = -1;
goto end; goto end;
} }
}
avctx->internal = av_mallocz(sizeof(AVCodecInternal)); avctx->internal = av_mallocz(sizeof(AVCodecInternal));
if (!avctx->internal) { if (!avctx->internal) {
...@@ -1085,12 +1086,15 @@ FF_ENABLE_DEPRECATION_WARNINGS ...@@ -1085,12 +1086,15 @@ FF_ENABLE_DEPRECATION_WARNINGS
#endif #endif
} }
end: end:
if (!(codec->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE)) {
entangled_thread_counter--; entangled_thread_counter--;
/* Release any user-supplied mutex. */ /* Release any user-supplied mutex. */
if (lockmgr_cb) { if (lockmgr_cb) {
(*lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE); (*lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
} }
}
if (options) { if (options) {
av_dict_free(options); av_dict_free(options);
*options = tmp; *options = tmp;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment