]> git.sesse.net Git - ffmpeg/commitdiff
lavc: Introduce AVCodec internal capabilities
authorVittorio Giovara <vittorio.giovara@gmail.com>
Wed, 11 Mar 2015 20:43:58 +0000 (20:43 +0000)
committerVittorio Giovara <vittorio.giovara@gmail.com>
Fri, 13 Mar 2015 19:47:47 +0000 (19:47 +0000)
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.

libavcodec/avcodec.h
libavcodec/internal.h
libavcodec/utils.c

index 8b9e21fbbde8982b19cb36ee7d66810ecd392410..3cd24b1fc1baaa8124d94e0c6b2f1b9069139f96 100644 (file)
@@ -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;
 
 /**
index a68d6134e3d8d9331baa9a5831615db8a8fe3bc0..a681329f20d0f63e724f8923f980cb0be551b599 100644 (file)
 #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)
index 7b169ff2095adc23670c25fcfe2407b82e93b49c..f1acd780dc12f631dff6f7f3ba055234c180996f 100644 (file)
@@ -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) {