Options are set before init, so that is the appropriate place to validate them.
Unified · Split
| @@ -155,6 +155,41 @@ static av_cold int common_init(AVFilterContext *ctx) · 154 unmodified lines | ||
| 155 | 155 | { |
| 156 | 156 | BufferSinkContext *buf = ctx->priv; |
| 157 | 157 | |
| 158 | +#if FF_API_BUFFERSINK_OPTS | |
| 159 | + | |
| 160 | +#define CHECK_LIST_SIZE(field) \ | |
| 161 | + if (buf->field ## _size % sizeof(*buf->field)) { \ | |
| 162 | + av_log(ctx, AV_LOG_ERROR, "Invalid size for " #field ": %d, " \ | |
| 163 | + "should be multiple of %d\n", \ | |
| 164 | + buf->field ## _size, (int)sizeof(*buf->field)); \ | |
| 165 | + return AVERROR(EINVAL); \ | |
| 166 | + } | |
| 167 | + | |
| 168 | + if (ctx->input_pads[0].type == AVMEDIA_TYPE_VIDEO) { | |
| 169 | + if ((buf->pixel_fmts_size || buf->color_spaces_size || buf->color_ranges_size) && | |
| 170 | + (buf->nb_pixel_formats || buf->nb_colorspaces || buf->nb_colorranges)) { | |
| 171 | + av_log(ctx, AV_LOG_ERROR, "Cannot combine old and new format lists\n"); | |
| 172 | + return AVERROR(EINVAL); | |
| 173 | + } | |
| 174 | + | |
| 175 | + CHECK_LIST_SIZE(pixel_fmts) | |
| 176 | + CHECK_LIST_SIZE(color_spaces) | |
| 177 | + CHECK_LIST_SIZE(color_ranges) | |
| 178 | + } else { | |
| 179 | + if ((buf->sample_fmts_size || buf->channel_layouts_str || buf->sample_rates_size) && | |
| 180 | + (buf->nb_sample_formats || buf->nb_samplerates || buf->nb_channel_layouts)) { | |
| 181 | + av_log(ctx, AV_LOG_ERROR, "Cannot combine old and new format lists\n"); | |
| 182 | + return AVERROR(EINVAL); | |
| 183 | + } | |
| 184 | + | |
| 185 | + CHECK_LIST_SIZE(sample_fmts) | |
| 186 | + CHECK_LIST_SIZE(sample_rates) | |
| 187 | + } | |
| 188 | + | |
| 189 | +#undef CHECK_LIST_SIZE | |
| 190 | + | |
| 191 | +#endif | |
| 192 | + | |
| 158 | 193 | buf->warning_limit = 100; |
| 159 | 194 | return 0; |
| 160 | 195 | } |
| @@ -291,14 +326,6 @@ int av_buffersink_get_ch_layout(const AVFilterContext *ctx, AVChannelLayout *out · 130 unmodified lines | ||
| 291 | 326 | |
| 292 | 327 | #if FF_API_BUFFERSINK_OPTS |
| 293 | 328 | #define NB_ITEMS(list) (list ## _size / sizeof(*list)) |
| 294 | − | |
| 295 | −#define CHECK_LIST_SIZE(field) \ | |
| 296 | − if (buf->field ## _size % sizeof(*buf->field)) { \ | |
| 297 | − av_log(ctx, AV_LOG_ERROR, "Invalid size for " #field ": %d, " \ | |
| 298 | − "should be multiple of %d\n", \ | |
| 299 | − buf->field ## _size, (int)sizeof(*buf->field)); \ | |
| 300 | − return AVERROR(EINVAL); \ | |
| 301 | − } | |
| 302 | 329 | #endif |
| 303 | 330 | |
| 304 | 331 | static int vsink_query_formats(AVFilterContext *ctx) |
| @@ -307,12 +334,6 @@ static int vsink_query_formats(AVFilterContext *ctx) · 2 unmodified lines | ||
| 307 | 334 | int ret; |
| 308 | 335 | |
| 309 | 336 | #if FF_API_BUFFERSINK_OPTS |
| 310 | − if ((buf->pixel_fmts_size || buf->color_spaces_size || buf->color_ranges_size) && | |
| 311 | − (buf->nb_pixel_formats || buf->nb_colorspaces || buf->nb_colorranges)) { | |
| 312 | − av_log(ctx, AV_LOG_ERROR, "Cannot combine old and new format lists\n"); | |
| 313 | − return AVERROR(EINVAL); | |
| 314 | − } | |
| 315 | − | |
| 316 | 337 | if (buf->nb_pixel_formats || buf->nb_colorspaces || buf->nb_colorranges) { |
| 317 | 338 | #endif |
| 318 | 339 | if (buf->nb_pixel_formats) { |
| @@ -333,9 +354,6 @@ static int vsink_query_formats(AVFilterContext *ctx) · 14 unmodified lines | ||
| 333 | 354 | #if FF_API_BUFFERSINK_OPTS |
| 334 | 355 | } else { |
| 335 | 356 | unsigned i; |
| 336 | − CHECK_LIST_SIZE(pixel_fmts) | |
| 337 | − CHECK_LIST_SIZE(color_spaces) | |
| 338 | − CHECK_LIST_SIZE(color_ranges) | |
| 339 | 357 | if (buf->pixel_fmts_size) { |
| 340 | 358 | AVFilterFormats *formats = NULL; |
| 341 | 359 | for (i = 0; i < NB_ITEMS(buf->pixel_fmts); i++) |
| @@ -374,12 +392,6 @@ static int asink_query_formats(AVFilterContext *ctx) · 32 unmodified lines | ||
| 374 | 392 | int ret; |
| 375 | 393 | |
| 376 | 394 | #if FF_API_BUFFERSINK_OPTS |
| 377 | − if ((buf->sample_fmts_size || buf->channel_layouts_str || buf->sample_rates_size) && | |
| 378 | − (buf->nb_sample_formats || buf->nb_samplerates || buf->nb_channel_layouts)) { | |
| 379 | − av_log(ctx, AV_LOG_ERROR, "Cannot combine old and new format lists\n"); | |
| 380 | − return AVERROR(EINVAL); | |
| 381 | − } | |
| 382 | − | |
| 383 | 395 | if (buf->nb_sample_formats || buf->nb_samplerates || buf->nb_channel_layouts) { |
| 384 | 396 | #endif |
| 385 | 397 | if (buf->nb_sample_formats) { |
| @@ -403,8 +415,6 @@ static int asink_query_formats(AVFilterContext *ctx) · 17 unmodified lines | ||
| 403 | 415 | AVChannelLayout layout = { 0 }; |
| 404 | 416 | AVFilterChannelLayouts *layouts = NULL; |
| 405 | 417 | unsigned i; |
| 406 | − CHECK_LIST_SIZE(sample_fmts) | |
| 407 | − CHECK_LIST_SIZE(sample_rates) | |
| 408 | 418 | |
| 409 | 419 | if (buf->sample_fmts_size) { |
| 410 | 420 | for (i = 0; i < NB_ITEMS(buf->sample_fmts); i++) |