]> git.sesse.net Git - vlc/blob - include/common.h
* Forgot a file in my last commit.
[vlc] / include / 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: common.h,v 1.62 2001/12/30 05:38:44 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 system headers
29  *****************************************************************************/
30 #include <string.h>                                            /* strerror() */
31
32 /*****************************************************************************
33  * Required vlc headers
34  *****************************************************************************/
35 #include "config.h"
36 #include "int_types.h"
37
38 /*****************************************************************************
39  * Basic types definitions
40  *****************************************************************************/
41
42 typedef u8                  byte_t;
43
44 /* Boolean type */
45 #ifdef BOOLEAN_T_IN_SYS_TYPES_H
46 #   include <sys/types.h>
47 #elif defined(BOOLEAN_T_IN_PTHREAD_H)
48 #   include <pthread.h>
49 #elif defined(BOOLEAN_T_IN_CTHREADS_H)
50 #   include <cthreads.h>
51 #else
52 typedef int                 boolean_t;
53 #endif
54 #ifdef SYS_GNU
55 #   define _MACH_I386_BOOLEAN_H_
56 #endif
57
58 /* ptrdiff_t definition */
59 #ifdef HAVE_STDDEF_H
60 #   include <stddef.h>
61 #else
62 #   include <malloc.h>
63 #   ifndef _PTRDIFF_T
64 #       define _PTRDIFF_T
65 /* Not portable in a 64-bit environment. */
66 typedef int                 ptrdiff_t;
67 #   endif
68 #endif
69
70 /* Counter for statistics and profiling */
71 typedef unsigned long       count_t;
72
73 /* DCT elements types */
74 typedef s16                 dctelem_t;
75
76 /* Video buffer types */
77 typedef u8                  yuv_data_t;
78
79 /*****************************************************************************
80  * mtime_t: high precision date or time interval
81  *****************************************************************************
82  * Store an high precision date or time interval. The maximum precision is the
83  * micro-second, and a 64 bits integer is used to avoid any overflow (maximum
84  * time interval is then 292271 years, which should be long enough for any
85  * video). Date are stored as a time interval since a common date.
86  * Note that date and time intervals can be manipulated using regular
87  * arithmetic operators, and that no special functions are required.
88  *****************************************************************************/
89 typedef s64 mtime_t;
90
91 /*****************************************************************************
92  * Classes declaration
93  *****************************************************************************/
94
95 /* Plugins */
96 struct plugin_bank_s;
97 struct plugin_info_s;
98
99 typedef struct plugin_bank_s *          p_plugin_bank_t;
100 typedef struct plugin_info_s *          p_plugin_info_t;
101
102 /* Plugins */
103 struct playlist_s;
104 struct playlist_item_s;
105 struct module_s;
106
107 typedef struct playlist_s *             p_playlist_t;
108 typedef struct playlist_item_s *        p_playlist_item_t;
109
110 /* Interface */
111 struct intf_thread_s;
112 struct intf_sys_s;
113 struct intf_console_s;
114 struct intf_msg_s;
115 struct intf_channel_s;
116
117 typedef struct intf_thread_s *          p_intf_thread_t;
118 typedef struct intf_sys_s *             p_intf_sys_t;
119 typedef struct intf_console_s *         p_intf_console_t;
120 typedef struct intf_msg_s *             p_intf_msg_t;
121 typedef struct intf_channel_s *         p_intf_channel_t;
122
123 /* Input */
124 struct input_thread_s;
125 struct input_channel_s;
126 struct input_cfg_s;
127 struct input_area_s;
128
129 typedef struct input_thread_s *         p_input_thread_t;
130 typedef struct input_channel_s *        p_input_channel_t;
131 typedef struct input_cfg_s *            p_input_cfg_t;
132 typedef struct input_area_s *           p_input_area_t;
133
134 /* Audio */
135 struct aout_thread_s;
136 struct aout_sys_s;
137
138 typedef struct aout_thread_s *          p_aout_thread_t;
139 typedef struct aout_sys_s *             p_aout_sys_t;
140
141 /* Video */
142 struct vout_thread_s;
143 struct vout_font_s;
144 struct vout_sys_s;
145 struct vdec_thread_s;
146 struct vpar_thread_s;
147 struct video_parser_s;
148
149 typedef struct vout_thread_s *          p_vout_thread_t;
150 typedef struct vout_font_s *            p_vout_font_t;
151 typedef struct vout_sys_s *             p_vout_sys_t;
152 typedef struct chroma_sys_s *           p_chroma_sys_t;
153 typedef struct vdec_thread_s *          p_vdec_thread_t;
154 typedef struct vpar_thread_s *          p_vpar_thread_t;
155 typedef struct video_parser_s *         p_video_parser_t;
156
157 /* Misc */
158 struct macroblock_s;
159 struct data_packet_s;
160 struct imdct_s;
161 struct complex_s;
162 struct dm_par_s;
163 struct picture_s;
164 struct picture_sys_s;
165 struct es_descriptor_s;
166 struct pgrm_descriptor_s;
167 struct pes_packet_s;
168 struct input_area_s;
169 struct bit_stream_s;
170
171 /* Decoders */
172 struct decoder_config_s;
173 struct decoder_fifo_s;
174
175 /*****************************************************************************
176  * Macros and inline functions
177  *****************************************************************************/
178 #ifdef NTOHL_IN_SYS_PARAM_H
179 #   include <sys/param.h>
180
181 #elif defined(WIN32)
182 /* Swap bytes in 16 bit value.  */
183 #   define __bswap_constant_16(x) \
184      ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
185
186 #   if defined __GNUC__ && __GNUC__ >= 2
187 #       define __bswap_16(x) \
188             (__extension__                                                    \
189              ({ register unsigned short int __v;                              \
190                 if (__builtin_constant_p (x))                                 \
191                   __v = __bswap_constant_16 (x);                              \
192                 else                                                          \
193                   __asm__ __volatile__ ("rorw $8, %w0"                        \
194                                         : "=r" (__v)                          \
195                                         : "0" ((unsigned short int) (x))      \
196                                         : "cc");                              \
197                 __v; }))
198 #   else
199 /* This is better than nothing.  */
200 #       define __bswap_16(x) __bswap_constant_16 (x)
201 #   endif
202
203 /* Swap bytes in 32 bit value.  */
204 #   define __bswap_constant_32(x) \
205         ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >>  8) |            \
206          (((x) & 0x0000ff00) <<  8) | (((x) & 0x000000ff) << 24))
207
208 #   if defined __GNUC__ && __GNUC__ >= 2
209 /* To swap the bytes in a word the i486 processors and up provide the
210    `bswap' opcode.  On i386 we have to use three instructions.  */
211 #       if !defined __i486__ && !defined __pentium__ && !defined __pentiumpro__
212 #           define __bswap_32(x) \
213                 (__extension__                                                \
214                  ({ register unsigned int __v;                                \
215                     if (__builtin_constant_p (x))                             \
216                       __v = __bswap_constant_32 (x);                          \
217                     else                                                      \
218                       __asm__ __volatile__ ("rorw $8, %w0;"                   \
219                                             "rorl $16, %0;"                   \
220                                             "rorw $8, %w0"                    \
221                                             : "=r" (__v)                      \
222                                             : "0" ((unsigned int) (x))        \
223                                             : "cc");                          \
224                     __v; }))
225 #       else
226 #           define __bswap_32(x) \
227                 (__extension__                                                \
228                  ({ register unsigned int __v;                                \
229                     if (__builtin_constant_p (x))                             \
230                       __v = __bswap_constant_32 (x);                          \
231                     else                                                      \
232                       __asm__ __volatile__ ("bswap %0"                        \
233                                             : "=r" (__v)                      \
234                                             : "0" ((unsigned int) (x)));      \
235                     __v; }))
236 #       endif
237 #   else
238 #       define __bswap_32(x) __bswap_constant_32 (x)
239 #   endif
240
241 #   if defined __GNUC__ && __GNUC__ >= 2
242 /* Swap bytes in 64 bit value.  */
243 #       define __bswap_constant_64(x) \
244             ((((x) & 0xff00000000000000ull) >> 56)                            \
245              | (((x) & 0x00ff000000000000ull) >> 40)                          \
246              | (((x) & 0x0000ff0000000000ull) >> 24)                          \
247              | (((x) & 0x000000ff00000000ull) >> 8)                           \
248              | (((x) & 0x00000000ff000000ull) << 8)                           \
249              | (((x) & 0x0000000000ff0000ull) << 24)                          \
250              | (((x) & 0x000000000000ff00ull) << 40)                          \
251              | (((x) & 0x00000000000000ffull) << 56))
252
253 #       define __bswap_64(x) \
254             (__extension__                                                    \
255              ({ union { __extension__ unsigned long long int __ll;            \
256                         unsigned long int __l[2]; } __w, __r;                 \
257                 if (__builtin_constant_p (x))                                 \
258                   __r.__ll = __bswap_constant_64 (x);                         \
259                 else                                                          \
260                   {                                                           \
261                     __w.__ll = (x);                                           \
262                     __r.__l[0] = __bswap_32 (__w.__l[1]);                     \
263                     __r.__l[1] = __bswap_32 (__w.__l[0]);                     \
264                   }                                                           \
265                 __r.__ll; }))
266 #   endif
267
268 #else /* NTOHL_IN_SYS_PARAM_H || WIN32 */
269 #   include <netinet/in.h>
270
271 #endif /* NTOHL_IN_SYS_PARAM_H || WIN32 */
272
273 /* CEIL: division with round to nearest greater integer */
274 #define CEIL(n, d)  ( ((n) / (d)) + ( ((n) % (d)) ? 1 : 0) )
275
276 /* PAD: PAD(n, d) = CEIL(n ,d) * d */
277 #define PAD(n, d)   ( ((n) % (d)) ? ((((n) / (d)) + 1) * (d)) : (n) )
278
279 /* MAX and MIN: self explanatory */
280 #ifndef MAX
281 #   define MAX(a, b)   ( ((a) > (b)) ? (a) : (b) )
282 #endif
283 #ifndef MIN
284 #   define MIN(a, b)   ( ((a) < (b)) ? (a) : (b) )
285 #endif
286
287 /* MSB (big endian)/LSB (little endian) conversions - network order is always
288  * MSB, and should be used for both network communications and files. Note that
289  * byte orders other than little and big endians are not supported, but only
290  * the VAX seems to have such exotic properties - note that these 'functions'
291  * needs <netinet/in.h> or the local equivalent. */
292 /* FIXME: hton64 should be declared as an extern inline function to avoid
293  * border effects (see byteorder.h) */
294 #if WORDS_BIGENDIAN
295 #   define hton16      htons
296 #   define hton32      htonl
297 #   define hton64(i)   ( i )
298 #   define ntoh16      ntohs
299 #   define ntoh32      ntohl
300 #   define ntoh64(i)   ( i )
301 #else
302 #   define hton16      htons
303 #   define hton32      htonl
304 #   define hton64(i)   ( ((u64)(htonl((i) & 0xffffffff)) << 32) | htonl(((i) >> 32) & 0xffffffff ) )
305 #   define ntoh16      ntohs
306 #   define ntoh32      ntohl
307 #   define ntoh64      hton64
308 #endif
309
310 /* Macros with automatic casts */
311 #define U64_AT(p)   ( ntoh64 ( *( (u64 *)(p) ) ) )
312 #define U32_AT(p)   ( ntoh32 ( *( (u32 *)(p) ) ) )
313 #define U16_AT(p)   ( ntoh16 ( *( (u16 *)(p) ) ) )
314
315 /* Alignment of critical static data structures */
316 #ifdef ATTRIBUTE_ALIGNED_MAX
317 #   define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
318 #else
319 #   define ATTR_ALIGN(align)
320 #endif
321
322 /* Alignment of critical dynamic data structure */
323 #ifdef HAVE_MEMALIGN
324     /* Some systems have memalign() but no declaration for it */
325     void * memalign( size_t align, size_t size );
326 #else
327 #   ifdef HAVE_VALLOC
328         /* That's like using a hammer to kill a fly, but eh... */
329 #       include <unistd.h>
330 #       define memalign(align,size) valloc(size)
331 #   else
332         /* Assume malloc alignment is sufficient */
333 #       define memalign(align,size) malloc(size)
334 #   endif    
335 #endif
336
337 #define I64C(x)         x##LL
338
339
340 #if defined( WIN32 )
341 /* The ntoh* and hton* bytes swapping functions are provided by winsock
342  * but for conveniency and speed reasons it is better to implement them
343  * ourselves. ( several plugins use them and it is too much hassle to link
344  * winsock with each of them ;-)
345  */
346 #   undef ntoh32(x)
347 #   undef ntoh16(x)
348 #   undef ntoh64(x)
349 #   undef hton32(x)
350 #   undef hton16(x)
351 #   undef hton64(x)
352
353 #   ifdef WORDS_BIGENDIAN
354 #       define ntoh32(x)       (x)
355 #       define ntoh16(x)       (x)
356 #       define ntoh64(x)       (x)
357 #       define hton32(x)       (x)
358 #       define hton16(x)       (x)
359 #       define hton64(x)       (x)
360 #   else
361 #       define ntoh32(x)     __bswap_32 (x)
362 #       define ntoh16(x)     __bswap_16 (x)
363 #       define ntoh64(x)     __bswap_32 (x)
364 #       define hton32(x)     __bswap_32 (x)
365 #       define hton16(x)     __bswap_16 (x)
366 #       define hton64(x)     __bswap_32 (x)
367 #   endif
368
369 /* win32, cl and icl support */
370 #   if defined( _MSC_VER )
371 #       define __attribute__(x)
372 #       define __inline__      __inline
373 #       define strncasecmp     strnicmp
374 #       define strcasecmp      stricmp
375 #       define S_ISBLK(m)      (0)
376 #       define S_ISCHR(m)      (0)
377 #       define S_ISFIFO(m)     (((m)&_S_IFMT) == _S_IFIFO)
378 #       define S_ISREG(m)      (((m)&_S_IFMT) == _S_IFREG)
379 #       undef I64C(x)
380 #       define I64C(x)         x##i64
381 #   endif
382
383 /* several type definitions */
384 #   if defined( __MINGW32__ )
385 #       if !defined( _OFF_T_ )
386 typedef long long _off_t;
387 typedef _off_t off_t;
388 #           define _OFF_T_
389 #       else
390 #           define off_t long long
391 #       endif
392 #   endif
393
394 #   if defined( _MSC_VER )
395 #       if !defined( _OFF_T_DEFINED )
396 typedef __int64 off_t;
397 #           define _OFF_T_DEFINED
398 #       else
399 #           define off_t __int64
400 #       endif
401 #       define stat _stati64
402 #   endif
403
404 #   ifndef snprintf
405 #       define snprintf _snprintf  /* snprintf not defined in mingw32 (bug?) */
406 #   endif
407
408 #endif
409
410 /*****************************************************************************
411  * I18n stuff
412  *****************************************************************************/
413 #if defined( ENABLE_NLS ) && defined ( HAVE_GETTEXT )
414 #   include <libintl.h>
415 #else
416 #   define _(String) (String)
417 #   define N_(String) (String)
418 #   define textdomain(Domain)
419 #   define bindtextdomain(Package, Directory) 1
420 #endif
421
422 /*****************************************************************************
423  * Plug-in stuff
424  *****************************************************************************/
425 typedef struct module_symbols_s
426 {
427     struct main_s* p_main;
428     struct aout_bank_s* p_aout_bank;
429     struct vout_bank_s* p_vout_bank;
430
431     int    ( * main_GetIntVariable ) ( char *, int );
432     char * ( * main_GetPszVariable ) ( char *, char * );
433     void   ( * main_PutIntVariable ) ( char *, int );
434     void   ( * main_PutPszVariable ) ( char *, char * );
435
436     int  ( * TestProgram )  ( char * );
437     int  ( * TestMethod )   ( char *, char * );
438     int  ( * TestCPU )      ( int );
439
440     int  ( * intf_ProcessKey ) ( struct intf_thread_s *, int );
441     void ( * intf_AssignKey )  ( struct intf_thread_s *, int, int, int );
442
443     void ( * intf_Msg )        ( char *, ... );
444     void ( * intf_ErrMsg )     ( char *, ... );
445     void ( * intf_StatMsg )    ( char *, ... );
446     void ( * intf_WarnMsg )    ( int, char *, ... );
447     void ( * intf_WarnMsgImm ) ( int, char *, ... );
448 #ifdef TRACE
449     void ( * intf_DbgMsg )     ( char *, char *, int, char *, ... );
450     void ( * intf_DbgMsgImm )  ( char *, char *, int, char *, ... );
451 #endif
452
453     int  ( * intf_PlaylistAdd )     ( struct playlist_s *, int, const char* );
454     int  ( * intf_PlaylistDelete )  ( struct playlist_s *, int );
455     void ( * intf_PlaylistNext )    ( struct playlist_s * );
456     void ( * intf_PlaylistPrev )    ( struct playlist_s * );
457     void ( * intf_PlaylistDestroy ) ( struct playlist_s * );
458     void ( * intf_PlaylistJumpto )  ( struct playlist_s *, int );
459     void ( * intf_UrlDecode )       ( char * );
460
461     void    ( * msleep )         ( mtime_t );
462     mtime_t ( * mdate )          ( void );
463
464     int  ( * network_ChannelCreate )( void );
465     int  ( * network_ChannelJoin )  ( int );
466
467     int  ( * input_SetProgram )     ( struct input_thread_s *,
468                                       struct pgrm_descriptor_s * );
469     void ( * input_SetStatus )      ( struct input_thread_s *, int );
470     void ( * input_Seek )           ( struct input_thread_s *, off_t );
471     void ( * input_DumpStream )     ( struct input_thread_s * );
472     char * ( * input_OffsetToTime ) ( struct input_thread_s *, char *, off_t );
473     int  ( * input_ChangeES )       ( struct input_thread_s *,
474                                       struct es_descriptor_s *, u8 );
475     int  ( * input_ToggleES )       ( struct input_thread_s *,
476                                       struct es_descriptor_s *, boolean_t );
477     int  ( * input_ChangeArea )     ( struct input_thread_s *,
478                                       struct input_area_s * );
479     struct es_descriptor_s * ( * input_FindES ) ( struct input_thread_s *,
480                                                   u16 );
481     struct es_descriptor_s * ( * input_AddES ) ( struct input_thread_s *,
482                                       struct pgrm_descriptor_s *, u16, size_t );
483     void ( * input_DelES )          ( struct input_thread_s *,
484                                       struct es_descriptor_s * );
485     int  ( * input_SelectES )       ( struct input_thread_s *,
486                                       struct es_descriptor_s * );
487     int  ( * input_UnselectES )     ( struct input_thread_s *,
488                                       struct es_descriptor_s * );
489     struct pgrm_descriptor_s* ( * input_AddProgram ) ( struct input_thread_s *,
490                                                        u16, size_t );
491     void ( * input_DelProgram )     ( struct input_thread_s *,
492                                       struct pgrm_descriptor_s * );
493     struct input_area_s * ( * input_AddArea ) ( struct input_thread_s * );
494     void ( * input_DelArea )        ( struct input_thread_s *,
495                                       struct input_area_s * );
496
497     void ( * InitBitstream )        ( struct bit_stream_s *,
498                                       struct decoder_fifo_s *,
499                                       void ( * ) ( struct bit_stream_s *,
500                                                    boolean_t ),
501                                       void * );
502     void ( * DecoderError )         ( struct decoder_fifo_s * p_fifo );
503     int  ( * input_InitStream )     ( struct input_thread_s *, size_t );
504     void ( * input_EndStream )      ( struct input_thread_s * );
505
506     void ( * input_ParsePES )       ( struct input_thread_s *,
507                                       struct es_descriptor_s * );
508     void ( * input_GatherPES )      ( struct input_thread_s *,
509                                       struct data_packet_s *,
510                                       struct es_descriptor_s *,
511                                       boolean_t, boolean_t );
512     void ( * input_DecodePES )      ( struct decoder_fifo_s *,
513                                       struct pes_packet_s * );
514     struct es_descriptor_s * ( * input_ParsePS ) ( struct input_thread_s *,
515                                                    struct data_packet_s * );
516     void ( * input_DemuxPS )        ( struct input_thread_s *,
517                                       struct data_packet_s * );
518     void ( * input_DemuxTS )        ( struct input_thread_s *,
519                                       struct data_packet_s * );
520     void ( * input_DemuxPSI )       ( struct input_thread_s *,
521                                       struct data_packet_s *,
522                                       struct es_descriptor_s *, 
523                                       boolean_t, boolean_t );
524
525     int ( * input_ClockManageControl )   ( struct input_thread_s *,
526                                            struct pgrm_descriptor_s *,
527                                            mtime_t );
528
529     struct aout_fifo_s * ( * aout_CreateFifo ) 
530                                        ( int, int, long, long, long, void * );
531     void ( * aout_DestroyFifo )     ( struct aout_fifo_s * );
532
533     struct vout_thread_s * (* vout_CreateThread) ( int *, int, int, int, int );
534     void  ( * vout_DestroyThread )  ( struct vout_thread_s *, int * );
535
536     struct picture_s * ( * vout_CreatePicture )
537                                     ( struct vout_thread_s *,
538                                       boolean_t, boolean_t, boolean_t ); 
539     void  ( * vout_AllocatePicture )( struct picture_s *, int, int, int );
540     void  ( * vout_DisplayPicture ) ( struct vout_thread_s *, 
541                                       struct picture_s * );
542     void  ( * vout_DestroyPicture ) ( struct vout_thread_s *,
543                                       struct picture_s * );
544     void  ( * vout_LinkPicture )    ( struct vout_thread_s *,
545                                       struct picture_s * );
546     void  ( * vout_UnlinkPicture )  ( struct vout_thread_s *,
547                                       struct picture_s * );
548     void  ( * vout_DatePicture )    ( struct vout_thread_s *, 
549                                       struct picture_s *, mtime_t );
550     void  ( * vout_PlacePicture )   ( struct vout_thread_s *, int, int,
551                                       int *, int *, int *, int * );
552
553     struct subpicture_s * (* vout_CreateSubPicture)
554                                         ( struct vout_thread_s *, int, int );
555     void  ( * vout_DestroySubPicture )  ( struct vout_thread_s *, 
556                                           struct subpicture_s * );
557     void  ( * vout_DisplaySubPicture )  ( struct vout_thread_s *, 
558                                           struct subpicture_s * );
559     
560     u32  ( * UnalignedShowBits )    ( struct bit_stream_s *, unsigned int );
561     void ( * UnalignedRemoveBits )  ( struct bit_stream_s * );
562     u32  ( * UnalignedGetBits )     ( struct bit_stream_s *, unsigned int );
563
564     char * ( * DecodeLanguage ) ( u16 );
565
566     struct module_s * ( * module_Need )    ( int, void * );
567     void ( * module_Unneed )        ( struct module_s * );
568 } module_symbols_t;
569
570 #ifdef PLUGIN
571 extern module_symbols_t* p_symbols;
572 #endif
573
574 /*****************************************************************************
575  * Required vlc headers
576  *****************************************************************************/
577 #include "main.h"
578