History

lavfi: check the validity of formats lists.

Part of the code expects valid lists, in particular no duplicates. These tests allow to catch bugs in filters (unlikely but possible) and to give a clear message when the error comes from the user ((a)formats) or the application (buffersink). If we decide to switch to a more efficient merging algorithm, possibly sorting the lists, these functions will be the preferred place for pre-processing, and can be renamed accordingly.

Nicolas George committed 6 years ago

Commit 69f5f6e1 parent 6479f403 files · +148 −0Browse files

Showing the changes to libavfilter/avfiltergraph.c (1 of 3 files). Show all

Unified · Split

libavfilter/avfiltergraph.c+50−0
@@ -313,6 +313,53 @@ static void sanitize_channel_layouts(void *log, AVFilterChannelLayouts *l) · 312 unmodified lines
313313 }
314314 }
315315
316+static int filter_link_check_formats(void *log, AVFilterLink *link, AVFilterFormatsConfig *cfg)
317+{
318+ int ret;
319+
320+ switch (link->type) {
321+
322+ case AVMEDIA_TYPE_VIDEO:
323+ if ((ret = ff_formats_check_pixel_formats(log, cfg->formats)) < 0)
324+ return ret;
325+ break;
326+
327+ case AVMEDIA_TYPE_AUDIO:
328+ if ((ret = ff_formats_check_sample_formats(log, cfg->formats)) < 0 ||
329+ (ret = ff_formats_check_sample_rates(log, cfg->samplerates)) < 0 ||
330+ (ret = ff_formats_check_channel_layouts(log, cfg->channel_layouts)) < 0)
331+ return ret;
332+ break;
333+
334+ default:
335+ av_assert0(!"reached");
336+ }
337+ return 0;
338+}
339+
340+/**
341+ * Check the validity of the formats / etc. lists set by query_formats().
342+ *
343+ * In particular, check they do not contain any redundant element.
344+ */
345+static int filter_check_formats(AVFilterContext *ctx)
346+{
347+ unsigned i;
348+ int ret;
349+
350+ for (i = 0; i < ctx->nb_inputs; i++) {
351+ ret = filter_link_check_formats(ctx, ctx->inputs[i], &ctx->inputs[i]->outcfg);
352+ if (ret < 0)
353+ return ret;
354+ }
355+ for (i = 0; i < ctx->nb_outputs; i++) {
356+ ret = filter_link_check_formats(ctx, ctx->outputs[i], &ctx->outputs[i]->incfg);
357+ if (ret < 0)
358+ return ret;
359+ }
360+ return 0;
361+}
362+
316363 static int filter_query_formats(AVFilterContext *ctx)
317364 {
318365 int ret, i;
@@ -329,6 +376,9 @@ static int filter_query_formats(AVFilterContext *ctx) · 10 unmodified lines
329376 ctx->name, av_err2str(ret));
330377 return ret;
331378 }
379+ ret = filter_check_formats(ctx);
380+ if (ret < 0)
381+ return ret;
332382
333383 for (i = 0; i < ctx->nb_inputs; i++)
334384 sanitize_channel_layouts(ctx, ctx->inputs[i]->outcfg.channel_layouts);

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