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

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
116116 return 0;
117117 }
118118
119+static 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+
119143 static av_cold int channelmap_init(AVFilterContext *ctx)
120144 {
121145 ChannelMapContext *s = ctx->priv;
@@ -334,10 +358,7 @@ static int channelmap_config_input(AVFilterLink *inlink) · 212 unmodified lines
334358 {
335359 AVFilterContext *ctx = inlink->dst;
336360 ChannelMapContext *s = ctx->priv;
337− int nb_channels = inlink->ch_layout.nb_channels;
338361 int i, err = 0;
339− char channel_name[64];
340− char layout_name[256];
341362
342363 for (i = 0; i < s->nch; i++) {
343364 struct ChannelMap *m = &s->map[i];
@@ -347,20 +368,8 @@ static int channelmap_config_input(AVFilterLink *inlink) · 3 unmodified lines
347368 &inlink->ch_layout, m->in_channel);
348369 }
349370
350− if (m->in_channel_idx < 0 || m->in_channel_idx >= nb_channels) {
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− }
371+ if (check_idx_and_id(ctx, m->in_channel_idx, m->in_channel, &inlink->ch_layout, "in") < 0)
362372 err = AVERROR(EINVAL);
363− }
364373 }
365374
366375 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