diff mbox series

[FFmpeg-devel,17/25] avfilter/af_headphone: Simplify finding channel index

Message ID 20200908211856.16290-17-andreas.rheinhardt@gmail.com
State Accepted
Commit 9d1f58424aa3154e63b7c7cfed6c5311ad6a6ccc
Headers show
Series [FFmpeg-devel,01/25] avfilter/af_headphone: Don't use uninitialized buffer in log message | expand

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Andreas Rheinhardt Sept. 8, 2020, 9:18 p.m. UTC
Before this commit, the headphone filter called
av_channel_layout_extract_channel() in a loop in order to find out
the index of a channel (given via its AV_CH_* value) in a channel layout.
This commit changes this to av_get_channel_layout_channel_index()
instead.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
---
 libavfilter/af_headphone.c | 32 ++++++++------------------------
 1 file changed, 8 insertions(+), 24 deletions(-)

Comments

Paul B Mahol Sept. 9, 2020, 1:25 a.m. UTC | #1
On Tue, Sep 08, 2020 at 11:18:48PM +0200, Andreas Rheinhardt wrote:
> Before this commit, the headphone filter called
> av_channel_layout_extract_channel() in a loop in order to find out
> the index of a channel (given via its AV_CH_* value) in a channel layout.
> This commit changes this to av_get_channel_layout_channel_index()
> instead.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@gmail.com>
> ---
>  libavfilter/af_headphone.c | 32 ++++++++------------------------
>  1 file changed, 8 insertions(+), 24 deletions(-)
> 

should be fine if does not break usage.
diff mbox series

Patch

diff --git a/libavfilter/af_headphone.c b/libavfilter/af_headphone.c
index d6647ff80b..b5c2bd6121 100644
--- a/libavfilter/af_headphone.c
+++ b/libavfilter/af_headphone.c
@@ -100,7 +100,6 @@  static void parse_map(AVFilterContext *ctx)
     char *arg, *tokenizer, *p;
     uint64_t used_channels = 0;
 
-    s->lfe_channel = -1;
     s->nb_inputs = 1;
 
     p = s->map;
@@ -452,18 +451,9 @@  static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink)
         ptr = (float *)s->in[i + 1].frame->extended_data[0];
 
         if (s->hrir_fmt == HRIR_STEREO) {
-            int idx = -1;
-
-            for (j = 0; j < inlink->channels; j++) {
-                if ((av_channel_layout_extract_channel(inlink->channel_layout, j)) == s->mapping[i]) {
-                    idx = j;
-                    if (s->mapping[i] == AV_CH_LOW_FREQUENCY)
-                        s->lfe_channel = j;
-                    break;
-                }
-            }
-
-            if (idx == -1)
+            int idx = av_get_channel_layout_channel_index(inlink->channel_layout,
+                                                          s->mapping[i]);
+            if (idx < 0)
                 continue;
             if (s->type == TIME_DOMAIN) {
                 float *data_ir_l = s->data_ir[0] + idx * s->air_len;
@@ -494,17 +484,9 @@  static int convert_coeffs(AVFilterContext *ctx, AVFilterLink *inlink)
             int I, N = ctx->inputs[1]->channels;
 
             for (k = 0; k < N / 2; k++) {
-                int idx = -1;
-
-                for (j = 0; j < inlink->channels; j++) {
-                    if ((av_channel_layout_extract_channel(inlink->channel_layout, j)) == s->mapping[k]) {
-                        idx = j;
-                        if (s->mapping[k] == AV_CH_LOW_FREQUENCY)
-                            s->lfe_channel = j;
-                        break;
-                    }
-                }
-                if (idx == -1)
+                int idx = av_get_channel_layout_channel_index(inlink->channel_layout,
+                                                              s->mapping[k]);
+                if (idx < 0)
                     continue;
 
                 I = k * 2;
@@ -671,6 +653,8 @@  static int config_input(AVFilterLink *inlink)
         return AVERROR(EINVAL);
     }
 
+    s->lfe_channel = av_get_channel_layout_channel_index(inlink->channel_layout,
+                                                         AV_CH_LOW_FREQUENCY);
     return 0;
 }