diff --git a/doc/APIchanges b/doc/APIchanges index 7545fa51dce7dacf3a46a43055946d9ba1053473..87de464ebbc15bb023e533b5604bf0c127016ddd 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -13,6 +13,9 @@ libavutil: 2011-04-18 API changes, most recent first: +2012-01-31 - xxxxxxx - lavc 54.01.0 + Add avcodec_is_open() function. + 2012-01-30 - xxxxxxx - lavu 51.22.0 - intfloat.h Add a new installed header libavutil/intfloat.h with int/float punning functions. diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index a6bb6863f2d4f51562d18a84595087ffca17a0f4..284c7f8cb821251437ae418576b0fe09449e5159 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -4183,4 +4183,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 c416b4aa4f18b2564a61f9fc4aa7caab56f040bf..52fc66400a1f232bb00243c5958208867213cb19 100644 --- a/libavcodec/options.c +++ b/libavcodec/options.c @@ -485,7 +485,7 @@ AVCodecContext *avcodec_alloc_context3(AVCodec *codec){ 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 34a4122d5d93f381e36976527e3077d9d9baa028..3ee6b09f748b76210ef1aeb4eedbd9a1aa039efc 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -627,6 +627,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); @@ -1803,3 +1806,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/libavformat/utils.c b/libavformat/utils.c index 9c59947fb719ab8eaae9885fdbf09516363c85f6..1b2239a068f9af787c719171d285e392437b6eb0 100644 --- a/libavformat/utils.c +++ b/libavformat/utils.c @@ -2006,7 +2006,7 @@ static int try_decode_frame(AVStream *st, AVPacket *avpkt, AVDictionary **option AVFrame picture; AVPacket pkt = *avpkt; - if(!st->codec->codec){ + if (!avcodec_is_open(st->codec)) { AVDictionary *thread_opt = NULL; codec = avcodec_find_decoder(st->codec->codec_id); @@ -2354,8 +2354,7 @@ int avformat_find_stream_info(AVFormatContext *ic, AVDictionary **options) // close codecs which were opened in try_decode_frame() for(i=0;i<ic->nb_streams;i++) { st = ic->streams[i]; - if(st->codec->codec) - avcodec_close(st->codec); + avcodec_close(st->codec); } for(i=0;i<ic->nb_streams;i++) { st = ic->streams[i];