mirror of
https://github.com/alsa-project/alsa-lib.git
synced 2025-11-06 13:29:59 -05:00
Added mode argument to open functions where it was missing. First part of CTL documentation
This commit is contained in:
parent
4bee8c5678
commit
7893ea238d
21 changed files with 570 additions and 276 deletions
|
|
@ -88,7 +88,7 @@ int snd_card_get_index(const char *string)
|
|||
for (card = 0; card < 32; card++) {
|
||||
if (snd_card_load(card) < 0)
|
||||
continue;
|
||||
if (snd_ctl_hw_open(&handle, NULL, card) < 0)
|
||||
if (snd_ctl_hw_open(&handle, NULL, card, 0) < 0)
|
||||
continue;
|
||||
if (snd_ctl_card_info(handle, &info) < 0) {
|
||||
snd_ctl_close(handle);
|
||||
|
|
@ -109,7 +109,7 @@ int snd_card_get_name(int card, char **name)
|
|||
|
||||
if (name == NULL)
|
||||
return -EINVAL;
|
||||
if ((err = snd_ctl_hw_open(&handle, NULL, card)) < 0)
|
||||
if ((err = snd_ctl_hw_open(&handle, NULL, card, 0)) < 0)
|
||||
return err;
|
||||
if ((err = snd_ctl_card_info(handle, &info)) < 0) {
|
||||
snd_ctl_close(handle);
|
||||
|
|
@ -130,7 +130,7 @@ int snd_card_get_longname(int card, char **name)
|
|||
|
||||
if (name == NULL)
|
||||
return -EINVAL;
|
||||
if ((err = snd_ctl_hw_open(&handle, NULL, card)) < 0)
|
||||
if ((err = snd_ctl_hw_open(&handle, NULL, card, 0)) < 0)
|
||||
return err;
|
||||
if ((err = snd_ctl_card_info(handle, &info)) < 0) {
|
||||
snd_ctl_close(handle);
|
||||
|
|
|
|||
|
|
@ -1,3 +1,10 @@
|
|||
/**
|
||||
* \file control/control.c
|
||||
* \author Abramo Bagnara <abramo@alsa-project.org>
|
||||
* \date 2000
|
||||
*
|
||||
* CTL interface is designed to access primitive controls.
|
||||
*/
|
||||
/*
|
||||
* Control Interface - main file
|
||||
* Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
|
||||
|
|
@ -19,6 +26,7 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#ifndef DOC_HIDDEN
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
|
|
@ -26,21 +34,46 @@
|
|||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <dlfcn.h>
|
||||
#include <signal.h>
|
||||
#include <sys/poll.h>
|
||||
#include "control_local.h"
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \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().
|
||||
*/
|
||||
const char *snd_ctl_name(snd_ctl_t *ctl)
|
||||
{
|
||||
assert(ctl);
|
||||
return ctl->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* \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.
|
||||
*/
|
||||
snd_ctl_type_t snd_ctl_type(snd_ctl_t *ctl)
|
||||
{
|
||||
assert(ctl);
|
||||
return ctl->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* \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.
|
||||
*/
|
||||
int snd_ctl_close(snd_ctl_t *ctl)
|
||||
{
|
||||
int res;
|
||||
|
|
@ -51,6 +84,12 @@ int snd_ctl_close(snd_ctl_t *ctl)
|
|||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief set nonblock mode
|
||||
* \param ctl CTL handle
|
||||
* \param nonblock 0 = block, 1 = nonblock mode
|
||||
* \return 0 on success otherwise a negative error code
|
||||
*/
|
||||
int snd_ctl_nonblock(snd_ctl_t *ctl, int nonblock)
|
||||
{
|
||||
int err;
|
||||
|
|
@ -62,24 +101,51 @@ int snd_ctl_nonblock(snd_ctl_t *ctl, int nonblock)
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \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.
|
||||
*/
|
||||
int snd_ctl_async(snd_ctl_t *ctl, int sig, pid_t pid)
|
||||
{
|
||||
int err;
|
||||
assert(ctl);
|
||||
return ctl->ops->async(ctl, sig, pid);
|
||||
}
|
||||
|
||||
int _snd_ctl_poll_descriptor(snd_ctl_t *ctl)
|
||||
{
|
||||
assert(ctl);
|
||||
return ctl->ops->poll_descriptor(ctl);
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief get count of poll descriptors for CTL handle
|
||||
* \param ctl CTL handle
|
||||
* \return count of poll descriptors
|
||||
*/
|
||||
int snd_ctl_poll_descriptors_count(snd_ctl_t *ctl)
|
||||
{
|
||||
assert(ctl);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* \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
|
||||
*/
|
||||
int snd_ctl_poll_descriptors(snd_ctl_t *ctl, struct pollfd *pfds, unsigned int space)
|
||||
{
|
||||
assert(ctl);
|
||||
|
|
@ -91,18 +157,37 @@ int snd_ctl_poll_descriptors(snd_ctl_t *ctl, struct pollfd *pfds, unsigned int s
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \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
|
||||
*/
|
||||
int snd_ctl_subscribe_events(snd_ctl_t *ctl, int subscribe)
|
||||
{
|
||||
assert(ctl);
|
||||
return ctl->ops->subscribe_events(ctl, subscribe);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Get card related information
|
||||
* \param ctl CTL handle
|
||||
* \param info Card info pointer
|
||||
* \return 0 on success otherwise a negative error code
|
||||
*/
|
||||
int snd_ctl_card_info(snd_ctl_t *ctl, snd_ctl_card_info_t *info)
|
||||
{
|
||||
assert(ctl && info);
|
||||
return ctl->ops->card_info(ctl, info);
|
||||
}
|
||||
|
||||
/**
|
||||
* \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
|
||||
*/
|
||||
int snd_ctl_elem_list(snd_ctl_t *ctl, snd_ctl_elem_list_t *list)
|
||||
{
|
||||
assert(ctl && list);
|
||||
|
|
@ -110,78 +195,157 @@ int snd_ctl_elem_list(snd_ctl_t *ctl, snd_ctl_elem_list_t *list)
|
|||
return ctl->ops->element_list(ctl, list);
|
||||
}
|
||||
|
||||
/**
|
||||
* \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
|
||||
*/
|
||||
int snd_ctl_elem_info(snd_ctl_t *ctl, snd_ctl_elem_info_t *info)
|
||||
{
|
||||
assert(ctl && info && (info->id.name[0] || info->id.numid));
|
||||
return ctl->ops->element_info(ctl, info);
|
||||
}
|
||||
|
||||
/**
|
||||
* \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
|
||||
*/
|
||||
int snd_ctl_elem_read(snd_ctl_t *ctl, snd_ctl_elem_value_t *control)
|
||||
{
|
||||
assert(ctl && control && (control->id.name[0] || control->id.numid));
|
||||
return ctl->ops->element_read(ctl, control);
|
||||
}
|
||||
|
||||
/**
|
||||
* \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
|
||||
*/
|
||||
int snd_ctl_elem_write(snd_ctl_t *ctl, snd_ctl_elem_value_t *control)
|
||||
{
|
||||
assert(ctl && control && (control->id.name[0] || control->id.numid));
|
||||
return ctl->ops->element_write(ctl, control);
|
||||
}
|
||||
|
||||
/**
|
||||
* \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
|
||||
*/
|
||||
int snd_ctl_hwdep_next_device(snd_ctl_t *ctl, int *device)
|
||||
{
|
||||
assert(ctl && device);
|
||||
return ctl->ops->hwdep_next_device(ctl, device);
|
||||
}
|
||||
|
||||
/**
|
||||
* \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
|
||||
*/
|
||||
int snd_ctl_hwdep_info(snd_ctl_t *ctl, snd_hwdep_info_t * info)
|
||||
{
|
||||
assert(ctl && info);
|
||||
return ctl->ops->hwdep_info(ctl, info);
|
||||
}
|
||||
|
||||
/**
|
||||
* \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
|
||||
*/
|
||||
int snd_ctl_pcm_next_device(snd_ctl_t *ctl, int * device)
|
||||
{
|
||||
assert(ctl && device);
|
||||
return ctl->ops->pcm_next_device(ctl, device);
|
||||
}
|
||||
|
||||
/**
|
||||
* \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
|
||||
*/
|
||||
int snd_ctl_pcm_info(snd_ctl_t *ctl, snd_pcm_info_t * info)
|
||||
{
|
||||
assert(ctl && info);
|
||||
return ctl->ops->pcm_info(ctl, info);
|
||||
}
|
||||
|
||||
/**
|
||||
* \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
|
||||
*/
|
||||
int snd_ctl_pcm_prefer_subdevice(snd_ctl_t *ctl, int subdev)
|
||||
{
|
||||
assert(ctl);
|
||||
return ctl->ops->pcm_prefer_subdevice(ctl, subdev);
|
||||
}
|
||||
|
||||
/**
|
||||
* \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
|
||||
*/
|
||||
int snd_ctl_rawmidi_next_device(snd_ctl_t *ctl, int * device)
|
||||
{
|
||||
assert(ctl && device);
|
||||
return ctl->ops->rawmidi_next_device(ctl, device);
|
||||
}
|
||||
|
||||
/**
|
||||
* \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
|
||||
*/
|
||||
int snd_ctl_rawmidi_info(snd_ctl_t *ctl, snd_rawmidi_info_t * info)
|
||||
{
|
||||
assert(ctl && info);
|
||||
return ctl->ops->rawmidi_info(ctl, info);
|
||||
}
|
||||
|
||||
/**
|
||||
* \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
|
||||
*/
|
||||
int snd_ctl_rawmidi_prefer_subdevice(snd_ctl_t *ctl, int subdev)
|
||||
{
|
||||
assert(ctl);
|
||||
return ctl->ops->rawmidi_prefer_subdevice(ctl, subdev);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Read an event
|
||||
* \param ctl CTL handle
|
||||
* \param event Event pointer
|
||||
* \return number of events read otherwise a negative error code on failure
|
||||
*/
|
||||
int snd_ctl_read(snd_ctl_t *ctl, snd_ctl_event_t *event)
|
||||
{
|
||||
assert(ctl && event);
|
||||
return ctl->ops->read(ctl, event);
|
||||
}
|
||||
|
||||
/**
|
||||
* \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
|
||||
*/
|
||||
int snd_ctl_wait(snd_ctl_t *ctl, int timeout)
|
||||
{
|
||||
struct pollfd pfd;
|
||||
|
|
@ -194,7 +358,14 @@ int snd_ctl_wait(snd_ctl_t *ctl, int timeout)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int snd_ctl_open(snd_ctl_t **ctlp, const char *name)
|
||||
/**
|
||||
* \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)
|
||||
{
|
||||
const char *str;
|
||||
char buf[256];
|
||||
|
|
@ -202,7 +373,7 @@ int snd_ctl_open(snd_ctl_t **ctlp, const char *name)
|
|||
snd_config_t *ctl_conf, *conf, *type_conf;
|
||||
snd_config_iterator_t i, next;
|
||||
const char *lib = NULL, *open = NULL;
|
||||
int (*open_func)(snd_ctl_t **ctlp, const char *name, snd_config_t *conf);
|
||||
int (*open_func)(snd_ctl_t **ctlp, const char *name, snd_config_t *conf, int mode);
|
||||
void *h;
|
||||
const char *name1;
|
||||
assert(ctlp && name);
|
||||
|
|
@ -217,10 +388,10 @@ int snd_ctl_open(snd_ctl_t **ctlp, const char *name)
|
|||
char socket[256], sname[256];
|
||||
err = sscanf(name1, "hw:%d", &card);
|
||||
if (err == 1)
|
||||
return snd_ctl_hw_open(ctlp, name, card);
|
||||
return snd_ctl_hw_open(ctlp, name, card, mode);
|
||||
err = sscanf(name1, "shm:%256[^,],%256[^,]", socket, sname);
|
||||
if (err == 2)
|
||||
return snd_ctl_shm_open(ctlp, name, socket, sname);
|
||||
return snd_ctl_shm_open(ctlp, name, socket, sname, mode);
|
||||
SNDERR("Unknown ctl %s", name1);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
|
@ -278,21 +449,31 @@ int snd_ctl_open(snd_ctl_t **ctlp, const char *name)
|
|||
dlclose(h);
|
||||
return -ENXIO;
|
||||
}
|
||||
return open_func(ctlp, name, ctl_conf);
|
||||
return open_func(ctlp, name, ctl_conf, mode);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set CTL element #SND_CTL_ELEM_TYPE_BYTES value
|
||||
* \param ctl CTL handle
|
||||
* \param data Bytes value
|
||||
* \param size Size in bytes
|
||||
*/
|
||||
void snd_ctl_elem_set_bytes(snd_ctl_elem_value_t *obj, void *data, size_t size)
|
||||
{
|
||||
assert(obj);
|
||||
assert(size <= sizeof(obj->value.bytes.data));
|
||||
if (size >= sizeof(obj->value.bytes.data)) {
|
||||
assert(0);
|
||||
return;
|
||||
}
|
||||
memcpy(obj->value.bytes.data, data, size);
|
||||
}
|
||||
|
||||
#ifndef DOC_HIDDEN
|
||||
#define TYPE(v) [SND_CTL_ELEM_TYPE_##v] = #v
|
||||
#define IFACE(v) [SND_CTL_ELEM_IFACE_##v] = #v
|
||||
#define EVENT(v) [SND_CTL_EVENT_##v] = #v
|
||||
|
||||
const char *snd_ctl_elem_type_names[] = {
|
||||
static const char *snd_ctl_elem_type_names[] = {
|
||||
TYPE(NONE),
|
||||
TYPE(BOOLEAN),
|
||||
TYPE(INTEGER),
|
||||
|
|
@ -301,7 +482,7 @@ const char *snd_ctl_elem_type_names[] = {
|
|||
TYPE(IEC958),
|
||||
};
|
||||
|
||||
const char *snd_ctl_elem_iface_names[] = {
|
||||
static const char *snd_ctl_elem_iface_names[] = {
|
||||
IFACE(CARD),
|
||||
IFACE(HWDEP),
|
||||
IFACE(MIXER),
|
||||
|
|
@ -311,28 +492,50 @@ const char *snd_ctl_elem_iface_names[] = {
|
|||
IFACE(SEQUENCER),
|
||||
};
|
||||
|
||||
const char *snd_ctl_event_type_names[] = {
|
||||
static const char *snd_ctl_event_type_names[] = {
|
||||
EVENT(ELEM),
|
||||
};
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \brief get name of a CTL element type
|
||||
* \param type CTL element type
|
||||
* \return ascii name of CTL element type
|
||||
*/
|
||||
const char *snd_ctl_elem_type_name(snd_ctl_elem_type_t type)
|
||||
{
|
||||
assert(type <= SND_CTL_ELEM_TYPE_LAST);
|
||||
return snd_ctl_elem_type_names[snd_enum_to_int(type)];
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief get name of a CTL element related interface
|
||||
* \param iface CTL element related interface
|
||||
* \return ascii name of CTL element related interface
|
||||
*/
|
||||
const char *snd_ctl_elem_iface_name(snd_ctl_elem_iface_t iface)
|
||||
{
|
||||
assert(iface <= SND_CTL_ELEM_IFACE_LAST);
|
||||
return snd_ctl_elem_iface_names[snd_enum_to_int(iface)];
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief get name of a CTL event type
|
||||
* \param type CTL event type
|
||||
* \return ascii name of CTL event type
|
||||
*/
|
||||
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)];
|
||||
}
|
||||
|
||||
/**
|
||||
* \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
|
||||
*/
|
||||
int snd_ctl_elem_list_alloc_space(snd_ctl_elem_list_t *obj, unsigned int entries)
|
||||
{
|
||||
if (obj->pids)
|
||||
|
|
@ -346,12 +549,21 @@ int snd_ctl_elem_list_alloc_space(snd_ctl_elem_list_t *obj, unsigned int entries
|
|||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief free previously allocated space for CTL element identificators list
|
||||
* \param obj CTL element identificators list
|
||||
*/
|
||||
void snd_ctl_elem_list_free_space(snd_ctl_elem_list_t *obj)
|
||||
{
|
||||
free(obj->pids);
|
||||
obj->pids = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Get event mask for an element related event
|
||||
* \param obj CTL event
|
||||
* \return event mask for element related event
|
||||
*/
|
||||
unsigned int snd_ctl_event_elem_get_mask(const snd_ctl_event_t *obj)
|
||||
{
|
||||
assert(obj);
|
||||
|
|
@ -359,6 +571,11 @@ unsigned int snd_ctl_event_elem_get_mask(const snd_ctl_event_t *obj)
|
|||
return obj->data.elem.mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Get element numeric identificator for an element related event
|
||||
* \param obj CTL event
|
||||
* \return element numeric identificator for element related event
|
||||
*/
|
||||
unsigned int snd_ctl_event_elem_get_numid(const snd_ctl_event_t *obj)
|
||||
{
|
||||
assert(obj);
|
||||
|
|
@ -366,6 +583,11 @@ unsigned int snd_ctl_event_elem_get_numid(const snd_ctl_event_t *obj)
|
|||
return obj->data.elem.id.numid;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Get CTL element identificator for an element related event
|
||||
* \param obj CTL event
|
||||
* \param ptr Pointer to returned CTL element identificator
|
||||
*/
|
||||
void snd_ctl_event_elem_get_id(const snd_ctl_event_t *obj, snd_ctl_elem_id_t *ptr)
|
||||
{
|
||||
assert(obj && ptr);
|
||||
|
|
@ -373,6 +595,11 @@ void snd_ctl_event_elem_get_id(const snd_ctl_event_t *obj, snd_ctl_elem_id_t *pt
|
|||
*ptr = obj->data.elem.id;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Get interface part of CTL element identificator for an element related event
|
||||
* \param obj CTL event
|
||||
* \return interface part of element identificator
|
||||
*/
|
||||
snd_ctl_elem_iface_t snd_ctl_event_elem_get_interface(const snd_ctl_event_t *obj)
|
||||
{
|
||||
assert(obj);
|
||||
|
|
@ -380,6 +607,11 @@ snd_ctl_elem_iface_t snd_ctl_event_elem_get_interface(const snd_ctl_event_t *obj
|
|||
return snd_int_to_enum(obj->data.elem.id.iface);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Get device part of CTL element identificator for an element related event
|
||||
* \param obj CTL event
|
||||
* \return device part of element identificator
|
||||
*/
|
||||
unsigned int snd_ctl_event_elem_get_device(const snd_ctl_event_t *obj)
|
||||
{
|
||||
assert(obj);
|
||||
|
|
@ -387,6 +619,11 @@ unsigned int snd_ctl_event_elem_get_device(const snd_ctl_event_t *obj)
|
|||
return obj->data.elem.id.device;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Get subdevice part of CTL element identificator for an element related event
|
||||
* \param obj CTL event
|
||||
* \return subdevice part of element identificator
|
||||
*/
|
||||
unsigned int snd_ctl_event_elem_get_subdevice(const snd_ctl_event_t *obj)
|
||||
{
|
||||
assert(obj);
|
||||
|
|
@ -394,6 +631,11 @@ unsigned int snd_ctl_event_elem_get_subdevice(const snd_ctl_event_t *obj)
|
|||
return obj->data.elem.id.subdevice;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Get name part of CTL element identificator for an element related event
|
||||
* \param obj CTL event
|
||||
* \return name part of element identificator
|
||||
*/
|
||||
const char *snd_ctl_event_elem_get_name(const snd_ctl_event_t *obj)
|
||||
{
|
||||
assert(obj);
|
||||
|
|
@ -401,6 +643,11 @@ const char *snd_ctl_event_elem_get_name(const snd_ctl_event_t *obj)
|
|||
return obj->data.elem.id.name;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Get index part of CTL element identificator for an element related event
|
||||
* \param obj CTL event
|
||||
* \return index part of element identificator
|
||||
*/
|
||||
unsigned int snd_ctl_event_elem_get_index(const snd_ctl_event_t *obj)
|
||||
{
|
||||
assert(obj);
|
||||
|
|
@ -408,3 +655,10 @@ unsigned int snd_ctl_event_elem_get_index(const snd_ctl_event_t *obj)
|
|||
return obj->data.elem.id.index;
|
||||
}
|
||||
|
||||
#ifndef DOC_HIDDEN
|
||||
int _snd_ctl_poll_descriptor(snd_ctl_t *ctl)
|
||||
{
|
||||
assert(ctl);
|
||||
return ctl->ops->poll_descriptor(ctl);
|
||||
}
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -259,10 +259,11 @@ snd_ctl_ops_t snd_ctl_hw_ops = {
|
|||
read: snd_ctl_hw_read,
|
||||
};
|
||||
|
||||
int snd_ctl_hw_open(snd_ctl_t **handle, const char *name, int card)
|
||||
int snd_ctl_hw_open(snd_ctl_t **handle, const char *name, int card, int mode)
|
||||
{
|
||||
int fd, ver;
|
||||
char filename[32];
|
||||
int fmode;
|
||||
snd_ctl_t *ctl;
|
||||
snd_ctl_hw_t *hw;
|
||||
|
||||
|
|
@ -270,7 +271,12 @@ int snd_ctl_hw_open(snd_ctl_t **handle, const char *name, int card)
|
|||
|
||||
assert(card >= 0 && card < 32);
|
||||
sprintf(filename, SNDRV_FILE_CONTROL, card);
|
||||
if ((fd = open(filename, O_RDWR)) < 0) {
|
||||
fmode = O_RDWR;
|
||||
if (mode & SND_CTL_NONBLOCK)
|
||||
fmode |= O_NONBLOCK;
|
||||
if (mode & SND_CTL_ASYNC)
|
||||
fmode |= O_ASYNC;
|
||||
if ((fd = open(filename, fmode)) < 0) {
|
||||
snd_card_load(card);
|
||||
if ((fd = open(filename, O_RDWR)) < 0)
|
||||
return -errno;
|
||||
|
|
@ -335,6 +341,6 @@ int _snd_ctl_hw_open(snd_ctl_t **handlep, char *name, snd_config_t *conf)
|
|||
}
|
||||
if (card < 0)
|
||||
return -EINVAL;
|
||||
return snd_ctl_hw_open(handlep, name, card);
|
||||
return snd_ctl_hw_open(handlep, name, card, 0);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -51,6 +51,8 @@ struct _snd_ctl {
|
|||
snd_ctl_ops_t *ops;
|
||||
void *private_data;
|
||||
int nonblock;
|
||||
int async_sig;
|
||||
pid_t async_pid;
|
||||
};
|
||||
|
||||
struct _snd_hctl_elem {
|
||||
|
|
@ -77,5 +79,5 @@ struct _snd_hctl {
|
|||
|
||||
|
||||
int _snd_ctl_poll_descriptor(snd_ctl_t *ctl);
|
||||
int snd_ctl_hw_open(snd_ctl_t **handle, const char *name, int card);
|
||||
int snd_ctl_shm_open(snd_ctl_t **handlep, const char *name, const char *socket, const char *sname);
|
||||
int snd_ctl_hw_open(snd_ctl_t **handle, const char *name, int card, int mode);
|
||||
int snd_ctl_shm_open(snd_ctl_t **handlep, const char *name, const char *socket, const char *sname, int mode);
|
||||
|
|
|
|||
|
|
@ -402,7 +402,7 @@ static int make_inet_socket(const char *host, int port)
|
|||
}
|
||||
#endif
|
||||
|
||||
int snd_ctl_shm_open(snd_ctl_t **handlep, const char *name, const char *socket, const char *sname)
|
||||
int snd_ctl_shm_open(snd_ctl_t **handlep, const char *name, const char *socket, const char *sname, int mode)
|
||||
{
|
||||
snd_ctl_t *ctl;
|
||||
snd_ctl_shm_t *shm = NULL;
|
||||
|
|
@ -430,7 +430,7 @@ int snd_ctl_shm_open(snd_ctl_t **handlep, const char *name, const char *socket,
|
|||
req->dev_type = SND_DEV_TYPE_CONTROL;
|
||||
req->transport_type = SND_TRANSPORT_TYPE_SHM;
|
||||
req->stream = 0;
|
||||
req->mode = 0;
|
||||
req->mode = mode;
|
||||
req->namelen = snamelen;
|
||||
err = write(sock, req, reqlen);
|
||||
if (err < 0) {
|
||||
|
|
@ -498,7 +498,7 @@ int snd_ctl_shm_open(snd_ctl_t **handlep, const char *name, const char *socket,
|
|||
|
||||
extern int is_local(struct hostent *hent);
|
||||
|
||||
int _snd_ctl_shm_open(snd_ctl_t **handlep, char *name, snd_config_t *conf)
|
||||
int _snd_ctl_shm_open(snd_ctl_t **handlep, char *name, snd_config_t *conf, int mode)
|
||||
{
|
||||
snd_config_iterator_t i, next;
|
||||
const char *server = NULL;
|
||||
|
|
@ -604,6 +604,6 @@ int _snd_ctl_shm_open(snd_ctl_t **handlep, char *name, snd_config_t *conf)
|
|||
SNDERR("%s is not the local host", host);
|
||||
return -EINVAL;
|
||||
}
|
||||
return snd_ctl_shm_open(handlep, name, socket, sname);
|
||||
return snd_ctl_shm_open(handlep, name, socket, sname, mode);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ int snd_defaults_pcm_device(void)
|
|||
if (result >= 0)
|
||||
return result;
|
||||
sprintf(id, "hw:%i", snd_defaults_pcm_card());
|
||||
if (snd_ctl_open(&handle, id) < 0)
|
||||
if (snd_ctl_open(&handle, id, 0) < 0)
|
||||
return -ENOENT;
|
||||
result = -1;
|
||||
if (snd_ctl_pcm_next_device(handle, &result) < 0) {
|
||||
|
|
@ -120,7 +120,7 @@ int snd_defaults_rawmidi_device(void)
|
|||
if (result >= 0)
|
||||
return result;
|
||||
sprintf(id, "hw:%i", snd_defaults_rawmidi_card());
|
||||
if (snd_ctl_open(&handle, id) < 0)
|
||||
if (snd_ctl_open(&handle, id, 0) < 0)
|
||||
return -ENOENT;
|
||||
result = -1;
|
||||
if (snd_ctl_rawmidi_next_device(handle, &result) < 0) {
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
static int snd_hctl_compare_default(const snd_hctl_elem_t *c1,
|
||||
const snd_hctl_elem_t *c2);
|
||||
|
||||
int snd_hctl_open(snd_hctl_t **hctlp, const char *name)
|
||||
int snd_hctl_open(snd_hctl_t **hctlp, const char *name, int mode)
|
||||
{
|
||||
snd_hctl_t *hctl;
|
||||
snd_ctl_t *ctl;
|
||||
|
|
@ -42,7 +42,7 @@ int snd_hctl_open(snd_hctl_t **hctlp, const char *name)
|
|||
|
||||
assert(hctlp);
|
||||
*hctlp = NULL;
|
||||
if ((err = snd_ctl_open(&ctl, name)) < 0)
|
||||
if ((err = snd_ctl_open(&ctl, name, mode)) < 0)
|
||||
return err;
|
||||
if ((hctl = (snd_hctl_t *)calloc(1, sizeof(snd_hctl_t))) == NULL) {
|
||||
snd_ctl_close(ctl);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue