Commit 6aaac24d authored by Ganesh Ajjanagadde's avatar Ganesh Ajjanagadde

avfilter/all: propagate errors of functions from avfilter/formats

Many of the functions from avfilter/formats can return errors, usually AVERROR(ENOMEM).
This propagates the return values.

All of these were found by using av_warn_unused_result, demonstrating its utility.

Tested with FATE. I am least sure of the changes to avfilter/filtergraph,
since I don't know what/how reduce_format is intended to behave and how it should
react to errors.

Fixes: CID 1325680, 1325679, 1325678.
Reviewed-by: 's avatarMichael Niedermayer <michael@niedermayer.cc>
Previous version Reviewed-by: Nicolas George <george@nsup.org>
Previous version Reviewed-by: Clément Bœsch <u@pkh.me>
Signed-off-by: 's avatarGanesh Ajjanagadde <gajjanagadde@gmail.com>
parent 8ededd58
......@@ -350,36 +350,34 @@ static int aeval_query_formats(AVFilterContext *ctx)
static const enum AVSampleFormat sample_fmts[] = {
AV_SAMPLE_FMT_DBLP, AV_SAMPLE_FMT_NONE
};
int ret;
// inlink supports any channel layout
layouts = ff_all_channel_counts();
ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
return ret;
if (eval->same_chlayout) {
layouts = ff_all_channel_counts();
if (!layouts)
return AVERROR(ENOMEM);
ff_set_common_channel_layouts(ctx, layouts);
if ((ret = ff_set_common_channel_layouts(ctx, layouts)) < 0)
return ret;
} else {
// outlink supports only requested output channel layout
layouts = NULL;
ff_add_channel_layout(&layouts,
if ((ret = ff_add_channel_layout(&layouts,
eval->out_channel_layout ? eval->out_channel_layout :
FF_COUNT2LAYOUT(eval->nb_channels));
ff_channel_layouts_ref(layouts, &outlink->in_channel_layouts);
FF_COUNT2LAYOUT(eval->nb_channels))) < 0)
return ret;
if ((ret = ff_channel_layouts_ref(layouts, &outlink->in_channel_layouts)) < 0)
return ret;
}
formats = ff_make_format_list(sample_fmts);
if (!formats)
return AVERROR(ENOMEM);
ff_set_common_formats(ctx, formats);
if ((ret = ff_set_common_formats(ctx, formats)) < 0)
return ret;
formats = ff_all_samplerates();
if (!formats)
return AVERROR(ENOMEM);
ff_set_common_samplerates(ctx, formats);
return 0;
return ff_set_common_samplerates(ctx, formats);
}
static int aeval_config_output(AVFilterLink *outlink)
......
......@@ -57,9 +57,10 @@ static const AVOption aformat_options[] = {
AVFILTER_DEFINE_CLASS(aformat);
#define PARSE_FORMATS(str, type, list, add_to_list, get_fmt, none, desc) \
#define PARSE_FORMATS(str, type, list, add_to_list, unref_fn, get_fmt, none, desc) \
do { \
char *next, *cur = str, sep; \
int ret; \
\
if (str && strchr(str, ',')) { \
av_log(ctx, AV_LOG_WARNING, "This syntax is deprecated, use '|' to "\
......@@ -78,7 +79,10 @@ do { \
av_log(ctx, AV_LOG_ERROR, "Error parsing " desc ": %s.\n", cur);\
return AVERROR(EINVAL); \
} \
add_to_list(&list, fmt); \
if ((ret = add_to_list(&list, fmt)) < 0) { \
unref_fn(&list); \
return ret; \
} \
\
cur = next; \
} \
......@@ -95,11 +99,11 @@ static av_cold int init(AVFilterContext *ctx)
AFormatContext *s = ctx->priv;
PARSE_FORMATS(s->formats_str, enum AVSampleFormat, s->formats,
ff_add_format, av_get_sample_fmt, AV_SAMPLE_FMT_NONE, "sample format");
PARSE_FORMATS(s->sample_rates_str, int, s->sample_rates, ff_add_format,
ff_add_format, ff_formats_unref, av_get_sample_fmt, AV_SAMPLE_FMT_NONE, "sample format");
PARSE_FORMATS(s->sample_rates_str, int, s->sample_rates, ff_add_format, ff_formats_unref,
get_sample_rate, 0, "sample rate");
PARSE_FORMATS(s->channel_layouts_str, uint64_t, s->channel_layouts,
ff_add_channel_layout, av_get_channel_layout, 0,
ff_add_channel_layout, ff_channel_layouts_unref, av_get_channel_layout, 0,
"channel layout");
return 0;
......
......@@ -77,7 +77,8 @@ static int query_formats(AVFilterContext *ctx)
AVFilterChannelLayouts *layouts;
int ret;
ff_add_format(&formats, AV_SAMPLE_FMT_DBL);
if ((ret = ff_add_format(&formats, AV_SAMPLE_FMT_DBL)) < 0)
return ret;
ret = ff_set_common_formats(ctx, formats);
if (ret < 0)
return ret;
......
......@@ -78,7 +78,7 @@ static int query_formats(AVFilterContext *ctx)
int64_t inlayout[SWR_CH_MAX], outlayout = 0;
AVFilterFormats *formats;
AVFilterChannelLayouts *layouts;
int i, overlap = 0, nb_ch = 0;
int i, ret, overlap = 0, nb_ch = 0;
for (i = 0; i < s->nb_inputs; i++) {
if (!ctx->inputs[i]->in_channel_layouts ||
......@@ -125,17 +125,22 @@ static int query_formats(AVFilterContext *ctx)
*(route[i]++) = out_ch_number++;
}
formats = ff_make_format_list(ff_packed_sample_fmts_array);
ff_set_common_formats(ctx, formats);
if ((ret = ff_set_common_formats(ctx, formats)) < 0)
return ret;
for (i = 0; i < s->nb_inputs; i++) {
layouts = NULL;
ff_add_channel_layout(&layouts, inlayout[i]);
ff_channel_layouts_ref(layouts, &ctx->inputs[i]->out_channel_layouts);
if ((ret = ff_add_channel_layout(&layouts, inlayout[i])) < 0)
return ret;
if ((ret = ff_channel_layouts_ref(layouts, &ctx->inputs[i]->out_channel_layouts)) < 0)
return ret;
}
layouts = NULL;
ff_add_channel_layout(&layouts, outlayout);
ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts);
ff_set_common_samplerates(ctx, ff_all_samplerates());
return 0;
if ((ret = ff_add_channel_layout(&layouts, outlayout)) < 0)
return ret;
if ((ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts)) < 0)
return ret;
return ff_set_common_samplerates(ctx, ff_all_samplerates());
}
static int config_output(AVFilterLink *outlink)
......
......@@ -537,12 +537,13 @@ static int query_formats(AVFilterContext *ctx)
int ret;
layouts = ff_all_channel_layouts();
if (!layouts)
return AVERROR(ENOMEM);
ff_add_format(&formats, AV_SAMPLE_FMT_FLT);
ff_add_format(&formats, AV_SAMPLE_FMT_FLTP);
if ((ret = ff_add_format(&formats, AV_SAMPLE_FMT_FLT)) < 0)
return ret;
if ((ret = ff_add_format(&formats, AV_SAMPLE_FMT_FLTP)) < 0)
return ret;
ret = ff_set_common_formats(ctx, formats);
if (ret < 0)
return ret;
......
......@@ -88,25 +88,23 @@ static int query_formats(AVFilterContext *ctx)
AVFilterFormats *in_formats, *out_formats;
AVFilterFormats *in_samplerates, *out_samplerates;
AVFilterChannelLayouts *in_layouts, *out_layouts;
int ret;
av_opt_get_sample_fmt(aresample->swr, "osf", 0, &out_format);
av_opt_get_int(aresample->swr, "osr", 0, &out_rate);
av_opt_get_int(aresample->swr, "ocl", 0, &out_layout);
in_formats = ff_all_formats(AVMEDIA_TYPE_AUDIO);
if (!in_formats)
return AVERROR(ENOMEM);
ff_formats_ref (in_formats, &inlink->out_formats);
if ((ret = ff_formats_ref(in_formats, &inlink->out_formats)) < 0)
return ret;
in_samplerates = ff_all_samplerates();
if (!in_samplerates)
return AVERROR(ENOMEM);
ff_formats_ref (in_samplerates, &inlink->out_samplerates);
if ((ret = ff_formats_ref(in_samplerates, &inlink->out_samplerates)) < 0)
return ret;
in_layouts = ff_all_channel_counts();
if (!in_layouts)
return AVERROR(ENOMEM);
ff_channel_layouts_ref(in_layouts, &inlink->out_channel_layouts);
if ((ret = ff_channel_layouts_ref(in_layouts, &inlink->out_channel_layouts)) < 0)
return ret;
if(out_rate > 0) {
int ratelist[] = { out_rate, -1 };
......@@ -114,28 +112,25 @@ static int query_formats(AVFilterContext *ctx)
} else {
out_samplerates = ff_all_samplerates();
}
if (!out_samplerates) {
av_log(ctx, AV_LOG_ERROR, "Cannot allocate output samplerates.\n");
return AVERROR(ENOMEM);
}
ff_formats_ref(out_samplerates, &outlink->in_samplerates);
if ((ret = ff_formats_ref(out_samplerates, &outlink->in_samplerates)) < 0)
return ret;
if(out_format != AV_SAMPLE_FMT_NONE) {
int formatlist[] = { out_format, -1 };
out_formats = ff_make_format_list(formatlist);
} else
out_formats = ff_all_formats(AVMEDIA_TYPE_AUDIO);
ff_formats_ref(out_formats, &outlink->in_formats);
if ((ret = ff_formats_ref(out_formats, &outlink->in_formats)) < 0)
return ret;
if(out_layout) {
int64_t layout_list[] = { out_layout, -1 };
out_layouts = avfilter_make_format64_list(layout_list);
} else
out_layouts = ff_all_channel_counts();
ff_channel_layouts_ref(out_layouts, &outlink->in_channel_layouts);
return 0;
return ff_channel_layouts_ref(out_layouts, &outlink->in_channel_layouts);
}
......
......@@ -89,20 +89,23 @@ static av_cold int init(AVFilterContext *ctx)
static int query_formats(AVFilterContext *ctx)
{
int i;
int i, ret;
AVFilterFormats *formats, *rates;
AVFilterChannelLayouts *layouts;
for (i = 0; i < 2; i++) {
formats = ctx->inputs[i]->in_formats;
ff_formats_ref(formats, &ctx->inputs[i]->out_formats);
ff_formats_ref(formats, &ctx->outputs[i]->in_formats);
if ((ret = ff_formats_ref(formats, &ctx->inputs[i]->out_formats)) < 0 ||
(ret = ff_formats_ref(formats, &ctx->outputs[i]->in_formats)) < 0)
return ret;
rates = ff_all_samplerates();
ff_formats_ref(rates, &ctx->inputs[i]->out_samplerates);
ff_formats_ref(rates, &ctx->outputs[i]->in_samplerates);
if ((ret = ff_formats_ref(rates, &ctx->inputs[i]->out_samplerates)) < 0 ||
(ret = ff_formats_ref(rates, &ctx->outputs[i]->in_samplerates)) < 0)
return ret;
layouts = ctx->inputs[i]->in_channel_layouts;
ff_channel_layouts_ref(layouts, &ctx->inputs[i]->out_channel_layouts);
ff_channel_layouts_ref(layouts, &ctx->outputs[i]->in_channel_layouts);
if ((ret = ff_channel_layouts_ref(layouts, &ctx->inputs[i]->out_channel_layouts)) < 0 ||
(ret = ff_channel_layouts_ref(layouts, &ctx->outputs[i]->in_channel_layouts)) < 0)
return ret;
}
return 0;
}
......
......@@ -289,18 +289,15 @@ static int channelmap_query_formats(AVFilterContext *ctx)
ChannelMapContext *s = ctx->priv;
AVFilterChannelLayouts *layouts;
AVFilterChannelLayouts *channel_layouts = NULL;
int ret;
layouts = ff_all_channel_layouts();
if (!layouts)
return AVERROR(ENOMEM);
ff_add_channel_layout(&channel_layouts, s->output_layout);
ff_set_common_formats(ctx, ff_planar_sample_fmts());
ff_set_common_samplerates(ctx, ff_all_samplerates());
ff_channel_layouts_ref(layouts, &ctx->inputs[0]->out_channel_layouts);
ff_channel_layouts_ref(channel_layouts, &ctx->outputs[0]->in_channel_layouts);
if ((ret = ff_add_channel_layout (&channel_layouts, s->output_layout )) < 0 ||
(ret = ff_set_common_formats (ctx , ff_planar_sample_fmts() )) < 0 ||
(ret = ff_set_common_samplerates (ctx , ff_all_samplerates() )) < 0 ||
(ret = ff_channel_layouts_ref (layouts , &ctx->inputs[0]->out_channel_layouts)) < 0 ||
(ret = ff_channel_layouts_ref (channel_layouts , &ctx->outputs[0]->in_channel_layouts)) < 0)
return ret;
return 0;
}
......
......@@ -82,20 +82,23 @@ static int query_formats(AVFilterContext *ctx)
{
ChannelSplitContext *s = ctx->priv;
AVFilterChannelLayouts *in_layouts = NULL;
int i;
int i, ret;
ff_set_common_formats (ctx, ff_planar_sample_fmts());
ff_set_common_samplerates(ctx, ff_all_samplerates());
if ((ret = ff_set_common_formats(ctx, ff_planar_sample_fmts())) < 0 ||
(ret = ff_set_common_samplerates(ctx, ff_all_samplerates())) < 0)
return ret;
ff_add_channel_layout(&in_layouts, s->channel_layout);
ff_channel_layouts_ref(in_layouts, &ctx->inputs[0]->out_channel_layouts);
if ((ret = ff_add_channel_layout(&in_layouts, s->channel_layout)) < 0 ||
(ret = ff_channel_layouts_ref(in_layouts, &ctx->inputs[0]->out_channel_layouts)) < 0)
return ret;
for (i = 0; i < ctx->nb_outputs; i++) {
AVFilterChannelLayouts *out_layouts = NULL;
uint64_t channel = av_channel_layout_extract_channel(s->channel_layout, i);
ff_add_channel_layout(&out_layouts, channel);
ff_channel_layouts_ref(out_layouts, &ctx->outputs[i]->in_channel_layouts);
if ((ret = ff_add_channel_layout(&out_layouts, channel)) < 0 ||
(ret = ff_channel_layouts_ref(out_layouts, &ctx->outputs[i]->in_channel_layouts)) < 0)
return ret;
}
return 0;
......
......@@ -78,15 +78,17 @@ typedef struct {
static int query_formats(AVFilterContext *ctx)
{
static const int sample_rates[] = { 44100, -1 };
int ret;
AVFilterFormats *formats = NULL;
AVFilterChannelLayouts *layout = NULL;
ff_add_format(&formats, AV_SAMPLE_FMT_S16);
ff_set_common_formats(ctx, formats);
ff_add_channel_layout(&layout, AV_CH_LAYOUT_STEREO);
ff_set_common_channel_layouts(ctx, layout);
ff_set_common_samplerates(ctx, ff_make_format_list(sample_rates));
if ((ret = ff_add_format (&formats, AV_SAMPLE_FMT_S16 )) < 0 ||
(ret = ff_set_common_formats (ctx , formats )) < 0 ||
(ret = ff_add_channel_layout (&layout , AV_CH_LAYOUT_STEREO )) < 0 ||
(ret = ff_set_common_channel_layouts (ctx , layout )) < 0 ||
(ret = ff_set_common_samplerates (ctx , ff_make_format_list(sample_rates) )) < 0)
return ret;
return 0;
}
......
......@@ -45,15 +45,15 @@ static int query_formats(AVFilterContext *ctx)
{
AVFilterFormats *formats = NULL;
AVFilterChannelLayouts *layout = NULL;
int ret;
ff_add_format(&formats, AV_SAMPLE_FMT_FLT);
ff_set_common_formats(ctx, formats);
ff_add_channel_layout(&layout, AV_CH_LAYOUT_STEREO);
ff_set_common_channel_layouts(ctx, layout);
if ((ret = ff_add_format (&formats, AV_SAMPLE_FMT_FLT )) < 0 ||
(ret = ff_set_common_formats (ctx , formats )) < 0 ||
(ret = ff_add_channel_layout (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
(ret = ff_set_common_channel_layouts (ctx , layout )) < 0)
return ret;
formats = ff_all_samplerates();
if (!formats)
return AVERROR(ENOMEM);
return ff_set_common_samplerates(ctx, formats);
}
......
......@@ -245,20 +245,21 @@ static int join_query_formats(AVFilterContext *ctx)
{
JoinContext *s = ctx->priv;
AVFilterChannelLayouts *layouts = NULL;
int i;
int i, ret;
ff_add_channel_layout(&layouts, s->channel_layout);
ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts);
if ((ret = ff_add_channel_layout(&layouts, s->channel_layout)) < 0 ||
(ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts)) < 0)
return ret;
for (i = 0; i < ctx->nb_inputs; i++) {
layouts = ff_all_channel_layouts();
if (!layouts)
return AVERROR(ENOMEM);
ff_channel_layouts_ref(layouts, &ctx->inputs[i]->out_channel_layouts);
if ((ret = ff_channel_layouts_ref(layouts, &ctx->inputs[i]->out_channel_layouts)) < 0)
return ret;
}
ff_set_common_formats (ctx, ff_planar_sample_fmts());
ff_set_common_samplerates(ctx, ff_all_samplerates());
if ((ret = ff_set_common_formats(ctx, ff_planar_sample_fmts())) < 0 ||
(ret = ff_set_common_samplerates(ctx, ff_all_samplerates())) < 0)
return ret;
return 0;
}
......
......@@ -227,27 +227,29 @@ static int query_formats(AVFilterContext *ctx)
AVFilterLink *outlink = ctx->outputs[0];
AVFilterFormats *formats = NULL;
AVFilterChannelLayouts *layouts;
int ret;
pan->pure_gains = are_gains_pure(pan);
/* libswr supports any sample and packing formats */
ff_set_common_formats(ctx, ff_all_formats(AVMEDIA_TYPE_AUDIO));
if ((ret = ff_set_common_formats(ctx, ff_all_formats(AVMEDIA_TYPE_AUDIO))) < 0)
return ret;
formats = ff_all_samplerates();
if (!formats)
return AVERROR(ENOMEM);
ff_set_common_samplerates(ctx, formats);
if ((ret = ff_set_common_samplerates(ctx, formats)) < 0)
return ret;
// inlink supports any channel layout
layouts = ff_all_channel_counts();
ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
return ret;
// outlink supports only requested output channel layout
layouts = NULL;
ff_add_channel_layout(&layouts,
if ((ret = ff_add_channel_layout(&layouts,
pan->out_channel_layout ? pan->out_channel_layout :
FF_COUNT2LAYOUT(pan->nb_output_channels));
ff_channel_layouts_ref(layouts, &outlink->in_channel_layouts);
return 0;
FF_COUNT2LAYOUT(pan->nb_output_channels))) < 0)
return ret;
return ff_channel_layouts_ref(layouts, &outlink->in_channel_layouts);
}
static int config_props(AVFilterLink *link)
......
......@@ -323,19 +323,21 @@ static int query_formats(AVFilterContext *ctx)
{
AVFilterFormats *formats = NULL;
AVFilterChannelLayouts *layout = NULL;
int i;
int i, ret;
ff_add_format(&formats, AV_SAMPLE_FMT_FLT);
ff_set_common_formats(ctx, formats);
ff_add_channel_layout(&layout, AV_CH_LAYOUT_STEREO);
ff_set_common_channel_layouts(ctx, layout);
if ((ret = ff_add_format (&formats, AV_SAMPLE_FMT_FLT )) < 0 ||
(ret = ff_set_common_formats (ctx , formats )) < 0 ||
(ret = ff_add_channel_layout (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
(ret = ff_set_common_channel_layouts (ctx , layout )) < 0)
return ret;
formats = NULL;
for (i = 0; i < FF_ARRAY_ELEMS(freqinfos); i++)
ff_add_format(&formats, freqinfos[i].sample_rate);
ff_set_common_samplerates(ctx, formats);
for (i = 0; i < FF_ARRAY_ELEMS(freqinfos); i++) {
if ((ret = ff_add_format(&formats, freqinfos[i].sample_rate)) < 0)
return ret;
}
return 0;
return ff_set_common_samplerates(ctx, formats);
}
static int config_input(AVFilterLink *inlink)
......
......@@ -90,22 +90,25 @@ static int query_formats(AVFilterContext *ctx)
{
AVFilterLink *inlink = ctx->inputs[0];
AVFilterLink *outlink = ctx->outputs[0];
AVFilterFormats *in_formats, *out_formats, *in_samplerates, *out_samplerates;
AVFilterChannelLayouts *in_layouts, *out_layouts;
int ret;
AVFilterFormats *in_formats = ff_all_formats(AVMEDIA_TYPE_AUDIO);
AVFilterFormats *out_formats = ff_all_formats(AVMEDIA_TYPE_AUDIO);
AVFilterFormats *in_samplerates = ff_all_samplerates();
AVFilterFormats *out_samplerates = ff_all_samplerates();
AVFilterChannelLayouts *in_layouts = ff_all_channel_layouts();
AVFilterChannelLayouts *out_layouts = ff_all_channel_layouts();
ff_formats_ref(in_formats, &inlink->out_formats);
ff_formats_ref(out_formats, &outlink->in_formats);
ff_formats_ref(in_samplerates, &inlink->out_samplerates);
ff_formats_ref(out_samplerates, &outlink->in_samplerates);
if (!(in_formats = ff_all_formats (AVMEDIA_TYPE_AUDIO)) ||
!(out_formats = ff_all_formats (AVMEDIA_TYPE_AUDIO)) ||
!(in_samplerates = ff_all_samplerates ( )) ||
!(out_samplerates = ff_all_samplerates ( )) ||
!(in_layouts = ff_all_channel_layouts ( )) ||
!(out_layouts = ff_all_channel_layouts ( )))
return AVERROR(ENOMEM);
ff_channel_layouts_ref(in_layouts, &inlink->out_channel_layouts);
ff_channel_layouts_ref(out_layouts, &outlink->in_channel_layouts);
if ((ret = ff_formats_ref (in_formats, &inlink->out_formats )) < 0 ||
(ret = ff_formats_ref (out_formats, &outlink->in_formats )) < 0 ||
(ret = ff_formats_ref (in_samplerates, &inlink->out_samplerates )) < 0 ||
(ret = ff_formats_ref (out_samplerates, &outlink->in_samplerates )) < 0 ||
(ret = ff_channel_layouts_ref (in_layouts, &inlink->out_channel_layouts)) < 0 ||
(ret = ff_channel_layouts_ref (out_layouts, &outlink->in_channel_layouts)) < 0)
return ret;
return 0;
}
......
......@@ -229,28 +229,21 @@ static int query_formats(AVFilterContext *ctx)
return AVERROR(EAGAIN);
}
ff_add_channel_layout(&layouts, ctx->inputs[0]->in_channel_layouts->channel_layouts[0]);
if (!layouts)
return AVERROR(ENOMEM);
ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts);
if ((ret = ff_add_channel_layout(&layouts, ctx->inputs[0]->in_channel_layouts->channel_layouts[0])) < 0 ||
(ret = ff_channel_layouts_ref(layouts, &ctx->outputs[0]->in_channel_layouts)) < 0)
return ret;
for (i = 0; i < 2; i++) {
layouts = ff_all_channel_counts();
if (!layouts)
return AVERROR(ENOMEM);
ff_channel_layouts_ref(layouts, &ctx->inputs[i]->out_channel_layouts);
if ((ret = ff_channel_layouts_ref(layouts, &ctx->inputs[i]->out_channel_layouts)) < 0)
return ret;
}
formats = ff_make_format_list(sample_fmts);
if (!formats)
return AVERROR(ENOMEM);
ret = ff_set_common_formats(ctx, formats);
if (ret < 0)
if ((ret = ff_set_common_formats(ctx, formats)) < 0)
return ret;
formats = ff_all_samplerates();
if (!formats)
return AVERROR(ENOMEM);
return ff_set_common_samplerates(ctx, formats);
}
......
......@@ -92,16 +92,15 @@ static int query_formats(AVFilterContext *ctx)
{
AVFilterFormats *formats = NULL;
AVFilterChannelLayouts *layout = NULL;
int ret;
ff_add_format(&formats, AV_SAMPLE_FMT_DBL);
ff_set_common_formats(ctx, formats);
ff_add_channel_layout(&layout, AV_CH_LAYOUT_STEREO);
ff_set_common_channel_layouts(ctx, layout);
if ((ret = ff_add_format (&formats, AV_SAMPLE_FMT_DBL )) < 0 ||
(ret = ff_set_common_formats (ctx , formats )) < 0 ||
(ret = ff_add_channel_layout (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
(ret = ff_set_common_channel_layouts (ctx , layout )) < 0)
return ret;
formats = ff_all_samplerates();
if (!formats)
return AVERROR(ENOMEM);
return ff_set_common_samplerates(ctx, formats);
}
......
......@@ -55,15 +55,15 @@ static int query_formats(AVFilterContext *ctx)
{
AVFilterFormats *formats = NULL;
AVFilterChannelLayouts *layout = NULL;
int ret;
ff_add_format(&formats, AV_SAMPLE_FMT_FLT);
ff_set_common_formats(ctx, formats);
ff_add_channel_layout(&layout, AV_CH_LAYOUT_STEREO);
ff_set_common_channel_layouts(ctx, layout);
if ((ret = ff_add_format (&formats, AV_SAMPLE_FMT_FLT )) < 0 ||
(ret = ff_set_common_formats (ctx , formats )) < 0 ||
(ret = ff_add_channel_layout (&layout , AV_CH_LAYOUT_STEREO)) < 0 ||
(ret = ff_set_common_channel_layouts (ctx , layout )) < 0)
return ret;
formats = ff_all_samplerates();
if (!formats)
return AVERROR(ENOMEM);
return ff_set_common_samplerates(ctx, formats);
}
......
......@@ -80,10 +80,12 @@ static int query_formats(AVFilterContext *ctx)
ANullContext *null = ctx->priv;
int64_t chlayouts[] = { null->channel_layout, -1 };
int sample_rates[] = { null->sample_rate, -1 };
int ret;
ff_set_common_formats (ctx, ff_all_formats(AVMEDIA_TYPE_AUDIO));
ff_set_common_channel_layouts(ctx, avfilter_make_format64_list(chlayouts));
ff_set_common_samplerates (ctx, ff_make_format_list(sample_rates));
if ((ret = ff_set_common_formats (ctx, ff_all_formats (AVMEDIA_TYPE_AUDIO))) < 0 ||
(ret = ff_set_common_channel_layouts (ctx, avfilter_make_format64_list (chlayouts ))) < 0 ||
(ret = ff_set_common_samplerates (ctx, ff_make_format_list (sample_rates ))) < 0)
return ret;
return 0;
}
......
......@@ -205,18 +205,20 @@ static av_cold void uninit(AVFilterContext *ctx)
static int query_formats(AVFilterContext *ctx)
{
FliteContext *flite = ctx->priv;
int ret;
AVFilterChannelLayouts *chlayouts = NULL;
int64_t chlayout = av_get_default_channel_layout(flite->wave->num_channels);
AVFilterFormats *sample_formats = NULL;
AVFilterFormats *sample_rates = NULL;
ff_add_channel_layout(&chlayouts, chlayout);
ff_set_common_channel_layouts(ctx, chlayouts);
ff_add_format(&sample_formats, AV_SAMPLE_FMT_S16);
ff_set_common_formats(ctx, sample_formats);
ff_add_format(&sample_rates, flite->wave->sample_rate);
ff_set_common_samplerates (ctx, sample_rates);
if ((ret = ff_add_channel_layout (&chlayouts , chlayout )) < 0 ||
(ret = ff_set_common_channel_layouts (ctx , chlayouts )) < 0 ||
(ret = ff_add_format (&sample_formats, AV_SAMPLE_FMT_S16 )) < 0 ||
(ret = ff_set_common_formats (ctx , sample_formats )) < 0 ||
(ret = ff_add_format (&sample_rates , flite->wave->sample_rate)) < 0 ||
(ret = ff_set_common_samplerates (ctx , sample_rates )) < 0)
return ret;
return 0;
}
......
......@@ -70,24 +70,21 @@ static int query_formats(AVFilterContext *ctx)
AVFilterLink *outlink = ctx->outputs[0];
static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_NONE };
static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_RGBA, AV_PIX_FMT_NONE };
int ret;
formats = ff_make_format_list(sample_fmts);
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &inlink->out_formats);
ff_add_channel_layout(&layout, AV_CH_LAYOUT_STEREO);
ff_channel_layouts_ref(layout, &inlink->out_channel_layouts);
if ((ret = ff_formats_ref (formats, &inlink->out_formats )) < 0 ||
(ret = ff_add_channel_layout (&layout, AV_CH_LAYOUT_STEREO )) < 0 ||
(ret = ff_channel_layouts_ref (layout , &inlink->out_channel_layouts)) < 0)
return ret;
formats = ff_all_samplerates();
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &inlink->out_samplerates);
if ((ret = ff_formats_ref(formats, &inlink->out_samplerates)) < 0)
return ret;
formats = ff_make_format_list(pix_fmts);
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &outlink->in_formats);
if ((ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
return ret;
return 0;
}
......
......@@ -126,24 +126,21 @@ static int query_formats(AVFilterContext *ctx)
AVFilterLink *outlink = ctx->outputs[0];
static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_NONE };
static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_RGBA, AV_PIX_FMT_NONE };
int ret;
formats = ff_make_format_list(sample_fmts);
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &inlink->out_formats);
ff_add_channel_layout(&layout, AV_CH_LAYOUT_STEREO);
ff_channel_layouts_ref(layout, &inlink->out_channel_layouts);
if ((ret = ff_formats_ref (formats, &inlink->out_formats )) < 0 ||
(ret = ff_add_channel_layout (&layout, AV_CH_LAYOUT_STEREO )) < 0 ||
(ret = ff_channel_layouts_ref (layout , &inlink->out_channel_layouts)) < 0)
return ret;
formats = ff_all_samplerates();
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &inlink->out_samplerates);
if ((ret = ff_formats_ref(formats, &inlink->out_samplerates)) < 0)
return ret;
formats = ff_make_format_list(pix_fmts);
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &outlink->in_formats);
if ((ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
return ret;
return 0;
}
......
......@@ -80,6 +80,7 @@ static int query_formats(AVFilterContext *ctx)
unsigned type, nb_str, idx0 = 0, idx, str, seg;
AVFilterFormats *formats, *rates = NULL;
AVFilterChannelLayouts *layouts = NULL;
int ret;
for (type = 0; type < TYPE_ALL; type++) {
nb_str = cat->nb_streams[type];
......@@ -88,26 +89,26 @@ static int query_formats(AVFilterContext *ctx)
/* Set the output formats */
formats = ff_all_formats(type);
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &ctx->outputs[idx]->in_formats);
if ((ret = ff_formats_ref(formats, &ctx->outputs[idx]->in_formats)) < 0)
return ret;
if (type == AVMEDIA_TYPE_AUDIO) {
rates = ff_all_samplerates();
if (!rates)
return AVERROR(ENOMEM);
ff_formats_ref(rates, &ctx->outputs[idx]->in_samplerates);
if ((ret = ff_formats_ref(rates, &ctx->outputs[idx]->in_samplerates)) < 0)
return ret;
layouts = ff_all_channel_layouts();
if (!layouts)
return AVERROR(ENOMEM);
ff_channel_layouts_ref(layouts, &ctx->outputs[idx]->in_channel_layouts);
if ((ret = ff_channel_layouts_ref(layouts, &ctx->outputs[idx]->in_channel_layouts)) < 0)
return ret;
}
/* Set the same formats for each corresponding input */
for (seg = 0; seg < cat->nb_segments; seg++) {
ff_formats_ref(formats, &ctx->inputs[idx]->out_formats);
if ((ret = ff_formats_ref(formats, &ctx->inputs[idx]->out_formats)) < 0)
return ret;
if (type == AVMEDIA_TYPE_AUDIO) {
ff_formats_ref(rates, &ctx->inputs[idx]->out_samplerates);
ff_channel_layouts_ref(layouts, &ctx->inputs[idx]->out_channel_layouts);
if ((ret = ff_formats_ref(rates, &ctx->inputs[idx]->out_samplerates)) < 0 ||
(ret = ff_channel_layouts_ref(layouts, &ctx->inputs[idx]->out_channel_layouts)) < 0)
return ret;
}
idx += ctx->nb_outputs;
}
......
......@@ -136,28 +136,25 @@ static int query_formats(AVFilterContext *ctx)
static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_RGB24, AV_PIX_FMT_NONE };
static const int64_t channel_layouts[] = { AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_STEREO_DOWNMIX, -1 };
static const int samplerates[] = { 44100, 48000, -1 };
int ret;
/* set input audio formats */
formats = ff_make_format_list(sample_fmts);
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &inlink->out_formats);
if ((ret = ff_formats_ref(formats, &inlink->out_formats)) < 0)
return ret;
layouts = avfilter_make_format64_list(channel_layouts);
if (!layouts)
return AVERROR(ENOMEM);
ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
return ret;
formats = ff_make_format_list(samplerates);
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &inlink->out_samplerates);
if ((ret = ff_formats_ref(formats, &inlink->out_samplerates)) < 0)
return ret;
/* set output video format */
formats = ff_make_format_list(pix_fmts);
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &outlink->in_formats);
if ((ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
return ret;
return 0;
}
......
......@@ -128,28 +128,25 @@ static int query_formats(AVFilterContext *ctx)
AVFilterLink *outlink = ctx->outputs[0];
static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE };
static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_RGBA, AV_PIX_FMT_NONE };
int ret;
/* set input audio formats */
formats = ff_make_format_list(sample_fmts);
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &inlink->out_formats);
if ((ret = ff_formats_ref(formats, &inlink->out_formats)) < 0)
return ret;
layouts = ff_all_channel_layouts();
if (!layouts)
return AVERROR(ENOMEM);
ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
return ret;
formats = ff_all_samplerates();
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &inlink->out_samplerates);
if ((ret = ff_formats_ref(formats, &inlink->out_samplerates)) < 0)
return ret;
/* set output video format */
formats = ff_make_format_list(pix_fmts);
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &outlink->in_formats);
if ((ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
return ret;
return 0;
}
......
......@@ -126,28 +126,25 @@ static int query_formats(AVFilterContext *ctx)
AVFilterLink *outlink = ctx->outputs[0];
static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_NONE };
static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_YUVJ444P, AV_PIX_FMT_NONE };
int ret;
/* set input audio formats */
formats = ff_make_format_list(sample_fmts);
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &inlink->out_formats);
if ((ret = ff_formats_ref(formats, &inlink->out_formats)) < 0)
return ret;
layouts = ff_all_channel_layouts();
if (!layouts)
return AVERROR(ENOMEM);
ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
return ret;
formats = ff_all_samplerates();
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &inlink->out_samplerates);
if ((ret = ff_formats_ref(formats, &inlink->out_samplerates)) < 0)
return ret;
/* set output video format */
formats = ff_make_format_list(pix_fmts);
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &outlink->in_formats);
if ((ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
return ret;
return 0;
}
......
......@@ -85,26 +85,23 @@ static int query_formats(AVFilterContext *ctx)
AVFilterLink *outlink = ctx->outputs[0];
static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE };
static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_RGBA, AV_PIX_FMT_NONE };
int ret;
formats = ff_make_format_list(sample_fmts);
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &inlink->out_formats);
if ((ret = ff_formats_ref(formats, &inlink->out_formats)) < 0)
return ret;
layouts = ff_all_channel_layouts();
if (!layouts)
return AVERROR(ENOMEM);
ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
return ret;
formats = ff_all_samplerates();
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &inlink->out_samplerates);
if ((ret = ff_formats_ref(formats, &inlink->out_samplerates)) < 0)
return ret;
formats = ff_make_format_list(pix_fmts);
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &outlink->in_formats);
if ((ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
return ret;
return 0;
}
......
......@@ -117,28 +117,25 @@ static int query_formats(AVFilterContext *ctx)
AVFilterLink *outlink = ctx->outputs[0];
static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_NONE };
static const enum AVPixelFormat pix_fmts[] = { AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE };
int ret;
/* set input audio formats */
formats = ff_make_format_list(sample_fmts);
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &inlink->out_formats);
if ((ret = ff_formats_ref(formats, &inlink->out_formats)) < 0)
return ret;
layouts = ff_all_channel_layouts();
if (!layouts)
return AVERROR(ENOMEM);
ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0)
return ret;
formats = ff_all_samplerates();
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &inlink->out_samplerates);
if ((ret = ff_formats_ref(formats, &inlink->out_samplerates)) < 0)
return ret;
/* set output video format */
formats = ff_make_format_list(pix_fmts);
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &outlink->in_formats);
if ((ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
return ret;
return 0;
}
......
......@@ -317,18 +317,15 @@ static int filter_query_formats(AVFilterContext *ctx)
sanitize_channel_layouts(ctx, ctx->outputs[i]->in_channel_layouts);
formats = ff_all_formats(type);
if (!formats)
return AVERROR(ENOMEM);
ff_set_common_formats(ctx, formats);
if ((ret = ff_set_common_formats(ctx, formats)) < 0)
return ret;
if (type == AVMEDIA_TYPE_AUDIO) {
samplerates = ff_all_samplerates();
if (!samplerates)
return AVERROR(ENOMEM);
ff_set_common_samplerates(ctx, samplerates);
if ((ret = ff_set_common_samplerates(ctx, samplerates)) < 0)
return ret;
chlayouts = ff_all_channel_layouts();
if (!chlayouts)
return AVERROR(ENOMEM);
ff_set_common_channel_layouts(ctx, chlayouts);
if ((ret = ff_set_common_channel_layouts(ctx, chlayouts)) < 0)
return ret;
}
return 0;
}
......@@ -728,7 +725,7 @@ static int pick_format(AVFilterLink *link, AVFilterLink *ref)
return 0;
}
#define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format) \
#define REDUCE_FORMATS(fmt_type, list_type, list, var, nb, add_format, unref_format) \
do { \
for (i = 0; i < filter->nb_inputs; i++) { \
AVFilterLink *link = filter->inputs[i]; \
......@@ -769,9 +766,9 @@ static int reduce_formats_on_filter(AVFilterContext *filter)
int i, j, k, ret = 0;
REDUCE_FORMATS(int, AVFilterFormats, formats, formats,
nb_formats, ff_add_format);
nb_formats, ff_add_format, ff_formats_unref);
REDUCE_FORMATS(int, AVFilterFormats, samplerates, formats,
nb_formats, ff_add_format);
nb_formats, ff_add_format, ff_formats_unref);
/* reduce channel layouts */
for (i = 0; i < filter->nb_inputs; i++) {
......@@ -795,7 +792,8 @@ static int reduce_formats_on_filter(AVFilterContext *filter)
(!FF_LAYOUT2COUNT(fmt) || fmts->all_counts)) {
/* Turn the infinite list into a singleton */
fmts->all_layouts = fmts->all_counts = 0;
ff_add_channel_layout(&outlink->in_channel_layouts, fmt);
if (ff_add_channel_layout(&outlink->in_channel_layouts, fmt) < 0)
ret = 1;
break;
}
......
......@@ -302,13 +302,13 @@ static int vsink_query_formats(AVFilterContext *ctx)
CHECK_LIST_SIZE(pixel_fmts)
if (buf->pixel_fmts_size) {
for (i = 0; i < NB_ITEMS(buf->pixel_fmts); i++)
if ((ret = ff_add_format(&formats, buf->pixel_fmts[i])) < 0) {
ff_formats_unref(&formats);
if ((ret = ff_add_format(&formats, buf->pixel_fmts[i])) < 0)
return ret;
}
ff_set_common_formats(ctx, formats);
if ((ret = ff_set_common_formats(ctx, formats)) < 0)
return ret;
} else {
ff_default_query_formats(ctx);
if ((ret = ff_default_query_formats(ctx)) < 0)
return ret;
}
return 0;
......@@ -346,25 +346,20 @@ static int asink_query_formats(AVFilterContext *ctx)
if (buf->sample_fmts_size) {
for (i = 0; i < NB_ITEMS(buf->sample_fmts); i++)
if ((ret = ff_add_format(&formats, buf->sample_fmts[i])) < 0) {
ff_formats_unref(&formats);
if ((ret = ff_add_format(&formats, buf->sample_fmts[i])) < 0)
return ret;
}
ff_set_common_formats(ctx, formats);
if ((ret = ff_set_common_formats(ctx, formats)) < 0)
return ret;
}
if (buf->channel_layouts_size || buf->channel_counts_size ||
buf->all_channel_counts) {
for (i = 0; i < NB_ITEMS(buf->channel_layouts); i++)
if ((ret = ff_add_channel_layout(&layouts, buf->channel_layouts[i])) < 0) {
ff_channel_layouts_unref(&layouts);
if ((ret = ff_add_channel_layout(&layouts, buf->channel_layouts[i])) < 0)
return ret;
}
for (i = 0; i < NB_ITEMS(buf->channel_counts); i++)
if ((ret = ff_add_channel_layout(&layouts, FF_COUNT2LAYOUT(buf->channel_counts[i]))) < 0) {
ff_channel_layouts_unref(&layouts);
if ((ret = ff_add_channel_layout(&layouts, FF_COUNT2LAYOUT(buf->channel_counts[i]))) < 0)
return ret;
}
if (buf->all_channel_counts) {
if (layouts)
av_log(ctx, AV_LOG_WARNING,
......@@ -372,17 +367,17 @@ static int asink_query_formats(AVFilterContext *ctx)
else if (!(layouts = ff_all_channel_counts()))
return AVERROR(ENOMEM);
}
ff_set_common_channel_layouts(ctx, layouts);
if ((ret = ff_set_common_channel_layouts(ctx, layouts)) < 0)
return ret;
}
if (buf->sample_rates_size) {
formats = NULL;
for (i = 0; i < NB_ITEMS(buf->sample_rates); i++)
if ((ret = ff_add_format(&formats, buf->sample_rates[i])) < 0) {
ff_formats_unref(&formats);
if ((ret = ff_add_format(&formats, buf->sample_rates[i])) < 0)
return ret;
}
ff_set_common_samplerates(ctx, formats);
if ((ret = ff_set_common_samplerates(ctx, formats)) < 0)
return ret;
}
return 0;
......
......@@ -314,23 +314,27 @@ static int query_formats(AVFilterContext *ctx)
AVFilterChannelLayouts *channel_layouts = NULL;
AVFilterFormats *formats = NULL;
AVFilterFormats *samplerates = NULL;
int ret;
switch (ctx->outputs[0]->type) {
case AVMEDIA_TYPE_VIDEO:
ff_add_format(&formats, c->pix_fmt);
ff_set_common_formats(ctx, formats);
if ((ret = ff_add_format (&formats, c->pix_fmt)) < 0 ||
(ret = ff_set_common_formats (ctx , formats )) < 0)
return ret;
break;
case AVMEDIA_TYPE_AUDIO:
ff_add_format(&formats, c->sample_fmt);
ff_set_common_formats(ctx, formats);
ff_add_format(&samplerates, c->sample_rate);
ff_set_common_samplerates(ctx, samplerates);
if ((ret = ff_add_format (&formats , c->sample_fmt )) < 0 ||
(ret = ff_set_common_formats (ctx , formats )) < 0 ||
(ret = ff_add_format (&samplerates, c->sample_rate)) < 0 ||
(ret = ff_set_common_samplerates (ctx , samplerates )) < 0)
return ret;
ff_add_channel_layout(&channel_layouts,
if ((ret = ff_add_channel_layout(&channel_layouts,
c->channel_layout ? c->channel_layout :
FF_COUNT2LAYOUT(c->channels));
ff_set_common_channel_layouts(ctx, channel_layouts);
FF_COUNT2LAYOUT(c->channels))) < 0)
return ret;
if ((ret = ff_set_common_channel_layouts(ctx, channel_layouts)) < 0)
return ret;
break;
default:
return AVERROR(EINVAL);
......
......@@ -532,10 +532,12 @@ AVFilterFormats *ff_draw_supported_pixel_formats(unsigned flags)
enum AVPixelFormat i;
FFDrawContext draw;
AVFilterFormats *fmts = NULL;
int ret;
for (i = 0; av_pix_fmt_desc_get(i); i++)
if (ff_draw_init(&draw, i, flags) >= 0)
ff_add_format(&fmts, i);
if (ff_draw_init(&draw, i, flags) >= 0 &&
(ret = ff_add_format(&fmts, i)) < 0)
return NULL;
return fmts;
}
......
......@@ -110,11 +110,11 @@ static int query_formats(AVFilterContext *ctx)
AV_PIX_FMT_RGBA,
AV_PIX_FMT_NONE
};
int ret;
AVFilterFormats *fmts_list = ff_make_format_list(pix_fmts);
if (!fmts_list)
return AVERROR(ENOMEM);
ff_formats_ref(fmts_list, &outlink->in_formats);
if ((ret = ff_formats_ref(fmts_list, &outlink->in_formats)) < 0)
return ret;
return 0;
}
......
......@@ -826,6 +826,7 @@ static int query_formats(AVFilterContext *ctx)
AVFilterChannelLayouts *layouts;
AVFilterLink *inlink = ctx->inputs[0];
AVFilterLink *outlink = ctx->outputs[0];
int ret;
static const enum AVSampleFormat sample_fmts[] = { AV_SAMPLE_FMT_DBL, AV_SAMPLE_FMT_NONE };
static const int input_srate[] = {48000, -1}; // ITU-R BS.1770 provides coeff only for 48kHz
......@@ -834,9 +835,8 @@ static int query_formats(AVFilterContext *ctx)
/* set optional output video format */
if (ebur128->do_video) {
formats = ff_make_format_list(pix_fmts);
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &outlink->in_formats);
if ((ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
return ret;
outlink = ctx->outputs[1];
}
......@@ -844,22 +844,19 @@ static int query_formats(AVFilterContext *ctx)
* Note: ff_set_common_* functions are not used because they affect all the
* links, and thus break the video format negotiation */
formats = ff_make_format_list(sample_fmts);
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &inlink->out_formats);
ff_formats_ref(formats, &outlink->in_formats);
if ((ret = ff_formats_ref(formats, &inlink->out_formats)) < 0 ||
(ret = ff_formats_ref(formats, &outlink->in_formats)) < 0)
return ret;
layouts = ff_all_channel_layouts();
if (!layouts)
return AVERROR(ENOMEM);
ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts);
ff_channel_layouts_ref(layouts, &outlink->in_channel_layouts);
if ((ret = ff_channel_layouts_ref(layouts, &inlink->out_channel_layouts)) < 0 ||
(ret = ff_channel_layouts_ref(layouts, &outlink->in_channel_layouts)) < 0)
return ret;
formats = ff_make_format_list(input_srate);
if (!formats)
return AVERROR(ENOMEM);
ff_formats_ref(formats, &inlink->out_samplerates);
ff_formats_ref(formats, &outlink->in_samplerates);
if ((ret = ff_formats_ref(formats, &inlink->out_samplerates)) < 0 ||
(ret = ff_formats_ref(formats, &outlink->in_samplerates)) < 0)
return ret;
return 0;
}
......
......@@ -300,17 +300,20 @@ AVFilterChannelLayouts *avfilter_make_format64_list(const int64_t *fmts)
return formats;
}
#define ADD_FORMAT(f, fmt, type, list, nb) \
#define ADD_FORMAT(f, fmt, unref_fn, type, list, nb) \
do { \
type *fmts; \
void *oldf = *f; \
\
if (!(*f) && !(*f = av_mallocz(sizeof(**f)))) \
if (!(*f) && !(*f = av_mallocz(sizeof(**f)))) { \
unref_fn(f); \
return AVERROR(ENOMEM); \
} \
\
fmts = av_realloc_array((*f)->list, (*f)->nb + 1, \
sizeof(*(*f)->list)); \
if (!fmts) { \
unref_fn(f); \
if (!oldf) \
av_freep(f); \
return AVERROR(ENOMEM); \
......@@ -322,14 +325,14 @@ do { \
int ff_add_format(AVFilterFormats **avff, int64_t fmt)
{
ADD_FORMAT(avff, fmt, int, formats, nb_formats);
ADD_FORMAT(avff, fmt, ff_formats_unref, int, formats, nb_formats);
return 0;
}
int ff_add_channel_layout(AVFilterChannelLayouts **l, uint64_t channel_layout)
{
av_assert1(!(*l && (*l)->all_layouts));
ADD_FORMAT(l, channel_layout, uint64_t, channel_layouts, nb_channel_layouts);
ADD_FORMAT(l, channel_layout, ff_channel_layouts_unref, uint64_t, channel_layouts, nb_channel_layouts);
return 0;
}
......@@ -340,12 +343,14 @@ AVFilterFormats *ff_all_formats(enum AVMediaType type)
if (type == AVMEDIA_TYPE_VIDEO) {
const AVPixFmtDescriptor *desc = NULL;
while ((desc = av_pix_fmt_desc_next(desc))) {
ff_add_format(&ret, av_pix_fmt_desc_get_id(desc));
if (ff_add_format(&ret, av_pix_fmt_desc_get_id(desc)) < 0)
return NULL;
}
} else if (type == AVMEDIA_TYPE_AUDIO) {
enum AVSampleFormat fmt = 0;
while (av_get_sample_fmt_name(fmt)) {
ff_add_format(&ret, fmt);
if (ff_add_format(&ret, fmt) < 0)
return NULL;
fmt++;
}
}
......@@ -370,7 +375,8 @@ AVFilterFormats *ff_planar_sample_fmts(void)
for (fmt = 0; av_get_bytes_per_sample(fmt)>0; fmt++)
if (av_sample_fmt_is_planar(fmt))
ff_add_format(&ret, fmt);
if (ff_add_format(&ret, fmt) < 0)
return NULL;
return ret;
}
......@@ -399,15 +405,17 @@ AVFilterChannelLayouts *ff_all_channel_counts(void)
return ret;
}
#define FORMATS_REF(f, ref) \
#define FORMATS_REF(f, ref, unref_fn) \
void *tmp; \
\
if (!ref) \
return AVERROR_BUG; \
if (!f || !ref) \
return AVERROR(ENOMEM); \
\
tmp = av_realloc_array(f->refs, sizeof(*f->refs), f->refcount + 1); \
if (!tmp) \
if (!tmp) { \
unref_fn(&f); \
return AVERROR(ENOMEM); \
} \
f->refs = tmp; \
f->refs[f->refcount++] = ref; \
*ref = f; \
......@@ -415,12 +423,12 @@ AVFilterChannelLayouts *ff_all_channel_counts(void)
int ff_channel_layouts_ref(AVFilterChannelLayouts *f, AVFilterChannelLayouts **ref)
{
FORMATS_REF(f, ref);
FORMATS_REF(f, ref, ff_channel_layouts_unref);
}
int ff_formats_ref(AVFilterFormats *f, AVFilterFormats **ref)
{
FORMATS_REF(f, ref);
FORMATS_REF(f, ref, ff_formats_unref);
}
#define FIND_REF_INDEX(ref, idx) \
......@@ -488,25 +496,29 @@ void ff_formats_changeref(AVFilterFormats **oldref, AVFilterFormats **newref)
FORMATS_CHANGEREF(oldref, newref);
}
#define SET_COMMON_FORMATS(ctx, fmts, in_fmts, out_fmts, ref, list) \
#define SET_COMMON_FORMATS(ctx, fmts, in_fmts, out_fmts, ref_fn, unref_fn, list) \
int count = 0, i; \
\
if (!fmts) \
return AVERROR_BUG; \
return AVERROR(ENOMEM); \
\
for (i = 0; i < ctx->nb_inputs; i++) { \
if (ctx->inputs[i] && !ctx->inputs[i]->out_fmts) { \
int ret = ref(fmts, &ctx->inputs[i]->out_fmts); \
if (ret < 0) \
int ret = ref_fn(fmts, &ctx->inputs[i]->out_fmts); \
if (ret < 0) { \
unref_fn(&fmts); \
return ret; \
} \
count++; \
} \
} \
for (i = 0; i < ctx->nb_outputs; i++) { \
if (ctx->outputs[i] && !ctx->outputs[i]->in_fmts) { \
int ret = ref(fmts, &ctx->outputs[i]->in_fmts); \
if (ret < 0) \
int ret = ref_fn(fmts, &ctx->outputs[i]->in_fmts); \
if (ret < 0) { \
unref_fn(&fmts); \
return ret; \
} \
count++; \
} \
} \
......@@ -523,14 +535,14 @@ int ff_set_common_channel_layouts(AVFilterContext *ctx,
AVFilterChannelLayouts *layouts)
{
SET_COMMON_FORMATS(ctx, layouts, in_channel_layouts, out_channel_layouts,
ff_channel_layouts_ref, channel_layouts);
ff_channel_layouts_ref, ff_channel_layouts_unref, channel_layouts);
}
int ff_set_common_samplerates(AVFilterContext *ctx,
AVFilterFormats *samplerates)
{
SET_COMMON_FORMATS(ctx, samplerates, in_samplerates, out_samplerates,
ff_formats_ref, formats);
ff_formats_ref, ff_formats_unref, formats);
}
/**
......@@ -541,7 +553,7 @@ int ff_set_common_samplerates(AVFilterContext *ctx,
int ff_set_common_formats(AVFilterContext *ctx, AVFilterFormats *formats)
{
SET_COMMON_FORMATS(ctx, formats, in_formats, out_formats,
ff_formats_ref, formats);
ff_formats_ref, ff_formats_unref, formats);
}
static int default_query_formats_common(AVFilterContext *ctx,
......
......@@ -333,7 +333,7 @@ static int movie_query_formats(AVFilterContext *ctx)
MovieContext *movie = ctx->priv;
int list[] = { 0, -1 };
int64_t list64[] = { 0, -1 };
int i;
int i, ret;
for (i = 0; i < ctx->nb_outputs; i++) {
MovieStream *st = &movie->st[i];
......@@ -343,16 +343,20 @@ static int movie_query_formats(AVFilterContext *ctx)
switch (c->codec_type) {
case AVMEDIA_TYPE_VIDEO:
list[0] = c->pix_fmt;
ff_formats_ref(ff_make_format_list(list), &outlink->in_formats);
if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->in_formats)) < 0)
return ret;
break;
case AVMEDIA_TYPE_AUDIO:
list[0] = c->sample_fmt;
ff_formats_ref(ff_make_format_list(list), &outlink->in_formats);
if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->in_formats)) < 0)
return ret;
list[0] = c->sample_rate;
ff_formats_ref(ff_make_format_list(list), &outlink->in_samplerates);
if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->in_samplerates)) < 0)
return ret;
list64[0] = c->channel_layout;
ff_channel_layouts_ref(avfilter_make_format64_list(list64),
&outlink->in_channel_layouts);
if ((ret = ff_channel_layouts_ref(avfilter_make_format64_list(list64),
&outlink->in_channel_layouts)) < 0)
return ret;
break;
}
}
......
......@@ -57,11 +57,16 @@ static int query_formats(AVFilterContext *ctx)
AV_PIX_FMT_NONE
};
static const enum AVPixelFormat alpha_fmts[] = { AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE };
AVFilterFormats *main_formats = ff_make_format_list(main_fmts);
AVFilterFormats *alpha_formats = ff_make_format_list(alpha_fmts);
ff_formats_ref(main_formats, &ctx->inputs[0]->out_formats);
ff_formats_ref(alpha_formats, &ctx->inputs[1]->out_formats);
ff_formats_ref(main_formats, &ctx->outputs[0]->in_formats);
AVFilterFormats *main_formats, *alpha_formats;
int ret;
if (!(main_formats = ff_make_format_list(main_fmts)) ||
!(alpha_formats = ff_make_format_list(alpha_fmts)))
return AVERROR(ENOMEM);
if ((ret = ff_formats_ref(main_formats , &ctx->inputs[0]->out_formats)) < 0 ||
(ret = ff_formats_ref(alpha_formats, &ctx->inputs[1]->out_formats)) < 0 ||
(ret = ff_formats_ref(main_formats , &ctx->outputs[0]->in_formats)) < 0)
return ret;
return 0;
}
......
......@@ -118,14 +118,15 @@ static av_cold void uninit(AVFilterContext *ctx)
static int query_formats(AVFilterContext *ctx)
{
AVFilterFormats *formats = NULL;
int fmt;
int fmt, ret;
for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
if (!(desc->flags & (AV_PIX_FMT_FLAG_HWACCEL | AV_PIX_FMT_FLAG_BITSTREAM | AV_PIX_FMT_FLAG_PAL)) &&
(desc->flags & AV_PIX_FMT_FLAG_PLANAR || desc->nb_components == 1) &&
(!(desc->flags & AV_PIX_FMT_FLAG_BE) == !HAVE_BIGENDIAN || desc->comp[0].depth == 8))
ff_add_format(&formats, fmt);
(!(desc->flags & AV_PIX_FMT_FLAG_BE) == !HAVE_BIGENDIAN || desc->comp[0].depth == 8) &&
(ret = ff_add_format(&formats, fmt)) < 0)
return ret;
}
return ff_set_common_formats(ctx, formats);
......
......@@ -93,13 +93,14 @@ typedef struct CropContext {
static int query_formats(AVFilterContext *ctx)
{
AVFilterFormats *formats = NULL;
int fmt;
int fmt, ret;
for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
if (!(desc->flags & (AV_PIX_FMT_FLAG_HWACCEL | AV_PIX_FMT_FLAG_BITSTREAM)) &&
!((desc->log2_chroma_w || desc->log2_chroma_h) && !(desc->flags & AV_PIX_FMT_FLAG_PLANAR)))
ff_add_format(&formats, fmt);
!((desc->log2_chroma_w || desc->log2_chroma_h) && !(desc->flags & AV_PIX_FMT_FLAG_PLANAR)) &&
(ret = ff_add_format(&formats, fmt)) < 0)
return ret;
}
return ff_set_common_formats(ctx, formats);
......
......@@ -116,14 +116,15 @@ static av_cold int init(AVFilterContext *ctx)
static int query_formats(AVFilterContext *ctx)
{
AVFilterFormats *pix_fmts = NULL;
int fmt;
int fmt, ret;
for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL ||
desc->flags & AV_PIX_FMT_FLAG_PAL ||
desc->flags & AV_PIX_FMT_FLAG_BITSTREAM))
ff_add_format(&pix_fmts, fmt);
desc->flags & AV_PIX_FMT_FLAG_BITSTREAM) &&
(ret = ff_add_format(&pix_fmts, fmt)) < 0)
return ret;
}
return ff_set_common_formats(ctx, pix_fmts);
......
......@@ -76,8 +76,7 @@ static int query_formats(AVFilterContext *ctx)
AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE
};
ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
return 0;
return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
}
static void displace_planar(DisplaceContext *s, const AVFrame *in,
......
......@@ -83,6 +83,7 @@ static av_cold int init(AVFilterContext *ctx)
static int query_formats(AVFilterContext *ctx)
{
ELBGContext *elbg = ctx->priv;
int ret;
static const enum AVPixelFormat pix_fmts[] = {
AV_PIX_FMT_ARGB, AV_PIX_FMT_RGBA, AV_PIX_FMT_ABGR, AV_PIX_FMT_BGRA,
......@@ -99,8 +100,9 @@ static int query_formats(AVFilterContext *ctx)
AV_PIX_FMT_PAL8,
AV_PIX_FMT_NONE
};
ff_formats_ref(ff_make_format_list(pix_fmts), &ctx->inputs[0]->out_formats);
ff_formats_ref(ff_make_format_list(pal8_fmt), &ctx->outputs[0]->in_formats);
if ((ret = ff_formats_ref(ff_make_format_list(pix_fmts), &ctx->inputs[0]->out_formats)) < 0 ||
(ret = ff_formats_ref(ff_make_format_list(pal8_fmt), &ctx->outputs[0]->in_formats)) < 0)
return ret;
}
return 0;
}
......
......@@ -99,7 +99,7 @@ static int query_formats(AVFilterContext *ctx)
const enum AVPixelFormat *out_pixfmts;
const AVPixFmtDescriptor *desc;
AVFilterFormats *avff;
int i, depth = 0, be = 0;
int i, ret, depth = 0, be = 0;
if (!ctx->inputs[0]->in_formats ||
!ctx->inputs[0]->in_formats->nb_formats) {
......@@ -107,7 +107,8 @@ static int query_formats(AVFilterContext *ctx)
}
if (!ctx->inputs[0]->out_formats)
ff_formats_ref(ff_make_format_list(in_pixfmts), &ctx->inputs[0]->out_formats);
if ((ret = ff_formats_ref(ff_make_format_list(in_pixfmts), &ctx->inputs[0]->out_formats)) < 0)
return ret;
avff = ctx->inputs[0]->in_formats;
desc = av_pix_fmt_desc_get(avff->formats[0]);
......@@ -129,7 +130,8 @@ static int query_formats(AVFilterContext *ctx)
out_pixfmts = out16le_pixfmts;
for (i = 0; i < ctx->nb_outputs; i++)
ff_formats_ref(ff_make_format_list(out_pixfmts), &ctx->outputs[i]->in_formats);
if ((ret = ff_formats_ref(ff_make_format_list(out_pixfmts), &ctx->outputs[i]->in_formats)) < 0)
return ret;
return 0;
}
......
......@@ -55,13 +55,12 @@ static int query_formats(AVFilterContext *ctx)
desc->flags & AV_PIX_FMT_FLAG_PAL ||
desc->flags & AV_PIX_FMT_FLAG_BITSTREAM) &&
desc->nb_components && !desc->log2_chroma_h &&
(ret = ff_add_format(&formats, pix_fmt)) < 0) {
ff_formats_unref(&formats);
(ret = ff_add_format(&formats, pix_fmt)) < 0)
return ret;
}
}
ff_formats_ref(formats, &ctx->inputs[0]->out_formats);
ff_formats_ref(formats, &ctx->outputs[0]->in_formats);
if ((ret = ff_formats_ref(formats, &ctx->inputs[0]->out_formats)) < 0 ||
(ret = ff_formats_ref(formats, &ctx->outputs[0]->in_formats)) < 0)
return ret;
}
return 0;
......
......@@ -370,11 +370,14 @@ static int query_formats(AVFilterContext *ctx)
{
Frei0rContext *s = ctx->priv;
AVFilterFormats *formats = NULL;
int ret;
if (s->plugin_info.color_model == F0R_COLOR_MODEL_BGRA8888) {
ff_add_format(&formats, AV_PIX_FMT_BGRA);
if ((ret = ff_add_format(&formats, AV_PIX_FMT_BGRA)) < 0)
return ret;
} else if (s->plugin_info.color_model == F0R_COLOR_MODEL_RGBA8888) {
ff_add_format(&formats, AV_PIX_FMT_RGBA);
if ((ret = ff_add_format(&formats, AV_PIX_FMT_RGBA)) < 0)
return ret;
} else { /* F0R_COLOR_MODEL_PACKED32 */
static const enum AVPixelFormat pix_fmts[] = {
AV_PIX_FMT_BGRA, AV_PIX_FMT_ARGB, AV_PIX_FMT_ABGR, AV_PIX_FMT_ARGB, AV_PIX_FMT_NONE
......
......@@ -44,15 +44,16 @@ typedef struct FlipContext {
static int query_formats(AVFilterContext *ctx)
{
AVFilterFormats *pix_fmts = NULL;
int fmt;
int fmt, ret;
for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL ||
desc->flags & AV_PIX_FMT_FLAG_BITSTREAM ||
(desc->log2_chroma_w != desc->log2_chroma_h &&
desc->comp[0].plane == desc->comp[1].plane)))
ff_add_format(&pix_fmts, fmt);
desc->comp[0].plane == desc->comp[1].plane)) &&
(ret = ff_add_format(&pix_fmts, fmt)) < 0)
return ret;
}
return ff_set_common_formats(ctx, pix_fmts);
......
......@@ -155,6 +155,7 @@ static int query_formats(AVFilterContext *ctx)
HistogramContext *h = ctx->priv;
const enum AVPixelFormat *pix_fmts;
AVFilterFormats *fmts_list;
int ret;
switch (h->mode) {
case MODE_WAVEFORM:
......@@ -173,7 +174,8 @@ static int query_formats(AVFilterContext *ctx)
}
if (!ctx->inputs[0]->out_formats)
ff_formats_ref(ff_make_format_list(levels_in_pix_fmts), &ctx->inputs[0]->out_formats);
if ((ret = ff_formats_ref(ff_make_format_list(levels_in_pix_fmts), &ctx->inputs[0]->out_formats)) < 0)
return ret;
avff = ctx->inputs[0]->in_formats;
desc = av_pix_fmt_desc_get(avff->formats[0]);
rgb = desc->flags & AV_PIX_FMT_FLAG_RGB;
......@@ -197,7 +199,8 @@ static int query_formats(AVFilterContext *ctx)
out_pix_fmts = levels_out_yuv9_pix_fmts;
else // if (bits == 10)
out_pix_fmts = levels_out_yuv10_pix_fmts;
ff_formats_ref(ff_make_format_list(out_pix_fmts), &ctx->outputs[0]->in_formats);
if ((ret = ff_formats_ref(ff_make_format_list(out_pix_fmts), &ctx->outputs[0]->in_formats)) < 0)
return ret;
return 0;
}
......
......@@ -84,12 +84,14 @@ AVFILTER_DEFINE_CLASS(il);
static int query_formats(AVFilterContext *ctx)
{
AVFilterFormats *formats = NULL;
int fmt;
int fmt, ret;
for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
if (!(desc->flags & AV_PIX_FMT_FLAG_PAL) && !(desc->flags & AV_PIX_FMT_FLAG_HWACCEL))
ff_add_format(&formats, fmt);
if (!(desc->flags & AV_PIX_FMT_FLAG_PAL) &&
!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL) &&
(ret = ff_add_format(&formats, fmt)) < 0)
return ret;
}
return ff_set_common_formats(ctx, formats);
......
......@@ -58,8 +58,7 @@ static int query_formats(AVFilterContext *ctx)
AV_PIX_FMT_NONE
};
ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
return 0;
return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
}
static int process_frame(FFFrameSync *fs)
......
......@@ -116,22 +116,25 @@ static int query_formats(AVFilterContext *ctx)
{
MergePlanesContext *s = ctx->priv;
AVFilterFormats *formats = NULL;
int i;
int i, ret;
s->outdesc = av_pix_fmt_desc_get(s->out_fmt);
for (i = 0; av_pix_fmt_desc_get(i); i++) {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(i);
if (desc->comp[0].depth == s->outdesc->comp[0].depth &&
av_pix_fmt_count_planes(i) == desc->nb_components)
ff_add_format(&formats, i);
av_pix_fmt_count_planes(i) == desc->nb_components &&
(ret = ff_add_format(&formats, i)) < 0)
return ret;
}
for (i = 0; i < s->nb_inputs; i++)
ff_formats_ref(formats, &ctx->inputs[i]->out_formats);
if ((ret = ff_formats_ref(formats, &ctx->inputs[i]->out_formats)) < 0)
return ret;
formats = NULL;
ff_add_format(&formats, s->out_fmt);
ff_formats_ref(formats, &ctx->outputs[0]->in_formats);
if ((ret = ff_add_format(&formats, s->out_fmt)) < 0 ||
(ret = ff_formats_ref(formats, &ctx->outputs[0]->in_formats)) < 0)
return ret;
return 0;
}
......
......@@ -49,8 +49,7 @@ static int query_formats(AVFilterContext *ctx)
AV_PIX_FMT_GBRP, AV_PIX_FMT_GBRAP, AV_PIX_FMT_GRAY8, AV_PIX_FMT_NONE
};
ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
return 0;
return ff_set_common_formats(ctx, ff_make_format_list(pix_fmts));
}
static av_cold void uninit(AVFilterContext *ctx)
......
......@@ -133,12 +133,13 @@ static av_cold int init_noise(NoiseContext *n, int comp)
static int query_formats(AVFilterContext *ctx)
{
AVFilterFormats *formats = NULL;
int fmt;
int fmt, ret;
for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
if (desc->flags & AV_PIX_FMT_FLAG_PLANAR && !(desc->comp[0].depth & 7))
ff_add_format(&formats, fmt);
if (desc->flags & AV_PIX_FMT_FLAG_PLANAR && !(desc->comp[0].depth & 7)
&& (ret = ff_add_format(&formats, fmt)) < 0)
return ret;
}
return ff_set_common_formats(ctx, formats);
......
......@@ -247,31 +247,37 @@ static int query_formats(AVFilterContext *ctx)
AVFilterFormats *main_formats;
AVFilterFormats *overlay_formats;
int ret;
switch (s->format) {
case OVERLAY_FORMAT_YUV420:
main_formats = ff_make_format_list(main_pix_fmts_yuv420);
overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv420);
if (!(main_formats = ff_make_format_list(main_pix_fmts_yuv420)) ||
!(overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv420)))
return AVERROR(ENOMEM);
break;
case OVERLAY_FORMAT_YUV422:
main_formats = ff_make_format_list(main_pix_fmts_yuv422);
overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv422);
if (!(main_formats = ff_make_format_list(main_pix_fmts_yuv422)) ||
!(overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv422)))
return AVERROR(ENOMEM);
break;
case OVERLAY_FORMAT_YUV444:
main_formats = ff_make_format_list(main_pix_fmts_yuv444);
overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv444);
if (!(main_formats = ff_make_format_list(main_pix_fmts_yuv444)) ||
!(overlay_formats = ff_make_format_list(overlay_pix_fmts_yuv444)))
return AVERROR(ENOMEM);
break;
case OVERLAY_FORMAT_RGB:
main_formats = ff_make_format_list(main_pix_fmts_rgb);
overlay_formats = ff_make_format_list(overlay_pix_fmts_rgb);
if (!(main_formats = ff_make_format_list(main_pix_fmts_rgb)) ||
!(overlay_formats = ff_make_format_list(overlay_pix_fmts_rgb)))
return AVERROR(ENOMEM);
break;
default:
av_assert0(0);
}
ff_formats_ref(main_formats, &ctx->inputs [MAIN ]->out_formats);
ff_formats_ref(overlay_formats, &ctx->inputs [OVERLAY]->out_formats);
ff_formats_ref(main_formats, &ctx->outputs[MAIN ]->in_formats );
if ((ret = ff_formats_ref(main_formats , &ctx->inputs[MAIN]->out_formats )) < 0 ||
(ret = ff_formats_ref(overlay_formats, &ctx->inputs[OVERLAY]->out_formats)) < 0 ||
(ret = ff_formats_ref(main_formats , &ctx->outputs[MAIN]->in_formats )) < 0)
return ret;
return 0;
}
......
......@@ -92,6 +92,7 @@ static int query_formats(AVFilterContext *ctx)
{
static const enum AVPixelFormat in_fmts[] = {AV_PIX_FMT_RGB32, AV_PIX_FMT_NONE};
static const enum AVPixelFormat out_fmts[] = {AV_PIX_FMT_RGB32, AV_PIX_FMT_NONE};
int ret;
AVFilterFormats *in = ff_make_format_list(in_fmts);
AVFilterFormats *out = ff_make_format_list(out_fmts);
if (!in || !out) {
......@@ -99,8 +100,9 @@ static int query_formats(AVFilterContext *ctx)
av_freep(&out);
return AVERROR(ENOMEM);
}
ff_formats_ref(in, &ctx->inputs[0]->out_formats);
ff_formats_ref(out, &ctx->outputs[0]->in_formats);
if ((ret = ff_formats_ref(in , &ctx->inputs[0]->out_formats)) < 0 ||
(ret = ff_formats_ref(out, &ctx->outputs[0]->in_formats)) < 0)
return ret;
return 0;
}
......
......@@ -132,6 +132,7 @@ static int query_formats(AVFilterContext *ctx)
static const enum AVPixelFormat in_fmts[] = {AV_PIX_FMT_RGB32, AV_PIX_FMT_NONE};
static const enum AVPixelFormat inpal_fmts[] = {AV_PIX_FMT_RGB32, AV_PIX_FMT_NONE};
static const enum AVPixelFormat out_fmts[] = {AV_PIX_FMT_PAL8, AV_PIX_FMT_NONE};
int ret;
AVFilterFormats *in = ff_make_format_list(in_fmts);
AVFilterFormats *inpal = ff_make_format_list(inpal_fmts);
AVFilterFormats *out = ff_make_format_list(out_fmts);
......@@ -141,9 +142,10 @@ static int query_formats(AVFilterContext *ctx)
av_freep(&out);
return AVERROR(ENOMEM);
}
ff_formats_ref(in, &ctx->inputs[0]->out_formats);
ff_formats_ref(inpal, &ctx->inputs[1]->out_formats);
ff_formats_ref(out, &ctx->outputs[0]->in_formats);
if ((ret = ff_formats_ref(in , &ctx->inputs[0]->out_formats)) < 0 ||
(ret = ff_formats_ref(inpal, &ctx->inputs[1]->out_formats)) < 0 ||
(ret = ff_formats_ref(out , &ctx->outputs[0]->in_formats)) < 0)
return ret;
return 0;
}
......
......@@ -188,11 +188,11 @@ static int query_formats(AVFilterContext *ctx)
if ((sws_isSupportedInput(pix_fmt) ||
sws_isSupportedEndiannessConversion(pix_fmt))
&& (ret = ff_add_format(&formats, pix_fmt)) < 0) {
ff_formats_unref(&formats);
return ret;
}
}
ff_formats_ref(formats, &ctx->inputs[0]->out_formats);
if ((ret = ff_formats_ref(formats, &ctx->inputs[0]->out_formats)) < 0)
return ret;
}
if (ctx->outputs[0]) {
const AVPixFmtDescriptor *desc = NULL;
......@@ -202,11 +202,11 @@ static int query_formats(AVFilterContext *ctx)
if ((sws_isSupportedOutput(pix_fmt) || pix_fmt == AV_PIX_FMT_PAL8 ||
sws_isSupportedEndiannessConversion(pix_fmt))
&& (ret = ff_add_format(&formats, pix_fmt)) < 0) {
ff_formats_unref(&formats);
return ret;
}
}
ff_formats_ref(formats, &ctx->outputs[0]->in_formats);
if ((ret = ff_formats_ref(formats, &ctx->outputs[0]->in_formats)) < 0)
return ret;
}
return 0;
......
......@@ -46,6 +46,7 @@ static int query_formats(AVFilterContext *ctx)
{
static const enum AVPixelFormat in_fmts[] = {AV_PIX_FMT_PAL8, AV_PIX_FMT_NONE};
static const enum AVPixelFormat out_fmts[] = {AV_PIX_FMT_RGB32, AV_PIX_FMT_NONE};
int ret;
AVFilterFormats *in = ff_make_format_list(in_fmts);
AVFilterFormats *out = ff_make_format_list(out_fmts);
if (!in || !out) {
......@@ -53,8 +54,9 @@ static int query_formats(AVFilterContext *ctx)
av_freep(&out);
return AVERROR(ENOMEM);
}
ff_formats_ref(in, &ctx->inputs[0]->out_formats);
ff_formats_ref(out, &ctx->outputs[0]->in_formats);
if ((ret = ff_formats_ref(in , &ctx->inputs[0]->out_formats)) < 0 ||
(ret = ff_formats_ref(out, &ctx->outputs[0]->in_formats)) < 0)
return ret;
return 0;
}
......
......@@ -43,14 +43,15 @@ typedef struct StackContext {
static int query_formats(AVFilterContext *ctx)
{
AVFilterFormats *pix_fmts = NULL;
int fmt;
int fmt, ret;
for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
if (!(desc->flags & AV_PIX_FMT_FLAG_PAL ||
desc->flags & AV_PIX_FMT_FLAG_HWACCEL ||
desc->flags & AV_PIX_FMT_FLAG_BITSTREAM))
ff_add_format(&pix_fmts, fmt);
desc->flags & AV_PIX_FMT_FLAG_BITSTREAM) &&
(ret = ff_add_format(&pix_fmts, fmt)) < 0)
return ret;
}
return ff_set_common_formats(ctx, pix_fmts);
......
......@@ -77,12 +77,12 @@ static int is_planar_yuv(const AVPixFmtDescriptor *desc)
static int query_formats(AVFilterContext *ctx)
{
AVFilterFormats *formats = NULL;
int fmt;
int fmt, ret;
for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
if (is_planar_yuv(desc))
ff_add_format(&formats, fmt);
if (is_planar_yuv(desc) && (ret = ff_add_format(&formats, fmt)) < 0)
return ret;
}
return ff_set_common_formats(ctx, formats);
......
......@@ -102,14 +102,15 @@ static av_cold int init(AVFilterContext *ctx)
static int query_formats(AVFilterContext *ctx)
{
AVFilterFormats *pix_fmts = NULL;
int fmt;
int fmt, ret;
for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
if (!(desc->flags & AV_PIX_FMT_FLAG_HWACCEL ||
desc->flags & AV_PIX_FMT_FLAG_PAL ||
desc->flags & AV_PIX_FMT_FLAG_BITSTREAM))
ff_add_format(&pix_fmts, fmt);
desc->flags & AV_PIX_FMT_FLAG_BITSTREAM) &&
(ret = ff_add_format(&pix_fmts, fmt)) < 0)
return ret;
}
return ff_set_common_formats(ctx, pix_fmts);
......
......@@ -63,15 +63,16 @@ typedef struct TransContext {
static int query_formats(AVFilterContext *ctx)
{
AVFilterFormats *pix_fmts = NULL;
int fmt;
int fmt, ret;
for (fmt = 0; av_pix_fmt_desc_get(fmt); fmt++) {
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(fmt);
if (!(desc->flags & AV_PIX_FMT_FLAG_PAL ||
desc->flags & AV_PIX_FMT_FLAG_HWACCEL ||
desc->flags & AV_PIX_FMT_FLAG_BITSTREAM ||
desc->log2_chroma_w != desc->log2_chroma_h))
ff_add_format(&pix_fmts, fmt);
desc->log2_chroma_w != desc->log2_chroma_h) &&
(ret = ff_add_format(&pix_fmts, fmt)) < 0)
return ret;
}
......
......@@ -140,7 +140,7 @@ static int query_formats(AVFilterContext *ctx)
const enum AVPixelFormat *out_pix_fmts;
const AVPixFmtDescriptor *desc;
AVFilterFormats *avff;
int depth, rgb, i;
int depth, rgb, i, ret;
if (!ctx->inputs[0]->in_formats ||
!ctx->inputs[0]->in_formats->nb_formats) {
......@@ -154,7 +154,8 @@ static int query_formats(AVFilterContext *ctx)
in_pix_fmts = in2_pix_fmts;
else
in_pix_fmts = in1_pix_fmts;
ff_formats_ref(ff_make_format_list(in_pix_fmts), &ctx->inputs[0]->out_formats);
if ((ret = ff_formats_ref(ff_make_format_list(in_pix_fmts), &ctx->inputs[0]->out_formats)) < 0)
return ret;
}
avff = ctx->inputs[0]->in_formats;
......@@ -180,7 +181,8 @@ static int query_formats(AVFilterContext *ctx)
out_pix_fmts = out_yuv10_pix_fmts;
else
out_pix_fmts = out_yuv8_pix_fmts;
ff_formats_ref(ff_make_format_list(out_pix_fmts), &ctx->outputs[0]->in_formats);
if ((ret = ff_formats_ref(ff_make_format_list(out_pix_fmts), &ctx->outputs[0]->in_formats)) < 0)
return ret;
return 0;
}
......
......@@ -428,10 +428,7 @@ static int query_formats(AVFilterContext *ctx)
}
fmts_list = ff_make_format_list(pix_fmts);
if (!fmts_list)
return AVERROR(ENOMEM);
ff_set_common_formats(ctx, fmts_list);
return 0;
return ff_set_common_formats(ctx, fmts_list);
}
static const AVFilterPad life_outputs[] = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment