Merge commit '117b432748ca87de4cd0f09d9b1495545e264733'
* commit '117b432748ca87de4cd0f09d9b1495545e264733': lavc: Introduce AVCodec internal capabilities Conflicts: libavcodec/utils.c Merged-by: Michael Niedermayer <michaelni@gmx.at>
This commit is contained in:
commit
a048bd44b2
@ -3262,6 +3262,11 @@ typedef struct AVCodec {
|
|||||||
* Will be called when seeking
|
* Will be called when seeking
|
||||||
*/
|
*/
|
||||||
void (*flush)(AVCodecContext *);
|
void (*flush)(AVCodecContext *);
|
||||||
|
/**
|
||||||
|
* Internal codec capabilities.
|
||||||
|
* See FF_CODEC_CAP_* in internal.h
|
||||||
|
*/
|
||||||
|
int caps_internal;
|
||||||
} AVCodec;
|
} AVCodec;
|
||||||
|
|
||||||
int av_codec_get_max_lowres(const AVCodec *codec);
|
int av_codec_get_max_lowres(const AVCodec *codec);
|
||||||
|
@ -33,6 +33,16 @@
|
|||||||
#include "avcodec.h"
|
#include "avcodec.h"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Codec is thread safe.
|
||||||
|
*/
|
||||||
|
#define FF_CODEC_CAP_INIT_THREADSAFE (1 << 0)
|
||||||
|
/**
|
||||||
|
* Codec cleans up memory on init failure.
|
||||||
|
*/
|
||||||
|
#define FF_CODEC_CAP_INIT_CLEANUP (1 << 1)
|
||||||
|
|
||||||
|
|
||||||
#define FF_SANE_NB_CHANNELS 63U
|
#define FF_SANE_NB_CHANNELS 63U
|
||||||
|
|
||||||
#define FF_SIGNBIT(x) ((x) >> CHAR_BIT * sizeof(x) - 1)
|
#define FF_SIGNBIT(x) ((x) >> CHAR_BIT * sizeof(x) - 1)
|
||||||
@ -157,7 +167,7 @@ int ff_init_buffer_info(AVCodecContext *s, AVFrame *frame);
|
|||||||
void avpriv_color_frame(AVFrame *frame, const int color[4]);
|
void avpriv_color_frame(AVFrame *frame, const int color[4]);
|
||||||
|
|
||||||
extern volatile int ff_avcodec_locked;
|
extern volatile int ff_avcodec_locked;
|
||||||
int ff_lock_avcodec(AVCodecContext *log_ctx);
|
int ff_lock_avcodec(AVCodecContext *log_ctx, AVCodec *codec);
|
||||||
int ff_unlock_avcodec(void);
|
int ff_unlock_avcodec(void);
|
||||||
|
|
||||||
int avpriv_lock_avformat(void);
|
int avpriv_lock_avformat(void);
|
||||||
|
@ -1318,7 +1318,7 @@ int attribute_align_arg ff_codec_open2_recursive(AVCodecContext *avctx, const AV
|
|||||||
|
|
||||||
ret = avcodec_open2(avctx, codec, options);
|
ret = avcodec_open2(avctx, codec, options);
|
||||||
|
|
||||||
ff_lock_avcodec(avctx);
|
ff_lock_avcodec(avctx, codec);
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1348,7 +1348,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
|
|||||||
if (options)
|
if (options)
|
||||||
av_dict_copy(&tmp, *options, 0);
|
av_dict_copy(&tmp, *options, 0);
|
||||||
|
|
||||||
ret = ff_lock_avcodec(avctx);
|
ret = ff_lock_avcodec(avctx, codec);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
@ -1477,7 +1477,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
|
|||||||
if (CONFIG_FRAME_THREAD_ENCODER) {
|
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(); //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);
|
ret = ff_frame_thread_encoder_init(avctx, options ? *options : NULL);
|
||||||
ff_lock_avcodec(avctx);
|
ff_lock_avcodec(avctx, codec);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto free_and_end;
|
goto free_and_end;
|
||||||
}
|
}
|
||||||
@ -1704,6 +1704,10 @@ end:
|
|||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
free_and_end:
|
free_and_end:
|
||||||
|
if (avctx->codec &&
|
||||||
|
(avctx->codec->caps_internal & FF_CODEC_CAP_INIT_CLEANUP))
|
||||||
|
avctx->codec->close(avctx);
|
||||||
|
|
||||||
av_dict_free(&tmp);
|
av_dict_free(&tmp);
|
||||||
if (codec->priv_class && codec->priv_data_size)
|
if (codec->priv_class && codec->priv_data_size)
|
||||||
av_opt_free(avctx->priv_data);
|
av_opt_free(avctx->priv_data);
|
||||||
@ -3600,14 +3604,15 @@ int av_lockmgr_register(int (*cb)(void **mutex, enum AVLockOp op))
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ff_lock_avcodec(AVCodecContext *log_ctx)
|
int ff_lock_avcodec(AVCodecContext *log_ctx, AVCodec *codec)
|
||||||
{
|
{
|
||||||
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(log_ctx, AV_LOG_ERROR,
|
av_log(log_ctx, 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",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user