mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-06 13:29:59 -05:00
Changes and cleanups for the timer API.
The device lists use the next device syntax now.
This commit is contained in:
parent
61e95094e7
commit
35cb79860d
12 changed files with 204 additions and 78 deletions
|
|
@ -52,39 +52,22 @@ int snd_card_load(int card)
|
|||
return open_dev;
|
||||
}
|
||||
|
||||
int snd_cards(void)
|
||||
int snd_card_next(int *rcard)
|
||||
{
|
||||
int idx, count;
|
||||
unsigned int mask;
|
||||
|
||||
mask = snd_cards_mask();
|
||||
for (idx = 0, count = 0; idx < SND_CARDS; idx++) {
|
||||
if (mask & (1 << idx))
|
||||
count++;
|
||||
int card;
|
||||
|
||||
if (rcard == NULL)
|
||||
return -EINVAL;
|
||||
card = *rcard;
|
||||
card = card < 0 ? 0 : card + 1;
|
||||
for (; card < 32; card++) {
|
||||
if (!snd_card_load(card)) {
|
||||
*rcard = card;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/*
|
||||
* this routine uses very ugly method...
|
||||
* need to do... (use only stat on /proc/asound?)
|
||||
* now is information cached over static variable
|
||||
*/
|
||||
|
||||
unsigned int snd_cards_mask(void)
|
||||
{
|
||||
int idx;
|
||||
unsigned int mask;
|
||||
static unsigned int save_mask = 0;
|
||||
|
||||
if (save_mask)
|
||||
return save_mask;
|
||||
for (idx = 0, mask = 0; idx < SND_CARDS; idx++) {
|
||||
if (snd_card_load(idx) >= 0)
|
||||
mask |= 1 << idx;
|
||||
}
|
||||
save_mask = mask;
|
||||
return mask;
|
||||
*rcard = -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int snd_card_get_index(const char *string)
|
||||
|
|
|
|||
|
|
@ -81,12 +81,24 @@ int snd_ctl_cwrite(snd_ctl_t *ctl, snd_control_t *control)
|
|||
return ctl->ops->cwrite(ctl, control);
|
||||
}
|
||||
|
||||
int snd_ctl_hwdep_next_device(snd_ctl_t *ctl, int * device)
|
||||
{
|
||||
assert(ctl && device);
|
||||
return ctl->ops->hwdep_next_device(ctl, device);
|
||||
}
|
||||
|
||||
int snd_ctl_hwdep_info(snd_ctl_t *ctl, snd_hwdep_info_t * info)
|
||||
{
|
||||
assert(ctl && info);
|
||||
return ctl->ops->hwdep_info(ctl, info);
|
||||
}
|
||||
|
||||
int snd_ctl_pcm_next_device(snd_ctl_t *ctl, int * device)
|
||||
{
|
||||
assert(ctl && device);
|
||||
return ctl->ops->pcm_next_device(ctl, device);
|
||||
}
|
||||
|
||||
int snd_ctl_pcm_info(snd_ctl_t *ctl, snd_pcm_info_t * info)
|
||||
{
|
||||
assert(ctl && info);
|
||||
|
|
@ -99,6 +111,12 @@ int snd_ctl_pcm_prefer_subdevice(snd_ctl_t *ctl, int subdev)
|
|||
return ctl->ops->pcm_prefer_subdevice(ctl, subdev);
|
||||
}
|
||||
|
||||
int snd_ctl_rawmidi_next_device(snd_ctl_t *ctl, int * device)
|
||||
{
|
||||
assert(ctl && device);
|
||||
return ctl->ops->rawmidi_next_device(ctl, device);
|
||||
}
|
||||
|
||||
int snd_ctl_rawmidi_info(snd_ctl_t *ctl, snd_rawmidi_info_t * info)
|
||||
{
|
||||
assert(ctl && info);
|
||||
|
|
|
|||
|
|
@ -94,6 +94,14 @@ static int snd_ctl_hw_cwrite(snd_ctl_t *handle, snd_control_t *control)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int snd_ctl_hw_hwdep_next_device(snd_ctl_t *handle, int * device)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
if (ioctl(hw->fd, SND_CTL_IOCTL_HWDEP_NEXT_DEVICE, device) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int snd_ctl_hw_hwdep_info(snd_ctl_t *handle, snd_hwdep_info_t * info)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
|
|
@ -102,6 +110,14 @@ static int snd_ctl_hw_hwdep_info(snd_ctl_t *handle, snd_hwdep_info_t * info)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int snd_ctl_hw_pcm_next_device(snd_ctl_t *handle, int * device)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
if (ioctl(hw->fd, SND_CTL_IOCTL_PCM_NEXT_DEVICE, device) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int snd_ctl_hw_pcm_info(snd_ctl_t *handle, snd_pcm_info_t * info)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
|
|
@ -118,6 +134,14 @@ static int snd_ctl_hw_pcm_prefer_subdevice(snd_ctl_t *handle, int subdev)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int snd_ctl_hw_rawmidi_next_device(snd_ctl_t *handle, int * device)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
if (ioctl(hw->fd, SND_CTL_IOCTL_RAWMIDI_NEXT_DEVICE, device) < 0)
|
||||
return -errno;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int snd_ctl_hw_rawmidi_info(snd_ctl_t *handle, snd_rawmidi_info_t * info)
|
||||
{
|
||||
snd_ctl_hw_t *hw = handle->private;
|
||||
|
|
@ -148,9 +172,12 @@ snd_ctl_ops_t snd_ctl_hw_ops = {
|
|||
cinfo: snd_ctl_hw_cinfo,
|
||||
cread: snd_ctl_hw_cread,
|
||||
cwrite: snd_ctl_hw_cwrite,
|
||||
hwdep_next_device: snd_ctl_hw_hwdep_next_device,
|
||||
hwdep_info: snd_ctl_hw_hwdep_info,
|
||||
pcm_next_device: snd_ctl_hw_pcm_next_device,
|
||||
pcm_info: snd_ctl_hw_pcm_info,
|
||||
pcm_prefer_subdevice: snd_ctl_hw_pcm_prefer_subdevice,
|
||||
rawmidi_next_device: snd_ctl_hw_rawmidi_next_device,
|
||||
rawmidi_info: snd_ctl_hw_rawmidi_info,
|
||||
rawmidi_prefer_subdevice: snd_ctl_hw_rawmidi_prefer_subdevice,
|
||||
read: snd_ctl_hw_read,
|
||||
|
|
|
|||
|
|
@ -39,9 +39,12 @@ typedef struct {
|
|||
int (*cinfo)(snd_ctl_t *handle, snd_control_info_t *info);
|
||||
int (*cread)(snd_ctl_t *handle, snd_control_t *control);
|
||||
int (*cwrite)(snd_ctl_t *handle, snd_control_t *control);
|
||||
int (*hwdep_next_device)(snd_ctl_t *handle, int *device);
|
||||
int (*hwdep_info)(snd_ctl_t *handle, snd_hwdep_info_t * info);
|
||||
int (*pcm_next_device)(snd_ctl_t *handle, int *device);
|
||||
int (*pcm_info)(snd_ctl_t *handle, snd_pcm_info_t * info);
|
||||
int (*pcm_prefer_subdevice)(snd_ctl_t *handle, int subdev);
|
||||
int (*rawmidi_next_device)(snd_ctl_t *handle, int *device);
|
||||
int (*rawmidi_info)(snd_ctl_t *handle, snd_rawmidi_info_t * info);
|
||||
int (*rawmidi_prefer_subdevice)(snd_ctl_t *handle, int subdev);
|
||||
int (*read)(snd_ctl_t *handle, snd_ctl_event_t *event);
|
||||
|
|
|
|||
|
|
@ -184,6 +184,20 @@ static int snd_ctl_shm_cwrite(snd_ctl_t *ctl, snd_control_t *control)
|
|||
return err;
|
||||
}
|
||||
|
||||
static int snd_ctl_shm_hwdep_next_device(snd_ctl_t *ctl, int * device)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
int err;
|
||||
ctrl->u.device = *device;
|
||||
ctrl->cmd = SND_CTL_IOCTL_HWDEP_NEXT_DEVICE;
|
||||
err = snd_ctl_shm_action(ctl);
|
||||
if (err < 0)
|
||||
return err;
|
||||
*device = ctrl->u.device;
|
||||
return err;
|
||||
}
|
||||
|
||||
static int snd_ctl_shm_hwdep_info(snd_ctl_t *ctl, snd_hwdep_info_t * info)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
|
|
@ -198,6 +212,20 @@ static int snd_ctl_shm_hwdep_info(snd_ctl_t *ctl, snd_hwdep_info_t * info)
|
|||
return err;
|
||||
}
|
||||
|
||||
static int snd_ctl_shm_pcm_next_device(snd_ctl_t *ctl, int * device)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
int err;
|
||||
ctrl->u.device = *device;
|
||||
ctrl->cmd = SND_CTL_IOCTL_PCM_NEXT_DEVICE;
|
||||
err = snd_ctl_shm_action(ctl);
|
||||
if (err < 0)
|
||||
return err;
|
||||
*device = ctrl->u.device;
|
||||
return err;
|
||||
}
|
||||
|
||||
static int snd_ctl_shm_pcm_info(snd_ctl_t *ctl, snd_pcm_info_t * info)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
|
|
@ -225,6 +253,20 @@ static int snd_ctl_shm_pcm_prefer_subdevice(snd_ctl_t *ctl, int subdev)
|
|||
return err;
|
||||
}
|
||||
|
||||
static int snd_ctl_shm_rawmidi_next_device(snd_ctl_t *ctl, int * device)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
|
||||
int err;
|
||||
ctrl->u.device = *device;
|
||||
ctrl->cmd = SND_CTL_IOCTL_RAWMIDI_NEXT_DEVICE;
|
||||
err = snd_ctl_shm_action(ctl);
|
||||
if (err < 0)
|
||||
return err;
|
||||
*device = ctrl->u.device;
|
||||
return err;
|
||||
}
|
||||
|
||||
static int snd_ctl_shm_rawmidi_info(snd_ctl_t *ctl, snd_rawmidi_info_t * info)
|
||||
{
|
||||
snd_ctl_shm_t *shm = ctl->private;
|
||||
|
|
@ -274,9 +316,12 @@ snd_ctl_ops_t snd_ctl_shm_ops = {
|
|||
cinfo: snd_ctl_shm_cinfo,
|
||||
cread: snd_ctl_shm_cread,
|
||||
cwrite: snd_ctl_shm_cwrite,
|
||||
hwdep_next_device: snd_ctl_shm_hwdep_next_device,
|
||||
hwdep_info: snd_ctl_shm_hwdep_info,
|
||||
pcm_next_device: snd_ctl_shm_pcm_next_device,
|
||||
pcm_info: snd_ctl_shm_pcm_info,
|
||||
pcm_prefer_subdevice: snd_ctl_shm_pcm_prefer_subdevice,
|
||||
rawmidi_next_device: snd_ctl_shm_rawmidi_next_device,
|
||||
rawmidi_info: snd_ctl_shm_rawmidi_info,
|
||||
rawmidi_prefer_subdevice: snd_ctl_shm_rawmidi_prefer_subdevice,
|
||||
read: snd_ctl_shm_read,
|
||||
|
|
|
|||
|
|
@ -51,16 +51,14 @@ static int defaults_device(const char *env)
|
|||
int snd_defaults_card(void)
|
||||
{
|
||||
int result;
|
||||
unsigned int mask;
|
||||
|
||||
result = defaults_card("ALSA_CARD");
|
||||
if (result >= 0)
|
||||
return result;
|
||||
mask = snd_cards_mask();
|
||||
for (result = 0; result < 31; result++)
|
||||
if (mask & (1 << result))
|
||||
return result;
|
||||
return -ENOENT;
|
||||
result = -1;
|
||||
if (snd_card_next(&result))
|
||||
return -ENOENT;
|
||||
return result;
|
||||
}
|
||||
|
||||
int snd_defaults_mixer_card(void)
|
||||
|
|
@ -85,7 +83,22 @@ int snd_defaults_pcm_card(void)
|
|||
|
||||
int snd_defaults_pcm_device(void)
|
||||
{
|
||||
return defaults_device("ALSA_PCM_DEVICE");
|
||||
snd_ctl_t *handle;
|
||||
char id[16];
|
||||
int result;
|
||||
|
||||
result = defaults_device("ALSA_PCM_DEVICE");
|
||||
if (result >= 0)
|
||||
return result;
|
||||
sprintf(id, "hw:%i", snd_defaults_pcm_card());
|
||||
if (snd_ctl_open(&handle, id) < 0)
|
||||
return -ENOENT;
|
||||
result = -1;
|
||||
if (snd_ctl_pcm_next_device(handle, &result) < 0) {
|
||||
snd_ctl_close(handle);
|
||||
return -ENOENT;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
int snd_defaults_rawmidi_card(void)
|
||||
|
|
@ -100,5 +113,20 @@ int snd_defaults_rawmidi_card(void)
|
|||
|
||||
int snd_defaults_rawmidi_device(void)
|
||||
{
|
||||
return defaults_device("ALSA_RAWMIDI_DEVICE");
|
||||
snd_ctl_t *handle;
|
||||
char id[16];
|
||||
int result;
|
||||
|
||||
result = defaults_device("ALSA_RAWMIDI_DEVICE");
|
||||
if (result >= 0)
|
||||
return result;
|
||||
sprintf(id, "hw:%i", snd_defaults_rawmidi_card());
|
||||
if (snd_ctl_open(&handle, id) < 0)
|
||||
return -ENOENT;
|
||||
result = -1;
|
||||
if (snd_ctl_rawmidi_next_device(handle, &result) < 0) {
|
||||
snd_ctl_close(handle);
|
||||
return -ENOENT;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue