• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  ALSA lib - local header file
3  *  Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
4  *
5  *
6  *   This library is free software; you can redistribute it and/or modify
7  *   it under the terms of the GNU Lesser General Public License as
8  *   published by the Free Software Foundation; either version 2.1 of
9  *   the License, or (at your option) any later version.
10  *
11  *   This program is distributed in the hope that it will be useful,
12  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *   GNU Lesser General Public License for more details.
15  *
16  *   You should have received a copy of the GNU Lesser General Public
17  *   License along with this library; if not, write to the Free Software
18  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
19  *
20  */
21 
22 #ifndef __LOCAL_H
23 #define __LOCAL_H
24 
25 #include "config.h"
26 
27 #include <unistd.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <fcntl.h>
32 #include <assert.h>
33 #ifdef HAVE_ENDIAN_H
34 #include <endian.h>
35 #elif defined(HAVE_SYS_ENDIAN_H)
36 #include <sys/endian.h>
37 #else
38 #error Header defining endianness not defined
39 #endif
40 #ifndef __BYTE_ORDER
41 #define __BYTE_ORDER BYTE_ORDER
42 #endif
43 #ifndef __LITTLE_ENDIAN
44 #define __LITTLE_ENDIAN LITTLE_ENDIAN
45 #endif
46 #ifndef __BIG_ENDIAN
47 #define __BIG_ENDIAN BIG_ENDIAN
48 #endif
49 #include <stdarg.h>
50 #include <poll.h>
51 #include <sys/types.h>
52 #include <errno.h>
53 #if defined(__linux__)
54 #include <linux/types.h>
55 #include <linux/ioctl.h>
56 #else
57 #include "type_compat.h"
58 #endif
59 
60 #ifdef SUPPORT_RESMGR
61 #include <resmgr.h>
62 #endif
63 #ifdef HAVE_LIBDL
64 #include <dlfcn.h>
65 #else
66 #define RTLD_NOW	0
67 #endif
68 
69 #if __BYTE_ORDER == __LITTLE_ENDIAN
70 #define SND_LITTLE_ENDIAN
71 #define SNDRV_LITTLE_ENDIAN
72 #define SNDRV_LITTLE_ENDIAN_BITFIELD
73 #elif __BYTE_ORDER == __BIG_ENDIAN
74 #define SND_BIG_ENDIAN
75 #define SNDRV_BIG_ENDIAN
76 #define SNDRV_BIG_ENDIAN_BITFIELD
77 #else
78 #error "Unsupported endian..."
79 #endif
80 
81 #ifndef HAVE_LFS
82 #define stat64 stat
83 #define lstat64 lstat
84 #define dirent64 dirent
85 #define readdir64 readdir
86 #define scandir64 scandir
87 #define versionsort64 versionsort
88 #define alphasort64 alphasort
89 #define ino64_t ino_t
90 #define fstat64 fstat
91 #define stat64 stat
92 #endif
93 
94 #define _snd_config_iterator list_head
95 #define _snd_interval snd_interval
96 #define _snd_pcm_info snd_pcm_info
97 #define _snd_pcm_hw_params snd_pcm_hw_params
98 #define _snd_pcm_sw_params snd_pcm_sw_params
99 #define _snd_pcm_status snd_pcm_status
100 
101 #define _snd_ctl_card_info snd_ctl_card_info
102 #define _snd_ctl_elem_id snd_ctl_elem_id
103 #define _snd_ctl_elem_list snd_ctl_elem_list
104 #define _snd_ctl_elem_info snd_ctl_elem_info
105 #define _snd_ctl_elem_value snd_ctl_elem_value
106 #define _snd_ctl_event snd_ctl_event
107 
108 #define _snd_rawmidi_info snd_rawmidi_info
109 #define _snd_rawmidi_params snd_rawmidi_params
110 #define _snd_rawmidi_status snd_rawmidi_status
111 
112 #define _snd_hwdep_info snd_hwdep_info
113 #define _snd_hwdep_dsp_status snd_hwdep_dsp_status
114 #define _snd_hwdep_dsp_image snd_hwdep_dsp_image
115 
116 #define _snd_seq_queue_tempo snd_seq_queue_tempo
117 #define _snd_seq_client_info snd_seq_client_info
118 #define _snd_seq_port_info snd_seq_port_info
119 #define _snd_seq_system_info snd_seq_system_info
120 #define _snd_seq_queue_info snd_seq_queue_info
121 #define _snd_seq_queue_status snd_seq_queue_status
122 #define _snd_seq_queue_timer snd_seq_queue_timer
123 #define _snd_seq_port_subscribe snd_seq_port_subscribe
124 #define _snd_seq_query_subscribe snd_seq_query_subs
125 #define _snd_seq_client_pool snd_seq_client_pool
126 #define _snd_seq_remove_events snd_seq_remove_events
127 
128 #define _snd_timer_id snd_timer_id
129 #define _snd_timer_ginfo snd_timer_ginfo
130 #define _snd_timer_gparams snd_timer_gparams
131 #define _snd_timer_gstatus snd_timer_gstatus
132 #define _snd_timer_select snd_timer_select
133 #define _snd_timer_info snd_timer_info
134 #define _snd_timer_params snd_timer_params
135 #define _snd_timer_status snd_timer_status
136 
137 #define ALSA_LIBRARY_BUILD
138 
139 /* rename some types for avoiding conflicts with alsalib's definitions */
140 #define snd_aes_iec958		sndrv_aes_iec958
141 #define snd_pcm_uframes_t	sndrv_pcm_uframes_t
142 #define snd_pcm_sframes_t	sndrv_pcm_sframes_t
143 #define snd_pcm_access_t	sndrv_pcm_access_t
144 #define snd_pcm_format_t	sndrv_pcm_format_t
145 #define snd_pcm_subformat_t	sndrv_pcm_subformat_t
146 #define snd_pcm_state_t		sndrv_pcm_state_t
147 #define snd_interval		sndrv_interval
148 #define snd_mask		sndrv_mask
149 #define snd_ctl_elem_type_t	sndrv_ctl_elem_type_t
150 #define snd_ctl_elem_iface_t	sndrv_ctl_elem_iface_t
151 #define snd_ctl_tlv		sndrv_ctl_tlv
152 
153 /* kill and replace kernel-specific types */
154 #ifndef __user
155 #define __user
156 #endif
157 #ifndef __force
158 #define __force
159 #endif
160 
161 #include <sound/asound.h>
162 
163 /* take back superfluous renames; some can be kept as is */
164 #undef snd_aes_iec958
165 #undef snd_pcm_uframes_t
166 #undef snd_pcm_sframes_t
167 #undef snd_pcm_access_t
168 #undef snd_pcm_format_t
169 #undef snd_pcm_subformat_t
170 #undef snd_pcm_state_t
171 #undef snd_ctl_elem_type_t
172 #undef snd_ctl_elem_iface_t
173 
174 #include "asoundef.h"
175 #include "alsa-symbols.h"
176 #include "version.h"
177 #include "global.h"
178 #include "input.h"
179 #include "output.h"
180 #include "error.h"
181 #include "conf.h"
182 #include "pcm.h"
183 #include "pcm_plugin.h"
184 #include "rawmidi.h"
185 #include "ump.h"
186 #include "timer.h"
187 #include "hwdep.h"
188 #include "control.h"
189 #include "mixer.h"
190 #include "seq_event.h"
191 #include "seq.h"
192 
193 /* rename some types for avoiding conflicts with alsalib's definitions */
194 #define snd_seq_addr		sndrv_seq_addr
195 #define snd_seq_tick_time_t	sndrv_seq_tick_time_t
196 #define snd_seq_real_time	sndrv_seq_real_time
197 #define snd_seq_timestamp	sndrv_seq_timestamp
198 #define snd_seq_event_type_t	sndrv_seq_event_type_t
199 #define snd_seq_event_data	sndrv_seq_event_data
200 #define snd_seq_event		sndrv_seq_event
201 #define snd_seq_ump_event	sndrv_seq_ump_event
202 #define snd_seq_connect		sndrv_seq_connect
203 #define snd_seq_ev_note		sndrv_seq_ev_note
204 #define snd_seq_ev_ctrl		sndrv_seq_ev_ctrl
205 #define snd_seq_ev_raw8		sndrv_seq_ev_raw8
206 #define snd_seq_ev_raw32	sndrv_seq_ev_raw32
207 #define snd_seq_ev_ext		sndrv_seq_ev_ext
208 #define snd_seq_result		sndrv_seq_result
209 #define snd_seq_queue_skew	sndrv_seq_queue_skew
210 #define snd_seq_ev_queue_control	sndrv_seq_ev_queue_control
211 #define snd_seq_client_t	sndrv_seq_client_t
212 #define snd_seq_client_type_t	sndrv_seq_client_type_t
213 
214 #include <sound/asequencer.h>
215 
216 /* take back some renames */
217 #undef snd_seq_client_t
218 #undef snd_seq_client_type_t
219 
220 #include "seqmid.h"
221 #include "seq_midi_event.h"
222 #include "list.h"
223 
224 struct _snd_async_handler {
225 	enum {
226 		SND_ASYNC_HANDLER_GENERIC,
227 		SND_ASYNC_HANDLER_CTL,
228 		SND_ASYNC_HANDLER_PCM,
229 		SND_ASYNC_HANDLER_TIMER,
230 	} type;
231 	int fd;
232 	union {
233 		snd_ctl_t *ctl;
234 		snd_pcm_t *pcm;
235 		snd_timer_t *timer;
236 	} u;
237 	snd_async_callback_t callback;
238 	void *private_data;
239 	struct list_head glist;
240 	struct list_head hlist;
241 };
242 
243 typedef enum _snd_set_mode {
244 	SND_CHANGE,
245 	SND_TRY,
246 	SND_TEST,
247 } snd_set_mode_t;
248 
249 size_t page_align(size_t size);
250 size_t page_size(void);
251 size_t page_ptr(size_t object_offset, size_t object_size, size_t *offset, size_t *mmap_offset);
252 
253 #define safe_strtoll_base _snd_safe_strtoll_base
254 int _snd_safe_strtoll_base(const char *str, long long *val, int base);
safe_strtoll(const char * str,long long * val)255 static inline int safe_strtoll(const char *str, long long *val) { return safe_strtoll_base(str, val, 0); }
256 #define safe_strtol_base _snd_safe_strtol_base
257 int _snd_safe_strtol_base(const char *str, long *val, int base);
safe_strtol(const char * str,long * val)258 static inline int safe_strtol(const char *str, long *val) { return safe_strtol_base(str, val, 0); }
259 #define safe_strtod _snd_safe_strtod
260 int _snd_safe_strtod(const char *str, double *val);
261 
262 int snd_send_fd(int sock, void *data, size_t len, int fd);
263 int snd_receive_fd(int sock, void *data, size_t len, int *fd);
264 size_t snd_strlcpy(char *dst, const char *src, size_t size);
265 
266 /*
267  * error messages
268  */
269 #ifndef NDEBUG
270 #define CHECK_SANITY(x) x
271 extern snd_lib_error_handler_t snd_err_msg;
272 #define SNDMSG(args...) snd_err_msg(__FILE__, __LINE__, __func__, 0, ##args)
273 #define SYSMSG(args...) snd_err_msg(__FILE__, __LINE__, __func__, errno, ##args)
274 #else
275 #define CHECK_SANITY(x) 0 /* not evaluated */
276 #define SNDMSG(args...) /* nop */
277 #define SYSMSG(args...) /* nop */
278 #endif
279 
280 /*
281  */
282 #define HAVE_GNU_LD
283 #define HAVE_ELF
284 #define HAVE_ASM_PREVIOUS_DIRECTIVE
285 
286 /* Stolen from libc-symbols.h in GNU glibc */
287 
288 /* When a reference to SYMBOL is encountered, the linker will emit a
289    warning message MSG.  */
290 
291 #define ASM_NAME(name) __SYMBOL_PREFIX name
292 
293 #ifdef HAVE_GNU_LD
294 # ifdef HAVE_ELF
295 
296 /* We want the .gnu.warning.SYMBOL section to be unallocated.  */
297 #  ifdef HAVE_ASM_PREVIOUS_DIRECTIVE
298 #   define __make_section_unallocated(section_string)	\
299   asm (".section " section_string "\n\t.previous");
300 #  elif defined HAVE_ASM_POPSECTION_DIRECTIVE
301 #   define __make_section_unallocated(section_string)	\
302   asm (".pushsection " section_string "\n\t.popsection");
303 #  else
304 #   define __make_section_unallocated(section_string)
305 #  endif
306 
307 /* Tacking on "\n\t#" to the section name makes gcc put it's bogus
308    section attributes on what looks like a comment to the assembler.  */
309 #  ifdef HAVE_SECTION_QUOTES
310 #   define link_warning(symbol, msg) \
311   __make_section_unallocated (".gnu.warning." ASM_NAME(#symbol)) \
312   static const char __evoke_link_warning_##symbol[]	\
313     __attribute__ ((section (".gnu.warning." ASM_NAME(#symbol) "\"\n\t#\""))) = msg;
314 #  else
315 #   define link_warning(symbol, msg) \
316   __make_section_unallocated (".gnu.warning." ASM_NAME(#symbol)) \
317   static const char __evoke_link_warning_##symbol[]	\
318     __attribute__ ((section (".gnu.warning." ASM_NAME(#symbol) "\n\t#"))) = msg;
319 #  endif
320 # else
321 #  define link_warning(symbol, msg)		\
322   asm (".stabs \"" msg "\",30,0,0,0\n\t"	\
323        ".stabs \"" ASM_NAME(#symbol) "\",1,0,0,0\n");
324 # endif
325 #else
326 /* We will never be heard; they will all die horribly.  */
327 # define link_warning(symbol, msg)
328 #endif
329 
snd_open_device(const char * filename,int fmode)330 static inline int snd_open_device(const char *filename, int fmode)
331 {
332 	int fd;
333 
334 #ifdef O_CLOEXEC
335 	fmode |= O_CLOEXEC;
336 #endif
337 	fd = open(filename, fmode);
338 
339 /* open with resmgr */
340 #ifdef SUPPORT_RESMGR
341 	if (fd < 0) {
342 		if (errno == EAGAIN || errno == EBUSY)
343 			return fd;
344 		if (! access(filename, F_OK))
345 			fd = rsm_open_device(filename, fmode);
346 	}
347 #endif
348 #ifndef O_CLOEXEC
349 	if (fd >= 0)
350 		fcntl(fd, F_SETFD, FD_CLOEXEC);
351 #endif
352 	return fd;
353 }
354 
355 /* make local functions really local */
356 #define snd_dlobj_cache_get \
357 	snd1_dlobj_cache_get
358 #define snd_dlobj_cache_get2 \
359 	snd1_dlobj_cache_get2
360 #define snd_dlobj_cache_put \
361 	snd1_dlobj_cache_put
362 #define snd_dlobj_cache_cleanup \
363 	snd1_dlobj_cache_cleanup
364 #define snd_config_set_hop \
365 	snd1_config_set_hop
366 #define snd_config_check_hop \
367 	snd1_config_check_hop
368 #define snd_config_search_alias_hooks \
369 	snd1_config_search_alias_hooks
370 
371 /* dlobj cache */
372 void *snd_dlobj_cache_get(const char *lib, const char *name, const char *version, int verbose);
373 void *snd_dlobj_cache_get2(const char *lib, const char *name, const char *version, int verbose);
374 int snd_dlobj_cache_put(void *open_func);
375 void snd_dlobj_cache_cleanup(void);
376 
377 /* for recursive checks */
378 void snd_config_set_hop(snd_config_t *conf, int hop);
379 int snd_config_check_hop(snd_config_t *conf);
380 #define SND_CONF_MAX_HOPS	64
381 
382 int snd_config_search_alias_hooks(snd_config_t *config,
383                                   const char *base, const char *key,
384 				  snd_config_t **result);
385 
386 int _snd_conf_generic_id(const char *id);
387 
388 int _snd_config_load_with_include(snd_config_t *config, snd_input_t *in,
389 				  int override, const char * const *default_include_path);
390 
391 /* convenience macros */
392 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
393 
394 #define container_of(ptr, type, member) ({                      \
395 	 const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
396 	(type *)( (char *)__mptr - offsetof(type,member) );})
397 
398 #ifdef INTERNAL
399 void *INTERNAL(snd_dlopen)(const char *name, int mode, char *errbuf, size_t errbuflen);
400 #endif
401 
402 #ifdef BUILD_UCM
403 
404 const char *uc_mgr_alibcfg_by_device(snd_config_t **config, const char *name);
405 
_snd_is_ucm_device(const char * name)406 static inline int _snd_is_ucm_device(const char *name)
407 {
408 	return name && name[0] == '_' && name[1] == 'u' && name[2] == 'c' && name[3] == 'm';
409 }
410 
411 #else
412 
uc_mgr_alibcfg_by_device(snd_config_t ** config,const char * name)413 static inline const char *uc_mgr_alibcfg_by_device(snd_config_t **config, const char *name) { return NULL; }
_snd_is_ucm_device(const char * name)414 static inline int _snd_is_ucm_device(const char *name) { return 0; }
415 
416 
417 #endif
418 
419 #endif
420