]> git.sesse.net Git - vlc/blob - include/vlc_common.h
Big round of fixes in the aout3.
[vlc] / include / vlc_common.h
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.22 2002/08/21 22:41:59 massiot Exp $
7  *
8  * Authors: Samuel Hocevar <sam@via.ecp.fr>
9  *          Vincent Seguin <seguin@via.ecp.fr>
10  *          Gildas Bazin <gbazin@netcourrier.com>
11  *
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.
16  * 
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.
21  *
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  *****************************************************************************/
26
27 /*****************************************************************************
28  * Compiler-specific workarounds
29  *****************************************************************************/
30 #if defined( __BORLANDC__ )
31 #   undef HAVE_VARIADIC_MACROS
32 #   undef HAVE_STDINT_H
33 #endif
34
35 /*****************************************************************************
36  * Required system headers
37  *****************************************************************************/
38 #ifdef HAVE_STRING_H
39 #   include <string.h>                                         /* strerror() */
40 #endif
41
42 #ifdef HAVE_SYS_TYPES_H
43 #   include <sys/types.h>
44 #endif
45
46 /*****************************************************************************
47  * Basic types definitions
48  *****************************************************************************/
49 #ifdef HAVE_STDINT_H
50 #   include <stdint.h>
51     typedef uint8_t             u8;
52     typedef int8_t              s8;
53
54     typedef uint16_t            u16;
55     typedef int16_t             s16;
56
57     typedef uint32_t            u32;
58     typedef int32_t             s32;
59
60     typedef uint64_t            u64;
61     typedef int64_t             s64;
62 #else
63     typedef unsigned char       u8;
64     typedef signed char         s8;
65
66     typedef unsigned short      u16;
67     typedef signed short        s16;
68
69     typedef unsigned int        u32;
70     typedef signed int          s32;
71
72 #   if defined( _MSC_VER ) || ( defined( WIN32 ) && !defined( __MINGW32__ ) )
73     typedef unsigned __int64    u64;
74     typedef signed __int64      s64;
75 #   else
76     typedef unsigned long long  u64;
77     typedef signed long long    s64;
78 #   endif
79 #endif
80
81 typedef u8                      byte_t;
82
83 /* ptrdiff_t definition */
84 #ifdef HAVE_STDDEF_H
85 #   include <stddef.h>
86 #else
87 #   include <malloc.h>
88 #   ifndef _PTRDIFF_T
89 #       define _PTRDIFF_T
90 /* Not portable in a 64-bit environment. */
91 typedef int                 ptrdiff_t;
92 #   endif
93 #endif
94
95 #if defined( WIN32 )
96 typedef int                 ssize_t;
97 #endif
98
99 /* Counter for statistics and profiling */
100 typedef unsigned long       count_t;
101
102 /* DCT elements types */
103 typedef s16                 dctelem_t;
104
105 /* Video buffer types */
106 typedef u8                  yuv_data_t;
107
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  *****************************************************************************/
118 typedef s64 mtime_t;
119
120 /*****************************************************************************
121  * The vlc_fourcc_t type.
122  *****************************************************************************
123  * See http://www.webartz.com/fourcc/ for a very detailed list.
124  *****************************************************************************/
125 typedef u32 vlc_fourcc_t;
126
127 #define VLC_FOURCC( a, b, c, d ) \
128     ( ((u32)a) | ( ((u32)b) << 8 ) | ( ((u32)c) << 16 ) | ( ((u32)d) << 24 ) )
129
130 #define VLC_TWOCC( a, b ) \
131     ( (u16)(a) | ( (u16)(b) << 8 ) )
132
133 /*****************************************************************************
134  * Classes declaration
135  *****************************************************************************/
136
137 /* Messages */
138 typedef struct msg_bank_t msg_bank_t;
139 typedef struct msg_subscription_t msg_subscription_t;
140
141 /* Playlist */
142 typedef struct playlist_t playlist_t;
143 typedef struct playlist_item_t playlist_item_t;
144
145 /* Modules */
146 typedef struct module_bank_t module_bank_t;
147 typedef struct module_t module_t;
148 typedef struct module_config_t module_config_t;
149 typedef struct module_symbols_t module_symbols_t;
150
151 /* Interface */
152 typedef struct intf_thread_t intf_thread_t;
153 typedef struct intf_sys_t intf_sys_t;
154 typedef struct intf_console_t intf_console_t;
155 typedef struct intf_msg_t intf_msg_t;
156 typedef struct intf_channel_t intf_channel_t;
157
158 /* Input */
159 typedef struct input_thread_t input_thread_t;
160 typedef struct input_channel_t input_channel_t;
161 typedef struct input_area_t input_area_t;
162 typedef struct input_buffers_t input_buffers_t;
163 typedef struct input_socket_t input_socket_t;
164 typedef struct input_info_t input_info_t;
165 typedef struct input_info_category_t input_info_category_t;
166 typedef struct access_sys_t access_sys_t;
167 typedef struct demux_sys_t demux_sys_t;
168 typedef struct es_descriptor_t es_descriptor_t;
169 typedef struct es_sys_t es_sys_t;
170 typedef struct pgrm_descriptor_t pgrm_descriptor_t;
171 typedef struct pgrm_sys_t pgrm_sys_t;
172 typedef struct stream_descriptor_t stream_descriptor_t;
173 typedef struct stream_sys_t stream_sys_t;
174
175 /* Audio */
176 typedef struct aout_instance_t aout_instance_t;
177 typedef struct aout_sys_t aout_sys_t;
178 typedef struct aout_input_t aout_input_t;
179 typedef struct aout_buffer_t aout_buffer_t;
180 typedef struct audio_sample_format_t audio_sample_format_t;
181 typedef struct audio_date_t audio_date_t;
182
183 /* Video */
184 typedef struct vout_thread_t vout_thread_t;
185 typedef struct vout_font_t vout_font_t;
186 typedef struct vout_sys_t vout_sys_t;
187 typedef struct chroma_sys_t chroma_sys_t;
188 typedef struct picture_t picture_t;
189 typedef struct picture_sys_t picture_sys_t;
190 typedef struct picture_heap_t picture_heap_t;
191 typedef struct subpicture_t subpicture_t;
192 typedef struct subpicture_sys_t subpicture_sys_t;
193
194 /* Stream output */
195 typedef struct sout_instance_t sout_instance_t;
196 typedef struct sout_fifo_t sout_fifo_t;
197
198 /* Decoders */
199 typedef struct decoder_fifo_t decoder_fifo_t;
200
201 /* Misc */
202 typedef struct data_packet_t data_packet_t;
203 typedef struct data_buffer_t data_buffer_t;
204 typedef struct stream_position_t stream_position_t;
205 typedef struct stream_ctrl_t stream_ctrl_t;
206 typedef struct pes_packet_t pes_packet_t;
207 typedef struct bit_stream_t bit_stream_t;
208 typedef struct network_socket_t network_socket_t;
209 typedef struct iso639_lang_t iso639_lang_t;
210
211 /*****************************************************************************
212  * Plug-in stuff
213  *****************************************************************************/
214 #ifndef __PLUGIN__
215 #   define VLC_EXPORT( type, name, args ) type name args
216 #else
217 #   define VLC_EXPORT( type, name, args ) struct _u_n_u_s_e_d_
218     extern module_symbols_t* p_symbols;
219 #endif
220
221 /*****************************************************************************
222  * OS-specific headers and thread types
223  *****************************************************************************/
224 #if defined( WIN32 )
225 #   define WIN32_LEAN_AND_MEAN
226 #   include <windows.h>
227 #endif
228
229 #include "vlc_threads.h"
230
231 /*****************************************************************************
232  * Common structure members
233  *****************************************************************************/
234
235 /* VLC_COMMON_MEMBERS : members common to all basic vlc objects */
236 #define VLC_COMMON_MEMBERS                                                  \
237     int   i_object_id;                                                      \
238     int   i_object_type;                                                    \
239     char *psz_object_type;                                                  \
240     char *psz_object_name;                                                  \
241                                                                             \
242     /* Thread properties, if any */                                         \
243     vlc_bool_t   b_thread;                                                  \
244     vlc_thread_t thread_id;                                                 \
245                                                                             \
246     /* Object access lock */                                                \
247     vlc_mutex_t  object_lock;                                               \
248     vlc_cond_t   object_wait;                                               \
249                                                                             \
250     volatile vlc_bool_t b_error;                    /* set by the object */ \
251     volatile vlc_bool_t b_die;                     /* set by the outside */ \
252     volatile vlc_bool_t b_dead;                     /* set by the object */ \
253     volatile vlc_bool_t b_attached;                 /* set by the object */ \
254                                                                             \
255     vlc_t *         p_vlc;                           /* root of all evil */ \
256                                                                             \
257     volatile int    i_refcount;                           /* usage count */ \
258     vlc_object_t *  p_parent;                              /* our parent */ \
259     vlc_object_t ** pp_children;                         /* our children */ \
260     volatile int    i_children;                                             \
261                                                                             \
262     /* Private data */                                                      \
263     void *          p_private;                                              \
264                                                                             \
265     /* Just a reminder so that people don't cast garbage */                 \
266     int be_sure_to_add_VLC_COMMON_MEMBERS_to_struct;                        \
267
268 /* The real vlc_object_t type. Yes, it's that simple :-) */
269 struct vlc_object_t
270 {
271     VLC_COMMON_MEMBERS
272 };
273
274 /* The object list */
275 struct vlc_list_t
276 {
277     int             i_count;
278     vlc_object_t ** pp_objects;
279
280     /* Private */
281     int             _i_extra;
282     vlc_object_t *  _p_first;
283 };  
284
285 /* VLC_OBJECT: attempt at doing a clever cast */
286 #define VLC_OBJECT( x ) \
287     ((vlc_object_t *)(x))+0*(x)->be_sure_to_add_VLC_COMMON_MEMBERS_to_struct
288
289 /*****************************************************************************
290  * Macros and inline functions
291  *****************************************************************************/
292 #ifdef NTOHL_IN_SYS_PARAM_H
293 #   include <sys/param.h>
294
295 #elif !defined(WIN32) /* NTOHL_IN_SYS_PARAM_H || WIN32 */
296 #   include <netinet/in.h>
297
298 #endif /* NTOHL_IN_SYS_PARAM_H || WIN32 */
299
300 /* CEIL: division with round to nearest greater integer */
301 #define CEIL(n, d)  ( ((n) / (d)) + ( ((n) % (d)) ? 1 : 0) )
302
303 /* PAD: PAD(n, d) = CEIL(n ,d) * d */
304 #define PAD(n, d)   ( ((n) % (d)) ? ((((n) / (d)) + 1) * (d)) : (n) )
305
306 /* __MAX and __MIN: self explanatory */
307 #ifndef __MAX
308 #   define __MAX(a, b)   ( ((a) > (b)) ? (a) : (b) )
309 #endif
310 #ifndef __MIN
311 #   define __MIN(a, b)   ( ((a) < (b)) ? (a) : (b) )
312 #endif
313
314 /* MSB (big endian)/LSB (little endian) conversions - network order is always
315  * MSB, and should be used for both network communications and files. Note that
316  * byte orders other than little and big endians are not supported, but only
317  * the VAX seems to have such exotic properties. */
318 static inline u16 U16_AT( void * _p )
319 {
320     u8 * p = (u8 *)_p;
321     return ( ((u16)p[0] << 8) | p[1] );
322 }
323 static inline u32 U32_AT( void * _p )
324 {
325     u8 * p = (u8 *)_p;
326     return ( ((u32)p[0] << 24) | ((u32)p[1] << 16) | ((u32)p[2] << 8) | p[3] );
327 }
328 static inline u64 U64_AT( void * _p )
329 {
330     u8 * p = (u8 *)_p;
331     return ( ((u64)p[0] << 56) | ((u64)p[1] << 48) | ((u64)p[2] << 40) 
332               | ((u64)p[3] << 32) | ((u64)p[4] << 24) | ((u64)p[5] << 16)
333               | ((u64)p[6] << 8) | p[7] );
334 }
335 #if WORDS_BIGENDIAN
336 #   define hton16(i)   ( i )
337 #   define hton32(i)   ( i )
338 #   define hton64(i)   ( i )
339 #   define ntoh16(i)   ( i )
340 #   define ntoh32(i)   ( i )
341 #   define ntoh64(i)   ( i )
342 #else
343 #   define hton16(i)   U16_AT(&i)
344 #   define hton32(i)   U32_AT(&i)
345 #   define hton64(i)   U64_AT(&i)
346 #   define ntoh16(i)   U16_AT(&i)
347 #   define ntoh32(i)   U32_AT(&i)
348 #   define ntoh64(i)   U64_AT(&i)
349 #endif
350
351 /* Alignment of critical static data structures */
352 #ifdef ATTRIBUTE_ALIGNED_MAX
353 #   define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
354 #else
355 #   define ATTR_ALIGN(align)
356 #endif
357
358 /* Alignment of critical dynamic data structure
359  *
360  * Not all platforms support memalign so we provide a vlc_memalign wrapper
361  * void *vlc_memalign( size_t align, size_t size, void **pp_orig )
362  * *pp_orig is the pointer that has to be freed afterwards.
363  */
364 #if 0
365 #ifdef HAVE_POSIX_MEMALIGN
366 #   define vlc_memalign(align,size,pp_orig) \
367     ( !posix_memalign( pp_orig, align, size ) ? *(pp_orig) : NULL )
368 #endif
369 #endif
370 #ifdef HAVE_MEMALIGN
371     /* Some systems have memalign() but no declaration for it */
372     void * memalign( size_t align, size_t size );
373
374 #   define vlc_memalign(pp_orig,align,size) \
375     ( *(pp_orig) = memalign( align, size ) )
376
377 #else /* We don't have any choice but to align manually */
378 #   define vlc_memalign(pp_orig,align,size) \
379     (( *(pp_orig) = malloc( size + align - 1 )) \
380         ? (void *)( (((unsigned long)*(pp_orig)) + (unsigned long)(align-1) ) \
381                        & (~(unsigned long)(align-1)) ) \
382         : NULL )
383
384 #endif
385
386 /* strndup (defined in src/misc/extras.c) */
387 #ifndef HAVE_STRNDUP
388 char * strndup( const char *s, size_t n );
389 #endif
390
391
392 #define I64C(x)         x##LL
393
394 #ifdef WIN32
395 /* win32, cl and icl support */
396 #   if defined( _MSC_VER ) || !defined( __MINGW32__ )
397 #       define __attribute__(x)
398 #       define __inline__      __inline
399 #       define strncasecmp     strnicmp
400 #       define strcasecmp      stricmp
401 #       define S_IFBLK         0x3000  /* Block */
402 #       define S_ISBLK(m)      (0)
403 #       define S_ISCHR(m)      (0)
404 #       define S_ISFIFO(m)     (((m)&_S_IFMT) == _S_IFIFO)
405 #       define S_ISREG(m)      (((m)&_S_IFMT) == _S_IFREG)
406 #       undef I64C
407 #       define I64C(x)         x##i64
408 #   endif
409
410 /* several type definitions */
411 #   if defined( __MINGW32__ )
412 #       if !defined( _OFF_T_ )
413 typedef long long _off_t;
414 typedef _off_t off_t;
415 #           define _OFF_T_
416 #       else
417 #           define off_t long long
418 #       endif
419 #   endif
420
421 #   if defined( _MSC_VER )
422 #       if !defined( _OFF_T_DEFINED )
423 typedef __int64 off_t;
424 #           define _OFF_T_DEFINED
425 #       else
426 #           define off_t __int64
427 #       endif
428 #   endif
429
430 #   if defined( __BORLANDC__ )
431 #       undef off_t
432 #       define off_t unsigned __int64
433 #   endif
434
435 #   ifndef O_NONBLOCK
436 #       define O_NONBLOCK 0
437 #   endif
438
439     /* These two are not defined in mingw32 (bug?) */
440 #   ifndef snprintf
441 #       define snprintf _snprintf
442 #   endif
443 #   ifndef vsnprintf
444 #       define vsnprintf _vsnprintf
445 #   endif
446
447 #endif
448
449 /*****************************************************************************
450  * CPU capabilities
451  *****************************************************************************/
452 #define CPU_CAPABILITY_NONE    0
453 #define CPU_CAPABILITY_486     (1<<0)
454 #define CPU_CAPABILITY_586     (1<<1)
455 #define CPU_CAPABILITY_PPRO    (1<<2)
456 #define CPU_CAPABILITY_MMX     (1<<3)
457 #define CPU_CAPABILITY_3DNOW   (1<<4)
458 #define CPU_CAPABILITY_MMXEXT  (1<<5)
459 #define CPU_CAPABILITY_SSE     (1<<6)
460 #define CPU_CAPABILITY_ALTIVEC (1<<16)
461 #define CPU_CAPABILITY_FPU     (1<<31)
462
463 /*****************************************************************************
464  * I18n stuff
465  *****************************************************************************/
466 #ifndef PACKAGE /* Borland C++ uses this ! */
467 #define PACKAGE VLC_PACKAGE
468 #endif
469 #define VERSION VLC_VERSION
470
471 #if defined( ENABLE_NLS ) && defined ( HAVE_GETTEXT ) && !defined( __BORLANDC__ ) && !defined( NEED_GNOMESUPPORT_H )
472 #   include <libintl.h>
473 #   undef _
474 #   define _(String) dgettext (PACKAGE, String)
475 #   ifdef gettext_noop
476 #       define N_(String) gettext_noop (String)
477 #   else
478 #       define N_(String) (String)
479 #   endif
480 #elif !defined( NEED_GNOMESUPPORT_H )
481 #   define _(String) (String)
482 #   define N_(String) (String)
483 #endif
484
485 /*****************************************************************************
486  * Plug-in stuff
487  *****************************************************************************/
488 #include "vlc_symbols.h"