Skip to content

Commit

Permalink
fir.c: fir_parse_opts(): Allow additional options.
Browse files Browse the repository at this point in the history
This feature is not currently used, but may be useful in the future.
  • Loading branch information
bmc0 committed Feb 5, 2025
1 parent 999346c commit 8b17eae
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 10 deletions.
22 changes: 14 additions & 8 deletions fir.c
Original file line number Diff line number Diff line change
Expand Up @@ -473,16 +473,18 @@ sample_t * fir_read_filter(const struct effect_info *ei, const char *dir, const
return data;
}

int fir_parse_codec_opts(const struct effect_info *ei, const struct stream_info *istream, struct codec_params *p, struct dsp_getopt_state *g, int argc, const char *const *argv)
int fir_parse_opts(const struct effect_info *ei, const struct stream_info *istream, struct codec_params *p, struct dsp_getopt_state *g, int argc, const char *const *argv, const char *optstr,
int (*extra_opts_fn)(const struct effect_info *, const struct stream_info *, const struct codec_params *, int, const char *))
{
int opt;
int opt, err;
char *endptr;

*p = (struct codec_params) CODEC_PARAMS_AUTO(NULL, CODEC_MODE_READ);
p->fs = istream->fs;
p->channels = istream->channels;
if (optstr == NULL) optstr = FIR_INPUT_CODEC_OPTS;

while ((opt = dsp_getopt(g, argc, argv, "t:e:BLNr:c:")) != -1) {
while ((opt = dsp_getopt(g, argc, argv, optstr)) != -1) {
switch (opt) {
case 't': p->type = g->arg; break;
case 'e': p->enc = g->arg; break;
Expand Down Expand Up @@ -511,12 +513,16 @@ int fir_parse_codec_opts(const struct effect_info *ei, const struct stream_info
return 1;
}
break;
case ':':
LOG_FMT(LL_ERROR, "%s: error: expected argument to option '%c'", ei->name, g->opt);
return 1;
default:
if (opt == ':')
LOG_FMT(LL_ERROR, "%s: error: expected argument to option '%c'", ei->name, g->opt);
else
if (opt == '?' || extra_opts_fn == NULL) {
LOG_FMT(LL_ERROR, "%s: error: illegal option '%c'", ei->name, g->opt);
return 1;
return 1;
}
else if ((err = extra_opts_fn(ei, istream, p, opt, g->arg)) != 0)
return err;
}
}
return 0;
Expand All @@ -531,7 +537,7 @@ struct effect * fir_effect_init(const struct effect_info *ei, const struct strea
struct codec_params c_params;
struct dsp_getopt_state g = DSP_GETOPT_STATE_INITIALIZER;

int err = fir_parse_codec_opts(ei, istream, &c_params, &g, argc, argv);
int err = fir_parse_opts(ei, istream, &c_params, &g, argc, argv, NULL, NULL);
if (err || g.ind != argc-1) {
LOG_FMT(LL_ERROR, "%s: usage: %s", argv[0], ei->usage);
return NULL;
Expand Down
5 changes: 4 additions & 1 deletion fir.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
#include "codec.h"
#include "util.h"

#define FIR_INPUT_CODEC_OPTS "t:e:BLNr:c:"

struct effect * fir_effect_init_with_filter(const struct effect_info *, const struct stream_info *, const char *, sample_t *, int, ssize_t, int);
sample_t * fir_read_filter(const struct effect_info *, const char *, const struct codec_params *, int *, ssize_t *);
int fir_parse_codec_opts(const struct effect_info *, const struct stream_info *, struct codec_params *, struct dsp_getopt_state *, int, const char *const *);
int fir_parse_opts(const struct effect_info *, const struct stream_info *, struct codec_params *, struct dsp_getopt_state *, int, const char *const *, const char *,
int (*extra_opt_fn)(const struct effect_info *, const struct stream_info *, const struct codec_params *, int, const char *));
struct effect * fir_effect_init(const struct effect_info *, const struct stream_info *, const char *, const char *, int, const char *const *);

#endif
2 changes: 1 addition & 1 deletion fir_p.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ struct effect * fir_p_effect_init(const struct effect_info *ei, const struct str
struct dsp_getopt_state g = DSP_GETOPT_STATE_INITIALIZER;
char *endptr;

int err = fir_parse_codec_opts(ei, istream, &c_params, &g, argc, argv);
int err = fir_parse_opts(ei, istream, &c_params, &g, argc, argv, NULL, NULL);
if (err || g.ind < argc-2 || g.ind > argc-1) {
LOG_FMT(LL_ERROR, "%s: usage: %s", argv[0], ei->usage);
return NULL;
Expand Down

0 comments on commit 8b17eae

Please sign in to comment.