[FFmpeg-cvslog] lavc: enable recursively using avcodec_open2/close.
Ash Hughes
git at videolan.org
Fri Oct 19 18:20:13 CEST 2012
ffmpeg | branch: master | Ash Hughes <ashes-iontach at hotmail.com> | Fri Oct 19 01:12:56 2012 +0000| [2470851f1228006473d9ce825604aa1cfe1c5916] | committer: Michael Niedermayer
lavc: enable recursively using avcodec_open2/close.
Signed-off-by: Michael Niedermayer <michaelni at gmx.at>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=2470851f1228006473d9ce825604aa1cfe1c5916
---
libavcodec/internal.h | 12 ++++++++++++
libavcodec/utils.c | 42 ++++++++++++++++++++++++++++++++++++++++++
2 files changed, 54 insertions(+)
diff --git a/libavcodec/internal.h b/libavcodec/internal.h
index ed38c61..9a8b4bc 100644
--- a/libavcodec/internal.h
+++ b/libavcodec/internal.h
@@ -178,4 +178,16 @@ int ff_get_logical_cpus(AVCodecContext *avctx);
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 ff_codec_open2_recursive(AVCodecContext *avctx, const AVCodec *codec, AVDictionary **options);
+
+/**
+ * Call avcodec_close recursively, counterpart to avcodec_open2_recursive.
+ */
+int ff_codec_close_recursive(AVCodecContext *avctx);
+
#endif /* AVCODEC_INTERNAL_H */
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index a238e62..926fdee 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -798,6 +798,27 @@ int attribute_align_arg avcodec_open(AVCodecContext *avctx, AVCodec *codec)
}
#endif
+int attribute_align_arg ff_codec_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 @@ void avsubtitle_free(AVSubtitle *sub)
memset(sub, 0, sizeof(AVSubtitle));
}
+av_cold int ff_codec_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. */
More information about the ffmpeg-cvslog
mailing list