History

lavc/avcodec: fix global/private option precendence

Broken after 7753a9d62725d5bd8313e2d249acbe1c8af79ab1. Apply only the whitelist early, and the rest with a single call to av_opt_set_dict2() with AV_OPT_SEARCH_CHILDREN, which should be equivalent to the original behaviour.

Anton Khirnov committed 2 years ago

Commit 9ce63e61 parent c961a721 file · +13 −4Browse files

Unified · Split

libavcodec/avcodec.c+13−4
@@ -145,6 +145,7 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code · 144 unmodified lines
145 int ret = 0;145 int ret = 0;
146 AVCodecInternal *avci;146 AVCodecInternal *avci;
147 const FFCodec *codec2;147 const FFCodec *codec2;
148 const AVDictionaryEntry *e;
148 149
149 if (avcodec_is_open(avctx))150 if (avcodec_is_open(avctx))
150 return 0;151 return 0;
@@ -175,8 +176,14 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code · 24 unmodified lines
175 if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)176 if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
176 return AVERROR(EINVAL);177 return AVERROR(EINVAL);
177 178
178 if ((ret = av_opt_set_dict(avctx, options)) < 0)179 // set the whitelist from provided options dict,
179 return ret;180 // so we can check it immediately
181 e = options ? av_dict_get(*options, "codec_whitelist", NULL, 0) : NULL;
182 if (e) {
183 ret = av_opt_set(avctx, e->key, e->value, 0);
184 if (ret < 0)
185 return ret;
186 }
180 187
181 if (avctx->codec_whitelist && av_match_list(codec->name, avctx->codec_whitelist, ',') <= 0) {188 if (avctx->codec_whitelist && av_match_list(codec->name, avctx->codec_whitelist, ',') <= 0) {
182 av_log(avctx, AV_LOG_ERROR, "Codec (%s) not on whitelist \'%s\'\n", codec->name, avctx->codec_whitelist);189 av_log(avctx, AV_LOG_ERROR, "Codec (%s) not on whitelist \'%s\'\n", codec->name, avctx->codec_whitelist);
@@ -211,12 +218,14 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code · 28 unmodified lines
211 av_opt_set_defaults(avctx->priv_data);218 av_opt_set_defaults(avctx->priv_data);
212 }219 }
213 }220 }
214 if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, options)) < 0)
215 goto free_and_end;
216 } else {221 } else {
217 avctx->priv_data = NULL;222 avctx->priv_data = NULL;
218 }223 }
219 224
225 ret = av_opt_set_dict2(avctx, options, AV_OPT_SEARCH_CHILDREN);
226 if (ret < 0)
227 goto free_and_end;
228
220 // only call ff_set_dimensions() for non H.264/VP6F/DXV codecs so as not to overwrite previously setup dimensions229 // only call ff_set_dimensions() for non H.264/VP6F/DXV codecs so as not to overwrite previously setup dimensions
221 if (!(avctx->coded_width && avctx->coded_height && avctx->width && avctx->height &&230 if (!(avctx->coded_width && avctx->coded_height && avctx->width && avctx->height &&
222 (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_VP6F || avctx->codec_id == AV_CODEC_ID_DXV))) {231 (avctx->codec_id == AV_CODEC_ID_H264 || avctx->codec_id == AV_CODEC_ID_VP6F || avctx->codec_id == AV_CODEC_ID_DXV))) {

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