History

avfilter: use AV_OPT_TYPE_CHLAYOUT

Paul B Mahol committed 2 years ago

Commit 4af412b1 parent 707e46d6 files · +35 −149Browse files

Showing the changes to libavfilter (6 of 6 files). Show all

Unified · Split

6 files
  1. libavfilter/af_channelmap.c +16 −43
  2. libavfilter/af_channelsplit.c +4 −10
  3. libavfilter/af_join.c +1 −22
  4. libavfilter/af_surround.c +8 −20
  5. libavfilter/asrc_afdelaysrc.c +2 −24
  6. libavfilter/asrc_anullsrc.c +4 −30
libavfilter/af_channelmap.c+16−43
@@ -58,7 +58,6 @@ enum MappingMode { · 57 unmodified lines
5858 typedef struct ChannelMapContext {
5959 const AVClass *class;
6060 char *mapping_str;
61− char *channel_layout_str;
6261 AVChannelLayout output_layout;
6362 struct ChannelMap map[MAX_CH];
6463 int nch;
@@ -72,7 +71,7 @@ static const AVOption channelmap_options[] = { · 7 unmodified lines
7271 { "map", "A comma-separated list of input channel numbers in output order.",
7372 OFFSET(mapping_str), AV_OPT_TYPE_STRING, .flags = A|F },
7473 { "channel_layout", "Output channel layout.",
75− OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, .flags = A|F },
74+ OFFSET(output_layout), AV_OPT_TYPE_CHLAYOUT, .flags = A|F },
7675 { NULL }
7776 };
7877
@@ -122,7 +121,6 @@ static av_cold int channelmap_init(AVFilterContext *ctx) · 43 unmodified lines
122121 ChannelMapContext *s = ctx->priv;
123122 char *mapping, separator = '|';
124123 int map_entries = 0;
125− char buf[256];
126124 enum MappingMode mode;
127125 uint64_t out_ch_mask = 0;
128126 int i;
@@ -232,50 +230,25 @@ static av_cold int channelmap_init(AVFilterContext *ctx) · 103 unmodified lines
232230 s->nch = map_entries;
233231 if (out_ch_mask)
234232 av_channel_layout_from_mask(&s->output_layout, out_ch_mask);
235− else
233+ else if (map_entries)
236234 av_channel_layout_default(&s->output_layout, map_entries);
237235
238− if (s->channel_layout_str) {
239− AVChannelLayout fmt = { 0 };
240− int ret;
241− if ((ret = av_channel_layout_from_string(&fmt, s->channel_layout_str)) < 0) {
242−#if FF_API_OLD_CHANNEL_LAYOUT
243− uint64_t mask;
244−FF_DISABLE_DEPRECATION_WARNINGS
245− if ((mask = av_get_channel_layout(s->channel_layout_str)) == 0) {
246−#endif
247− av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout: '%s'.\n",
248− s->channel_layout_str);
249− return AVERROR(EINVAL);
250−#if FF_API_OLD_CHANNEL_LAYOUT
251− }
252−FF_ENABLE_DEPRECATION_WARNINGS
253− av_log(ctx, AV_LOG_WARNING, "Channel layout '%s' uses a deprecated syntax.\n",
254− s->channel_layout_str);
255− av_channel_layout_from_mask(&fmt, mask);
256−#endif
257− }
258− if (mode == MAP_NONE) {
259− int i;
260− s->nch = fmt.nb_channels;
261− for (i = 0; i < s->nch; i++) {
262− s->map[i].in_channel_idx = i;
263− s->map[i].out_channel_idx = i;
264− }
265− } else if (out_ch_mask && av_channel_layout_compare(&s->output_layout, &fmt)) {
266− av_channel_layout_describe(&s->output_layout, buf, sizeof(buf));
267− av_log(ctx, AV_LOG_ERROR,
268− "Output channel layout '%s' does not match the list of channel mapped: '%s'.\n",
269− s->channel_layout_str, buf);
270− return AVERROR(EINVAL);
271− } else if (s->nch != fmt.nb_channels) {
272− av_log(ctx, AV_LOG_ERROR,
273− "Output channel layout %s does not match the number of channels mapped %d.\n",
274− s->channel_layout_str, s->nch);
275− return AVERROR(EINVAL);
236+ if (mode == MAP_NONE) {
237+ int i;
238+ s->nch = s->output_layout.nb_channels;
239+ for (i = 0; i < s->nch; i++) {
240+ s->map[i].in_channel_idx = i;
241+ s->map[i].out_channel_idx = i;
276242 }
277− s->output_layout = fmt;
243+ } else if (s->nch != s->output_layout.nb_channels) {
244+ char buf[256];
245+ av_channel_layout_describe(&s->output_layout, buf, sizeof(buf));
246+ av_log(ctx, AV_LOG_ERROR,
247+ "Output channel layout %s does not match the number of channels mapped %d.\n",
248+ buf, s->nch);
249+ return AVERROR(EINVAL);
278250 }
251+
279252 if (!s->output_layout.nb_channels) {
280253 av_log(ctx, AV_LOG_ERROR, "Output channel layout is not set and "
281254 "cannot be guessed from the maps.\n");
libavfilter/af_channelsplit.c+4−10
@@ -40,7 +40,6 @@ typedef struct ChannelSplitContext { · 39 unmodified lines
4040 const AVClass *class;
4141
4242 AVChannelLayout channel_layout;
43− char *channel_layout_str;
4443 char *channels_str;
4544
4645 int map[64];
@@ -50,7 +49,7 @@ typedef struct ChannelSplitContext { · 3 unmodified lines
5049 #define A AV_OPT_FLAG_AUDIO_PARAM
5150 #define F AV_OPT_FLAG_FILTERING_PARAM
5251 static const AVOption channelsplit_options[] = {
53− { "channel_layout", "Input channel layout.", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, { .str = "stereo" }, .flags = A|F },
52+ { "channel_layout", "Input channel layout.", OFFSET(channel_layout), AV_OPT_TYPE_CHLAYOUT, { .str = "stereo" }, .flags = A|F },
5453 { "channels", "Channels to extract.", OFFSET(channels_str), AV_OPT_TYPE_STRING, { .str = "all" }, .flags = A|F },
5554 { NULL }
5655 };
@@ -63,13 +62,6 @@ static av_cold int init(AVFilterContext *ctx) · 6 unmodified lines
6362 AVChannelLayout channel_layout = { 0 };
6463 int all = 0, ret = 0, i;
6564
66− if ((ret = av_channel_layout_from_string(&s->channel_layout, s->channel_layout_str)) < 0) {
67− av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout '%s'.\n",
68− s->channel_layout_str);
69− ret = AVERROR(EINVAL);
70− goto fail;
71− }
72−
7365 if (!strcmp(s->channels_str, "all")) {
7466 if ((ret = av_channel_layout_copy(&channel_layout, &s->channel_layout)) < 0)
7567 goto fail;
@@ -100,9 +92,11 @@ static av_cold int init(AVFilterContext *ctx) · 24 unmodified lines
10092 if (all) {
10193 s->map[i] = i;
10294 } else {
95+ char buf[128];
96+ av_channel_layout_describe(&s->channel_layout, buf, sizeof(buf));
10397 if ((ret = av_channel_layout_index_from_channel(&s->channel_layout, channel)) < 0) {
10498 av_log(ctx, AV_LOG_ERROR, "Channel name '%s' not present in channel layout '%s'.\n",
105− pad.name, s->channel_layout_str);
99+ pad.name, buf);
106100 av_freep(&pad.name);
107101 goto fail;
108102 }
libavfilter/af_join.c+1−22
@@ -48,7 +48,6 @@ typedef struct JoinContext { · 47 unmodified lines
4848
4949 int inputs;
5050 char *map;
51− char *channel_layout_str;
5251 AVChannelLayout ch_layout;
5352
5453 int64_t eof_pts;
@@ -73,7 +72,7 @@ typedef struct JoinContext { · 18 unmodified lines
7372 static const AVOption join_options[] = {
7473 { "inputs", "Number of input streams.", OFFSET(inputs), AV_OPT_TYPE_INT, { .i64 = 2 }, 1, INT_MAX, A|F },
7574 { "channel_layout", "Channel layout of the "
76− "output stream.", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0, A|F },
75+ "output stream.", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str = "stereo"}, 0, 0, A|F },
7776 { "map", "A comma-separated list of channels maps in the format "
7877 "'input_stream.input_channel-output_channel.",
7978 OFFSET(map), AV_OPT_TYPE_STRING, .flags = A|F },
@@ -157,26 +156,6 @@ static av_cold int join_init(AVFilterContext *ctx) · 77 unmodified lines
157156 JoinContext *s = ctx->priv;
158157 int ret, i;
159158
160− ret = av_channel_layout_from_string(&s->ch_layout, s->channel_layout_str);
161− if (ret < 0) {
162−#if FF_API_OLD_CHANNEL_LAYOUT
163− uint64_t mask;
164−FF_DISABLE_DEPRECATION_WARNINGS
165− mask = av_get_channel_layout(s->channel_layout_str);
166− if (!mask) {
167−#endif
168− av_log(ctx, AV_LOG_ERROR, "Error parsing channel layout '%s'.\n",
169− s->channel_layout_str);
170− return AVERROR(EINVAL);
171−#if FF_API_OLD_CHANNEL_LAYOUT
172− }
173−FF_ENABLE_DEPRECATION_WARNINGS
174− av_log(ctx, AV_LOG_WARNING, "Channel layout '%s' uses a deprecated syntax.\n",
175− s->channel_layout_str);
176− av_channel_layout_from_mask(&s->ch_layout, mask);
177−#endif
178− }
179−
180159 s->channels = av_calloc(s->ch_layout.nb_channels, sizeof(*s->channels));
181160 s->buffers = av_calloc(s->ch_layout.nb_channels, sizeof(*s->buffers));
182161 s->input_frames = av_calloc(s->inputs, sizeof(*s->input_frames));
libavfilter/af_surround.c+8−20
@@ -61,8 +61,8 @@ static const int sc_map[16] = { · 60 unmodified lines
6161 typedef struct AudioSurroundContext {
6262 const AVClass *class;
6363
64− char *out_channel_layout_str;
65− char *in_channel_layout_str;
64+ AVChannelLayout out_ch_layout;
65+ AVChannelLayout in_ch_layout;
6666
6767 float level_in;
6868 float level_out;
@@ -93,8 +93,6 @@ typedef struct AudioSurroundContext { · 24 unmodified lines
9393 float lowcut;
9494 float highcut;
9595
96− AVChannelLayout out_ch_layout;
97− AVChannelLayout in_ch_layout;
9896 int nb_in_channels;
9997 int nb_out_channels;
10098
@@ -1107,20 +1105,8 @@ static av_cold int init(AVFilterContext *ctx) · 1006 unmodified lines
11071105 {
11081106 AudioSurroundContext *s = ctx->priv;
11091107 int64_t in_channel_layout, out_channel_layout;
1108+ char in_name[128], out_name[128];
11101109 float overlap;
1111− int ret;
1112−
1113− if ((ret = av_channel_layout_from_string(&s->out_ch_layout, s->out_channel_layout_str)) < 0) {
1114− av_log(ctx, AV_LOG_ERROR, "Error parsing output channel layout '%s'.\n",
1115− s->out_channel_layout_str);
1116− return ret;
1117− }
1118−
1119− if ((ret = av_channel_layout_from_string(&s->in_ch_layout, s->in_channel_layout_str)) < 0) {
1120− av_log(ctx, AV_LOG_ERROR, "Error parsing input channel layout '%s'.\n",
1121− s->in_channel_layout_str);
1122− return AVERROR(EINVAL);
1123− }
11241110
11251111 if (s->lowcutf >= s->highcutf) {
11261112 av_log(ctx, AV_LOG_ERROR, "Low cut-off '%d' should be less than high cut-off '%d'.\n",
@@ -1181,8 +1167,10 @@ static av_cold int init(AVFilterContext *ctx) · 54 unmodified lines
11811167 break;
11821168 default:
11831169 fail:
1170+ av_channel_layout_describe(&s->out_ch_layout, out_name, sizeof(out_name));
1171+ av_channel_layout_describe(&s->in_ch_layout, in_name, sizeof(in_name));
11841172 av_log(ctx, AV_LOG_ERROR, "Unsupported upmix: '%s' -> '%s'.\n",
1185− s->in_channel_layout_str, s->out_channel_layout_str);
1173+ in_name, out_name);
11861174 return AVERROR(EINVAL);
11871175 }
11881176
@@ -1417,8 +1405,8 @@ static int process_command(AVFilterContext *ctx, const char *cmd, const char *ar · 228 unmodified lines
14171405 #define TFLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM|AV_OPT_FLAG_RUNTIME_PARAM
14181406
14191407 static const AVOption surround_options[] = {
1420− { "chl_out", "set output channel layout", OFFSET(out_channel_layout_str), AV_OPT_TYPE_STRING, {.str="5.1"}, 0, 0, FLAGS },
1421− { "chl_in", "set input channel layout", OFFSET(in_channel_layout_str), AV_OPT_TYPE_STRING, {.str="stereo"},0, 0, FLAGS },
1408+ { "chl_out", "set output channel layout", OFFSET(out_ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="5.1"}, 0, 0, FLAGS },
1409+ { "chl_in", "set input channel layout", OFFSET(in_ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str="stereo"},0, 0, FLAGS },
14221410 { "level_in", "set input level", OFFSET(level_in), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },
14231411 { "level_out", "set output level", OFFSET(level_out), AV_OPT_TYPE_FLOAT, {.dbl=1}, 0, 10, TFLAGS },
14241412 { "lfe", "output LFE", OFFSET(output_lfe), AV_OPT_TYPE_BOOL, {.i64=1}, 0, 1, TFLAGS },
libavfilter/asrc_afdelaysrc.c+2−24
@@ -36,23 +36,10 @@ typedef struct AFDelaySrcContext { · 35 unmodified lines
3636 int nb_samples;
3737 int nb_taps;
3838 AVChannelLayout chlayout;
39− char *chlayout_str;
4039
4140 int64_t pts;
4241 } AFDelaySrcContext;
4342
44−static av_cold int init(AVFilterContext *ctx)
45−{
46− AFDelaySrcContext *s = ctx->priv;
47− int ret;
48−
49− ret = ff_parse_channel_layout(&s->chlayout, NULL, s->chlayout_str, ctx);
50− if (ret < 0)
51− return ret;
52−
53− return 0;
54−}
55−
5643 static float sincf(float x)
5744 {
5845 if (x == 0.f)
@@ -134,13 +121,6 @@ static const AVFilterPad afdelaysrc_outputs[] = { · 75 unmodified lines
134121 },
135122 };
136123
137−static av_cold void uninit(AVFilterContext *ctx)
138−{
139− AFDelaySrcContext *s = ctx->priv;
140−
141− av_channel_layout_uninit(&s->chlayout);
142−}
143−
144124 #define AF AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
145125 #define OFFSET(x) offsetof(AFDelaySrcContext, x)
146126
@@ -153,8 +133,8 @@ static const AVOption afdelaysrc_options[] = { · 6 unmodified lines
153133 { "n", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64=1024}, 1, INT_MAX, AF },
154134 { "taps", "set number of taps for delay filter", OFFSET(nb_taps), AV_OPT_TYPE_INT, {.i64=0}, 0, 32768, AF },
155135 { "t", "set number of taps for delay filter", OFFSET(nb_taps), AV_OPT_TYPE_INT, {.i64=0}, 0, 32768, AF },
156− { "channel_layout", "set channel layout", OFFSET(chlayout_str),AV_OPT_TYPE_STRING,{.str="stereo"},0, 0, AF },
157− { "c", "set channel layout", OFFSET(chlayout_str),AV_OPT_TYPE_STRING,{.str="stereo"},0, 0, AF },
136+ { "channel_layout", "set channel layout", OFFSET(chlayout), AV_OPT_TYPE_CHLAYOUT,{.str="stereo"},0, 0, AF },
137+ { "c", "set channel layout", OFFSET(chlayout), AV_OPT_TYPE_CHLAYOUT,{.str="stereo"},0, 0, AF },
158138 { NULL }
159139 };
160140
@@ -165,9 +145,7 @@ const AVFilter ff_asrc_afdelaysrc = { · 4 unmodified lines
165145 .description = NULL_IF_CONFIG_SMALL("Generate a Fractional delay FIR coefficients."),
166146 .priv_size = sizeof(AFDelaySrcContext),
167147 .priv_class = &afdelaysrc_class,
168− .init = init,
169148 .activate = activate,
170− .uninit = uninit,
171149 .inputs = NULL,
172150 FILTER_OUTPUTS(afdelaysrc_outputs),
173151 FILTER_QUERY_FUNC(query_formats),
libavfilter/asrc_anullsrc.c+4−30
@@ -38,9 +38,7 @@ · 37 unmodified lines
3838
3939 typedef struct ANullContext {
4040 const AVClass *class;
41− char *channel_layout_str;
4241 AVChannelLayout ch_layout;
43− char *sample_rate_str;
4442 int sample_rate;
4543 int64_t duration;
4644 int nb_samples; ///< number of samples per requested frame
@@ -51,10 +49,10 @@ typedef struct ANullContext { · 4 unmodified lines
5149 #define FLAGS AV_OPT_FLAG_AUDIO_PARAM|AV_OPT_FLAG_FILTERING_PARAM
5250
5351 static const AVOption anullsrc_options[]= {
54− { "channel_layout", "set channel_layout", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0, FLAGS },
55− { "cl", "set channel_layout", OFFSET(channel_layout_str), AV_OPT_TYPE_STRING, {.str = "stereo"}, 0, 0, FLAGS },
56− { "sample_rate", "set sample rate", OFFSET(sample_rate_str) , AV_OPT_TYPE_STRING, {.str = "44100"}, 0, 0, FLAGS },
57− { "r", "set sample rate", OFFSET(sample_rate_str) , AV_OPT_TYPE_STRING, {.str = "44100"}, 0, 0, FLAGS },
52+ { "channel_layout", "set channel_layout", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str = "stereo"}, 0, 0, FLAGS },
53+ { "cl", "set channel_layout", OFFSET(ch_layout), AV_OPT_TYPE_CHLAYOUT, {.str = "stereo"}, 0, 0, FLAGS },
54+ { "sample_rate", "set sample rate", OFFSET(sample_rate) , AV_OPT_TYPE_INT, {.i64 = 44100}, 0, 0, FLAGS },
55+ { "r", "set sample rate", OFFSET(sample_rate) , AV_OPT_TYPE_INT, {.i64 = 44100}, 0, 0, FLAGS },
5856 { "nb_samples", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64 = 1024}, 1, UINT16_MAX, FLAGS },
5957 { "n", "set the number of samples per requested frame", OFFSET(nb_samples), AV_OPT_TYPE_INT, {.i64 = 1024}, 1, UINT16_MAX, FLAGS },
6058 { "duration", "set the audio duration", OFFSET(duration), AV_OPT_TYPE_DURATION, {.i64 = -1}, -1, INT64_MAX, FLAGS },
@@ -64,22 +62,6 @@ static const AVOption anullsrc_options[]= { · 3 unmodified lines
6462
6563 AVFILTER_DEFINE_CLASS(anullsrc);
6664
67−static av_cold int init(AVFilterContext *ctx)
68−{
69− ANullContext *null = ctx->priv;
70− int ret;
71−
72− if ((ret = ff_parse_sample_rate(&null->sample_rate,
73− null->sample_rate_str, ctx)) < 0)
74− return ret;
75−
76− if ((ret = ff_parse_channel_layout(&null->ch_layout, NULL,
77− null->channel_layout_str, ctx)) < 0)
78− return ret;
79−
80− return 0;
81−}
82−
8365 static int query_formats(AVFilterContext *ctx)
8466 {
8567 ANullContext *null = ctx->priv;
@@ -129,12 +111,6 @@ static int activate(AVFilterContext *ctx) · 43 unmodified lines
129111 return FFERROR_NOT_READY;
130112 }
131113
132−static av_cold void uninit(AVFilterContext *ctx)
133−{
134− ANullContext *s = ctx->priv;
135− av_channel_layout_uninit(&s->ch_layout);
136−}
137−
138114 static const AVFilterPad avfilter_asrc_anullsrc_outputs[] = {
139115 {
140116 .name = "default",
@@ -146,8 +122,6 @@ static const AVFilterPad avfilter_asrc_anullsrc_outputs[] = { · 5 unmodified lines
146122 const AVFilter ff_asrc_anullsrc = {
147123 .name = "anullsrc",
148124 .description = NULL_IF_CONFIG_SMALL("Null audio source, return empty audio frames."),
149− .init = init,
150− .uninit = uninit,
151125 .priv_size = sizeof(ANullContext),
152126 .inputs = NULL,
153127 FILTER_OUTPUTS(avfilter_asrc_anullsrc_outputs),

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