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: vlc_common.h,v 1.9 2002/07/12 21:57:25 massiot Exp $
8 * Authors: Samuel Hocevar <sam@via.ecp.fr>
9 * Vincent Seguin <seguin@via.ecp.fr>
10 * Gildas Bazin <gbazin@netcourrier.com>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
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 General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
25 *****************************************************************************/
27 /*****************************************************************************
28 * Compiler-specific workarounds
29 *****************************************************************************/
30 #if defined( __BORLANDC__ )
31 # undef HAVE_VARIADIC_MACROS
35 /*****************************************************************************
36 * Required system headers
37 *****************************************************************************/
39 # include <string.h> /* strerror() */
42 #ifdef HAVE_SYS_TYPES_H
43 # include <sys/types.h>
46 /*****************************************************************************
47 * Basic types definitions
48 *****************************************************************************/
63 typedef unsigned char u8;
64 typedef signed char s8;
66 typedef unsigned short u16;
67 typedef signed short s16;
69 typedef unsigned int u32;
70 typedef signed int s32;
72 # if defined( _MSC_VER ) || ( defined( WIN32 ) && !defined( __MINGW32__ ) )
73 typedef unsigned __int64 u64;
74 typedef signed __int64 s64;
76 typedef unsigned long long u64;
77 typedef signed long long s64;
83 /* ptrdiff_t definition */
90 /* Not portable in a 64-bit environment. */
91 typedef int ptrdiff_t;
99 /* Counter for statistics and profiling */
100 typedef unsigned long count_t;
102 /* DCT elements types */
103 typedef s16 dctelem_t;
105 /* Video buffer types */
106 typedef u8 yuv_data_t;
108 /*****************************************************************************
109 * mtime_t: high precision date or time interval
110 *****************************************************************************
111 * Store an high precision date or time interval. The maximum precision is the
112 * micro-second, and a 64 bits integer is used to avoid any overflow (maximum
113 * time interval is then 292271 years, which should be long enough for any
114 * video). Date are stored as a time interval since a common date.
115 * Note that date and time intervals can be manipulated using regular
116 * arithmetic operators, and that no special functions are required.
117 *****************************************************************************/
120 /*****************************************************************************
121 * Classes declaration
122 *****************************************************************************/
125 VLC_DECLARE_STRUCT(msg_bank)
126 VLC_DECLARE_STRUCT(msg_subscription)
129 VLC_DECLARE_STRUCT(playlist)
130 VLC_DECLARE_STRUCT(playlist_item)
133 VLC_DECLARE_STRUCT(module_bank)
134 VLC_DECLARE_STRUCT(module)
135 VLC_DECLARE_STRUCT(module_config)
136 VLC_DECLARE_STRUCT(module_symbols)
137 VLC_DECLARE_STRUCT(module_functions)
140 VLC_DECLARE_STRUCT(intf_thread)
141 VLC_DECLARE_STRUCT(intf_sys)
142 VLC_DECLARE_STRUCT(intf_console)
143 VLC_DECLARE_STRUCT(intf_msg)
144 VLC_DECLARE_STRUCT(intf_channel)
147 VLC_DECLARE_STRUCT(input_thread)
148 VLC_DECLARE_STRUCT(input_channel)
149 VLC_DECLARE_STRUCT(input_cfg)
150 VLC_DECLARE_STRUCT(input_area)
151 VLC_DECLARE_STRUCT(input_buffers)
152 VLC_DECLARE_STRUCT(input_socket)
155 VLC_DECLARE_STRUCT(aout_thread)
156 VLC_DECLARE_STRUCT(aout_sys)
157 VLC_DECLARE_STRUCT(aout_fifo)
160 VLC_DECLARE_STRUCT(vout_thread)
161 VLC_DECLARE_STRUCT(vout_font)
162 VLC_DECLARE_STRUCT(vout_sys)
163 VLC_DECLARE_STRUCT(chroma_sys)
164 VLC_DECLARE_STRUCT(picture)
165 VLC_DECLARE_STRUCT(picture_sys)
166 VLC_DECLARE_STRUCT(picture_heap)
167 VLC_DECLARE_STRUCT(subpicture)
168 VLC_DECLARE_STRUCT(subpicture_sys)
171 VLC_DECLARE_STRUCT(decoder_fifo)
174 VLC_DECLARE_STRUCT(macroblock)
175 VLC_DECLARE_STRUCT(data_packet)
176 VLC_DECLARE_STRUCT(data_buffer)
177 VLC_DECLARE_STRUCT(downmix)
178 VLC_DECLARE_STRUCT(imdct)
179 VLC_DECLARE_STRUCT(complex)
180 VLC_DECLARE_STRUCT(dm_par)
181 VLC_DECLARE_STRUCT(es_descriptor)
182 VLC_DECLARE_STRUCT(pgrm_descriptor)
183 VLC_DECLARE_STRUCT(stream_descriptor)
184 VLC_DECLARE_STRUCT(stream_position)
185 VLC_DECLARE_STRUCT(stream_ctrl)
186 VLC_DECLARE_STRUCT(pes_packet)
187 VLC_DECLARE_STRUCT(bit_stream)
188 VLC_DECLARE_STRUCT(network_socket)
189 VLC_DECLARE_STRUCT(iso639_lang)
191 /*****************************************************************************
193 *****************************************************************************/
195 # define VLC_EXPORT( type, name, args ) type name args;
197 # define VLC_EXPORT( type, name, args ) ;
198 extern module_symbols_t* p_symbols;
201 /*****************************************************************************
202 * OS-specific headers and thread types
203 *****************************************************************************/
205 # define WIN32_LEAN_AND_MEAN
206 # include <windows.h>
209 #include "vlc_threads.h"
211 /*****************************************************************************
212 * Common structure members
213 *****************************************************************************/
215 /* VLC_COMMON_MEMBERS : members common to all basic vlc objects */
216 #define VLC_COMMON_MEMBERS \
219 char *psz_object_type; \
220 char *psz_object_name; \
222 /* Thread properties, if any */ \
223 vlc_bool_t b_thread; \
224 vlc_thread_t thread_id; \
226 /* Object access lock */ \
227 vlc_mutex_t object_lock; \
228 vlc_cond_t object_wait; \
230 volatile vlc_bool_t b_error; /* set by the object */ \
231 volatile vlc_bool_t b_die; /* set by the outside */ \
232 volatile vlc_bool_t b_dead; /* set by the object */ \
234 vlc_t * p_vlc; /* root of all evil */ \
236 volatile int i_refcount; \
237 vlc_object_t ** pp_parents; /* our parents */ \
238 volatile int i_parents; \
239 vlc_object_t ** pp_children; /* our children */ \
240 volatile int i_children; \
242 /* Just a reminder so that people don't cast garbage */ \
243 int be_sure_to_add_VLC_COMMON_MEMBERS_to_struct; \
245 /* The real vlc_object_t type. Yes, it's that simple :-) */
251 /* CAST_TO_VLC_OBJECT: attempt at doing a clever cast */
252 #define CAST_TO_VLC_OBJECT( x ) \
253 ((vlc_object_t *)(x))+0*(x)->be_sure_to_add_VLC_COMMON_MEMBERS_to_struct
255 /*****************************************************************************
256 * Macros and inline functions
257 *****************************************************************************/
258 #ifdef NTOHL_IN_SYS_PARAM_H
259 # include <sys/param.h>
261 #elif !defined(WIN32) /* NTOHL_IN_SYS_PARAM_H || WIN32 */
262 # include <netinet/in.h>
264 #endif /* NTOHL_IN_SYS_PARAM_H || WIN32 */
266 /* CEIL: division with round to nearest greater integer */
267 #define CEIL(n, d) ( ((n) / (d)) + ( ((n) % (d)) ? 1 : 0) )
269 /* PAD: PAD(n, d) = CEIL(n ,d) * d */
270 #define PAD(n, d) ( ((n) % (d)) ? ((((n) / (d)) + 1) * (d)) : (n) )
272 /* __MAX and __MIN: self explanatory */
274 # define __MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
277 # define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
280 /* MSB (big endian)/LSB (little endian) conversions - network order is always
281 * MSB, and should be used for both network communications and files. Note that
282 * byte orders other than little and big endians are not supported, but only
283 * the VAX seems to have such exotic properties. */
284 static inline u16 U16_AT( void * _p )
287 return ( ((u16)p[0] << 8) | p[1] );
289 static inline u32 U32_AT( void * _p )
292 return ( ((u32)p[0] << 24) | ((u32)p[1] << 16) | ((u32)p[2] << 8) | p[3] );
294 static inline u64 U64_AT( void * _p )
297 return ( ((u64)p[0] << 56) | ((u64)p[1] << 48) | ((u64)p[2] << 40)
298 | ((u64)p[3] << 32) | ((u64)p[4] << 24) | ((u64)p[5] << 16)
299 | ((u64)p[6] << 8) | p[7] );
302 # define hton16(i) ( i )
303 # define hton32(i) ( i )
304 # define hton64(i) ( i )
305 # define ntoh16(i) ( i )
306 # define ntoh32(i) ( i )
307 # define ntoh64(i) ( i )
309 # define hton16(i) U16_AT(&i)
310 # define hton32(i) U32_AT(&i)
311 # define hton64(i) U64_AT(&i)
312 # define ntoh16(i) U16_AT(&i)
313 # define ntoh32(i) U32_AT(&i)
314 # define ntoh64(i) U64_AT(&i)
317 /* Alignment of critical static data structures */
318 #ifdef ATTRIBUTE_ALIGNED_MAX
319 # define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
321 # define ATTR_ALIGN(align)
324 /* Alignment of critical dynamic data structure
326 * Not all platforms support memalign so we provide a vlc_memalign wrapper
327 * void *vlc_memalign( size_t align, size_t size, void **pp_orig )
328 * *pp_orig is the pointer that has to be freed afterwards.
331 #ifdef HAVE_POSIX_MEMALIGN
332 # define vlc_memalign(align,size,pp_orig) \
333 ( !posix_memalign( pp_orig, align, size ) ? *(pp_orig) : NULL )
337 /* Some systems have memalign() but no declaration for it */
338 void * memalign( size_t align, size_t size );
340 # define vlc_memalign(pp_orig,align,size) \
341 ( *(pp_orig) = memalign( align, size ) )
343 #else /* We don't have any choice but to align manually */
344 # define vlc_memalign(pp_orig,align,size) \
345 (( *(pp_orig) = malloc( size + align - 1 )) \
346 ? (void *)( (((unsigned long)*(pp_orig)) + (unsigned long)(align-1) ) \
347 & (~(unsigned long)(align-1)) ) \
352 /* strndup (defined in src/misc/extras.c) */
354 char * strndup( const char *s, size_t n );
358 #define I64C(x) x##LL
361 /* win32, cl and icl support */
362 # if defined( _MSC_VER ) || !defined( __MINGW32__ )
363 # define __attribute__(x)
364 # define __inline__ __inline
365 # define strncasecmp strnicmp
366 # define strcasecmp stricmp
367 # define S_IFBLK 0x3000 /* Block */
368 # define S_ISBLK(m) (0)
369 # define S_ISCHR(m) (0)
370 # define S_ISFIFO(m) (((m)&_S_IFMT) == _S_IFIFO)
371 # define S_ISREG(m) (((m)&_S_IFMT) == _S_IFREG)
373 # define I64C(x) x##i64
376 /* several type definitions */
377 # if defined( __MINGW32__ )
378 # if !defined( _OFF_T_ )
379 typedef long long _off_t;
380 typedef _off_t off_t;
383 # define off_t long long
387 # if defined( _MSC_VER )
388 # if !defined( _OFF_T_DEFINED )
389 typedef __int64 off_t;
390 # define _OFF_T_DEFINED
392 # define off_t __int64
396 # if defined( __BORLANDC__ )
398 # define off_t unsigned __int64
402 # define O_NONBLOCK 0
406 # define snprintf _snprintf /* snprintf not defined in mingw32 (bug?) */
411 /*****************************************************************************
413 *****************************************************************************/
414 #define CPU_CAPABILITY_NONE 0
415 #define CPU_CAPABILITY_486 (1<<0)
416 #define CPU_CAPABILITY_586 (1<<1)
417 #define CPU_CAPABILITY_PPRO (1<<2)
418 #define CPU_CAPABILITY_MMX (1<<3)
419 #define CPU_CAPABILITY_3DNOW (1<<4)
420 #define CPU_CAPABILITY_MMXEXT (1<<5)
421 #define CPU_CAPABILITY_SSE (1<<6)
422 #define CPU_CAPABILITY_ALTIVEC (1<<16)
423 #define CPU_CAPABILITY_FPU (1<<31)
425 /*****************************************************************************
427 *****************************************************************************/
428 #ifndef PACKAGE /* Borland C++ uses this ! */
429 #define PACKAGE VLC_PACKAGE
431 #define VERSION VLC_VERSION
433 #if defined( ENABLE_NLS ) && defined ( HAVE_GETTEXT ) && !defined( __BORLANDC__ ) && !defined( MODULE_NAME_IS_gnome )
434 # include <libintl.h>
436 # define _(String) dgettext (PACKAGE, String)
438 # define N_(String) gettext_noop (String)
440 # define N_(String) (String)
442 #elif !defined( MODULE_NAME_IS_gnome )
443 # define _(String) (String)
444 # define N_(String) (String)
447 /*****************************************************************************
449 *****************************************************************************/
450 #include "vlc_symbols.h"