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 # if !defined(unreachable)
116 # define unreachable() __builtin_unreachable()
119 # define likely(p) (!!(p))
120 # define unlikely(p) (!!(p))
121 # define unreachable() ((void)0)
124 #define vlc_assert_unreachable() (assert(!"unreachable"), unreachable())
128 # define VLC_EXTERN extern "C"
133 #if defined (_WIN32) && defined (DLL_EXPORT)
134 # define VLC_EXPORT __declspec(dllexport)
135 #elif defined (__GNUC__)
136 # define VLC_EXPORT __attribute__((visibility("default")))
141 #define VLC_API VLC_EXTERN VLC_EXPORT
160 #define VLC_TICK_INVALID VLC_TS_INVALID
161 #define VLC_TICK_0 VLC_TS_0
170 #ifdef WORDS_BIGENDIAN
171 # define VLC_FOURCC( a, b, c, d ) \
172 ( ((uint32_t)d) | ( ((uint32_t)c) << 8 ) \
173 | ( ((uint32_t)b) << 16 ) | ( ((uint32_t)a) << 24 ) )
174 # define VLC_TWOCC( a, b ) \
175 ( (uint16_t)(b) | ( (uint16_t)(a) << 8 ) )
178 # define VLC_FOURCC( a, b, c, d ) \
179 ( ((uint32_t)a) | ( ((uint32_t)b) << 8 ) \
180 | ( ((uint32_t)c) << 16 ) | ( ((uint32_t)d) << 24 ) )
181 # define VLC_TWOCC( a, b ) \
182 ( (uint16_t)(a) | ( (uint16_t)(b) << 8 ) )
195 memcpy( psz_fourcc, &fcc, 4 );
345 struct { int32_t x; int32_t y; } coords;
362 #define VLC_SUCCESS (-0)
363 #define VLC_EGENERIC (-1)
364 #define VLC_ENOMEM (-2)
365 #define VLC_ETIMEOUT (-3)
366 #define VLC_ENOMOD (-4)
367 #define VLC_ENOOBJ (-5)
368 #define VLC_ENOVAR (-6)
369 #define VLC_EBADVAR (-7)
370 #define VLC_ENOITEM (-8)
393 #if defined( _WIN32 )
396 # define PATH_MAX MAX_PATH
398 # include <windows.h>
402 #include <sys/syslimits.h>
403 #include <AvailabilityMacros.h>
407 # define OS2EMX_PLAIN_CHAR
410 # include <os2safe.h>
469 #define VLC_COMMON_MEMBERS struct vlc_common_members obj;
479 #if !defined(__cplusplus)
480 # define VLC_OBJECT(x) \
482 vlc_object_t: (vlc_object_t *)(&(x)->obj), \
483 struct vlc_common_members: (vlc_object_t *)(x) \
486 # define VLC_OBJECT( x ) ((vlc_object_t *)&(x)->obj)
495 # define __MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
498 # define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
502 #define VLC_CLIP(v, min, max) __MIN(__MAX((v), (min)), (max))
505 static inline int64_t
GCD ( int64_t a, int64_t b )
520 if( a&(~255) )
return (-a)>>31;
526 static inline unsigned (
clz)(
unsigned x)
529 return __builtin_clz (x);
531 unsigned i =
sizeof (x) * 8;
542 #define clz8( x ) (clz(x) - ((sizeof(unsigned) - sizeof (uint8_t)) * 8))
543 #define clz16( x ) (clz(x) - ((sizeof(unsigned) - sizeof (uint16_t)) * 8))
545 #define clz32( x ) (clz(x) - ((sizeof(unsigned) - sizeof (uint32_t)) * 8))
549 static inline unsigned (
ctz)(
unsigned x)
552 return __builtin_ctz (x);
554 unsigned i =
sizeof (x) * 8;
565 #if !defined(__NetBSD__)
568 static inline unsigned (
popcount)(
unsigned x)
571 return __builtin_popcount (x);
585 static inline int (
popcountll)(
unsigned long long x)
588 return __builtin_popcountll(x);
602 static inline unsigned (
parity)(
unsigned x)
605 return __builtin_parity (x);
607 for (
unsigned i = 4 *
sizeof (x); i > 0; i /= 2)
613 #if !defined(__NetBSD__)
616 static inline uint16_t (
bswap16)(uint16_t x)
618 return (x << 8) | (x >> 8);
623 static inline uint32_t (
bswap32)(uint32_t x)
625 #if defined (__GNUC__) || defined(__clang__)
626 return __builtin_bswap32 (x);
628 return ((x & 0x000000FF) << 24)
629 | ((x & 0x0000FF00) << 8)
630 | ((x & 0x00FF0000) >> 8)
631 | ((x & 0xFF000000) >> 24);
637 static inline uint64_t (
bswap64)(uint64_t x)
639 #if defined (__GNUC__) || defined(__clang__)
640 return __builtin_bswap64 (x);
641 #elif !defined (__cplusplus)
642 return ((x & 0x00000000000000FF) << 56)
643 | ((x & 0x000000000000FF00) << 40)
644 | ((x & 0x0000000000FF0000) << 24)
645 | ((x & 0x00000000FF000000) << 8)
646 | ((x & 0x000000FF00000000) >> 8)
647 | ((x & 0x0000FF0000000000) >> 24)
648 | ((x & 0x00FF000000000000) >> 40)
649 | ((x & 0xFF00000000000000) >> 56);
651 return ((x & 0x00000000000000FFULL) << 56)
652 | ((x & 0x000000000000FF00ULL) << 40)
653 | ((x & 0x0000000000FF0000ULL) << 24)
654 | ((x & 0x00000000FF000000ULL) << 8)
655 | ((x & 0x000000FF00000000ULL) >> 8)
656 | ((x & 0x0000FF0000000000ULL) >> 24)
657 | ((x & 0x00FF000000000000ULL) >> 40)
658 | ((x & 0xFF00000000000000ULL) >> 56);
664 static inline bool uadd_overflow(
unsigned a,
unsigned b,
unsigned *res)
666 #if VLC_GCC_VERSION(5,0) || defined(__clang__)
667 return __builtin_uadd_overflow(a, b, res);
677 #if VLC_GCC_VERSION(5,0) || defined(__clang__)
678 return __builtin_uaddl_overflow(a, b, res);
685 static inline bool uaddll_overflow(
unsigned long long a,
unsigned long long b,
686 unsigned long long *res)
688 #if VLC_GCC_VERSION(5,0) || defined(__clang__)
689 return __builtin_uaddll_overflow(a, b, res);
697 # define add_overflow(a,b,r) \
699 unsigned: uadd_overflow(a, b, (unsigned *)(r)), \
700 unsigned long: uaddl_overflow(a, b, (unsigned long *)(r)), \
701 unsigned long long: uaddll_overflow(a, b, (unsigned long long *)(r)))
703 static inline bool add_overflow(
unsigned a,
unsigned b,
unsigned *res)
708 static inline bool add_overflow(
unsigned long a,
unsigned long b,
714 static inline bool add_overflow(
unsigned long long a,
unsigned long long b,
715 unsigned long long *res)
721 #if !(VLC_GCC_VERSION(5,0) || defined(__clang__))
725 static inline bool umul_overflow(
unsigned a,
unsigned b,
unsigned *res)
727 #if VLC_GCC_VERSION(5,0) || defined(__clang__)
728 return __builtin_umul_overflow(a, b, res);
731 return b > 0 && a > (UINT_MAX / b);
738 #if VLC_GCC_VERSION(5,0) || defined(__clang__)
739 return __builtin_umull_overflow(a, b, res);
742 return b > 0 && a > (ULONG_MAX / b);
746 static inline bool umulll_overflow(
unsigned long long a,
unsigned long long b,
747 unsigned long long *res)
749 #if VLC_GCC_VERSION(5,0) || defined(__clang__)
750 return __builtin_umulll_overflow(a, b, res);
753 return b > 0 && a > (ULLONG_MAX / b);
758 #define mul_overflow(a,b,r) \
760 unsigned: umul_overflow(a, b, (unsigned *)(r)), \
761 unsigned long: umull_overflow(a, b, (unsigned long *)(r)), \
762 unsigned long long: umulll_overflow(a, b, (unsigned long long *)(r)))
764 static inline bool mul_overflow(
unsigned a,
unsigned b,
unsigned *res)
769 static inline bool mul_overflow(
unsigned long a,
unsigned long b,
775 static inline bool mul_overflow(
unsigned long long a,
unsigned long long b,
776 unsigned long long *res)
783 #define FREENULL(a) do { free( a ); a = NULL; } while(0)
785 #define EMPTY_STR(str) (!str || !*str)
794 #ifdef WORDS_BIGENDIAN
795 # define hton16(i) ((uint16_t)(i))
796 # define hton32(i) ((uint32_t)(i))
797 # define hton64(i) ((uint64_t)(i))
799 # define hton16(i) bswap16(i)
800 # define hton32(i) bswap32(i)
801 # define hton64(i) bswap64(i)
803 #define ntoh16(i) hton16(i)
804 #define ntoh32(i) hton32(i)
805 #define ntoh64(i) hton64(i)
809 static inline uint16_t
U16_AT (
const void *
p)
813 memcpy (&x,
p,
sizeof (x));
819 static inline uint32_t
U32_AT (
const void *
p)
823 memcpy (&x,
p,
sizeof (x));
829 static inline uint64_t
U64_AT (
const void *
p)
833 memcpy (&x,
p,
sizeof (x));
837 #define GetWBE(p) U16_AT(p)
838 #define GetDWBE(p) U32_AT(p)
839 #define GetQWBE(p) U64_AT(p)
843 static inline uint16_t
GetWLE (
const void *
p)
847 memcpy (&x,
p,
sizeof (x));
848 #ifdef WORDS_BIGENDIAN
856 static inline uint32_t
GetDWLE (
const void *
p)
860 memcpy (&x,
p,
sizeof (x));
861 #ifdef WORDS_BIGENDIAN
869 static inline uint64_t
GetQWLE (
const void *
p)
873 memcpy (&x,
p,
sizeof (x));
874 #ifdef WORDS_BIGENDIAN
881 static inline void SetWBE (
void *
p, uint16_t w)
884 memcpy (
p, &w,
sizeof (w));
888 static inline void SetDWBE (
void *
p, uint32_t dw)
891 memcpy (
p, &dw,
sizeof (dw));
895 static inline void SetQWBE (
void *
p, uint64_t qw)
898 memcpy (
p, &qw,
sizeof (qw));
902 static inline void SetWLE (
void *
p, uint16_t w)
904 #ifdef WORDS_BIGENDIAN
907 memcpy (
p, &w,
sizeof (w));
911 static inline void SetDWLE (
void *
p, uint32_t dw)
913 #ifdef WORDS_BIGENDIAN
916 memcpy (
p, &dw,
sizeof (dw));
920 static inline void SetQWLE (
void *
p, uint64_t qw)
922 #ifdef WORDS_BIGENDIAN
925 memcpy (
p, &qw,
sizeof (qw));
929 #define VLC_UNUSED(x) (void)(x)
935 # if defined( __MINGW32__ )
936 # if !defined( _OFF_T_ )
937 typedef long long _off_t;
938 typedef _off_t off_t;
944 # define off_t long long
949 # define O_NONBLOCK 0
954 # define swab(a,b,c) swab((char*) (a), (char*) (b), (c))
966 #define container_of(ptr, type, member) \
967 ((type *)(((char *)(ptr)) - offsetof(type, member)))
981 #define vlc_pgettext( ctx, id ) \
982 vlc_pgettext_aux( ctx "\004" id, id )
985 static inline const
char *
vlc_pgettext_aux( const
char *ctx, const
char *
id )
988 return (tr == ctx) ? id : tr;
994 static inline void *
xmalloc(
size_t len)
996 void *ptr = malloc(len);
1002 static inline void *
xrealloc(
void *ptr,
size_t len)
1004 void *nptr = realloc(ptr, len);
1010 static inline void *
xcalloc(
size_t n,
size_t size)
1012 void *ptr = calloc(n, size);
1013 if (
unlikely(ptr == NULL && (n > 0 || size > 0)))
1018 static inline char *
xstrdup (
const char *str)
1020 char *ptr =
strdup (str);
1042 #if defined( _WIN32 ) || defined( __OS2__ )
1043 # define DIR_SEP_CHAR '\\'
1044 # define DIR_SEP "\\"
1045 # define PATH_SEP_CHAR ';'
1046 # define PATH_SEP ";"
1048 # define DIR_SEP_CHAR '/'
1049 # define DIR_SEP "/"
1050 # define PATH_SEP_CHAR ':'
1051 # define PATH_SEP ":"
1054 #define LICENSE_MSG \
1055 _("This program comes with NO WARRANTY, to the extent permitted by " \
1056 "law.\nYou may redistribute it under the terms of the GNU General " \
1057 "Public License;\nsee the file named COPYING for details.\n" \
1058 "Written by the VideoLAN team; see the AUTHORS file.\n")
#define hton16(i)
Definition: vlc_common.h:788
struct demux_sys_t demux_sys_t
Definition: vlc_common.h:225
Structure containing information about the playlist.
Definition: vlc_playlist.h:151
struct picture_sys_t picture_sys_t
Definition: vlc_common.h:252
size_t count
Definition: core.c:461
static bool umull_overflow(unsigned long a, unsigned long b, unsigned long *res)
Definition: vlc_common.h:724
vlc_tick_t mtime_t
Definition: vlc_common.h:153
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:674
static void SetQWLE(void *p, uint64_t qw)
Writes 64 bits in little endian order.
Definition: vlc_common.h:909
#define VLC_USED
Definition: vlc_common.h:103
VLC list structure.
Definition: vlc_common.h:346
#define VLC_API
Definition: vlc_common.h:137
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:152
#define hton32(i)
Definition: vlc_common.h:789
static uint64_t() bswap64(uint64_t x)
Byte swap (64 bits)
Definition: vlc_common.h:626
#define ntoh64(i)
Definition: vlc_common.h:794
static bool uaddl_overflow(unsigned long a, unsigned long b, unsigned long *res)
Definition: vlc_common.h:663
Definition: vlc_input.h:48
Definition: vlc_input_item.h:48
libvlc_int_t * libvlc
LibVLC instance.
Definition: vlc_common.h:447
static char * xstrdup(const char *str)
Definition: vlc_common.h:1005
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:818
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:313
struct decoder_sys_t decoder_sys_t
Definition: vlc_common.h:281
static uint32_t() bswap32(uint32_t x)
Byte swap (32 bits)
Definition: vlc_common.h:612
uint32_t vlc_fourcc_t
The vlc_fourcc_t type.
Definition: vlc_common.h:163
Stream output access_output.
Definition: vlc_sout.h:72
struct sout_access_out_sys_t sout_access_out_sys_t
Definition: vlc_common.h:268
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:798
struct xml_sys_t xml_sys_t
Definition: vlc_common.h:307
#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:884
struct filter_sys_t filter_sys_t
Definition: vlc_common.h:290
const char * VLC_Compiler(void)
Definition: version.c:43
static uint8_t clip_uint8_vlc(int32_t a)
Definition: vlc_common.h:507
struct decoder_synchro_t decoder_synchro_t
Definition: vlc_common.h:282
int(* vlc_list_callback_t)(vlc_object_t *, char const *, int, vlc_value_t *, void *)
Definition: vlc_common.h:375
vlc_object_t * parent
Parent object.
Definition: vlc_common.h:454
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:877
static int64_t GCD(int64_t a, int64_t b)
Definition: vlc_common.h:494
struct encoder_sys_t encoder_sys_t
Definition: vlc_common.h:286
int i_type
Definition: vlc_common.h:348
static uint16_t() bswap16(uint16_t x)
Byte swap (16 bits)
Definition: vlc_common.h:605
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:274
Definition: vlm_internal.h:83
Video subtitle.
Definition: vlc_subpicture.h:153
Definition: vlc_mtime.h:118
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:900
static bool umul_overflow(unsigned a, unsigned b, unsigned *res)
Definition: vlc_common.h:714
static unsigned() clz(unsigned x)
Count leading zeroes.
Definition: vlc_common.h:515
static void SetWBE(void *p, uint16_t w)
Writes 16 bits in network byte order.
Definition: vlc_common.h:870
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:891
Muxer structure.
Definition: vlc_sout.h:120
struct services_discovery_sys_t services_discovery_sys_t
Definition: vlc_common.h:207
Definition: fourcc_gen.c:33
static int() popcountll(unsigned long long x)
Bit weight of long long.
Definition: vlc_common.h:574
video_format_t video_frame_format_t
Definition: vlc_common.h:250
static void * xmalloc(size_t len)
Definition: vlc_common.h:981
const char * VLC_CompileHost(void)
Definition: version.c:42
Common structure members.
Definition: vlc_common.h:418
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:973
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:790
int i_count
Definition: vlc_common.h:349
#define mul_overflow(a, b, r)
Definition: vlc_common.h:747
Definition: vlc_image.h:39
Definition: renderer_discovery.c:33
#define ntoh32(i)
Definition: vlc_common.h:793
#define VLC_MALLOC
Definition: vlc_common.h:102
static void * xcalloc(size_t n, size_t size)
Definition: vlc_common.h:997
static unsigned() popcount(unsigned x)
Bit weight.
Definition: vlc_common.h:557
static void * xrealloc(void *ptr, size_t len)
Definition: vlc_common.h:989
static uint64_t GetQWLE(const void *p)
Reads 64 bits in little-endian order.
Definition: vlc_common.h:858
bool force
Module probe flag.
Definition: vlc_common.h:441
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:591
#define unlikely(p)
Definition: vlc_common.h:116
static bool uadd_overflow(unsigned a, unsigned b, unsigned *res)
Definition: vlc_common.h:653
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:244
struct vod_media_t vod_media_t
Definition: vlc_common.h:314
struct aout_sys_t aout_sys_t
Definition: vlc_common.h:243
char * header
Log messages header.
Definition: vlc_common.h:432
static uint32_t U32_AT(const void *p)
Reads 32 bits in network byte order.
Definition: vlc_common.h:808
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:188
Video output thread descriptor.
Definition: vlc_vout.h:70
#define add_overflow(a, b, r)
Definition: vlc_common.h:686
struct sout_mux_sys_t sout_mux_sys_t
Definition: vlc_common.h:271
static bool umulll_overflow(unsigned long long a, unsigned long long b, unsigned long long *res)
Definition: vlc_common.h:735
static void * vlc_alloc(size_t count, size_t size)
Definition: vlc_common.h:959
VLC value structure.
Definition: vlc_common.h:331
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:425
static uint32_t GetDWLE(const void *p)
Reads 32 bits in little-endian order.
Definition: vlc_common.h:845
static unsigned() ctz(unsigned x)
Count trailing zeroes.
Definition: vlc_common.h:538
vlc_value_t * p_values
Definition: vlc_common.h:350
struct xml_reader_sys_t xml_reader_sys_t
Definition: vlc_common.h:309
Definition: vlc_renderer_discovery.h:164
#define ntoh16(i)
Definition: vlc_common.h:792
static uint16_t GetWLE(const void *p)
Reads 16 bits in little-endian order.
Definition: vlc_common.h:832
uint32_t vlc_fourcc_t
Definition: fourcc_gen.c:32
int flags
Definition: vlc_common.h:434
int(* vlc_callback_t)(vlc_object_t *, char const *, vlc_value_t, vlc_value_t, void *)
Definition: vlc_common.h:367