summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2006-03-20 11:26:16 +0000
committerTakashi Iwai <tiwai@suse.de>2006-03-20 11:26:16 +0000
commit5c0674aee33d8672ced5f990f505bc543cddc8c5 (patch)
treeb16d72392a850dfa72c74370c868f4407b298779
parent38a3aa096c173ccd2020794c0ba6e68d32f0b337 (diff)
Add init callback to extplug
- Fix the hw constraints of extplug - Add init callback to extplug
-rw-r--r--include/pcm_extplug.h6
-rw-r--r--src/pcm/pcm_extplug.c68
2 files changed, 50 insertions, 24 deletions
diff --git a/include/pcm_extplug.h b/include/pcm_extplug.h
index 7a822d8f..b14c5be4 100644
--- a/include/pcm_extplug.h
+++ b/include/pcm_extplug.h
@@ -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_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
*/
@@ -147,6 +147,10 @@ struct snd_pcm_extplug_callback {
* 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);
};
diff --git a/src/pcm/pcm_extplug.c b/src/pcm/pcm_extplug.c
index 2bde9e5b..fdccc53a 100644
--- a/src/pcm/pcm_extplug.c
+++ b/src/pcm/pcm_extplug.c
@@ -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)
{
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++) {
if (params[i].active)
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;
unsigned int links = get_links(ext->sparams);
- int err, change;
- err = extplug_hw_refine(sparams, ext->sparams);
- 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;
+
+ return _snd_pcm_hw_params_refine(sparams, links, params);
}
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;
unsigned int links = get_links(ext->params);
- int err, change;
- err = extplug_hw_refine(params, ext->params);
- 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;
+
+ return _snd_pcm_hw_params_refine(params, links, sparams);
}
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_cchange,
snd_pcm_extplug_hw_refine_sprepare,
snd_pcm_extplug_hw_refine_schange,
snd_pcm_generic_hw_refine);
+ return err;
}
/*
@@ -369,6 +366,15 @@ snd_pcm_extplug_read_areas(snd_pcm_t *pcm,
}
/*
+ * 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
*/
static void snd_pcm_extplug_dump(snd_pcm_t *pcm, snd_output_t *out)
@@ -480,6 +486,7 @@ struct myplug_info {
SND_PCM_PLUGIN_DEFINE_FUNC(myplug)
{
snd_config_iterator_t i, next;
+ snd_config_t *slave = NULL;
struct myplug_info *myplug;
int err;
@@ -490,6 +497,10 @@ SND_PCM_PLUGIN_DEFINE_FUNC(myplug)
continue;
if (strcmp(id, "comment") == 0 || strcmp(id, "type") == 0)
continue;
+ if (strcmp(id, "slave") == 0) {
+ slave = n;
+ continue;
+ }
if (strcmp(id, "my_own_parameter") == 0) {
....
continue;
@@ -498,6 +509,11 @@ SND_PCM_PLUGIN_DEFINE_FUNC(myplug)
return -EINVAL;
}
+ if (! slave) {
+ SNDERR("No slave defined for myplug");
+ return -EINVAL;
+ }
+
myplug = calloc(1, sizeof(*myplug));
if (myplug == NULL)
return -ENOMEM;
@@ -508,7 +524,7 @@ SND_PCM_PLUGIN_DEFINE_FUNC(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) {
myplug_free(myplug);
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
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
#snd_pcm_extplug_set_param_minmax() and #snd_pcm_extplug_set_param_list()
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.gen.slave = spcm;
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);
if (err < 0) {