Go to the documentation of this file.
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))
86 # if VLC_GCC_VERSION(6,0)
87 # define VLC_DEPRECATED_ENUM __attribute__((deprecated))
89 # define VLC_DEPRECATED_ENUM
92 # if defined( _WIN32 ) && !defined( __clang__ )
93 # define VLC_FORMAT(x,y) __attribute__ ((format(gnu_printf,x,y)))
95 # define VLC_FORMAT(x,y) __attribute__ ((format(printf,x,y)))
97 # define VLC_FORMAT_ARG(x) __attribute__ ((format_arg(x)))
98 # define VLC_MALLOC __attribute__ ((malloc))
99 # define VLC_USED __attribute__ ((warn_unused_result))
102 # define VLC_DEPRECATED
103 # define VLC_DEPRECATED_ENUM
104 # define VLC_FORMAT(x,y)
105 # define VLC_FORMAT_ARG(x)
113 # define likely(p) __builtin_expect(!!(p), 1)
114 # define unlikely(p) __builtin_expect(!!(p), 0)
115 # define unreachable() __builtin_unreachable()
117 # define likely(p) (!!(p))
118 # define unlikely(p) (!!(p))
119 # define unreachable() ((void)0)
122 #define vlc_assert_unreachable() (assert(!"unreachable"), unreachable())
126 # define VLC_EXTERN extern "C"
131 #if defined (_WIN32) && defined (DLL_EXPORT)
132 # define VLC_EXPORT __declspec(dllexport)
133 #elif defined (__GNUC__)
134 # define VLC_EXPORT __attribute__((visibility("default")))
139 #define VLC_API VLC_EXTERN VLC_EXPORT
158 #define VLC_TICK_INVALID VLC_TS_INVALID
159 #define VLC_TICK_0 VLC_TS_0
168 #ifdef WORDS_BIGENDIAN
169 # define VLC_FOURCC( a, b, c, d ) \
170 ( ((uint32_t)d) | ( ((uint32_t)c) << 8 ) \
171 | ( ((uint32_t)b) << 16 ) | ( ((uint32_t)a) << 24 ) )
172 # define VLC_TWOCC( a, b ) \
173 ( (uint16_t)(b) | ( (uint16_t)(a) << 8 ) )
176 # define VLC_FOURCC( a, b, c, d ) \
177 ( ((uint32_t)a) | ( ((uint32_t)b) << 8 ) \
178 | ( ((uint32_t)c) << 16 ) | ( ((uint32_t)d) << 24 ) )
179 # define VLC_TWOCC( a, b ) \
180 ( (uint16_t)(a) | ( (uint16_t)(b) << 8 ) )
193 memcpy( psz_fourcc, &fcc, 4 );
343 struct { int32_t x; int32_t y; } coords;
360 #define VLC_SUCCESS (-0)
361 #define VLC_EGENERIC (-1)
362 #define VLC_ENOMEM (-2)
363 #define VLC_ETIMEOUT (-3)
364 #define VLC_ENOMOD (-4)
365 #define VLC_ENOOBJ (-5)
366 #define VLC_ENOVAR (-6)
367 #define VLC_EBADVAR (-7)
368 #define VLC_ENOITEM (-8)
391 #if defined( _WIN32 )
394 # define PATH_MAX MAX_PATH
396 # include <windows.h>
400 #include <sys/syslimits.h>
401 #include <AvailabilityMacros.h>
405 # define OS2EMX_PLAIN_CHAR
408 # include <os2safe.h>
467 #define VLC_COMMON_MEMBERS struct vlc_common_members obj;
477 #if !defined(__cplusplus)
478 # define VLC_OBJECT(x) \
480 vlc_object_t: (vlc_object_t *)(&(x)->obj), \
481 struct vlc_common_members: (vlc_object_t *)(x) \
484 # define VLC_OBJECT( x ) ((vlc_object_t *)&(x)->obj)
493 # define __MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
496 # define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
500 #define VLC_CLIP(v, min, max) __MIN(__MAX((v), (min)), (max))
503 static inline int64_t
GCD ( int64_t a, int64_t b )
518 if( a&(~255) )
return (-a)>>31;
524 static inline unsigned (
clz)(
unsigned x)
527 return __builtin_clz (x);
529 unsigned i =
sizeof (x) * 8;
540 #define clz8( x ) (clz(x) - ((sizeof(unsigned) - sizeof (uint8_t)) * 8))
541 #define clz16( x ) (clz(x) - ((sizeof(unsigned) - sizeof (uint16_t)) * 8))
543 #define clz32( x ) (clz(x) - ((sizeof(unsigned) - sizeof (uint32_t)) * 8))
547 static inline unsigned (
ctz)(
unsigned x)
550 return __builtin_ctz (x);
552 unsigned i =
sizeof (x) * 8;
563 #if !defined(__NetBSD__)
566 static inline unsigned (
popcount)(
unsigned x)
569 return __builtin_popcount (x);
583 static inline int (
popcountll)(
unsigned long long x)
586 return __builtin_popcountll(x);
600 static inline unsigned (
parity)(
unsigned x)
603 return __builtin_parity (x);
605 for (
unsigned i = 4 *
sizeof (x); i > 0; i /= 2)
611 #if !defined(__NetBSD__)
614 static inline uint16_t (
bswap16)(uint16_t x)
616 return (x << 8) | (x >> 8);
621 static inline uint32_t (
bswap32)(uint32_t x)
623 #if defined (__GNUC__) || defined(__clang__)
624 return __builtin_bswap32 (x);
626 return ((x & 0x000000FF) << 24)
627 | ((x & 0x0000FF00) << 8)
628 | ((x & 0x00FF0000) >> 8)
629 | ((x & 0xFF000000) >> 24);
635 static inline uint64_t (
bswap64)(uint64_t x)
637 #if defined (__GNUC__) || defined(__clang__)
638 return __builtin_bswap64 (x);
639 #elif !defined (__cplusplus)
640 return ((x & 0x00000000000000FF) << 56)
641 | ((x & 0x000000000000FF00) << 40)
642 | ((x & 0x0000000000FF0000) << 24)
643 | ((x & 0x00000000FF000000) << 8)
644 | ((x & 0x000000FF00000000) >> 8)
645 | ((x & 0x0000FF0000000000) >> 24)
646 | ((x & 0x00FF000000000000) >> 40)
647 | ((x & 0xFF00000000000000) >> 56);
649 return ((x & 0x00000000000000FFULL) << 56)
650 | ((x & 0x000000000000FF00ULL) << 40)
651 | ((x & 0x0000000000FF0000ULL) << 24)
652 | ((x & 0x00000000FF000000ULL) << 8)
653 | ((x & 0x000000FF00000000ULL) >> 8)
654 | ((x & 0x0000FF0000000000ULL) >> 24)
655 | ((x & 0x00FF000000000000ULL) >> 40)
656 | ((x & 0xFF00000000000000ULL) >> 56);
662 static inline bool uadd_overflow(
unsigned a,
unsigned b,
unsigned *res)
664 #if VLC_GCC_VERSION(5,0) || defined(__clang__)
665 return __builtin_uadd_overflow(a, b, res);
675 #if VLC_GCC_VERSION(5,0) || defined(__clang__)
676 return __builtin_uaddl_overflow(a, b, res);
683 static inline bool uaddll_overflow(
unsigned long long a,
unsigned long long b,
684 unsigned long long *res)
686 #if VLC_GCC_VERSION(5,0) || defined(__clang__)
687 return __builtin_uaddll_overflow(a, b, res);
695 # define add_overflow(a,b,r) \
697 unsigned: uadd_overflow(a, b, (unsigned *)(r)), \
698 unsigned long: uaddl_overflow(a, b, (unsigned long *)(r)), \
699 unsigned long long: uaddll_overflow(a, b, (unsigned long long *)(r)))
701 static inline bool add_overflow(
unsigned a,
unsigned b,
unsigned *res)
706 static inline bool add_overflow(
unsigned long a,
unsigned long b,
712 static inline bool add_overflow(
unsigned long long a,
unsigned long long b,
713 unsigned long long *res)
719 #if !(VLC_GCC_VERSION(5,0) || defined(__clang__))
723 static inline bool umul_overflow(
unsigned a,
unsigned b,
unsigned *res)
725 #if VLC_GCC_VERSION(5,0) || defined(__clang__)
726 return __builtin_umul_overflow(a, b, res);
729 return b > 0 && a > (UINT_MAX / b);
736 #if VLC_GCC_VERSION(5,0) || defined(__clang__)
737 return __builtin_umull_overflow(a, b, res);
740 return b > 0 && a > (ULONG_MAX / b);
744 static inline bool umulll_overflow(
unsigned long long a,
unsigned long long b,
745 unsigned long long *res)
747 #if VLC_GCC_VERSION(5,0) || defined(__clang__)
748 return __builtin_umulll_overflow(a, b, res);
751 return b > 0 && a > (ULLONG_MAX / b);
756 #define mul_overflow(a,b,r) \
758 unsigned: umul_overflow(a, b, (unsigned *)(r)), \
759 unsigned long: umull_overflow(a, b, (unsigned long *)(r)), \
760 unsigned long long: umulll_overflow(a, b, (unsigned long long *)(r)))
762 static inline bool mul_overflow(
unsigned a,
unsigned b,
unsigned *res)
767 static inline bool mul_overflow(
unsigned long a,
unsigned long b,
773 static inline bool mul_overflow(
unsigned long long a,
unsigned long long b,
774 unsigned long long *res)
781 #define FREENULL(a) do { free( a ); a = NULL; } while(0)
783 #define EMPTY_STR(str) (!str || !*str)
792 #ifdef WORDS_BIGENDIAN
793 # define hton16(i) ((uint16_t)(i))
794 # define hton32(i) ((uint32_t)(i))
795 # define hton64(i) ((uint64_t)(i))
797 # define hton16(i) bswap16(i)
798 # define hton32(i) bswap32(i)
799 # define hton64(i) bswap64(i)
801 #define ntoh16(i) hton16(i)
802 #define ntoh32(i) hton32(i)
803 #define ntoh64(i) hton64(i)
807 static inline uint16_t
U16_AT (
const void *
p)
811 memcpy (&x,
p,
sizeof (x));
817 static inline uint32_t
U32_AT (
const void *
p)
821 memcpy (&x,
p,
sizeof (x));
827 static inline uint64_t
U64_AT (
const void *
p)
831 memcpy (&x,
p,
sizeof (x));
835 #define GetWBE(p) U16_AT(p)
836 #define GetDWBE(p) U32_AT(p)
837 #define GetQWBE(p) U64_AT(p)
841 static inline uint16_t
GetWLE (
const void *
p)
845 memcpy (&x,
p,
sizeof (x));
846 #ifdef WORDS_BIGENDIAN
854 static inline uint32_t
GetDWLE (
const void *
p)
858 memcpy (&x,
p,
sizeof (x));
859 #ifdef WORDS_BIGENDIAN
867 static inline uint64_t
GetQWLE (
const void *
p)
871 memcpy (&x,
p,
sizeof (x));
872 #ifdef WORDS_BIGENDIAN
879 static inline void SetWBE (
void *
p, uint16_t w)
882 memcpy (
p, &w,
sizeof (w));
886 static inline void SetDWBE (
void *
p, uint32_t dw)
889 memcpy (
p, &dw,
sizeof (dw));
893 static inline void SetQWBE (
void *
p, uint64_t qw)
896 memcpy (
p, &qw,
sizeof (qw));
900 static inline void SetWLE (
void *
p, uint16_t w)
902 #ifdef WORDS_BIGENDIAN
905 memcpy (
p, &w,
sizeof (w));
909 static inline void SetDWLE (
void *
p, uint32_t dw)
911 #ifdef WORDS_BIGENDIAN
914 memcpy (
p, &dw,
sizeof (dw));
918 static inline void SetQWLE (
void *
p, uint64_t qw)
920 #ifdef WORDS_BIGENDIAN
923 memcpy (
p, &qw,
sizeof (qw));
927 #define VLC_UNUSED(x) (void)(x)
933 # if defined( __MINGW32__ )
934 # if !defined( _OFF_T_ )
935 typedef long long _off_t;
936 typedef _off_t off_t;
942 # define off_t long long
947 # define O_NONBLOCK 0
952 # define swab(a,b,c) swab((char*) (a), (char*) (b), (c))
964 #define container_of(ptr, type, member) \
965 ((type *)(((char *)(ptr)) - offsetof(type, member)))
979 #define vlc_pgettext( ctx, id ) \
980 vlc_pgettext_aux( ctx "\004" id, id )
983 static inline const
char *
vlc_pgettext_aux( const
char *ctx, const
char *
id )
986 return (tr == ctx) ? id : tr;
992 static inline void *
xmalloc(
size_t len)
994 void *ptr = malloc(len);
1000 static inline void *
xrealloc(
void *ptr,
size_t len)
1002 void *nptr = realloc(ptr, len);
1008 static inline void *
xcalloc(
size_t n,
size_t size)
1010 void *ptr = calloc(n, size);
1011 if (
unlikely(ptr == NULL && (n > 0 || size > 0)))
1016 static inline char *
xstrdup (
const char *str)
1018 char *ptr =
strdup (str);
1040 #if defined( _WIN32 ) || defined( __OS2__ )
1041 # define DIR_SEP_CHAR '\\'
1042 # define DIR_SEP "\\"
1043 # define PATH_SEP_CHAR ';'
1044 # define PATH_SEP ";"
1046 # define DIR_SEP_CHAR '/'
1047 # define DIR_SEP "/"
1048 # define PATH_SEP_CHAR ':'
1049 # define PATH_SEP ":"
1052 #define LICENSE_MSG \
1053 _("This program comes with NO WARRANTY, to the extent permitted by " \
1054 "law.\nYou may redistribute it under the terms of the GNU General " \
1055 "Public License;\nsee the file named COPYING for details.\n" \
1056 "Written by the VideoLAN team; see the AUTHORS file.\n")
#define hton16(i)
Definition: vlc_common.h:786
struct demux_sys_t demux_sys_t
Definition: vlc_common.h:223
Structure containing information about the playlist.
Definition: vlc_playlist.h:151
struct picture_sys_t picture_sys_t
Definition: vlc_common.h:250
size_t count
Definition: core.c:461
static bool umull_overflow(unsigned long a, unsigned long b, unsigned long *res)
Definition: vlc_common.h:722
vlc_tick_t mtime_t
Definition: vlc_common.h:151
Definition: vlc_configuration.h:41
static bool uaddll_overflow(unsigned long long a, unsigned long long b, unsigned long long *res)
Definition: vlc_common.h:672
static void SetQWLE(void *p, uint64_t qw)
Writes 64 bits in little endian order.
Definition: vlc_common.h:907
#define VLC_USED
Definition: vlc_common.h:103
VLC list structure.
Definition: vlc_common.h:344
#define VLC_API
Definition: vlc_common.h:135
Main service discovery structure to build a SD module.
Definition: vlc_services_discovery.h:54
Definition: vlc_main.h:33
playlist item / node
Definition: vlc_playlist.h:126
Definition: vlc_sout.h:196
Definition: vlc_addons.h:71
int64_t vlc_tick_t
High precision date or time interval.
Definition: vlc_common.h:150
#define hton32(i)
Definition: vlc_common.h:787
static uint64_t() bswap64(uint64_t x)
Byte swap (64 bits)
Definition: vlc_common.h:624
#define ntoh64(i)
Definition: vlc_common.h:792
static bool uaddl_overflow(unsigned long a, unsigned long b, unsigned long *res)
Definition: vlc_common.h:661
Definition: vlc_input.h:48
Definition: vlc_input_item.h:48
libvlc_int_t * libvlc
LibVLC instance.
Definition: vlc_common.h:445
static char * xstrdup(const char *str)
Definition: vlc_common.h:1003
Definition: vlc_demux.h:43
Definition: vlc_codec.h:55
static uint64_t U64_AT(const void *p)
Reads 64 bits in network byte order.
Definition: vlc_common.h:816
Viewpoints.
Definition: vlc_viewpoint.h:44
Internal state for block queues.
Definition: fifo.c:37
struct vod_sys_t vod_sys_t
Definition: vlc_common.h:311
struct decoder_sys_t decoder_sys_t
Definition: vlc_common.h:279
static uint32_t() bswap32(uint32_t x)
Byte swap (32 bits)
Definition: vlc_common.h:610
uint32_t vlc_fourcc_t
The vlc_fourcc_t type.
Definition: vlc_common.h:161
Stream output access_output.
Definition: vlc_sout.h:72
struct sout_access_out_sys_t sout_access_out_sys_t
Definition: vlc_common.h:266
Video picture.
Definition: vlc_picture.h:68
static uint16_t U16_AT(const void *p)
Reads 16 bits in network byte order.
Definition: vlc_common.h:796
struct xml_sys_t xml_sys_t
Definition: vlc_common.h:305
#define VLC_FORMAT_ARG(x)
Definition: vlc_common.h:101
char * vlc_gettext(const char *msgid)
In-tree plugins share their gettext domain with LibVLC.
Definition: textdomain.c:89
static void SetQWBE(void *p, uint64_t qw)
Writes 64 bits in network byte order.
Definition: vlc_common.h:882
struct filter_sys_t filter_sys_t
Definition: vlc_common.h:288
const char * VLC_Compiler(void)
Definition: version.c:43
static uint8_t clip_uint8_vlc(int32_t a)
Definition: vlc_common.h:505
struct decoder_synchro_t decoder_synchro_t
Definition: vlc_common.h:280
int(* vlc_list_callback_t)(vlc_object_t *, char const *, int, vlc_value_t *, void *)
Definition: vlc_common.h:373
vlc_object_t * parent
Parent object.
Definition: vlc_common.h:452
Audio output object.
Definition: vlc_aout.h:114
Definition: vlc_es_out.h:111
const char * vlc_error(int)
Definition: error.c:36
static void SetDWBE(void *p, uint32_t dw)
Writes 32 bits in network byte order.
Definition: vlc_common.h:875
static int64_t GCD(int64_t a, int64_t b)
Definition: vlc_common.h:492
struct encoder_sys_t encoder_sys_t
Definition: vlc_common.h:284
int i_type
Definition: vlc_common.h:346
static uint16_t() bswap16(uint16_t x)
Byte swap (16 bits)
Definition: vlc_common.h:603
Definition: vlc_configuration.h:155
Internal module descriptor.
Definition: modules.h:79
Structure describing a filter.
Definition: vlc_filter.h:65
struct sout_stream_sys_t sout_stream_sys_t
Definition: vlc_common.h:272
Definition: vlm_internal.h:83
Video subtitle.
Definition: vlc_subpicture.h:153
Definition: vlc_mtime.h:58
Subpicture unit descriptor.
Definition: vlc_spu.h:47
Video subtitle region.
Definition: vlc_subpicture.h:57
Definition: vlc_codec.h:211
static void SetDWLE(void *p, uint32_t dw)
Writes 32 bits in little endian order.
Definition: vlc_common.h:898
static bool umul_overflow(unsigned a, unsigned b, unsigned *res)
Definition: vlc_common.h:712
static unsigned() clz(unsigned x)
Count leading zeroes.
Definition: vlc_common.h:513
static void SetWBE(void *p, uint16_t w)
Writes 16 bits in network byte order.
Definition: vlc_common.h:868
const char * VLC_CompileBy(void)
Definition: version.c:41
stream_t definition
Definition: vlc_stream.h:46
static void SetWLE(void *p, uint16_t w)
Writes 16 bits in little endian order.
Definition: vlc_common.h:889
Muxer structure.
Definition: vlc_sout.h:120
struct services_discovery_sys_t services_discovery_sys_t
Definition: vlc_common.h:205
Definition: fourcc_gen.c:33
static int() popcountll(unsigned long long x)
Bit weight of long long.
Definition: vlc_common.h:572
video_format_t video_frame_format_t
Definition: vlc_common.h:248
static void * xmalloc(size_t len)
Definition: vlc_common.h:979
const char * VLC_CompileHost(void)
Definition: version.c:42
Common structure members.
Definition: vlc_common.h:416
Definition: vlc_url.h:145
The main vlc_object_t structure.
Definition: vlc_objects.h:39
static const char * vlc_pgettext_aux(const char *ctx, const char *id)
Definition: vlc_common.h:971
The update object.
Definition: update.h:156
Definition: vlc_configuration.h:60
Definition: vlc_iso_lang.h:30
Definition: stream_fifo.c:35
char * strdup(const char *)
#define hton64(i)
Definition: vlc_common.h:788
int i_count
Definition: vlc_common.h:347
#define mul_overflow(a, b, r)
Definition: vlc_common.h:745
Definition: vlc_image.h:39
Definition: renderer_discovery.c:33
#define ntoh32(i)
Definition: vlc_common.h:791
#define VLC_MALLOC
Definition: vlc_common.h:102
static void * xcalloc(size_t n, size_t size)
Definition: vlc_common.h:995
static unsigned() popcount(unsigned x)
Bit weight.
Definition: vlc_common.h:555
static void * xrealloc(void *ptr, size_t len)
Definition: vlc_common.h:987
static uint64_t GetQWLE(const void *p)
Reads 64 bits in little-endian order.
Definition: vlc_common.h:856
bool force
Module probe flag.
Definition: vlc_common.h:439
char * vlc_ngettext(const char *s, const char *p, unsigned long n)
Definition: textdomain.c:98
static unsigned() parity(unsigned x)
Definition: vlc_common.h:589
#define unlikely(p)
Definition: vlc_common.h:114
static bool uadd_overflow(unsigned a, unsigned b, unsigned *res)
Definition: vlc_common.h:651
Definition: vlc_input_item.h:42
bool vlc_ureduce(unsigned *, unsigned *, uint64_t, uint64_t, uint64_t)
Definition: vlc_vlm.h:172
audio_format_t audio_sample_format_t
Definition: vlc_common.h:242
struct vod_media_t vod_media_t
Definition: vlc_common.h:312
struct aout_sys_t aout_sys_t
Definition: vlc_common.h:241
char * header
Log messages header.
Definition: vlc_common.h:430
static uint32_t U32_AT(const void *p)
Reads 32 bits in network byte order.
Definition: vlc_common.h:806
static void vlc_fourcc_to_char(vlc_fourcc_t fcc, char *psz_fourcc)
Translate a vlc_fourcc into its string representation.
Definition: vlc_common.h:186
Video output thread descriptor.
Definition: vlc_vout.h:70
#define add_overflow(a, b, r)
Definition: vlc_common.h:684
struct sout_mux_sys_t sout_mux_sys_t
Definition: vlc_common.h:269
static bool umulll_overflow(unsigned long long a, unsigned long long b, unsigned long long *res)
Definition: vlc_common.h:733
static void * vlc_alloc(size_t count, size_t size)
Definition: vlc_common.h:957
VLC value structure.
Definition: vlc_common.h:329
Stream output instance (FIXME: should be private to src/ to avoid invalid unsynchronized access)
Definition: vlc_sout.h:48
Definition: vlc_block.h:111
const char * object_type
Object type name.
Definition: vlc_common.h:423
static uint32_t GetDWLE(const void *p)
Reads 32 bits in little-endian order.
Definition: vlc_common.h:843
static unsigned() ctz(unsigned x)
Count trailing zeroes.
Definition: vlc_common.h:536
vlc_value_t * p_values
Definition: vlc_common.h:348
struct xml_reader_sys_t xml_reader_sys_t
Definition: vlc_common.h:307
Definition: vlc_renderer_discovery.h:164
#define ntoh16(i)
Definition: vlc_common.h:790
static uint16_t GetWLE(const void *p)
Reads 16 bits in little-endian order.
Definition: vlc_common.h:830
uint32_t vlc_fourcc_t
Definition: fourcc_gen.c:32
int flags
Definition: vlc_common.h:432
int(* vlc_callback_t)(vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void *)
Definition: vlc_common.h:365