History

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.

Anton Khirnov committed 4 years ago

Commit 7efa6411 parent 4a7c8bb1 file · +6 −8Browse files

Unified · Split

libavcodec/avcodec.c+6−8
@@ -158,17 +158,15 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code · 157 unmodified lines
158 codec = avctx->codec;158 codec = avctx->codec;
159 codec2 = ffcodec(codec);159 codec2 = ffcodec(codec);
160 160
161 if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&161 if ((avctx->codec_type != AVMEDIA_TYPE_UNKNOWN && avctx->codec_type != codec->type) ||
162 avctx->codec_id == AV_CODEC_ID_NONE) {162 (avctx->codec_id != AV_CODEC_ID_NONE && avctx->codec_id != codec->id)) {
163 avctx->codec_type = codec->type;
164 avctx->codec_id = codec->id;
165 }
166 if (avctx->codec_id != codec->id || (avctx->codec_type != codec->type &&
167 avctx->codec_type != AVMEDIA_TYPE_ATTACHMENT)) {
168 av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n");163 av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n");
169 return AVERROR(EINVAL);164 return AVERROR(EINVAL);
170 }165 }
171 avctx->codec = codec;166
167 avctx->codec_type = codec->type;
168 avctx->codec_id = codec->id;
169 avctx->codec = codec;
172 170
173 if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)171 if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
174 return AVERROR(EINVAL);172 return AVERROR(EINVAL);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t