pcm_ladspa - fix none policy

In some configurations, channel samples were not copied correctly.
Also, fix memory leaks and remove extra end-of-line chars from SNDERR
strings.
This commit is contained in:
Jaroslav Kysela 2006-12-20 16:01:27 +01:00
parent 2c02c139f4
commit 4a1cefd24d

View file

@ -406,33 +406,36 @@ static int snd_pcm_ladspa_connect_plugin1(snd_pcm_ladspa_plugin_t *plugin,
snd_pcm_ladspa_plugin_io_t *io, snd_pcm_ladspa_plugin_io_t *io,
snd_pcm_ladspa_eps_t *eps) snd_pcm_ladspa_eps_t *eps)
{ {
unsigned int port, channels, idx; unsigned int port, channels, idx, idx1;
int err; int err;
assert(plugin->policy == SND_PCM_LADSPA_POLICY_NONE); assert(plugin->policy == SND_PCM_LADSPA_POLICY_NONE);
channels = io->port_bindings_size > 0 ? channels = io->port_bindings_size > 0 ?
io->port_bindings_size : io->port_bindings_size :
snd_pcm_ladspa_count_ports(plugin, io->pdesc | LADSPA_PORT_AUDIO); snd_pcm_ladspa_count_ports(plugin, io->pdesc | LADSPA_PORT_AUDIO);
for (idx = 0; idx < channels; idx++) { for (idx = idx1 = 0; idx < channels; idx++) {
if (io->port_bindings_size > 0) if (io->port_bindings_size > 0)
port = io->port_bindings[idx]; port = io->port_bindings[idx];
else { else {
err = snd_pcm_ladspa_find_port(&port, plugin, io->pdesc | LADSPA_PORT_AUDIO, idx); err = snd_pcm_ladspa_find_port(&port, plugin, io->pdesc | LADSPA_PORT_AUDIO, idx);
if (err < 0) { if (err < 0) {
SNDERR("unable to find audio %s port %u plugin '%s'\n", io->pdesc & LADSPA_PORT_INPUT ? "input" : "output", idx, plugin->desc->Name); SNDERR("unable to find audio %s port %u plugin '%s'", io->pdesc & LADSPA_PORT_INPUT ? "input" : "output", idx, plugin->desc->Name);
return err; return err;
} }
} }
err = snd_pcm_ladspa_add_to_carray(&eps->channels, idx, idx); if (port == NO_ASSIGN)
continue;
err = snd_pcm_ladspa_add_to_carray(&eps->channels, idx1, idx);
if (err < 0) { if (err < 0) {
SNDERR("unable to add channel %u for audio %s plugin '%s'\n", idx, io->pdesc & LADSPA_PORT_INPUT ? "input" : "output", plugin->desc->Name); SNDERR("unable to add channel %u for audio %s plugin '%s'", idx, io->pdesc & LADSPA_PORT_INPUT ? "input" : "output", plugin->desc->Name);
return err; return err;
} }
err = snd_pcm_ladspa_add_to_array(&eps->ports, idx, port); err = snd_pcm_ladspa_add_to_array(&eps->ports, idx1, port);
if (err < 0) { if (err < 0) {
SNDERR("unable to add port %u for audio %s plugin '%s'\n", port, io->pdesc & LADSPA_PORT_INPUT ? "input" : "output", plugin->desc->Name); SNDERR("unable to add port %u for audio %s plugin '%s'", port, io->pdesc & LADSPA_PORT_INPUT ? "input" : "output", plugin->desc->Name);
return err; return err;
} }
idx1++;
} }
return 0; return 0;
} }
@ -465,18 +468,18 @@ static int snd_pcm_ladspa_connect_plugin_duplicate1(snd_pcm_ladspa_plugin_t *plu
} else { } else {
err = snd_pcm_ladspa_find_port(&port, plugin, io->pdesc | LADSPA_PORT_AUDIO, 0); err = snd_pcm_ladspa_find_port(&port, plugin, io->pdesc | LADSPA_PORT_AUDIO, 0);
if (err < 0) { if (err < 0) {
SNDERR("unable to find audio %s port %u plugin '%s'\n", io->pdesc & LADSPA_PORT_INPUT ? "input" : "output", (unsigned int)0, plugin->desc->Name); SNDERR("unable to find audio %s port %u plugin '%s'", io->pdesc & LADSPA_PORT_INPUT ? "input" : "output", (unsigned int)0, plugin->desc->Name);
return err; return err;
} }
} }
err = snd_pcm_ladspa_add_to_carray(&eps->channels, 0, idx); err = snd_pcm_ladspa_add_to_carray(&eps->channels, 0, idx);
if (err < 0) { if (err < 0) {
SNDERR("unable to add channel %u for audio %s plugin '%s'\n", idx, io->pdesc & LADSPA_PORT_INPUT ? "input" : "output", plugin->desc->Name); SNDERR("unable to add channel %u for audio %s plugin '%s'", idx, io->pdesc & LADSPA_PORT_INPUT ? "input" : "output", plugin->desc->Name);
return err; return err;
} }
err = snd_pcm_ladspa_add_to_array(&eps->ports, 0, port); err = snd_pcm_ladspa_add_to_array(&eps->ports, 0, port);
if (err < 0) { if (err < 0) {
SNDERR("unable to add port %u for audio %s plugin '%s'\n", port, io->pdesc & LADSPA_PORT_INPUT ? "input" : "output", plugin->desc->Name); SNDERR("unable to add port %u for audio %s plugin '%s'", port, io->pdesc & LADSPA_PORT_INPUT ? "input" : "output", plugin->desc->Name);
return err; return err;
} }
return 0; return 0;
@ -592,13 +595,13 @@ static int snd_pcm_ladspa_check_connect(snd_pcm_ladspa_plugin_t *plugin,
for (idx = midx = 0; idx < plugin->desc->PortCount; idx++) for (idx = midx = 0; idx < plugin->desc->PortCount; idx++)
if ((plugin->desc->PortDescriptors[idx] & (io->pdesc | LADSPA_PORT_AUDIO)) == (io->pdesc | LADSPA_PORT_AUDIO)) { if ((plugin->desc->PortDescriptors[idx] & (io->pdesc | LADSPA_PORT_AUDIO)) == (io->pdesc | LADSPA_PORT_AUDIO)) {
if (eps->channels.array[midx] == NO_ASSIGN) { if (eps->channels.array[midx] == NO_ASSIGN) {
SNDERR("%s port for plugin %s depth %u is not connected\n", io->pdesc & LADSPA_PORT_INPUT ? "input" : "output", plugin->desc->Name, depth); SNDERR("%s port for plugin %s depth %u is not connected", io->pdesc & LADSPA_PORT_INPUT ? "input" : "output", plugin->desc->Name, depth);
err++; err++;
} }
midx++; midx++;
} }
if (err > 0) { if (err > 0) {
SNDERR("%i connection errors total\n", err); SNDERR("%i connection errors total", err);
return -EINVAL; return -EINVAL;
} }
return 0; return 0;
@ -715,11 +718,13 @@ static int snd_pcm_ladspa_allocate_memory(snd_pcm_t *pcm, snd_pcm_ladspa_t *lads
nchannels = channels; nchannels = channels;
for (idx = 0; idx < instance->input.channels.size; idx++) { for (idx = 0; idx < instance->input.channels.size; idx++) {
chn = instance->input.channels.array[idx]; chn = instance->input.channels.array[idx];
assert(instance->input.ports.array[idx] != NO_ASSIGN);
if (chn >= nchannels) if (chn >= nchannels)
nchannels = chn + 1; nchannels = chn + 1;
} }
for (idx = 0; idx < instance->output.channels.size; idx++) { for (idx = 0; idx < instance->output.channels.size; idx++) {
chn = instance->output.channels.array[idx]; chn = instance->output.channels.array[idx];
assert(instance->output.ports.array[idx] != NO_ASSIGN);
if (chn >= nchannels) if (chn >= nchannels)
nchannels = chn + 1; nchannels = chn + 1;
} }
@ -1005,7 +1010,7 @@ static void snd_pcm_ladspa_dump_array(snd_output_t *out,
snd_output_putc(out, '-'); snd_output_putc(out, '-');
else else
snd_output_printf(out, "%u", val); snd_output_printf(out, "%u", val);
if (plugin) if (plugin && val != NO_ASSIGN)
snd_output_printf(out, " \"%s\"", plugin->desc->PortNames[val]); snd_output_printf(out, " \"%s\"", plugin->desc->PortNames[val]);
} }
} }
@ -1099,8 +1104,10 @@ static int snd_pcm_ladspa_check_file(snd_pcm_ladspa_plugin_t * const plugin,
if (label != NULL) { if (label != NULL) {
lc = localeconv (); lc = localeconv ();
labellocale = malloc (strlen (label) + 1); labellocale = malloc (strlen (label) + 1);
if (labellocale == NULL) if (labellocale == NULL) {
dlclose(handle);
return -ENOMEM; return -ENOMEM;
}
strcpy (labellocale, label); strcpy (labellocale, label);
if (strrchr(labellocale, '.')) if (strrchr(labellocale, '.'))
*strrchr (labellocale, '.') = *lc->decimal_point; *strrchr (labellocale, '.') = *lc->decimal_point;
@ -1114,8 +1121,10 @@ static int snd_pcm_ladspa_check_file(snd_pcm_ladspa_plugin_t * const plugin,
if (ladspa_id > 0 && d->UniqueID != ladspa_id) if (ladspa_id > 0 && d->UniqueID != ladspa_id)
continue; continue;
plugin->filename = strdup(filename); plugin->filename = strdup(filename);
if (plugin->filename == NULL) if (plugin->filename == NULL) {
dlclose(handle);
return -ENOMEM; return -ENOMEM;
}
plugin->dl_handle = handle; plugin->dl_handle = handle;
plugin->desc = d; plugin->desc = d;
return 1; return 1;
@ -1153,19 +1162,25 @@ static int snd_pcm_ladspa_check_dir(snd_pcm_ladspa_plugin_t * const plugin,
} }
filename = malloc(len + strlen(dirent->d_name) + 1 + need_slash); filename = malloc(len + strlen(dirent->d_name) + 1 + need_slash);
if (filename == NULL) if (filename == NULL) {
closedir(dir);
return -ENOMEM; return -ENOMEM;
}
strcpy(filename, path); strcpy(filename, path);
if (need_slash) if (need_slash)
strcat(filename, "/"); strcat(filename, "/");
strcat(filename, dirent->d_name); strcat(filename, dirent->d_name);
err = snd_pcm_ladspa_check_file(plugin, filename, label, ladspa_id); err = snd_pcm_ladspa_check_file(plugin, filename, label, ladspa_id);
free(filename); free(filename);
if (err < 0 && err != -ENOENT) if (err < 0 && err != -ENOENT) {
closedir(dir);
return err; return err;
if (err > 0) }
if (err > 0) {
closedir(dir);
return 1; return 1;
} }
}
/* never reached */ /* never reached */
return 0; return 0;
} }