@@ -473,16 +473,18 @@ sample_t * fir_read_filter(const struct effect_info *ei, const char *dir, const
473
473
return data ;
474
474
}
475
475
476
- 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 )
476
+ 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 ,
477
+ int (* extra_opts_fn )(const struct effect_info * , const struct stream_info * , const struct codec_params * , int , const char * ))
477
478
{
478
- int opt ;
479
+ int opt , err ;
479
480
char * endptr ;
480
481
481
482
* p = (struct codec_params ) CODEC_PARAMS_AUTO (NULL , CODEC_MODE_READ );
482
483
p -> fs = istream -> fs ;
483
484
p -> channels = istream -> channels ;
485
+ if (optstr == NULL ) optstr = FIR_INPUT_CODEC_OPTS ;
484
486
485
- while ((opt = dsp_getopt (g , argc , argv , "t:e:BLNr:c:" )) != -1 ) {
487
+ while ((opt = dsp_getopt (g , argc , argv , optstr )) != -1 ) {
486
488
switch (opt ) {
487
489
case 't' : p -> type = g -> arg ; break ;
488
490
case 'e' : p -> enc = g -> arg ; break ;
@@ -511,12 +513,16 @@ int fir_parse_codec_opts(const struct effect_info *ei, const struct stream_info
511
513
return 1 ;
512
514
}
513
515
break ;
516
+ case ':' :
517
+ LOG_FMT (LL_ERROR , "%s: error: expected argument to option '%c'" , ei -> name , g -> opt );
518
+ return 1 ;
514
519
default :
515
- if (opt == ':' )
516
- LOG_FMT (LL_ERROR , "%s: error: expected argument to option '%c'" , ei -> name , g -> opt );
517
- else
520
+ if (opt == '?' || extra_opts_fn == NULL ) {
518
521
LOG_FMT (LL_ERROR , "%s: error: illegal option '%c'" , ei -> name , g -> opt );
519
- return 1 ;
522
+ return 1 ;
523
+ }
524
+ else if ((err = extra_opts_fn (ei , istream , p , opt , g -> arg )) != 0 )
525
+ return err ;
520
526
}
521
527
}
522
528
return 0 ;
@@ -531,7 +537,7 @@ struct effect * fir_effect_init(const struct effect_info *ei, const struct strea
531
537
struct codec_params c_params ;
532
538
struct dsp_getopt_state g = DSP_GETOPT_STATE_INITIALIZER ;
533
539
534
- int err = fir_parse_codec_opts (ei , istream , & c_params , & g , argc , argv );
540
+ int err = fir_parse_opts (ei , istream , & c_params , & g , argc , argv , NULL , NULL );
535
541
if (err || g .ind != argc - 1 ) {
536
542
LOG_FMT (LL_ERROR , "%s: usage: %s" , argv [0 ], ei -> usage );
537
543
return NULL ;
0 commit comments