alsa-lib/include/pcm_extplug.h
Timo Wischer ee64b4b83a 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>
2018-12-10 11:53:41 +01:00

208 lines
6.2 KiB
C

/**
* \file include/pcm_extplug.h
* \brief External Filter-Plugin SDK
* \author Takashi Iwai <tiwai@suse.de>
* \date 2005
*
* External Filter-Plugin SDK
*/
/*
* ALSA external PCM plugin SDK (draft version)
*
* Copyright (c) 2005 Takashi Iwai <tiwai@suse.de>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef __ALSA_PCM_EXTPLUG_H
#define __ALSA_PCM_EXTPLUG_H
/**
* \defgroup PCM_ExtPlug External Filter plugin SDK
* \ingroup Plugin_SDK
* See the \ref pcm page for more details.
* \{
*/
/** hw constraints for extplug */
enum {
SND_PCM_EXTPLUG_HW_FORMAT, /**< format */
SND_PCM_EXTPLUG_HW_CHANNELS, /**< channels */
SND_PCM_EXTPLUG_HW_PARAMS /**< max number of hw constraints */
};
/** Handle of external filter plugin */
typedef struct snd_pcm_extplug snd_pcm_extplug_t;
/** Callback table of extplug */
typedef struct snd_pcm_extplug_callback snd_pcm_extplug_callback_t;
#ifdef DOC_HIDDEN
/* redefine typedefs for stupid doxygen */
typedef snd_pcm_extplug snd_pcm_extplug_t;
typedef snd_pcm_extplug_callback snd_pcm_extplug_callback_t;
#endif
/*
* Protocol version
*/
#define SND_PCM_EXTPLUG_VERSION_MAJOR 1 /**< Protocol major version */
#define SND_PCM_EXTPLUG_VERSION_MINOR 0 /**< Protocol minor version */
#define SND_PCM_EXTPLUG_VERSION_TINY 2 /**< Protocol tiny version */
/**
* Filter-plugin protocol version
*/
#define SND_PCM_EXTPLUG_VERSION ((SND_PCM_EXTPLUG_VERSION_MAJOR<<16) |\
(SND_PCM_EXTPLUG_VERSION_MINOR<<8) |\
(SND_PCM_EXTPLUG_VERSION_TINY))
/** Handle of extplug */
struct snd_pcm_extplug {
/**
* protocol version; #SND_PCM_EXTPLUG_VERSION must be filled here
* before calling #snd_pcm_extplug_create()
*/
unsigned int version;
/**
* name of this plugin; must be filled before calling #snd_pcm_extplug_create()
*/
const char *name;
/**
* callbacks of this plugin; must be filled before calling #snd_pcm_extplug_create()
*/
const snd_pcm_extplug_callback_t *callback;
/**
* private data, which can be used freely in the driver callbacks
*/
void *private_data;
/**
* PCM handle filled by #snd_pcm_extplug_create()
*/
snd_pcm_t *pcm;
/**
* stream direction; read-only status
*/
snd_pcm_stream_t stream;
/**
* format hw parameter; filled after hw_params is caled
*/
snd_pcm_format_t format;
/**
* subformat hw parameter; filled after hw_params is caled
*/
snd_pcm_subformat_t subformat;
/**
* channels hw parameter; filled after hw_params is caled
*/
unsigned int channels;
/**
* rate hw parameter; filled after hw_params is caled
*/
unsigned int rate;
/**
* slave_format hw parameter; filled after hw_params is caled
*/
snd_pcm_format_t slave_format;
/**
* slave_subformat hw parameter; filled after hw_params is caled
*/
snd_pcm_subformat_t slave_subformat;
/**
* slave_channels hw parameter; filled after hw_params is caled
*/
unsigned int slave_channels;
};
/** Callback table of extplug */
struct snd_pcm_extplug_callback {
/**
* transfer between source and destination; this is a required callback
*/
snd_pcm_sframes_t (*transfer)(snd_pcm_extplug_t *ext,
const snd_pcm_channel_area_t *dst_areas,
snd_pcm_uframes_t dst_offset,
const snd_pcm_channel_area_t *src_areas,
snd_pcm_uframes_t src_offset,
snd_pcm_uframes_t size);
/**
* close the PCM; optional
*/
int (*close)(snd_pcm_extplug_t *ext);
/**
* hw_params; optional
*/
int (*hw_params)(snd_pcm_extplug_t *ext, snd_pcm_hw_params_t *params);
/**
* hw_free; optional
*/
int (*hw_free)(snd_pcm_extplug_t *ext);
/**
* dump; optional
*/
void (*dump)(snd_pcm_extplug_t *ext, snd_output_t *out);
/**
* init; optional initialization called at prepare or reset
*/
int (*init)(snd_pcm_extplug_t *ext);
/**
* query the channel maps; optional; since v1.0.2
*/
snd_pcm_chmap_query_t **(*query_chmaps)(snd_pcm_extplug_t *ext);
/**
* get the channel map; optional; since v1.0.2
*/
snd_pcm_chmap_t *(*get_chmap)(snd_pcm_extplug_t *ext);
/**
* set the channel map; optional; since v1.0.2
*/
int (*set_chmap)(snd_pcm_extplug_t *ext, const snd_pcm_chmap_t *map);
};
int snd_pcm_extplug_create(snd_pcm_extplug_t *ext, const char *name,
snd_config_t *root, snd_config_t *slave_conf,
snd_pcm_stream_t stream, int mode);
int snd_pcm_extplug_delete(snd_pcm_extplug_t *ext);
/* clear hw_parameter setting */
void snd_pcm_extplug_params_reset(snd_pcm_extplug_t *ext);
/* hw_parameter setting */
int snd_pcm_extplug_set_param_list(snd_pcm_extplug_t *extplug, int type, unsigned int num_list, const unsigned int *list);
int snd_pcm_extplug_set_param_minmax(snd_pcm_extplug_t *extplug, int type, unsigned int min, unsigned int max);
int snd_pcm_extplug_set_slave_param_list(snd_pcm_extplug_t *extplug, int type, unsigned int num_list, const unsigned int *list);
int snd_pcm_extplug_set_slave_param_minmax(snd_pcm_extplug_t *extplug, int type, unsigned int min, unsigned int max);
int snd_pcm_extplug_set_param_link(snd_pcm_extplug_t *extplug, int type,
int keep_link);
/**
* set the parameter constraint with a single value
*/
static __inline__ int snd_pcm_extplug_set_param(snd_pcm_extplug_t *extplug, int type, unsigned int val)
{
return snd_pcm_extplug_set_param_list(extplug, type, 1, &val);
}
/**
* set the parameter constraint for slave PCM with a single value
*/
static __inline__ int snd_pcm_extplug_set_slave_param(snd_pcm_extplug_t *extplug, int type, unsigned int val)
{
return snd_pcm_extplug_set_slave_param_list(extplug, type, 1, &val);
}
/** \} */
#endif /* __ALSA_PCM_EXTPLUG_H */