mirror of
https://gitee.com/openharmony/third_party_alsa-lib
synced 2024-11-23 07:30:32 +00:00
big simple mixer update
- exported all necessary functions to create a mixer module outside alsa-lib - separated simple mixer API from the simple mixer implementation (using callbacks as usuall) - src/mixer/simple.c is the core - src/mixer/simple_none.c is the current (no-abstraction) implementation based on control names; note that this module does not depend on internal ALSA structures now - src/mixer/simple_abst.c is the ongoing abstraction which will use external dynamic modules; src/conf/smixer.conf will describe which modules will be used depending on the components from the driver
This commit is contained in:
parent
ae07fd40fb
commit
597b4d0942
@ -6,7 +6,7 @@ alsaincludedir = ${includedir}/alsa
|
||||
alsainclude_HEADERS = asoundlib.h asoundef.h \
|
||||
version.h global.h input.h output.h error.h \
|
||||
conf.h pcm.h pcm_old.h pcm_plugin.h rawmidi.h timer.h \
|
||||
hwdep.h control.h mixer.h \
|
||||
hwdep.h control.h mixer.h mixer_abst.h \
|
||||
seq_event.h seq.h seqmid.h seq_midi_event.h \
|
||||
conv.h instr.h iatomic.h \
|
||||
alisp.h pcm_external.h pcm_ioplug.h pcm_extplug.h
|
||||
|
@ -74,6 +74,18 @@ typedef int (*snd_mixer_elem_callback_t)(snd_mixer_elem_t *elem,
|
||||
typedef int (*snd_mixer_compare_t)(const snd_mixer_elem_t *e1,
|
||||
const snd_mixer_elem_t *e2);
|
||||
|
||||
/**
|
||||
* \brief Event callback for the mixer class
|
||||
* \param class Mixer class
|
||||
* \param mask Event mask (SND_CTL_EVENT_*)
|
||||
* \param helem HCTL element which invoked the event
|
||||
* \param melem Mixer element associated to HCTL element
|
||||
* \return zero if success, otherwise a negative error value
|
||||
*/
|
||||
typedef int (*snd_mixer_event_t)(snd_mixer_class_t *class, unsigned int mask,
|
||||
snd_hctl_elem_t *helem, snd_mixer_elem_t *melem);
|
||||
|
||||
|
||||
/** Mixer element type */
|
||||
typedef enum _snd_mixer_elem_type {
|
||||
/* Simple (legacy) mixer elements */
|
||||
@ -88,6 +100,7 @@ snd_mixer_elem_t *snd_mixer_last_elem(snd_mixer_t *mixer);
|
||||
int snd_mixer_handle_events(snd_mixer_t *mixer);
|
||||
int snd_mixer_attach(snd_mixer_t *mixer, const char *name);
|
||||
int snd_mixer_detach(snd_mixer_t *mixer, const char *name);
|
||||
int snd_mixer_get_hctl(snd_mixer_t *mixer, const char *name, snd_hctl_t **hctl);
|
||||
int snd_mixer_poll_descriptors_count(snd_mixer_t *mixer);
|
||||
int snd_mixer_poll_descriptors(snd_mixer_t *mixer, struct pollfd *pfds, unsigned int space);
|
||||
int snd_mixer_poll_descriptors_revents(snd_mixer_t *mixer, struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
|
||||
@ -108,6 +121,41 @@ void * snd_mixer_elem_get_callback_private(const snd_mixer_elem_t *obj);
|
||||
void snd_mixer_elem_set_callback_private(snd_mixer_elem_t *obj, void * val);
|
||||
snd_mixer_elem_type_t snd_mixer_elem_get_type(const snd_mixer_elem_t *obj);
|
||||
|
||||
int snd_mixer_class_register(snd_mixer_class_t *class, snd_mixer_t *mixer);
|
||||
int snd_mixer_add_elem(snd_mixer_t *mixer, snd_mixer_elem_t *elem);
|
||||
int snd_mixer_remove_elem(snd_mixer_t *mixer, snd_mixer_elem_t *elem);
|
||||
int snd_mixer_elem_new(snd_mixer_elem_t **elem,
|
||||
snd_mixer_elem_type_t type,
|
||||
int compare_weight,
|
||||
void *private_data,
|
||||
void (*private_free)(snd_mixer_elem_t *elem));
|
||||
int snd_mixer_elem_add(snd_mixer_elem_t *elem, snd_mixer_class_t *class);
|
||||
int snd_mixer_elem_remove(snd_mixer_elem_t *elem);
|
||||
void snd_mixer_elem_free(snd_mixer_elem_t *elem);
|
||||
int snd_mixer_elem_info(snd_mixer_elem_t *elem);
|
||||
int snd_mixer_elem_value(snd_mixer_elem_t *elem);
|
||||
int snd_mixer_elem_attach(snd_mixer_elem_t *melem, snd_hctl_elem_t *helem);
|
||||
int snd_mixer_elem_detach(snd_mixer_elem_t *melem, snd_hctl_elem_t *helem);
|
||||
int snd_mixer_elem_empty(snd_mixer_elem_t *melem);
|
||||
void *snd_mixer_elem_get_private(const snd_mixer_elem_t *melem);
|
||||
|
||||
size_t snd_mixer_class_sizeof(void);
|
||||
/** \hideinitializer
|
||||
* \brief allocate an invalid #snd_mixer_class_t using standard alloca
|
||||
* \param ptr returned pointer
|
||||
*/
|
||||
#define snd_mixer_class_alloca(ptr) do { assert(ptr); *ptr = (snd_mixer_selem_id_t *) alloca(snd_mixer_class_sizeof()); memset(*ptr, 0, snd_mixer_class_sizeof()); } while (0)
|
||||
int snd_mixer_class_malloc(snd_mixer_class_t **ptr);
|
||||
void snd_mixer_class_free(snd_mixer_class_t *obj);
|
||||
void snd_mixer_class_copy(snd_mixer_class_t *dst, const snd_mixer_class_t *src);
|
||||
snd_mixer_t *snd_mixer_class_get_mixer(const snd_mixer_class_t *class);
|
||||
snd_mixer_event_t snd_mixer_class_get_event(const snd_mixer_class_t *class);
|
||||
void *snd_mixer_class_get_private(const snd_mixer_class_t *class);
|
||||
snd_mixer_compare_t snd_mixer_class_get_compare(const snd_mixer_class_t *class);
|
||||
int snd_mixer_class_set_event(snd_mixer_class_t *class, snd_mixer_event_t event);
|
||||
int snd_mixer_class_set_private(snd_mixer_class_t *class, void *private_data);
|
||||
int snd_mixer_class_set_private_free(snd_mixer_class_t *class, void (*private_free)(snd_mixer_class_t *class));
|
||||
int snd_mixer_class_set_compare(snd_mixer_class_t *class, snd_mixer_compare_t compare);
|
||||
|
||||
/**
|
||||
* \defgroup SimpleMixer Simple Mixer Interface
|
||||
@ -126,14 +174,20 @@ typedef enum _snd_mixer_selem_channel_id {
|
||||
SND_MIXER_SCHN_FRONT_LEFT = 0,
|
||||
/** Front right */
|
||||
SND_MIXER_SCHN_FRONT_RIGHT,
|
||||
/** Front center */
|
||||
SND_MIXER_SCHN_FRONT_CENTER,
|
||||
/** Rear left */
|
||||
SND_MIXER_SCHN_REAR_LEFT,
|
||||
/** Rear right */
|
||||
SND_MIXER_SCHN_REAR_RIGHT,
|
||||
/** Front center */
|
||||
SND_MIXER_SCHN_FRONT_CENTER,
|
||||
/** Woofer */
|
||||
SND_MIXER_SCHN_WOOFER,
|
||||
/** Side Left */
|
||||
SND_MIXER_SCHN_SIDE_LEFT,
|
||||
/** Side Right */
|
||||
SND_MIXER_SCHN_SIDE_RIGHT,
|
||||
/** Rear Center */
|
||||
SND_MIXER_SCHN_REAR_CENTER,
|
||||
SND_MIXER_SCHN_LAST = 31,
|
||||
/** Mono (Front left alias) */
|
||||
SND_MIXER_SCHN_MONO = SND_MIXER_SCHN_FRONT_LEFT
|
||||
@ -153,9 +207,11 @@ struct snd_mixer_selem_regopt {
|
||||
int ver;
|
||||
/** v1: abstract layer selection */
|
||||
enum snd_mixer_selem_regopt_abstract abstract;
|
||||
/** v1: playback PCM connected to mixer device */
|
||||
/** v1: device name (must be NULL when playback_pcm or capture_pcm != NULL) */
|
||||
const char *device;
|
||||
/** v1: playback PCM connected to mixer device (NULL == none) */
|
||||
snd_pcm_t *playback_pcm;
|
||||
/** v1: playback PCM connected to mixer device */
|
||||
/** v1: capture PCM connected to mixer device (NULL == none) */
|
||||
snd_pcm_t *capture_pcm;
|
||||
};
|
||||
|
||||
@ -204,8 +260,8 @@ int snd_mixer_selem_set_playback_dB(snd_mixer_elem_t *elem, snd_mixer_selem_chan
|
||||
int snd_mixer_selem_set_capture_dB(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, long value, int dir);
|
||||
int snd_mixer_selem_set_playback_volume_all(snd_mixer_elem_t *elem, long value);
|
||||
int snd_mixer_selem_set_capture_volume_all(snd_mixer_elem_t *elem, long value);
|
||||
int snd_mixer_selem_set_playback_volume_dB(snd_mixer_elem_t *elem, long value, int dir);
|
||||
int snd_mixer_selem_set_capture_volume_dB(snd_mixer_elem_t *elem, long value, int dir);
|
||||
int snd_mixer_selem_set_playback_dB_all(snd_mixer_elem_t *elem, long value, int dir);
|
||||
int snd_mixer_selem_set_capture_dB_all(snd_mixer_elem_t *elem, long value, int dir);
|
||||
int snd_mixer_selem_set_playback_switch(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, int value);
|
||||
int snd_mixer_selem_set_capture_switch(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, int value);
|
||||
int snd_mixer_selem_set_playback_switch_all(snd_mixer_elem_t *elem, int value);
|
||||
|
100
include/mixer_abst.h
Normal file
100
include/mixer_abst.h
Normal file
@ -0,0 +1,100 @@
|
||||
/**
|
||||
* \file include/mixer_abst.h
|
||||
* \brief Mixer abstract implementation interface library for the ALSA library
|
||||
* \author Jaroslav Kysela <perex@suse.cz>
|
||||
* \date 2005
|
||||
*
|
||||
* Mixer abstact implementation interface library for the ALSA library
|
||||
*/
|
||||
/*
|
||||
* This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __ALSA_MIXER_ABST_H
|
||||
#define __ALSA_MIXER_ABST_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* \defgroup Mixer_Abstract Mixer Abstact Module Interface
|
||||
* The mixer abstact module interface.
|
||||
* \{
|
||||
*/
|
||||
|
||||
#define SM_PLAY 0
|
||||
#define SM_CAPT 1
|
||||
|
||||
#define SM_CAP_GVOLUME (1<<1)
|
||||
#define SM_CAP_GSWITCH (1<<2)
|
||||
#define SM_CAP_PVOLUME (1<<3)
|
||||
#define SM_CAP_PVOLUME_JOIN (1<<4)
|
||||
#define SM_CAP_PSWITCH (1<<5)
|
||||
#define SM_CAP_PSWITCH_JOIN (1<<6)
|
||||
#define SM_CAP_CVOLUME (1<<7)
|
||||
#define SM_CAP_CVOLUME_JOIN (1<<8)
|
||||
#define SM_CAP_CSWITCH (1<<9)
|
||||
#define SM_CAP_CSWITCH_JOIN (1<<10)
|
||||
#define SM_CAP_CSWITCH_EXCL (1<<11)
|
||||
#define SM_CAP_ENUM (1<<12)
|
||||
/* SM_CAP_* 24-31 => private for module use */
|
||||
|
||||
#define SM_OPS_IS_ACTIVE 0
|
||||
#define SM_OPS_IS_MONO 1
|
||||
#define SM_OPS_IS_CHANNEL 2
|
||||
#define SM_OPS_IS_ENUMERATED 3
|
||||
#define SM_OPS_IS_ENUMCNT 4
|
||||
|
||||
#define sm_selem(x) ((sm_selem_t *)((x)->private_data))
|
||||
#define sm_selem_ops(x) ((sm_selem_t *)((x)->private_data))->ops
|
||||
|
||||
typedef struct _sm_selem {
|
||||
snd_mixer_selem_id_t *id;
|
||||
struct sm_elem_ops *ops;
|
||||
unsigned int caps;
|
||||
unsigned int capture_group;
|
||||
} sm_selem_t;
|
||||
|
||||
struct sm_elem_ops {
|
||||
int (*is)(snd_mixer_elem_t *elem, int dir, int cmd, int val);
|
||||
int (*get_range)(snd_mixer_elem_t *elem, int dir, long *min, long *max);
|
||||
int (*set_range)(snd_mixer_elem_t *elem, int dir, long min, long max);
|
||||
int (*get_dB_range)(snd_mixer_elem_t *elem, int dir, long *min, long *max);
|
||||
int (*get_volume)(snd_mixer_elem_t *elem, int dir, snd_mixer_selem_channel_id_t channel, long *value);
|
||||
int (*get_dB)(snd_mixer_elem_t *elem, int dir, snd_mixer_selem_channel_id_t channel, long *value);
|
||||
int (*set_volume)(snd_mixer_elem_t *elem, int dir, snd_mixer_selem_channel_id_t channel, long value);
|
||||
int (*set_dB)(snd_mixer_elem_t *elem, int dir, snd_mixer_selem_channel_id_t channel, long value, int xdir);
|
||||
int (*set_volume_all)(snd_mixer_elem_t *elem, int dir, long value);
|
||||
int (*set_dB_all)(snd_mixer_elem_t *elem, int dir, long value, int xdir);
|
||||
int (*get_switch)(snd_mixer_elem_t *elem, int dir, snd_mixer_selem_channel_id_t channel, int *value);
|
||||
int (*set_switch)(snd_mixer_elem_t *elem, int dir, snd_mixer_selem_channel_id_t channel, int value);
|
||||
int (*set_switch_all)(snd_mixer_elem_t *elem, int dir, int value);
|
||||
int (*enum_item_name)(snd_mixer_elem_t *elem, unsigned int item, size_t maxlen, char *buf);
|
||||
int (*get_enum_item)(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, unsigned int *itemp);
|
||||
int (*set_enum_item)(snd_mixer_elem_t *elem, snd_mixer_selem_channel_id_t channel, unsigned int item);
|
||||
};
|
||||
|
||||
int snd_mixer_selem_compare(const snd_mixer_elem_t *c1, const snd_mixer_elem_t *c2);
|
||||
|
||||
/** \} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __ALSA_MIXER_ABST_H */
|
||||
|
36
src/Versions
36
src/Versions
@ -218,3 +218,39 @@ ALSA_1.0.9 {
|
||||
snd_timer_ginfo_get_clients;
|
||||
|
||||
} ALSA_1.0.8;
|
||||
|
||||
ALSA_1.0.10 {
|
||||
global:
|
||||
|
||||
snd_mixer_get_hctl;
|
||||
snd_mixer_elem_get_private;
|
||||
|
||||
snd_mixer_class_register;
|
||||
snd_mixer_add_elem;
|
||||
snd_mixer_remove_elem;
|
||||
snd_mixer_elem_new;
|
||||
snd_mixer_elem_add;
|
||||
snd_mixer_elem_remove;
|
||||
snd_mixer_elem_free;
|
||||
snd_mixer_elem_info;
|
||||
snd_mixer_elem_value;
|
||||
snd_mixer_elem_attach;
|
||||
snd_mixer_elem_detach;
|
||||
snd_mixer_elem_empty;
|
||||
|
||||
snd_mixer_class_malloc;
|
||||
snd_mixer_class_free;
|
||||
snd_mixer_class_copy;
|
||||
snd_mixer_class_get_mixer;
|
||||
snd_mixer_class_get_event;
|
||||
snd_mixer_class_get_private;
|
||||
snd_mixer_class_get_compare;
|
||||
snd_mixer_class_set_event;
|
||||
snd_mixer_class_set_private;
|
||||
snd_mixer_class_set_private_free;
|
||||
snd_mixer_class_set_compare;
|
||||
|
||||
snd_mixer_selem_set_playback_dB_all;
|
||||
snd_mixer_selem_set_capture_dB_all;
|
||||
|
||||
} ALSA_1.0.9;
|
||||
|
8
src/conf/smixer.conf
Normal file
8
src/conf/smixer.conf
Normal file
@ -0,0 +1,8 @@
|
||||
usb {
|
||||
searchl "USB"
|
||||
lib smixer_usb.so
|
||||
}
|
||||
ac97 {
|
||||
searchl "AC97a:"
|
||||
lib smixer_ac97.so
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
EXTRA_LTLIBRARIES=libmixer.la
|
||||
|
||||
libmixer_la_SOURCES = bag.c mixer.c simple.c
|
||||
libmixer_la_SOURCES = bag.c mixer.c simple.c simple_none.c simple_abst.c
|
||||
|
||||
noinst_HEADERS = mixer_local.h
|
||||
|
||||
|
@ -45,7 +45,6 @@ This is an abstraction layer over the hcontrol layer.
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <pthread.h>
|
||||
#include "mixer_local.h"
|
||||
|
||||
#ifndef DOC_HIDDEN
|
||||
@ -244,6 +243,27 @@ int snd_mixer_detach(snd_mixer_t *mixer, const char *name)
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Obtain a HCTL pointer associated to given name
|
||||
* \param mixer Mixer handle
|
||||
* \param name HCTL previously attached
|
||||
* \param hctl HCTL pointer
|
||||
* \return 0 on success otherwise a negative error code
|
||||
*/
|
||||
int snd_mixer_get_hctl(snd_mixer_t *mixer, const char *name, snd_hctl_t **hctl)
|
||||
{
|
||||
struct list_head *pos;
|
||||
list_for_each(pos, &mixer->slaves) {
|
||||
snd_mixer_slave_t *s;
|
||||
s = list_entry(pos, snd_mixer_slave_t, list);
|
||||
if (strcmp(name, snd_hctl_name(s->hctl)) == 0) {
|
||||
*hctl = s->hctl;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
static int snd_mixer_throw_event(snd_mixer_t *mixer, unsigned int mask,
|
||||
snd_mixer_elem_t *elem)
|
||||
{
|
||||
@ -284,6 +304,47 @@ static int _snd_mixer_find_elem(snd_mixer_t *mixer, snd_mixer_elem_t *elem, int
|
||||
return idx;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Get private data associated to give mixer element
|
||||
* \param elem Mixer element
|
||||
* \return private data
|
||||
*
|
||||
* For use by mixer element class specific code.
|
||||
*/
|
||||
void *snd_mixer_elem_get_private(const snd_mixer_elem_t *elem)
|
||||
{
|
||||
return elem->private_data;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Allocate a new mixer element
|
||||
* \param elem Returned mixer element
|
||||
* \param type Mixer element type
|
||||
* \param compare_weight Mixer element compare weight
|
||||
* \param private_data Private data
|
||||
* \param private_free Private data free callback
|
||||
* \return 0 on success otherwise a negative error code
|
||||
*
|
||||
* For use by mixer element class specific code.
|
||||
*/
|
||||
int snd_mixer_elem_new(snd_mixer_elem_t **elem,
|
||||
snd_mixer_elem_type_t type,
|
||||
int compare_weight,
|
||||
void *private_data,
|
||||
void (*private_free)(snd_mixer_elem_t *elem))
|
||||
{
|
||||
snd_mixer_elem_t *melem = calloc(1, sizeof(*melem));
|
||||
if (melem == NULL)
|
||||
return -ENOMEM;
|
||||
melem->type = type;
|
||||
melem->compare_weight = compare_weight;
|
||||
melem->private_data = private_data;
|
||||
melem->private_free = private_free;
|
||||
INIT_LIST_HEAD(&melem->helems);
|
||||
*elem = melem;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Add an element for a registered mixer element class
|
||||
* \param elem Mixer element
|
||||
@ -353,9 +414,7 @@ int snd_mixer_elem_remove(snd_mixer_elem_t *elem)
|
||||
}
|
||||
err = snd_mixer_elem_throw_event(elem, SND_CTL_EVENT_MASK_REMOVE);
|
||||
list_del(&elem->list);
|
||||
if (elem->private_free)
|
||||
elem->private_free(elem);
|
||||
free(elem);
|
||||
snd_mixer_elem_free(elem);
|
||||
mixer->count--;
|
||||
m = mixer->count - idx;
|
||||
if (m > 0)
|
||||
@ -365,6 +424,20 @@ int snd_mixer_elem_remove(snd_mixer_elem_t *elem)
|
||||
return err;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Free a mixer element
|
||||
* \param elem Mixer element
|
||||
* \return 0 on success otherwise a negative error code
|
||||
*
|
||||
* For use by mixer element class specific code.
|
||||
*/
|
||||
void snd_mixer_elem_free(snd_mixer_elem_t *elem)
|
||||
{
|
||||
if (elem->private_free)
|
||||
elem->private_free(elem);
|
||||
free(elem);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Mixer element informations are changed
|
||||
* \param elem Mixer element
|
||||
@ -521,26 +594,22 @@ static int snd_mixer_compare_default(const snd_mixer_elem_t *c1,
|
||||
return c1->class->compare(c1, c2);
|
||||
}
|
||||
|
||||
static snd_mixer_t *compare_mixer;
|
||||
static int mixer_compare(const void *a, const void *b) {
|
||||
return compare_mixer->compare(*(const snd_mixer_elem_t * const *) a,
|
||||
*(const snd_mixer_elem_t * const *) b);
|
||||
static int mixer_compare(const void *a, const void *b)
|
||||
{
|
||||
snd_mixer_t *mixer;
|
||||
|
||||
mixer = (*((const snd_mixer_elem_t * const *)a))->class->mixer;
|
||||
return mixer->compare(*(const snd_mixer_elem_t * const *)a, *(const snd_mixer_elem_t * const *)b);
|
||||
}
|
||||
|
||||
typedef int (*qsort_func)(const void *, const void *);
|
||||
static int snd_mixer_sort(snd_mixer_t *mixer)
|
||||
{
|
||||
unsigned int k;
|
||||
static pthread_mutex_t sync_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
assert(mixer);
|
||||
assert(mixer->compare);
|
||||
INIT_LIST_HEAD(&mixer->elems);
|
||||
|
||||
pthread_mutex_lock(&sync_lock);
|
||||
compare_mixer = mixer;
|
||||
qsort(mixer->pelems, mixer->count, sizeof(snd_mixer_elem_t*), mixer_compare);
|
||||
pthread_mutex_unlock(&sync_lock);
|
||||
|
||||
qsort(mixer->pelems, mixer->count, sizeof(snd_mixer_elem_t *), mixer_compare);
|
||||
for (k = 0; k < mixer->count; k++)
|
||||
list_add_tail(&mixer->pelems[k]->list, &mixer->elems);
|
||||
return 0;
|
||||
@ -744,8 +813,8 @@ int snd_mixer_handle_events(snd_mixer_t *mixer)
|
||||
|
||||
/**
|
||||
* \brief Set callback function for a mixer
|
||||
* \param obj mixer handle
|
||||
* \param val callback function
|
||||
* \param mixer mixer handle
|
||||
* \param callback callback function
|
||||
*/
|
||||
void snd_mixer_set_callback(snd_mixer_t *obj, snd_mixer_callback_t val)
|
||||
{
|
||||
@ -755,78 +824,217 @@ void snd_mixer_set_callback(snd_mixer_t *obj, snd_mixer_callback_t val)
|
||||
|
||||
/**
|
||||
* \brief Set callback private value for a mixer
|
||||
* \param obj mixer handle
|
||||
* \param val callback private value
|
||||
* \param mixer mixer handle
|
||||
* \param callback_private callback private value
|
||||
*/
|
||||
void snd_mixer_set_callback_private(snd_mixer_t *obj, void * val)
|
||||
void snd_mixer_set_callback_private(snd_mixer_t *mixer, void * val)
|
||||
{
|
||||
assert(obj);
|
||||
obj->callback_private = val;
|
||||
assert(mixer);
|
||||
mixer->callback_private = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Get callback private value for a mixer
|
||||
* \param obj mixer handle
|
||||
* \param mixer mixer handle
|
||||
* \return callback private value
|
||||
*/
|
||||
void * snd_mixer_get_callback_private(const snd_mixer_t *obj)
|
||||
void * snd_mixer_get_callback_private(const snd_mixer_t *mixer)
|
||||
{
|
||||
assert(obj);
|
||||
return obj->callback_private;
|
||||
assert(mixer);
|
||||
return mixer->callback_private;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Get elements count for a mixer
|
||||
* \param obj mixer handle
|
||||
* \param mixer mixer handle
|
||||
* \return elements count
|
||||
*/
|
||||
unsigned int snd_mixer_get_count(const snd_mixer_t *obj)
|
||||
unsigned int snd_mixer_get_count(const snd_mixer_t *mixer)
|
||||
{
|
||||
assert(obj);
|
||||
return obj->count;
|
||||
assert(mixer);
|
||||
return mixer->count;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set callback function for a mixer element
|
||||
* \param obj mixer element
|
||||
* \param mixer mixer element
|
||||
* \param val callback function
|
||||
*/
|
||||
void snd_mixer_elem_set_callback(snd_mixer_elem_t *obj, snd_mixer_elem_callback_t val)
|
||||
void snd_mixer_elem_set_callback(snd_mixer_elem_t *mixer, snd_mixer_elem_callback_t val)
|
||||
{
|
||||
assert(obj);
|
||||
obj->callback = val;
|
||||
assert(mixer);
|
||||
mixer->callback = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set callback private value for a mixer element
|
||||
* \param obj mixer element
|
||||
* \param mixer mixer element
|
||||
* \param val callback private value
|
||||
*/
|
||||
void snd_mixer_elem_set_callback_private(snd_mixer_elem_t *obj, void * val)
|
||||
void snd_mixer_elem_set_callback_private(snd_mixer_elem_t *mixer, void * val)
|
||||
{
|
||||
assert(obj);
|
||||
obj->callback_private = val;
|
||||
assert(mixer);
|
||||
mixer->callback_private = val;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Get callback private value for a mixer element
|
||||
* \param obj mixer element
|
||||
* \param mixer mixer element
|
||||
* \return callback private value
|
||||
*/
|
||||
void * snd_mixer_elem_get_callback_private(const snd_mixer_elem_t *obj)
|
||||
void * snd_mixer_elem_get_callback_private(const snd_mixer_elem_t *mixer)
|
||||
{
|
||||
assert(obj);
|
||||
return obj->callback_private;
|
||||
assert(mixer);
|
||||
return mixer->callback_private;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Get type for a mixer element
|
||||
* \param obj mixer element
|
||||
* \param mixer mixer element
|
||||
* \return mixer element type
|
||||
*/
|
||||
snd_mixer_elem_type_t snd_mixer_elem_get_type(const snd_mixer_elem_t *obj)
|
||||
snd_mixer_elem_type_t snd_mixer_elem_get_type(const snd_mixer_elem_t *mixer)
|
||||
{
|
||||
assert(obj);
|
||||
return obj->type;
|
||||
assert(mixer);
|
||||
return mixer->type;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief get size of #snd_mixer_class_t
|
||||
* \return size in bytes
|
||||
*/
|
||||
size_t snd_mixer_class_sizeof()
|
||||
{
|
||||
return sizeof(snd_mixer_class_t);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief allocate an invalid #snd_mixer_class_t using standard malloc
|
||||
* \param ptr returned pointer
|
||||
* \return 0 on success otherwise negative error code
|
||||
*/
|
||||
int snd_mixer_class_malloc(snd_mixer_class_t **ptr)
|
||||
{
|
||||
assert(ptr);
|
||||
*ptr = calloc(1, sizeof(snd_mixer_class_t));
|
||||
if (!*ptr)
|
||||
return -ENOMEM;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief frees a previously allocated #snd_mixer_class_t
|
||||
* \param pointer to object to free
|
||||
*/
|
||||
void snd_mixer_class_free(snd_mixer_class_t *obj)
|
||||
{
|
||||
free(obj);
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief copy one #snd_mixer_class_t to another
|
||||
* \param dst pointer to destination
|
||||
* \param src pointer to source
|
||||
*/
|
||||
void snd_mixer_class_copy(snd_mixer_class_t *dst, const snd_mixer_class_t *src)
|
||||
{
|
||||
assert(dst && src);
|
||||
*dst = *src;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Get a mixer associated to given mixer class
|
||||
* \param obj Mixer simple class identifier
|
||||
* \return mixer pointer
|
||||
*/
|
||||
snd_mixer_t *snd_mixer_class_get_mixer(const snd_mixer_class_t *obj)
|
||||
{
|
||||
assert(obj);
|
||||
return obj->mixer;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Get mixer event callback associated to given mixer class
|
||||
* \param obj Mixer simple class identifier
|
||||
* \return event callback pointer
|
||||
*/
|
||||
snd_mixer_event_t snd_mixer_class_get_event(const snd_mixer_class_t *obj)
|
||||
{
|
||||
assert(obj);
|
||||
return obj->event;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Get mixer private data associated to given mixer class
|
||||
* \param obj Mixer simple class identifier
|
||||
* \return event callback pointer
|
||||
*/
|
||||
void *snd_mixer_class_get_private(const snd_mixer_class_t *obj)
|
||||
{
|
||||
assert(obj);
|
||||
return obj->private_data;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* \brief Get mixer compare callback associated to given mixer class
|
||||
* \param obj Mixer simple class identifier
|
||||
* \return event callback pointer
|
||||
*/
|
||||
snd_mixer_compare_t snd_mixer_class_get_compare(const snd_mixer_class_t *obj)
|
||||
{
|
||||
assert(obj);
|
||||
return obj->compare;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set mixer event callback to given mixer class
|
||||
* \param obj Mixer simple class identifier
|
||||
* \param event Event callback
|
||||
* \return zero if success, otherwise a negative error code
|
||||
*/
|
||||
int snd_mixer_class_set_event(snd_mixer_class_t *obj, snd_mixer_event_t event)
|
||||
{
|
||||
assert(obj);
|
||||
obj->event = event;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set mixer private data to given mixer class
|
||||
* \param obj Mixer simple class identifier
|
||||
* \param private_data class private data
|
||||
* \return zero if success, otherwise a negative error code
|
||||
*/
|
||||
int snd_mixer_class_set_private(snd_mixer_class_t *obj, void *private_data)
|
||||
{
|
||||
assert(obj);
|
||||
obj->private_data = private_data;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set mixer private data free callback to given mixer class
|
||||
* \param obj Mixer simple class identifier
|
||||
* \param private_free Mixer class private data free callback
|
||||
* \return zero if success, otherwise a negative error code
|
||||
*/
|
||||
int snd_mixer_class_set_private_free(snd_mixer_class_t *obj, void (*private_free)(snd_mixer_class_t *class))
|
||||
{
|
||||
assert(obj);
|
||||
obj->private_free = private_free;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* \brief Set mixer compare callback to given mixer class
|
||||
* \param obj Mixer simple class identifier
|
||||
* \return zero if success, otherwise a negative error code
|
||||
*/
|
||||
int snd_mixer_class_set_compare(snd_mixer_class_t *obj, snd_mixer_compare_t compare)
|
||||
{
|
||||
assert(obj);
|
||||
obj->compare = compare;
|
||||
return 0;
|
||||
}
|
||||
|
@ -42,15 +42,10 @@ typedef struct list_head *bag_iterator_t;
|
||||
#define bag_for_each(pos, bag) list_for_each(pos, bag)
|
||||
#define bag_for_each_safe(pos, next, bag) list_for_each_safe(pos, next, bag)
|
||||
|
||||
#define MIXER_COMPARE_WEIGHT_SIMPLE_BASE 0
|
||||
#define MIXER_COMPARE_WEIGHT_NEXT_BASE 10000000
|
||||
#define MIXER_COMPARE_WEIGHT_NOT_FOUND 1000000000
|
||||
|
||||
struct _snd_mixer_class {
|
||||
struct list_head list;
|
||||
snd_mixer_t *mixer;
|
||||
int (*event)(snd_mixer_class_t *class, unsigned int mask,
|
||||
snd_hctl_elem_t *helem, snd_mixer_elem_t *melem);
|
||||
snd_mixer_event_t event;
|
||||
void *private_data;
|
||||
void (*private_free)(snd_mixer_class_t *class);
|
||||
snd_mixer_compare_t compare;
|
||||
@ -85,16 +80,3 @@ struct _snd_mixer_selem_id {
|
||||
unsigned char name[60];
|
||||
unsigned int index;
|
||||
};
|
||||
|
||||
int snd_mixer_class_register(snd_mixer_class_t *class, snd_mixer_t *mixer);
|
||||
int snd_mixer_add_elem(snd_mixer_t *mixer, snd_mixer_elem_t *elem);
|
||||
int snd_mixer_remove_elem(snd_mixer_t *mixer, snd_mixer_elem_t *elem);
|
||||
int snd_mixer_elem_add(snd_mixer_elem_t *elem, snd_mixer_class_t *class);
|
||||
int snd_mixer_elem_remove(snd_mixer_elem_t *elem);
|
||||
int snd_mixer_elem_info(snd_mixer_elem_t *elem);
|
||||
int snd_mixer_elem_value(snd_mixer_elem_t *elem);
|
||||
int snd_mixer_elem_attach(snd_mixer_elem_t *melem,
|
||||
snd_hctl_elem_t *helem);
|
||||
int snd_mixer_elem_detach(snd_mixer_elem_t *melem,
|
||||
snd_hctl_elem_t *helem);
|
||||
int snd_mixer_elem_empty(snd_mixer_elem_t *melem);
|
||||
|
25
src/mixer/mixer_simple.h
Normal file
25
src/mixer/mixer_simple.h
Normal file
@ -0,0 +1,25 @@
|
||||
/*
|
||||
* Mixer Simple Interface - local header file
|
||||
* Copyright (c) 2005 by Jaroslav Kysela <perex@suse.cz>
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include "mixer_abst.h"
|
||||
|
||||
int snd_mixer_simple_none_register(snd_mixer_t *mixer, struct snd_mixer_selem_regopt *options, snd_mixer_class_t **classp);
|
||||
int snd_mixer_simple_basic_register(snd_mixer_t *mixer, struct snd_mixer_selem_regopt *options, snd_mixer_class_t **classp);
|
1625
src/mixer/simple.c
1625
src/mixer/simple.c
File diff suppressed because it is too large
Load Diff
77
src/mixer/simple_abst.c
Normal file
77
src/mixer/simple_abst.c
Normal file
@ -0,0 +1,77 @@
|
||||
/**
|
||||
* \file mixer/simple_abst.c
|
||||
* \brief Mixer Simple Element Class Interface - Module Abstraction
|
||||
* \author Jaroslav Kysela <perex@suse.cz>
|
||||
* \date 2005
|
||||
*
|
||||
* Mixer simple element class interface.
|
||||
*/
|
||||
/*
|
||||
* Mixer Interface - simple controls - abstraction module
|
||||
* Copyright (c) 2005 by Jaroslav Kysela <perex@suse.cz>
|
||||
*
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as
|
||||
* published by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <math.h>
|
||||
#include "mixer_local.h"
|
||||
#include "mixer_simple.h"
|
||||
|
||||
/**
|
||||
* \brief Register mixer simple element class - basic abstraction
|
||||
* \param mixer Mixer handle
|
||||
* \param options Options container
|
||||
* \param classp Pointer to returned mixer simple element class handle (or NULL
|
||||
* \return 0 on success otherwise a negative error code
|
||||
*/
|
||||
int snd_mixer_simple_basic_register(snd_mixer_t *mixer,
|
||||
struct snd_mixer_selem_regopt *options,
|
||||
snd_mixer_class_t **classp)
|
||||
{
|
||||
snd_mixer_class_t *class = calloc(1, sizeof(*class));
|
||||
const char *file;
|
||||
snd_input_t *input;
|
||||
int err;
|
||||
|
||||
if (snd_mixer_class_malloc(&class))
|
||||
return -ENOMEM;
|
||||
//snd_mixer_class_set_event(class, simple_event);
|
||||
snd_mixer_class_set_compare(class, snd_mixer_selem_compare);
|
||||
file = getenv("ALSA_MIXER_SIMPLE");
|
||||
if (!file)
|
||||
file = DATADIR "/alsa/smixer.conf";
|
||||
if ((err = snd_input_stdio_open(&input, file, "r")) < 0) {
|
||||
SNDERR("unable to open simple mixer configuration file '%s'", file);
|
||||
goto __error;
|
||||
}
|
||||
err = snd_mixer_class_register(class, mixer);
|
||||
if (err < 0) {
|
||||
__error:
|
||||
if (class)
|
||||
snd_mixer_class_free(class);
|
||||
return err;
|
||||
}
|
||||
if (classp)
|
||||
*classp = class;
|
||||
return 0;
|
||||
}
|
1491
src/mixer/simple_none.c
Normal file
1491
src/mixer/simple_none.c
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user