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.26 2002/08/30 22:22:24 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 * Required vlc headers
29 *****************************************************************************/
30 #if defined( __BORLANDC__ )
36 #if defined( __BORLANDC__ )
37 # undef HAVE_VARIADIC_MACROS
41 #include "vlc_config.h"
42 #include "modules_inner.h"
44 /*****************************************************************************
45 * Required system headers
46 *****************************************************************************/
48 # include <string.h> /* strerror() */
51 #ifdef HAVE_SYS_TYPES_H
52 # include <sys/types.h>
55 /*****************************************************************************
56 * Basic types definitions
57 *****************************************************************************/
72 typedef unsigned char u8;
73 typedef signed char s8;
75 typedef unsigned short u16;
76 typedef signed short s16;
78 typedef unsigned int u32;
79 typedef signed int s32;
81 # if defined( _MSC_VER ) || ( defined( WIN32 ) && !defined( __MINGW32__ ) )
82 typedef unsigned __int64 u64;
83 typedef signed __int64 s64;
85 typedef unsigned long long u64;
86 typedef signed long long s64;
92 /* ptrdiff_t definition */
99 /* Not portable in a 64-bit environment. */
100 typedef int ptrdiff_t;
108 /* Counter for statistics and profiling */
109 typedef unsigned long count_t;
111 /* DCT elements types */
112 typedef s16 dctelem_t;
114 /* Video buffer types */
115 typedef u8 yuv_data_t;
117 /*****************************************************************************
118 * mtime_t: high precision date or time interval
119 *****************************************************************************
120 * Store an high precision date or time interval. The maximum precision is the
121 * micro-second, and a 64 bits integer is used to avoid any overflow (maximum
122 * time interval is then 292271 years, which should be long enough for any
123 * video). Date are stored as a time interval since a common date.
124 * Note that date and time intervals can be manipulated using regular
125 * arithmetic operators, and that no special functions are required.
126 *****************************************************************************/
129 /*****************************************************************************
130 * The vlc_fourcc_t type.
131 *****************************************************************************
132 * See http://www.webartz.com/fourcc/ for a very detailed list.
133 *****************************************************************************/
134 typedef u32 vlc_fourcc_t;
136 #ifdef WORDS_BIGENDIAN
137 # define VLC_FOURCC( a, b, c, d ) \
138 ( ((u32)d) | ( ((u32)c) << 8 ) | ( ((u32)b) << 16 ) | ( ((u32)a) << 24 ) )
139 # define VLC_TWOCC( a, b ) \
140 ( (u16)(b) | ( (u16)(a) << 8 ) )
143 # define VLC_FOURCC( a, b, c, d ) \
144 ( ((u32)a) | ( ((u32)b) << 8 ) | ( ((u32)c) << 16 ) | ( ((u32)d) << 24 ) )
145 # define VLC_TWOCC( a, b ) \
146 ( (u16)(a) | ( (u16)(b) << 8 ) )
150 /*****************************************************************************
151 * Classes declaration
152 *****************************************************************************/
155 typedef struct msg_bank_t msg_bank_t;
156 typedef struct msg_subscription_t msg_subscription_t;
159 typedef struct playlist_t playlist_t;
160 typedef struct playlist_item_t playlist_item_t;
163 typedef struct module_bank_t module_bank_t;
164 typedef struct module_t module_t;
165 typedef struct module_config_t module_config_t;
166 typedef struct module_symbols_t module_symbols_t;
169 typedef struct intf_thread_t intf_thread_t;
170 typedef struct intf_sys_t intf_sys_t;
171 typedef struct intf_console_t intf_console_t;
172 typedef struct intf_msg_t intf_msg_t;
173 typedef struct intf_channel_t intf_channel_t;
176 typedef struct input_thread_t input_thread_t;
177 typedef struct input_channel_t input_channel_t;
178 typedef struct input_area_t input_area_t;
179 typedef struct input_buffers_t input_buffers_t;
180 typedef struct input_socket_t input_socket_t;
181 typedef struct input_info_t input_info_t;
182 typedef struct input_info_category_t input_info_category_t;
183 typedef struct access_sys_t access_sys_t;
184 typedef struct demux_sys_t demux_sys_t;
185 typedef struct es_descriptor_t es_descriptor_t;
186 typedef struct es_sys_t es_sys_t;
187 typedef struct pgrm_descriptor_t pgrm_descriptor_t;
188 typedef struct pgrm_sys_t pgrm_sys_t;
189 typedef struct stream_descriptor_t stream_descriptor_t;
190 typedef struct stream_sys_t stream_sys_t;
193 typedef struct aout_instance_t aout_instance_t;
194 typedef struct aout_sys_t aout_sys_t;
195 typedef struct aout_fifo_t aout_fifo_t;
196 typedef struct aout_input_t aout_input_t;
197 typedef struct aout_buffer_t aout_buffer_t;
198 typedef struct audio_sample_format_t audio_sample_format_t;
199 typedef struct audio_date_t audio_date_t;
202 typedef struct vout_thread_t vout_thread_t;
203 typedef struct vout_font_t vout_font_t;
204 typedef struct vout_sys_t vout_sys_t;
205 typedef struct chroma_sys_t chroma_sys_t;
206 typedef struct picture_t picture_t;
207 typedef struct picture_sys_t picture_sys_t;
208 typedef struct picture_heap_t picture_heap_t;
209 typedef struct subpicture_t subpicture_t;
210 typedef struct subpicture_sys_t subpicture_sys_t;
213 typedef struct sout_instance_t sout_instance_t;
214 typedef struct sout_fifo_t sout_fifo_t;
217 typedef struct decoder_fifo_t decoder_fifo_t;
220 typedef struct data_packet_t data_packet_t;
221 typedef struct data_buffer_t data_buffer_t;
222 typedef struct stream_position_t stream_position_t;
223 typedef struct stream_ctrl_t stream_ctrl_t;
224 typedef struct pes_packet_t pes_packet_t;
225 typedef struct bit_stream_t bit_stream_t;
226 typedef struct network_socket_t network_socket_t;
227 typedef struct iso639_lang_t iso639_lang_t;
229 /*****************************************************************************
231 *****************************************************************************/
233 # define VLC_EXPORT( type, name, args ) type name args
235 # define VLC_EXPORT( type, name, args ) struct _u_n_u_s_e_d_
236 extern module_symbols_t* p_symbols;
239 /*****************************************************************************
240 * OS-specific headers and thread types
241 *****************************************************************************/
243 # define WIN32_LEAN_AND_MEAN
244 # include <windows.h>
247 #include "vlc_threads.h"
249 /*****************************************************************************
250 * Common structure members
251 *****************************************************************************/
253 /* VLC_COMMON_MEMBERS : members common to all basic vlc objects */
254 #define VLC_COMMON_MEMBERS \
257 char *psz_object_type; \
258 char *psz_object_name; \
260 /* Thread properties, if any */ \
261 vlc_bool_t b_thread; \
262 vlc_thread_t thread_id; \
264 /* Object access lock */ \
265 vlc_mutex_t object_lock; \
266 vlc_cond_t object_wait; \
268 volatile vlc_bool_t b_error; /* set by the object */ \
269 volatile vlc_bool_t b_die; /* set by the outside */ \
270 volatile vlc_bool_t b_dead; /* set by the object */ \
271 volatile vlc_bool_t b_attached; /* set by the object */ \
273 vlc_t * p_vlc; /* root of all evil */ \
275 volatile int i_refcount; /* usage count */ \
276 vlc_object_t * p_parent; /* our parent */ \
277 vlc_object_t ** pp_children; /* our children */ \
278 volatile int i_children; \
283 /* Just a reminder so that people don't cast garbage */ \
284 int be_sure_to_add_VLC_COMMON_MEMBERS_to_struct; \
286 /* The real vlc_object_t type. Yes, it's that simple :-) */
292 /* The object list */
296 vlc_object_t ** pp_objects;
300 vlc_object_t * _p_first;
303 /* VLC_OBJECT: attempt at doing a clever cast */
304 #define VLC_OBJECT( x ) \
305 ((vlc_object_t *)(x))+0*(x)->be_sure_to_add_VLC_COMMON_MEMBERS_to_struct
307 /*****************************************************************************
308 * Macros and inline functions
309 *****************************************************************************/
310 #ifdef NTOHL_IN_SYS_PARAM_H
311 # include <sys/param.h>
313 #elif !defined(WIN32) /* NTOHL_IN_SYS_PARAM_H || WIN32 */
314 # include <netinet/in.h>
316 #endif /* NTOHL_IN_SYS_PARAM_H || WIN32 */
318 /* CEIL: division with round to nearest greater integer */
319 #define CEIL(n, d) ( ((n) / (d)) + ( ((n) % (d)) ? 1 : 0) )
321 /* PAD: PAD(n, d) = CEIL(n ,d) * d */
322 #define PAD(n, d) ( ((n) % (d)) ? ((((n) / (d)) + 1) * (d)) : (n) )
324 /* __MAX and __MIN: self explanatory */
326 # define __MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
329 # define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
332 /* MSB (big endian)/LSB (little endian) conversions - network order is always
333 * MSB, and should be used for both network communications and files. Note that
334 * byte orders other than little and big endians are not supported, but only
335 * the VAX seems to have such exotic properties. */
336 static inline u16 U16_AT( void * _p )
339 return ( ((u16)p[0] << 8) | p[1] );
341 static inline u32 U32_AT( void * _p )
344 return ( ((u32)p[0] << 24) | ((u32)p[1] << 16) | ((u32)p[2] << 8) | p[3] );
346 static inline u64 U64_AT( void * _p )
349 return ( ((u64)p[0] << 56) | ((u64)p[1] << 48) | ((u64)p[2] << 40)
350 | ((u64)p[3] << 32) | ((u64)p[4] << 24) | ((u64)p[5] << 16)
351 | ((u64)p[6] << 8) | p[7] );
354 # define hton16(i) ( i )
355 # define hton32(i) ( i )
356 # define hton64(i) ( i )
357 # define ntoh16(i) ( i )
358 # define ntoh32(i) ( i )
359 # define ntoh64(i) ( i )
361 # define hton16(i) U16_AT(&i)
362 # define hton32(i) U32_AT(&i)
363 # define hton64(i) U64_AT(&i)
364 # define ntoh16(i) U16_AT(&i)
365 # define ntoh32(i) U32_AT(&i)
366 # define ntoh64(i) U64_AT(&i)
369 /* Alignment of critical static data structures */
370 #ifdef ATTRIBUTE_ALIGNED_MAX
371 # define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
373 # define ATTR_ALIGN(align)
376 /* Alignment of critical dynamic data structure
378 * Not all platforms support memalign so we provide a vlc_memalign wrapper
379 * void *vlc_memalign( size_t align, size_t size, void **pp_orig )
380 * *pp_orig is the pointer that has to be freed afterwards.
383 #ifdef HAVE_POSIX_MEMALIGN
384 # define vlc_memalign(align,size,pp_orig) \
385 ( !posix_memalign( pp_orig, align, size ) ? *(pp_orig) : NULL )
389 /* Some systems have memalign() but no declaration for it */
390 void * memalign( size_t align, size_t size );
392 # define vlc_memalign(pp_orig,align,size) \
393 ( *(pp_orig) = memalign( align, size ) )
395 #else /* We don't have any choice but to align manually */
396 # define vlc_memalign(pp_orig,align,size) \
397 (( *(pp_orig) = malloc( size + align - 1 )) \
398 ? (void *)( (((unsigned long)*(pp_orig)) + (unsigned long)(align-1) ) \
399 & (~(unsigned long)(align-1)) ) \
404 /* strndup (defined in src/misc/extras.c) */
406 char * strndup( const char *s, size_t n );
410 #define I64C(x) x##LL
413 /* win32, cl and icl support */
414 # if defined( _MSC_VER ) || !defined( __MINGW32__ )
415 # define __attribute__(x)
416 # define __inline__ __inline
417 # define strncasecmp strnicmp
418 # define strcasecmp stricmp
419 # define S_IFBLK 0x3000 /* Block */
420 # define S_ISBLK(m) (0)
421 # define S_ISCHR(m) (0)
422 # define S_ISFIFO(m) (((m)&_S_IFMT) == _S_IFIFO)
423 # define S_ISREG(m) (((m)&_S_IFMT) == _S_IFREG)
425 # define I64C(x) x##i64
428 /* several type definitions */
429 # if defined( __MINGW32__ )
430 # if !defined( _OFF_T_ )
431 typedef long long _off_t;
432 typedef _off_t off_t;
435 # define off_t long long
439 # if defined( _MSC_VER )
440 # if !defined( _OFF_T_DEFINED )
441 typedef __int64 off_t;
442 # define _OFF_T_DEFINED
444 # define off_t __int64
448 # if defined( __BORLANDC__ )
450 # define off_t unsigned __int64
454 # define O_NONBLOCK 0
457 /* These two are not defined in mingw32 (bug?) */
459 # define snprintf _snprintf
462 # define vsnprintf _vsnprintf
467 /*****************************************************************************
469 *****************************************************************************/
470 #define CPU_CAPABILITY_NONE 0
471 #define CPU_CAPABILITY_486 (1<<0)
472 #define CPU_CAPABILITY_586 (1<<1)
473 #define CPU_CAPABILITY_PPRO (1<<2)
474 #define CPU_CAPABILITY_MMX (1<<3)
475 #define CPU_CAPABILITY_3DNOW (1<<4)
476 #define CPU_CAPABILITY_MMXEXT (1<<5)
477 #define CPU_CAPABILITY_SSE (1<<6)
478 #define CPU_CAPABILITY_ALTIVEC (1<<16)
479 #define CPU_CAPABILITY_FPU (1<<31)
481 /*****************************************************************************
483 *****************************************************************************/
484 #if defined( ENABLE_NLS ) && defined ( HAVE_GETTEXT ) && !defined( __BORLANDC__ ) && !defined( NEED_GNOMESUPPORT_H )
485 # include <libintl.h>
487 # define _(String) dgettext (PACKAGE, String)
489 # define N_(String) gettext_noop (String)
491 # define N_(String) (String)
493 #elif !defined( NEED_GNOMESUPPORT_H )
494 # define _(String) (String)
495 # define N_(String) (String)
498 /*****************************************************************************
499 * Additional vlc stuff
500 *****************************************************************************/
501 #include "vlc_symbols.h"
502 #include "os_specific.h"
503 #include "vlc_messages.h"
504 #include "vlc_threads_funcs.h"
508 #include "configuration.h"
509 #include "vlc_objects.h"
511 #if defined( __BORLANDC__ )