summaryrefslogtreecommitdiff
path: root/libavfilter/af_aformat.c
diff options
context:
space:
mode:
authorStefano Sabatini <stefano.sabatini-lala@poste.it>2011-08-16 16:54:04 +0200
committerStefano Sabatini <stefano.sabatini-lala@poste.it>2011-08-22 10:34:43 +0200
commit8aa62bb950a75415e8d09a37464d60584ddaf206 (patch)
treefffeb41508f5213ddb7f564a576109f9d5349ba9 /libavfilter/af_aformat.c
parent5fa98ab42d221c294b0b35ad3d2f6dd3170cc594 (diff)
af_aformat: use evil ADD_FORMATS macro for cutting out duplicated code
Diffstat (limited to 'libavfilter/af_aformat.c')
-rw-r--r--libavfilter/af_aformat.c74
1 files changed, 22 insertions, 52 deletions
diff --git a/libavfilter/af_aformat.c b/libavfilter/af_aformat.c
index c753ea7b60..0eb7dfa4e2 100644
--- a/libavfilter/af_aformat.c
+++ b/libavfilter/af_aformat.c
@@ -42,60 +42,30 @@ static av_cold int init(AVFilterContext *ctx, const char *args, void *opaque)
if (!args)
goto arg_fail;
- fmts_str = av_get_token(&args, ":");
- if (!fmts_str || !*fmts_str)
- goto arg_fail;
- if (!strcmp(fmts_str, "all")) {
- aformat->formats = avfilter_all_formats(AVMEDIA_TYPE_AUDIO);
- } else {
- for (fmt_str = fmts_str;
- fmt_str = strtok_r(fmt_str, ",", &ptr); fmt_str = NULL) {
- if ((ret = ff_parse_sample_format((int*)&fmt, fmt_str, ctx)) < 0) {
- av_freep(&fmts_str);
- return ret;
- }
- avfilter_add_format(&aformat->formats, fmt);
- }
- }
- av_freep(&fmts_str);
-
- if (*args)
+#define ADD_FORMATS(all_formats, fmt_name, fmt_type, fmts_list) \
+ fmts_str = av_get_token(&args, ":"); \
+ if (!fmts_str || !*fmts_str) \
+ goto arg_fail; \
+ if (!strcmp(fmts_str, "all")) { \
+ aformat->fmts_list = all_formats; \
+ } else { \
+ for (fmt_str = fmts_str; \
+ fmt_str = strtok_r(fmt_str, ",", &ptr); fmt_str = NULL) { \
+ if ((ret = ff_parse_##fmt_name((fmt_type *)&fmt, \
+ fmt_str, ctx)) < 0) { \
+ av_freep(&fmts_str); \
+ return ret; \
+ } \
+ avfilter_add_format(&aformat->fmts_list, fmt); \
+ } \
+ } \
+ av_freep(&fmts_str); \
+ if (*args) \
args++;
- fmts_str = av_get_token(&args, ":");
- if (!fmts_str || !*fmts_str)
- goto arg_fail;
- if (!strcmp(fmts_str, "all")) {
- aformat->chlayouts = avfilter_all_channel_layouts();
- } else {
- for (fmt_str = fmts_str;
- fmt_str = strtok_r(fmt_str, ",", &ptr); fmt_str = NULL) {
- if ((ret = ff_parse_channel_layout(&fmt, fmt_str, ctx)) < 0) {
- av_freep(&fmts_str);
- return ret;
- }
- avfilter_add_format(&aformat->chlayouts, fmt);
- }
- }
- av_freep(&fmts_str);
- if (*args)
- args++;
- fmts_str = av_get_token(&args, ":");
- if (!fmts_str || !*fmts_str)
- goto arg_fail;
- if (!strcmp(fmts_str, "all")) {
- aformat->packing = avfilter_all_packing_formats();
- } else {
- for (fmt_str = fmts_str;
- fmt_str = strtok_r(fmt_str, ",", &ptr); fmt_str = NULL) {
- if ((ret = ff_parse_packing_format((int*)&fmt, fmt_str, ctx)) < 0) {
- av_freep(&fmts_str);
- return ret;
- }
- avfilter_add_format(&aformat->packing, fmt);
- }
- }
- av_freep(&fmts_str);
+ ADD_FORMATS(avfilter_all_formats(AVMEDIA_TYPE_AUDIO), sample_format, int, formats);
+ ADD_FORMATS(avfilter_all_channel_layouts(), channel_layout, int64_t, chlayouts);
+ ADD_FORMATS(avfilter_all_packing_formats(), packing_format, int, packing);
return 0;