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
145145 int ret = 0;
146146 AVCodecInternal *avci;
147147 const FFCodec *codec2;
148+ const AVDictionaryEntry *e;
148149
149150 if (avcodec_is_open(avctx))
150151 return 0;
@@ -175,8 +176,14 @@ int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code · 24 unmodified lines
175176 if (avctx->extradata_size < 0 || avctx->extradata_size >= FF_MAX_EXTRADATA_SIZE)
176177 return AVERROR(EINVAL);
177178
178− if ((ret = av_opt_set_dict(avctx, options)) < 0)
179− return ret;
179+ // set the whitelist from provided options dict,
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+ }
180187
181188 if (avctx->codec_whitelist && av_match_list(codec->name, avctx->codec_whitelist, ',') <= 0) {
182189 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
211218 av_opt_set_defaults(avctx->priv_data);
212219 }
213220 }
214− if (codec->priv_class && (ret = av_opt_set_dict(avctx->priv_data, options)) < 0)
215− goto free_and_end;
216221 } else {
217222 avctx->priv_data = NULL;
218223 }
219224
225+ ret = av_opt_set_dict2(avctx, options, AV_OPT_SEARCH_CHILDREN);
226+ if (ret < 0)
227+ goto free_and_end;
228+
220229 // only call ff_set_dimensions() for non H.264/VP6F/DXV codecs so as not to overwrite previously setup dimensions
221230 if (!(avctx->coded_width && avctx->coded_height && avctx->width && avctx->height &&
222231 (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