History

lavfi/buffersink: move the option sanity check to init

Options are set before init, so that is the appropriate place to validate them.

Anton Khirnov committed 2 years ago

Commit 2aad37f1 parent eff9ed71 file · +35 −25Browse files

Unified · Split

libavfilter/buffersink.c+35−25
@@ -155,6 +155,41 @@ static av_cold int common_init(AVFilterContext *ctx) · 154 unmodified lines
155155 {
156156 BufferSinkContext *buf = ctx->priv;
157157
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+
158193 buf->warning_limit = 100;
159194 return 0;
160195 }
@@ -291,14 +326,6 @@ int av_buffersink_get_ch_layout(const AVFilterContext *ctx, AVChannelLayout *out · 130 unmodified lines
291326
292327 #if FF_API_BUFFERSINK_OPTS
293328 #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− }
302329 #endif
303330
304331 static int vsink_query_formats(AVFilterContext *ctx)
@@ -307,12 +334,6 @@ static int vsink_query_formats(AVFilterContext *ctx) · 2 unmodified lines
307334 int ret;
308335
309336 #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−
316337 if (buf->nb_pixel_formats || buf->nb_colorspaces || buf->nb_colorranges) {
317338 #endif
318339 if (buf->nb_pixel_formats) {
@@ -333,9 +354,6 @@ static int vsink_query_formats(AVFilterContext *ctx) · 14 unmodified lines
333354 #if FF_API_BUFFERSINK_OPTS
334355 } else {
335356 unsigned i;
336− CHECK_LIST_SIZE(pixel_fmts)
337− CHECK_LIST_SIZE(color_spaces)
338− CHECK_LIST_SIZE(color_ranges)
339357 if (buf->pixel_fmts_size) {
340358 AVFilterFormats *formats = NULL;
341359 for (i = 0; i < NB_ITEMS(buf->pixel_fmts); i++)
@@ -374,12 +392,6 @@ static int asink_query_formats(AVFilterContext *ctx) · 32 unmodified lines
374392 int ret;
375393
376394 #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−
383395 if (buf->nb_sample_formats || buf->nb_samplerates || buf->nb_channel_layouts) {
384396 #endif
385397 if (buf->nb_sample_formats) {
@@ -403,8 +415,6 @@ static int asink_query_formats(AVFilterContext *ctx) · 17 unmodified lines
403415 AVChannelLayout layout = { 0 };
404416 AVFilterChannelLayouts *layouts = NULL;
405417 unsigned i;
406− CHECK_LIST_SIZE(sample_fmts)
407− CHECK_LIST_SIZE(sample_rates)
408418
409419 if (buf->sample_fmts_size) {
410420 for (i = 0; i < NB_ITEMS(buf->sample_fmts); i++)

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