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 /** Return EINTR instead blocking (flag for open mode) \hideinitializer */
360 #define SND_CTL_EINTR			0x0080
361 
362 /** CTL handle */
363 typedef struct _snd_ctl snd_ctl_t;
364 
365 /** Don't destroy the ctl handle when close */
366 #define SND_SCTL_NOFREE			0x0001
367 
368 /** SCTL type */
369 typedef struct _snd_sctl snd_sctl_t;
370 
371 int snd_card_load(int card);
372 int snd_card_next(int *card);
373 int snd_card_get_index(const char *name);
374 int snd_card_get_name(int card, char **name);
375 int snd_card_get_longname(int card, char **name);
376 
377 int snd_ctl_open(snd_ctl_t **ctl, const char *name, int mode);
378 int snd_ctl_open_lconf(snd_ctl_t **ctl, const char *name, int mode, snd_config_t *lconf);
379 int snd_ctl_open_fallback(snd_ctl_t **ctl, snd_config_t *root, const char *name, const char *orig_name, int mode);
380 int snd_ctl_close(snd_ctl_t *ctl);
381 int snd_ctl_nonblock(snd_ctl_t *ctl, int nonblock);
snd_ctl_abort(snd_ctl_t *ctl)382 static __inline__ int snd_ctl_abort(snd_ctl_t *ctl) { return snd_ctl_nonblock(ctl, 2); }
383 int snd_async_add_ctl_handler(snd_async_handler_t **handler, snd_ctl_t *ctl,
384 			      snd_async_callback_t callback, void *private_data);
385 snd_ctl_t *snd_async_handler_get_ctl(snd_async_handler_t *handler);
386 int snd_ctl_poll_descriptors_count(snd_ctl_t *ctl);
387 int snd_ctl_poll_descriptors(snd_ctl_t *ctl, struct pollfd *pfds, unsigned int space);
388 int snd_ctl_poll_descriptors_revents(snd_ctl_t *ctl, struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
389 int snd_ctl_subscribe_events(snd_ctl_t *ctl, int subscribe);
390 int snd_ctl_card_info(snd_ctl_t *ctl, snd_ctl_card_info_t *info);
391 int snd_ctl_elem_list(snd_ctl_t *ctl, snd_ctl_elem_list_t *list);
392 int snd_ctl_elem_info(snd_ctl_t *ctl, snd_ctl_elem_info_t *info);
393 int snd_ctl_elem_read(snd_ctl_t *ctl, snd_ctl_elem_value_t *data);
394 int snd_ctl_elem_write(snd_ctl_t *ctl, snd_ctl_elem_value_t *data);
395 int snd_ctl_elem_lock(snd_ctl_t *ctl, snd_ctl_elem_id_t *id);
396 int snd_ctl_elem_unlock(snd_ctl_t *ctl, snd_ctl_elem_id_t *id);
397 int snd_ctl_elem_tlv_read(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
398 			  unsigned int *tlv, unsigned int tlv_size);
399 int snd_ctl_elem_tlv_write(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
400 			   const unsigned int *tlv);
401 int snd_ctl_elem_tlv_command(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
402 			     const unsigned int *tlv);
403 #ifdef __ALSA_HWDEP_H
404 int snd_ctl_hwdep_next_device(snd_ctl_t *ctl, int * device);
405 int snd_ctl_hwdep_info(snd_ctl_t *ctl, snd_hwdep_info_t * info);
406 #endif
407 #ifdef __ALSA_PCM_H
408 int snd_ctl_pcm_next_device(snd_ctl_t *ctl, int *device);
409 int snd_ctl_pcm_info(snd_ctl_t *ctl, snd_pcm_info_t * info);
410 int snd_ctl_pcm_prefer_subdevice(snd_ctl_t *ctl, int subdev);
411 #endif
412 #ifdef __ALSA_RAWMIDI_H
413 int snd_ctl_rawmidi_next_device(snd_ctl_t *ctl, int * device);
414 int snd_ctl_rawmidi_info(snd_ctl_t *ctl, snd_rawmidi_info_t * info);
415 int snd_ctl_rawmidi_prefer_subdevice(snd_ctl_t *ctl, int subdev);
416 #endif
417 #ifdef __ALSA_UMP_H
418 int snd_ctl_ump_next_device(snd_ctl_t *ctl, int *device);
419 int snd_ctl_ump_endpoint_info(snd_ctl_t *ctl, snd_ump_endpoint_info_t *info);
420 int snd_ctl_ump_block_info(snd_ctl_t *ctl, snd_ump_block_info_t *info);
421 #endif
422 int snd_ctl_set_power_state(snd_ctl_t *ctl, unsigned int state);
423 int snd_ctl_get_power_state(snd_ctl_t *ctl, unsigned int *state);
424 
425 int snd_ctl_read(snd_ctl_t *ctl, snd_ctl_event_t *event);
426 int snd_ctl_wait(snd_ctl_t *ctl, int timeout);
427 const char *snd_ctl_name(snd_ctl_t *ctl);
428 snd_ctl_type_t snd_ctl_type(snd_ctl_t *ctl);
429 
430 const char *snd_ctl_elem_type_name(snd_ctl_elem_type_t type);
431 const char *snd_ctl_elem_iface_name(snd_ctl_elem_iface_t iface);
432 const char *snd_ctl_event_type_name(snd_ctl_event_type_t type);
433 
434 unsigned int snd_ctl_event_elem_get_mask(const snd_ctl_event_t *obj);
435 unsigned int snd_ctl_event_elem_get_numid(const snd_ctl_event_t *obj);
436 void snd_ctl_event_elem_get_id(const snd_ctl_event_t *obj, snd_ctl_elem_id_t *ptr);
437 snd_ctl_elem_iface_t snd_ctl_event_elem_get_interface(const snd_ctl_event_t *obj);
438 unsigned int snd_ctl_event_elem_get_device(const snd_ctl_event_t *obj);
439 unsigned int snd_ctl_event_elem_get_subdevice(const snd_ctl_event_t *obj);
440 const char *snd_ctl_event_elem_get_name(const snd_ctl_event_t *obj);
441 unsigned int snd_ctl_event_elem_get_index(const snd_ctl_event_t *obj);
442 
443 int snd_ctl_elem_list_alloc_space(snd_ctl_elem_list_t *obj, unsigned int entries);
444 void snd_ctl_elem_list_free_space(snd_ctl_elem_list_t *obj);
445 
446 char *snd_ctl_ascii_elem_id_get(snd_ctl_elem_id_t *id);
447 int snd_ctl_ascii_elem_id_parse(snd_ctl_elem_id_t *dst, const char *str);
448 int snd_ctl_ascii_value_parse(snd_ctl_t *handle,
449 			      snd_ctl_elem_value_t *dst,
450 			      snd_ctl_elem_info_t *info,
451 			      const char *value);
452 
453 size_t snd_ctl_elem_id_sizeof(void);
454 /** \hideinitializer
455  * \brief allocate an invalid #snd_ctl_elem_id_t using standard alloca
456  * \param ptr returned pointer
457  */
458 #define snd_ctl_elem_id_alloca(ptr) __snd_alloca(ptr, snd_ctl_elem_id)
459 int snd_ctl_elem_id_malloc(snd_ctl_elem_id_t **ptr);
460 void snd_ctl_elem_id_free(snd_ctl_elem_id_t *obj);
461 void snd_ctl_elem_id_clear(snd_ctl_elem_id_t *obj);
462 void snd_ctl_elem_id_copy(snd_ctl_elem_id_t *dst, const snd_ctl_elem_id_t *src);
463 int snd_ctl_elem_id_compare_numid(const snd_ctl_elem_id_t *id1, const snd_ctl_elem_id_t *id2);
464 int snd_ctl_elem_id_compare_set(const snd_ctl_elem_id_t *id1, const snd_ctl_elem_id_t *id2);
465 unsigned int snd_ctl_elem_id_get_numid(const snd_ctl_elem_id_t *obj);
466 snd_ctl_elem_iface_t snd_ctl_elem_id_get_interface(const snd_ctl_elem_id_t *obj);
467 unsigned int snd_ctl_elem_id_get_device(const snd_ctl_elem_id_t *obj);
468 unsigned int snd_ctl_elem_id_get_subdevice(const snd_ctl_elem_id_t *obj);
469 const char *snd_ctl_elem_id_get_name(const snd_ctl_elem_id_t *obj);
470 unsigned int snd_ctl_elem_id_get_index(const snd_ctl_elem_id_t *obj);
471 void snd_ctl_elem_id_set_numid(snd_ctl_elem_id_t *obj, unsigned int val);
472 void snd_ctl_elem_id_set_interface(snd_ctl_elem_id_t *obj, snd_ctl_elem_iface_t val);
473 void snd_ctl_elem_id_set_device(snd_ctl_elem_id_t *obj, unsigned int val);
474 void snd_ctl_elem_id_set_subdevice(snd_ctl_elem_id_t *obj, unsigned int val);
475 void snd_ctl_elem_id_set_name(snd_ctl_elem_id_t *obj, const char *val);
476 void snd_ctl_elem_id_set_index(snd_ctl_elem_id_t *obj, unsigned int val);
477 
478 size_t snd_ctl_card_info_sizeof(void);
479 
480 /** \hideinitializer
481  * \brief Allocate an invalid #snd_ctl_card_info_t on the stack.
482  *
483  * Allocate space for a card info object on the stack. The allocated
484  * memory need not be freed, because it is on the stack.
485  *
486  * See snd_ctl_card_info_t for details.
487  *
488  * \param ptr Pointer to a snd_ctl_elem_value_t pointer. The address
489  *            of the allocated space will returned here.
490  */
491 #define snd_ctl_card_info_alloca(ptr) __snd_alloca(ptr, snd_ctl_card_info)
492 
493 int snd_ctl_card_info_malloc(snd_ctl_card_info_t **ptr);
494 void snd_ctl_card_info_free(snd_ctl_card_info_t *obj);
495 void snd_ctl_card_info_clear(snd_ctl_card_info_t *obj);
496 void snd_ctl_card_info_copy(snd_ctl_card_info_t *dst, const snd_ctl_card_info_t *src);
497 int snd_ctl_card_info_get_card(const snd_ctl_card_info_t *obj);
498 const char *snd_ctl_card_info_get_id(const snd_ctl_card_info_t *obj);
499 const char *snd_ctl_card_info_get_driver(const snd_ctl_card_info_t *obj);
500 const char *snd_ctl_card_info_get_name(const snd_ctl_card_info_t *obj);
501 const char *snd_ctl_card_info_get_longname(const snd_ctl_card_info_t *obj);
502 const char *snd_ctl_card_info_get_mixername(const snd_ctl_card_info_t *obj);
503 const char *snd_ctl_card_info_get_components(const snd_ctl_card_info_t *obj);
504 
505 size_t snd_ctl_event_sizeof(void);
506 /** \hideinitializer
507  * \brief allocate an invalid #snd_ctl_event_t using standard alloca
508  * \param ptr returned pointer
509  */
510 #define snd_ctl_event_alloca(ptr) __snd_alloca(ptr, snd_ctl_event)
511 int snd_ctl_event_malloc(snd_ctl_event_t **ptr);
512 void snd_ctl_event_free(snd_ctl_event_t *obj);
513 void snd_ctl_event_clear(snd_ctl_event_t *obj);
514 void snd_ctl_event_copy(snd_ctl_event_t *dst, const snd_ctl_event_t *src);
515 snd_ctl_event_type_t snd_ctl_event_get_type(const snd_ctl_event_t *obj);
516 
517 size_t snd_ctl_elem_list_sizeof(void);
518 
519 /** \hideinitializer
520  *
521  * \brief Allocate a #snd_ctl_elem_list_t using standard alloca.
522  *
523  * The memory is allocated on the stack and will automatically be
524  * released when the stack unwinds (i.e. no free() is needed).
525  *
526  * \param ptr Pointer to allocated memory.
527  */
528 #define snd_ctl_elem_list_alloca(ptr) __snd_alloca(ptr, snd_ctl_elem_list)
529 
530 int snd_ctl_elem_list_malloc(snd_ctl_elem_list_t **ptr);
531 void snd_ctl_elem_list_free(snd_ctl_elem_list_t *obj);
532 void snd_ctl_elem_list_clear(snd_ctl_elem_list_t *obj);
533 void snd_ctl_elem_list_copy(snd_ctl_elem_list_t *dst, const snd_ctl_elem_list_t *src);
534 void snd_ctl_elem_list_set_offset(snd_ctl_elem_list_t *obj, unsigned int val);
535 unsigned int snd_ctl_elem_list_get_used(const snd_ctl_elem_list_t *obj);
536 unsigned int snd_ctl_elem_list_get_count(const snd_ctl_elem_list_t *obj);
537 void snd_ctl_elem_list_get_id(const snd_ctl_elem_list_t *obj, unsigned int idx, snd_ctl_elem_id_t *ptr);
538 unsigned int snd_ctl_elem_list_get_numid(const snd_ctl_elem_list_t *obj, unsigned int idx);
539 snd_ctl_elem_iface_t snd_ctl_elem_list_get_interface(const snd_ctl_elem_list_t *obj, unsigned int idx);
540 unsigned int snd_ctl_elem_list_get_device(const snd_ctl_elem_list_t *obj, unsigned int idx);
541 unsigned int snd_ctl_elem_list_get_subdevice(const snd_ctl_elem_list_t *obj, unsigned int idx);
542 const char *snd_ctl_elem_list_get_name(const snd_ctl_elem_list_t *obj, unsigned int idx);
543 unsigned int snd_ctl_elem_list_get_index(const snd_ctl_elem_list_t *obj, unsigned int idx);
544 
545 size_t snd_ctl_elem_info_sizeof(void);
546 /** \hideinitializer
547  * \brief allocate an invalid #snd_ctl_elem_info_t using standard alloca
548  * \param ptr returned pointer
549  */
550 #define snd_ctl_elem_info_alloca(ptr) __snd_alloca(ptr, snd_ctl_elem_info)
551 int snd_ctl_elem_info_malloc(snd_ctl_elem_info_t **ptr);
552 void snd_ctl_elem_info_free(snd_ctl_elem_info_t *obj);
553 void snd_ctl_elem_info_clear(snd_ctl_elem_info_t *obj);
554 void snd_ctl_elem_info_copy(snd_ctl_elem_info_t *dst, const snd_ctl_elem_info_t *src);
555 snd_ctl_elem_type_t snd_ctl_elem_info_get_type(const snd_ctl_elem_info_t *obj);
556 int snd_ctl_elem_info_is_readable(const snd_ctl_elem_info_t *obj);
557 int snd_ctl_elem_info_is_writable(const snd_ctl_elem_info_t *obj);
558 int snd_ctl_elem_info_is_volatile(const snd_ctl_elem_info_t *obj);
559 int snd_ctl_elem_info_is_inactive(const snd_ctl_elem_info_t *obj);
560 int snd_ctl_elem_info_is_locked(const snd_ctl_elem_info_t *obj);
561 int snd_ctl_elem_info_is_tlv_readable(const snd_ctl_elem_info_t *obj);
562 int snd_ctl_elem_info_is_tlv_writable(const snd_ctl_elem_info_t *obj);
563 int snd_ctl_elem_info_is_tlv_commandable(const snd_ctl_elem_info_t *obj);
564 int snd_ctl_elem_info_is_owner(const snd_ctl_elem_info_t *obj);
565 int snd_ctl_elem_info_is_user(const snd_ctl_elem_info_t *obj);
566 pid_t snd_ctl_elem_info_get_owner(const snd_ctl_elem_info_t *obj);
567 unsigned int snd_ctl_elem_info_get_count(const snd_ctl_elem_info_t *obj);
568 long snd_ctl_elem_info_get_min(const snd_ctl_elem_info_t *obj);
569 long snd_ctl_elem_info_get_max(const snd_ctl_elem_info_t *obj);
570 long snd_ctl_elem_info_get_step(const snd_ctl_elem_info_t *obj);
571 long long snd_ctl_elem_info_get_min64(const snd_ctl_elem_info_t *obj);
572 long long snd_ctl_elem_info_get_max64(const snd_ctl_elem_info_t *obj);
573 long long snd_ctl_elem_info_get_step64(const snd_ctl_elem_info_t *obj);
574 unsigned int snd_ctl_elem_info_get_items(const snd_ctl_elem_info_t *obj);
575 void snd_ctl_elem_info_set_item(snd_ctl_elem_info_t *obj, unsigned int val);
576 const char *snd_ctl_elem_info_get_item_name(const snd_ctl_elem_info_t *obj);
577 int snd_ctl_elem_info_get_dimensions(const snd_ctl_elem_info_t *obj);
578 int snd_ctl_elem_info_get_dimension(const snd_ctl_elem_info_t *obj, unsigned int idx);
579 int snd_ctl_elem_info_set_dimension(snd_ctl_elem_info_t *info,
580 				    const int dimension[4]);
581 void snd_ctl_elem_info_get_id(const snd_ctl_elem_info_t *obj, snd_ctl_elem_id_t *ptr);
582 unsigned int snd_ctl_elem_info_get_numid(const snd_ctl_elem_info_t *obj);
583 snd_ctl_elem_iface_t snd_ctl_elem_info_get_interface(const snd_ctl_elem_info_t *obj);
584 unsigned int snd_ctl_elem_info_get_device(const snd_ctl_elem_info_t *obj);
585 unsigned int snd_ctl_elem_info_get_subdevice(const snd_ctl_elem_info_t *obj);
586 const char *snd_ctl_elem_info_get_name(const snd_ctl_elem_info_t *obj);
587 unsigned int snd_ctl_elem_info_get_index(const snd_ctl_elem_info_t *obj);
588 void snd_ctl_elem_info_set_id(snd_ctl_elem_info_t *obj, const snd_ctl_elem_id_t *ptr);
589 void snd_ctl_elem_info_set_numid(snd_ctl_elem_info_t *obj, unsigned int val);
590 void snd_ctl_elem_info_set_interface(snd_ctl_elem_info_t *obj, snd_ctl_elem_iface_t val);
591 void snd_ctl_elem_info_set_device(snd_ctl_elem_info_t *obj, unsigned int val);
592 void snd_ctl_elem_info_set_subdevice(snd_ctl_elem_info_t *obj, unsigned int val);
593 void snd_ctl_elem_info_set_name(snd_ctl_elem_info_t *obj, const char *val);
594 void snd_ctl_elem_info_set_index(snd_ctl_elem_info_t *obj, unsigned int val);
595 void snd_ctl_elem_info_set_read_write(snd_ctl_elem_info_t *obj, int rval, int wval);
596 void snd_ctl_elem_info_set_tlv_read_write(snd_ctl_elem_info_t *obj, int rval, int wval);
597 void snd_ctl_elem_info_set_inactive(snd_ctl_elem_info_t *obj, int val);
598 
599 int snd_ctl_add_integer_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
600 				 unsigned int element_count,
601 				 unsigned int member_count,
602 				 long min, long max, long step);
603 int snd_ctl_add_integer64_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
604 				   unsigned int element_count,
605 				   unsigned int member_count,
606 				   long long min, long long max,
607 				   long long step);
608 int snd_ctl_add_boolean_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
609 				 unsigned int element_count,
610 				 unsigned int member_count);
611 int snd_ctl_add_enumerated_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
612 				    unsigned int element_count,
613 				    unsigned int member_count,
614 				    unsigned int items,
615 				    const char *const labels[]);
616 int snd_ctl_add_bytes_elem_set(snd_ctl_t *ctl, snd_ctl_elem_info_t *info,
617 			       unsigned int element_count,
618 			       unsigned int member_count);
619 
620 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);
621 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);
622 int snd_ctl_elem_add_boolean(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id, unsigned int count);
623 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[]);
624 int snd_ctl_elem_add_iec958(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id);
625 int snd_ctl_elem_remove(snd_ctl_t *ctl, snd_ctl_elem_id_t *id);
626 
627 size_t snd_ctl_elem_value_sizeof(void);
628 
629 /** \hideinitializer
630  * \brief Allocate an invalid #snd_ctl_elem_value_t on the stack.
631  *
632  * Allocate space for a value object on the stack. The allocated
633  * memory need not be freed, because it is on the stack.
634  *
635  * See snd_ctl_elem_value_t for details.
636  *
637  * \param ptr Pointer to a snd_ctl_elem_value_t pointer. The address
638  *            of the allocated space will returned here.
639  */
640 #define snd_ctl_elem_value_alloca(ptr) __snd_alloca(ptr, snd_ctl_elem_value)
641 
642 int snd_ctl_elem_value_malloc(snd_ctl_elem_value_t **ptr);
643 void snd_ctl_elem_value_free(snd_ctl_elem_value_t *obj);
644 void snd_ctl_elem_value_clear(snd_ctl_elem_value_t *obj);
645 void snd_ctl_elem_value_copy(snd_ctl_elem_value_t *dst, const snd_ctl_elem_value_t *src);
646 int snd_ctl_elem_value_compare(snd_ctl_elem_value_t *left, const snd_ctl_elem_value_t *right);
647 void snd_ctl_elem_value_get_id(const snd_ctl_elem_value_t *obj, snd_ctl_elem_id_t *ptr);
648 unsigned int snd_ctl_elem_value_get_numid(const snd_ctl_elem_value_t *obj);
649 snd_ctl_elem_iface_t snd_ctl_elem_value_get_interface(const snd_ctl_elem_value_t *obj);
650 unsigned int snd_ctl_elem_value_get_device(const snd_ctl_elem_value_t *obj);
651 unsigned int snd_ctl_elem_value_get_subdevice(const snd_ctl_elem_value_t *obj);
652 const char *snd_ctl_elem_value_get_name(const snd_ctl_elem_value_t *obj);
653 unsigned int snd_ctl_elem_value_get_index(const snd_ctl_elem_value_t *obj);
654 void snd_ctl_elem_value_set_id(snd_ctl_elem_value_t *obj, const snd_ctl_elem_id_t *ptr);
655 void snd_ctl_elem_value_set_numid(snd_ctl_elem_value_t *obj, unsigned int val);
656 void snd_ctl_elem_value_set_interface(snd_ctl_elem_value_t *obj, snd_ctl_elem_iface_t val);
657 void snd_ctl_elem_value_set_device(snd_ctl_elem_value_t *obj, unsigned int val);
658 void snd_ctl_elem_value_set_subdevice(snd_ctl_elem_value_t *obj, unsigned int val);
659 void snd_ctl_elem_value_set_name(snd_ctl_elem_value_t *obj, const char *val);
660 void snd_ctl_elem_value_set_index(snd_ctl_elem_value_t *obj, unsigned int val);
661 int snd_ctl_elem_value_get_boolean(const snd_ctl_elem_value_t *obj, unsigned int idx);
662 long snd_ctl_elem_value_get_integer(const snd_ctl_elem_value_t *obj, unsigned int idx);
663 long long snd_ctl_elem_value_get_integer64(const snd_ctl_elem_value_t *obj, unsigned int idx);
664 unsigned int snd_ctl_elem_value_get_enumerated(const snd_ctl_elem_value_t *obj, unsigned int idx);
665 unsigned char snd_ctl_elem_value_get_byte(const snd_ctl_elem_value_t *obj, unsigned int idx);
666 void snd_ctl_elem_value_set_boolean(snd_ctl_elem_value_t *obj, unsigned int idx, long val);
667 void snd_ctl_elem_value_set_integer(snd_ctl_elem_value_t *obj, unsigned int idx, long val);
668 void snd_ctl_elem_value_set_integer64(snd_ctl_elem_value_t *obj, unsigned int idx, long long val);
669 void snd_ctl_elem_value_set_enumerated(snd_ctl_elem_value_t *obj, unsigned int idx, unsigned int val);
670 void snd_ctl_elem_value_set_byte(snd_ctl_elem_value_t *obj, unsigned int idx, unsigned char val);
671 void snd_ctl_elem_set_bytes(snd_ctl_elem_value_t *obj, void *data, size_t size);
672 const void * snd_ctl_elem_value_get_bytes(const snd_ctl_elem_value_t *obj);
673 void snd_ctl_elem_value_get_iec958(const snd_ctl_elem_value_t *obj, snd_aes_iec958_t *ptr);
674 void snd_ctl_elem_value_set_iec958(snd_ctl_elem_value_t *obj, const snd_aes_iec958_t *ptr);
675 
676 int snd_tlv_parse_dB_info(unsigned int *tlv, unsigned int tlv_size,
677 			  unsigned int **db_tlvp);
678 int snd_tlv_get_dB_range(unsigned int *tlv, long rangemin, long rangemax,
679 			 long *min, long *max);
680 int snd_tlv_convert_to_dB(unsigned int *tlv, long rangemin, long rangemax,
681 			  long volume, long *db_gain);
682 int snd_tlv_convert_from_dB(unsigned int *tlv, long rangemin, long rangemax,
683 			    long db_gain, long *value, int xdir);
684 int snd_ctl_get_dB_range(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
685 			 long *min, long *max);
686 int snd_ctl_convert_to_dB(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
687 			  long volume, long *db_gain);
688 int snd_ctl_convert_from_dB(snd_ctl_t *ctl, const snd_ctl_elem_id_t *id,
689 			    long db_gain, long *value, int xdir);
690 
691 /**
692  *  \defgroup HControl High level Control Interface
693  *  \ingroup Control
694  *  The high level control interface.
695  *  See \ref hcontrol page for more details.
696  *  \{
697  */
698 
699 /** HCTL element handle */
700 typedef struct _snd_hctl_elem snd_hctl_elem_t;
701 
702 /** HCTL handle */
703 typedef struct _snd_hctl snd_hctl_t;
704 
705 /**
706  * \brief Compare function for sorting HCTL elements
707  * \param e1 First element
708  * \param e2 Second element
709  * \return -1 if e1 < e2, 0 if e1 == e2, 1 if e1 > e2
710  */
711 typedef int (*snd_hctl_compare_t)(const snd_hctl_elem_t *e1,
712 				  const snd_hctl_elem_t *e2);
713 int snd_hctl_compare_fast(const snd_hctl_elem_t *c1,
714 			  const snd_hctl_elem_t *c2);
715 /**
716  * \brief HCTL callback function
717  * \param hctl HCTL handle
718  * \param mask event mask
719  * \param elem related HCTL element (if any)
720  * \return 0 on success otherwise a negative error code
721  */
722 typedef int (*snd_hctl_callback_t)(snd_hctl_t *hctl,
723 				   unsigned int mask,
724 				   snd_hctl_elem_t *elem);
725 /**
726  * \brief HCTL element callback function
727  * \param elem HCTL element
728  * \param mask event mask
729  * \return 0 on success otherwise a negative error code
730  */
731 typedef int (*snd_hctl_elem_callback_t)(snd_hctl_elem_t *elem,
732 					unsigned int mask);
733 
734 int snd_hctl_open(snd_hctl_t **hctl, const char *name, int mode);
735 int snd_hctl_open_ctl(snd_hctl_t **hctlp, snd_ctl_t *ctl);
736 int snd_hctl_close(snd_hctl_t *hctl);
737 int snd_hctl_nonblock(snd_hctl_t *hctl, int nonblock);
snd_hctl_abort(snd_hctl_t *hctl)738 static __inline__ int snd_hctl_abort(snd_hctl_t *hctl) { return snd_hctl_nonblock(hctl, 2); }
739 int snd_hctl_poll_descriptors_count(snd_hctl_t *hctl);
740 int snd_hctl_poll_descriptors(snd_hctl_t *hctl, struct pollfd *pfds, unsigned int space);
741 int snd_hctl_poll_descriptors_revents(snd_hctl_t *ctl, struct pollfd *pfds, unsigned int nfds, unsigned short *revents);
742 unsigned int snd_hctl_get_count(snd_hctl_t *hctl);
743 int snd_hctl_set_compare(snd_hctl_t *hctl, snd_hctl_compare_t hsort);
744 snd_hctl_elem_t *snd_hctl_first_elem(snd_hctl_t *hctl);
745 snd_hctl_elem_t *snd_hctl_last_elem(snd_hctl_t *hctl);
746 snd_hctl_elem_t *snd_hctl_find_elem(snd_hctl_t *hctl, const snd_ctl_elem_id_t *id);
747 void snd_hctl_set_callback(snd_hctl_t *hctl, snd_hctl_callback_t callback);
748 void snd_hctl_set_callback_private(snd_hctl_t *hctl, void *data);
749 void *snd_hctl_get_callback_private(snd_hctl_t *hctl);
750 int snd_hctl_load(snd_hctl_t *hctl);
751 int snd_hctl_free(snd_hctl_t *hctl);
752 int snd_hctl_handle_events(snd_hctl_t *hctl);
753 const char *snd_hctl_name(snd_hctl_t *hctl);
754 int snd_hctl_wait(snd_hctl_t *hctl, int timeout);
755 snd_ctl_t *snd_hctl_ctl(snd_hctl_t *hctl);
756 
757 snd_hctl_elem_t *snd_hctl_elem_next(snd_hctl_elem_t *elem);
758 snd_hctl_elem_t *snd_hctl_elem_prev(snd_hctl_elem_t *elem);
759 int snd_hctl_elem_info(snd_hctl_elem_t *elem, snd_ctl_elem_info_t * info);
760 int snd_hctl_elem_read(snd_hctl_elem_t *elem, snd_ctl_elem_value_t * value);
761 int snd_hctl_elem_write(snd_hctl_elem_t *elem, snd_ctl_elem_value_t * value);
762 int snd_hctl_elem_tlv_read(snd_hctl_elem_t *elem, unsigned int *tlv, unsigned int tlv_size);
763 int snd_hctl_elem_tlv_write(snd_hctl_elem_t *elem, const unsigned int *tlv);
764 int snd_hctl_elem_tlv_command(snd_hctl_elem_t *elem, const unsigned int *tlv);
765 
766 snd_hctl_t *snd_hctl_elem_get_hctl(snd_hctl_elem_t *elem);
767 
768 void snd_hctl_elem_get_id(const snd_hctl_elem_t *obj, snd_ctl_elem_id_t *ptr);
769 unsigned int snd_hctl_elem_get_numid(const snd_hctl_elem_t *obj);
770 snd_ctl_elem_iface_t snd_hctl_elem_get_interface(const snd_hctl_elem_t *obj);
771 unsigned int snd_hctl_elem_get_device(const snd_hctl_elem_t *obj);
772 unsigned int snd_hctl_elem_get_subdevice(const snd_hctl_elem_t *obj);
773 const char *snd_hctl_elem_get_name(const snd_hctl_elem_t *obj);
774 unsigned int snd_hctl_elem_get_index(const snd_hctl_elem_t *obj);
775 void snd_hctl_elem_set_callback(snd_hctl_elem_t *obj, snd_hctl_elem_callback_t val);
776 void * snd_hctl_elem_get_callback_private(const snd_hctl_elem_t *obj);
777 void snd_hctl_elem_set_callback_private(snd_hctl_elem_t *obj, void * val);
778 
779 /** \} */
780 
781 /** \} */
782 
783 /**
784  *  \defgroup SControl Setup Control Interface
785  *  \ingroup Control
786  *  The setup control interface - set or modify control elements from a configuration file.
787  *  \{
788  */
789 
790 int snd_sctl_build(snd_sctl_t **ctl, snd_ctl_t *handle, snd_config_t *config,
791 		   snd_config_t *private_data, int mode);
792 int snd_sctl_free(snd_sctl_t *handle);
793 int snd_sctl_install(snd_sctl_t *handle);
794 int snd_sctl_remove(snd_sctl_t *handle);
795 
796 /** \} */
797 
798 /**
799  *  \defgroup Hint Name Hint Interface
800  *  \ingroup Configuration
801  *  The name hint interface - get descriptive information about a device
802  *  (name, description, input/output).
803  *  \{
804  */
805 
806 int snd_device_name_hint(int card, const char *iface, void ***hints);
807 int snd_device_name_free_hint(void **hints);
808 char *snd_device_name_get_hint(const void *hint, const char *id);
809 
810 /** \} */
811 
812 #ifdef __cplusplus
813 }
814 #endif
815 
816 #endif /* __ALSA_CONTROL_H */
817