Blame include/local.h

Packit 4a16fb
/*
Packit 4a16fb
 *  ALSA lib - local header file
Packit 4a16fb
 *  Copyright (c) 2000 by Abramo Bagnara <abramo@alsa-project.org>
Packit 4a16fb
 *
Packit 4a16fb
 *
Packit 4a16fb
 *   This library is free software; you can redistribute it and/or modify
Packit 4a16fb
 *   it under the terms of the GNU Lesser General Public License as
Packit 4a16fb
 *   published by the Free Software Foundation; either version 2.1 of
Packit 4a16fb
 *   the License, or (at your option) any later version.
Packit 4a16fb
 *
Packit 4a16fb
 *   This program is distributed in the hope that it will be useful,
Packit 4a16fb
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 4a16fb
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 4a16fb
 *   GNU Lesser General Public License for more details.
Packit 4a16fb
 *
Packit 4a16fb
 *   You should have received a copy of the GNU Lesser General Public
Packit 4a16fb
 *   License along with this library; if not, write to the Free Software
Packit 4a16fb
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit 4a16fb
 *
Packit 4a16fb
 */
Packit 4a16fb
Packit 4a16fb
#ifndef __LOCAL_H
Packit 4a16fb
#define __LOCAL_H
Packit 4a16fb
Packit 4a16fb
#include "config.h"
Packit 4a16fb
Packit 4a16fb
#include <unistd.h>
Packit 4a16fb
#include <stdio.h>
Packit 4a16fb
#include <stdlib.h>
Packit 4a16fb
#include <string.h>
Packit 4a16fb
#include <fcntl.h>
Packit 4a16fb
#include <assert.h>
Packit 4a16fb
#ifdef HAVE_ENDIAN_H
Packit 4a16fb
#include <endian.h>
Packit 4a16fb
#elif defined(HAVE_SYS_ENDIAN_H)
Packit 4a16fb
#include <sys/endian.h>
Packit 4a16fb
#ifndef __BYTE_ORDER
Packit 4a16fb
#define __BYTE_ORDER BYTE_ORDER
Packit 4a16fb
#endif
Packit 4a16fb
#ifndef __LITTLE_ENDIAN
Packit 4a16fb
#define __LITTLE_ENDIAN LITTLE_ENDIAN
Packit 4a16fb
#endif
Packit 4a16fb
#ifndef __BIG_ENDIAN
Packit 4a16fb
#define __BIG_ENDIAN BIG_ENDIAN
Packit 4a16fb
#endif
Packit 4a16fb
#else
Packit 4a16fb
#error Header defining endianness not defined
Packit 4a16fb
#endif
Packit 4a16fb
#include <stdarg.h>
Packit 4a16fb
#include <poll.h>
Packit 4a16fb
#include <sys/types.h>
Packit 4a16fb
#include <errno.h>
Packit 4a16fb
#if defined(__linux__)
Packit 4a16fb
#include <linux/types.h>
Packit 4a16fb
#include <linux/ioctl.h>
Packit 4a16fb
#else
Packit 4a16fb
#include "type_compat.h"
Packit 4a16fb
#endif
Packit 4a16fb
Packit 4a16fb
#ifdef SUPPORT_RESMGR
Packit 4a16fb
#include <resmgr.h>
Packit 4a16fb
#endif
Packit 4a16fb
#ifdef HAVE_LIBDL
Packit 4a16fb
#include <dlfcn.h>
Packit 4a16fb
#else
Packit 4a16fb
#define RTLD_NOW	0
Packit 4a16fb
#endif
Packit 4a16fb
Packit 4a16fb
#if __BYTE_ORDER == __LITTLE_ENDIAN
Packit 4a16fb
#define SND_LITTLE_ENDIAN
Packit 4a16fb
#define SNDRV_LITTLE_ENDIAN
Packit 4a16fb
#elif __BYTE_ORDER == __BIG_ENDIAN
Packit 4a16fb
#define SND_BIG_ENDIAN
Packit 4a16fb
#define SNDRV_BIG_ENDIAN
Packit 4a16fb
#else
Packit 4a16fb
#error "Unsupported endian..."
Packit 4a16fb
#endif
Packit 4a16fb
Packit 4a16fb
#define _snd_config_iterator list_head
Packit 4a16fb
#define _snd_interval snd_interval
Packit 4a16fb
#define _snd_pcm_info snd_pcm_info
Packit 4a16fb
#define _snd_pcm_hw_params snd_pcm_hw_params
Packit 4a16fb
#define _snd_pcm_sw_params snd_pcm_sw_params
Packit 4a16fb
#define _snd_pcm_status snd_pcm_status
Packit 4a16fb
Packit 4a16fb
#define _snd_ctl_card_info snd_ctl_card_info
Packit 4a16fb
#define _snd_ctl_elem_id snd_ctl_elem_id
Packit 4a16fb
#define _snd_ctl_elem_list snd_ctl_elem_list
Packit 4a16fb
#define _snd_ctl_elem_info snd_ctl_elem_info
Packit 4a16fb
#define _snd_ctl_elem_value snd_ctl_elem_value
Packit 4a16fb
#define _snd_ctl_event snd_ctl_event
Packit 4a16fb
Packit 4a16fb
#define _snd_rawmidi_info snd_rawmidi_info
Packit 4a16fb
#define _snd_rawmidi_params snd_rawmidi_params
Packit 4a16fb
#define _snd_rawmidi_status snd_rawmidi_status
Packit 4a16fb
Packit 4a16fb
#define _snd_hwdep_info snd_hwdep_info
Packit 4a16fb
#define _snd_hwdep_dsp_status snd_hwdep_dsp_status
Packit 4a16fb
#define _snd_hwdep_dsp_image snd_hwdep_dsp_image
Packit 4a16fb
Packit 4a16fb
#define _snd_seq_queue_tempo snd_seq_queue_tempo
Packit 4a16fb
#define _snd_seq_client_info snd_seq_client_info
Packit 4a16fb
#define _snd_seq_port_info snd_seq_port_info
Packit 4a16fb
#define _snd_seq_system_info snd_seq_system_info
Packit 4a16fb
#define _snd_seq_queue_info snd_seq_queue_info
Packit 4a16fb
#define _snd_seq_queue_status snd_seq_queue_status
Packit 4a16fb
#define _snd_seq_queue_timer snd_seq_queue_timer
Packit 4a16fb
#define _snd_seq_port_subscribe snd_seq_port_subscribe
Packit 4a16fb
#define _snd_seq_query_subscribe snd_seq_query_subs
Packit 4a16fb
#define _snd_seq_client_pool snd_seq_client_pool
Packit 4a16fb
#define _snd_seq_remove_events snd_seq_remove_events
Packit 4a16fb
Packit 4a16fb
#define _snd_timer_id snd_timer_id
Packit 4a16fb
#define _snd_timer_ginfo snd_timer_ginfo
Packit 4a16fb
#define _snd_timer_gparams snd_timer_gparams
Packit 4a16fb
#define _snd_timer_gstatus snd_timer_gstatus
Packit 4a16fb
#define _snd_timer_select snd_timer_select
Packit 4a16fb
#define _snd_timer_info snd_timer_info
Packit 4a16fb
#define _snd_timer_params snd_timer_params
Packit 4a16fb
#define _snd_timer_status snd_timer_status
Packit 4a16fb
Packit 4a16fb
#define ALSA_LIBRARY_BUILD
Packit 4a16fb
Packit 4a16fb
/* rename some types for avoiding conflicts with alsalib's definitions */
Packit 4a16fb
#define snd_aes_iec958		sndrv_aes_iec958
Packit 4a16fb
#define snd_pcm_uframes_t	sndrv_pcm_uframes_t
Packit 4a16fb
#define snd_pcm_sframes_t	sndrv_pcm_sframes_t
Packit 4a16fb
#define snd_pcm_access_t	sndrv_pcm_access_t
Packit 4a16fb
#define snd_pcm_format_t	sndrv_pcm_format_t
Packit 4a16fb
#define snd_pcm_subformat_t	sndrv_pcm_subformat_t
Packit 4a16fb
#define snd_pcm_state_t		sndrv_pcm_state_t
Packit 4a16fb
#define snd_interval		sndrv_interval
Packit 4a16fb
#define snd_mask		sndrv_mask
Packit 4a16fb
#define snd_ctl_elem_type_t	sndrv_ctl_elem_type_t
Packit 4a16fb
#define snd_ctl_elem_iface_t	sndrv_ctl_elem_iface_t
Packit 4a16fb
#define snd_ctl_tlv		sndrv_ctl_tlv
Packit 4a16fb
Packit 4a16fb
/* kill and replace kernel-specific types */
Packit 4a16fb
#ifndef __user
Packit 4a16fb
#define __user
Packit 4a16fb
#endif
Packit 4a16fb
#ifndef __force
Packit 4a16fb
#define __force
Packit 4a16fb
#endif
Packit 4a16fb
Packit 4a16fb
#include <sound/asound.h>
Packit 4a16fb
Packit 4a16fb
/* take back superfluous renames; some can be kept as is */
Packit 4a16fb
#undef snd_aes_iec958
Packit 4a16fb
#undef snd_pcm_uframes_t
Packit 4a16fb
#undef snd_pcm_sframes_t
Packit 4a16fb
#undef snd_pcm_access_t
Packit 4a16fb
#undef snd_pcm_format_t
Packit 4a16fb
#undef snd_pcm_subformat_t
Packit 4a16fb
#undef snd_pcm_state_t
Packit 4a16fb
#undef snd_ctl_elem_type_t
Packit 4a16fb
#undef snd_ctl_elem_iface_t
Packit 4a16fb
Packit 4a16fb
#include "asoundef.h"
Packit 4a16fb
#include "alsa-symbols.h"
Packit 4a16fb
#include "version.h"
Packit 4a16fb
#include "global.h"
Packit 4a16fb
#include "input.h"
Packit 4a16fb
#include "output.h"
Packit 4a16fb
#include "error.h"
Packit 4a16fb
#include "conf.h"
Packit 4a16fb
#include "pcm.h"
Packit 4a16fb
#include "pcm_plugin.h"
Packit 4a16fb
#include "rawmidi.h"
Packit 4a16fb
#include "timer.h"
Packit 4a16fb
#include "hwdep.h"
Packit 4a16fb
#include "control.h"
Packit 4a16fb
#include "mixer.h"
Packit 4a16fb
#include "seq_event.h"
Packit 4a16fb
#include "seq.h"
Packit 4a16fb
Packit 4a16fb
/* rename some types for avoiding conflicts with alsalib's definitions */
Packit 4a16fb
#define snd_seq_addr		sndrv_seq_addr
Packit 4a16fb
#define snd_seq_tick_time_t	sndrv_seq_tick_time_t
Packit 4a16fb
#define snd_seq_real_time	sndrv_seq_real_time
Packit 4a16fb
#define snd_seq_timestamp	sndrv_seq_timestamp
Packit 4a16fb
#define snd_seq_event_type_t	sndrv_seq_event_type_t
Packit 4a16fb
#define snd_seq_event		sndrv_seq_event
Packit 4a16fb
#define snd_seq_connect		sndrv_seq_connect
Packit 4a16fb
#define snd_seq_ev_note		sndrv_seq_ev_note
Packit 4a16fb
#define snd_seq_ev_ctrl		sndrv_seq_ev_ctrl
Packit 4a16fb
#define snd_seq_ev_raw8		sndrv_seq_ev_raw8
Packit 4a16fb
#define snd_seq_ev_raw32	sndrv_seq_ev_raw32
Packit 4a16fb
#define snd_seq_ev_ext		sndrv_seq_ev_ext
Packit 4a16fb
#define snd_seq_result		sndrv_seq_result
Packit 4a16fb
#define snd_seq_queue_skew	sndrv_seq_queue_skew
Packit 4a16fb
#define snd_seq_ev_queue_control	sndrv_seq_ev_queue_control
Packit 4a16fb
#define snd_seq_client_t	sndrv_seq_client_t
Packit 4a16fb
#define snd_seq_client_type_t	sndrv_seq_client_type_t
Packit 4a16fb
Packit 4a16fb
#include <sound/asequencer.h>
Packit 4a16fb
Packit 4a16fb
/* take back some renames */
Packit 4a16fb
#undef snd_seq_client_t
Packit 4a16fb
#undef snd_seq_client_type_t
Packit 4a16fb
Packit 4a16fb
#include "seqmid.h"
Packit 4a16fb
#include "seq_midi_event.h"
Packit 4a16fb
#include "list.h"
Packit 4a16fb
Packit 4a16fb
struct _snd_async_handler {
Packit 4a16fb
	enum {
Packit 4a16fb
		SND_ASYNC_HANDLER_GENERIC,
Packit 4a16fb
		SND_ASYNC_HANDLER_CTL,
Packit 4a16fb
		SND_ASYNC_HANDLER_PCM,
Packit 4a16fb
		SND_ASYNC_HANDLER_TIMER,
Packit 4a16fb
	} type;
Packit 4a16fb
	int fd;
Packit 4a16fb
	union {
Packit 4a16fb
		snd_ctl_t *ctl;
Packit 4a16fb
		snd_pcm_t *pcm;
Packit 4a16fb
		snd_timer_t *timer;
Packit 4a16fb
	} u;
Packit 4a16fb
	snd_async_callback_t callback;
Packit 4a16fb
	void *private_data;
Packit 4a16fb
	struct list_head glist;
Packit 4a16fb
	struct list_head hlist;
Packit 4a16fb
};
Packit 4a16fb
Packit 4a16fb
typedef enum _snd_set_mode {
Packit 4a16fb
	SND_CHANGE,
Packit 4a16fb
	SND_TRY,
Packit 4a16fb
	SND_TEST,
Packit 4a16fb
} snd_set_mode_t;
Packit 4a16fb
Packit 4a16fb
size_t page_align(size_t size);
Packit 4a16fb
size_t page_size(void);
Packit 4a16fb
size_t page_ptr(size_t object_offset, size_t object_size, size_t *offset, size_t *mmap_offset);
Packit 4a16fb
Packit 4a16fb
int safe_strtol(const char *str, long *val);
Packit 4a16fb
Packit 4a16fb
int snd_send_fd(int sock, void *data, size_t len, int fd);
Packit 4a16fb
int snd_receive_fd(int sock, void *data, size_t len, int *fd);
Packit 4a16fb
size_t snd_strlcpy(char *dst, const char *src, size_t size);
Packit 4a16fb
Packit 4a16fb
/*
Packit 4a16fb
 * error messages
Packit 4a16fb
 */
Packit 4a16fb
#ifndef NDEBUG
Packit 4a16fb
#define CHECK_SANITY(x) x
Packit 4a16fb
extern snd_lib_error_handler_t snd_err_msg;
Packit 4a16fb
#define SNDMSG(args...) snd_err_msg(__FILE__, __LINE__, __func__, 0, ##args)
Packit 4a16fb
#define SYSMSG(args...) snd_err_msg(__FILE__, __LINE__, __func__, errno, ##args)
Packit 4a16fb
#else
Packit 4a16fb
#define CHECK_SANITY(x) 0 /* not evaluated */
Packit 4a16fb
#define SNDMSG(args...) /* nop */
Packit 4a16fb
#define SYSMSG(args...) /* nop */
Packit 4a16fb
#endif
Packit 4a16fb
Packit 4a16fb
/*
Packit 4a16fb
 */
Packit 4a16fb
#define HAVE_GNU_LD
Packit 4a16fb
#define HAVE_ELF
Packit 4a16fb
#define HAVE_ASM_PREVIOUS_DIRECTIVE
Packit 4a16fb
Packit 4a16fb
/* Stolen from libc-symbols.h in GNU glibc */
Packit 4a16fb
Packit 4a16fb
/* When a reference to SYMBOL is encountered, the linker will emit a
Packit 4a16fb
   warning message MSG.  */
Packit 4a16fb
Packit 4a16fb
#define ASM_NAME(name) __SYMBOL_PREFIX name
Packit 4a16fb
Packit 4a16fb
#ifdef HAVE_GNU_LD
Packit 4a16fb
# ifdef HAVE_ELF
Packit 4a16fb
Packit 4a16fb
/* We want the .gnu.warning.SYMBOL section to be unallocated.  */
Packit 4a16fb
#  ifdef HAVE_ASM_PREVIOUS_DIRECTIVE
Packit 4a16fb
#   define __make_section_unallocated(section_string)	\
Packit 4a16fb
  asm (".section " section_string "\n\t.previous");
Packit 4a16fb
#  elif defined HAVE_ASM_POPSECTION_DIRECTIVE
Packit 4a16fb
#   define __make_section_unallocated(section_string)	\
Packit 4a16fb
  asm (".pushsection " section_string "\n\t.popsection");
Packit 4a16fb
#  else
Packit 4a16fb
#   define __make_section_unallocated(section_string)
Packit 4a16fb
#  endif
Packit 4a16fb
Packit 4a16fb
/* Tacking on "\n\t#" to the section name makes gcc put it's bogus
Packit 4a16fb
   section attributes on what looks like a comment to the assembler.  */
Packit 4a16fb
#  ifdef HAVE_SECTION_QUOTES
Packit 4a16fb
#   define link_warning(symbol, msg) \
Packit 4a16fb
  __make_section_unallocated (".gnu.warning." ASM_NAME(#symbol)) \
Packit 4a16fb
  static const char __evoke_link_warning_##symbol[]	\
Packit 4a16fb
    __attribute__ ((section (".gnu.warning." ASM_NAME(#symbol) "\"\n\t#\""))) = msg;
Packit 4a16fb
#  else
Packit 4a16fb
#   define link_warning(symbol, msg) \
Packit 4a16fb
  __make_section_unallocated (".gnu.warning." ASM_NAME(#symbol)) \
Packit 4a16fb
  static const char __evoke_link_warning_##symbol[]	\
Packit 4a16fb
    __attribute__ ((section (".gnu.warning." ASM_NAME(#symbol) "\n\t#"))) = msg;
Packit 4a16fb
#  endif
Packit 4a16fb
# else
Packit 4a16fb
#  define link_warning(symbol, msg)		\
Packit 4a16fb
  asm (".stabs \"" msg "\",30,0,0,0\n\t"	\
Packit 4a16fb
       ".stabs \"" ASM_NAME(#symbol) "\",1,0,0,0\n");
Packit 4a16fb
# endif
Packit 4a16fb
#else
Packit 4a16fb
/* We will never be heard; they will all die horribly.  */
Packit 4a16fb
# define link_warning(symbol, msg)
Packit 4a16fb
#endif
Packit 4a16fb
Packit 4a16fb
static inline int snd_open_device(const char *filename, int fmode)
Packit 4a16fb
{
Packit 4a16fb
	int fd;
Packit 4a16fb
Packit 4a16fb
#ifdef O_CLOEXEC
Packit 4a16fb
	fmode |= O_CLOEXEC;
Packit 4a16fb
#endif
Packit 4a16fb
	fd = open(filename, fmode);
Packit 4a16fb
Packit 4a16fb
/* open with resmgr */
Packit 4a16fb
#ifdef SUPPORT_RESMGR
Packit 4a16fb
	if (fd < 0) {
Packit 4a16fb
		if (errno == EAGAIN || errno == EBUSY)
Packit 4a16fb
			return fd;
Packit 4a16fb
		if (! access(filename, F_OK))
Packit 4a16fb
			fd = rsm_open_device(filename, fmode);
Packit 4a16fb
	}
Packit 4a16fb
#endif
Packit 4a16fb
	if (fd >= 0)
Packit 4a16fb
		fcntl(fd, F_SETFD, FD_CLOEXEC);
Packit 4a16fb
	return fd;
Packit 4a16fb
}
Packit 4a16fb
Packit 4a16fb
/* make local functions really local */
Packit 4a16fb
#define snd_dlobj_cache_get \
Packit 4a16fb
	snd1_dlobj_cache_get
Packit 4a16fb
#define snd_dlobj_cache_get2 \
Packit 4a16fb
	snd1_dlobj_cache_get2
Packit 4a16fb
#define snd_dlobj_cache_put \
Packit 4a16fb
	snd1_dlobj_cache_put
Packit 4a16fb
#define snd_dlobj_cache_cleanup \
Packit 4a16fb
	snd1_dlobj_cache_cleanup
Packit 4a16fb
#define snd_config_set_hop \
Packit 4a16fb
	snd1_config_set_hop
Packit 4a16fb
#define snd_config_check_hop \
Packit 4a16fb
	snd1_config_check_hop
Packit 4a16fb
#define snd_config_search_alias_hooks \
Packit 4a16fb
	snd1_config_search_alias_hooks
Packit 4a16fb
Packit 4a16fb
/* dlobj cache */
Packit 4a16fb
void *snd_dlobj_cache_get(const char *lib, const char *name, const char *version, int verbose);
Packit 4a16fb
void *snd_dlobj_cache_get2(const char *lib, const char *name, const char *version, int verbose);
Packit 4a16fb
int snd_dlobj_cache_put(void *open_func);
Packit 4a16fb
void snd_dlobj_cache_cleanup(void);
Packit 4a16fb
Packit 4a16fb
/* for recursive checks */
Packit 4a16fb
void snd_config_set_hop(snd_config_t *conf, int hop);
Packit 4a16fb
int snd_config_check_hop(snd_config_t *conf);
Packit 4a16fb
#define SND_CONF_MAX_HOPS	64
Packit 4a16fb
Packit 4a16fb
int snd_config_search_alias_hooks(snd_config_t *config,
Packit 4a16fb
                                  const char *base, const char *key,
Packit 4a16fb
				  snd_config_t **result);
Packit 4a16fb
Packit 4a16fb
int _snd_conf_generic_id(const char *id);
Packit 4a16fb
Packit 4a16fb
int _snd_config_load_with_include(snd_config_t *config, snd_input_t *in,
Packit 4a16fb
				  int override, const char * const *default_include_path);
Packit 4a16fb
Packit 4a16fb
/* convenience macros */
Packit 4a16fb
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
Packit 4a16fb
Packit 4a16fb
#define container_of(ptr, type, member) ({                      \
Packit 4a16fb
	 const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
Packit 4a16fb
	(type *)( (char *)__mptr - offsetof(type,member) );})
Packit 4a16fb
Packit 4a16fb
#ifdef INTERNAL
Packit 4a16fb
void *INTERNAL(snd_dlopen)(const char *name, int mode, char *errbuf, size_t errbuflen);
Packit 4a16fb
#endif
Packit 4a16fb
Packit 4a16fb
#endif