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.
Unified · Split
| @@ -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); |