aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2022-03-23 14:11:03 +0100
committerAnton Khirnov <anton@khirnov.net>2022-04-13 12:13:15 +0200
commit7efa6418b83ae123770c6930f492edb87cd19274 (patch)
tree098a910685f0e9c920c18b54413a011b6a8008fb /libavcodec
parent4a7c8bb3d8cc793dab8baf110c1562980c4a3165 (diff)
downloadffmpeg-7efa6418b83ae123770c6930f492edb87cd19274.tar.gz
lavc/avcodec: simplify codec id/type validity checking
On entry to avcodec_open2(), the AVCodecContext type and id either have to be UNKNOWN/NONE or have to match the codec to be used.
Diffstat (limited to 'libavcodec')
-rw-r--r--libavcodec/avcodec.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/libavcodec/avcodec.c b/libavcodec/avcodec.c
index fbe4a5e413..dbaa9f78a2 100644
--- a/libavcodec/avcodec.c
+++ b/libavcodec/avcodec.c
@@ -158,17 +158,15 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
codec = avctx->codec;
codec2 = ffcodec(codec);
- if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
- avctx->codec_id == AV_CODEC_ID_NONE) {
- avctx->codec_type = codec->type;
- avctx->codec_id = codec->id;
- }
- if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type &&
- avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {
+ if ((avctx->codec_type != AVMEDIA_TYPE_UNKNOWN && avctx->codec_type != codec->type) ||
+ (avctx->codec_id != AV_CODEC_ID_NONE && avctx->codec_id != codec->id)) {
av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n");
return AVERROR(EINVAL);
}
- avctx->codec = codec;
+
+ avctx->codec_type = codec->type;
+ avctx->codec_id = codec->id;
+ avctx->codec = codec;
if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
return AVERROR(EINVAL);