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.90 2002/04/01 21:54:26 gbazin 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]); \
291 # define __bswap_64(i) \
292 (u64)((__bswap_32((i) & 0xffffffff) << 32) | \
293 __bswap_32(((i) >> 32) & 0xffffffff ))
296 #else /* NTOHL_IN_SYS_PARAM_H || WIN32 */
297 # include <netinet/in.h>
299 #endif /* NTOHL_IN_SYS_PARAM_H || WIN32 */
301 /* CEIL: division with round to nearest greater integer */
302 #define CEIL(n, d) ( ((n) / (d)) + ( ((n) % (d)) ? 1 : 0) )
304 /* PAD: PAD(n, d) = CEIL(n ,d) * d */
305 #define PAD(n, d) ( ((n) % (d)) ? ((((n) / (d)) + 1) * (d)) : (n) )
307 /* __MAX and __MIN: self explanatory */
309 # define __MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
312 # define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
315 /* MSB (big endian)/LSB (little endian) conversions - network order is always
316 * MSB, and should be used for both network communications and files. Note that
317 * byte orders other than little and big endians are not supported, but only
318 * the VAX seems to have such exotic properties - note that these 'functions'
319 * needs <netinet/in.h> or the local equivalent. */
320 #if !defined( WIN32 )
322 # define hton16 htons
323 # define hton32 htonl
324 # define hton64(i) ( i )
325 # define ntoh16 ntohs
326 # define ntoh32 ntohl
327 # define ntoh64(i) ( i )
329 # define hton16 htons
330 # define hton32 htonl
331 static __inline__ u64 __hton64( u64 i )
333 return ((u64)(htonl((i) & 0xffffffff)) << 32)
334 | htonl(((i) >> 32) & 0xffffffff );
336 # define hton64(i) __hton64( i )
337 # define ntoh16 ntohs
338 # define ntoh32 ntohl
339 # define ntoh64 hton64
341 #endif /* !defined( WIN32 ) */
343 /* Macros with automatic casts */
344 #define U64_AT(p) ( ntoh64 ( *( (u64 *)(p) ) ) )
345 #define U32_AT(p) ( ntoh32 ( *( (u32 *)(p) ) ) )
346 #define U16_AT(p) ( ntoh16 ( *( (u16 *)(p) ) ) )
348 /* Alignment of critical static data structures */
349 #ifdef ATTRIBUTE_ALIGNED_MAX
350 # define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
352 # define ATTR_ALIGN(align)
355 /* Alignment of critical dynamic data structure */
357 /* Some systems have memalign() but no declaration for it */
358 void * memalign( size_t align, size_t size );
361 /* That's like using a hammer to kill a fly, but eh... */
363 # define memalign(align,size) valloc(size)
365 /* Assume malloc alignment is sufficient */
366 # define memalign(align,size) malloc(size)
370 #define I64C(x) x##LL
374 /* The ntoh* and hton* bytes swapping functions are provided by winsock
375 * but for conveniency and speed reasons it is better to implement them
376 * ourselves. ( several plugins use them and it is too much hassle to link
377 * winsock with each of them ;-)
379 # ifdef WORDS_BIGENDIAN
380 # define ntoh32(x) (x)
381 # define ntoh16(x) (x)
382 # define ntoh64(x) (x)
383 # define hton32(x) (x)
384 # define hton16(x) (x)
385 # define hton64(x) (x)
387 # define ntoh32(x) __bswap_32 (x)
388 # define ntoh16(x) __bswap_16 (x)
389 # define ntoh64(x) __bswap_32 (x)
390 # define hton32(x) __bswap_32 (x)
391 # define hton16(x) __bswap_16 (x)
392 # define hton64(x) __bswap_64 (x)
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)
407 # define I64C(x) x##i64
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;
417 # define off_t long long
421 # if defined( _MSC_VER )
422 # if !defined( _OFF_T_DEFINED )
423 typedef __int64 off_t;
424 # define _OFF_T_DEFINED
426 # define off_t __int64
430 # if defined( __BORLANDC__ )
432 # define off_t unsigned __int64
436 # define O_NONBLOCK 0
440 # define snprintf _snprintf /* snprintf not defined in mingw32 (bug?) */
445 /*****************************************************************************
447 *****************************************************************************/
448 #define CPU_CAPABILITY_NONE 0
449 #define CPU_CAPABILITY_486 (1<<0)
450 #define CPU_CAPABILITY_586 (1<<1)
451 #define CPU_CAPABILITY_PPRO (1<<2)
452 #define CPU_CAPABILITY_MMX (1<<3)
453 #define CPU_CAPABILITY_3DNOW (1<<4)
454 #define CPU_CAPABILITY_MMXEXT (1<<5)
455 #define CPU_CAPABILITY_SSE (1<<6)
456 #define CPU_CAPABILITY_ALTIVEC (1<<16)
457 #define CPU_CAPABILITY_FPU (1<<31)
459 /*****************************************************************************
461 *****************************************************************************/
462 #if defined( ENABLE_NLS ) && defined ( HAVE_GETTEXT )
463 # include <libintl.h>
465 # define _(String) (String)
466 # define N_(String) (String)
469 /*****************************************************************************
471 *****************************************************************************/
472 typedef struct module_symbols_s
474 struct main_s* p_main;
475 struct module_bank_s* p_module_bank;
476 struct input_bank_s* p_input_bank;
477 struct aout_bank_s* p_aout_bank;
478 struct vout_bank_s* p_vout_bank;
480 int ( * config_GetIntVariable ) ( const char * );
481 char * ( * config_GetPszVariable ) ( const char * );
482 void ( * config_PutIntVariable ) ( const char *, int );
483 void ( * config_PutPszVariable ) ( const char *, char * );
484 int ( * config_LoadConfigFile ) ( const char * );
485 int ( * config_SaveConfigFile ) ( const char * );
486 struct module_config_s * ( * config_FindConfig ) ( const char * );
487 struct module_config_s * ( * config_Duplicate ) ( struct module_s * );
489 struct intf_subscription_s * ( * intf_MsgSub ) ( void );
490 void ( * intf_MsgUnsub ) ( struct intf_subscription_s * );
492 void ( * intf_Msg ) ( char *, ... );
493 void ( * intf_ErrMsg ) ( char *, ... );
494 void ( * intf_StatMsg ) ( char *, ... );
495 void ( * intf_WarnMsg ) ( int, char *, ... );
497 int ( * intf_PlaylistAdd ) ( struct playlist_s *, int, const char* );
498 int ( * intf_PlaylistDelete ) ( struct playlist_s *, int );
499 void ( * intf_PlaylistNext ) ( struct playlist_s * );
500 void ( * intf_PlaylistPrev ) ( struct playlist_s * );
501 void ( * intf_PlaylistDestroy ) ( struct playlist_s * );
502 void ( * intf_PlaylistJumpto ) ( struct playlist_s *, int );
503 void ( * intf_UrlDecode ) ( char * );
504 int ( * intf_Eject ) ( const char * );
506 void ( * msleep ) ( mtime_t );
507 mtime_t ( * mdate ) ( void );
508 char * ( * mstrtime ) ( char *, mtime_t );
510 int ( * network_ChannelCreate )( void );
511 int ( * network_ChannelJoin ) ( int );
513 int ( * input_SetProgram ) ( struct input_thread_s *,
514 struct pgrm_descriptor_s * );
515 void ( * input_SetStatus ) ( struct input_thread_s *, int );
516 void ( * input_Seek ) ( struct input_thread_s *, off_t );
517 void ( * input_DumpStream ) ( struct input_thread_s * );
518 char * ( * input_OffsetToTime ) ( struct input_thread_s *, char *, off_t );
519 int ( * input_ChangeES ) ( struct input_thread_s *,
520 struct es_descriptor_s *, u8 );
521 int ( * input_ToggleES ) ( struct input_thread_s *,
522 struct es_descriptor_s *, boolean_t );
523 int ( * input_ChangeArea ) ( struct input_thread_s *,
524 struct input_area_s * );
525 int ( * input_ChangeProgram ) ( struct input_thread_s *, u16 );
526 struct es_descriptor_s * ( * input_FindES ) ( struct input_thread_s *,
528 struct es_descriptor_s * ( * input_AddES ) ( struct input_thread_s *,
529 struct pgrm_descriptor_s *, u16, size_t );
530 void ( * input_DelES ) ( struct input_thread_s *,
531 struct es_descriptor_s * );
532 int ( * input_SelectES ) ( struct input_thread_s *,
533 struct es_descriptor_s * );
534 int ( * input_UnselectES ) ( struct input_thread_s *,
535 struct es_descriptor_s * );
536 struct pgrm_descriptor_s* ( * input_AddProgram ) ( struct input_thread_s *,
538 void ( * input_DelProgram ) ( struct input_thread_s *,
539 struct pgrm_descriptor_s * );
540 struct input_area_s * ( * input_AddArea ) ( struct input_thread_s * );
541 void ( * input_DelArea ) ( struct input_thread_s *,
542 struct input_area_s * );
544 void ( * InitBitstream ) ( struct bit_stream_s *,
545 struct decoder_fifo_s *,
546 void ( * ) ( struct bit_stream_s *,
549 void ( * BitstreamNextDataPacket )( struct bit_stream_s * );
550 boolean_t ( * NextDataPacket ) ( struct decoder_fifo_s *,
551 struct data_packet_s ** );
552 void ( * DecoderError ) ( struct decoder_fifo_s * p_fifo );
553 int ( * input_InitStream ) ( struct input_thread_s *, size_t );
554 void ( * input_EndStream ) ( struct input_thread_s * );
556 void ( * input_ParsePES ) ( struct input_thread_s *,
557 struct es_descriptor_s * );
558 void ( * input_GatherPES ) ( struct input_thread_s *,
559 struct data_packet_s *,
560 struct es_descriptor_s *,
561 boolean_t, boolean_t );
562 void ( * input_DecodePES ) ( struct decoder_fifo_s *,
563 struct pes_packet_s * );
564 struct es_descriptor_s * ( * input_ParsePS ) ( struct input_thread_s *,
565 struct data_packet_s * );
566 ssize_t ( * input_ReadPS ) ( struct input_thread_s *,
567 struct data_packet_s ** );
568 void ( * input_DemuxPS ) ( struct input_thread_s *,
569 struct data_packet_s * );
570 ssize_t ( * input_ReadTS ) ( struct input_thread_s *,
571 struct data_packet_s ** );
572 void ( * input_DemuxTS ) ( struct input_thread_s *,
573 struct data_packet_s * );
574 void ( * input_DemuxPSI ) ( struct input_thread_s *,
575 struct data_packet_s *,
576 struct es_descriptor_s *,
577 boolean_t, boolean_t );
578 int ( * input_ClockManageControl ) ( struct input_thread_s *,
579 struct pgrm_descriptor_s *,
581 void ( * input_FDSeek ) ( struct input_thread_s *, off_t );
582 void ( * input_FDClose ) ( struct input_thread_s * );
583 ssize_t ( * input_FDRead ) ( struct input_thread_s *, byte_t *,
585 ssize_t ( * input_FDNetworkRead ) ( struct input_thread_s *, byte_t *,
588 void * ( * input_BuffersInit )( void );
589 void ( * input_BuffersEnd )( struct input_buffers_s * );
590 struct data_buffer_s * ( * input_NewBuffer )( struct input_buffers_s *, size_t );
591 void ( * input_ReleaseBuffer )( struct input_buffers_s *, struct data_buffer_s * );
592 struct data_packet_s * ( * input_ShareBuffer )( struct input_buffers_s *,
593 struct data_buffer_s * );
594 struct data_packet_s * ( * input_NewPacket )( struct input_buffers_s *, size_t );
595 void ( * input_DeletePacket )( struct input_buffers_s *, struct data_packet_s * );
596 struct pes_packet_s * ( * input_NewPES )( struct input_buffers_s * );
597 void ( * input_DeletePES )( struct input_buffers_s *, struct pes_packet_s * );
598 ssize_t ( * input_FillBuffer )( struct input_thread_s * );
599 ssize_t ( * input_Peek )( struct input_thread_s *, byte_t **, size_t );
600 ssize_t ( * input_SplitBuffer )( struct input_thread_s *, struct data_packet_s **, size_t );
601 int ( * input_AccessInit )( struct input_thread_s * );
602 void ( * input_AccessReinit )( struct input_thread_s * );
603 void ( * input_AccessEnd )( struct input_thread_s * );
605 struct aout_fifo_s * ( * aout_CreateFifo ) ( int, int, int, int, void * );
606 void ( * aout_DestroyFifo ) ( struct aout_fifo_s * );
608 struct vout_thread_s * (* vout_CreateThread) ( int *, int, int, u32, int );
609 void ( * vout_DestroyThread ) ( struct vout_thread_s *, int * );
611 struct picture_s * ( * vout_CreatePicture )
612 ( struct vout_thread_s *,
613 boolean_t, boolean_t, boolean_t );
614 void ( * vout_AllocatePicture )( struct picture_s *, int, int, u32 );
615 void ( * vout_DisplayPicture ) ( struct vout_thread_s *,
616 struct picture_s * );
617 void ( * vout_DestroyPicture ) ( struct vout_thread_s *,
618 struct picture_s * );
619 void ( * vout_LinkPicture ) ( struct vout_thread_s *,
620 struct picture_s * );
621 void ( * vout_UnlinkPicture ) ( struct vout_thread_s *,
622 struct picture_s * );
623 void ( * vout_DatePicture ) ( struct vout_thread_s *,
624 struct picture_s *, mtime_t );
625 void ( * vout_PlacePicture ) ( struct vout_thread_s *, int, int,
626 int *, int *, int *, int * );
628 struct subpicture_s * (* vout_CreateSubPicture)
629 ( struct vout_thread_s *, int, int );
630 void ( * vout_DestroySubPicture ) ( struct vout_thread_s *,
631 struct subpicture_s * );
632 void ( * vout_DisplaySubPicture ) ( struct vout_thread_s *,
633 struct subpicture_s * );
635 u32 ( * UnalignedShowBits ) ( struct bit_stream_s *, unsigned int );
636 void ( * UnalignedRemoveBits ) ( struct bit_stream_s * );
637 u32 ( * UnalignedGetBits ) ( struct bit_stream_s *, unsigned int );
638 void ( * CurrentPTS ) ( struct bit_stream_s *, mtime_t *,
641 char * ( * DecodeLanguage ) ( u16 );
643 struct module_s * ( * module_Need ) ( int, char *, void * );
644 void ( * module_Unneed ) ( struct module_s * );
649 extern module_symbols_t* p_symbols;