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
158158 codec = avctx->codec;
159159 codec2 = ffcodec(codec);
160160
161− if ((avctx->codec_type == AVMEDIA_TYPE_UNKNOWN || avctx->codec_type == codec->type) &&
162− avctx->codec_id == AV_CODEC_ID_NONE) {
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)) {
161+ if ((avctx->codec_type != AVMEDIA_TYPE_UNKNOWN && avctx->codec_type != codec->type) ||
162+ (avctx->codec_id != AV_CODEC_ID_NONE && avctx->codec_id != codec->id)) {
168163 av_log(avctx, AV_LOG_ERROR, "Codec type or id mismatches\n");
169164 return AVERROR(EINVAL);
170165 }
171− avctx->codec = codec;
166+
167+ avctx->codec_type = codec->type;
168+ avctx->codec_id = codec->id;
169+ avctx->codec = codec;
172170
173171 if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
174172 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