[FFmpeg-cvslog] lavc: Introduce AVCodec internal capabilities
Vittorio Giovara
git at videolan.org
Fri Mar 13 22:48:05 CET 2015
ffmpeg | branch: master | Vittorio Giovara <vittorio.giovara at gmail.com> | Wed Mar 11 20:43:58 2015 +0000| [117b432748ca87de4cd0f09d9b1495545e264733] | committer: Vittorio Giovara
lavc: Introduce AVCodec internal capabilities
This field is designed for marking codec properties useful to lavc internals.
Two internal capabilities are added:
- FF_CODEC_CAP_INIT_THREADSAFE: codec can be opened without locks;
- FF_CODEC_CAP_INIT_CLEANUP: codec frees memory if initialization fails.
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=117b432748ca87de4cd0f09d9b1495545e264733
---
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..3cd24b1 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 FF_CODEC_CAP_* in internal.h
+ */
+ int caps_internal;
} AVCodec;
/**
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index a68d613..a681329 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -33,6 +33,16 @@
#include "avcodec.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_SIGNBIT(x) (x >> CHAR_BIT * sizeof(x) - 1)
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 7b169ff..f1acd78 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->caps_internal & FF_CODEC_CAP_INIT_THREADSAFE)) {
av_log(avctx, AV_LOG_ERROR,
"Insufficient thread locking. At least %d threads are "
"calling avcodec_open2() at the same time right now.\n",
@@ -1286,6 +1287,10 @@ end:
return ret;
free_and_end:
+ if (avctx->codec &&
+ (avctx->codec->caps_internal & FF_CODEC_CAP_INIT_CLEANUP))
+ avctx->codec->close(avctx);
+
av_dict_free(&tmp);
av_freep(&avctx->priv_data);
if (avctx->internal) {
More information about the ffmpeg-cvslog
mailing list