On Tue, 10 Mar 2015 01:28:53 +0000
Vittorio Giovara <[email protected]> wrote:
> This field is designed for marking codec properties useful to lavc internals.
> Two internal capabilities are added:
> - CODEC_INT_CAP_THREAD_SAFE: codec can be opened without locks;
> - CODEC_INT_CAP_CLEANUP_INIT: codec frees memory if initialization fails.
> ---
> I feel like the variable name is overly long but not sure how else (or if
> at all) to call it. Any suggestions?
> Vittorio
>
> libavcodec/avcodec.h | 5 +++++
> libavcodec/internal.h | 10 ++++++++++
> libavcodec/utils.c | 7 ++++++-
> 3 files changed, 21 insertions(+), 1 deletion(-)
>
> diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
> index 8b9e21f..b9e5375 100644
> --- a/libavcodec/avcodec.h
> +++ b/libavcodec/avcodec.h
> @@ -2924,6 +2924,11 @@ typedef struct AVCodec {
> * Will be called when seeking
> */
> void (*flush)(AVCodecContext *);
> + /**
> + * Internal codec capabilities.
> + * see CODEC_CAP_INT_* in internal.h
> + */
> + int internal_capabilities;
> } AVCodec;
>
> /**
> diff --git a/libavcodec/internal.h b/libavcodec/internal.h
> index a68d613..bbc7d22 100644
> --- a/libavcodec/internal.h
> +++ b/libavcodec/internal.h
> @@ -33,6 +33,16 @@
> #include "avcodec.h"
> #include "config.h"
>
> +/**
> + * Codec is thread safe.
> + */
> +#define CODEC_INT_CAP_THREAD_SAFE 1 << 0
Isn't it a bit unspecific? Maybe ODEC_INT_CAP_THREAD_SAFE_INIT.
Otherwise I'd think it's something about being able to call the decoder
function concurrently or so.
> +/**
> + * Codec cleans up memory on init failure.
> + */
> +#define CODEC_INT_CAP_CLEANUP_INIT 1 << 1
> +
> +
> #define FF_SANE_NB_CHANNELS 63U
>
> #define FF_SIGNBIT(x) (x >> CHAR_BIT * sizeof(x) - 1)
> diff --git a/libavcodec/utils.c b/libavcodec/utils.c
> index f8a8908..451d005 100644
> --- a/libavcodec/utils.c
> +++ b/libavcodec/utils.c
> @@ -1049,7 +1049,8 @@ int attribute_align_arg avcodec_open2(AVCodecContext
> *avctx, const AVCodec *code
> }
>
> entangled_thread_counter++;
> - if (entangled_thread_counter != 1) {
> + if (entangled_thread_counter != 1 &&
> + !(codec->internal_capabilities & CODEC_INT_CAP_THREAD_SAFE)) {
> av_log(avctx, AV_LOG_ERROR,
> "Insufficient thread locking around avcodec_open2(). "
> "At least %d threads are running at the same time right
> now.\n",
> @@ -1286,6 +1287,10 @@ end:
>
> return ret;
> free_and_end:
> + if (avctx->codec &&
> + (avctx->codec->internal_capabilities & CODEC_INT_CAP_CLEANUP_INIT))
> + avctx->codec->close(avctx);
> +
> av_dict_free(&tmp);
> av_freep(&avctx->priv_data);
> if (avctx->internal) {
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel