Browse Source

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 af08d9aeea)

Conflicts:

	doc/APIchanges
tags/n0.10.1
Anton Khirnov 14 years ago
parent
commit
350d06d63f
6 changed files with 21 additions and 5 deletions
  1. +3
    -0
      doc/APIchanges
  2. +6
    -0
      libavcodec/avcodec.h
  3. +1
    -1
      libavcodec/options.c
  4. +8
    -0
      libavcodec/utils.c
  5. +1
    -1
      libavcodec/version.h
  6. +2
    -3
      libavformat/utils.c

+ 3
- 0
doc/APIchanges View File

@@ -13,6 +13,9 @@ libavutil: 2011-04-18

API changes, most recent first:

2012-02-17 - xxxxxxx - lavc 53.35.0
Add avcodec_is_open() function.

2012-01-15 - lavc 53.34.0
New audio encoding API:
b2c75b6 Add CODEC_CAP_VARIABLE_FRAME_SIZE capability for use by audio


+ 6
- 0
libavcodec/avcodec.h View File

@@ -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 */

+ 1
- 1
libavcodec/options.c View File

@@ -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);


+ 8
- 0
libavcodec/utils.c View File

@@ -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;
}

+ 1
- 1
libavcodec/version.h View File

@@ -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, \


+ 2
- 3
libavformat/utils.c View File

@@ -2137,7 +2137,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);
@@ -2487,8 +2487,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];


Loading…
Cancel
Save