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.2 2002/01/02 14:37:42 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;
151 struct vdec_thread_s;
152 struct vpar_thread_s;
153 struct video_parser_s;
155 typedef struct vout_thread_s * p_vout_thread_t;
156 typedef struct vout_font_s * p_vout_font_t;
157 typedef struct vout_sys_s * p_vout_sys_t;
158 typedef struct chroma_sys_s * p_chroma_sys_t;
159 typedef struct vdec_thread_s * p_vdec_thread_t;
160 typedef struct vpar_thread_s * p_vpar_thread_t;
161 typedef struct video_parser_s * p_video_parser_t;
164 struct decoder_config_s;
165 struct decoder_fifo_s;
169 struct data_packet_s;
174 struct picture_sys_s;
175 struct picture_heap_s;
176 struct es_descriptor_s;
177 struct pgrm_descriptor_s;
183 /*****************************************************************************
184 * Macros and inline functions
185 *****************************************************************************/
186 #ifdef NTOHL_IN_SYS_PARAM_H
187 # include <sys/param.h>
190 /* Swap bytes in 16 bit value. */
191 # define __bswap_constant_16(x) \
192 ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
194 # if defined __GNUC__ && __GNUC__ >= 2
195 # define __bswap_16(x) \
197 ({ register unsigned short int __v; \
198 if (__builtin_constant_p (x)) \
199 __v = __bswap_constant_16 (x); \
201 __asm__ __volatile__ ("rorw $8, %w0" \
203 : "0" ((unsigned short int) (x)) \
207 /* This is better than nothing. */
208 # define __bswap_16(x) __bswap_constant_16 (x)
211 /* Swap bytes in 32 bit value. */
212 # define __bswap_constant_32(x) \
213 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
214 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
216 # if defined __GNUC__ && __GNUC__ >= 2
217 /* To swap the bytes in a word the i486 processors and up provide the
218 `bswap' opcode. On i386 we have to use three instructions. */
219 # if !defined __i486__ && !defined __pentium__ && !defined __pentiumpro__
220 # define __bswap_32(x) \
222 ({ register unsigned int __v; \
223 if (__builtin_constant_p (x)) \
224 __v = __bswap_constant_32 (x); \
226 __asm__ __volatile__ ("rorw $8, %w0;" \
230 : "0" ((unsigned int) (x)) \
234 # define __bswap_32(x) \
236 ({ register unsigned int __v; \
237 if (__builtin_constant_p (x)) \
238 __v = __bswap_constant_32 (x); \
240 __asm__ __volatile__ ("bswap %0" \
242 : "0" ((unsigned int) (x))); \
246 # define __bswap_32(x) __bswap_constant_32 (x)
249 # if defined __GNUC__ && __GNUC__ >= 2
250 /* Swap bytes in 64 bit value. */
251 # define __bswap_constant_64(x) \
252 ((((x) & 0xff00000000000000ull) >> 56) \
253 | (((x) & 0x00ff000000000000ull) >> 40) \
254 | (((x) & 0x0000ff0000000000ull) >> 24) \
255 | (((x) & 0x000000ff00000000ull) >> 8) \
256 | (((x) & 0x00000000ff000000ull) << 8) \
257 | (((x) & 0x0000000000ff0000ull) << 24) \
258 | (((x) & 0x000000000000ff00ull) << 40) \
259 | (((x) & 0x00000000000000ffull) << 56))
261 # define __bswap_64(x) \
263 ({ union { __extension__ unsigned long long int __ll; \
264 unsigned long int __l[2]; } __w, __r; \
265 if (__builtin_constant_p (x)) \
266 __r.__ll = __bswap_constant_64 (x); \
270 __r.__l[0] = __bswap_32 (__w.__l[1]); \
271 __r.__l[1] = __bswap_32 (__w.__l[0]); \
276 #else /* NTOHL_IN_SYS_PARAM_H || WIN32 */
277 # include <netinet/in.h>
279 #endif /* NTOHL_IN_SYS_PARAM_H || WIN32 */
281 /* CEIL: division with round to nearest greater integer */
282 #define CEIL(n, d) ( ((n) / (d)) + ( ((n) % (d)) ? 1 : 0) )
284 /* PAD: PAD(n, d) = CEIL(n ,d) * d */
285 #define PAD(n, d) ( ((n) % (d)) ? ((((n) / (d)) + 1) * (d)) : (n) )
287 /* MAX and MIN: self explanatory */
289 # define MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
292 # define MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
295 /* MSB (big endian)/LSB (little endian) conversions - network order is always
296 * MSB, and should be used for both network communications and files. Note that
297 * byte orders other than little and big endians are not supported, but only
298 * the VAX seems to have such exotic properties - note that these 'functions'
299 * needs <netinet/in.h> or the local equivalent. */
300 /* FIXME: hton64 should be declared as an extern inline function to avoid
301 * border effects (see byteorder.h) */
303 # define hton16 htons
304 # define hton32 htonl
305 # define hton64(i) ( i )
306 # define ntoh16 ntohs
307 # define ntoh32 ntohl
308 # define ntoh64(i) ( i )
310 # define hton16 htons
311 # define hton32 htonl
312 # define hton64(i) ( ((u64)(htonl((i) & 0xffffffff)) << 32) | htonl(((i) >> 32) & 0xffffffff ) )
313 # define ntoh16 ntohs
314 # define ntoh32 ntohl
315 # define ntoh64 hton64
318 /* Macros with automatic casts */
319 #define U64_AT(p) ( ntoh64 ( *( (u64 *)(p) ) ) )
320 #define U32_AT(p) ( ntoh32 ( *( (u32 *)(p) ) ) )
321 #define U16_AT(p) ( ntoh16 ( *( (u16 *)(p) ) ) )
323 /* Alignment of critical static data structures */
324 #ifdef ATTRIBUTE_ALIGNED_MAX
325 # define ATTR_ALIGN(align) __attribute__ ((__aligned__ ((ATTRIBUTE_ALIGNED_MAX < align) ? ATTRIBUTE_ALIGNED_MAX : align)))
327 # define ATTR_ALIGN(align)
330 /* Alignment of critical dynamic data structure */
332 /* Some systems have memalign() but no declaration for it */
333 void * memalign( size_t align, size_t size );
336 /* That's like using a hammer to kill a fly, but eh... */
338 # define memalign(align,size) valloc(size)
340 /* Assume malloc alignment is sufficient */
341 # define memalign(align,size) malloc(size)
345 #define I64C(x) x##LL
349 /* The ntoh* and hton* bytes swapping functions are provided by winsock
350 * but for conveniency and speed reasons it is better to implement them
351 * ourselves. ( several plugins use them and it is too much hassle to link
352 * winsock with each of them ;-)
361 # ifdef WORDS_BIGENDIAN
362 # define ntoh32(x) (x)
363 # define ntoh16(x) (x)
364 # define ntoh64(x) (x)
365 # define hton32(x) (x)
366 # define hton16(x) (x)
367 # define hton64(x) (x)
369 # define ntoh32(x) __bswap_32 (x)
370 # define ntoh16(x) __bswap_16 (x)
371 # define ntoh64(x) __bswap_32 (x)
372 # define hton32(x) __bswap_32 (x)
373 # define hton16(x) __bswap_16 (x)
374 # define hton64(x) __bswap_32 (x)
377 /* win32, cl and icl support */
378 # if defined( _MSC_VER )
379 # define __attribute__(x)
380 # define __inline__ __inline
381 # define strncasecmp strnicmp
382 # define strcasecmp stricmp
383 # define S_ISBLK(m) (0)
384 # define S_ISCHR(m) (0)
385 # define S_ISFIFO(m) (((m)&_S_IFMT) == _S_IFIFO)
386 # define S_ISREG(m) (((m)&_S_IFMT) == _S_IFREG)
388 # define I64C(x) x##i64
391 /* several type definitions */
392 # if defined( __MINGW32__ )
393 # if !defined( _OFF_T_ )
394 typedef long long _off_t;
395 typedef _off_t off_t;
398 # define off_t long long
402 # if defined( _MSC_VER )
403 # if !defined( _OFF_T_DEFINED )
404 typedef __int64 off_t;
405 # define _OFF_T_DEFINED
407 # define off_t __int64
409 # define stat _stati64
413 # define snprintf _snprintf /* snprintf not defined in mingw32 (bug?) */
418 /*****************************************************************************
420 *****************************************************************************/
421 #define CPU_CAPABILITY_NONE 0
422 #define CPU_CAPABILITY_486 1<<0
423 #define CPU_CAPABILITY_586 1<<1
424 #define CPU_CAPABILITY_PPRO 1<<2
425 #define CPU_CAPABILITY_MMX 1<<3
426 #define CPU_CAPABILITY_3DNOW 1<<4
427 #define CPU_CAPABILITY_MMXEXT 1<<5
428 #define CPU_CAPABILITY_SSE 1<<6
429 #define CPU_CAPABILITY_ALTIVEC 1<<16
430 #define CPU_CAPABILITY_FPU 1<<31
432 /*****************************************************************************
434 *****************************************************************************/
435 #if defined( ENABLE_NLS ) && defined ( HAVE_GETTEXT )
436 # include <libintl.h>
438 # define _(String) (String)
439 # define N_(String) (String)
440 # define textdomain(Domain)
441 # define bindtextdomain(Package, Directory) 1
444 /*****************************************************************************
446 *****************************************************************************/
447 typedef struct module_symbols_s
449 struct main_s* p_main;
450 struct aout_bank_s* p_aout_bank;
451 struct vout_bank_s* p_vout_bank;
453 int ( * main_GetIntVariable ) ( char *, int );
454 char * ( * main_GetPszVariable ) ( char *, char * );
455 void ( * main_PutIntVariable ) ( char *, int );
456 void ( * main_PutPszVariable ) ( char *, char * );
458 int ( * intf_ProcessKey ) ( struct intf_thread_s *, int );
459 void ( * intf_AssignKey ) ( struct intf_thread_s *, int, int, int );
461 void ( * intf_Msg ) ( char *, ... );
462 void ( * intf_ErrMsg ) ( char *, ... );
463 void ( * intf_StatMsg ) ( char *, ... );
464 void ( * intf_WarnMsg ) ( int, char *, ... );
465 void ( * intf_WarnMsgImm ) ( int, char *, ... );
467 void ( * intf_DbgMsg ) ( char *, char *, int, char *, ... );
468 void ( * intf_DbgMsgImm ) ( char *, char *, int, char *, ... );
471 int ( * intf_PlaylistAdd ) ( struct playlist_s *, int, const char* );
472 int ( * intf_PlaylistDelete ) ( struct playlist_s *, int );
473 void ( * intf_PlaylistNext ) ( struct playlist_s * );
474 void ( * intf_PlaylistPrev ) ( struct playlist_s * );
475 void ( * intf_PlaylistDestroy ) ( struct playlist_s * );
476 void ( * intf_PlaylistJumpto ) ( struct playlist_s *, int );
477 void ( * intf_UrlDecode ) ( char * );
479 void ( * msleep ) ( mtime_t );
480 mtime_t ( * mdate ) ( void );
482 int ( * network_ChannelCreate )( void );
483 int ( * network_ChannelJoin ) ( int );
485 int ( * input_SetProgram ) ( struct input_thread_s *,
486 struct pgrm_descriptor_s * );
487 void ( * input_SetStatus ) ( struct input_thread_s *, int );
488 void ( * input_Seek ) ( struct input_thread_s *, off_t );
489 void ( * input_DumpStream ) ( struct input_thread_s * );
490 char * ( * input_OffsetToTime ) ( struct input_thread_s *, char *, off_t );
491 int ( * input_ChangeES ) ( struct input_thread_s *,
492 struct es_descriptor_s *, u8 );
493 int ( * input_ToggleES ) ( struct input_thread_s *,
494 struct es_descriptor_s *, boolean_t );
495 int ( * input_ChangeArea ) ( struct input_thread_s *,
496 struct input_area_s * );
497 struct es_descriptor_s * ( * input_FindES ) ( struct input_thread_s *,
499 struct es_descriptor_s * ( * input_AddES ) ( struct input_thread_s *,
500 struct pgrm_descriptor_s *, u16, size_t );
501 void ( * input_DelES ) ( struct input_thread_s *,
502 struct es_descriptor_s * );
503 int ( * input_SelectES ) ( struct input_thread_s *,
504 struct es_descriptor_s * );
505 int ( * input_UnselectES ) ( struct input_thread_s *,
506 struct es_descriptor_s * );
507 struct pgrm_descriptor_s* ( * input_AddProgram ) ( struct input_thread_s *,
509 void ( * input_DelProgram ) ( struct input_thread_s *,
510 struct pgrm_descriptor_s * );
511 struct input_area_s * ( * input_AddArea ) ( struct input_thread_s * );
512 void ( * input_DelArea ) ( struct input_thread_s *,
513 struct input_area_s * );
515 void ( * InitBitstream ) ( struct bit_stream_s *,
516 struct decoder_fifo_s *,
517 void ( * ) ( struct bit_stream_s *,
520 void ( * DecoderError ) ( struct decoder_fifo_s * p_fifo );
521 int ( * input_InitStream ) ( struct input_thread_s *, size_t );
522 void ( * input_EndStream ) ( struct input_thread_s * );
524 void ( * input_ParsePES ) ( struct input_thread_s *,
525 struct es_descriptor_s * );
526 void ( * input_GatherPES ) ( struct input_thread_s *,
527 struct data_packet_s *,
528 struct es_descriptor_s *,
529 boolean_t, boolean_t );
530 void ( * input_DecodePES ) ( struct decoder_fifo_s *,
531 struct pes_packet_s * );
532 struct es_descriptor_s * ( * input_ParsePS ) ( struct input_thread_s *,
533 struct data_packet_s * );
534 void ( * input_DemuxPS ) ( struct input_thread_s *,
535 struct data_packet_s * );
536 void ( * input_DemuxTS ) ( struct input_thread_s *,
537 struct data_packet_s * );
538 void ( * input_DemuxPSI ) ( struct input_thread_s *,
539 struct data_packet_s *,
540 struct es_descriptor_s *,
541 boolean_t, boolean_t );
543 int ( * input_ClockManageControl ) ( struct input_thread_s *,
544 struct pgrm_descriptor_s *,
547 struct aout_fifo_s * ( * aout_CreateFifo )
548 ( int, int, long, long, long, void * );
549 void ( * aout_DestroyFifo ) ( struct aout_fifo_s * );
551 struct vout_thread_s * (* vout_CreateThread) ( int *, int, int, u64, int );
552 void ( * vout_DestroyThread ) ( struct vout_thread_s *, int * );
554 struct picture_s * ( * vout_CreatePicture )
555 ( struct vout_thread_s *,
556 boolean_t, boolean_t, boolean_t );
557 void ( * vout_AllocatePicture )( struct picture_s *, int, int, int );
558 void ( * vout_DisplayPicture ) ( struct vout_thread_s *,
559 struct picture_s * );
560 void ( * vout_DestroyPicture ) ( struct vout_thread_s *,
561 struct picture_s * );
562 void ( * vout_LinkPicture ) ( struct vout_thread_s *,
563 struct picture_s * );
564 void ( * vout_UnlinkPicture ) ( struct vout_thread_s *,
565 struct picture_s * );
566 void ( * vout_DatePicture ) ( struct vout_thread_s *,
567 struct picture_s *, mtime_t );
568 void ( * vout_PlacePicture ) ( struct vout_thread_s *, int, int,
569 int *, int *, int *, int * );
571 struct subpicture_s * (* vout_CreateSubPicture)
572 ( struct vout_thread_s *, int, int );
573 void ( * vout_DestroySubPicture ) ( struct vout_thread_s *,
574 struct subpicture_s * );
575 void ( * vout_DisplaySubPicture ) ( struct vout_thread_s *,
576 struct subpicture_s * );
578 u32 ( * UnalignedShowBits ) ( struct bit_stream_s *, unsigned int );
579 void ( * UnalignedRemoveBits ) ( struct bit_stream_s * );
580 u32 ( * UnalignedGetBits ) ( struct bit_stream_s *, unsigned int );
582 char * ( * DecodeLanguage ) ( u16 );
584 struct module_s * ( * module_Need ) ( int, char *, struct probedata_s * );
585 void ( * module_Unneed ) ( struct module_s * );
589 extern module_symbols_t* p_symbols;
592 /*****************************************************************************
593 * Required vlc headers
594 *****************************************************************************/
596 # include "beos_specific.h"
599 # include "darwin_specific.h"
602 # include "win32_specific.h"
605 #include "intf_msg.h"