2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \file control/control.c
|
|
|
|
|
* \author Abramo Bagnara <abramo@alsa-project.org>
|
|
|
|
|
* \date 2000
|
|
|
|
|
*
|
|
|
|
|
* CTL interface is designed to access primitive controls.
|
|
|
|
|
*/
|
1998-08-13 15:42:56 +00:00
|
|
|
/*
|
|
|
|
|
* Control Interface - main file
|
2000-09-11 15:49:10 +00:00
|
|
|
* Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
|
1998-08-13 15:42:56 +00:00
|
|
|
*
|
|
|
|
|
*
|
|
|
|
|
* This library is free software; you can redistribute it and/or modify
|
|
|
|
|
* it under the terms of the GNU Library General Public License as
|
|
|
|
|
* published by the Free Software Foundation; either version 2 of
|
|
|
|
|
* the License, or (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU Library General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
#ifndef DOC_HIDDEN
|
1998-08-13 15:42:56 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
2000-11-20 20:10:46 +00:00
|
|
|
#include <stdarg.h>
|
1998-08-13 15:42:56 +00:00
|
|
|
#include <unistd.h>
|
1998-08-27 20:47:51 +00:00
|
|
|
#include <string.h>
|
1998-08-13 15:42:56 +00:00
|
|
|
#include <fcntl.h>
|
2000-10-14 10:31:34 +00:00
|
|
|
#include <dlfcn.h>
|
2001-03-26 12:45:48 +00:00
|
|
|
#include <signal.h>
|
2001-02-09 11:20:31 +00:00
|
|
|
#include <sys/poll.h>
|
2000-07-28 20:21:12 +00:00
|
|
|
#include "control_local.h"
|
2001-03-26 12:45:48 +00:00
|
|
|
#endif
|
1998-08-13 15:42:56 +00:00
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief get identifier of CTL handle
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \return ascii identifier of CTL handle
|
|
|
|
|
*
|
|
|
|
|
* Returns the ASCII identifier of given CTL handle. It's the same
|
|
|
|
|
* identifier specified in snd_ctl_open().
|
|
|
|
|
*/
|
2001-02-11 15:45:35 +00:00
|
|
|
const char *snd_ctl_name(snd_ctl_t *ctl)
|
|
|
|
|
{
|
|
|
|
|
assert(ctl);
|
|
|
|
|
return ctl->name;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief get type of CTL handle
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \return type of CTL handle
|
|
|
|
|
*
|
|
|
|
|
* Returns the type #snd_ctl_type_t of given CTL handle.
|
|
|
|
|
*/
|
2000-09-11 15:49:10 +00:00
|
|
|
snd_ctl_type_t snd_ctl_type(snd_ctl_t *ctl)
|
1998-11-27 14:57:39 +00:00
|
|
|
{
|
2001-02-11 15:45:35 +00:00
|
|
|
assert(ctl);
|
2000-09-11 15:49:10 +00:00
|
|
|
return ctl->type;
|
1998-08-27 20:47:51 +00:00
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief close CTL handle
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \return 0 on success otherwise a negative error code
|
|
|
|
|
*
|
|
|
|
|
* Closes the specified CTL handle and frees all associated
|
|
|
|
|
* resources.
|
|
|
|
|
*/
|
2000-09-11 15:49:10 +00:00
|
|
|
int snd_ctl_close(snd_ctl_t *ctl)
|
1998-08-13 15:42:56 +00:00
|
|
|
{
|
1998-11-27 14:57:39 +00:00
|
|
|
int res;
|
2000-09-11 15:49:10 +00:00
|
|
|
res = ctl->ops->close(ctl);
|
2001-02-11 15:45:35 +00:00
|
|
|
if (ctl->name)
|
|
|
|
|
free(ctl->name);
|
2000-09-11 15:49:10 +00:00
|
|
|
free(ctl);
|
1998-11-27 14:57:39 +00:00
|
|
|
return res;
|
1998-08-13 15:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief set nonblock mode
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \param nonblock 0 = block, 1 = nonblock mode
|
|
|
|
|
* \return 0 on success otherwise a negative error code
|
|
|
|
|
*/
|
2001-02-09 11:20:31 +00:00
|
|
|
int snd_ctl_nonblock(snd_ctl_t *ctl, int nonblock)
|
|
|
|
|
{
|
|
|
|
|
int err;
|
|
|
|
|
assert(ctl);
|
|
|
|
|
err = ctl->ops->nonblock(ctl, nonblock);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
|
|
|
|
ctl->nonblock = nonblock;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief set async mode
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \param sig Signal to raise: < 0 disable, 0 default (SIGIO)
|
|
|
|
|
* \param pid Process ID to signal: 0 current
|
|
|
|
|
* \return 0 on success otherwise a negative error code
|
|
|
|
|
*
|
|
|
|
|
* A signal is raised when a change happens.
|
|
|
|
|
*/
|
2001-02-09 11:20:31 +00:00
|
|
|
int snd_ctl_async(snd_ctl_t *ctl, int sig, pid_t pid)
|
|
|
|
|
{
|
2001-03-26 12:45:48 +00:00
|
|
|
int err;
|
2001-02-09 11:20:31 +00:00
|
|
|
assert(ctl);
|
2001-03-26 12:45:48 +00:00
|
|
|
err = ctl->ops->async(ctl, sig, pid);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
|
|
|
|
if (sig)
|
|
|
|
|
ctl->async_sig = sig;
|
|
|
|
|
else
|
|
|
|
|
ctl->async_sig = SIGIO;
|
|
|
|
|
if (pid)
|
|
|
|
|
ctl->async_pid = pid;
|
|
|
|
|
else
|
|
|
|
|
ctl->async_pid = getpid();
|
|
|
|
|
return 0;
|
2000-09-11 15:49:10 +00:00
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief get count of poll descriptors for CTL handle
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \return count of poll descriptors
|
|
|
|
|
*/
|
2001-02-18 18:32:30 +00:00
|
|
|
int snd_ctl_poll_descriptors_count(snd_ctl_t *ctl)
|
2001-02-14 12:15:03 +00:00
|
|
|
{
|
|
|
|
|
assert(ctl);
|
2001-02-18 18:32:30 +00:00
|
|
|
return 1;
|
2001-02-14 12:15:03 +00:00
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief get poll descriptors
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \param pfds array of poll descriptors
|
|
|
|
|
* \param space space in the poll descriptor array
|
|
|
|
|
* \return count of filled descriptors
|
|
|
|
|
*/
|
2001-02-12 23:51:49 +00:00
|
|
|
int snd_ctl_poll_descriptors(snd_ctl_t *ctl, struct pollfd *pfds, unsigned int space)
|
|
|
|
|
{
|
|
|
|
|
assert(ctl);
|
2001-02-14 12:15:03 +00:00
|
|
|
if (space > 0) {
|
2001-02-12 23:51:49 +00:00
|
|
|
pfds->fd = ctl->ops->poll_descriptor(ctl);
|
|
|
|
|
pfds->events = POLLIN;
|
2001-02-14 12:15:03 +00:00
|
|
|
return 1;
|
2001-02-12 23:51:49 +00:00
|
|
|
}
|
2001-02-14 12:15:03 +00:00
|
|
|
return 0;
|
2001-02-12 23:51:49 +00:00
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Ask to be informed about events (poll, #snd_ctl_async, #snd_ctl_read)
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \param subscribe 0 = unsubscribe, 1 = subscribe
|
|
|
|
|
* \return 0 on success otherwise a negative error code
|
|
|
|
|
*/
|
2001-02-13 21:29:30 +00:00
|
|
|
int snd_ctl_subscribe_events(snd_ctl_t *ctl, int subscribe)
|
|
|
|
|
{
|
|
|
|
|
assert(ctl);
|
|
|
|
|
return ctl->ops->subscribe_events(ctl, subscribe);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Get card related information
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \param info Card info pointer
|
|
|
|
|
* \return 0 on success otherwise a negative error code
|
|
|
|
|
*/
|
2001-02-07 15:13:15 +00:00
|
|
|
int snd_ctl_card_info(snd_ctl_t *ctl, snd_ctl_card_info_t *info)
|
1998-08-13 15:42:56 +00:00
|
|
|
{
|
2000-09-11 15:49:10 +00:00
|
|
|
assert(ctl && info);
|
2001-02-13 21:29:30 +00:00
|
|
|
return ctl->ops->card_info(ctl, info);
|
1998-08-13 15:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Get a list of element identificators
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \param list CTL element identificators list pointer
|
|
|
|
|
* \return 0 on success otherwise a negative error code
|
|
|
|
|
*/
|
2001-02-09 11:20:31 +00:00
|
|
|
int snd_ctl_elem_list(snd_ctl_t *ctl, snd_ctl_elem_list_t *list)
|
1998-08-13 15:42:56 +00:00
|
|
|
{
|
2000-09-11 15:49:10 +00:00
|
|
|
assert(ctl && list);
|
2001-02-09 11:20:31 +00:00
|
|
|
assert(list->space == 0 || list->pids);
|
|
|
|
|
return ctl->ops->element_list(ctl, list);
|
1998-08-13 15:42:56 +00:00
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Get CTL element information
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \param info CTL element id/information pointer
|
|
|
|
|
* \return 0 on success otherwise a negative error code
|
|
|
|
|
*/
|
2001-02-09 11:20:31 +00:00
|
|
|
int snd_ctl_elem_info(snd_ctl_t *ctl, snd_ctl_elem_info_t *info)
|
1998-09-08 14:37:31 +00:00
|
|
|
{
|
2000-09-11 15:49:10 +00:00
|
|
|
assert(ctl && info && (info->id.name[0] || info->id.numid));
|
2001-02-09 11:20:31 +00:00
|
|
|
return ctl->ops->element_info(ctl, info);
|
1998-09-08 14:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Get CTL element value
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \param control CTL element id/value pointer
|
|
|
|
|
* \return 0 on success otherwise a negative error code
|
|
|
|
|
*/
|
2001-02-11 15:45:35 +00:00
|
|
|
int snd_ctl_elem_read(snd_ctl_t *ctl, snd_ctl_elem_value_t *control)
|
1998-11-27 14:57:39 +00:00
|
|
|
{
|
2000-09-11 15:49:10 +00:00
|
|
|
assert(ctl && control && (control->id.name[0] || control->id.numid));
|
2001-02-09 11:20:31 +00:00
|
|
|
return ctl->ops->element_read(ctl, control);
|
1998-09-08 14:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Set CTL element value
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \param control CTL element id/value pointer
|
|
|
|
|
* \return 0 on success otherwise a negative error code
|
|
|
|
|
*/
|
2001-02-11 15:45:35 +00:00
|
|
|
int snd_ctl_elem_write(snd_ctl_t *ctl, snd_ctl_elem_value_t *control)
|
1998-09-08 14:37:31 +00:00
|
|
|
{
|
2000-09-11 15:49:10 +00:00
|
|
|
assert(ctl && control && (control->id.name[0] || control->id.numid));
|
2001-02-09 11:20:31 +00:00
|
|
|
return ctl->ops->element_write(ctl, control);
|
2000-07-15 10:20:32 +00:00
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Get next hardware dependent device number
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \param device current device on entry and next device on return
|
|
|
|
|
* \return 0 on success otherwise a negative error code
|
|
|
|
|
*/
|
2001-02-05 16:04:15 +00:00
|
|
|
int snd_ctl_hwdep_next_device(snd_ctl_t *ctl, int *device)
|
2000-11-30 19:17:55 +00:00
|
|
|
{
|
|
|
|
|
assert(ctl && device);
|
|
|
|
|
return ctl->ops->hwdep_next_device(ctl, device);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Get info about a hardware dependent device
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \param info Hardware dependent device id/info pointer
|
|
|
|
|
* \return 0 on success otherwise a negative error code
|
|
|
|
|
*/
|
2000-09-11 15:49:10 +00:00
|
|
|
int snd_ctl_hwdep_info(snd_ctl_t *ctl, snd_hwdep_info_t * info)
|
2000-07-15 10:20:32 +00:00
|
|
|
{
|
2000-09-11 15:49:10 +00:00
|
|
|
assert(ctl && info);
|
|
|
|
|
return ctl->ops->hwdep_info(ctl, info);
|
1999-06-22 13:18:24 +00:00
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Get next PCM device number
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \param device current device on entry and next device on return
|
|
|
|
|
* \return 0 on success otherwise a negative error code
|
|
|
|
|
*/
|
2000-11-30 19:17:55 +00:00
|
|
|
int snd_ctl_pcm_next_device(snd_ctl_t *ctl, int * device)
|
|
|
|
|
{
|
|
|
|
|
assert(ctl && device);
|
|
|
|
|
return ctl->ops->pcm_next_device(ctl, device);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Get info about a PCM device
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \param info PCM device id/info pointer
|
|
|
|
|
* \return 0 on success otherwise a negative error code
|
|
|
|
|
*/
|
2000-09-11 15:49:10 +00:00
|
|
|
int snd_ctl_pcm_info(snd_ctl_t *ctl, snd_pcm_info_t * info)
|
1998-09-08 14:37:31 +00:00
|
|
|
{
|
2000-09-11 15:49:10 +00:00
|
|
|
assert(ctl && info);
|
|
|
|
|
return ctl->ops->pcm_info(ctl, info);
|
1998-09-08 14:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Set preferred PCM subdevice number of successive PCM open
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \param subdev Preferred PCM subdevice number
|
|
|
|
|
* \return 0 on success otherwise a negative error code
|
|
|
|
|
*/
|
2000-09-11 15:49:10 +00:00
|
|
|
int snd_ctl_pcm_prefer_subdevice(snd_ctl_t *ctl, int subdev)
|
1998-09-08 14:37:31 +00:00
|
|
|
{
|
2000-09-11 15:49:10 +00:00
|
|
|
assert(ctl);
|
|
|
|
|
return ctl->ops->pcm_prefer_subdevice(ctl, subdev);
|
1998-09-08 14:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Get next RawMidi device number
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \param device current device on entry and next device on return
|
|
|
|
|
* \return 0 on success otherwise a negative error code
|
|
|
|
|
*/
|
2000-11-30 19:17:55 +00:00
|
|
|
int snd_ctl_rawmidi_next_device(snd_ctl_t *ctl, int * device)
|
|
|
|
|
{
|
|
|
|
|
assert(ctl && device);
|
|
|
|
|
return ctl->ops->rawmidi_next_device(ctl, device);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Get info about a RawMidi device
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \param info RawMidi device id/info pointer
|
|
|
|
|
* \return 0 on success otherwise a negative error code
|
|
|
|
|
*/
|
2000-09-11 15:49:10 +00:00
|
|
|
int snd_ctl_rawmidi_info(snd_ctl_t *ctl, snd_rawmidi_info_t * info)
|
1998-09-08 14:37:31 +00:00
|
|
|
{
|
2000-09-11 15:49:10 +00:00
|
|
|
assert(ctl && info);
|
|
|
|
|
return ctl->ops->rawmidi_info(ctl, info);
|
1998-11-27 14:57:39 +00:00
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Set preferred RawMidi subdevice number of successive RawMidi open
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \param subdev Preferred RawMidi subdevice number
|
|
|
|
|
* \return 0 on success otherwise a negative error code
|
|
|
|
|
*/
|
2000-10-30 12:15:18 +00:00
|
|
|
int snd_ctl_rawmidi_prefer_subdevice(snd_ctl_t *ctl, int subdev)
|
|
|
|
|
{
|
|
|
|
|
assert(ctl);
|
|
|
|
|
return ctl->ops->rawmidi_prefer_subdevice(ctl, subdev);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* \brief Read an event
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \param event Event pointer
|
|
|
|
|
* \return number of events read otherwise a negative error code on failure
|
|
|
|
|
*/
|
2001-02-09 11:20:31 +00:00
|
|
|
int snd_ctl_read(snd_ctl_t *ctl, snd_ctl_event_t *event)
|
1998-11-27 14:57:39 +00:00
|
|
|
{
|
2000-09-11 15:49:10 +00:00
|
|
|
assert(ctl && event);
|
|
|
|
|
return ctl->ops->read(ctl, event);
|
1998-09-08 14:37:31 +00:00
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Wait for a CTL to become ready (i.e. at least one event pending)
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \param timeout maximum time in milliseconds to wait
|
|
|
|
|
* \return 0 otherwise a negative error code on failure
|
|
|
|
|
*/
|
2001-02-09 11:20:31 +00:00
|
|
|
int snd_ctl_wait(snd_ctl_t *ctl, int timeout)
|
1999-05-04 19:21:28 +00:00
|
|
|
{
|
2001-02-09 11:20:31 +00:00
|
|
|
struct pollfd pfd;
|
|
|
|
|
int err;
|
2001-02-12 23:51:49 +00:00
|
|
|
err = snd_ctl_poll_descriptors(ctl, &pfd, 1);
|
|
|
|
|
assert(err == 1);
|
2001-02-09 11:20:31 +00:00
|
|
|
err = poll(&pfd, 1, timeout);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return -errno;
|
|
|
|
|
return 0;
|
1999-05-04 19:21:28 +00:00
|
|
|
}
|
2000-09-11 15:49:10 +00:00
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Opens a CTL
|
|
|
|
|
* \param ctlp Returned CTL handle
|
|
|
|
|
* \param name ASCII identifier of the CTL handle
|
|
|
|
|
* \param mode Open mode (see #SND_CTL_NONBLOCK, #SND_CTL_ASYNC)
|
|
|
|
|
* \return 0 on success otherwise a negative error code
|
|
|
|
|
*/
|
|
|
|
|
int snd_ctl_open(snd_ctl_t **ctlp, const char *name, int mode)
|
2000-09-11 15:49:10 +00:00
|
|
|
{
|
2001-02-06 23:48:10 +00:00
|
|
|
const char *str;
|
2001-03-07 12:36:05 +00:00
|
|
|
char buf[256];
|
2000-09-11 15:49:10 +00:00
|
|
|
int err;
|
2000-10-14 10:31:34 +00:00
|
|
|
snd_config_t *ctl_conf, *conf, *type_conf;
|
2001-02-11 15:45:35 +00:00
|
|
|
snd_config_iterator_t i, next;
|
2001-02-06 23:48:10 +00:00
|
|
|
const char *lib = NULL, *open = NULL;
|
2001-03-26 12:45:48 +00:00
|
|
|
int (*open_func)(snd_ctl_t **ctlp, const char *name, snd_config_t *conf, int mode);
|
2000-10-14 10:31:34 +00:00
|
|
|
void *h;
|
2001-03-17 16:34:43 +00:00
|
|
|
const char *name1;
|
2000-10-14 10:31:34 +00:00
|
|
|
assert(ctlp && name);
|
2000-09-11 15:49:10 +00:00
|
|
|
err = snd_config_update();
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
2001-03-17 16:34:43 +00:00
|
|
|
|
|
|
|
|
err = snd_config_search_alias(snd_config, "ctl", name, &ctl_conf);
|
|
|
|
|
name1 = name;
|
|
|
|
|
if (err < 0 || snd_config_get_string(ctl_conf, &name1) >= 0) {
|
2000-11-20 20:10:46 +00:00
|
|
|
int card;
|
|
|
|
|
char socket[256], sname[256];
|
2001-03-17 16:34:43 +00:00
|
|
|
err = sscanf(name1, "hw:%d", &card);
|
2000-11-20 20:10:46 +00:00
|
|
|
if (err == 1)
|
2001-03-26 12:45:48 +00:00
|
|
|
return snd_ctl_hw_open(ctlp, name, card, mode);
|
2001-03-17 16:34:43 +00:00
|
|
|
err = sscanf(name1, "shm:%256[^,],%256[^,]", socket, sname);
|
2000-11-20 20:10:46 +00:00
|
|
|
if (err == 2)
|
2001-03-26 12:45:48 +00:00
|
|
|
return snd_ctl_shm_open(ctlp, name, socket, sname, mode);
|
2001-03-17 16:34:43 +00:00
|
|
|
SNDERR("Unknown ctl %s", name1);
|
2000-11-20 20:10:46 +00:00
|
|
|
return -ENOENT;
|
2000-10-14 10:43:02 +00:00
|
|
|
}
|
2001-03-17 16:34:43 +00:00
|
|
|
if (snd_config_get_type(ctl_conf) != SND_CONFIG_TYPE_COMPOUND) {
|
|
|
|
|
SNDERR("Invalid type for %s", snd_config_get_id(ctl_conf));
|
2000-09-11 15:49:10 +00:00
|
|
|
return -EINVAL;
|
2001-03-17 16:34:43 +00:00
|
|
|
}
|
2000-09-11 15:49:10 +00:00
|
|
|
err = snd_config_search(ctl_conf, "type", &conf);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
2001-02-07 11:34:33 +00:00
|
|
|
err = snd_config_get_string(conf, &str);
|
2000-09-11 15:49:10 +00:00
|
|
|
if (err < 0)
|
|
|
|
|
return err;
|
2001-03-17 16:34:43 +00:00
|
|
|
err = snd_config_search_alias(snd_config, "ctl_type", str, &type_conf);
|
2001-03-07 12:36:05 +00:00
|
|
|
if (err >= 0) {
|
2001-03-17 16:34:43 +00:00
|
|
|
if (snd_config_get_type(type_conf) != SND_CONFIG_TYPE_COMPOUND) {
|
|
|
|
|
SNDERR("Invalid type for ctl type %s definition", str);
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
2001-03-07 12:36:05 +00:00
|
|
|
snd_config_for_each(i, next, type_conf) {
|
|
|
|
|
snd_config_t *n = snd_config_iterator_entry(i);
|
|
|
|
|
const char *id = snd_config_get_id(n);
|
|
|
|
|
if (strcmp(id, "comment") == 0)
|
|
|
|
|
continue;
|
|
|
|
|
if (strcmp(id, "lib") == 0) {
|
|
|
|
|
err = snd_config_get_string(n, &lib);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (strcmp(id, "open") == 0) {
|
|
|
|
|
err = snd_config_get_string(n, &open);
|
|
|
|
|
if (err < 0)
|
|
|
|
|
return -EINVAL;
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
SNDERR("Unknown field %s", id);
|
2000-10-14 10:31:34 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
}
|
|
|
|
|
}
|
2001-03-07 12:36:05 +00:00
|
|
|
if (!open) {
|
|
|
|
|
open = buf;
|
|
|
|
|
snprintf(buf, sizeof(buf), "_snd_ctl_%s_open", str);
|
|
|
|
|
}
|
2000-10-14 10:31:34 +00:00
|
|
|
if (!lib)
|
|
|
|
|
lib = "libasound.so";
|
|
|
|
|
h = dlopen(lib, RTLD_NOW);
|
2001-03-07 12:36:05 +00:00
|
|
|
if (!h) {
|
|
|
|
|
SNDERR("Cannot open shared library %s", lib);
|
2000-10-14 10:31:34 +00:00
|
|
|
return -ENOENT;
|
2001-03-07 12:36:05 +00:00
|
|
|
}
|
2000-10-14 10:31:34 +00:00
|
|
|
open_func = dlsym(h, open);
|
2001-03-07 12:36:05 +00:00
|
|
|
if (!open_func) {
|
|
|
|
|
SNDERR("symbol %s is not defined inside %s", open, lib);
|
|
|
|
|
dlclose(h);
|
2000-10-14 10:31:34 +00:00
|
|
|
return -ENXIO;
|
2001-03-07 12:36:05 +00:00
|
|
|
}
|
2001-03-26 12:45:48 +00:00
|
|
|
return open_func(ctlp, name, ctl_conf, mode);
|
2000-09-11 15:49:10 +00:00
|
|
|
}
|
2000-11-20 20:10:46 +00:00
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Set CTL element #SND_CTL_ELEM_TYPE_BYTES value
|
|
|
|
|
* \param ctl CTL handle
|
|
|
|
|
* \param data Bytes value
|
|
|
|
|
* \param size Size in bytes
|
|
|
|
|
*/
|
2001-02-11 15:45:35 +00:00
|
|
|
void snd_ctl_elem_set_bytes(snd_ctl_elem_value_t *obj, void *data, size_t size)
|
2001-02-06 23:48:10 +00:00
|
|
|
{
|
|
|
|
|
assert(obj);
|
2001-03-26 12:45:48 +00:00
|
|
|
if (size >= sizeof(obj->value.bytes.data)) {
|
|
|
|
|
assert(0);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2001-02-06 23:48:10 +00:00
|
|
|
memcpy(obj->value.bytes.data, data, size);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
#ifndef DOC_HIDDEN
|
2001-02-09 11:20:31 +00:00
|
|
|
#define TYPE(v) [SND_CTL_ELEM_TYPE_##v] = #v
|
|
|
|
|
#define IFACE(v) [SND_CTL_ELEM_IFACE_##v] = #v
|
2001-02-06 23:48:10 +00:00
|
|
|
#define EVENT(v) [SND_CTL_EVENT_##v] = #v
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
static const char *snd_ctl_elem_type_names[] = {
|
2001-02-06 23:48:10 +00:00
|
|
|
TYPE(NONE),
|
|
|
|
|
TYPE(BOOLEAN),
|
|
|
|
|
TYPE(INTEGER),
|
|
|
|
|
TYPE(ENUMERATED),
|
|
|
|
|
TYPE(BYTES),
|
|
|
|
|
TYPE(IEC958),
|
|
|
|
|
};
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
static const char *snd_ctl_elem_iface_names[] = {
|
2001-02-06 23:48:10 +00:00
|
|
|
IFACE(CARD),
|
|
|
|
|
IFACE(HWDEP),
|
|
|
|
|
IFACE(MIXER),
|
|
|
|
|
IFACE(PCM),
|
|
|
|
|
IFACE(RAWMIDI),
|
|
|
|
|
IFACE(TIMER),
|
|
|
|
|
IFACE(SEQUENCER),
|
|
|
|
|
};
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
static const char *snd_ctl_event_type_names[] = {
|
2001-02-13 21:29:30 +00:00
|
|
|
EVENT(ELEM),
|
2001-02-06 23:48:10 +00:00
|
|
|
};
|
2001-03-26 12:45:48 +00:00
|
|
|
#endif
|
2001-02-06 23:48:10 +00:00
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief get name of a CTL element type
|
|
|
|
|
* \param type CTL element type
|
|
|
|
|
* \return ascii name of CTL element type
|
|
|
|
|
*/
|
2001-02-09 11:20:31 +00:00
|
|
|
const char *snd_ctl_elem_type_name(snd_ctl_elem_type_t type)
|
2001-02-06 23:48:10 +00:00
|
|
|
{
|
2001-02-09 11:20:31 +00:00
|
|
|
assert(type <= SND_CTL_ELEM_TYPE_LAST);
|
|
|
|
|
return snd_ctl_elem_type_names[snd_enum_to_int(type)];
|
2001-02-06 23:48:10 +00:00
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief get name of a CTL element related interface
|
|
|
|
|
* \param iface CTL element related interface
|
|
|
|
|
* \return ascii name of CTL element related interface
|
|
|
|
|
*/
|
2001-02-09 11:20:31 +00:00
|
|
|
const char *snd_ctl_elem_iface_name(snd_ctl_elem_iface_t iface)
|
2001-02-06 23:48:10 +00:00
|
|
|
{
|
2001-02-09 11:20:31 +00:00
|
|
|
assert(iface <= SND_CTL_ELEM_IFACE_LAST);
|
|
|
|
|
return snd_ctl_elem_iface_names[snd_enum_to_int(iface)];
|
2001-02-06 23:48:10 +00:00
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief get name of a CTL event type
|
|
|
|
|
* \param type CTL event type
|
|
|
|
|
* \return ascii name of CTL event type
|
|
|
|
|
*/
|
2001-02-06 23:48:10 +00:00
|
|
|
const char *snd_ctl_event_type_name(snd_ctl_event_type_t type)
|
|
|
|
|
{
|
|
|
|
|
assert(type <= SND_CTL_EVENT_LAST);
|
|
|
|
|
return snd_ctl_event_type_names[snd_enum_to_int(type)];
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief allocate space for CTL element identificators list
|
|
|
|
|
* \param obj CTL element identificators list
|
|
|
|
|
* \param entries Entries to allocate
|
|
|
|
|
* \return 0 on success otherwise a negative error code
|
|
|
|
|
*/
|
2001-02-09 11:20:31 +00:00
|
|
|
int snd_ctl_elem_list_alloc_space(snd_ctl_elem_list_t *obj, unsigned int entries)
|
2001-02-06 23:48:10 +00:00
|
|
|
{
|
2001-02-09 11:20:31 +00:00
|
|
|
if (obj->pids)
|
|
|
|
|
free(obj->pids);
|
2001-02-06 23:48:10 +00:00
|
|
|
obj->pids = calloc(entries, sizeof(*obj->pids));
|
|
|
|
|
if (!obj->pids) {
|
|
|
|
|
obj->space = 0;
|
|
|
|
|
return -ENOMEM;
|
|
|
|
|
}
|
|
|
|
|
obj->space = entries;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief free previously allocated space for CTL element identificators list
|
|
|
|
|
* \param obj CTL element identificators list
|
|
|
|
|
*/
|
2001-02-09 11:20:31 +00:00
|
|
|
void snd_ctl_elem_list_free_space(snd_ctl_elem_list_t *obj)
|
2001-02-06 23:48:10 +00:00
|
|
|
{
|
|
|
|
|
free(obj->pids);
|
|
|
|
|
obj->pids = NULL;
|
|
|
|
|
}
|
2001-02-13 21:29:30 +00:00
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Get event mask for an element related event
|
|
|
|
|
* \param obj CTL event
|
|
|
|
|
* \return event mask for element related event
|
|
|
|
|
*/
|
2001-02-13 21:29:30 +00:00
|
|
|
unsigned int snd_ctl_event_elem_get_mask(const snd_ctl_event_t *obj)
|
|
|
|
|
{
|
|
|
|
|
assert(obj);
|
|
|
|
|
assert(obj->type == SND_CTL_EVENT_ELEM);
|
|
|
|
|
return obj->data.elem.mask;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Get element numeric identificator for an element related event
|
|
|
|
|
* \param obj CTL event
|
|
|
|
|
* \return element numeric identificator for element related event
|
|
|
|
|
*/
|
2001-02-13 21:29:30 +00:00
|
|
|
unsigned int snd_ctl_event_elem_get_numid(const snd_ctl_event_t *obj)
|
|
|
|
|
{
|
|
|
|
|
assert(obj);
|
|
|
|
|
assert(obj->type == SND_CTL_EVENT_ELEM);
|
|
|
|
|
return obj->data.elem.id.numid;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Get CTL element identificator for an element related event
|
|
|
|
|
* \param obj CTL event
|
|
|
|
|
* \param ptr Pointer to returned CTL element identificator
|
|
|
|
|
*/
|
2001-02-13 21:29:30 +00:00
|
|
|
void snd_ctl_event_elem_get_id(const snd_ctl_event_t *obj, snd_ctl_elem_id_t *ptr)
|
|
|
|
|
{
|
|
|
|
|
assert(obj && ptr);
|
|
|
|
|
assert(obj->type == SND_CTL_EVENT_ELEM);
|
|
|
|
|
*ptr = obj->data.elem.id;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Get interface part of CTL element identificator for an element related event
|
|
|
|
|
* \param obj CTL event
|
|
|
|
|
* \return interface part of element identificator
|
|
|
|
|
*/
|
2001-02-13 21:29:30 +00:00
|
|
|
snd_ctl_elem_iface_t snd_ctl_event_elem_get_interface(const snd_ctl_event_t *obj)
|
|
|
|
|
{
|
|
|
|
|
assert(obj);
|
|
|
|
|
assert(obj->type == SND_CTL_EVENT_ELEM);
|
|
|
|
|
return snd_int_to_enum(obj->data.elem.id.iface);
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Get device part of CTL element identificator for an element related event
|
|
|
|
|
* \param obj CTL event
|
|
|
|
|
* \return device part of element identificator
|
|
|
|
|
*/
|
2001-02-13 21:29:30 +00:00
|
|
|
unsigned int snd_ctl_event_elem_get_device(const snd_ctl_event_t *obj)
|
|
|
|
|
{
|
|
|
|
|
assert(obj);
|
|
|
|
|
assert(obj->type == SND_CTL_EVENT_ELEM);
|
|
|
|
|
return obj->data.elem.id.device;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Get subdevice part of CTL element identificator for an element related event
|
|
|
|
|
* \param obj CTL event
|
|
|
|
|
* \return subdevice part of element identificator
|
|
|
|
|
*/
|
2001-02-13 21:29:30 +00:00
|
|
|
unsigned int snd_ctl_event_elem_get_subdevice(const snd_ctl_event_t *obj)
|
|
|
|
|
{
|
|
|
|
|
assert(obj);
|
|
|
|
|
assert(obj->type == SND_CTL_EVENT_ELEM);
|
|
|
|
|
return obj->data.elem.id.subdevice;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Get name part of CTL element identificator for an element related event
|
|
|
|
|
* \param obj CTL event
|
|
|
|
|
* \return name part of element identificator
|
|
|
|
|
*/
|
2001-02-13 21:29:30 +00:00
|
|
|
const char *snd_ctl_event_elem_get_name(const snd_ctl_event_t *obj)
|
|
|
|
|
{
|
|
|
|
|
assert(obj);
|
|
|
|
|
assert(obj->type == SND_CTL_EVENT_ELEM);
|
|
|
|
|
return obj->data.elem.id.name;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
/**
|
|
|
|
|
* \brief Get index part of CTL element identificator for an element related event
|
|
|
|
|
* \param obj CTL event
|
|
|
|
|
* \return index part of element identificator
|
|
|
|
|
*/
|
2001-02-13 21:29:30 +00:00
|
|
|
unsigned int snd_ctl_event_elem_get_index(const snd_ctl_event_t *obj)
|
|
|
|
|
{
|
|
|
|
|
assert(obj);
|
|
|
|
|
assert(obj->type == SND_CTL_EVENT_ELEM);
|
|
|
|
|
return obj->data.elem.id.index;
|
|
|
|
|
}
|
|
|
|
|
|
2001-03-26 12:45:48 +00:00
|
|
|
#ifndef DOC_HIDDEN
|
|
|
|
|
int _snd_ctl_poll_descriptor(snd_ctl_t *ctl)
|
|
|
|
|
{
|
|
|
|
|
assert(ctl);
|
|
|
|
|
return ctl->ops->poll_descriptor(ctl);
|
|
|
|
|
}
|
|
|
|
|
#endif
|