1 /*****************************************************************************
2 * common.h: common definitions
3 * Collection of useful common types and macros definitions
4 *****************************************************************************
5 * Copyright (C) 1998, 1999, 2000 VideoLAN
6 * $Id: common.h,v 1.23 2001/01/11 15:35:35 sam Exp $
8 * Authors: Samuel Hocevar <sam@via.ecp.fr>
9 * Vincent Seguin <seguin@via.ecp.fr>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
24 *****************************************************************************/
26 /*****************************************************************************
29 *****************************************************************************/
31 /*****************************************************************************
32 * Basic types definitions
33 *****************************************************************************/
35 #include "int_types.h"
40 #ifdef BOOLEAN_T_IN_SYS_TYPES_H
41 # include <sys/types.h>
43 typedef int boolean_t;
46 # define _MACH_I386_BOOLEAN_H_
49 /* ptrdiff_t definition */
56 /* Not portable in a 64-bit environment. */
57 typedef int ptrdiff_t;
61 /* Counter for statistics and profiling */
62 typedef unsigned long count_t;
64 /*****************************************************************************
66 *****************************************************************************/
72 typedef struct plugin_bank_s * p_plugin_bank_t;
73 typedef struct plugin_info_s * p_plugin_info_t;
78 typedef struct playlist_s * p_playlist_t;
83 struct intf_console_s;
85 struct intf_channel_s;
87 typedef struct intf_thread_s * p_intf_thread_t;
88 typedef struct intf_sys_s * p_intf_sys_t;
89 typedef struct intf_console_s * p_intf_console_t;
90 typedef struct intf_msg_s * p_intf_msg_t;
91 typedef struct intf_channel_s * p_intf_channel_t;
94 struct input_thread_s;
98 typedef struct input_thread_s * p_input_thread_t;
99 typedef struct input_vlan_s * p_input_vlan_t;
100 typedef struct input_cfg_s * p_input_cfg_t;
103 struct aout_thread_s;
106 typedef struct aout_thread_s * p_aout_thread_t;
107 typedef struct aout_sys_s * p_aout_sys_t;
110 struct vout_thread_s;
113 struct vdec_thread_s;
114 struct vpar_thread_s;
115 struct video_parser_s;
117 typedef struct vout_thread_s * p_vout_thread_t;
118 typedef struct vout_font_s * p_vout_font_t;
119 typedef struct vout_sys_s * p_vout_sys_t;
120 typedef struct vdec_thread_s * p_vdec_thread_t;
121 typedef struct vpar_thread_s * p_vpar_thread_t;
122 typedef struct video_parser_s * p_video_parser_t;
124 /*****************************************************************************
125 * Macros and inline functions
126 *****************************************************************************/
128 #ifdef NTOHL_IN_SYS_PARAM_H
129 # include <sys/param.h>
131 # include <netinet/in.h>
134 /* CEIL: division with round to nearest greater integer */
135 #define CEIL(n, d) ( ((n) / (d)) + ( ((n) % (d)) ? 1 : 0) )
137 /* PAD: PAD(n, d) = CEIL(n ,d) * d */
138 #define PAD(n, d) ( ((n) % (d)) ? ((((n) / (d)) + 1) * (d)) : (n) )
140 /* MAX and MIN: self explanatory */
142 #define MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
145 #define MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
149 * This is stolen from the livid source who stole it from the kernel
152 #if defined(SYS_BEOS)
153 # define swab32(x) B_BENDIAN_TO_HOST_INT32(x)
155 # ifdef WORDS_BIG_ENDIAN
156 # define swab32(x) (x)
158 # if defined (HAVE_X86_BSWAP)
159 static __inline__ const u32 __i386_swab32( u32 x )
161 __asm__("bswap %0" : "=r" (x) : "0" (x));
164 # define swab32(x) __i386_swab32(x)
167 ( ( (u32)(((u8*)&x)[0]) << 24 ) | ( (u32)(((u8*)&x)[1]) << 16 ) |\
168 ( (u32)(((u8*)&x)[2]) << 8 ) | ( (u32)(((u8*)&x)[3])) )
173 /* MSB (big endian)/LSB (little endian) conversions - network order is always
174 * MSB, and should be used for both network communications and files. Note that
175 * byte orders other than little and big endians are not supported, but only
176 * the VAX seems to have such exotic properties - note that these 'functions'
177 * needs <netinet/in.h> or the local equivalent. */
178 /* FIXME: hton64 should be declared as an extern inline function to avoid
179 * border effects (see byteorder.h) */
183 #define hton64(i) ( i )
186 #define ntoh64(i) ( i )
190 #define hton64(i) ( ((u64)(htonl((i) & 0xffffffff)) << 32) | htonl(((i) >> 32) & 0xffffffff ) )
193 #define ntoh64 hton64
196 /* Macros with automatic casts */
197 #define U32_AT(p) ( swab32 ( *( (u32 *)(p) ) ) )
198 #define U16_AT(p) ( ntohs ( *( (u16 *)(p) ) ) )