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 ) )
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) )
356 struct { int32_t x; int32_t
y; } coords;
374 #define VLC_SUCCESS (-0)
375 #define VLC_EGENERIC (-1)
376 #define VLC_ENOMEM (-2)
377 #define VLC_ETIMEOUT (-3)
378 #define VLC_ENOMOD (-4)
379 #define VLC_ENOOBJ (-5)
380 #define VLC_ENOVAR (-6)
381 #define VLC_EBADVAR (-7)
382 #define VLC_ENOITEM (-8)
399 # define PATH_MAX MAX_PATH
401 # include <windows.h>
405 #include <sys/syslimits.h>
409 # define OS2EMX_PLAIN_CHAR
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 )
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 & 0x00000000000000FFLLU) << 56)
616 | ((x & 0x000000000000FF00LLU) << 40)
617 | ((x & 0x0000000000FF0000LLU) << 24)
618 | ((x & 0x00000000FF000000LLU) << 8)
619 | ((x & 0x000000FF00000000LLU) >> 8)
620 | ((x & 0x0000FF0000000000LLU) >> 24)
621 | ((x & 0x00FF000000000000LLU) >> 40)
622 | ((x & 0xFF00000000000000LLU) >> 56);
628 #define FREENULL(a) do { free( a ); a = NULL; } while(0)
630 #define EMPTY_STR(str) (!str || !*str)
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
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;
828 free((
char*)ptr - ((
char*)ptr)[-1]);
831 static inline void *
vlc_memalign(
size_t align,
size_t size)
838 # define vlc_free(base) free(base)
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 )
856 return (tr == ctx) ?
id : tr;
862 static inline void *
xmalloc (
size_t len)
864 void *ptr = malloc (len);
870 static inline void *
xrealloc (
void *ptr,
size_t len)
872 void *nptr = realloc (ptr, len);
878 static inline void *
xcalloc (
size_t n,
size_t size)
880 void *ptr = calloc (n, size);
886 static inline char *
xstrdup (
const char *str)
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")