diff options
author | Anton Khirnov <anton@khirnov.net> | 2012-01-28 19:15:15 +0100 |
---|---|---|
committer | Anton Khirnov <anton@khirnov.net> | 2012-01-31 16:53:35 +0100 |
commit | bc901998487bf9b77a423961d9f961bcc28a9291 (patch) | |
tree | 10fc23398897ab2e4294e11d3af307d091b3beeb /libavcodec/utils.c | |
parent | 0e72ad95f9fef6a6b8ae55e47339a5c40526502f (diff) | |
download | ffmpeg-bc901998487bf9b77a423961d9f961bcc28a9291.tar.gz |
lavc: set AVCodecContext.codec in avcodec_get_context_defaults3().
This way, if the AVCodecContext is allocated for a specific codec, the
caller doesn't need to store this codec separately and then pass it
again to avcodec_open2().
It also allows to set codec private options using av_opt_set_* before
opening the codec.
Diffstat (limited to 'libavcodec/utils.c')
-rw-r--r-- | libavcodec/utils.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/libavcodec/utils.c b/libavcodec/utils.c index 9cdae22305..fa609534a5 100644 --- a/libavcodec/utils.c +++ b/libavcodec/utils.c @@ -630,6 +630,18 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVD if (avcodec_is_open(avctx)) return 0; + if ((!codec && !avctx->codec)) { + av_log(avctx, AV_LOG_ERROR, "No codec provided to avcodec_open2().\n"); + return AVERROR(EINVAL); + } + if ((codec && avctx->codec && codec != avctx->codec)) { + av_log(avctx, AV_LOG_ERROR, "This AVCodecContext was allocated for %s, " + "but %s passed to avcodec_open2().\n", avctx->codec->name, codec->name); + return AVERROR(EINVAL); + } + if (!codec) + codec = avctx->codec; + if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE) return AVERROR(EINVAL); @@ -649,11 +661,6 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, AVCodec *codec, AVD goto end; } - if(avctx->codec || !codec) { - ret = AVERROR(EINVAL); - goto end; - } - avctx->internal = av_mallocz(sizeof(AVCodecInternal)); if (!avctx->internal) { ret = AVERROR(ENOMEM); |