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 #ifndef __BYTE_ORDER
38 #define __BYTE_ORDER BYTE_ORDER
39 #endif
40 #ifndef __LITTLE_ENDIAN
41 #define __LITTLE_ENDIAN LITTLE_ENDIAN
42 #endif
43 #ifndef __BIG_ENDIAN
44 #define __BIG_ENDIAN BIG_ENDIAN
45 #endif
46 #else
47 #error Header defining endianness not defined
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 #elif __BYTE_ORDER == __BIG_ENDIAN
73 #define SND_BIG_ENDIAN
74 #define SNDRV_BIG_ENDIAN
75 #else
76 #error "Unsupported endian..."
77 #endif
78
79 #define _snd_config_iterator list_head
80 #define _snd_interval snd_interval
81 #define _snd_pcm_info snd_pcm_info
82 #define _snd_pcm_hw_params snd_pcm_hw_params
83 #define _snd_pcm_sw_params snd_pcm_sw_params
84 #define _snd_pcm_status snd_pcm_status
85
86 #define _snd_ctl_card_info snd_ctl_card_info
87 #define _snd_ctl_elem_id snd_ctl_elem_id
88 #define _snd_ctl_elem_list snd_ctl_elem_list
89 #define _snd_ctl_elem_info snd_ctl_elem_info
90 #define _snd_ctl_elem_value snd_ctl_elem_value
91 #define _snd_ctl_event snd_ctl_event
92
93 #define _snd_rawmidi_info snd_rawmidi_info
94 #define _snd_rawmidi_params snd_rawmidi_params
95 #define _snd_rawmidi_status snd_rawmidi_status
96
97 #define _snd_hwdep_info snd_hwdep_info
98 #define _snd_hwdep_dsp_status snd_hwdep_dsp_status
99 #define _snd_hwdep_dsp_image snd_hwdep_dsp_image
100
101 #define _snd_seq_queue_tempo snd_seq_queue_tempo
102 #define _snd_seq_client_info snd_seq_client_info
103 #define _snd_seq_port_info snd_seq_port_info
104 #define _snd_seq_system_info snd_seq_system_info
105 #define _snd_seq_queue_info snd_seq_queue_info
106 #define _snd_seq_queue_status snd_seq_queue_status
107 #define _snd_seq_queue_timer snd_seq_queue_timer
108 #define _snd_seq_port_subscribe snd_seq_port_subscribe
109 #define _snd_seq_query_subscribe snd_seq_query_subs
110 #define _snd_seq_client_pool snd_seq_client_pool
111 #define _snd_seq_remove_events snd_seq_remove_events
112
113 #define _snd_timer_id snd_timer_id
114 #define _snd_timer_ginfo snd_timer_ginfo
115 #define _snd_timer_gparams snd_timer_gparams
116 #define _snd_timer_gstatus snd_timer_gstatus
117 #define _snd_timer_select snd_timer_select
118 #define _snd_timer_info snd_timer_info
119 #define _snd_timer_params snd_timer_params
120 #define _snd_timer_status snd_timer_status
121
122 #define ALSA_LIBRARY_BUILD
123
124 /* rename some types for avoiding conflicts with alsalib's definitions */
125 #define snd_aes_iec958 sndrv_aes_iec958
126 #define snd_pcm_uframes_t sndrv_pcm_uframes_t
127 #define snd_pcm_sframes_t sndrv_pcm_sframes_t
128 #define snd_pcm_access_t sndrv_pcm_access_t
129 #define snd_pcm_format_t sndrv_pcm_format_t
130 #define snd_pcm_subformat_t sndrv_pcm_subformat_t
131 #define snd_pcm_state_t sndrv_pcm_state_t
132 #define snd_interval sndrv_interval
133 #define snd_mask sndrv_mask
134 #define snd_ctl_elem_type_t sndrv_ctl_elem_type_t
135 #define snd_ctl_elem_iface_t sndrv_ctl_elem_iface_t
136 #define snd_ctl_tlv sndrv_ctl_tlv
137
138 /* kill and replace kernel-specific types */
139 #ifndef __user
140 #define __user
141 #endif
142 #ifndef __force
143 #define __force
144 #endif
145
146 #include <sound/asound.h>
147
148 /* take back superfluous renames; some can be kept as is */
149 #undef snd_aes_iec958
150 #undef snd_pcm_uframes_t
151 #undef snd_pcm_sframes_t
152 #undef snd_pcm_access_t
153 #undef snd_pcm_format_t
154 #undef snd_pcm_subformat_t
155 #undef snd_pcm_state_t
156 #undef snd_ctl_elem_type_t
157 #undef snd_ctl_elem_iface_t
158
159 #include "asoundef.h"
160 #include "alsa-symbols.h"
161 #include "version.h"
162 #include "global.h"
163 #include "input.h"
164 #include "output.h"
165 #include "error.h"
166 #include "conf.h"
167 #include "pcm.h"
168 #include "pcm_plugin.h"
169 #include "rawmidi.h"
170 #include "timer.h"
171 #include "hwdep.h"
172 #include "control.h"
173 #include "mixer.h"
174 #include "seq_event.h"
175 #include "seq.h"
176
177 /* rename some types for avoiding conflicts with alsalib's definitions */
178 #define snd_seq_addr sndrv_seq_addr
179 #define snd_seq_tick_time_t sndrv_seq_tick_time_t
180 #define snd_seq_real_time sndrv_seq_real_time
181 #define snd_seq_timestamp sndrv_seq_timestamp
182 #define snd_seq_event_type_t sndrv_seq_event_type_t
183 #define snd_seq_event sndrv_seq_event
184 #define snd_seq_connect sndrv_seq_connect
185 #define snd_seq_ev_note sndrv_seq_ev_note
186 #define snd_seq_ev_ctrl sndrv_seq_ev_ctrl
187 #define snd_seq_ev_raw8 sndrv_seq_ev_raw8
188 #define snd_seq_ev_raw32 sndrv_seq_ev_raw32
189 #define snd_seq_ev_ext sndrv_seq_ev_ext
190 #define snd_seq_result sndrv_seq_result
191 #define snd_seq_queue_skew sndrv_seq_queue_skew
192 #define snd_seq_ev_queue_control sndrv_seq_ev_queue_control
193 #define snd_seq_client_t sndrv_seq_client_t
194 #define snd_seq_client_type_t sndrv_seq_client_type_t
195
196 #include <sound/asequencer.h>
197
198 /* take back some renames */
199 #undef snd_seq_client_t
200 #undef snd_seq_client_type_t
201
202 #include "seqmid.h"
203 #include "seq_midi_event.h"
204 #include "list.h"
205
206 struct _snd_async_handler {
207 enum {
208 SND_ASYNC_HANDLER_GENERIC,
209 SND_ASYNC_HANDLER_CTL,
210 SND_ASYNC_HANDLER_PCM,
211 SND_ASYNC_HANDLER_TIMER,
212 } type;
213 int fd;
214 union {
215 snd_ctl_t *ctl;
216 snd_pcm_t *pcm;
217 snd_timer_t *timer;
218 } u;
219 snd_async_callback_t callback;
220 void *private_data;
221 struct list_head glist;
222 struct list_head hlist;
223 };
224
225 typedef enum _snd_set_mode {
226 SND_CHANGE,
227 SND_TRY,
228 SND_TEST,
229 } snd_set_mode_t;
230
231 size_t page_align(size_t size);
232 size_t page_size(void);
233 size_t page_ptr(size_t object_offset, size_t object_size, size_t *offset, size_t *mmap_offset);
234
235 int safe_strtol(const char *str, long *val);
236
237 int snd_send_fd(int sock, void *data, size_t len, int fd);
238 int snd_receive_fd(int sock, void *data, size_t len, int *fd);
239 size_t snd_strlcpy(char *dst, const char *src, size_t size);
240
241 /*
242 * error messages
243 */
244 #ifndef NDEBUG
245 #define CHECK_SANITY(x) x
246 extern snd_lib_error_handler_t snd_err_msg;
247 #define SNDMSG(args...) snd_err_msg(__FILE__, __LINE__, __func__, 0, ##args)
248 #define SYSMSG(args...) snd_err_msg(__FILE__, __LINE__, __func__, errno, ##args)
249 #else
250 #define CHECK_SANITY(x) 0 /* not evaluated */
251 #define SNDMSG(args...) /* nop */
252 #define SYSMSG(args...) /* nop */
253 #endif
254
255 /*
256 */
257 #define HAVE_GNU_LD
258 #define HAVE_ELF
259 #define HAVE_ASM_PREVIOUS_DIRECTIVE
260
261 /* Stolen from libc-symbols.h in GNU glibc */
262
263 /* When a reference to SYMBOL is encountered, the linker will emit a
264 warning message MSG. */
265
266 #define ASM_NAME(name) __SYMBOL_PREFIX name
267
268 #ifdef HAVE_GNU_LD
269 # ifdef HAVE_ELF
270
271 /* We want the .gnu.warning.SYMBOL section to be unallocated. */
272 # ifdef HAVE_ASM_PREVIOUS_DIRECTIVE
273 # define __make_section_unallocated(section_string) \
274 asm (".section " section_string "\n\t.previous");
275 # elif defined HAVE_ASM_POPSECTION_DIRECTIVE
276 # define __make_section_unallocated(section_string) \
277 asm (".pushsection " section_string "\n\t.popsection");
278 # else
279 # define __make_section_unallocated(section_string)
280 # endif
281
282 /* Tacking on "\n\t#" to the section name makes gcc put it's bogus
283 section attributes on what looks like a comment to the assembler. */
284 # ifdef HAVE_SECTION_QUOTES
285 # define link_warning(symbol, msg) \
286 __make_section_unallocated (".gnu.warning." ASM_NAME(#symbol)) \
287 static const char __evoke_link_warning_##symbol[] \
288 __attribute__ ((section (".gnu.warning." ASM_NAME(#symbol) "\"\n\t#\""))) = msg;
289 # else
290 # define link_warning(symbol, msg) \
291 __make_section_unallocated (".gnu.warning." ASM_NAME(#symbol)) \
292 static const char __evoke_link_warning_##symbol[] \
293 __attribute__ ((section (".gnu.warning." ASM_NAME(#symbol) "\n\t#"))) = msg;
294 # endif
295 # else
296 # define link_warning(symbol, msg) \
297 asm (".stabs \"" msg "\",30,0,0,0\n\t" \
298 ".stabs \"" ASM_NAME(#symbol) "\",1,0,0,0\n");
299 # endif
300 #else
301 /* We will never be heard; they will all die horribly. */
302 # define link_warning(symbol, msg)
303 #endif
304
snd_open_device(const char * filename,int fmode)305 static inline int snd_open_device(const char *filename, int fmode)
306 {
307 int fd;
308
309 #ifdef O_CLOEXEC
310 fmode |= O_CLOEXEC;
311 #endif
312 fd = open(filename, fmode);
313
314 /* open with resmgr */
315 #ifdef SUPPORT_RESMGR
316 if (fd < 0) {
317 if (errno == EAGAIN || errno == EBUSY)
318 return fd;
319 if (! access(filename, F_OK))
320 fd = rsm_open_device(filename, fmode);
321 }
322 #endif
323 #ifndef O_CLOEXEC
324 if (fd >= 0)
325 fcntl(fd, F_SETFD, FD_CLOEXEC);
326 #endif
327 return fd;
328 }
329
330 /* make local functions really local */
331 #define snd_dlobj_cache_get \
332 snd1_dlobj_cache_get
333 #define snd_dlobj_cache_get2 \
334 snd1_dlobj_cache_get2
335 #define snd_dlobj_cache_put \
336 snd1_dlobj_cache_put
337 #define snd_dlobj_cache_cleanup \
338 snd1_dlobj_cache_cleanup
339 #define snd_config_set_hop \
340 snd1_config_set_hop
341 #define snd_config_check_hop \
342 snd1_config_check_hop
343 #define snd_config_search_alias_hooks \
344 snd1_config_search_alias_hooks
345
346 /* dlobj cache */
347 void *snd_dlobj_cache_get(const char *lib, const char *name, const char *version, int verbose);
348 void *snd_dlobj_cache_get2(const char *lib, const char *name, const char *version, int verbose);
349 int snd_dlobj_cache_put(void *open_func);
350 void snd_dlobj_cache_cleanup(void);
351
352 /* for recursive checks */
353 void snd_config_set_hop(snd_config_t *conf, int hop);
354 int snd_config_check_hop(snd_config_t *conf);
355 #define SND_CONF_MAX_HOPS 64
356
357 int snd_config_search_alias_hooks(snd_config_t *config,
358 const char *base, const char *key,
359 snd_config_t **result);
360
361 int _snd_conf_generic_id(const char *id);
362
363 int _snd_config_load_with_include(snd_config_t *config, snd_input_t *in,
364 int override, const char * const *default_include_path);
365
366 /* convenience macros */
367 #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
368
369 #define container_of(ptr, type, member) ({ \
370 const typeof( ((type *)0)->member ) *__mptr = (ptr); \
371 (type *)( (char *)__mptr - offsetof(type,member) );})
372
373 #ifdef INTERNAL
374 void *INTERNAL(snd_dlopen)(const char *name, int mode, char *errbuf, size_t errbuflen);
375 #endif
376
377 #endif
378