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:
Jaroslav Kysela 2005-06-03 13:33:04 +00:00
parent ae07fd40fb
commit 597b4d0942
12 changed files with 2270 additions and 1486 deletions

View file

@ -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

View file

@ -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
View 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 */