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.89 2002/03/25 23:36:57 ipkiss 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 system headers
29 *****************************************************************************/
30 #include <string.h> /* strerror() */
31 #include <sys/types.h>
33 /*****************************************************************************
34 * Basic types definitions
35 *****************************************************************************/
37 typedef unsigned char u8;
38 typedef signed char s8;
40 typedef unsigned short u16;
41 typedef signed short s16;
43 typedef unsigned int u32;
44 typedef signed int s32;
46 #if defined( _MSC_VER ) || ( defined( WIN32 ) && !defined( __MINGW32__ ) )
47 typedef unsigned __int64 u64;
48 typedef signed __int64 s64;
50 typedef unsigned long long u64;
51 typedef signed long long s64;
57 #ifdef BOOLEAN_T_IN_SYS_TYPES_H
58 /* <sys/types.h> already included */
59 #elif defined(BOOLEAN_T_IN_PTHREAD_H)
61 #elif defined(BOOLEAN_T_IN_CTHREADS_H)
62 # include <cthreads.h>
64 typedef int boolean_t;
67 # define _MACH_I386_BOOLEAN_H_
70 /* ptrdiff_t definition */
77 /* Not portable in a 64-bit environment. */
78 typedef int ptrdiff_t;
86 /* Counter for statistics and profiling */
87 typedef unsigned long count_t;
89 /* DCT elements types */
90 typedef s16 dctelem_t;
92 /* Video buffer types */
93 typedef u8 yuv_data_t;
95 /*****************************************************************************
96 * mtime_t: high precision date or time interval
97 *****************************************************************************
98 * Store an high precision date or time interval. The maximum precision is the
99 * micro-second, and a 64 bits integer is used to avoid any overflow (maximum
100 * time interval is then 292271 years, which should be long enough for any
101 * video). Date are stored as a time interval since a common date.
102 * Note that date and time intervals can be manipulated using regular
103 * arithmetic operators, and that no special functions are required.
104 *****************************************************************************/
107 /*****************************************************************************
108 * Classes declaration
109 *****************************************************************************/
112 struct plugin_bank_s;
113 struct plugin_info_s;
115 typedef struct plugin_bank_s * p_plugin_bank_t;
116 typedef struct plugin_info_s * p_plugin_info_t;
120 struct playlist_item_s;
122 struct module_config_s;
124 typedef struct playlist_s * p_playlist_t;
125 typedef struct playlist_item_s * p_playlist_item_t;
126 typedef struct module_s * p_module_t;
127 typedef struct module_config_s * p_module_config_t;
130 struct intf_thread_s;
132 struct intf_console_s;
134 struct intf_channel_s;
136 typedef struct intf_thread_s * p_intf_thread_t;
137 typedef struct intf_sys_s * p_intf_sys_t;
138 typedef struct intf_console_s * p_intf_console_t;
139 typedef struct intf_msg_s * p_intf_msg_t;
140 typedef struct intf_channel_s * p_intf_channel_t;
143 struct input_thread_s;
144 struct input_channel_s;
148 typedef struct input_thread_s * p_input_thread_t;
149 typedef struct input_channel_s * p_input_channel_t;
150 typedef struct input_cfg_s * p_input_cfg_t;
151 typedef struct input_area_s * p_input_area_t;
154 struct aout_thread_s;
157 typedef struct aout_thread_s * p_aout_thread_t;
158 typedef struct aout_sys_s * p_aout_sys_t;
161 struct vout_thread_s;
165 struct vdec_thread_s;
166 struct vpar_thread_s;
167 struct video_parser_s;
169 typedef struct vout_thread_s * p_vout_thread_t;
170 typedef struct vout_font_s * p_vout_font_t;
171 typedef struct vout_sys_s * p_vout_sys_t;
172 typedef struct chroma_sys_s * p_chroma_sys_t;
173 typedef struct vdec_thread_s * p_vdec_thread_t;
174 typedef struct vpar_thread_s * p_vpar_thread_t;
175 typedef struct video_parser_s * p_video_parser_t;
178 struct decoder_config_s;
179 struct decoder_fifo_s;
183 struct data_packet_s;
188 struct picture_sys_s;
189 struct picture_heap_s;
190 struct es_descriptor_s;
191 struct pgrm_descriptor_s;
195 struct input_buffers_s;
196 struct network_socket_s;
197 struct intf_subscription_s;
199 /*****************************************************************************
200 * Macros and inline functions
201 *****************************************************************************/
202 #ifdef NTOHL_IN_SYS_PARAM_H
203 # include <sys/param.h>
206 /* Swap bytes in 16 bit value. */
207 # define __bswap_constant_16(x) \
208 ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
210 # if defined __GNUC__ && __GNUC__ >= 2
211 # define __bswap_16(x) \
213 ({ register unsigned short int __v; \
214 if (__builtin_constant_p (x)) \
215 __v = __bswap_constant_16 (x); \
217 __asm__ __volatile__ ("rorw $8, %w0" \
219 : "0" ((unsigned short int) (x)) \
223 /* This is better than nothing. */
224 # define __bswap_16(x) __bswap_constant_16 (x)
227 /* Swap bytes in 32 bit value. */
228 # define __bswap_constant_32(x) \
229 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
230 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
232 # if defined __GNUC__ && __GNUC__ >= 2
233 /* To swap the bytes in a word the i486 processors and up provide the
234 `bswap' opcode. On i386 we have to use three instructions. */
235 # if !defined __i486__ && !defined __pentium__ && !defined __pentiumpro__
236 # define __bswap_32(x) \
238 ({ register unsigned int __v; \
239 if (__builtin_constant_p (x)) \
240 __v = __bswap_constant_32 (x); \
242 __asm__ __volatile__ ("rorw $8, %w0;" \
246 : "0" ((unsigned int) (x)) \
250 # define __bswap_32(x) \
252 ({ register unsigned int __v; \
253 if (__builtin_constant_p (x)) \
254 __v = __bswap_constant_32 (x); \
256 __asm__ __volatile__ ("bswap %0" \
258 : "0" ((unsigned int) (x))); \
262 # define __bswap_32(x) __bswap_constant_32 (x)
265 # if defined __GNUC__ && __GNUC__ >= 2
266 /* Swap bytes in 64 bit value. */
267 # define __bswap_constant_64(x) \
268 ((((x) & 0xff00000000000000ull) >> 56) \
269 | (((x) & 0x00ff000000000000ull) >> 40) \
270 | (((x) & 0x0000ff0000000000ull) >> 24) \
271 | (((x) & 0x000000ff00000000ull) >> 8) \
272 | (((x) & 0x00000000ff000000ull) << 8) \
273 | (((x) & 0x0000000000ff0000ull) << 24) \
274 | (((x) & 0x000000000000ff00ull) << 40) \
275 | (((x) & 0x00000000000000ffull) << 56))
277 # define __bswap_64(x) \
279 ({ union { __extension__ unsigned long long int __ll; \
280 unsigned long int __l[2]; } __w, __r; \
281 if (__builtin_constant_p (x)) \
282 __r.__ll = __bswap_constant_64 (x); \
286 __r.__l[0] = __bswap_32 (__w.__l[1]); \
287 __r.__l[1] = __bswap_32 (__w.__l[0]); \
292 #else /* NTOHL_IN_SYS_PARAM_H || WIN32 */
293 # include <netinet/in.h>
295 #endif /* NTOHL_IN_SYS_PARAM_H || WIN32 */
297 /* CEIL: division with round to nearest greater integer */
298 #define CEIL(n, d) ( ((n) / (d)) + ( ((n) % (d)) ? 1 : 0) )
300 /* PAD: PAD(n, d) = CEIL(n ,d) * d */
301 #define PAD(n, d) ( ((n) % (d)) ? ((((n) / (d)) + 1) * (d)) : (n) )
303 /* __MAX and __MIN: self explanatory */
305 # define __MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
308 # define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
311 /* MSB (big endian)/LSB (little endian) conversions - network order is always
312 * MSB, and should be used for both network communications and files. Note that
313 * byte orders other than little and big endians are not supported, but only
314 * the VAX seems to have such exotic properties - note that these 'functions'
315 * needs <netinet/in.h> or the local equivalent. */
316 #if !defined( WIN32 )
318 # define hton16 htons
319 # define hton32 htonl
320 # define hton64(i) ( i )
321 # define ntoh16 ntohs
322 # define ntoh32 ntohl
323 # define ntoh64(i) ( i )
325 # define hton16 htons
326 # define hton32 htonl
327 static __inline__ u64 __hton64( u64 i )
329 return ((u64)(htonl((i) & 0xffffffff)) << 32)
330 | htonl(((i) >> 32) & 0xffffffff );
332 # define hton64(i) __hton64( i )
333 # define ntoh16 ntohs
334 # define ntoh32 ntohl
335 # define ntoh64 hton64
337 #endif /* !defined( WIN32 ) */
339 /* Macros with automatic casts */
340 #define U64_AT(p) ( ntoh64 ( *( (u64 *)(p) ) ) )
341 #define U32_AT(p) ( ntoh32 ( *( (u32 *)(p) ) ) )
342 #define U16_AT(p) ( ntoh16 ( *( (u16 *)(p) ) ) )
344 /* Alignment of critical static data structures */
345 #ifdef ATTRIBUTE_ALIGNED_MAX
346 # define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
348 # define ATTR_ALIGN(align)
351 /* Alignment of critical dynamic data structure */
353 /* Some systems have memalign() but no declaration for it */
354 void * memalign( size_t align, size_t size );
357 /* That's like using a hammer to kill a fly, but eh... */
359 # define memalign(align,size) valloc(size)
361 /* Assume malloc alignment is sufficient */
362 # define memalign(align,size) malloc(size)
366 #define I64C(x) x##LL
370 /* The ntoh* and hton* bytes swapping functions are provided by winsock
371 * but for conveniency and speed reasons it is better to implement them
372 * ourselves. ( several plugins use them and it is too much hassle to link
373 * winsock with each of them ;-)
375 # ifdef WORDS_BIGENDIAN
376 # define ntoh32(x) (x)
377 # define ntoh16(x) (x)
378 # define ntoh64(x) (x)
379 # define hton32(x) (x)
380 # define hton16(x) (x)
381 # define hton64(x) (x)
383 # define ntoh32(x) __bswap_32 (x)
384 # define ntoh16(x) __bswap_16 (x)
385 # define ntoh64(x) __bswap_32 (x)
386 # define hton32(x) __bswap_32 (x)
387 # define hton16(x) __bswap_16 (x)
388 # define hton64(x) __bswap_64 (x)
391 /* win32, cl and icl support */
392 # if defined( _MSC_VER ) || !defined( __MINGW32__ )
393 # define __attribute__(x)
394 # define __inline__ __inline
395 # define strncasecmp strnicmp
396 # define strcasecmp stricmp
397 # define S_ISBLK(m) (0)
398 # define S_ISCHR(m) (0)
399 # define S_ISFIFO(m) (((m)&_S_IFMT) == _S_IFIFO)
400 # define S_ISREG(m) (((m)&_S_IFMT) == _S_IFREG)
402 # define I64C(x) x##i64
405 /* several type definitions */
406 # if defined( __MINGW32__ )
407 # if !defined( _OFF_T_ )
408 typedef long long _off_t;
409 typedef _off_t off_t;
412 # define off_t long long
416 # if defined( _MSC_VER )
417 # if !defined( _OFF_T_DEFINED )
418 typedef __int64 off_t;
419 # define _OFF_T_DEFINED
421 # define off_t __int64
423 # define stat _stati64
426 # if defined( __BORLANDC__ )
428 # define off_t unsigned __int64
432 # define O_NONBLOCK 0
436 # define snprintf _snprintf /* snprintf not defined in mingw32 (bug?) */
441 /*****************************************************************************
443 *****************************************************************************/
444 #define CPU_CAPABILITY_NONE 0
445 #define CPU_CAPABILITY_486 (1<<0)
446 #define CPU_CAPABILITY_586 (1<<1)
447 #define CPU_CAPABILITY_PPRO (1<<2)
448 #define CPU_CAPABILITY_MMX (1<<3)
449 #define CPU_CAPABILITY_3DNOW (1<<4)
450 #define CPU_CAPABILITY_MMXEXT (1<<5)
451 #define CPU_CAPABILITY_SSE (1<<6)
452 #define CPU_CAPABILITY_ALTIVEC (1<<16)
453 #define CPU_CAPABILITY_FPU (1<<31)
455 /*****************************************************************************
457 *****************************************************************************/
458 #if defined( ENABLE_NLS ) && defined ( HAVE_GETTEXT )
459 # include <libintl.h>
461 # define _(String) (String)
462 # define N_(String) (String)
465 /*****************************************************************************
467 *****************************************************************************/
468 typedef struct module_symbols_s
470 struct main_s* p_main;
471 struct module_bank_s* p_module_bank;
472 struct input_bank_s* p_input_bank;
473 struct aout_bank_s* p_aout_bank;
474 struct vout_bank_s* p_vout_bank;
476 int ( * config_GetIntVariable ) ( const char * );
477 char * ( * config_GetPszVariable ) ( const char * );
478 void ( * config_PutIntVariable ) ( const char *, int );
479 void ( * config_PutPszVariable ) ( const char *, char * );
480 int ( * config_LoadConfigFile ) ( const char * );
481 int ( * config_SaveConfigFile ) ( const char * );
482 struct module_config_s * ( * config_FindConfig ) ( const char * );
483 struct module_config_s * ( * config_Duplicate ) ( struct module_s * );
485 struct intf_subscription_s * ( * intf_MsgSub ) ( void );
486 void ( * intf_MsgUnsub ) ( struct intf_subscription_s * );
488 void ( * intf_Msg ) ( char *, ... );
489 void ( * intf_ErrMsg ) ( char *, ... );
490 void ( * intf_StatMsg ) ( char *, ... );
491 void ( * intf_WarnMsg ) ( int, char *, ... );
493 int ( * intf_PlaylistAdd ) ( struct playlist_s *, int, const char* );
494 int ( * intf_PlaylistDelete ) ( struct playlist_s *, int );
495 void ( * intf_PlaylistNext ) ( struct playlist_s * );
496 void ( * intf_PlaylistPrev ) ( struct playlist_s * );
497 void ( * intf_PlaylistDestroy ) ( struct playlist_s * );
498 void ( * intf_PlaylistJumpto ) ( struct playlist_s *, int );
499 void ( * intf_UrlDecode ) ( char * );
500 int ( * intf_Eject ) ( const char * );
502 void ( * msleep ) ( mtime_t );
503 mtime_t ( * mdate ) ( void );
504 char * ( * mstrtime ) ( char *, mtime_t );
506 int ( * network_ChannelCreate )( void );
507 int ( * network_ChannelJoin ) ( int );
509 int ( * input_SetProgram ) ( struct input_thread_s *,
510 struct pgrm_descriptor_s * );
511 void ( * input_SetStatus ) ( struct input_thread_s *, int );
512 void ( * input_Seek ) ( struct input_thread_s *, off_t );
513 void ( * input_DumpStream ) ( struct input_thread_s * );
514 char * ( * input_OffsetToTime ) ( struct input_thread_s *, char *, off_t );
515 int ( * input_ChangeES ) ( struct input_thread_s *,
516 struct es_descriptor_s *, u8 );
517 int ( * input_ToggleES ) ( struct input_thread_s *,
518 struct es_descriptor_s *, boolean_t );
519 int ( * input_ChangeArea ) ( struct input_thread_s *,
520 struct input_area_s * );
521 int ( * input_ChangeProgram ) ( struct input_thread_s *, u16 );
522 struct es_descriptor_s * ( * input_FindES ) ( struct input_thread_s *,
524 struct es_descriptor_s * ( * input_AddES ) ( struct input_thread_s *,
525 struct pgrm_descriptor_s *, u16, size_t );
526 void ( * input_DelES ) ( struct input_thread_s *,
527 struct es_descriptor_s * );
528 int ( * input_SelectES ) ( struct input_thread_s *,
529 struct es_descriptor_s * );
530 int ( * input_UnselectES ) ( struct input_thread_s *,
531 struct es_descriptor_s * );
532 struct pgrm_descriptor_s* ( * input_AddProgram ) ( struct input_thread_s *,
534 void ( * input_DelProgram ) ( struct input_thread_s *,
535 struct pgrm_descriptor_s * );
536 struct input_area_s * ( * input_AddArea ) ( struct input_thread_s * );
537 void ( * input_DelArea ) ( struct input_thread_s *,
538 struct input_area_s * );
540 void ( * InitBitstream ) ( struct bit_stream_s *,
541 struct decoder_fifo_s *,
542 void ( * ) ( struct bit_stream_s *,
545 void ( * BitstreamNextDataPacket )( struct bit_stream_s * );
546 boolean_t ( * NextDataPacket ) ( struct decoder_fifo_s *,
547 struct data_packet_s ** );
548 void ( * DecoderError ) ( struct decoder_fifo_s * p_fifo );
549 int ( * input_InitStream ) ( struct input_thread_s *, size_t );
550 void ( * input_EndStream ) ( struct input_thread_s * );
552 void ( * input_ParsePES ) ( struct input_thread_s *,
553 struct es_descriptor_s * );
554 void ( * input_GatherPES ) ( struct input_thread_s *,
555 struct data_packet_s *,
556 struct es_descriptor_s *,
557 boolean_t, boolean_t );
558 void ( * input_DecodePES ) ( struct decoder_fifo_s *,
559 struct pes_packet_s * );
560 struct es_descriptor_s * ( * input_ParsePS ) ( struct input_thread_s *,
561 struct data_packet_s * );
562 ssize_t ( * input_ReadPS ) ( struct input_thread_s *,
563 struct data_packet_s ** );
564 void ( * input_DemuxPS ) ( struct input_thread_s *,
565 struct data_packet_s * );
566 ssize_t ( * input_ReadTS ) ( struct input_thread_s *,
567 struct data_packet_s ** );
568 void ( * input_DemuxTS ) ( struct input_thread_s *,
569 struct data_packet_s * );
570 void ( * input_DemuxPSI ) ( struct input_thread_s *,
571 struct data_packet_s *,
572 struct es_descriptor_s *,
573 boolean_t, boolean_t );
574 int ( * input_ClockManageControl ) ( struct input_thread_s *,
575 struct pgrm_descriptor_s *,
577 void ( * input_FDSeek ) ( struct input_thread_s *, off_t );
578 void ( * input_FDClose ) ( struct input_thread_s * );
579 ssize_t ( * input_FDRead ) ( struct input_thread_s *, byte_t *,
581 ssize_t ( * input_FDNetworkRead ) ( struct input_thread_s *, byte_t *,
584 void * ( * input_BuffersInit )( void );
585 void ( * input_BuffersEnd )( struct input_buffers_s * );
586 struct data_buffer_s * ( * input_NewBuffer )( struct input_buffers_s *, size_t );
587 void ( * input_ReleaseBuffer )( struct input_buffers_s *, struct data_buffer_s * );
588 struct data_packet_s * ( * input_ShareBuffer )( struct input_buffers_s *,
589 struct data_buffer_s * );
590 struct data_packet_s * ( * input_NewPacket )( struct input_buffers_s *, size_t );
591 void ( * input_DeletePacket )( struct input_buffers_s *, struct data_packet_s * );
592 struct pes_packet_s * ( * input_NewPES )( struct input_buffers_s * );
593 void ( * input_DeletePES )( struct input_buffers_s *, struct pes_packet_s * );
594 ssize_t ( * input_FillBuffer )( struct input_thread_s * );
595 ssize_t ( * input_Peek )( struct input_thread_s *, byte_t **, size_t );
596 ssize_t ( * input_SplitBuffer )( struct input_thread_s *, struct data_packet_s **, size_t );
597 int ( * input_AccessInit )( struct input_thread_s * );
598 void ( * input_AccessReinit )( struct input_thread_s * );
599 void ( * input_AccessEnd )( struct input_thread_s * );
601 struct aout_fifo_s * ( * aout_CreateFifo ) ( int, int, int, int, void * );
602 void ( * aout_DestroyFifo ) ( struct aout_fifo_s * );
604 struct vout_thread_s * (* vout_CreateThread) ( int *, int, int, u32, int );
605 void ( * vout_DestroyThread ) ( struct vout_thread_s *, int * );
607 struct picture_s * ( * vout_CreatePicture )
608 ( struct vout_thread_s *,
609 boolean_t, boolean_t, boolean_t );
610 void ( * vout_AllocatePicture )( struct picture_s *, int, int, u32 );
611 void ( * vout_DisplayPicture ) ( struct vout_thread_s *,
612 struct picture_s * );
613 void ( * vout_DestroyPicture ) ( struct vout_thread_s *,
614 struct picture_s * );
615 void ( * vout_LinkPicture ) ( struct vout_thread_s *,
616 struct picture_s * );
617 void ( * vout_UnlinkPicture ) ( struct vout_thread_s *,
618 struct picture_s * );
619 void ( * vout_DatePicture ) ( struct vout_thread_s *,
620 struct picture_s *, mtime_t );
621 void ( * vout_PlacePicture ) ( struct vout_thread_s *, int, int,
622 int *, int *, int *, int * );
624 struct subpicture_s * (* vout_CreateSubPicture)
625 ( struct vout_thread_s *, int, int );
626 void ( * vout_DestroySubPicture ) ( struct vout_thread_s *,
627 struct subpicture_s * );
628 void ( * vout_DisplaySubPicture ) ( struct vout_thread_s *,
629 struct subpicture_s * );
631 u32 ( * UnalignedShowBits ) ( struct bit_stream_s *, unsigned int );
632 void ( * UnalignedRemoveBits ) ( struct bit_stream_s * );
633 u32 ( * UnalignedGetBits ) ( struct bit_stream_s *, unsigned int );
634 void ( * CurrentPTS ) ( struct bit_stream_s *, mtime_t *,
637 char * ( * DecodeLanguage ) ( u16 );
639 struct module_s * ( * module_Need ) ( int, char *, void * );
640 void ( * module_Unneed ) ( struct module_s * );
645 extern module_symbols_t* p_symbols;