64-bit fixes.

Controls API uses binary tree functions (tsearch ...).
This commit is contained in:
Jaroslav Kysela 2000-08-04 10:24:12 +00:00
parent e22a79b707
commit f981892e3a
13 changed files with 174 additions and 164 deletions

View file

@ -57,7 +57,7 @@ int snd_ctl_read(snd_ctl_t *handle, snd_ctl_callbacks_t * callbacks);
typedef struct snd_hcontrol_stru snd_hcontrol_t; typedef struct snd_hcontrol_stru snd_hcontrol_t;
struct snd_hcontrol_stru { struct snd_hcontrol_stru {
snd_control_id_t id; snd_control_id_t id; /* must be always on top */
int change: 1, /* structure change */ int change: 1, /* structure change */
value: 1; /* value change */ value: 1; /* value change */
/* event callbacks */ /* event callbacks */
@ -68,20 +68,17 @@ struct snd_hcontrol_stru {
void *private_data; void *private_data;
void (*private_free)(void *private_data); void (*private_free)(void *private_data);
/* links */ /* links */
snd_hcontrol_t *prev; snd_ctl_t *handle; /* associated handle */
snd_hcontrol_t *next;
}; };
typedef int (snd_ctl_csort_t)(const snd_hcontrol_t **c1, const snd_hcontrol_t **c2); typedef int (snd_ctl_csort_t)(const snd_hcontrol_t *c1, const snd_hcontrol_t *c2);
typedef int (snd_ctl_ccallback_rebuild_t)(snd_ctl_t *handle, void *private_data); typedef int (snd_ctl_ccallback_rebuild_t)(snd_ctl_t *handle, void *private_data);
typedef int (snd_ctl_ccallback_add_t)(snd_ctl_t *handle, void *private_data, snd_hcontrol_t *hcontrol); typedef int (snd_ctl_ccallback_add_t)(snd_ctl_t *handle, void *private_data, snd_hcontrol_t *hcontrol);
int snd_ctl_cbuild(snd_ctl_t *handle, snd_ctl_csort_t *csort); int snd_ctl_cbuild(snd_ctl_t *handle, snd_ctl_csort_t *csort);
int snd_ctl_cfree(snd_ctl_t *handle); int snd_ctl_cfree(snd_ctl_t *handle);
snd_hcontrol_t *snd_ctl_cfirst(snd_ctl_t *handle);
snd_hcontrol_t *snd_ctl_clast(snd_ctl_t *handle);
snd_hcontrol_t *snd_ctl_cfind(snd_ctl_t *handle, snd_control_id_t *id); snd_hcontrol_t *snd_ctl_cfind(snd_ctl_t *handle, snd_control_id_t *id);
int snd_ctl_csort(const snd_hcontrol_t **c1, const snd_hcontrol_t **c2); int snd_ctl_csort(const snd_hcontrol_t *c1, const snd_hcontrol_t *c2);
int snd_ctl_cresort(snd_ctl_t *handle, snd_ctl_csort_t *csort); int snd_ctl_cresort(snd_ctl_t *handle, snd_ctl_csort_t *csort);
int snd_ctl_ccallback_rebuild(snd_ctl_t *handle, snd_ctl_ccallback_rebuild_t *callback, void *private_data); int snd_ctl_ccallback_rebuild(snd_ctl_t *handle, snd_ctl_ccallback_rebuild_t *callback, void *private_data);
int snd_ctl_ccallback_add(snd_ctl_t *handle, snd_ctl_ccallback_add_t *callback, void *private_data); int snd_ctl_ccallback_add(snd_ctl_t *handle, snd_ctl_ccallback_add_t *callback, void *private_data);

View file

@ -24,8 +24,8 @@ struct snd_ctl {
int fd; int fd;
int ccount; int ccount;
int cerr; int cerr;
snd_hcontrol_t *cfirst; void *croot; /* root of controls */
snd_hcontrol_t *clast; void *croot_new; /* new croot */
snd_ctl_csort_t *csort; snd_ctl_csort_t *csort;
snd_ctl_ccallback_rebuild_t *callback_rebuild; snd_ctl_ccallback_rebuild_t *callback_rebuild;
void *callback_rebuild_private_data; void *callback_rebuild_private_data;

View file

@ -27,21 +27,26 @@
#include <fcntl.h> #include <fcntl.h>
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <assert.h> #include <assert.h>
#define __USE_GNU
#include <search.h>
#include "asoundlib.h" #include "asoundlib.h"
#include "control_local.h" #include "control_local.h"
static void snd_ctl_link_after(snd_ctl_t *handle, snd_hcontrol_t *point, snd_hcontrol_t *hcontrol); static void snd_ctl_cfree1(snd_hcontrol_t *hcontrol);
int snd_ctl_cbuild(snd_ctl_t *handle, snd_ctl_csort_t *csort) int snd_ctl_cbuild(snd_ctl_t *handle, snd_ctl_csort_t *csort)
{ {
snd_control_list_t list; snd_control_list_t list;
snd_hcontrol_t *hcontrol, *prev; snd_hcontrol_t *hcontrol, *prev;
int err, idx; int err;
unsigned int idx;
printf("cbuild - start\n");
assert(handle != NULL); assert(handle != NULL);
if ((err = snd_ctl_cfree(handle)) < 0) if ((err = snd_ctl_cfree(handle)) < 0)
return err; return err;
__rebuild: if (csort == NULL)
csort = snd_ctl_csort;
memset(&list, 0, sizeof(list)); memset(&list, 0, sizeof(list));
do { do {
if (list.pids != NULL) if (list.pids != NULL)
@ -68,93 +73,49 @@ int snd_ctl_cbuild(snd_ctl_t *handle, snd_ctl_csort_t *csort)
return -ENOMEM; return -ENOMEM;
} }
hcontrol->id = list.pids[idx]; hcontrol->id = list.pids[idx];
if (prev == NULL) { hcontrol->handle = handle;
handle->cfirst = handle->clast = hcontrol; if (tsearch(hcontrol, &handle->croot, (__compar_fn_t)csort) == NULL) {
handle->ccount = 1; tdestroy(&handle->croot, (__free_fn_t)snd_ctl_cfree1);
} else { handle->croot = NULL;
snd_ctl_link_after(handle, prev, hcontrol);
} }
prev = hcontrol; handle->ccount++;
} }
if (list.pids != NULL) if (list.pids != NULL)
free(list.pids); free(list.pids);
if (csort != NULL && (err = snd_ctl_cresort(handle, csort)) < 0) handle->csort = csort;
return err;
return 0; return 0;
} }
snd_hcontrol_t *snd_ctl_cfirst(snd_ctl_t *handle) static void snd_ctl_cfree1(snd_hcontrol_t *hcontrol)
{ {
snd_ctl_t *handle;
assert(hcontrol != NULL);
handle = hcontrol->handle;
assert(handle != NULL); assert(handle != NULL);
return handle->cfirst; assert(handle->ccount > 0);
}
snd_hcontrol_t *snd_ctl_clast(snd_ctl_t *handle)
{
assert(handle != NULL);
return handle->clast;
}
static void snd_ctl_unlink(snd_ctl_t *handle, snd_hcontrol_t *hcontrol)
{
if (handle->cfirst == hcontrol)
handle->cfirst = hcontrol->next;
if (handle->clast == hcontrol)
handle->clast = hcontrol->prev;
if (hcontrol->prev != NULL)
hcontrol->prev->next = hcontrol->next;
if (hcontrol->next != NULL)
hcontrol->next->prev = hcontrol->prev;
hcontrol->prev = hcontrol->next = NULL;
handle->ccount--;
}
static void snd_ctl_link_before(snd_ctl_t *handle, snd_hcontrol_t *point, snd_hcontrol_t *hcontrol)
{
if (point == handle->cfirst)
handle->cfirst = hcontrol;
hcontrol->next = point;
hcontrol->prev = point->prev;
if (point->prev != NULL)
point->prev->next = hcontrol;
point->prev = hcontrol;
handle->ccount++;
}
static void snd_ctl_link_after(snd_ctl_t *handle, snd_hcontrol_t *point, snd_hcontrol_t *hcontrol)
{
if (point == handle->clast)
handle->clast = hcontrol;
hcontrol->prev = point;
hcontrol->next = point->next;
if (point->next != NULL)
point->next->prev = hcontrol;
point->next = hcontrol;
handle->ccount++;
}
static void snd_ctl_cfree1(snd_ctl_t *handle, snd_hcontrol_t *hcontrol)
{
snd_ctl_unlink(handle, hcontrol);
if (hcontrol->event_remove) if (hcontrol->event_remove)
hcontrol->event_remove(handle, hcontrol); hcontrol->event_remove(handle, hcontrol);
if (hcontrol->private_free) if (hcontrol->private_free)
hcontrol->private_free(hcontrol->private_data); hcontrol->private_free(hcontrol->private_data);
free(hcontrol); free(hcontrol);
handle->ccount--;
} }
int snd_ctl_cfree(snd_ctl_t *handle) int snd_ctl_cfree(snd_ctl_t *handle)
{ {
handle->csort = NULL; handle->csort = NULL;
while (handle->cfirst) handle->cerr = 0;
snd_ctl_cfree1(handle, handle->cfirst); if (handle->croot != NULL) {
tdestroy(handle->croot, (__free_fn_t)snd_ctl_cfree1);
handle->croot = NULL;
}
assert(handle->ccount == 0); assert(handle->ccount == 0);
return 0;
} }
int snd_ctl_csort(const snd_hcontrol_t **_c1, const snd_hcontrol_t **_c2) int snd_ctl_csort(const snd_hcontrol_t *c1, const snd_hcontrol_t *c2)
{ {
const snd_hcontrol_t *c1 = *_c1;
const snd_hcontrol_t *c2 = *_c2;
int res; int res;
res = strcmp(c1->id.name, c2->id.name); res = strcmp(c1->id.name, c2->id.name);
@ -165,54 +126,70 @@ int snd_ctl_csort(const snd_hcontrol_t **_c1, const snd_hcontrol_t **_c2)
return 1; return 1;
return 0; return 0;
} }
return res;
}
static void snd_ctl_cresort_action(snd_hcontrol_t *hcontrol, VISIT which, int level)
{
snd_ctl_t *handle;
level = 0; /* to keep GCC happy */
assert(hcontrol != NULL);
handle = hcontrol->handle;
assert(handle != NULL);
if (handle->cerr < 0)
return;
switch (which) {
case preorder: break;
case postorder: break;
case endorder:
case leaf:
if (tsearch(hcontrol, &handle->croot, (__compar_fn_t)handle->csort) == NULL)
handle->cerr = -ENOMEM;
break;
}
}
static void snd_ctl_cresort_free(snd_hcontrol_t *hcontrol)
{
hcontrol = NULL; /* to keep GCC happy */
/* nothing */
} }
int snd_ctl_cresort(snd_ctl_t *handle, snd_ctl_csort_t *csort) int snd_ctl_cresort(snd_ctl_t *handle, snd_ctl_csort_t *csort)
{ {
int idx, count; int result;
snd_hcontrol_t **pmap, *hcontrol; snd_ctl_csort_t *csort_old;
assert(handle != NULL && csort != NULL); assert(handle != NULL && csort != NULL);
if (handle->ccount == 0) if (handle->ccount == 0)
return 0; return 0;
pmap = (snd_hcontrol_t **)calloc(handle->ccount, sizeof(snd_hcontrol_t *)); if (handle->cerr < 0)
if (pmap == NULL) return handle->cerr;
return -ENOMEM; assert(handle->croot_new == NULL);
for (hcontrol = handle->cfirst, idx = 0; hcontrol != NULL; hcontrol = hcontrol->next, idx++) { csort_old = handle->csort;
printf("idx = %i, hcontrol = 0x%x (0x%x), '%s'\n", idx, (int)hcontrol, (int)&pmap[idx], hcontrol->id.name);
pmap[idx] = hcontrol;
}
assert(idx == handle->ccount);
handle->csort = csort; handle->csort = csort;
qsort(pmap, count = handle->ccount, sizeof(snd_hcontrol_t *), (int (*)(const void *, const void *))csort); twalk(handle->croot, (__action_fn_t)snd_ctl_cresort_action);
while (handle->cfirst) if (handle->cerr < 0) {
snd_ctl_unlink(handle, handle->cfirst); result = handle->cerr;
handle->cfirst = handle->clast = pmap[0]; handle->ccount = 1; handle->cerr = 0;
for (idx = 1; idx < count; idx++) handle->csort = csort_old;
snd_ctl_link_after(handle, pmap[idx-1], pmap[idx]); tdestroy(handle->croot_new, (__free_fn_t)snd_ctl_cresort_free);
free(pmap); handle->croot_new = NULL;
return result;
}
tdestroy(handle->croot, (__free_fn_t)snd_ctl_cresort_free);
handle->croot = handle->croot_new;
handle->croot_new = NULL;
return 0; return 0;
} }
snd_hcontrol_t *snd_ctl_cfind(snd_ctl_t *handle, snd_control_id_t *id) snd_hcontrol_t *snd_ctl_cfind(snd_ctl_t *handle, snd_control_id_t *id)
{ {
snd_hcontrol_t *hcontrol;
assert(handle != NULL); assert(handle != NULL);
for (hcontrol = handle->cfirst; hcontrol != NULL; hcontrol = hcontrol->next) { if (handle->croot == NULL)
if (hcontrol->id.iface != id->iface) return NULL;
continue; return (snd_hcontrol_t *)tfind(id, &handle->croot, (__compar_fn_t)handle->csort);
if (hcontrol->id.device != id->device)
continue;
if (hcontrol->id.subdevice != id->subdevice)
continue;
if (strncmp(hcontrol->id.name, id->name, sizeof(hcontrol->id.name)))
continue;
if (hcontrol->id.index != id->index)
continue;
return hcontrol;
}
return NULL;
} }
int snd_ctl_ccallback_rebuild(snd_ctl_t *handle, snd_ctl_ccallback_rebuild_t *callback, void *private_data) int snd_ctl_ccallback_rebuild(snd_ctl_t *handle, snd_ctl_ccallback_rebuild_t *callback, void *private_data)
@ -220,6 +197,7 @@ int snd_ctl_ccallback_rebuild(snd_ctl_t *handle, snd_ctl_ccallback_rebuild_t *ca
assert(handle != NULL); assert(handle != NULL);
handle->callback_rebuild = callback; handle->callback_rebuild = callback;
handle->callback_rebuild_private_data = private_data; handle->callback_rebuild_private_data = private_data;
return 0;
} }
int snd_ctl_ccallback_add(snd_ctl_t *handle, snd_ctl_ccallback_add_t *callback, void *private_data) int snd_ctl_ccallback_add(snd_ctl_t *handle, snd_ctl_ccallback_add_t *callback, void *private_data)
@ -227,10 +205,12 @@ int snd_ctl_ccallback_add(snd_ctl_t *handle, snd_ctl_ccallback_add_t *callback,
assert(handle != NULL); assert(handle != NULL);
handle->callback_add = callback; handle->callback_add = callback;
handle->callback_add_private_data = private_data; handle->callback_add_private_data = private_data;
return 0;
} }
static void callback_rebuild(snd_ctl_t *handle, void *private_data) static void callback_rebuild(snd_ctl_t *handle, void *private_data)
{ {
private_data = NULL; /* to keep GCC happy */
handle->cerr = snd_ctl_cbuild(handle, handle->csort); handle->cerr = snd_ctl_cbuild(handle, handle->csort);
if (handle->cerr >= 0 && handle->callback_rebuild) if (handle->cerr >= 0 && handle->callback_rebuild)
handle->callback_rebuild(handle, handle->callback_rebuild_private_data); handle->callback_rebuild(handle, handle->callback_rebuild_private_data);
@ -240,6 +220,7 @@ static void callback_change(snd_ctl_t *handle, void *private_data, snd_control_i
{ {
snd_hcontrol_t *hcontrol; snd_hcontrol_t *hcontrol;
private_data = NULL; /* to keep GCC happy */
if (handle->cerr < 0) if (handle->cerr < 0)
return; return;
hcontrol = snd_ctl_cfind(handle, id); hcontrol = snd_ctl_cfind(handle, id);
@ -254,6 +235,7 @@ static void callback_value(snd_ctl_t *handle, void *private_data, snd_control_id
{ {
snd_hcontrol_t *hcontrol; snd_hcontrol_t *hcontrol;
private_data = NULL; /* to keep GCC happy */
if (handle->cerr < 0) if (handle->cerr < 0)
return; return;
hcontrol = snd_ctl_cfind(handle, id); hcontrol = snd_ctl_cfind(handle, id);
@ -268,6 +250,7 @@ static void callback_add(snd_ctl_t *handle, void *private_data, snd_control_id_t
{ {
snd_hcontrol_t *hcontrol, *icontrol; snd_hcontrol_t *hcontrol, *icontrol;
private_data = NULL; /* to keep GCC happy */
if (handle->cerr < 0) if (handle->cerr < 0)
return; return;
hcontrol = (snd_hcontrol_t *)calloc(1, sizeof(snd_hcontrol_t)); hcontrol = (snd_hcontrol_t *)calloc(1, sizeof(snd_hcontrol_t));
@ -276,17 +259,16 @@ static void callback_add(snd_ctl_t *handle, void *private_data, snd_control_id_t
return; return;
} }
hcontrol->id = *id; hcontrol->id = *id;
if (handle->csort != NULL) { hcontrol->handle = handle;
for (icontrol = handle->cfirst; icontrol != NULL; icontrol = icontrol->next) { icontrol = tsearch(hcontrol, &handle->croot, (__compar_fn_t)handle->csort);
if (handle->csort((const snd_hcontrol_t **)&icontrol, (const snd_hcontrol_t **)&hcontrol) > 0) { if (icontrol == NULL) {
snd_ctl_link_before(handle, icontrol, hcontrol); free(hcontrol);
break; handle->cerr = -ENOMEM;
} return;
} }
if (icontrol == NULL) if (icontrol != hcontrol) { /* double hit */
snd_ctl_link_after(handle, handle->clast, hcontrol); free(hcontrol);
} else { return;
snd_ctl_link_after(handle, handle->clast, hcontrol);
} }
if (handle->callback_add) if (handle->callback_add)
handle->callback_add(handle, handle->callback_add_private_data, hcontrol); handle->callback_add(handle, handle->callback_add_private_data, hcontrol);
@ -296,6 +278,7 @@ static void callback_remove(snd_ctl_t *handle, void *private_data, snd_control_i
{ {
snd_hcontrol_t *hcontrol; snd_hcontrol_t *hcontrol;
private_data = NULL; /* to keep GCC happy */
if (handle->cerr < 0) if (handle->cerr < 0)
return; return;
hcontrol = snd_ctl_cfind(handle, id); hcontrol = snd_ctl_cfind(handle, id);
@ -303,19 +286,42 @@ static void callback_remove(snd_ctl_t *handle, void *private_data, snd_control_i
handle->cerr = -ENOENT; handle->cerr = -ENOENT;
return; return;
} }
snd_ctl_cfree1(handle, hcontrol); if (tdelete(hcontrol, &handle->croot, (__compar_fn_t)handle->csort) != NULL)
snd_ctl_cfree1(hcontrol);
}
static void snd_ctl_cevent_walk1(snd_hcontrol_t *hcontrol, VISIT which, int level)
{
level = 0; /* to keep GCC happy */
assert(hcontrol != NULL);
switch (which) {
case preorder: break;
case postorder: break;
case endorder:
case leaf:
if (hcontrol->change && hcontrol->event_change) {
hcontrol->event_change(hcontrol->handle, hcontrol);
hcontrol->change = 0;
}
if (hcontrol->value && hcontrol->event_value) {
hcontrol->event_value(hcontrol->handle, hcontrol);
hcontrol->value = 0;
}
break;
}
} }
int snd_ctl_cevent(snd_ctl_t *handle) int snd_ctl_cevent(snd_ctl_t *handle)
{ {
snd_ctl_callbacks_t callbacks = { static snd_ctl_callbacks_t callbacks = {
rebuild: callback_rebuild, rebuild: callback_rebuild,
value: callback_value, value: callback_value,
change: callback_change, change: callback_change,
add: callback_add, add: callback_add,
remove: callback_remove remove: callback_remove,
private_data: NULL,
reserved: { NULL, }
}; };
snd_hcontrol_t *hcontrol;
int res; int res;
assert(handle != NULL); assert(handle != NULL);
@ -325,15 +331,6 @@ int snd_ctl_cevent(snd_ctl_t *handle)
return res; return res;
if (handle->cerr < 0) if (handle->cerr < 0)
return handle->cerr; return handle->cerr;
for (hcontrol = handle->cfirst; hcontrol != NULL; hcontrol = hcontrol->next) { twalk(handle->croot, (__action_fn_t)snd_ctl_cevent_walk1);
if (hcontrol->change && hcontrol->event_change) {
hcontrol->event_change(handle, hcontrol);
hcontrol->change = 0;
}
if (hcontrol->value && hcontrol->event_value) {
hcontrol->event_value(handle, hcontrol);
hcontrol->value = 0;
}
}
return res; return res;
} }

View file

@ -20,6 +20,7 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <string.h>
#include <errno.h> #include <errno.h>
#include "asoundlib.h" #include "asoundlib.h"

View file

@ -245,7 +245,7 @@ int snd_instr_iwffff_open(snd_iwffff_handle_t **handle, const char *name_fff, co
} }
iwf->share_id1 = IWFFFF_SHARE_FILE; iwf->share_id1 = IWFFFF_SHARE_FILE;
#ifdef __alpha__ #ifdef __alpha__
iwf->share_id2 = (info.st_dev << 16) | ((info.st_ino >> 32) & 0xffff); iwf->share_id2 = (info.st_dev << 16) /* | ((info.st_ino >> 32) & 0xffff) */;
#else #else
iwf->share_id2 = info.st_dev << 16; iwf->share_id2 = info.st_dev << 16;
#endif #endif

View file

@ -206,7 +206,6 @@ static void snd_mixer_simple_read_remove(snd_ctl_t *ctl_handle, void *private_da
int snd_mixer_simple_read(snd_mixer_t *handle, snd_mixer_simple_callbacks_t *callbacks) int snd_mixer_simple_read(snd_mixer_t *handle, snd_mixer_simple_callbacks_t *callbacks)
{ {
snd_ctl_callbacks_t xcallbacks;
int err; int err;
if (handle == NULL) if (handle == NULL)

View file

@ -38,8 +38,9 @@ static int test_mixer_id(snd_mixer_t *handle, const char *name, int index)
id.iface = SND_CONTROL_IFACE_MIXER; id.iface = SND_CONTROL_IFACE_MIXER;
strcpy(id.name, name); strcpy(id.name, name);
id.index = index; id.index = index;
printf("look\n");
hcontrol = snd_ctl_cfind(handle->ctl_handle, &id); hcontrol = snd_ctl_cfind(handle->ctl_handle, &id);
// fprintf(stderr, "Looking for control: '%s', %i (0x%lx)\n", name, index, (long)hcontrol); fprintf(stderr, "Looking for control: '%s', %i (0x%lx)\n", name, index, (long)hcontrol);
return hcontrol != NULL; return hcontrol != NULL;
} }
@ -130,6 +131,7 @@ static int input_get_volume(snd_mixer_t *handle, mixer_simple_t *simple, snd_mix
return err; return err;
for (idx = 0; idx < simple->voices && idx < 32; idx++) for (idx = 0; idx < simple->voices && idx < 32; idx++)
control->volume.values[idx] = ctl.value.integer.value[voices == 1 ? 0 : idx]; control->volume.values[idx] = ctl.value.integer.value[voices == 1 ? 0 : idx];
return 0;
} }
static int input_get_mute_switch(snd_mixer_t *handle, mixer_simple_t *simple, snd_mixer_simple_control_t *control, const char *direction, int voices) static int input_get_mute_switch(snd_mixer_t *handle, mixer_simple_t *simple, snd_mixer_simple_control_t *control, const char *direction, int voices)
@ -144,6 +146,7 @@ static int input_get_mute_switch(snd_mixer_t *handle, mixer_simple_t *simple, sn
for (idx = 0; idx < simple->voices && idx < 32; idx++) for (idx = 0; idx < simple->voices && idx < 32; idx++)
if (ctl.value.integer.value[voices == 1 ? 0 : idx] == 0) if (ctl.value.integer.value[voices == 1 ? 0 : idx] == 0)
control->mute |= 1 << idx; control->mute |= 1 << idx;
return 0;
} }
static int input_get_capture_switch(snd_mixer_t *handle, mixer_simple_t *simple, snd_mixer_simple_control_t *control, const char *direction, int voices) static int input_get_capture_switch(snd_mixer_t *handle, mixer_simple_t *simple, snd_mixer_simple_control_t *control, const char *direction, int voices)
@ -158,6 +161,7 @@ static int input_get_capture_switch(snd_mixer_t *handle, mixer_simple_t *simple,
for (idx = 0; idx < simple->voices && idx < 32; idx++) for (idx = 0; idx < simple->voices && idx < 32; idx++)
if (ctl.value.integer.value[voices == 1 ? 0 : idx]) if (ctl.value.integer.value[voices == 1 ? 0 : idx])
control->capture |= 1 << idx; control->capture |= 1 << idx;
return 0;
} }
static int input_get(snd_mixer_t *handle, mixer_simple_t *simple, snd_mixer_simple_control_t *control) static int input_get(snd_mixer_t *handle, mixer_simple_t *simple, snd_mixer_simple_control_t *control)
@ -197,7 +201,6 @@ static int input_get(snd_mixer_t *handle, mixer_simple_t *simple, snd_mixer_simp
if (simple->present & MIXER_PRESENT_CAPTURE_SWITCH) { if (simple->present & MIXER_PRESENT_CAPTURE_SWITCH) {
input_get_capture_switch(handle, simple, control, "Capture ", simple->cswitch_values); input_get_capture_switch(handle, simple, control, "Capture ", simple->cswitch_values);
} else if (simple->present & MIXER_PRESENT_CAPTURE_SOURCE) { } else if (simple->present & MIXER_PRESENT_CAPTURE_SOURCE) {
char str[128];
snd_control_t ctl; snd_control_t ctl;
if ((err = get_mixer_read(handle, "Capture Source", 0, &ctl)) < 0) if ((err = get_mixer_read(handle, "Capture Source", 0, &ctl)) < 0)
return err; return err;
@ -224,6 +227,7 @@ static int input_put_volume(snd_mixer_t *handle, mixer_simple_t *simple, snd_mix
} }
if ((err = put_mixer_write(handle, str, simple->sid.index, &ctl)) < 0) if ((err = put_mixer_write(handle, str, simple->sid.index, &ctl)) < 0)
return err; return err;
return 0;
} }
static int input_put_mute_switch(snd_mixer_t *handle, mixer_simple_t *simple, snd_mixer_simple_control_t *control, const char *direction, int voices) static int input_put_mute_switch(snd_mixer_t *handle, mixer_simple_t *simple, snd_mixer_simple_control_t *control, const char *direction, int voices)
@ -242,6 +246,7 @@ static int input_put_mute_switch(snd_mixer_t *handle, mixer_simple_t *simple, sn
err = put_mixer_write(handle, str, simple->sid.index, &ctl); err = put_mixer_write(handle, str, simple->sid.index, &ctl);
if ((err = put_mixer_write(handle, str, simple->sid.index, &ctl)) < 0) if ((err = put_mixer_write(handle, str, simple->sid.index, &ctl)) < 0)
return err; return err;
return 0;
} }
static int input_put_capture_switch(snd_mixer_t *handle, mixer_simple_t *simple, snd_mixer_simple_control_t *control, const char *direction, int voices) static int input_put_capture_switch(snd_mixer_t *handle, mixer_simple_t *simple, snd_mixer_simple_control_t *control, const char *direction, int voices)
@ -257,6 +262,7 @@ static int input_put_capture_switch(snd_mixer_t *handle, mixer_simple_t *simple,
ctl.value.integer.value[idx] = (control->capture & (1 << idx)) ? 1 : 0; ctl.value.integer.value[idx] = (control->capture & (1 << idx)) ? 1 : 0;
if ((err = put_mixer_write(handle, str, simple->sid.index, &ctl)) < 0) if ((err = put_mixer_write(handle, str, simple->sid.index, &ctl)) < 0)
return err; return err;
return 0;
} }
static int input_put(snd_mixer_t *handle, mixer_simple_t *simple, snd_mixer_simple_control_t *control) static int input_put(snd_mixer_t *handle, mixer_simple_t *simple, snd_mixer_simple_control_t *control)
@ -285,7 +291,6 @@ static int input_put(snd_mixer_t *handle, mixer_simple_t *simple, snd_mixer_simp
if (simple->present & MIXER_PRESENT_CAPTURE_SWITCH) { if (simple->present & MIXER_PRESENT_CAPTURE_SWITCH) {
input_put_capture_switch(handle, simple, control, "Capture ", simple->cswitch_values); input_put_capture_switch(handle, simple, control, "Capture ", simple->cswitch_values);
} else if (simple->present & MIXER_PRESENT_CAPTURE_SOURCE) { } else if (simple->present & MIXER_PRESENT_CAPTURE_SOURCE) {
char str[128];
snd_control_t ctl; snd_control_t ctl;
if ((err = get_mixer_read(handle, "Capture Source", 0, &ctl)) < 0) if ((err = get_mixer_read(handle, "Capture Source", 0, &ctl)) < 0)
return err; return err;
@ -320,8 +325,8 @@ static mixer_simple_t *build_input_scontrol(snd_mixer_t *handle, const char *sna
static int build_input(snd_mixer_t *handle, const char *sname) static int build_input(snd_mixer_t *handle, const char *sname)
{ {
char str[128]; char str[128];
unsigned int present, caps, capture_item; unsigned int present, caps, capture_item, voices;
int index = -1, voices, err; int index = -1, err;
snd_control_info_t gswitch_info, pswitch_info, cswitch_info; snd_control_info_t gswitch_info, pswitch_info, cswitch_info;
snd_control_info_t gvolume_info, pvolume_info, cvolume_info; snd_control_info_t gvolume_info, pvolume_info, cvolume_info;
snd_control_info_t csource_info; snd_control_info_t csource_info;
@ -334,15 +339,19 @@ static int build_input(snd_mixer_t *handle, const char *sname)
memset(&gvolume_info, 0, sizeof(gvolume_info)); memset(&gvolume_info, 0, sizeof(gvolume_info));
memset(&pvolume_info, 0, sizeof(pvolume_info)); memset(&pvolume_info, 0, sizeof(pvolume_info));
memset(&cvolume_info, 0, sizeof(cvolume_info)); memset(&cvolume_info, 0, sizeof(cvolume_info));
printf("b (1)\n");
do { do {
index++; index++;
voices = 0; voices = 0;
present = caps = capture_item = 0; present = caps = capture_item = 0;
min = max = 0; min = max = 0;
sprintf(str, "%s Switch", sname); sprintf(str, "%s Switch", sname);
printf("b (2)\n");
if (test_mixer_id(handle, str, index)) { if (test_mixer_id(handle, str, index)) {
printf("b (3)\n");
if ((err = get_mixer_info(handle, str, index, &gswitch_info)) < 0) if ((err = get_mixer_info(handle, str, index, &gswitch_info)) < 0)
return err; return err;
printf("b (4)\n");
if (gswitch_info.type == SND_CONTROL_TYPE_BOOLEAN) { if (gswitch_info.type == SND_CONTROL_TYPE_BOOLEAN) {
if (voices < gswitch_info.values_count) if (voices < gswitch_info.values_count)
voices = gswitch_info.values_count; voices = gswitch_info.values_count;
@ -350,6 +359,7 @@ static int build_input(snd_mixer_t *handle, const char *sname)
present |= MIXER_PRESENT_GLOBAL_SWITCH; present |= MIXER_PRESENT_GLOBAL_SWITCH;
} }
} }
printf("b (3)\n");
sprintf(str, "%s Volume", sname); sprintf(str, "%s Volume", sname);
if (test_mixer_id(handle, str, index)) { if (test_mixer_id(handle, str, index)) {
if ((err = get_mixer_info(handle, str, index, &gvolume_info)) < 0) if ((err = get_mixer_info(handle, str, index, &gvolume_info)) < 0)
@ -473,6 +483,7 @@ static int build_input(snd_mixer_t *handle, const char *sname)
caps &= ~SND_MIXER_SCTCAP_JOINTLY_VOLUME; caps &= ~SND_MIXER_SCTCAP_JOINTLY_VOLUME;
} }
} }
printf("b (4)\n");
simple = build_input_scontrol(handle, sname, index); simple = build_input_scontrol(handle, sname, index);
if (simple == NULL) if (simple == NULL)
return -ENOMEM; return -ENOMEM;
@ -489,7 +500,7 @@ static int build_input(snd_mixer_t *handle, const char *sname)
simple->voices = voices; simple->voices = voices;
simple->min = min; simple->min = min;
simple->max = max; simple->max = max;
// fprintf(stderr, "sname = '%s', index = %i, present = 0x%x, voices = %i\n", sname, index, present, voices); fprintf(stderr, "sname = '%s', index = %i, present = 0x%x, voices = %i\n", sname, index, present, voices);
} while (present != 0); } while (present != 0);
return 0; return 0;
} }
@ -516,9 +527,11 @@ int snd_mixer_simple_build(snd_mixer_t *handle)
char **input = inputs; char **input = inputs;
int err; int err;
printf("simple build - start\n");
if ((err = snd_ctl_cbuild(handle->ctl_handle, snd_ctl_csort)) < 0) if ((err = snd_ctl_cbuild(handle->ctl_handle, snd_ctl_csort)) < 0)
return err; return err;
while (*input) { while (*input) {
printf("simple build - input '%s'\n", *input);
if ((err = build_input(handle, *input)) < 0) { if ((err = build_input(handle, *input)) < 0) {
snd_mixer_simple_destroy(handle); snd_mixer_simple_destroy(handle);
return err; return err;
@ -526,6 +539,7 @@ int snd_mixer_simple_build(snd_mixer_t *handle)
input++; input++;
} }
handle->simple_valid = 1; handle->simple_valid = 1;
printf("simple build - end\n");
return 0; return 0;
} }

View file

@ -139,7 +139,7 @@ int snd_pcm_state(snd_pcm_t *handle)
return handle->fast_ops->state(handle->fast_op_arg); return handle->fast_ops->state(handle->fast_op_arg);
} }
int snd_pcm_frame_io(snd_pcm_t *handle, int update) ssize_t snd_pcm_frame_io(snd_pcm_t *handle, int update)
{ {
assert(handle); assert(handle);
assert(handle->valid_setup); assert(handle->valid_setup);
@ -428,16 +428,16 @@ int snd_pcm_dump_setup(snd_pcm_t *handle, FILE *fp)
fprintf(fp, "xrun_mode: %s\n", assoc(setup->xrun_mode, xruns)); fprintf(fp, "xrun_mode: %s\n", assoc(setup->xrun_mode, xruns));
fprintf(fp, "time: %s\n", assoc(setup->time, onoff)); fprintf(fp, "time: %s\n", assoc(setup->time, onoff));
// ust_time // ust_time
fprintf(fp, "buffer_size: %d\n", setup->buffer_size); fprintf(fp, "buffer_size: %ld\n", (long)setup->buffer_size);
fprintf(fp, "frag_size: %d\n", setup->frag_size); fprintf(fp, "frag_size: %ld\n", (long)setup->frag_size);
fprintf(fp, "frags: %d\n", setup->frags); fprintf(fp, "frags: %ld\n", (long)setup->frags);
fprintf(fp, "frame_boundary: %d\n", setup->frame_boundary); fprintf(fp, "frame_boundary: %ld\n", (long)setup->frame_boundary);
fprintf(fp, "msbits_per_sample: %d\n", setup->msbits_per_sample); fprintf(fp, "msbits_per_sample: %d\n", setup->msbits_per_sample);
fprintf(fp, "frames_min: %d\n", setup->frames_min); fprintf(fp, "frames_min: %ld\n", (long)setup->frames_min);
fprintf(fp, "frames_align: %d\n", setup->frames_align); fprintf(fp, "frames_align: %ld\n", (long)setup->frames_align);
fprintf(fp, "frames_xrun_max: %d\n", setup->frames_xrun_max); fprintf(fp, "frames_xrun_max: %ld\n", (long)setup->frames_xrun_max);
fprintf(fp, "fill_mode: %s\n", assoc(setup->fill_mode, fills)); fprintf(fp, "fill_mode: %s\n", assoc(setup->fill_mode, fills));
fprintf(fp, "frames_fill_max: %d\n", setup->frames_fill_max); fprintf(fp, "frames_fill_max: %ld\n", (long)setup->frames_fill_max);
return 0; return 0;
} }
@ -473,28 +473,28 @@ int snd_pcm_format_value(const char* name)
return -1; return -1;
} }
ssize_t snd_pcm_bytes_to_frames(snd_pcm_t *handle, int bytes) ssize_t snd_pcm_bytes_to_frames(snd_pcm_t *handle, ssize_t bytes)
{ {
assert(handle); assert(handle);
assert(handle->valid_setup); assert(handle->valid_setup);
return bytes * 8 / handle->bits_per_frame; return bytes * 8 / handle->bits_per_frame;
} }
ssize_t snd_pcm_frames_to_bytes(snd_pcm_t *handle, int frames) ssize_t snd_pcm_frames_to_bytes(snd_pcm_t *handle, ssize_t frames)
{ {
assert(handle); assert(handle);
assert(handle->valid_setup); assert(handle->valid_setup);
return frames * handle->bits_per_frame / 8; return frames * handle->bits_per_frame / 8;
} }
ssize_t snd_pcm_bytes_to_samples(snd_pcm_t *handle, int bytes) ssize_t snd_pcm_bytes_to_samples(snd_pcm_t *handle, ssize_t bytes)
{ {
assert(handle); assert(handle);
assert(handle->valid_setup); assert(handle->valid_setup);
return bytes * 8 / handle->bits_per_sample; return bytes * 8 / handle->bits_per_sample;
} }
ssize_t snd_pcm_samples_to_bytes(snd_pcm_t *handle, int samples) ssize_t snd_pcm_samples_to_bytes(snd_pcm_t *handle, ssize_t samples)
{ {
assert(handle); assert(handle);
assert(handle->valid_setup); assert(handle->valid_setup);

View file

@ -121,7 +121,7 @@ static int snd_pcm_hw_status(void *private, snd_pcm_status_t * status)
return 0; return 0;
} }
static ssize_t snd_pcm_hw_state(void *private) static int snd_pcm_hw_state(void *private)
{ {
snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private; snd_pcm_hw_t *hw = (snd_pcm_hw_t*) private;
int fd = hw->fd; int fd = hw->fd;

View file

@ -111,9 +111,9 @@ int snd_pcm_plug_playback_channels_mask(snd_pcm_plug_t *plug,
bitset_t *client_vmask); bitset_t *client_vmask);
int snd_pcm_plug_capture_channels_mask(snd_pcm_plug_t *plug, int snd_pcm_plug_capture_channels_mask(snd_pcm_plug_t *plug,
bitset_t *client_vmask); bitset_t *client_vmask);
int snd_pcm_plugin_client_channels(snd_pcm_plugin_t *plugin, ssize_t snd_pcm_plugin_client_channels(snd_pcm_plugin_t *plugin,
size_t frames, size_t frames,
snd_pcm_plugin_channel_t **channels); snd_pcm_plugin_channel_t **channels);
void *snd_pcm_plug_buf_alloc(snd_pcm_plug_t *plug, size_t size); void *snd_pcm_plug_buf_alloc(snd_pcm_plug_t *plug, size_t size);
void snd_pcm_plug_buf_unlock(snd_pcm_plug_t *pcm, void *ptr); void snd_pcm_plug_buf_unlock(snd_pcm_plug_t *pcm, void *ptr);

View file

@ -20,6 +20,7 @@
#include <stdio.h> #include <stdio.h>
#include <malloc.h> #include <malloc.h>
#include <string.h>
#include <errno.h> #include <errno.h>
#include <sys/poll.h> #include <sys/poll.h>
#include <sys/uio.h> #include <sys/uio.h>
@ -118,7 +119,7 @@ int snd_pcm_mmap_state(snd_pcm_t *handle)
return handle->mmap_status->state; return handle->mmap_status->state;
} }
int snd_pcm_mmap_frame_io(snd_pcm_t *handle) ssize_t snd_pcm_mmap_frame_io(snd_pcm_t *handle)
{ {
assert(handle); assert(handle);
assert(handle->mmap_status); assert(handle->mmap_status);

View file

@ -68,7 +68,7 @@ int snd_pcm_plugin_append(snd_pcm_plugin_t *plugin)
void snd_pcm_plugin_dump(snd_pcm_plugin_t *plugin, FILE *fp) void snd_pcm_plugin_dump(snd_pcm_plugin_t *plugin, FILE *fp)
{ {
fprintf(fp, "----------- %s\n", plugin->name); fprintf(fp, "----------- %s\n", plugin->name);
fprintf(fp, "Buffer: %d frames\n", plugin->buf_frames); fprintf(fp, "Buffer: %ld frames\n", (long)plugin->buf_frames);
if (plugin->src_format.interleave != plugin->dst_format.interleave) { if (plugin->src_format.interleave != plugin->dst_format.interleave) {
if (plugin->src_format.interleave) if (plugin->src_format.interleave)
fprintf(fp, "Interleaved -> Non interleaved\n"); fprintf(fp, "Interleaved -> Non interleaved\n");
@ -314,7 +314,7 @@ static int snd_pcm_plug_state(void *private)
return snd_pcm_state(plug->slave); return snd_pcm_state(plug->slave);
} }
static int snd_pcm_plug_frame_io(void *private, int update) static ssize_t snd_pcm_plug_frame_io(void *private, int update)
{ {
snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private; snd_pcm_plug_t *plug = (snd_pcm_plug_t*) private;
ssize_t frame_io = snd_pcm_frame_io(plug->slave, update); ssize_t frame_io = snd_pcm_frame_io(plug->slave, update);

View file

@ -733,7 +733,8 @@ int snd_seq_flush_output(snd_seq_t *seq)
*/ */
int snd_seq_extract_output(snd_seq_t *seq, snd_seq_event_t **ev_res) int snd_seq_extract_output(snd_seq_t *seq, snd_seq_event_t **ev_res)
{ {
int len, olen, err; size_t len, olen;
int err;
snd_seq_event_t *ev; snd_seq_event_t *ev;
if (!seq) if (!seq)
@ -890,7 +891,7 @@ static int snd_seq_decode_event(char **buf, size_t *len, snd_seq_event_t *ev)
static int snd_seq_event_read_buffer(snd_seq_t *seq) static int snd_seq_event_read_buffer(snd_seq_t *seq)
{ {
char *buf; char *buf;
int count; ssize_t count;
count = read(seq->fd, seq->ibuf, seq->ibufsize); count = read(seq->fd, seq->ibuf, seq->ibufsize);
if (count < 0) if (count < 0)