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 )
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
164 #ifdef WORDS_BIGENDIAN
165 # define VLC_FOURCC( a, b, c, d ) \
166 ( ((uint32_t)d) | ( ((uint32_t)c) << 8 ) \
167 | ( ((uint32_t)b) << 16 ) | ( ((uint32_t)a) << 24 ) )
168 # define VLC_TWOCC( a, b ) \
169 ( (uint16_t)(b) | ( (uint16_t)(a) << 8 ) )
172 # define VLC_FOURCC( a, b, c, d ) \
173 ( ((uint32_t)a) | ( ((uint32_t)b) << 8 ) \
174 | ( ((uint32_t)c) << 16 ) | ( ((uint32_t)d) << 24 ) )
175 # define VLC_TWOCC( a, b ) \
176 ( (uint16_t)(a) | ( (uint16_t)(b) << 8 ) )
189 memcpy( psz_fourcc, &fcc, 4 );
339 struct { int32_t x; int32_t y; } coords;
356 #define VLC_SUCCESS (-0)
357 #define VLC_EGENERIC (-1)
358 #define VLC_ENOMEM (-2)
359 #define VLC_ETIMEOUT (-3)
360 #define VLC_ENOMOD (-4)
361 #define VLC_ENOOBJ (-5)
362 #define VLC_ENOVAR (-6)
363 #define VLC_EBADVAR (-7)
364 #define VLC_ENOITEM (-8)
387 #if defined( _WIN32 )
390 # define PATH_MAX MAX_PATH
392 # include <windows.h>
396 #include <sys/syslimits.h>
397 #include <AvailabilityMacros.h>
401 # define OS2EMX_PLAIN_CHAR
404 # include <os2safe.h>
463 #define VLC_COMMON_MEMBERS struct vlc_common_members obj;
473 #if !defined(__cplusplus)
474 # define VLC_OBJECT(x) \
476 struct vlc_common_members: (vlc_object_t *)(&(x)->obj), \
477 const struct vlc_common_members: (const vlc_object_t *)(&(x)->obj) \
480 # define VLC_OBJECT( x ) ((vlc_object_t *)&(x)->obj)
489 # define __MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
492 # define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
496 #define VLC_CLIP(v, min, max) __MIN(__MAX((v), (min)), (max))
499 static inline int64_t
GCD ( int64_t a, int64_t b )
514 if( a&(~255) )
return (-a)>>31;
520 static inline unsigned (
clz)(
unsigned x)
523 return __builtin_clz (x);
525 unsigned i =
sizeof (x) * 8;
536 #define clz8( x ) (clz(x) - ((sizeof(unsigned) - sizeof (uint8_t)) * 8))
537 #define clz16( x ) (clz(x) - ((sizeof(unsigned) - sizeof (uint16_t)) * 8))
539 #define clz32( x ) (clz(x) - ((sizeof(unsigned) - sizeof (uint32_t)) * 8))
543 static inline unsigned (
ctz)(
unsigned x)
546 return __builtin_ctz (x);
548 unsigned i =
sizeof (x) * 8;
559 #if !defined(__NetBSD__)
562 static inline unsigned (
popcount)(
unsigned x)
565 return __builtin_popcount (x);
579 static inline int (
popcountll)(
unsigned long long x)
582 return __builtin_popcountll(x);
596 static inline unsigned (
parity)(
unsigned x)
599 return __builtin_parity (x);
601 for (
unsigned i = 4 *
sizeof (x); i > 0; i /= 2)
607 #if !defined(__NetBSD__)
610 static inline uint16_t (
bswap16)(uint16_t x)
612 return (x << 8) | (x >> 8);
617 static inline uint32_t (
bswap32)(uint32_t x)
619 #if defined (__GNUC__) || defined(__clang__)
620 return __builtin_bswap32 (x);
622 return ((x & 0x000000FF) << 24)
623 | ((x & 0x0000FF00) << 8)
624 | ((x & 0x00FF0000) >> 8)
625 | ((x & 0xFF000000) >> 24);
631 static inline uint64_t (
bswap64)(uint64_t x)
633 #if defined (__GNUC__) || defined(__clang__)
634 return __builtin_bswap64 (x);
635 #elif !defined (__cplusplus)
636 return ((x & 0x00000000000000FF) << 56)
637 | ((x & 0x000000000000FF00) << 40)
638 | ((x & 0x0000000000FF0000) << 24)
639 | ((x & 0x00000000FF000000) << 8)
640 | ((x & 0x000000FF00000000) >> 8)
641 | ((x & 0x0000FF0000000000) >> 24)
642 | ((x & 0x00FF000000000000) >> 40)
643 | ((x & 0xFF00000000000000) >> 56);
645 return ((x & 0x00000000000000FFULL) << 56)
646 | ((x & 0x000000000000FF00ULL) << 40)
647 | ((x & 0x0000000000FF0000ULL) << 24)
648 | ((x & 0x00000000FF000000ULL) << 8)
649 | ((x & 0x000000FF00000000ULL) >> 8)
650 | ((x & 0x0000FF0000000000ULL) >> 24)
651 | ((x & 0x00FF000000000000ULL) >> 40)
652 | ((x & 0xFF00000000000000ULL) >> 56);
658 static inline bool uadd_overflow(
unsigned a,
unsigned b,
unsigned *res)
660 #if VLC_GCC_VERSION(5,0) || defined(__clang__)
661 return __builtin_uadd_overflow(a, b, res);
671 #if VLC_GCC_VERSION(5,0) || defined(__clang__)
672 return __builtin_uaddl_overflow(a, b, res);
679 static inline bool uaddll_overflow(
unsigned long long a,
unsigned long long b,
680 unsigned long long *res)
682 #if VLC_GCC_VERSION(5,0) || defined(__clang__)
683 return __builtin_uaddll_overflow(a, b, res);
691 # define add_overflow(a,b,r) \
693 unsigned: uadd_overflow(a, b, (unsigned *)(r)), \
694 unsigned long: uaddl_overflow(a, b, (unsigned long *)(r)), \
695 unsigned long long: uaddll_overflow(a, b, (unsigned long long *)(r)))
697 static inline bool add_overflow(
unsigned a,
unsigned b,
unsigned *res)
702 static inline bool add_overflow(
unsigned long a,
unsigned long b,
708 static inline bool add_overflow(
unsigned long long a,
unsigned long long b,
709 unsigned long long *res)
715 #if !(VLC_GCC_VERSION(5,0) || defined(__clang__))
719 static inline bool umul_overflow(
unsigned a,
unsigned b,
unsigned *res)
721 #if VLC_GCC_VERSION(5,0) || defined(__clang__)
722 return __builtin_umul_overflow(a, b, res);
725 return b > 0 && a > (UINT_MAX / b);
732 #if VLC_GCC_VERSION(5,0) || defined(__clang__)
733 return __builtin_umull_overflow(a, b, res);
736 return b > 0 && a > (ULONG_MAX / b);
740 static inline bool umulll_overflow(
unsigned long long a,
unsigned long long b,
741 unsigned long long *res)
743 #if VLC_GCC_VERSION(5,0) || defined(__clang__)
744 return __builtin_umulll_overflow(a, b, res);
747 return b > 0 && a > (ULLONG_MAX / b);
752 #define mul_overflow(a,b,r) \
754 unsigned: umul_overflow(a, b, (unsigned *)(r)), \
755 unsigned long: umull_overflow(a, b, (unsigned long *)(r)), \
756 unsigned long long: umulll_overflow(a, b, (unsigned long long *)(r)))
758 static inline bool mul_overflow(
unsigned a,
unsigned b,
unsigned *res)
763 static inline bool mul_overflow(
unsigned long a,
unsigned long b,
769 static inline bool mul_overflow(
unsigned long long a,
unsigned long long b,
770 unsigned long long *res)
777 #define FREENULL(a) do { free( a ); a = NULL; } while(0)
779 #define EMPTY_STR(str) (!str || !*str)
788 #ifdef WORDS_BIGENDIAN
789 # define hton16(i) ((uint16_t)(i))
790 # define hton32(i) ((uint32_t)(i))
791 # define hton64(i) ((uint64_t)(i))
793 # define hton16(i) bswap16(i)
794 # define hton32(i) bswap32(i)
795 # define hton64(i) bswap64(i)
797 #define ntoh16(i) hton16(i)
798 #define ntoh32(i) hton32(i)
799 #define ntoh64(i) hton64(i)
803 static inline uint16_t
U16_AT (
const void *
p)
807 memcpy (&x,
p,
sizeof (x));
813 static inline uint32_t
U32_AT (
const void *
p)
817 memcpy (&x,
p,
sizeof (x));
823 static inline uint64_t
U64_AT (
const void *
p)
827 memcpy (&x,
p,
sizeof (x));
831 #define GetWBE(p) U16_AT(p)
832 #define GetDWBE(p) U32_AT(p)
833 #define GetQWBE(p) U64_AT(p)
837 static inline uint16_t
GetWLE (
const void *
p)
841 memcpy (&x,
p,
sizeof (x));
842 #ifdef WORDS_BIGENDIAN
850 static inline uint32_t
GetDWLE (
const void *
p)
854 memcpy (&x,
p,
sizeof (x));
855 #ifdef WORDS_BIGENDIAN
863 static inline uint64_t
GetQWLE (
const void *
p)
867 memcpy (&x,
p,
sizeof (x));
868 #ifdef WORDS_BIGENDIAN
875 static inline void SetWBE (
void *
p, uint16_t w)
878 memcpy (
p, &w,
sizeof (w));
882 static inline void SetDWBE (
void *
p, uint32_t dw)
885 memcpy (
p, &dw,
sizeof (dw));
889 static inline void SetQWBE (
void *
p, uint64_t qw)
892 memcpy (
p, &qw,
sizeof (qw));
896 static inline void SetWLE (
void *
p, uint16_t w)
898 #ifdef WORDS_BIGENDIAN
901 memcpy (
p, &w,
sizeof (w));
905 static inline void SetDWLE (
void *
p, uint32_t dw)
907 #ifdef WORDS_BIGENDIAN
910 memcpy (
p, &dw,
sizeof (dw));
914 static inline void SetQWLE (
void *
p, uint64_t qw)
916 #ifdef WORDS_BIGENDIAN
919 memcpy (
p, &qw,
sizeof (qw));
923 #define VLC_UNUSED(x) (void)(x)
929 # if defined( __MINGW32__ )
930 # if !defined( _OFF_T_ )
931 typedef long long _off_t;
932 typedef _off_t off_t;
938 # define off_t long long
943 # define O_NONBLOCK 0
955 #define container_of(ptr, type, member) \
956 ((type *)(((char *)(ptr)) - offsetof(type, member)))
970 #define vlc_pgettext( ctx, id ) \
971 vlc_pgettext_aux( ctx "\004" id, id )
974 static inline const
char *
vlc_pgettext_aux( const
char *ctx, const
char *
id )
977 return (tr == ctx) ? id : tr;
983 static inline void *
xmalloc(
size_t len)
985 void *ptr = malloc(len);
991 static inline void *
xrealloc(
void *ptr,
size_t len)
993 void *nptr = realloc(ptr, len);
999 static inline void *
xcalloc(
size_t n,
size_t size)
1001 void *ptr = calloc(n, size);
1002 if (
unlikely(ptr == NULL && (n > 0 || size > 0)))
1007 static inline char *
xstrdup (
const char *str)
1009 char *ptr =
strdup (str);
1031 #if defined( _WIN32 ) || defined( __OS2__ )
1032 # define DIR_SEP_CHAR '\\'
1033 # define DIR_SEP "\\"
1034 # define PATH_SEP_CHAR ';'
1035 # define PATH_SEP ";"
1037 # define DIR_SEP_CHAR '/'
1038 # define DIR_SEP "/"
1039 # define PATH_SEP_CHAR ':'
1040 # define PATH_SEP ":"
1043 #define LICENSE_MSG \
1044 _("This program comes with NO WARRANTY, to the extent permitted by " \
1045 "law.\nYou may redistribute it under the terms of the GNU General " \
1046 "Public License;\nsee the file named COPYING for details.\n" \
1047 "Written by the VideoLAN team; see the AUTHORS file.\n")
#define hton16(i)
Definition: vlc_common.h:782
struct demux_sys_t demux_sys_t
Definition: vlc_common.h:219
Structure containing information about the playlist.
Definition: vlc_playlist.h:151
struct picture_sys_t picture_sys_t
Definition: vlc_common.h:246
size_t count
Definition: core.c:461
static bool umull_overflow(unsigned long a, unsigned long b, unsigned long *res)
Definition: vlc_common.h:718
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:668
static void SetQWLE(void *p, uint64_t qw)
Writes 64 bits in little endian order.
Definition: vlc_common.h:903
#define VLC_USED
Definition: vlc_common.h:103
VLC list structure.
Definition: vlc_common.h:340
#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
#define hton32(i)
Definition: vlc_common.h:783
static uint64_t() bswap64(uint64_t x)
Byte swap (64 bits)
Definition: vlc_common.h:620
#define ntoh64(i)
Definition: vlc_common.h:788
static bool uaddl_overflow(unsigned long a, unsigned long b, unsigned long *res)
Definition: vlc_common.h:657
Definition: vlc_input.h:48
Definition: vlc_input_item.h:48
libvlc_int_t * libvlc
LibVLC instance.
Definition: vlc_common.h:441
static char * xstrdup(const char *str)
Definition: vlc_common.h:994
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:812
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:307
struct decoder_sys_t decoder_sys_t
Definition: vlc_common.h:275
static uint32_t() bswap32(uint32_t x)
Byte swap (32 bits)
Definition: vlc_common.h:606
uint32_t vlc_fourcc_t
The vlc_fourcc_t type.
Definition: vlc_common.h:157
Stream output access_output.
Definition: vlc_sout.h:72
struct sout_access_out_sys_t sout_access_out_sys_t
Definition: vlc_common.h:262
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:792
struct xml_sys_t xml_sys_t
Definition: vlc_common.h:301
#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:878
struct filter_sys_t filter_sys_t
Definition: vlc_common.h:284
const char * VLC_Compiler(void)
Definition: version.c:43
static uint8_t clip_uint8_vlc(int32_t a)
Definition: vlc_common.h:501
struct decoder_synchro_t decoder_synchro_t
Definition: vlc_common.h:276
int(* vlc_list_callback_t)(vlc_object_t *, char const *, int, vlc_value_t *, void *)
Definition: vlc_common.h:369
vlc_object_t * parent
Parent object.
Definition: vlc_common.h:448
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:871
static int64_t GCD(int64_t a, int64_t b)
Definition: vlc_common.h:488
struct encoder_sys_t encoder_sys_t
Definition: vlc_common.h:280
int i_type
Definition: vlc_common.h:342
static uint16_t() bswap16(uint16_t x)
Byte swap (16 bits)
Definition: vlc_common.h:599
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:268
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:894
static bool umul_overflow(unsigned a, unsigned b, unsigned *res)
Definition: vlc_common.h:708
static unsigned() clz(unsigned x)
Count leading zeroes.
Definition: vlc_common.h:509
static void SetWBE(void *p, uint16_t w)
Writes 16 bits in network byte order.
Definition: vlc_common.h:864
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:885
Muxer structure.
Definition: vlc_sout.h:120
struct services_discovery_sys_t services_discovery_sys_t
Definition: vlc_common.h:201
Definition: fourcc_gen.c:33
static int() popcountll(unsigned long long x)
Bit weight of long long.
Definition: vlc_common.h:568
video_format_t video_frame_format_t
Definition: vlc_common.h:244
static void * xmalloc(size_t len)
Definition: vlc_common.h:970
const char * VLC_CompileHost(void)
Definition: version.c:42
Common structure members.
Definition: vlc_common.h:412
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:962
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:784
int i_count
Definition: vlc_common.h:343
#define mul_overflow(a, b, r)
Definition: vlc_common.h:741
Definition: vlc_image.h:39
Definition: renderer_discovery.c:33
#define ntoh32(i)
Definition: vlc_common.h:787
#define VLC_MALLOC
Definition: vlc_common.h:102
static void * xcalloc(size_t n, size_t size)
Definition: vlc_common.h:986
static unsigned() popcount(unsigned x)
Bit weight.
Definition: vlc_common.h:551
static void * xrealloc(void *ptr, size_t len)
Definition: vlc_common.h:978
static uint64_t GetQWLE(const void *p)
Reads 64 bits in little-endian order.
Definition: vlc_common.h:852
bool force
Module probe flag.
Definition: vlc_common.h:435
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:585
#define unlikely(p)
Definition: vlc_common.h:114
static bool uadd_overflow(unsigned a, unsigned b, unsigned *res)
Definition: vlc_common.h:647
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:238
struct vod_media_t vod_media_t
Definition: vlc_common.h:308
struct aout_sys_t aout_sys_t
Definition: vlc_common.h:237
int64_t mtime_t
High precision date or time interval.
Definition: vlc_common.h:150
char * header
Log messages header.
Definition: vlc_common.h:426
static uint32_t U32_AT(const void *p)
Reads 32 bits in network byte order.
Definition: vlc_common.h:802
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:182
Video output thread descriptor.
Definition: vlc_vout.h:70
#define add_overflow(a, b, r)
Definition: vlc_common.h:680
struct sout_mux_sys_t sout_mux_sys_t
Definition: vlc_common.h:265
static bool umulll_overflow(unsigned long long a, unsigned long long b, unsigned long long *res)
Definition: vlc_common.h:729
static void * vlc_alloc(size_t count, size_t size)
Definition: vlc_common.h:948
VLC value structure.
Definition: vlc_common.h:325
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:419
static uint32_t GetDWLE(const void *p)
Reads 32 bits in little-endian order.
Definition: vlc_common.h:839
static unsigned() ctz(unsigned x)
Count trailing zeroes.
Definition: vlc_common.h:532
vlc_value_t * p_values
Definition: vlc_common.h:344
struct xml_reader_sys_t xml_reader_sys_t
Definition: vlc_common.h:303
Definition: vlc_renderer_discovery.h:164
#define ntoh16(i)
Definition: vlc_common.h:786
static uint16_t GetWLE(const void *p)
Reads 16 bits in little-endian order.
Definition: vlc_common.h:826
uint32_t vlc_fourcc_t
Definition: fourcc_gen.c:32
int flags
Definition: vlc_common.h:428
int(* vlc_callback_t)(vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void *)
Definition: vlc_common.h:361