]> git.alsa-project.org Git - alsa-lib.git/commit
pcm: extplug: Keep format and channels the same if requested
authorTimo Wischer <twischer@de.adit-jv.com>
Mon, 10 Dec 2018 10:33:16 +0000 (11:33 +0100)
committerTakashi Iwai <tiwai@suse.de>
Mon, 10 Dec 2018 10:53:41 +0000 (11:53 +0100)
commitee64b4b83afc0b1bdf99e1ccf7e6ea4602ef613f
tree94bba18289e46b2aa5b73c7404daf194365ee049
parentc9fcf9836907b1ccda0c1f72b698ee5c5dd5199c
pcm: extplug: Keep format and channels the same if requested

Without this patch it is not possible to link the channel and format
parameter if snd_pcm_extplug_set_param_*() or
snd_pcm_extplug_set_slave_param_*() is called. Therefore the client and
slave parameter can differ. So the extplug has to implement conversion.

To avoid this the new snd_pcm_extplug_set_param_link() function can be
called.
As a reproduction sceanrio the following extplug source code can be used:

===
static snd_pcm_sframes_t my_transfer(snd_pcm_extplug_t *e,
const snd_pcm_channel_area_t *da, snd_pcm_uframes_t dof,
const snd_pcm_channel_area_t *sa, snd_pcm_uframes_t sof,
snd_pcm_uframes_t s) {
return s;
}
static const snd_pcm_extplug_callback_t my_own_callback = {
.transfer = my_transfer
};
SND_PCM_PLUGIN_DEFINE_FUNC(my_plug) {
snd_config_iterator_t i, next;
snd_config_t *slave = NULL;
snd_pcm_extplug_t *myplug;
snd_config_for_each(i, next, conf) {
snd_config_t *n = snd_config_iterator_entry(i);
const char *id;
if (snd_config_get_id(n, &id) < 0)
continue;
if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0)
continue;
if (strcmp(id, "slave") == 0) {
slave = n;
continue;
}
return -EINVAL;
}
myplug = calloc(1, sizeof(*myplug));
myplug->version = SND_PCM_EXTPLUG_VERSION;
myplug->callback = &my_own_callback;
snd_pcm_extplug_create(myplug, name, root, slave, stream, mode);

snd_pcm_extplug_set_param_minmax(myplug,
SND_PCM_EXTPLUG_HW_CHANNELS, 1, 16);
// snd_pcm_extplug_set_param_link(myplug, SND_PCM_EXTPLUG_HW_CHANNELS, 1);

*pcmp = myplug->pcm;
return 0;
}
SND_PCM_PLUGIN_SYMBOL(my_plug);
===

To use this plugin the following ALSA configuration is required:

pcm.myplug {
    type my_plug
    slave.pcm hw:Dummy
}

With this configuration without this patch
snd_pcm_hw_params_get_channels_max() will always return 16 channels
independent of the supported channels of the dummy device. Due to that for
example the start up of JACK would fail:

$ modprobe snd_dummy
$ jackd -d alsa -P myplug
ALSA: cannot set channel count to 16 for playback
ALSA: cannot configure playback channel

Signed-off-by: Timo Wischer <twischer@de.adit-jv.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
include/pcm_extplug.h
src/pcm/pcm_ext_parm.h
src/pcm/pcm_extplug.c