ffmpeg | branch: master | Marton Balint <c...@passwd.hu> | Tue Mar 19 01:06:20 
2024 +0100| [bba6dd391f4e9fd8cbe91a202b8f5be04bf9f133] | committer: Marton 
Balint

avfilter/af_channelmap: factorize checking indexes against a channel layout

Signed-off-by: Marton Balint <c...@passwd.hu>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=bba6dd391f4e9fd8cbe91a202b8f5be04bf9f133
---

 libavfilter/af_channelmap.c | 41 +++++++++++++++++++++++++----------------
 1 file changed, 25 insertions(+), 16 deletions(-)

diff --git a/libavfilter/af_channelmap.c b/libavfilter/af_channelmap.c
index 1ecbddd462..62e11103ad 100644
--- a/libavfilter/af_channelmap.c
+++ b/libavfilter/af_channelmap.c
@@ -116,6 +116,30 @@ static int get_channel(char **map, int *ch, char delim)
     return 0;
 }
 
+static int check_idx_and_id(AVFilterContext *ctx, int channel_idx, int 
channel, AVChannelLayout *ch_layout, const char *io)
+{
+    char channel_name[64];
+    char layout_name[256];
+    int nb_channels = ch_layout->nb_channels;
+
+    if (channel_idx < 0 || channel_idx >= nb_channels) {
+        av_channel_layout_describe(ch_layout, layout_name, 
sizeof(layout_name));
+        if (channel >= 0) {
+            av_channel_name(channel_name, sizeof(channel_name), channel);
+            av_log(ctx, AV_LOG_ERROR,
+                   "%sput channel '%s' not available from %sput layout '%s'\n",
+                   io, channel_name, io, layout_name);
+        } else {
+            av_log(ctx, AV_LOG_ERROR,
+                   "%sput channel #%d not available from %sput layout '%s'\n",
+                   io, channel_idx, io, layout_name);
+        }
+        return AVERROR(EINVAL);
+    }
+
+    return 0;
+}
+
 static av_cold int channelmap_init(AVFilterContext *ctx)
 {
     ChannelMapContext *s = ctx->priv;
@@ -334,10 +358,7 @@ static int channelmap_config_input(AVFilterLink *inlink)
 {
     AVFilterContext *ctx = inlink->dst;
     ChannelMapContext *s = ctx->priv;
-    int nb_channels = inlink->ch_layout.nb_channels;
     int i, err = 0;
-    char channel_name[64];
-    char layout_name[256];
 
     for (i = 0; i < s->nch; i++) {
         struct ChannelMap *m = &s->map[i];
@@ -347,20 +368,8 @@ static int channelmap_config_input(AVFilterLink *inlink)
                 &inlink->ch_layout, m->in_channel);
         }
 
-        if (m->in_channel_idx < 0 || m->in_channel_idx >= nb_channels) {
-            av_channel_layout_describe(&inlink->ch_layout, layout_name, 
sizeof(layout_name));
-            if (m->in_channel >= 0) {
-                av_channel_name(channel_name, sizeof(channel_name), 
m->in_channel);
-                av_log(ctx, AV_LOG_ERROR,
-                       "input channel '%s' not available from input layout 
'%s'\n",
-                       channel_name, layout_name);
-            } else {
-                av_log(ctx, AV_LOG_ERROR,
-                       "input channel #%d not available from input layout 
'%s'\n",
-                       m->in_channel_idx, layout_name);
-            }
+        if (check_idx_and_id(ctx, m->in_channel_idx, m->in_channel, 
&inlink->ch_layout, "in") < 0)
             err = AVERROR(EINVAL);
-        }
     }
 
     return err;

_______________________________________________
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

To unsubscribe, visit link above, or email
ffmpeg-cvslog-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to