diff mbox series

[FFmpeg-devel,1/8] avfilter/tests/filtfmts: Replace macro by ordinary function

Message ID AM7PR03MB666021302B12654F39D2704C8FAF9@AM7PR03MB6660.eurprd03.prod.outlook.com
State Accepted
Commit 2b72e693c7c03f2901f53a51b195fb0c7c19c960
Headers show
Series [FFmpeg-devel,1/8] avfilter/tests/filtfmts: Replace macro by ordinary function | expand

Checks

Context Check Description
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished
andriy/make_ppc success Make finished
andriy/make_fate_ppc success Make fate finished

Commit Message

Andreas Rheinhardt Oct. 5, 2021, 8:50 p.m. UTC
This is possible now that AVFilterFormatsConfig exists.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavfilter/tests/filtfmts.c | 77 ++++++++++++++++++++----------------
 1 file changed, 42 insertions(+), 35 deletions(-)

Comments

Andreas Rheinhardt Oct. 9, 2021, 12:53 p.m. UTC | #1
Andreas Rheinhardt:
> This is possible now that AVFilterFormatsConfig exists.
> 
> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
> ---
>  libavfilter/tests/filtfmts.c | 77 ++++++++++++++++++++----------------
>  1 file changed, 42 insertions(+), 35 deletions(-)
> 
> diff --git a/libavfilter/tests/filtfmts.c b/libavfilter/tests/filtfmts.c
> index 55bb64abc5..07e387b92e 100644
> --- a/libavfilter/tests/filtfmts.c
> +++ b/libavfilter/tests/filtfmts.c
> @@ -32,43 +32,50 @@
>  #include "libavfilter/formats.h"
>  #include "libavfilter/internal.h"
>  
> +static void print_formats_internal(AVFilterLink **links, const AVFilterPad *pads,
> +                                   unsigned nb, size_t fmts_cfg_offset,
> +                                   const char *inout_string)
> +{
> +    for (unsigned i = 0; i < nb; i++) {
> +        const AVFilterLink *const link = links[i];
> +        const AVFilterFormatsConfig *const cfg = (AVFilterFormatsConfig*)((const char*)link + fmts_cfg_offset);
> +        const char *pad_name = avfilter_pad_get_name(pads, i);
> +
> +        if (link->type == AVMEDIA_TYPE_VIDEO) {
> +            const AVFilterFormats *const fmts = cfg->formats;
> +            for (unsigned j = 0; j < fmts->nb_formats; j++) {
> +                printf("%s[%u] %s: fmt:%s\n",
> +                        inout_string, i, pad_name,
> +                        av_get_pix_fmt_name(fmts->formats[j]));
> +            }
> +        } else if (link->type == AVMEDIA_TYPE_AUDIO) {
> +            const AVFilterFormats *const fmts = cfg->formats;
> +            const AVFilterChannelLayouts *const layouts = cfg->channel_layouts;
> +
> +            for (unsigned j = 0; j < fmts->nb_formats; j++)
> +                printf("%s[%u] %s: fmt:%s\n",
> +                       inout_string, i, pad_name,
> +                       av_get_sample_fmt_name(fmts->formats[j]));
> +
> +            for (unsigned j = 0; j < layouts->nb_channel_layouts; j++) {
> +                char buf[256];
> +                av_get_channel_layout_string(buf, sizeof(buf), -1,
> +                                             layouts->channel_layouts[j]);
> +                printf("%s[%u] %s: chlayout:%s\n",
> +                       inout_string, i, pad_name, buf);
> +            }
> +        }
> +    }
> +}
> +
>  static void print_formats(AVFilterContext *filter_ctx)
>  {
> -    int i, j;
> -
> -#define PRINT_FMTS(inout, outin, INOUT)                                 \
> -    for (i = 0; i < filter_ctx->nb_##inout##puts; i++) {                     \
> -        if (filter_ctx->inout##puts[i]->type == AVMEDIA_TYPE_VIDEO) {   \
> -            AVFilterFormats *fmts =                                     \
> -                filter_ctx->inout##puts[i]->outin##cfg.formats;            \
> -            for (j = 0; j < fmts->nb_formats; j++)                    \
> -                if(av_get_pix_fmt_name(fmts->formats[j]))               \
> -                printf(#INOUT "PUT[%d] %s: fmt:%s\n",                   \
> -                       i, avfilter_pad_get_name(filter_ctx->inout##put_pads, i),      \
> -                       av_get_pix_fmt_name(fmts->formats[j]));          \
> -        } else if (filter_ctx->inout##puts[i]->type == AVMEDIA_TYPE_AUDIO) { \
> -            AVFilterFormats *fmts;                                      \
> -            AVFilterChannelLayouts *layouts;                            \
> -                                                                        \
> -            fmts = filter_ctx->inout##puts[i]->outin##cfg.formats;         \
> -            for (j = 0; j < fmts->nb_formats; j++)                    \
> -                printf(#INOUT "PUT[%d] %s: fmt:%s\n",                   \
> -                       i, avfilter_pad_get_name(filter_ctx->inout##put_pads, i),      \
> -                       av_get_sample_fmt_name(fmts->formats[j]));       \
> -                                                                        \
> -            layouts = filter_ctx->inout##puts[i]->outin##cfg.channel_layouts; \
> -            for (j = 0; j < layouts->nb_channel_layouts; j++) {                  \
> -                char buf[256];                                          \
> -                av_get_channel_layout_string(buf, sizeof(buf), -1,      \
> -                                             layouts->channel_layouts[j]);         \
> -                printf(#INOUT "PUT[%d] %s: chlayout:%s\n",              \
> -                       i, avfilter_pad_get_name(filter_ctx->inout##put_pads, i), buf); \
> -            }                                                           \
> -        }                                                               \
> -    }                                                                   \
> -
> -    PRINT_FMTS(in,  out, IN);
> -    PRINT_FMTS(out, in,  OUT);
> +    print_formats_internal(filter_ctx->inputs, filter_ctx->input_pads,
> +                           filter_ctx->nb_inputs,
> +                           offsetof(AVFilterLink, outcfg), "INPUT");
> +    print_formats_internal(filter_ctx->outputs, filter_ctx->output_pads,
> +                           filter_ctx->nb_outputs,
> +                           offsetof(AVFilterLink, incfg), "OUTPUT");
>  }
>  
>  int main(int argc, char **argv)
> 

Will apply this patchset tonight unless there are objections.

- Andreas
diff mbox series

Patch

diff --git a/libavfilter/tests/filtfmts.c b/libavfilter/tests/filtfmts.c
index 55bb64abc5..07e387b92e 100644
--- a/libavfilter/tests/filtfmts.c
+++ b/libavfilter/tests/filtfmts.c
@@ -32,43 +32,50 @@ 
 #include "libavfilter/formats.h"
 #include "libavfilter/internal.h"
 
+static void print_formats_internal(AVFilterLink **links, const AVFilterPad *pads,
+                                   unsigned nb, size_t fmts_cfg_offset,
+                                   const char *inout_string)
+{
+    for (unsigned i = 0; i < nb; i++) {
+        const AVFilterLink *const link = links[i];
+        const AVFilterFormatsConfig *const cfg = (AVFilterFormatsConfig*)((const char*)link + fmts_cfg_offset);
+        const char *pad_name = avfilter_pad_get_name(pads, i);
+
+        if (link->type == AVMEDIA_TYPE_VIDEO) {
+            const AVFilterFormats *const fmts = cfg->formats;
+            for (unsigned j = 0; j < fmts->nb_formats; j++) {
+                printf("%s[%u] %s: fmt:%s\n",
+                        inout_string, i, pad_name,
+                        av_get_pix_fmt_name(fmts->formats[j]));
+            }
+        } else if (link->type == AVMEDIA_TYPE_AUDIO) {
+            const AVFilterFormats *const fmts = cfg->formats;
+            const AVFilterChannelLayouts *const layouts = cfg->channel_layouts;
+
+            for (unsigned j = 0; j < fmts->nb_formats; j++)
+                printf("%s[%u] %s: fmt:%s\n",
+                       inout_string, i, pad_name,
+                       av_get_sample_fmt_name(fmts->formats[j]));
+
+            for (unsigned j = 0; j < layouts->nb_channel_layouts; j++) {
+                char buf[256];
+                av_get_channel_layout_string(buf, sizeof(buf), -1,
+                                             layouts->channel_layouts[j]);
+                printf("%s[%u] %s: chlayout:%s\n",
+                       inout_string, i, pad_name, buf);
+            }
+        }
+    }
+}
+
 static void print_formats(AVFilterContext *filter_ctx)
 {
-    int i, j;
-
-#define PRINT_FMTS(inout, outin, INOUT)                                 \
-    for (i = 0; i < filter_ctx->nb_##inout##puts; i++) {                     \
-        if (filter_ctx->inout##puts[i]->type == AVMEDIA_TYPE_VIDEO) {   \
-            AVFilterFormats *fmts =                                     \
-                filter_ctx->inout##puts[i]->outin##cfg.formats;            \
-            for (j = 0; j < fmts->nb_formats; j++)                    \
-                if(av_get_pix_fmt_name(fmts->formats[j]))               \
-                printf(#INOUT "PUT[%d] %s: fmt:%s\n",                   \
-                       i, avfilter_pad_get_name(filter_ctx->inout##put_pads, i),      \
-                       av_get_pix_fmt_name(fmts->formats[j]));          \
-        } else if (filter_ctx->inout##puts[i]->type == AVMEDIA_TYPE_AUDIO) { \
-            AVFilterFormats *fmts;                                      \
-            AVFilterChannelLayouts *layouts;                            \
-                                                                        \
-            fmts = filter_ctx->inout##puts[i]->outin##cfg.formats;         \
-            for (j = 0; j < fmts->nb_formats; j++)                    \
-                printf(#INOUT "PUT[%d] %s: fmt:%s\n",                   \
-                       i, avfilter_pad_get_name(filter_ctx->inout##put_pads, i),      \
-                       av_get_sample_fmt_name(fmts->formats[j]));       \
-                                                                        \
-            layouts = filter_ctx->inout##puts[i]->outin##cfg.channel_layouts; \
-            for (j = 0; j < layouts->nb_channel_layouts; j++) {                  \
-                char buf[256];                                          \
-                av_get_channel_layout_string(buf, sizeof(buf), -1,      \
-                                             layouts->channel_layouts[j]);         \
-                printf(#INOUT "PUT[%d] %s: chlayout:%s\n",              \
-                       i, avfilter_pad_get_name(filter_ctx->inout##put_pads, i), buf); \
-            }                                                           \
-        }                                                               \
-    }                                                                   \
-
-    PRINT_FMTS(in,  out, IN);
-    PRINT_FMTS(out, in,  OUT);
+    print_formats_internal(filter_ctx->inputs, filter_ctx->input_pads,
+                           filter_ctx->nb_inputs,
+                           offsetof(AVFilterLink, outcfg), "INPUT");
+    print_formats_internal(filter_ctx->outputs, filter_ctx->output_pads,
+                           filter_ctx->nb_outputs,
+                           offsetof(AVFilterLink, incfg), "OUTPUT");
 }
 
 int main(int argc, char **argv)