aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2011-12-08 06:57:44 +0100
committerAnton Khirnov <anton@khirnov.net>2012-02-26 09:03:33 +0100
commit350d06d63fc758d047c050e0835f540277799f60 (patch)
treec75ebcb075a3b5edab209a8158504c366155ca37 /libavcodec
parent4b63cc18bc44517f0f9e04b39ab873cbc3c6aee5 (diff)
downloadffmpeg-350d06d63fc758d047c050e0835f540277799f60.tar.gz
lavc: add avcodec_is_open().
It allows to check whether an AVCodecContext is open in a documented way. Right now the undocumented way this check is done in lavf/lavc is by checking whether AVCodecContext.codec is NULL. However it's desirable to be able to set AVCodecContext.codec before avcodec_open2(). (cherry picked from commit af08d9aeea870de017139f7b1c44b7d816cf8e56) Conflicts: doc/APIchanges
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/avcodec.h6
-rw-r--r--libavcodec/options.c2
-rw-r--r--libavcodec/utils.c8
-rw-r--r--libavcodec/version.h2
4 files changed, 16 insertions, 2 deletions
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index be1b2021bd..6db34fa78e 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -4737,4 +4737,10 @@ enum AVMediaType avcodec_get_type(enum CodecID codec_id);
*/
const AVClass *avcodec_get_class(void);
+/**
+ * @return a positive value if s is open (i.e. avcodec_open2() was called on it
+ * with no corresponding avcodec_close()), 0 otherwise.
+ */
+int avcodec_is_open(AVCodecContext *s);
+
#endif /* AVCODEC_AVCODEC_H */
diff --git a/libavcodec/options.c b/libavcodec/options.c
index 2689d32a92..7481f1a685 100644
--- a/libavcodec/options.c
+++ b/libavcodec/options.c
@@ -634,7 +634,7 @@ AVCodecContext *avcodec_alloc_context(void){
int avcodec_copy_context(AVCodecContext *dest, const AVCodecContext *src)
{
- if (dest->codec) { // check that the dest context is uninitialized
+ if (avcodec_is_open(dest)) { // check that the dest context is uninitialized
av_log(dest, AV_LOG_ERROR,
"Tried to copy AVCodecContext %p into already-initialized %p\n",
src, dest);
diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index ff3f065064..b097c9b421 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -637,6 +637,9 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVD
int ret = 0;
AVDictionary *tmp = NULL;
+ if (avcodec_is_open(avctx))
+ return 0;
+
if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
return AVERROR(EINVAL);
@@ -1836,3 +1839,8 @@ enum AVMediaType avcodec_get_type(enum CodecID codec_id)
return AVMEDIA_TYPE_UNKNOWN;
}
+
+int avcodec_is_open(AVCodecContext *s)
+{
+ return !!s->internal;
+}
diff --git a/libavcodec/version.h b/libavcodec/version.h
index c7b4c15b7a..77e16823f9 100644
--- a/libavcodec/version.h
+++ b/libavcodec/version.h
@@ -21,7 +21,7 @@
#define AVCODEC_VERSION_H
#define LIBAVCODEC_VERSION_MAJOR 53
-#define LIBAVCODEC_VERSION_MINOR 34
+#define LIBAVCODEC_VERSION_MINOR 35
#define LIBAVCODEC_VERSION_MICRO 0
#define LIBAVCODEC_VERSION_INT AV_VERSION_INT(LIBAVCODEC_VERSION_MAJOR, \