• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * \file include/control.h
3  * \brief Application interface library for the ALSA driver
4  * \author Jaroslav Kysela <perex@perex.cz>
5  * \author Abramo Bagnara <abramo@alsa-project.org>
6  * \author Takashi Iwai <tiwai@suse.de>
7  * \date 1998-2001
8  *
9  * Application interface library for the ALSA driver
10  */
11 /*
12  *   This library is free software; you can redistribute it and/or modify
13  *   it under the terms of the GNU Lesser General Public License as
14  *   published by the Free Software Foundation; either version 2.1 of
15  *   the License, or (at your option) any later version.
16  *
17  *   This program is distributed in the hope that it will be useful,
18  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
19  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  *   GNU Lesser General Public License for more details.
21  *
22  *   You should have received a copy of the GNU Lesser General Public
23  *   License along with this library; if not, write to the Free Software
24  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
25  *
26  */
27 
28 #ifndef __ALSA_CONTROL_H
29 #define __ALSA_CONTROL_H
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34 
35 /**
36  *  \defgroup Control Control Interface
37  *  The control interface.
38  *  See \ref control page for more details.
39  *  \{
40  */
41 
42 /** dlsym version for interface entry callback */
43 #define SND_CONTROL_DLSYM_VERSION	_dlsym_control_001
44 
45 /** IEC958 structure */
46 typedef struct snd_aes_iec958 {
47 	unsigned char status[24];	/**< AES/IEC958 channel status bits */
48 	unsigned char subcode[147];	/**< AES/IEC958 subcode bits */
49 	unsigned char pad;		/**< nothing */
50 	unsigned char dig_subframe[4];	/**< AES/IEC958 subframe bits */
51 } snd_aes_iec958_t;
52 
53 /** \brief CTL card info container.
54  *
55  * This type contains meta information about a sound card, such as the index,
56  * name, longname, etc.
57  *
58  * \par Memory management
59  *
60  * Before using a snd_ctl_card_info_t object, it must be allocated using
61  * snd_ctl_card_info_alloca() or snd_ctl_card_info_malloc(). When using the
62  * latter, it must be freed again using snd_ctl_card_info_free().
63  *
64  * A card info object can be zeroed out using snd_ctl_card_info_clear().
65  *
66  * A card info object can be copied to another one using
67  * snd_ctl_card_info_copy().
68  *
69  * \par Obtaining the Information
70  *
71  * To obtain the card information, it must first be opened using
72  * snd_ctl_open(), and a snd_ctl_card_info_t container must be
73  * allocated. Then, the information can be read using
74  * snd_ctl_card_info_get_card().
75  *
76  * Thereafter, the card properties can be read using the
77  * snd_ctl_card_info_get_*() functions.
78  */
79 typedef struct _snd_ctl_card_info snd_ctl_card_info_t;
80 
81 /** CTL element identifier container */
82 typedef struct _snd_ctl_elem_id snd_ctl_elem_id_t;
83 
84 /** CTL element list container
85  *
86  * This is a list of CTL elements. The list contains management
87  * information (e.g. how many elements the sound card has) as well as
88  * the element identifiers. All functions which operate on the list
89  * are named snd_ctl_elem_list_*().
90  *
91  * \par Memory management
92  *
93  * There are two memory areas to deal with: The list container itself
94  * and the memory for the element identifiers.
95  *
96  * To manage the area for the list container, the following functions
97  * are used:
98  *
99  * - snd_ctl_elem_list_malloc() / snd_ctl_elem_list_free() to allocate
100  *   and free memory on the heap, or
101  * - snd_ctl_elem_list_alloca() to allocate the memory on the
102  *   stack. This memory is auto-released when the stack is unwound.
103  *
104  * To manage the space for the element identifiers, the
105  * snd_ctl_elem_list_alloc_space() and snd_ctl_elem_list_free_space()
106  * are used. Allocating the right amount of space can be achieved by
107  * first obtaining the number of elements and then calling
108  * snd_ctl_elem_list_alloc_space():
109  *
110  * \code
111  *   snd_ctl_elem_list_t* list;
112  *   int count;
113  *
114  *   // Initialise list
115  *   snd_ctl_elem_list_malloc(&list);
116  *
117  *   // Get number of elements
118  *   snd_ctl_elem_list(ctl, list);
119  *   count = snd_ctl_elem_list_get_count(list);
120  *
121  *   // Allocate space for identifiers
122  *   snd_ctl_elem_list_alloc_space(list, count);
123  *
124  *   // Get identifiers
125  *   snd_ctl_elem_list(ctl, list); // yes, this is same as above :)
126  *
127  *   // Do something useful with the list...
128  *
129  *   // Cleanup
130  *   snd_ctl_elem_list_free_space(list);
131  *   snd_ctl_elem_list_free(list);
132  * \endcode
133  *
134  *
135  * \par The Elements
136  *
137  * The elements in the list are accessed using an index. This index is
138  * the location in the list; Don't confuse it with the 'index' of the
139  * element identifier. For example:
140  *
141  * \code
142  *     snd_ctl_elem_list_t list;
143  *     unsigned int element_index;
144  *
145  *     // Allocate space, fill list ...
146  *
147  *     element_index = snd_ctl_elem_list_get_index(&list, 2);
148  * \endcode
149  *
150  * This will access the 3rd element in the list (index=2) and get the
151  * elements index from the driver (which might be 13, for example).
152  */
153 typedef struct _snd_ctl_elem_list snd_ctl_elem_list_t;
154 
155 /** CTL element info container */
156 typedef struct _snd_ctl_elem_info snd_ctl_elem_info_t;
157 
158 /** CTL element value container.
159  *
160  * Contains the value(s) (i.e. members) of a single element. All
161  * values of a given element are of the same type.
162  *
163  * \par Memory management
164  *
165  * To access a value, a snd_ctl_elem_value_t must be allocated using
166  * snd_ctl_elem_value_alloca() or snd_ctl_elem_value_malloc(). When
167  * using the latter, it must be freed again using
168  * snd_ctl_elem_value_free().
169  *
170  * A value object can be zeroed out using snd_ctl_elem_value_clear().
171  *
172  * A value object can be copied to another one using
173  * snd_ctl_elem_value_copy().
174  *
175  * \par Identifier
176  *
177  * Then, the ID must be filled. It is sufficient to fill only the
178  * numid, if known. Otherwise, interface type, device, subdevice,
179  * name, index must all be given.  The following functions can be used
180  * to fill the ID:
181  *
182  * - snd_ctl_elem_value_set_id(): Set the ID. Requires an
183  *   snd_ctl_elem_id_t object.
184  * - snd_ctl_elem_value_set_numid(): Set the numid.
185  * - Or use all of the following:
186  *
187  *   - snd_ctl_elem_value_set_interface()
188  *   - snd_ctl_elem_value_set_device()
189  *   - snd_ctl_elem_value_set_subdevice()
190  *   - snd_ctl_elem_value_set_name()
191  *   - snd_ctl_elem_value_set_index()
192  *
193  * When communicating with the driver (snd_ctl_elem_read(),
194  * snd_ctl_elem_write()), and the numid was given, the interface,
195  * device, ... are filled (even if you set the before). When the numid
196  * is unset (i.e. it is 0), it is filled.
197  *
198  * \par Communicating with the driver
199  *
200  * After the value container was created and filled with the ID of the
201  * desired element, the value(s) can be fetched from the driver (and
202  * thus from the hardware) or written to the driver.
203  *
204  * To fetch a value, use snd_ctl_elem_read(). Thereafter, use the
205  * snd_ctl_elem_value_get_*() functions to obtain the actual value.
206  *
207  * To write a new value, first use a snd_ctl_elem_value_set_*() to set
208  * it, then call snd_ctl_elem_write() to write it to the driver.
209  */
210 typedef struct _snd_ctl_elem_value snd_ctl_elem_value_t;
211 
212 /** CTL event container */
213 typedef struct _snd_ctl_event snd_ctl_event_t;
214 
215 /** CTL element type */
216 typedef enum _snd_ctl_elem_type {
217 	/** Invalid type */
218 	SND_CTL_ELEM_TYPE_NONE = 0,
219 	/** Boolean contents */
220 	SND_CTL_ELEM_TYPE_BOOLEAN,
221 	/** Integer contents */
222 	SND_CTL_ELEM_TYPE_INTEGER,
223 	/** Enumerated contents */
224 	SND_CTL_ELEM_TYPE_ENUMERATED,
225 	/** Bytes contents */
226 	SND_CTL_ELEM_TYPE_BYTES,
227 	/** IEC958 (S/PDIF) setting content */
228 	SND_CTL_ELEM_TYPE_IEC958,
229 	/** 64-bit integer contents */
230 	SND_CTL_ELEM_TYPE_INTEGER64,
231 	SND_CTL_ELEM_TYPE_LAST = SND_CTL_ELEM_TYPE_INTEGER64
232 } snd_ctl_elem_type_t;
233 
234 /** CTL related interface */
235 typedef enum _snd_ctl_elem_iface {
236 	/** Card level */
237 	SND_CTL_ELEM_IFACE_CARD = 0,
238 	/** Hardware dependent device */
239 	SND_CTL_ELEM_IFACE_HWDEP,
240 	/** Mixer */
241 	SND_CTL_ELEM_IFACE_MIXER,
242 	/** PCM */
243 	SND_CTL_ELEM_IFACE_PCM,
244 	/** RawMidi */
245 	SND_CTL_ELEM_IFACE_RAWMIDI,
246 	/** Timer */
247 	SND_CTL_ELEM_IFACE_TIMER,
248 	/** Sequencer */
249 	SND_CTL_ELEM_IFACE_SEQUENCER,
250 	SND_CTL_ELEM_IFACE_LAST = SND_CTL_ELEM_IFACE_SEQUENCER
251 } snd_ctl_elem_iface_t;
252 
253 /** Event class */
254 typedef enum _snd_ctl_event_type {
255 	/** Elements related event */
256 	SND_CTL_EVENT_ELEM = 0,
257 	SND_CTL_EVENT_LAST = SND_CTL_EVENT_ELEM
258 }snd_ctl_event_type_t;
259 
260 /** Element has been removed (Warning: test this first and if set don't
261   * test the other masks) \hideinitializer */
262 #define SND_CTL_EVENT_MASK_REMOVE 	(~0U)
263 /** Element value has been changed \hideinitializer */
264 #define SND_CTL_EVENT_MASK_VALUE	(1<<0)
265 /** Element info has been changed \hideinitializer */
266 #define SND_CTL_EVENT_MASK_INFO		(1<<1)
267 /** Element has been added \hideinitializer */
268 #define SND_CTL_EVENT_MASK_ADD		(1<<2)
269 /** Element's TLV value has been changed \hideinitializer */
270 #define SND_CTL_EVENT_MASK_TLV		(1<<3)
271 
272 /** CTL name helper */
273 #define SND_CTL_NAME_NONE				""
274 /** CTL name helper */
275 #define SND_CTL_NAME_PLAYBACK				"Playback "
276 /** CTL name helper */
277 #define SND_CTL_NAME_CAPTURE				"Capture "
278 
279 /** CTL name helper */
280 #define SND_CTL_NAME_IEC958_NONE			""
281 /** CTL name helper */
282 #define SND_CTL_NAME_IEC958_SWITCH			"Switch"
283 /** CTL name helper */
284 #define SND_CTL_NAME_IEC958_VOLUME			"Volume"
285 /** CTL name helper */
286 #define SND_CTL_NAME_IEC958_DEFAULT			"Default"
287 /** CTL name helper */
288 #define SND_CTL_NAME_IEC958_MASK			"Mask"
289 /** CTL name helper */
290 #define SND_CTL_NAME_IEC958_CON_MASK			"Con Mask"
291 /** CTL name helper */
292 #define SND_CTL_NAME_IEC958_PRO_MASK			"Pro Mask"
293 /** CTL name helper */
294 #define SND_CTL_NAME_IEC958_PCM_STREAM			"PCM Stream"
295 /** Element name for IEC958 (S/PDIF) */
296 #define SND_CTL_NAME_IEC958(expl,direction,what)	"IEC958 " expl SND_CTL_NAME_##direction SND_CTL_NAME_IEC958_##what
297 
298 /** Mask for the major Power State identifier */
299 #define SND_CTL_POWER_MASK		0xff00
300 /** ACPI/PCI Power State D0 */
301 #define SND_CTL_POWER_D0          	0x0000
302 /** ACPI/PCI Power State D1 */
303 #define SND_CTL_POWER_D1     	     	0x0100
304 /** ACPI/PCI Power State D2 */
305 #define SND_CTL_POWER_D2 	        0x0200
306 /** ACPI/PCI Power State D3 */
307 #define SND_CTL_POWER_D3         	0x0300
308 /** ACPI/PCI Power State D3hot */
309 #define SND_CTL_POWER_D3hot		(SND_CTL_POWER_D3|0x0000)
310 /** ACPI/PCI Power State D3cold */
311 #define SND_CTL_POWER_D3cold	      	(SND_CTL_POWER_D3|0x0001)
312 
313 /** TLV type - Container */
314 #define SND_CTL_TLVT_CONTAINER		0x0000
315 /** TLV type - basic dB scale */
316 #define SND_CTL_TLVT_DB_SCALE		0x0001
317 /** TLV type - linear volume */
318 #define SND_CTL_TLVT_DB_LINEAR		0x0002
319 /** TLV type - dB range container */
320 #define SND_CTL_TLVT_DB_RANGE		0x0003
321 /** TLV type - dB scale specified by min/max values */
322 #define SND_CTL_TLVT_DB_MINMAX		0x0004
323 /** TLV type - dB scale specified by min/max values (with mute) */
324 #define SND_CTL_TLVT_DB_MINMAX_MUTE	0x0005
325 
326 /** Mute state */
327 #define SND_CTL_TLV_DB_GAIN_MUTE	-9999999
328 
329 /** TLV type - fixed channel map positions */
330 #define SND_CTL_TLVT_CHMAP_FIXED	0x00101
331 /** TLV type - freely swappable channel map positions */
332 #define SND_CTL_TLVT_CHMAP_VAR		0x00102
333 /** TLV type - pair-wise swappable channel map positions */
334 #define SND_CTL_TLVT_CHMAP_PAIRED	0x00103
335 
336 /** CTL type */
337 typedef enum _snd_ctl_type {
338 	/** Kernel level CTL */
339 	SND_CTL_TYPE_HW,
340 	/** Shared memory client CTL */
341 	SND_CTL_TYPE_SHM,
342 	/** INET client CTL (not yet implemented) */
343 	SND_CTL_TYPE_INET,
344 	/** External control plugin */
345 	SND_CTL_TYPE_EXT,
346 	/** Control functionality remapping */
347 	SND_CTL_TYPE_REMAP,
348 } snd_ctl_type_t;
349 
350 /** Non blocking mode (flag for open mode) \hideinitializer */
351 #define SND_CTL_NONBLOCK		0x0001
352 
353 /** Async notification (flag for open mode) \hideinitializer */
354 #define SND_CTL_ASYNC			0x0002
355 
356 /** Read only (flag for open mode) \hideinitializer */
357 #define SND_CTL_READONLY		0x0004
358 
359 /** CTL handle */
360 typedef struct _snd_ctl snd_ctl_t;
361 
362 /** Don't destroy the ctl handle when close */
363 #define SND_SCTL_NOFREE			0x0001
364 
365 /** SCTL type */
366 typedef struct _snd_sctl snd_sctl_t;
367 
368 int snd_card_load(int card);
369 int snd_card_next(int *card);
370 int snd_card_get_index(const char *name);
371 int snd_card_get_name(int card, char **name);
372 int snd_card_get_longname(int card, char **name);
373 
374 int snd_device_name_hint(int card, const char *iface, void ***hints);
375 int snd_device_name_free_hint(void **hints);
376 char *snd_device_name_get_hint(const void *hint, const char *id);
377 
378 int snd_ctl_open(snd_ctl_t **ctl, const char *name, int mode);
379 int snd_ctl_open_lconf(snd_ctl_t **ctl, const char *name, int mode, snd_config_t *lconf);
380 int snd_ctl_open_fallback(snd_ctl_t **ctl, snd_config_t *root, const char *name, const char *orig_name, int mode);
381 int snd_ctl_close(snd_ctl_t *ctl);
382 int snd_ctl_nonblock(snd_ctl_t *ctl, int nonblock);
snd_ctl_abort(snd_ctl_t * ctl)383 static __inline__ int snd_ctl_abort(snd_ctl_t *ctl) { return snd_ctl_nonblock(ctl, 2); }
384 int snd_async_add_ctl_handler(snd_async_handler_t **handler, snd_ctl_t *ctl,
385 			      snd_async_callback_t callback, void *private_data);
386 snd_ctl_t *snd_async_handler_get_ctl(snd_async_handler_t *handler);
387 int snd_ctl_poll_descriptors_count(snd_ctl_t *ctl);
388 int snd_ctl_poll_descriptors(snd_ctl_t *ctl, struct pollfd *pfds, unsigned int space);
389 int snd_ctl_poll_descriptors_revents(snd_ctl_t *ctl, struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
390 int snd_ctl_subscribe_events(snd_ctl_t *ctl, int subscribe);
391 int snd_ctl_card_info(snd_ctl_t *ctl, snd_ctl_card_info_t *info);
392 int snd_ctl_elem_list(snd_ctl_t *ctl, snd_ctl_elem_list_t *list);
393 int snd_ctl_elem_info(snd_ctl_t *ctl, snd_ctl_elem_info_t *info);
394 int snd_ctl_elem_read(snd_ctl_t *ctl, snd_ctl_elem_value_t *data);
395 int snd_ctl_elem_write(snd_ctl_t *ctl, snd_ctl_elem_value_t *data);
396 int snd_ctl_elem_lock(snd_ctl_t *ctl, snd_ctl_elem_id_t *id);
397 int snd_ctl_elem_unlock(snd_ctl_t *ctl, snd_ctl_elem_id_t *id);
398 int snd_ctl_elem_tlv_read(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
399 			  unsigned int *tlv, unsigned int tlv_size);
400 int snd_ctl_elem_tlv_write(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
401 			   const unsigned int *tlv);
402 int snd_ctl_elem_tlv_command(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
403 			     const unsigned int *tlv);
404 #ifdef __ALSA_HWDEP_H
405 int snd_ctl_hwdep_next_device(snd_ctl_t *ctl, int * device);
406 int snd_ctl_hwdep_info(snd_ctl_t *ctl, snd_hwdep_info_t * info);
407 #endif
408 #ifdef __ALSA_PCM_H
409 int snd_ctl_pcm_next_device(snd_ctl_t *ctl, int *device);
410 int snd_ctl_pcm_info(snd_ctl_t *ctl, snd_pcm_info_t * info);
411 int snd_ctl_pcm_prefer_subdevice(snd_ctl_t *ctl, int subdev);
412 #endif
413 #ifdef __ALSA_RAWMIDI_H
414 int snd_ctl_rawmidi_next_device(snd_ctl_t *ctl, int * device);
415 int snd_ctl_rawmidi_info(snd_ctl_t *ctl, snd_rawmidi_info_t * info);
416 int snd_ctl_rawmidi_prefer_subdevice(snd_ctl_t *ctl, int subdev);
417 #endif
418 int snd_ctl_set_power_state(snd_ctl_t *ctl, unsigned int state);
419 int snd_ctl_get_power_state(snd_ctl_t *ctl, unsigned int *state);
420 
421 int snd_ctl_read(snd_ctl_t *ctl, snd_ctl_event_t *event);
422 int snd_ctl_wait(snd_ctl_t *ctl, int timeout);
423 const char *snd_ctl_name(snd_ctl_t *ctl);
424 snd_ctl_type_t snd_ctl_type(snd_ctl_t *ctl);
425 
426 const char *snd_ctl_elem_type_name(snd_ctl_elem_type_t type);
427 const char *snd_ctl_elem_iface_name(snd_ctl_elem_iface_t iface);
428 const char *snd_ctl_event_type_name(snd_ctl_event_type_t type);
429 
430 unsigned int snd_ctl_event_elem_get_mask(const snd_ctl_event_t *obj);
431 unsigned int snd_ctl_event_elem_get_numid(const snd_ctl_event_t *obj);
432 void snd_ctl_event_elem_get_id(const snd_ctl_event_t *obj, snd_ctl_elem_id_t *ptr);
433 snd_ctl_elem_iface_t snd_ctl_event_elem_get_interface(const snd_ctl_event_t *obj);
434 unsigned int snd_ctl_event_elem_get_device(const snd_ctl_event_t *obj);
435 unsigned int snd_ctl_event_elem_get_subdevice(const snd_ctl_event_t *obj);
436 const char *snd_ctl_event_elem_get_name(const snd_ctl_event_t *obj);
437 unsigned int snd_ctl_event_elem_get_index(const snd_ctl_event_t *obj);
438 
439 int snd_ctl_elem_list_alloc_space(snd_ctl_elem_list_t *obj, unsigned int entries);
440 void snd_ctl_elem_list_free_space(snd_ctl_elem_list_t *obj);
441 
442 char *snd_ctl_ascii_elem_id_get(snd_ctl_elem_id_t *id);
443 int snd_ctl_ascii_elem_id_parse(snd_ctl_elem_id_t *dst, const char *str);
444 int snd_ctl_ascii_value_parse(snd_ctl_t *handle,
445 			      snd_ctl_elem_value_t *dst,
446 			      snd_ctl_elem_info_t *info,
447 			      const char *value);
448 
449 size_t snd_ctl_elem_id_sizeof(void);
450 /** \hideinitializer
451  * \brief allocate an invalid #snd_ctl_elem_id_t using standard alloca
452  * \param ptr returned pointer
453  */
454 #define snd_ctl_elem_id_alloca(ptr) __snd_alloca(ptr, snd_ctl_elem_id)
455 int snd_ctl_elem_id_malloc(snd_ctl_elem_id_t **ptr);
456 void snd_ctl_elem_id_free(snd_ctl_elem_id_t *obj);
457 void snd_ctl_elem_id_clear(snd_ctl_elem_id_t *obj);
458 void snd_ctl_elem_id_copy(snd_ctl_elem_id_t *dst, const snd_ctl_elem_id_t *src);
459 int snd_ctl_elem_id_compare_numid(const snd_ctl_elem_id_t *id1, const snd_ctl_elem_id_t *id2);
460 int snd_ctl_elem_id_compare_set(const snd_ctl_elem_id_t *id1, const snd_ctl_elem_id_t *id2);
461 unsigned int snd_ctl_elem_id_get_numid(const snd_ctl_elem_id_t *obj);
462 snd_ctl_elem_iface_t snd_ctl_elem_id_get_interface(const snd_ctl_elem_id_t *obj);
463 unsigned int snd_ctl_elem_id_get_device(const snd_ctl_elem_id_t *obj);
464 unsigned int snd_ctl_elem_id_get_subdevice(const snd_ctl_elem_id_t *obj);
465 const char *snd_ctl_elem_id_get_name(const snd_ctl_elem_id_t *obj);
466 unsigned int snd_ctl_elem_id_get_index(const snd_ctl_elem_id_t *obj);
467 void snd_ctl_elem_id_set_numid(snd_ctl_elem_id_t *obj, unsigned int val);
468 void snd_ctl_elem_id_set_interface(snd_ctl_elem_id_t *obj, snd_ctl_elem_iface_t val);
469 void snd_ctl_elem_id_set_device(snd_ctl_elem_id_t *obj, unsigned int val);
470 void snd_ctl_elem_id_set_subdevice(snd_ctl_elem_id_t *obj, unsigned int val);
471 void snd_ctl_elem_id_set_name(snd_ctl_elem_id_t *obj, const char *val);
472 void snd_ctl_elem_id_set_index(snd_ctl_elem_id_t *obj, unsigned int val);
473 
474 size_t snd_ctl_card_info_sizeof(void);
475 
476 /** \hideinitializer
477  * \brief Allocate an invalid #snd_ctl_card_info_t on the stack.
478  *
479  * Allocate space for a card info object on the stack. The allocated
480  * memory need not be freed, because it is on the stack.
481  *
482  * See snd_ctl_card_info_t for details.
483  *
484  * \param ptr Pointer to a snd_ctl_elem_value_t pointer. The address
485  *            of the allocated space will returned here.
486  */
487 #define snd_ctl_card_info_alloca(ptr) __snd_alloca(ptr, snd_ctl_card_info)
488 
489 int snd_ctl_card_info_malloc(snd_ctl_card_info_t **ptr);
490 void snd_ctl_card_info_free(snd_ctl_card_info_t *obj);
491 void snd_ctl_card_info_clear(snd_ctl_card_info_t *obj);
492 void snd_ctl_card_info_copy(snd_ctl_card_info_t *dst, const snd_ctl_card_info_t *src);
493 int snd_ctl_card_info_get_card(const snd_ctl_card_info_t *obj);
494 const char *snd_ctl_card_info_get_id(const snd_ctl_card_info_t *obj);
495 const char *snd_ctl_card_info_get_driver(const snd_ctl_card_info_t *obj);
496 const char *snd_ctl_card_info_get_name(const snd_ctl_card_info_t *obj);
497 const char *snd_ctl_card_info_get_longname(const snd_ctl_card_info_t *obj);
498 const char *snd_ctl_card_info_get_mixername(const snd_ctl_card_info_t *obj);
499 const char *snd_ctl_card_info_get_components(const snd_ctl_card_info_t *obj);
500 
501 size_t snd_ctl_event_sizeof(void);
502 /** \hideinitializer
503  * \brief allocate an invalid #snd_ctl_event_t using standard alloca
504  * \param ptr returned pointer
505  */
506 #define snd_ctl_event_alloca(ptr) __snd_alloca(ptr, snd_ctl_event)
507 int snd_ctl_event_malloc(snd_ctl_event_t **ptr);
508 void snd_ctl_event_free(snd_ctl_event_t *obj);
509 void snd_ctl_event_clear(snd_ctl_event_t *obj);
510 void snd_ctl_event_copy(snd_ctl_event_t *dst, const snd_ctl_event_t *src);
511 snd_ctl_event_type_t snd_ctl_event_get_type(const snd_ctl_event_t *obj);
512 
513 size_t snd_ctl_elem_list_sizeof(void);
514 
515 /** \hideinitializer
516  *
517  * \brief Allocate a #snd_ctl_elem_list_t using standard alloca.
518  *
519  * The memory is allocated on the stack and will automatically be
520  * released when the stack unwinds (i.e. no free() is needed).
521  *
522  * \param ptr Pointer to allocated memory.
523  */
524 #define snd_ctl_elem_list_alloca(ptr) __snd_alloca(ptr, snd_ctl_elem_list)
525 
526 int snd_ctl_elem_list_malloc(snd_ctl_elem_list_t **ptr);
527 void snd_ctl_elem_list_free(snd_ctl_elem_list_t *obj);
528 void snd_ctl_elem_list_clear(snd_ctl_elem_list_t *obj);
529 void snd_ctl_elem_list_copy(snd_ctl_elem_list_t *dst, const snd_ctl_elem_list_t *src);
530 void snd_ctl_elem_list_set_offset(snd_ctl_elem_list_t *obj, unsigned int val);
531 unsigned int snd_ctl_elem_list_get_used(const snd_ctl_elem_list_t *obj);
532 unsigned int snd_ctl_elem_list_get_count(const snd_ctl_elem_list_t *obj);
533 void snd_ctl_elem_list_get_id(const snd_ctl_elem_list_t *obj, unsigned int idx, snd_ctl_elem_id_t *ptr);
534 unsigned int snd_ctl_elem_list_get_numid(const snd_ctl_elem_list_t *obj, unsigned int idx);
535 snd_ctl_elem_iface_t snd_ctl_elem_list_get_interface(const snd_ctl_elem_list_t *obj, unsigned int idx);
536 unsigned int snd_ctl_elem_list_get_device(const snd_ctl_elem_list_t *obj, unsigned int idx);
537 unsigned int snd_ctl_elem_list_get_subdevice(const snd_ctl_elem_list_t *obj, unsigned int idx);
538 const char *snd_ctl_elem_list_get_name(const snd_ctl_elem_list_t *obj, unsigned int idx);
539 unsigned int snd_ctl_elem_list_get_index(const snd_ctl_elem_list_t *obj, unsigned int idx);
540 
541 size_t snd_ctl_elem_info_sizeof(void);
542 /** \hideinitializer
543  * \brief allocate an invalid #snd_ctl_elem_info_t using standard alloca
544  * \param ptr returned pointer
545  */
546 #define snd_ctl_elem_info_alloca(ptr) __snd_alloca(ptr, snd_ctl_elem_info)
547 int snd_ctl_elem_info_malloc(snd_ctl_elem_info_t **ptr);
548 void snd_ctl_elem_info_free(snd_ctl_elem_info_t *obj);
549 void snd_ctl_elem_info_clear(snd_ctl_elem_info_t *obj);
550 void snd_ctl_elem_info_copy(snd_ctl_elem_info_t *dst, const snd_ctl_elem_info_t *src);
551 snd_ctl_elem_type_t snd_ctl_elem_info_get_type(const snd_ctl_elem_info_t *obj);
552 int snd_ctl_elem_info_is_readable(const snd_ctl_elem_info_t *obj);
553 int snd_ctl_elem_info_is_writable(const snd_ctl_elem_info_t *obj);
554 int snd_ctl_elem_info_is_volatile(const snd_ctl_elem_info_t *obj);
555 int snd_ctl_elem_info_is_inactive(const snd_ctl_elem_info_t *obj);
556 int snd_ctl_elem_info_is_locked(const snd_ctl_elem_info_t *obj);
557 int snd_ctl_elem_info_is_tlv_readable(const snd_ctl_elem_info_t *obj);
558 int snd_ctl_elem_info_is_tlv_writable(const snd_ctl_elem_info_t *obj);
559 int snd_ctl_elem_info_is_tlv_commandable(const snd_ctl_elem_info_t *obj);
560 int snd_ctl_elem_info_is_owner(const snd_ctl_elem_info_t *obj);
561 int snd_ctl_elem_info_is_user(const snd_ctl_elem_info_t *obj);
562 pid_t snd_ctl_elem_info_get_owner(const snd_ctl_elem_info_t *obj);
563 unsigned int snd_ctl_elem_info_get_count(const snd_ctl_elem_info_t *obj);
564 long snd_ctl_elem_info_get_min(const snd_ctl_elem_info_t *obj);
565 long snd_ctl_elem_info_get_max(const snd_ctl_elem_info_t *obj);
566 long snd_ctl_elem_info_get_step(const snd_ctl_elem_info_t *obj);
567 long long snd_ctl_elem_info_get_min64(const snd_ctl_elem_info_t *obj);
568 long long snd_ctl_elem_info_get_max64(const snd_ctl_elem_info_t *obj);
569 long long snd_ctl_elem_info_get_step64(const snd_ctl_elem_info_t *obj);
570 unsigned int snd_ctl_elem_info_get_items(const snd_ctl_elem_info_t *obj);
571 void snd_ctl_elem_info_set_item(snd_ctl_elem_info_t *obj, unsigned int val);
572 const char *snd_ctl_elem_info_get_item_name(const snd_ctl_elem_info_t *obj);
573 int snd_ctl_elem_info_get_dimensions(const snd_ctl_elem_info_t *obj);
574 int snd_ctl_elem_info_get_dimension(const snd_ctl_elem_info_t *obj, unsigned int idx);
575 int snd_ctl_elem_info_set_dimension(snd_ctl_elem_info_t *info,
576 				    const int dimension[4]);
577 void snd_ctl_elem_info_get_id(const snd_ctl_elem_info_t *obj, snd_ctl_elem_id_t *ptr);
578 unsigned int snd_ctl_elem_info_get_numid(const snd_ctl_elem_info_t *obj);
579 snd_ctl_elem_iface_t snd_ctl_elem_info_get_interface(const snd_ctl_elem_info_t *obj);
580 unsigned int snd_ctl_elem_info_get_device(const snd_ctl_elem_info_t *obj);
581 unsigned int snd_ctl_elem_info_get_subdevice(const snd_ctl_elem_info_t *obj);
582 const char *snd_ctl_elem_info_get_name(const snd_ctl_elem_info_t *obj);
583 unsigned int snd_ctl_elem_info_get_index(const snd_ctl_elem_info_t *obj);
584 void snd_ctl_elem_info_set_id(snd_ctl_elem_info_t *obj, const snd_ctl_elem_id_t *ptr);
585 void snd_ctl_elem_info_set_numid(snd_ctl_elem_info_t *obj, unsigned int val);
586 void snd_ctl_elem_info_set_interface(snd_ctl_elem_info_t *obj, snd_ctl_elem_iface_t val);
587 void snd_ctl_elem_info_set_device(snd_ctl_elem_info_t *obj, unsigned int val);
588 void snd_ctl_elem_info_set_subdevice(snd_ctl_elem_info_t *obj, unsigned int val);
589 void snd_ctl_elem_info_set_name(snd_ctl_elem_info_t *obj, const char *val);
590 void snd_ctl_elem_info_set_index(snd_ctl_elem_info_t *obj, unsigned int val);
591 void snd_ctl_elem_info_set_read_write(snd_ctl_elem_info_t *obj, int rval, int wval);
592 void snd_ctl_elem_info_set_tlv_read_write(snd_ctl_elem_info_t *obj, int rval, int wval);
593 void snd_ctl_elem_info_set_inactive(snd_ctl_elem_info_t *obj, int val);
594 
595 int snd_ctl_add_integer_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
596 				 unsigned int element_count,
597 				 unsigned int member_count,
598 				 long min, long max, long step);
599 int snd_ctl_add_integer64_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
600 				   unsigned int element_count,
601 				   unsigned int member_count,
602 				   long long min, long long max,
603 				   long long step);
604 int snd_ctl_add_boolean_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
605 				 unsigned int element_count,
606 				 unsigned int member_count);
607 int snd_ctl_add_enumerated_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
608 				    unsigned int element_count,
609 				    unsigned int member_count,
610 				    unsigned int items,
611 				    const char *const labels[]);
612 int snd_ctl_add_bytes_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
613 			       unsigned int element_count,
614 			       unsigned int member_count);
615 
616 int snd_ctl_elem_add_integer(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, unsigned int count, long imin, long imax, long istep);
617 int snd_ctl_elem_add_integer64(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, unsigned int count, long long imin, long long imax, long long istep);
618 int snd_ctl_elem_add_boolean(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, unsigned int count);
619 int snd_ctl_elem_add_enumerated(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, unsigned int count, unsigned int items, const char *const names[]);
620 int snd_ctl_elem_add_iec958(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id);
621 int snd_ctl_elem_remove(snd_ctl_t *ctl, snd_ctl_elem_id_t *id);
622 
623 size_t snd_ctl_elem_value_sizeof(void);
624 
625 /** \hideinitializer
626  * \brief Allocate an invalid #snd_ctl_elem_value_t on the stack.
627  *
628  * Allocate space for a value object on the stack. The allocated
629  * memory need not be freed, because it is on the stack.
630  *
631  * See snd_ctl_elem_value_t for details.
632  *
633  * \param ptr Pointer to a snd_ctl_elem_value_t pointer. The address
634  *            of the allocated space will returned here.
635  */
636 #define snd_ctl_elem_value_alloca(ptr) __snd_alloca(ptr, snd_ctl_elem_value)
637 
638 int snd_ctl_elem_value_malloc(snd_ctl_elem_value_t **ptr);
639 void snd_ctl_elem_value_free(snd_ctl_elem_value_t *obj);
640 void snd_ctl_elem_value_clear(snd_ctl_elem_value_t *obj);
641 void snd_ctl_elem_value_copy(snd_ctl_elem_value_t *dst, const snd_ctl_elem_value_t *src);
642 int snd_ctl_elem_value_compare(snd_ctl_elem_value_t *left, const snd_ctl_elem_value_t *right);
643 void snd_ctl_elem_value_get_id(const snd_ctl_elem_value_t *obj, snd_ctl_elem_id_t *ptr);
644 unsigned int snd_ctl_elem_value_get_numid(const snd_ctl_elem_value_t *obj);
645 snd_ctl_elem_iface_t snd_ctl_elem_value_get_interface(const snd_ctl_elem_value_t *obj);
646 unsigned int snd_ctl_elem_value_get_device(const snd_ctl_elem_value_t *obj);
647 unsigned int snd_ctl_elem_value_get_subdevice(const snd_ctl_elem_value_t *obj);
648 const char *snd_ctl_elem_value_get_name(const snd_ctl_elem_value_t *obj);
649 unsigned int snd_ctl_elem_value_get_index(const snd_ctl_elem_value_t *obj);
650 void snd_ctl_elem_value_set_id(snd_ctl_elem_value_t *obj, const snd_ctl_elem_id_t *ptr);
651 void snd_ctl_elem_value_set_numid(snd_ctl_elem_value_t *obj, unsigned int val);
652 void snd_ctl_elem_value_set_interface(snd_ctl_elem_value_t *obj, snd_ctl_elem_iface_t val);
653 void snd_ctl_elem_value_set_device(snd_ctl_elem_value_t *obj, unsigned int val);
654 void snd_ctl_elem_value_set_subdevice(snd_ctl_elem_value_t *obj, unsigned int val);
655 void snd_ctl_elem_value_set_name(snd_ctl_elem_value_t *obj, const char *val);
656 void snd_ctl_elem_value_set_index(snd_ctl_elem_value_t *obj, unsigned int val);
657 int snd_ctl_elem_value_get_boolean(const snd_ctl_elem_value_t *obj, unsigned int idx);
658 long snd_ctl_elem_value_get_integer(const snd_ctl_elem_value_t *obj, unsigned int idx);
659 long long snd_ctl_elem_value_get_integer64(const snd_ctl_elem_value_t *obj, unsigned int idx);
660 unsigned int snd_ctl_elem_value_get_enumerated(const snd_ctl_elem_value_t *obj, unsigned int idx);
661 unsigned char snd_ctl_elem_value_get_byte(const snd_ctl_elem_value_t *obj, unsigned int idx);
662 void snd_ctl_elem_value_set_boolean(snd_ctl_elem_value_t *obj, unsigned int idx, long val);
663 void snd_ctl_elem_value_set_integer(snd_ctl_elem_value_t *obj, unsigned int idx, long val);
664 void snd_ctl_elem_value_set_integer64(snd_ctl_elem_value_t *obj, unsigned int idx, long long val);
665 void snd_ctl_elem_value_set_enumerated(snd_ctl_elem_value_t *obj, unsigned int idx, unsigned int val);
666 void snd_ctl_elem_value_set_byte(snd_ctl_elem_value_t *obj, unsigned int idx, unsigned char val);
667 void snd_ctl_elem_set_bytes(snd_ctl_elem_value_t *obj, void *data, size_t size);
668 const void * snd_ctl_elem_value_get_bytes(const snd_ctl_elem_value_t *obj);
669 void snd_ctl_elem_value_get_iec958(const snd_ctl_elem_value_t *obj, snd_aes_iec958_t *ptr);
670 void snd_ctl_elem_value_set_iec958(snd_ctl_elem_value_t *obj, const snd_aes_iec958_t *ptr);
671 
672 int snd_tlv_parse_dB_info(unsigned int *tlv, unsigned int tlv_size,
673 			  unsigned int **db_tlvp);
674 int snd_tlv_get_dB_range(unsigned int *tlv, long rangemin, long rangemax,
675 			 long *min, long *max);
676 int snd_tlv_convert_to_dB(unsigned int *tlv, long rangemin, long rangemax,
677 			  long volume, long *db_gain);
678 int snd_tlv_convert_from_dB(unsigned int *tlv, long rangemin, long rangemax,
679 			    long db_gain, long *value, int xdir);
680 int snd_ctl_get_dB_range(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
681 			 long *min, long *max);
682 int snd_ctl_convert_to_dB(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
683 			  long volume, long *db_gain);
684 int snd_ctl_convert_from_dB(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
685 			    long db_gain, long *value, int xdir);
686 
687 /**
688  *  \defgroup HControl High level Control Interface
689  *  \ingroup Control
690  *  The high level control interface.
691  *  See \ref hcontrol page for more details.
692  *  \{
693  */
694 
695 /** HCTL element handle */
696 typedef struct _snd_hctl_elem snd_hctl_elem_t;
697 
698 /** HCTL handle */
699 typedef struct _snd_hctl snd_hctl_t;
700 
701 /**
702  * \brief Compare function for sorting HCTL elements
703  * \param e1 First element
704  * \param e2 Second element
705  * \return -1 if e1 < e2, 0 if e1 == e2, 1 if e1 > e2
706  */
707 typedef int (*snd_hctl_compare_t)(const snd_hctl_elem_t *e1,
708 				  const snd_hctl_elem_t *e2);
709 int snd_hctl_compare_fast(const snd_hctl_elem_t *c1,
710 			  const snd_hctl_elem_t *c2);
711 /**
712  * \brief HCTL callback function
713  * \param hctl HCTL handle
714  * \param mask event mask
715  * \param elem related HCTL element (if any)
716  * \return 0 on success otherwise a negative error code
717  */
718 typedef int (*snd_hctl_callback_t)(snd_hctl_t *hctl,
719 				   unsigned int mask,
720 				   snd_hctl_elem_t *elem);
721 /**
722  * \brief HCTL element callback function
723  * \param elem HCTL element
724  * \param mask event mask
725  * \return 0 on success otherwise a negative error code
726  */
727 typedef int (*snd_hctl_elem_callback_t)(snd_hctl_elem_t *elem,
728 					unsigned int mask);
729 
730 int snd_hctl_open(snd_hctl_t **hctl, const char *name, int mode);
731 int snd_hctl_open_ctl(snd_hctl_t **hctlp, snd_ctl_t *ctl);
732 int snd_hctl_close(snd_hctl_t *hctl);
733 int snd_hctl_nonblock(snd_hctl_t *hctl, int nonblock);
snd_hctl_abort(snd_hctl_t * hctl)734 static __inline__ int snd_hctl_abort(snd_hctl_t *hctl) { return snd_hctl_nonblock(hctl, 2); }
735 int snd_hctl_poll_descriptors_count(snd_hctl_t *hctl);
736 int snd_hctl_poll_descriptors(snd_hctl_t *hctl, struct pollfd *pfds, unsigned int space);
737 int snd_hctl_poll_descriptors_revents(snd_hctl_t *ctl, struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
738 unsigned int snd_hctl_get_count(snd_hctl_t *hctl);
739 int snd_hctl_set_compare(snd_hctl_t *hctl, snd_hctl_compare_t hsort);
740 snd_hctl_elem_t *snd_hctl_first_elem(snd_hctl_t *hctl);
741 snd_hctl_elem_t *snd_hctl_last_elem(snd_hctl_t *hctl);
742 snd_hctl_elem_t *snd_hctl_find_elem(snd_hctl_t *hctl, const snd_ctl_elem_id_t *id);
743 void snd_hctl_set_callback(snd_hctl_t *hctl, snd_hctl_callback_t callback);
744 void snd_hctl_set_callback_private(snd_hctl_t *hctl, void *data);
745 void *snd_hctl_get_callback_private(snd_hctl_t *hctl);
746 int snd_hctl_load(snd_hctl_t *hctl);
747 int snd_hctl_free(snd_hctl_t *hctl);
748 int snd_hctl_handle_events(snd_hctl_t *hctl);
749 const char *snd_hctl_name(snd_hctl_t *hctl);
750 int snd_hctl_wait(snd_hctl_t *hctl, int timeout);
751 snd_ctl_t *snd_hctl_ctl(snd_hctl_t *hctl);
752 
753 snd_hctl_elem_t *snd_hctl_elem_next(snd_hctl_elem_t *elem);
754 snd_hctl_elem_t *snd_hctl_elem_prev(snd_hctl_elem_t *elem);
755 int snd_hctl_elem_info(snd_hctl_elem_t *elem, snd_ctl_elem_info_t * info);
756 int snd_hctl_elem_read(snd_hctl_elem_t *elem, snd_ctl_elem_value_t * value);
757 int snd_hctl_elem_write(snd_hctl_elem_t *elem, snd_ctl_elem_value_t * value);
758 int snd_hctl_elem_tlv_read(snd_hctl_elem_t *elem, unsigned int *tlv, unsigned int tlv_size);
759 int snd_hctl_elem_tlv_write(snd_hctl_elem_t *elem, const unsigned int *tlv);
760 int snd_hctl_elem_tlv_command(snd_hctl_elem_t *elem, const unsigned int *tlv);
761 
762 snd_hctl_t *snd_hctl_elem_get_hctl(snd_hctl_elem_t *elem);
763 
764 void snd_hctl_elem_get_id(const snd_hctl_elem_t *obj, snd_ctl_elem_id_t *ptr);
765 unsigned int snd_hctl_elem_get_numid(const snd_hctl_elem_t *obj);
766 snd_ctl_elem_iface_t snd_hctl_elem_get_interface(const snd_hctl_elem_t *obj);
767 unsigned int snd_hctl_elem_get_device(const snd_hctl_elem_t *obj);
768 unsigned int snd_hctl_elem_get_subdevice(const snd_hctl_elem_t *obj);
769 const char *snd_hctl_elem_get_name(const snd_hctl_elem_t *obj);
770 unsigned int snd_hctl_elem_get_index(const snd_hctl_elem_t *obj);
771 void snd_hctl_elem_set_callback(snd_hctl_elem_t *obj, snd_hctl_elem_callback_t val);
772 void * snd_hctl_elem_get_callback_private(const snd_hctl_elem_t *obj);
773 void snd_hctl_elem_set_callback_private(snd_hctl_elem_t *obj, void * val);
774 
775 /** \} */
776 
777 /** \} */
778 
779 /**
780  *  \defgroup SControl Setup Control Interface
781  *  \ingroup Control
782  *  The setup control interface - set or modify control elements from a configuration file.
783  *  \{
784  */
785 
786 int snd_sctl_build(snd_sctl_t **ctl, snd_ctl_t *handle, snd_config_t *config,
787 		   snd_config_t *private_data, int mode);
788 int snd_sctl_free(snd_sctl_t *handle);
789 int snd_sctl_install(snd_sctl_t *handle);
790 int snd_sctl_remove(snd_sctl_t *handle);
791 
792 /** \} */
793 
794 #ifdef __cplusplus
795 }
796 #endif
797 
798 #endif /* __ALSA_CONTROL_H */
799