mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-10-31 22:25:35 -04:00
Add init callback to extplug
- Fix the hw constraints of extplug - Add init callback to extplug
This commit is contained in:
parent
38a3aa096c
commit
5c0674aee3
2 changed files with 50 additions and 24 deletions
|
|
@ -55,7 +55,7 @@ typedef struct snd_pcm_extplug_callback snd_pcm_extplug_callback_t;
|
||||||
*/
|
*/
|
||||||
#define SND_PCM_EXTPLUG_VERSION_MAJOR 1 /**< Protocol major 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_MINOR 0 /**< Protocol minor version */
|
||||||
#define SND_PCM_EXTPLUG_VERSION_TINY 0 /**< Protocol tiny version */
|
#define SND_PCM_EXTPLUG_VERSION_TINY 1 /**< Protocol tiny version */
|
||||||
/**
|
/**
|
||||||
* Filter-plugin protocol version
|
* Filter-plugin protocol version
|
||||||
*/
|
*/
|
||||||
|
|
@ -147,6 +147,10 @@ struct snd_pcm_extplug_callback {
|
||||||
* dump; optional
|
* dump; optional
|
||||||
*/
|
*/
|
||||||
void (*dump)(snd_pcm_extplug_t *ext, snd_output_t *out);
|
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);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -228,7 +228,19 @@ static int snd_pcm_extplug_hw_refine_sprepare(snd_pcm_t *pcm,
|
||||||
static unsigned int get_links(struct snd_ext_parm *params)
|
static unsigned int get_links(struct snd_ext_parm *params)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
unsigned int links = -1;
|
unsigned int links = (SND_PCM_HW_PARBIT_FORMAT |
|
||||||
|
SND_PCM_HW_PARBIT_SUBFORMAT |
|
||||||
|
SND_PCM_HW_PARBIT_SAMPLE_BITS |
|
||||||
|
SND_PCM_HW_PARBIT_CHANNELS |
|
||||||
|
SND_PCM_HW_PARBIT_FRAME_BITS |
|
||||||
|
SND_PCM_HW_PARBIT_RATE |
|
||||||
|
SND_PCM_HW_PARBIT_PERIODS |
|
||||||
|
SND_PCM_HW_PARBIT_PERIOD_SIZE |
|
||||||
|
SND_PCM_HW_PARBIT_PERIOD_TIME |
|
||||||
|
SND_PCM_HW_PARBIT_BUFFER_SIZE |
|
||||||
|
SND_PCM_HW_PARBIT_BUFFER_TIME |
|
||||||
|
SND_PCM_HW_PARBIT_TICK_TIME);
|
||||||
|
|
||||||
for (i = 0; i < SND_PCM_EXTPLUG_HW_PARAMS; i++) {
|
for (i = 0; i < SND_PCM_EXTPLUG_HW_PARAMS; i++) {
|
||||||
if (params[i].active)
|
if (params[i].active)
|
||||||
links &= ~excl_parbits[i];
|
links &= ~excl_parbits[i];
|
||||||
|
|
@ -242,16 +254,8 @@ static int snd_pcm_extplug_hw_refine_schange(snd_pcm_t *pcm,
|
||||||
{
|
{
|
||||||
extplug_priv_t *ext = pcm->private_data;
|
extplug_priv_t *ext = pcm->private_data;
|
||||||
unsigned int links = get_links(ext->sparams);
|
unsigned int links = get_links(ext->sparams);
|
||||||
int err, change;
|
|
||||||
err = extplug_hw_refine(sparams, ext->sparams);
|
return _snd_pcm_hw_params_refine(sparams, links, params);
|
||||||
if (err < 0)
|
|
||||||
return err;
|
|
||||||
change = err;
|
|
||||||
err = _snd_pcm_hw_params_refine(sparams, links, params);
|
|
||||||
if (err < 0)
|
|
||||||
return err;
|
|
||||||
change |= err;
|
|
||||||
return change;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int snd_pcm_extplug_hw_refine_cchange(snd_pcm_t *pcm,
|
static int snd_pcm_extplug_hw_refine_cchange(snd_pcm_t *pcm,
|
||||||
|
|
@ -260,26 +264,19 @@ static int snd_pcm_extplug_hw_refine_cchange(snd_pcm_t *pcm,
|
||||||
{
|
{
|
||||||
extplug_priv_t *ext = pcm->private_data;
|
extplug_priv_t *ext = pcm->private_data;
|
||||||
unsigned int links = get_links(ext->params);
|
unsigned int links = get_links(ext->params);
|
||||||
int err, change;
|
|
||||||
err = extplug_hw_refine(params, ext->params);
|
return _snd_pcm_hw_params_refine(params, links, sparams);
|
||||||
if (err < 0)
|
|
||||||
return err;
|
|
||||||
change = err;
|
|
||||||
err = _snd_pcm_hw_params_refine(params, links, sparams);
|
|
||||||
if (err < 0)
|
|
||||||
return err;
|
|
||||||
change |= err;
|
|
||||||
return change;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int snd_pcm_extplug_hw_refine(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
|
static int snd_pcm_extplug_hw_refine(snd_pcm_t *pcm, snd_pcm_hw_params_t *params)
|
||||||
{
|
{
|
||||||
return snd_pcm_hw_refine_slave(pcm, params,
|
int err = snd_pcm_hw_refine_slave(pcm, params,
|
||||||
snd_pcm_extplug_hw_refine_cprepare,
|
snd_pcm_extplug_hw_refine_cprepare,
|
||||||
snd_pcm_extplug_hw_refine_cchange,
|
snd_pcm_extplug_hw_refine_cchange,
|
||||||
snd_pcm_extplug_hw_refine_sprepare,
|
snd_pcm_extplug_hw_refine_sprepare,
|
||||||
snd_pcm_extplug_hw_refine_schange,
|
snd_pcm_extplug_hw_refine_schange,
|
||||||
snd_pcm_generic_hw_refine);
|
snd_pcm_generic_hw_refine);
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
@ -368,6 +365,15 @@ snd_pcm_extplug_read_areas(snd_pcm_t *pcm,
|
||||||
return size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* call init callback
|
||||||
|
*/
|
||||||
|
static int snd_pcm_extplug_init(snd_pcm_t *pcm)
|
||||||
|
{
|
||||||
|
extplug_priv_t *ext = pcm->private_data;
|
||||||
|
return ext->data->callback->init(ext->data);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* dump setup
|
* dump setup
|
||||||
*/
|
*/
|
||||||
|
|
@ -480,6 +486,7 @@ struct myplug_info {
|
||||||
SND_PCM_PLUGIN_DEFINE_FUNC(myplug)
|
SND_PCM_PLUGIN_DEFINE_FUNC(myplug)
|
||||||
{
|
{
|
||||||
snd_config_iterator_t i, next;
|
snd_config_iterator_t i, next;
|
||||||
|
snd_config_t *slave = NULL;
|
||||||
struct myplug_info *myplug;
|
struct myplug_info *myplug;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
|
|
@ -490,6 +497,10 @@ SND_PCM_PLUGIN_DEFINE_FUNC(myplug)
|
||||||
continue;
|
continue;
|
||||||
if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0)
|
if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0)
|
||||||
continue;
|
continue;
|
||||||
|
if (strcmp(id, "slave") == 0) {
|
||||||
|
slave = n;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (strcmp(id, "my_own_parameter") == 0) {
|
if (strcmp(id, "my_own_parameter") == 0) {
|
||||||
....
|
....
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -498,6 +509,11 @@ SND_PCM_PLUGIN_DEFINE_FUNC(myplug)
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! slave) {
|
||||||
|
SNDERR("No slave defined for myplug");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
myplug = calloc(1, sizeof(*myplug));
|
myplug = calloc(1, sizeof(*myplug));
|
||||||
if (myplug == NULL)
|
if (myplug == NULL)
|
||||||
return -ENOMEM;
|
return -ENOMEM;
|
||||||
|
|
@ -508,7 +524,7 @@ SND_PCM_PLUGIN_DEFINE_FUNC(myplug)
|
||||||
myplug->ext.private_data = myplug;
|
myplug->ext.private_data = myplug;
|
||||||
....
|
....
|
||||||
|
|
||||||
err = snd_pcm_extplug_create(&myplug->ext, name, stream, mode);
|
err = snd_pcm_extplug_create(&myplug->ext, name, root, conf, stream, mode);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
myplug_free(myplug);
|
myplug_free(myplug);
|
||||||
return err;
|
return err;
|
||||||
|
|
@ -562,6 +578,10 @@ again. The hw_params and hw_free callbacks are called at
|
||||||
respectively. The last, dump callback, is called for printing the
|
respectively. The last, dump callback, is called for printing the
|
||||||
information of the given plugin.
|
information of the given plugin.
|
||||||
|
|
||||||
|
The init callback is called when the PCM is at prepare state or any
|
||||||
|
initialization is issued. Use this callback to reset the PCM instance
|
||||||
|
to a sane initial state.
|
||||||
|
|
||||||
The hw_params constraints can be defined via either
|
The hw_params constraints can be defined via either
|
||||||
#snd_pcm_extplug_set_param_minmax() and #snd_pcm_extplug_set_param_list()
|
#snd_pcm_extplug_set_param_minmax() and #snd_pcm_extplug_set_param_list()
|
||||||
functions after calling #snd_pcm_extplug_create().
|
functions after calling #snd_pcm_extplug_create().
|
||||||
|
|
@ -641,6 +661,8 @@ int snd_pcm_extplug_create(snd_pcm_extplug_t *extplug, const char *name,
|
||||||
ext->plug.undo_write = snd_pcm_plugin_undo_write_generic;
|
ext->plug.undo_write = snd_pcm_plugin_undo_write_generic;
|
||||||
ext->plug.gen.slave = spcm;
|
ext->plug.gen.slave = spcm;
|
||||||
ext->plug.gen.close_slave = 1;
|
ext->plug.gen.close_slave = 1;
|
||||||
|
if (extplug->callback->init)
|
||||||
|
ext->plug.init = snd_pcm_extplug_init;
|
||||||
|
|
||||||
err = snd_pcm_new(&pcm, SND_PCM_TYPE_EXTPLUG, name, stream, mode);
|
err = snd_pcm_new(&pcm, SND_PCM_TYPE_EXTPLUG, name, stream, mode);
|
||||||
if (err < 0) {
|
if (err < 0) {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue