33 # define VLC_COMMON_H 1
60 # define VLC_GCC_VERSION(maj,min) \
61 ((__GNUC__ > (maj)) || (__GNUC__ == (maj) && __GNUC_MINOR__ >= (min)))
63 # define VLC_GCC_VERSION(maj,min) (0)
67 #if defined( _WIN32 ) && defined( __USE_MINGW_ANSI_STDIO )
78 #define snprintf __mingw_snprintf
79 #define vsnprintf __mingw_vsnprintf
80 #define swprintf _snwprintf
85 # define VLC_DEPRECATED __attribute__((deprecated))
87 # if defined( _WIN32 ) && VLC_GCC_VERSION(4,4)
88 # define VLC_FORMAT(x,y) __attribute__ ((format(gnu_printf,x,y)))
90 # define VLC_FORMAT(x,y) __attribute__ ((format(printf,x,y)))
92 # define VLC_FORMAT_ARG(x) __attribute__ ((format_arg(x)))
94 # define VLC_MALLOC __attribute__ ((malloc))
95 # define VLC_NORETURN __attribute__ ((noreturn))
97 # if VLC_GCC_VERSION(3,4)
98 # define VLC_USED __attribute__ ((warn_unused_result))
104 # define VLC_DEPRECATED
105 # define VLC_FORMAT(x,y)
106 # define VLC_FORMAT_ARG(x)
108 # define VLC_NORETURN
115 # define likely(p) __builtin_expect(!!(p), 1)
116 # define unlikely(p) __builtin_expect(!!(p), 0)
118 # define likely(p) (!!(p))
119 # define unlikely(p) (!!(p))
124 # define VLC_EXTERN extern "C"
129 #if defined (_WIN32) && defined (DLL_EXPORT)
130 # define VLC_EXPORT __declspec(dllexport)
131 #elif VLC_GCC_VERSION(4,0)
132 # define VLC_EXPORT __attribute__((visibility("default")))
137 #define VLC_API VLC_EXTERN VLC_EXPORT
162 #ifdef WORDS_BIGENDIAN
163 # define VLC_FOURCC( a, b, c, d ) \
164 ( ((uint32_t)d) | ( ((uint32_t)c) << 8 ) \
165 | ( ((uint32_t)b) << 16 ) | ( ((uint32_t)a) << 24 ) )
166 # define VLC_TWOCC( a, b ) \
167 ( (uint16_t)(b) | ( (uint16_t)(a) << 8 ) )
170 # define VLC_FOURCC( a, b, c, d ) \
171 ( ((uint32_t)a) | ( ((uint32_t)b) << 8 ) \
172 | ( ((uint32_t)c) << 16 ) | ( ((uint32_t)d) << 24 ) )
173 # define VLC_TWOCC( a, b ) \
174 ( (uint16_t)(a) | ( (uint16_t)(b) << 8 ) )
185 static inline void vlc_fourcc_to_char(
vlc_fourcc_t fcc,
char *psz_fourcc )
187 memcpy( psz_fourcc, &fcc, 4 );
190 #define vlc_fourcc_to_char( a, b ) \
191 vlc_fourcc_to_char( (vlc_fourcc_t)(a), (char *)(b) )
222 typedef struct services_discovery_sys_t services_discovery_sys_t;
226 typedef struct module_t module_t;
236 typedef struct access_sys_t access_sys_t;
238 typedef struct stream_sys_t stream_sys_t;
240 typedef struct demux_sys_t demux_sys_t;
242 typedef struct es_out_id_t es_out_id_t;
243 typedef struct es_out_sys_t es_out_sys_t;
258 typedef struct aout_sys_t aout_sys_t;
266 typedef struct picture_sys_t picture_sys_t;
279 typedef struct sout_packetizer_input_t sout_packetizer_input_t;
282 typedef struct sout_access_out_sys_t sout_access_out_sys_t;
285 typedef struct sout_mux_sys_t sout_mux_sys_t;
288 typedef struct sout_stream_sys_t sout_stream_sys_t;
291 typedef struct session_descriptor_t session_descriptor_t;
295 typedef struct decoder_sys_t decoder_sys_t;
296 typedef struct decoder_synchro_t decoder_synchro_t;
300 typedef struct encoder_sys_t encoder_sys_t;
304 typedef struct filter_sys_t filter_sys_t;
311 typedef struct iso639_lang_t iso639_lang_t;
315 typedef struct block_fifo_t block_fifo_t;
322 typedef struct xml_sys_t xml_sys_t;
324 typedef struct xml_reader_sys_t xml_reader_sys_t;
327 typedef struct vod_t vod_t;
328 typedef struct vod_sys_t vod_sys_t;
329 typedef struct vod_media_t vod_media_t;
332 typedef struct vlm_t vlm_t;
336 typedef struct vlc_meta_t vlc_meta_t;
340 typedef struct update_t update_t;
355 struct { int32_t x; int32_t y; } coords;
373 #define VLC_SUCCESS (-0)
374 #define VLC_EGENERIC (-1)
375 #define VLC_ENOMEM (-2)
376 #define VLC_ETIMEOUT (-3)
377 #define VLC_ENOMOD (-4)
378 #define VLC_ENOOBJ (-5)
379 #define VLC_ENOVAR (-6)
380 #define VLC_EBADVAR (-7)
381 #define VLC_ENOITEM (-8)
395 #if defined( _WIN32 )
398 # define PATH_MAX MAX_PATH
400 # include <windows.h>
404 #include <sys/syslimits.h>
408 # define OS2EMX_PLAIN_CHAR
411 # include <os2safe.h>
415 #include "vlc_mtime.h"
423 #define VLC_COMMON_MEMBERS \
428 const char *psz_object_type; \
438 libvlc_int_t *p_libvlc; \
440 vlc_object_t * p_parent; \
445 #if VLC_GCC_VERSION(4,0)
447 # define VLC_OBJECT( x ) \
448 __builtin_choose_expr( \
449 __builtin_offsetof(__typeof__(*(x)), psz_object_type), \
453 # define VLC_OBJECT( x ) \
454 ((vlc_object_t *)(x) \
455 + 0 * __builtin_offsetof(__typeof__(*(x)), psz_object_type))
458 # define VLC_OBJECT( x ) ((vlc_object_t *)(x))
466 #define CEIL(n, d) ( ((n) / (d)) + ( ((n) % (d)) ? 1 : 0) )
469 #define PAD(n, d) ( ((n) % (d)) ? ((((n) / (d)) + 1) * (d)) : (n) )
473 # define __MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
476 # define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
480 #define VLC_CLIP(v, min, max) __MIN(__MAX((v), (min)), (max))
483 static inline int64_t GCD ( int64_t a, int64_t b )
496 static inline uint8_t clip_uint8_vlc( int32_t a )
498 if( a&(~255) )
return (-a)>>31;
504 static inline unsigned clz (
unsigned x)
506 #if VLC_GCC_VERSION(3,4)
507 return __builtin_clz (x);
509 unsigned i =
sizeof (x) * 8;
520 #define clz8( x ) (clz(x) - ((sizeof(unsigned) - sizeof (uint8_t)) * 8))
521 #define clz16( x ) (clz(x) - ((sizeof(unsigned) - sizeof (uint16_t)) * 8))
523 #define clz32( x ) (clz(x) - ((sizeof(unsigned) - sizeof (uint32_t)) * 8))
527 static inline unsigned ctz (
unsigned x)
529 #if VLC_GCC_VERSION(3,4)
530 return __builtin_ctz (x);
532 unsigned i =
sizeof (x) * 8;
545 static inline unsigned popcount (
unsigned x)
547 #if VLC_GCC_VERSION(3,4)
548 return __builtin_popcount (x);
561 static inline unsigned parity (
unsigned x)
563 #if VLC_GCC_VERSION(3,4)
564 return __builtin_parity (x);
566 for (
unsigned i = 4 *
sizeof (x); i > 0; i /= 2)
580 static inline uint16_t bswap16 (uint16_t x)
582 return (x << 8) | (x >> 8);
587 static inline uint32_t bswap32 (uint32_t x)
589 #if VLC_GCC_VERSION(4,3) || defined(__clang__)
590 return __builtin_bswap32 (x);
592 return ((x & 0x000000FF) << 24)
593 | ((x & 0x0000FF00) << 8)
594 | ((x & 0x00FF0000) >> 8)
595 | ((x & 0xFF000000) >> 24);
601 static inline uint64_t bswap64 (uint64_t x)
603 #if VLC_GCC_VERSION(4,3) || defined(__clang__)
604 return __builtin_bswap64 (x);
605 #elif !defined (__cplusplus)
606 return ((x & 0x00000000000000FF) << 56)
607 | ((x & 0x000000000000FF00) << 40)
608 | ((x & 0x0000000000FF0000) << 24)
609 | ((x & 0x00000000FF000000) << 8)
610 | ((x & 0x000000FF00000000) >> 8)
611 | ((x & 0x0000FF0000000000) >> 24)
612 | ((x & 0x00FF000000000000) >> 40)
613 | ((x & 0xFF00000000000000) >> 56);
615 return ((x & 0x00000000000000FFULL) << 56)
616 | ((x & 0x000000000000FF00ULL) << 40)
617 | ((x & 0x0000000000FF0000ULL) << 24)
618 | ((x & 0x00000000FF000000ULL) << 8)
619 | ((x & 0x000000FF00000000ULL) >> 8)
620 | ((x & 0x0000FF0000000000ULL) >> 24)
621 | ((x & 0x00FF000000000000ULL) >> 40)
622 | ((x & 0xFF00000000000000ULL) >> 56);
628 #define FREENULL(a) do { free( a ); a = NULL; } while(0)
630 #define EMPTY_STR(str) (!str || !*str)
632 VLC_API
char const * vlc_error(
int ) VLC_USED;
634 #include <vlc_arrays.h>
639 #ifdef WORDS_BIGENDIAN
640 # define hton16(i) ((uint16_t)(i))
641 # define hton32(i) ((uint32_t)(i))
642 # define hton64(i) ((uint64_t)(i))
644 # define hton16(i) bswap16(i)
645 # define hton32(i) bswap32(i)
646 # define hton64(i) bswap64(i)
648 #define ntoh16(i) hton16(i)
649 #define ntoh32(i) hton32(i)
650 #define ntoh64(i) hton64(i)
654 static inline uint16_t U16_AT (
const void *p)
658 memcpy (&x, p,
sizeof (x));
664 static inline uint32_t U32_AT (
const void *p)
668 memcpy (&x, p,
sizeof (x));
674 static inline uint64_t U64_AT (
const void *p)
678 memcpy (&x, p,
sizeof (x));
682 #define GetWBE(p) U16_AT(p)
683 #define GetDWBE(p) U32_AT(p)
684 #define GetQWBE(p) U64_AT(p)
688 static inline uint16_t GetWLE (
const void *p)
692 memcpy (&x, p,
sizeof (x));
693 #ifdef WORDS_BIGENDIAN
701 static inline uint32_t GetDWLE (
const void *p)
705 memcpy (&x, p,
sizeof (x));
706 #ifdef WORDS_BIGENDIAN
714 static inline uint64_t GetQWLE (
const void *p)
718 memcpy (&x, p,
sizeof (x));
719 #ifdef WORDS_BIGENDIAN
726 static inline void SetWBE (
void *p, uint16_t w)
729 memcpy (p, &w,
sizeof (w));
733 static inline void SetDWBE (
void *p, uint32_t dw)
736 memcpy (p, &dw,
sizeof (dw));
740 static inline void SetQWBE (
void *p, uint64_t qw)
743 memcpy (p, &qw,
sizeof (qw));
747 static inline void SetWLE (
void *p, uint16_t w)
749 #ifdef WORDS_BIGENDIAN
752 memcpy (p, &w,
sizeof (w));
756 static inline void SetDWLE (
void *p, uint32_t dw)
758 #ifdef WORDS_BIGENDIAN
761 memcpy (p, &dw,
sizeof (dw));
765 static inline void SetQWLE (
void *p, uint64_t qw)
767 #ifdef WORDS_BIGENDIAN
770 memcpy (p, &qw,
sizeof (qw));
774 #define VLC_UNUSED(x) (void)(x)
780 # if defined( __MINGW32__ )
781 # if !defined( _OFF_T_ )
782 typedef long long _off_t;
783 typedef _off_t off_t;
789 # define off_t long long
794 # define O_NONBLOCK 0
800 VLC_API
bool vlc_ureduce(
unsigned *,
unsigned *, uint64_t, uint64_t, uint64_t );
804 #include <AvailabilityMacros.h>
808 # define vlc_memalign(align, size) (__mingw_aligned_malloc(size, align))
809 # define vlc_free(base) (__mingw_aligned_free(base))
810 #elif defined(__APPLE__) && !defined(MAC_OS_X_VERSION_10_6)
811 static inline void *vlc_memalign(
size_t align,
size_t size)
816 ptr = malloc(size+align);
819 diff = ((-(long)ptr - 1)&(align-1)) + 1;
820 ptr = (
char*)ptr + diff;
821 ((
char*)ptr)[-1]= diff;
825 static void vlc_free(
void *ptr)
828 free((
char*)ptr - ((
char*)ptr)[-1]);
831 static inline void *vlc_memalign(
size_t align,
size_t size)
834 if (unlikely(posix_memalign(&base, align, size)))
838 # define vlc_free(base) free(base)
841 VLC_API
void vlc_tdestroy(
void *,
void (*)(
void *) );
846 VLC_API
char *vlc_gettext(
const char *msgid ) VLC_FORMAT_ARG(1);
847 VLC_API
char *vlc_ngettext(
const char *s,
const char *p,
unsigned long n ) VLC_FORMAT_ARG(1) VLC_FORMAT_ARG(2);
849 #define vlc_pgettext( ctx, id ) \
850 vlc_pgettext_aux( ctx "\004" id, id )
853 static inline const
char *vlc_pgettext_aux( const
char *ctx, const
char *
id )
855 const char *tr = vlc_gettext( ctx );
856 return (tr == ctx) ?
id : tr;
862 static inline void *xmalloc (
size_t len)
864 void *ptr = malloc (len);
865 if (unlikely (ptr == NULL))
870 static inline void *xrealloc (
void *ptr,
size_t len)
872 void *nptr = realloc (ptr, len);
873 if (unlikely (nptr == NULL))
878 static inline void *xcalloc (
size_t n,
size_t size)
880 void *ptr = calloc (n, size);
881 if (unlikely (ptr == NULL))
886 static inline char *xstrdup (
const char *str)
888 char *ptr = strdup (str);
889 if (unlikely(ptr == NULL))
897 VLC_API
const char * VLC_CompileBy(
void ) VLC_USED;
898 VLC_API const
char * VLC_CompileHost(
void ) VLC_USED;
899 VLC_API const
char * VLC_Compiler(
void ) VLC_USED;
904 #include "vlc_messages.h"
910 #if defined( _WIN32 ) || defined( __SYMBIAN32__ ) || defined( __OS2__ )
911 # define DIR_SEP_CHAR '\\'
912 # define DIR_SEP "\\"
913 # define PATH_SEP_CHAR ';'
914 # define PATH_SEP ";"
916 # define DIR_SEP_CHAR '/'
918 # define PATH_SEP_CHAR ':'
919 # define PATH_SEP ":"
922 #define LICENSE_MSG \
923 _("This program comes with NO WARRANTY, to the extent permitted by " \
924 "law.\nYou may redistribute it under the terms of the GNU General " \
925 "Public License;\nsee the file named COPYING for details.\n" \
926 "Written by the VideoLAN team; see the AUTHORS file.\n")
Definition: vlc_picture.h:69
Definition: vlc_vlm.h:173
Definition: vlc_demux.h:41
Definition: vlc_subpicture.h:57
Definition: vlc_configuration.h:41
Definition: vlc_configuration.h:60
Definition: vlc_common.h:213
Definition: vlc_subpicture.h:136
Definition: vlc_common.h:211
Definition: vlc_main.h:38
Definition: vlc_services_discovery.h:47
Definition: vlc_image.h:38
Definition: vlc_common.h:345
Definition: vlc_mtime.h:63
Definition: vlc_network.h:140
Definition: vlc_input.h:45
Definition: vlc_configuration.h:156
Definition: vlc_es_out.h:96
Definition: vlc_sout.h:64
Definition: vlc_playlist.h:133
Definition: vlc_common.h:210
Definition: vlc_vout.h:73
Definition: vlc_input_item.h:48
Definition: vlc_common.h:215
Definition: vlc_access.h:74
Definition: vlc_sout.h:176
Definition: vlc_input_item.h:42
Definition: vlc_aout.h:101
Definition: vlc_stream.h:52
Definition: vlc_sout.h:104
Definition: vlc_codec.h:52
int64_t mtime_t
Definition: vlc_common.h:153
Definition: vlc_filter.h:45
uint32_t vlc_fourcc_t
Definition: vlc_common.h:160
Definition: vlc_playlist.h:187
Definition: vlc_sout.h:45
Definition: vlc_block.h:102
Definition: vlc_common.h:362
Definition: vlc_common.h:214
Definition: vlc_objects.h:42
Definition: vlc_codec.h:150
Definition: vlc_playlist.h:162
playlist_command_t
Definition: vlc_common.h:209