1 /*****************************************************************************
2 * vlc.h: common definitions
3 * Collection of useful common types and macros definitions
4 *****************************************************************************
5 * Copyright (C) 1998, 1999, 2000 VideoLAN
6 * $Id: vlc.h,v 1.1 2001/12/30 07:09:54 sam 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() */
32 /*****************************************************************************
33 * Required vlc headers
34 *****************************************************************************/
37 #include "int_types.h"
39 #if defined( PLUGIN ) || defined( BUILTIN )
40 # include "modules_inner.h"
43 /*****************************************************************************
44 * Basic types definitions
45 *****************************************************************************/
50 #ifdef BOOLEAN_T_IN_SYS_TYPES_H
51 # include <sys/types.h>
52 #elif defined(BOOLEAN_T_IN_PTHREAD_H)
54 #elif defined(BOOLEAN_T_IN_CTHREADS_H)
55 # include <cthreads.h>
57 typedef int boolean_t;
60 # define _MACH_I386_BOOLEAN_H_
63 /* ptrdiff_t definition */
70 /* Not portable in a 64-bit environment. */
71 typedef int ptrdiff_t;
75 /* Counter for statistics and profiling */
76 typedef unsigned long count_t;
78 /* DCT elements types */
79 typedef s16 dctelem_t;
81 /* Video buffer types */
82 typedef u8 yuv_data_t;
84 /*****************************************************************************
85 * mtime_t: high precision date or time interval
86 *****************************************************************************
87 * Store an high precision date or time interval. The maximum precision is the
88 * micro-second, and a 64 bits integer is used to avoid any overflow (maximum
89 * time interval is then 292271 years, which should be long enough for any
90 * video). Date are stored as a time interval since a common date.
91 * Note that date and time intervals can be manipulated using regular
92 * arithmetic operators, and that no special functions are required.
93 *****************************************************************************/
96 /*****************************************************************************
98 *****************************************************************************/
101 struct plugin_bank_s;
102 struct plugin_info_s;
104 typedef struct plugin_bank_s * p_plugin_bank_t;
105 typedef struct plugin_info_s * p_plugin_info_t;
109 struct playlist_item_s;
112 typedef struct playlist_s * p_playlist_t;
113 typedef struct playlist_item_s * p_playlist_item_t;
116 struct intf_thread_s;
118 struct intf_console_s;
120 struct intf_channel_s;
122 typedef struct intf_thread_s * p_intf_thread_t;
123 typedef struct intf_sys_s * p_intf_sys_t;
124 typedef struct intf_console_s * p_intf_console_t;
125 typedef struct intf_msg_s * p_intf_msg_t;
126 typedef struct intf_channel_s * p_intf_channel_t;
129 struct input_thread_s;
130 struct input_channel_s;
134 typedef struct input_thread_s * p_input_thread_t;
135 typedef struct input_channel_s * p_input_channel_t;
136 typedef struct input_cfg_s * p_input_cfg_t;
137 typedef struct input_area_s * p_input_area_t;
140 struct aout_thread_s;
143 typedef struct aout_thread_s * p_aout_thread_t;
144 typedef struct aout_sys_s * p_aout_sys_t;
147 struct vout_thread_s;
150 struct vdec_thread_s;
151 struct vpar_thread_s;
152 struct video_parser_s;
154 typedef struct vout_thread_s * p_vout_thread_t;
155 typedef struct vout_font_s * p_vout_font_t;
156 typedef struct vout_sys_s * p_vout_sys_t;
157 typedef struct chroma_sys_s * p_chroma_sys_t;
158 typedef struct vdec_thread_s * p_vdec_thread_t;
159 typedef struct vpar_thread_s * p_vpar_thread_t;
160 typedef struct video_parser_s * p_video_parser_t;
163 struct decoder_config_s;
164 struct decoder_fifo_s;
168 struct data_packet_s;
173 struct picture_sys_s;
174 struct picture_heap_s;
175 struct es_descriptor_s;
176 struct pgrm_descriptor_s;
182 /*****************************************************************************
183 * Macros and inline functions
184 *****************************************************************************/
185 #ifdef NTOHL_IN_SYS_PARAM_H
186 # include <sys/param.h>
189 /* Swap bytes in 16 bit value. */
190 # define __bswap_constant_16(x) \
191 ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
193 # if defined __GNUC__ && __GNUC__ >= 2
194 # define __bswap_16(x) \
196 ({ register unsigned short int __v; \
197 if (__builtin_constant_p (x)) \
198 __v = __bswap_constant_16 (x); \
200 __asm__ __volatile__ ("rorw $8, %w0" \
202 : "0" ((unsigned short int) (x)) \
206 /* This is better than nothing. */
207 # define __bswap_16(x) __bswap_constant_16 (x)
210 /* Swap bytes in 32 bit value. */
211 # define __bswap_constant_32(x) \
212 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
213 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
215 # if defined __GNUC__ && __GNUC__ >= 2
216 /* To swap the bytes in a word the i486 processors and up provide the
217 `bswap' opcode. On i386 we have to use three instructions. */
218 # if !defined __i486__ && !defined __pentium__ && !defined __pentiumpro__
219 # define __bswap_32(x) \
221 ({ register unsigned int __v; \
222 if (__builtin_constant_p (x)) \
223 __v = __bswap_constant_32 (x); \
225 __asm__ __volatile__ ("rorw $8, %w0;" \
229 : "0" ((unsigned int) (x)) \
233 # define __bswap_32(x) \
235 ({ register unsigned int __v; \
236 if (__builtin_constant_p (x)) \
237 __v = __bswap_constant_32 (x); \
239 __asm__ __volatile__ ("bswap %0" \
241 : "0" ((unsigned int) (x))); \
245 # define __bswap_32(x) __bswap_constant_32 (x)
248 # if defined __GNUC__ && __GNUC__ >= 2
249 /* Swap bytes in 64 bit value. */
250 # define __bswap_constant_64(x) \
251 ((((x) & 0xff00000000000000ull) >> 56) \
252 | (((x) & 0x00ff000000000000ull) >> 40) \
253 | (((x) & 0x0000ff0000000000ull) >> 24) \
254 | (((x) & 0x000000ff00000000ull) >> 8) \
255 | (((x) & 0x00000000ff000000ull) << 8) \
256 | (((x) & 0x0000000000ff0000ull) << 24) \
257 | (((x) & 0x000000000000ff00ull) << 40) \
258 | (((x) & 0x00000000000000ffull) << 56))
260 # define __bswap_64(x) \
262 ({ union { __extension__ unsigned long long int __ll; \
263 unsigned long int __l[2]; } __w, __r; \
264 if (__builtin_constant_p (x)) \
265 __r.__ll = __bswap_constant_64 (x); \
269 __r.__l[0] = __bswap_32 (__w.__l[1]); \
270 __r.__l[1] = __bswap_32 (__w.__l[0]); \
275 #else /* NTOHL_IN_SYS_PARAM_H || WIN32 */
276 # include <netinet/in.h>
278 #endif /* NTOHL_IN_SYS_PARAM_H || WIN32 */
280 /* CEIL: division with round to nearest greater integer */
281 #define CEIL(n, d) ( ((n) / (d)) + ( ((n) % (d)) ? 1 : 0) )
283 /* PAD: PAD(n, d) = CEIL(n ,d) * d */
284 #define PAD(n, d) ( ((n) % (d)) ? ((((n) / (d)) + 1) * (d)) : (n) )
286 /* MAX and MIN: self explanatory */
288 # define MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
291 # define MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
294 /* MSB (big endian)/LSB (little endian) conversions - network order is always
295 * MSB, and should be used for both network communications and files. Note that
296 * byte orders other than little and big endians are not supported, but only
297 * the VAX seems to have such exotic properties - note that these 'functions'
298 * needs <netinet/in.h> or the local equivalent. */
299 /* FIXME: hton64 should be declared as an extern inline function to avoid
300 * border effects (see byteorder.h) */
302 # define hton16 htons
303 # define hton32 htonl
304 # define hton64(i) ( i )
305 # define ntoh16 ntohs
306 # define ntoh32 ntohl
307 # define ntoh64(i) ( i )
309 # define hton16 htons
310 # define hton32 htonl
311 # define hton64(i) ( ((u64)(htonl((i) & 0xffffffff)) << 32) | htonl(((i) >> 32) & 0xffffffff ) )
312 # define ntoh16 ntohs
313 # define ntoh32 ntohl
314 # define ntoh64 hton64
317 /* Macros with automatic casts */
318 #define U64_AT(p) ( ntoh64 ( *( (u64 *)(p) ) ) )
319 #define U32_AT(p) ( ntoh32 ( *( (u32 *)(p) ) ) )
320 #define U16_AT(p) ( ntoh16 ( *( (u16 *)(p) ) ) )
322 /* Alignment of critical static data structures */
323 #ifdef ATTRIBUTE_ALIGNED_MAX
324 # define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
326 # define ATTR_ALIGN(align)
329 /* Alignment of critical dynamic data structure */
331 /* Some systems have memalign() but no declaration for it */
332 void * memalign( size_t align, size_t size );
335 /* That's like using a hammer to kill a fly, but eh... */
337 # define memalign(align,size) valloc(size)
339 /* Assume malloc alignment is sufficient */
340 # define memalign(align,size) malloc(size)
344 #define I64C(x) x##LL
348 /* The ntoh* and hton* bytes swapping functions are provided by winsock
349 * but for conveniency and speed reasons it is better to implement them
350 * ourselves. ( several plugins use them and it is too much hassle to link
351 * winsock with each of them ;-)
360 # ifdef WORDS_BIGENDIAN
361 # define ntoh32(x) (x)
362 # define ntoh16(x) (x)
363 # define ntoh64(x) (x)
364 # define hton32(x) (x)
365 # define hton16(x) (x)
366 # define hton64(x) (x)
368 # define ntoh32(x) __bswap_32 (x)
369 # define ntoh16(x) __bswap_16 (x)
370 # define ntoh64(x) __bswap_32 (x)
371 # define hton32(x) __bswap_32 (x)
372 # define hton16(x) __bswap_16 (x)
373 # define hton64(x) __bswap_32 (x)
376 /* win32, cl and icl support */
377 # if defined( _MSC_VER )
378 # define __attribute__(x)
379 # define __inline__ __inline
380 # define strncasecmp strnicmp
381 # define strcasecmp stricmp
382 # define S_ISBLK(m) (0)
383 # define S_ISCHR(m) (0)
384 # define S_ISFIFO(m) (((m)&_S_IFMT) == _S_IFIFO)
385 # define S_ISREG(m) (((m)&_S_IFMT) == _S_IFREG)
387 # define I64C(x) x##i64
390 /* several type definitions */
391 # if defined( __MINGW32__ )
392 # if !defined( _OFF_T_ )
393 typedef long long _off_t;
394 typedef _off_t off_t;
397 # define off_t long long
401 # if defined( _MSC_VER )
402 # if !defined( _OFF_T_DEFINED )
403 typedef __int64 off_t;
404 # define _OFF_T_DEFINED
406 # define off_t __int64
408 # define stat _stati64
412 # define snprintf _snprintf /* snprintf not defined in mingw32 (bug?) */
417 /*****************************************************************************
419 *****************************************************************************/
420 #define CPU_CAPABILITY_NONE 0
421 #define CPU_CAPABILITY_486 1<<0
422 #define CPU_CAPABILITY_586 1<<1
423 #define CPU_CAPABILITY_PPRO 1<<2
424 #define CPU_CAPABILITY_MMX 1<<3
425 #define CPU_CAPABILITY_3DNOW 1<<4
426 #define CPU_CAPABILITY_MMXEXT 1<<5
427 #define CPU_CAPABILITY_SSE 1<<6
428 #define CPU_CAPABILITY_ALTIVEC 1<<16
429 #define CPU_CAPABILITY_FPU 1<<31
431 /*****************************************************************************
433 *****************************************************************************/
434 #if defined( ENABLE_NLS ) && defined ( HAVE_GETTEXT )
435 # include <libintl.h>
437 # define _(String) (String)
438 # define N_(String) (String)
439 # define textdomain(Domain)
440 # define bindtextdomain(Package, Directory) 1
443 /*****************************************************************************
445 *****************************************************************************/
446 typedef struct module_symbols_s
448 struct main_s* p_main;
449 struct aout_bank_s* p_aout_bank;
450 struct vout_bank_s* p_vout_bank;
452 int ( * main_GetIntVariable ) ( char *, int );
453 char * ( * main_GetPszVariable ) ( char *, char * );
454 void ( * main_PutIntVariable ) ( char *, int );
455 void ( * main_PutPszVariable ) ( char *, char * );
457 int ( * intf_ProcessKey ) ( struct intf_thread_s *, int );
458 void ( * intf_AssignKey ) ( struct intf_thread_s *, int, int, int );
460 void ( * intf_Msg ) ( char *, ... );
461 void ( * intf_ErrMsg ) ( char *, ... );
462 void ( * intf_StatMsg ) ( char *, ... );
463 void ( * intf_WarnMsg ) ( int, char *, ... );
464 void ( * intf_WarnMsgImm ) ( int, char *, ... );
466 void ( * intf_DbgMsg ) ( char *, char *, int, char *, ... );
467 void ( * intf_DbgMsgImm ) ( char *, char *, int, char *, ... );
470 int ( * intf_PlaylistAdd ) ( struct playlist_s *, int, const char* );
471 int ( * intf_PlaylistDelete ) ( struct playlist_s *, int );
472 void ( * intf_PlaylistNext ) ( struct playlist_s * );
473 void ( * intf_PlaylistPrev ) ( struct playlist_s * );
474 void ( * intf_PlaylistDestroy ) ( struct playlist_s * );
475 void ( * intf_PlaylistJumpto ) ( struct playlist_s *, int );
476 void ( * intf_UrlDecode ) ( char * );
478 void ( * msleep ) ( mtime_t );
479 mtime_t ( * mdate ) ( void );
481 int ( * network_ChannelCreate )( void );
482 int ( * network_ChannelJoin ) ( int );
484 int ( * input_SetProgram ) ( struct input_thread_s *,
485 struct pgrm_descriptor_s * );
486 void ( * input_SetStatus ) ( struct input_thread_s *, int );
487 void ( * input_Seek ) ( struct input_thread_s *, off_t );
488 void ( * input_DumpStream ) ( struct input_thread_s * );
489 char * ( * input_OffsetToTime ) ( struct input_thread_s *, char *, off_t );
490 int ( * input_ChangeES ) ( struct input_thread_s *,
491 struct es_descriptor_s *, u8 );
492 int ( * input_ToggleES ) ( struct input_thread_s *,
493 struct es_descriptor_s *, boolean_t );
494 int ( * input_ChangeArea ) ( struct input_thread_s *,
495 struct input_area_s * );
496 struct es_descriptor_s * ( * input_FindES ) ( struct input_thread_s *,
498 struct es_descriptor_s * ( * input_AddES ) ( struct input_thread_s *,
499 struct pgrm_descriptor_s *, u16, size_t );
500 void ( * input_DelES ) ( struct input_thread_s *,
501 struct es_descriptor_s * );
502 int ( * input_SelectES ) ( struct input_thread_s *,
503 struct es_descriptor_s * );
504 int ( * input_UnselectES ) ( struct input_thread_s *,
505 struct es_descriptor_s * );
506 struct pgrm_descriptor_s* ( * input_AddProgram ) ( struct input_thread_s *,
508 void ( * input_DelProgram ) ( struct input_thread_s *,
509 struct pgrm_descriptor_s * );
510 struct input_area_s * ( * input_AddArea ) ( struct input_thread_s * );
511 void ( * input_DelArea ) ( struct input_thread_s *,
512 struct input_area_s * );
514 void ( * InitBitstream ) ( struct bit_stream_s *,
515 struct decoder_fifo_s *,
516 void ( * ) ( struct bit_stream_s *,
519 void ( * DecoderError ) ( struct decoder_fifo_s * p_fifo );
520 int ( * input_InitStream ) ( struct input_thread_s *, size_t );
521 void ( * input_EndStream ) ( struct input_thread_s * );
523 void ( * input_ParsePES ) ( struct input_thread_s *,
524 struct es_descriptor_s * );
525 void ( * input_GatherPES ) ( struct input_thread_s *,
526 struct data_packet_s *,
527 struct es_descriptor_s *,
528 boolean_t, boolean_t );
529 void ( * input_DecodePES ) ( struct decoder_fifo_s *,
530 struct pes_packet_s * );
531 struct es_descriptor_s * ( * input_ParsePS ) ( struct input_thread_s *,
532 struct data_packet_s * );
533 void ( * input_DemuxPS ) ( struct input_thread_s *,
534 struct data_packet_s * );
535 void ( * input_DemuxTS ) ( struct input_thread_s *,
536 struct data_packet_s * );
537 void ( * input_DemuxPSI ) ( struct input_thread_s *,
538 struct data_packet_s *,
539 struct es_descriptor_s *,
540 boolean_t, boolean_t );
542 int ( * input_ClockManageControl ) ( struct input_thread_s *,
543 struct pgrm_descriptor_s *,
546 struct aout_fifo_s * ( * aout_CreateFifo )
547 ( int, int, long, long, long, void * );
548 void ( * aout_DestroyFifo ) ( struct aout_fifo_s * );
550 struct vout_thread_s * (* vout_CreateThread) ( int *, int, int, int, int );
551 void ( * vout_DestroyThread ) ( struct vout_thread_s *, int * );
553 struct picture_s * ( * vout_CreatePicture )
554 ( struct vout_thread_s *,
555 boolean_t, boolean_t, boolean_t );
556 void ( * vout_AllocatePicture )( struct picture_s *, int, int, int );
557 void ( * vout_DisplayPicture ) ( struct vout_thread_s *,
558 struct picture_s * );
559 void ( * vout_DestroyPicture ) ( struct vout_thread_s *,
560 struct picture_s * );
561 void ( * vout_LinkPicture ) ( struct vout_thread_s *,
562 struct picture_s * );
563 void ( * vout_UnlinkPicture ) ( struct vout_thread_s *,
564 struct picture_s * );
565 void ( * vout_DatePicture ) ( struct vout_thread_s *,
566 struct picture_s *, mtime_t );
567 void ( * vout_PlacePicture ) ( struct vout_thread_s *, int, int,
568 int *, int *, int *, int * );
570 struct subpicture_s * (* vout_CreateSubPicture)
571 ( struct vout_thread_s *, int, int );
572 void ( * vout_DestroySubPicture ) ( struct vout_thread_s *,
573 struct subpicture_s * );
574 void ( * vout_DisplaySubPicture ) ( struct vout_thread_s *,
575 struct subpicture_s * );
577 u32 ( * UnalignedShowBits ) ( struct bit_stream_s *, unsigned int );
578 void ( * UnalignedRemoveBits ) ( struct bit_stream_s * );
579 u32 ( * UnalignedGetBits ) ( struct bit_stream_s *, unsigned int );
581 char * ( * DecodeLanguage ) ( u16 );
583 struct module_s * ( * module_Need ) ( int, char *, struct probedata_s * );
584 void ( * module_Unneed ) ( struct module_s * );
588 extern module_symbols_t* p_symbols;
591 /*****************************************************************************
592 * Required vlc headers
593 *****************************************************************************/
595 # include "beos_specific.h"
598 # include "darwin_specific.h"
601 # include "win32_specific.h"
604 #include "intf_msg.h"