History

avfilter/af_channelmap: factorize checking indexes against a channel layout

Marton Balint committed 2 years ago

Commit bba6dd31 parent 2f754a91 file · +25 −16Browse files

Showing the changes to libavfilter (1 of 1 file). Show all

Unified · Split

libavfilter/af_channelmap.c+25−16
@@ -116,6 +116,30 @@ static int get_channel(char **map, int *ch, char delim) · 115 unmodified lines
116 return 0;116 return 0;
117}117}
118 118
119static int check_idx_and_id(AVFilterContext *ctx, int channel_idx, int channel, AVChannelLayout *ch_layout, const char *io)
120{
121 char channel_name[64];
122 char layout_name[256];
123 int nb_channels = ch_layout->nb_channels;
124
125 if (channel_idx < 0 || channel_idx >= nb_channels) {
126 av_channel_layout_describe(ch_layout, layout_name, sizeof(layout_name));
127 if (channel >= 0) {
128 av_channel_name(channel_name, sizeof(channel_name), channel);
129 av_log(ctx, AV_LOG_ERROR,
130 "%sput channel '%s' not available from %sput layout '%s'\n",
131 io, channel_name, io, layout_name);
132 } else {
133 av_log(ctx, AV_LOG_ERROR,
134 "%sput channel #%d not available from %sput layout '%s'\n",
135 io, channel_idx, io, layout_name);
136 }
137 return AVERROR(EINVAL);
138 }
139
140 return 0;
141}
142
119static av_cold int channelmap_init(AVFilterContext *ctx)143static av_cold int channelmap_init(AVFilterContext *ctx)
120{144{
121 ChannelMapContext *s = ctx->priv;145 ChannelMapContext *s = ctx->priv;
@@ -334,10 +358,7 @@ static int channelmap_config_input(AVFilterLink *inlink) · 212 unmodified lines
334{358{
335 AVFilterContext *ctx = inlink->dst;359 AVFilterContext *ctx = inlink->dst;
336 ChannelMapContext *s = ctx->priv;360 ChannelMapContext *s = ctx->priv;
337 int nb_channels = inlink->ch_layout.nb_channels;
338 int i, err = 0;361 int i, err = 0;
339 char channel_name[64];
340 char layout_name[256];
341 362
342 for (i = 0; i < s->nch; i++) {363 for (i = 0; i < s->nch; i++) {
343 struct ChannelMap *m = &s->map[i];364 struct ChannelMap *m = &s->map[i];
@@ -347,20 +368,8 @@ static int channelmap_config_input(AVFilterLink *inlink) · 3 unmodified lines
347 &inlink->ch_layout, m->in_channel);368 &inlink->ch_layout, m->in_channel);
348 }369 }
349 370
350 if (m->in_channel_idx < 0 || m->in_channel_idx >= nb_channels) {371 if (check_idx_and_id(ctx, m->in_channel_idx, m->in_channel, &inlink->ch_layout, "in") < 0)
351 av_channel_layout_describe(&inlink->ch_layout, layout_name, sizeof(layout_name));
352 if (m->in_channel >= 0) {
353 av_channel_name(channel_name, sizeof(channel_name), m->in_channel);
354 av_log(ctx, AV_LOG_ERROR,
355 "input channel '%s' not available from input layout '%s'\n",
356 channel_name, layout_name);
357 } else {
358 av_log(ctx, AV_LOG_ERROR,
359 "input channel #%d not available from input layout '%s'\n",
360 m->in_channel_idx, layout_name);
361 }
362 err = AVERROR(EINVAL);372 err = AVERROR(EINVAL);
363 }
364 }373 }
365 374
366 return err;375 return err;

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