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