axfer: add an option to dump available hardware parameters

In ALSA PCM interface, before configuring hardware actually, applications
can request available set of hardware parameters for runtime of PCM
substream. The set of parameters are represented and delivered by a
structure.

In alsa-lib PCM API, the above design is abstracted by a series of
snd_pcm_hw_params_xxx() functions. An actual layout of the structure is
hidden from applications by an opaque pointer.

In aplay, '--dump-hw-params' option is for this purpose. With this option,
the command output available set of the hardware parameters.

This commit adds support for the option. Unlike aplay, this commit takes
this program to finish after dumping the parameters for simplicity of
usage.

I note that all of combinations in the set are not necessarily available
when the PCM substream includes dependencies of parameters described by
constraints and rules.

Signed-off-by: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Takashi Sakamoto 2018-11-13 15:41:31 +09:00 committed by Takashi Iwai
parent 2b4d826893
commit ae378611b7
4 changed files with 16 additions and 1 deletions

View file

@ -447,7 +447,7 @@ int subcmd_transfer(int argc, char *const *argv, snd_pcm_stream_t direction)
err = context_init(&ctx, direction, argc, argv); err = context_init(&ctx, direction, argc, argv);
if (err < 0) if (err < 0)
goto end; goto end;
if (ctx.xfer.help) if (ctx.xfer.help || ctx.xfer.dump_hw_params)
goto end; goto end;
err = context_pre_process(&ctx, direction, &expected_frame_count); err = context_pre_process(&ctx, direction, &expected_frame_count);

View file

@ -99,6 +99,15 @@ static int open_handle(struct xfer_context *xfer)
// TODO: Applying NO_PERIOD_WAKEUP should be done here. // TODO: Applying NO_PERIOD_WAKEUP should be done here.
if (xfer->dump_hw_params) {
logging(state, "Available HW Params of node: %s\n",
snd_pcm_name(state->handle));
snd_pcm_hw_params_dump(state->hw_params, state->log);
// TODO: there're more parameters which are not dumped by
// alsa-lib.
return 0;
}
return set_access_hw_param(state); return set_access_hw_param(state);
} }

View file

@ -16,6 +16,7 @@
enum no_short_opts { enum no_short_opts {
// 128 or later belong to non us-ascii character set. // 128 or later belong to non us-ascii character set.
OPT_XFER_TYPE = 128, OPT_XFER_TYPE = 128,
OPT_DUMP_HW_PARAMS,
}; };
static int allocate_paths(struct xfer_context *xfer, char *const *paths, static int allocate_paths(struct xfer_context *xfer, char *const *paths,
@ -244,6 +245,8 @@ int xfer_options_parse_args(struct xfer_context *xfer,
{"file-type", 1, 0, 't'}, {"file-type", 1, 0, 't'},
// For mapper. // For mapper.
{"separate-channels", 0, 0, 'I'}, {"separate-channels", 0, 0, 'I'},
// For debugging.
{"dump-hw-params", 0, 0, OPT_DUMP_HW_PARAMS},
}; };
char *s_opts; char *s_opts;
struct option *l_opts; struct option *l_opts;
@ -302,6 +305,8 @@ int xfer_options_parse_args(struct xfer_context *xfer,
xfer->cntr_format_literal = arg_duplicate_string(optarg, &err); xfer->cntr_format_literal = arg_duplicate_string(optarg, &err);
else if (key == 'I') else if (key == 'I')
xfer->multiple_cntrs = true; xfer->multiple_cntrs = true;
else if (key == OPT_DUMP_HW_PARAMS)
xfer->dump_hw_params = true;
else if (key == '?') else if (key == '?')
return -EINVAL; return -EINVAL;
else { else {

View file

@ -34,6 +34,7 @@ struct xfer_context {
unsigned int samples_per_frame; unsigned int samples_per_frame;
bool help:1; bool help:1;
bool quiet:1; bool quiet:1;
bool dump_hw_params:1;
bool multiple_cntrs:1; // For mapper. bool multiple_cntrs:1; // For mapper.
snd_pcm_format_t sample_format; snd_pcm_format_t sample_format;