[FFmpeg-devel] [PATCH 1/2] Support playing SMV files.

Ash Hughes ashes-iontach at hotmail.com
Tue Oct 16 20:48:06 CEST 2012


This patch updates libavcodec to enable recursively using avcodec_open2/close. Used in the SMV decoder to open an MJPEG decoder.

Ash

---
diff -uNr ffmpeg-vanilla/libavcodec/utils.c ffmpeg/libavcodec/utils.c
--- ffmpeg-vanilla/libavcodec/utils.c    2012-10-16 18:09:41.283863114 +0100
+++ ffmpeg/libavcodec/utils.c    2012-10-16 17:58:22.784498604 +0100
@@ -798,6 +798,27 @@
 }
 #endif
 
+int attribute_align_arg avcodec_open2_recursive(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
+{
+    int ret = 0;
+
+    entangled_thread_counter--;
+    /* Release any user-supplied mutex. */
+    if (ff_lockmgr_cb) {
+        (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
+    }
+
+    ret = avcodec_open2(avctx, codec, options);
+
+    /* If there is a user-supplied mutex locking routine, call it. */
+    if (ff_lockmgr_cb) {
+        if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
+            return -1;
+    }
+    entangled_thread_counter++;
+    return ret;
+}
+
 int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options)
 {
     int ret = 0;
@@ -1809,6 +1830,27 @@
     memset(sub, 0, sizeof(AVSubtitle));
 }
 
+av_cold int avcodec_close_recursive(AVCodecContext *avctx)
+{
+    int ret = 0;
+
+    entangled_thread_counter--;
+    /* Release any user-supplied mutex. */
+    if (ff_lockmgr_cb) {
+        (*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_RELEASE);
+    }
+
+    ret = avcodec_close(avctx);
+
+    /* If there is a user-supplied mutex locking routine, call it. */
+    if (ff_lockmgr_cb) {
+        if ((*ff_lockmgr_cb)(&codec_mutex, AV_LOCK_OBTAIN))
+            return -1;
+    }
+    entangled_thread_counter++;
+    return ret;
+}
+
 av_cold int avcodec_close(AVCodecContext *avctx)
 {
     /* If there is a user-supplied mutex locking routine, call it. */
diff -uNr ffmpeg-vanilla/libavcodec/internal.h ffmpeg/libavcodec/internal.h
--- ffmpeg-vanilla/libavcodec/internal.h    2012-10-16 18:09:41.247862923 +0100
+++ ffmpeg/libavcodec/internal.h    2012-10-16 17:58:22.764498508 +0100
@@ -178,4 +178,16 @@
 
 int avpriv_h264_has_num_reorder_frames(AVCodecContext *avctx);
 
+/**
+ * Call avcodec_open2 recursively by decrementing counter, unlocking mutex,
+ * calling the function and then restoring again. Assumes the mutex is
+ * already locked
+ */
+int avcodec_open2_recursive(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);
+
+/**
+ * Call avcodec_close recursively, counterpart to avcodec_open2_recursive.
+ */
+int avcodec_close_recursive(AVCodecContext *avctx);
+
 #endif /* AVCODEC_INTERNAL_H */
 		 	   		  


More information about the ffmpeg-devel mailing list