mirror of
https://github.com/FFmpeg/FFmpeg.git
synced 2025-01-03 05:10:03 +02:00
avcodec/avcodec: Decrease the amount of time while holding the lock
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
parent
1e93f42743
commit
23b17f96f7
@ -169,8 +169,6 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
|
|||||||
if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
|
if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
|
||||||
return AVERROR(EINVAL);
|
return AVERROR(EINVAL);
|
||||||
|
|
||||||
lock_avcodec(codec);
|
|
||||||
|
|
||||||
avci = av_mallocz(sizeof(*avci));
|
avci = av_mallocz(sizeof(*avci));
|
||||||
if (!avci) {
|
if (!avci) {
|
||||||
ret = AVERROR(ENOMEM);
|
ret = AVERROR(ENOMEM);
|
||||||
@ -301,16 +299,17 @@ 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");
|
av_log(avctx, AV_LOG_WARNING, "Warning: not compiled with thread support, using thread emulation\n");
|
||||||
|
|
||||||
if (CONFIG_FRAME_THREAD_ENCODER && av_codec_is_encoder(avctx->codec)) {
|
if (CONFIG_FRAME_THREAD_ENCODER && av_codec_is_encoder(avctx->codec)) {
|
||||||
unlock_avcodec(codec); //we will instantiate a few encoders thus kick the counter to prevent false detection of a problem
|
|
||||||
ret = ff_frame_thread_encoder_init(avctx);
|
ret = ff_frame_thread_encoder_init(avctx);
|
||||||
lock_avcodec(codec);
|
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto free_and_end;
|
goto free_and_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HAVE_THREADS
|
if (HAVE_THREADS
|
||||||
&& !(avci->frame_thread_encoder && (avctx->active_thread_type&FF_THREAD_FRAME))) {
|
&& !(avci->frame_thread_encoder && (avctx->active_thread_type&FF_THREAD_FRAME))) {
|
||||||
|
/* Frame-threaded decoders call AVCodec.init for their child contexts. */
|
||||||
|
lock_avcodec(codec);
|
||||||
ret = ff_thread_init(avctx);
|
ret = ff_thread_init(avctx);
|
||||||
|
unlock_avcodec(codec);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
goto free_and_end;
|
goto free_and_end;
|
||||||
}
|
}
|
||||||
@ -321,7 +320,9 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
|
|||||||
if (!(avctx->active_thread_type & FF_THREAD_FRAME) ||
|
if (!(avctx->active_thread_type & FF_THREAD_FRAME) ||
|
||||||
avci->frame_thread_encoder) {
|
avci->frame_thread_encoder) {
|
||||||
if (avctx->codec->init) {
|
if (avctx->codec->init) {
|
||||||
|
lock_avcodec(codec);
|
||||||
ret = avctx->codec->init(avctx);
|
ret = avctx->codec->init(avctx);
|
||||||
|
unlock_avcodec(codec);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
avci->needs_close = avctx->codec->caps_internal & FF_CODEC_CAP_INIT_CLEANUP;
|
avci->needs_close = avctx->codec->caps_internal & FF_CODEC_CAP_INIT_CLEANUP;
|
||||||
goto free_and_end;
|
goto free_and_end;
|
||||||
@ -369,7 +370,6 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
|
|||||||
av_assert0(*(const AVClass **)avctx->priv_data == codec->priv_class);
|
av_assert0(*(const AVClass **)avctx->priv_data == codec->priv_class);
|
||||||
|
|
||||||
end:
|
end:
|
||||||
unlock_avcodec(codec);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
free_and_end:
|
free_and_end:
|
||||||
|
Loading…
Reference in New Issue
Block a user