]> git.alsa-project.org Git - alsa-utils.git/commitdiff
axfer: add an option to dump available hardware parameters
authorTakashi Sakamoto <o-takashi@sakamocchi.jp>
Tue, 13 Nov 2018 06:41:31 +0000 (15:41 +0900)
committerTakashi Iwai <tiwai@suse.de>
Tue, 13 Nov 2018 11:04:35 +0000 (12:04 +0100)
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>
axfer/subcmd-transfer.c
axfer/xfer-libasound.c
axfer/xfer-options.c
axfer/xfer.h

index a165a93db28b66e3432902d59fd98ceb23111d73..36817f38ac55dcaf94b2062bdd5caba89740e100 100644 (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);
        if (err < 0)
                goto end;
-       if (ctx.xfer.help)
+       if (ctx.xfer.help || ctx.xfer.dump_hw_params)
                goto end;
 
        err = context_pre_process(&ctx, direction, &expected_frame_count);
index bf1b0564de5a2c42480cb62923c274f13e43cfa9..60e9aaba027821fb708d4635eedf2289bea97286 100644 (file)
@@ -99,6 +99,15 @@ static int open_handle(struct xfer_context *xfer)
 
        // 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);
 }
 
index 7790ea9e5be31d09770750060961d1acab5ee40f..21fc6bb72d288e09d74fad0d78da56cffcce1df5 100644 (file)
@@ -16,6 +16,7 @@
 enum no_short_opts {
        // 128 or later belong to non us-ascii character set.
        OPT_XFER_TYPE = 128,
+       OPT_DUMP_HW_PARAMS,
 };
 
 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'},
                // For mapper.
                {"separate-channels",   0, 0, 'I'},
+               // For debugging.
+               {"dump-hw-params",      0, 0, OPT_DUMP_HW_PARAMS},
        };
        char *s_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);
                else if (key == 'I')
                        xfer->multiple_cntrs = true;
+               else if (key == OPT_DUMP_HW_PARAMS)
+                       xfer->dump_hw_params = true;
                else if (key == '?')
                        return -EINVAL;
                else {
index 0ed84e47dbcbe2b4bdd8d4a6d9efb2dea2fe1be4..a2348510c6334525491ff7c32596a5240a983e1a 100644 (file)
@@ -34,6 +34,7 @@ struct xfer_context {
        unsigned int samples_per_frame;
        bool help:1;
        bool quiet:1;
+       bool dump_hw_params:1;
        bool multiple_cntrs:1;  // For mapper.
 
        snd_pcm_format_t sample_format;