28# define VLC_COMMON_H 1
69#if defined __has_attribute
70# if __has_attribute(warning)
71# define VLC_WARN_CALL(w) VLC_NOINLINE_FUNC __attribute__((warning((w))))
73# define VLC_WARN_CALL(w)
76# if __has_attribute(error)
77# define VLC_ERROR_CALL(e) VLC_NOINLINE_FUNC __attribute__((error((e))))
79# define VLC_ERROR_CALL(e)
82# if __has_attribute(unused)
83# define VLC_UNUSED_FUNC __attribute__((unused))
85# define VLC_UNUSED_FUNC
88# if __has_attribute(noinline)
89# define VLC_NOINLINE_FUNC __attribute__((noinline))
91# define VLC_NOINLINE_FUNC
94# if __has_attribute(deprecated)
95# define VLC_DEPRECATED __attribute__((deprecated))
106# define VLC_DEPRECATED
109# if __has_attribute(malloc)
110# define VLC_MALLOC __attribute__((malloc))
128# if __has_attribute(warn_unused_result)
129# define VLC_USED __attribute__((warn_unused_result))
149#elif defined(_MSC_VER)
150# define VLC_USED _Check_return_
154# define VLC_DEPRECATED
158# define VLC_DEPRECATED
163# define VLC_DEPRECATED_ENUM __attribute__((deprecated))
165# if defined( _WIN32 ) && !defined( __clang__ )
166# define VLC_FORMAT(x,y) __attribute__ ((format(gnu_printf,x,y)))
168# define VLC_FORMAT(x,y) __attribute__ ((format(printf,x,y)))
170# define VLC_FORMAT_ARG(x) __attribute__ ((format_arg(x)))
181# define VLC_DEPRECATED_ENUM
193# define VLC_FORMAT(x,y)
204# define VLC_FORMAT_ARG(x)
207#if defined (__ELF__) || defined (__MACH__) || defined (__wasm__)
208# define VLC_WEAK __attribute__((weak))
221#if defined (__GNUC__) || defined (__clang__)
222# define likely(p) __builtin_expect(!!(p), 1)
223# define unlikely(p) __builtin_expect(!!(p), 0)
224# if !defined(unreachable)
225# define unreachable() __builtin_unreachable()
227#elif defined(_MSC_VER)
228# define likely(p) (!!(p))
229# define unlikely(p) (!!(p))
230# define unreachable() (__assume(0))
239# define likely(p) (!!(p))
248# define unlikely(p) (!!(p))
260# define unreachable() ((void)0)
274#define vlc_assert_unreachable() (vlc_assert(!"unreachable"), unreachable())
289#ifdef LIBVLC_INTERNAL_
290# define vlc_assert(pred) assert(pred)
292# define vlc_assert(pred) ((void)0)
297# define VLC_EXTERN extern "C"
302#if defined (_WIN32) && defined (VLC_DLL_EXPORT)
303# define VLC_EXPORT __declspec(dllexport)
304#elif defined (__GNUC__)
305# define VLC_EXPORT __attribute__((visibility("default")))
316#define VLC_API VLC_EXTERN VLC_EXPORT
330#ifdef WORDS_BIGENDIAN
331# define VLC_FOURCC( a, b, c, d ) \
332 ( ((uint32_t)d) | ( ((uint32_t)c) << 8 ) \
333 | ( ((uint32_t)b) << 16 ) | ( ((uint32_t)a) << 24 ) )
334# define VLC_TWOCC( a, b ) \
335 ( (uint16_t)(b) | ( (uint16_t)(a) << 8 ) )
338# define VLC_FOURCC( a, b, c, d ) \
339 ( ((uint32_t)a) | ( ((uint32_t)b) << 8 ) \
340 | ( ((uint32_t)c) << 16 ) | ( ((uint32_t)d) << 24 ) )
341# define VLC_TWOCC( a, b ) \
342 ( (uint16_t)(a) | ( (uint16_t)(b) << 8 ) )
355 memcpy( psz_fourcc, &fcc, 4 );
482#define VLC_EGENERIC (-2 * (1 << (sizeof (int) * 8 - 2)))
484#define VLC_ENOMEM (-ENOMEM)
486#define VLC_ETIMEOUT (-ETIMEDOUT)
488#define VLC_ENOENT (-ENOENT)
490#define VLC_EINVAL (-EINVAL)
492#define VLC_EACCES (-EACCES)
494#define VLC_ENOTSUP (-ENOTSUP)
506#include <sys/syslimits.h>
507#include <AvailabilityMacros.h>
511# define OS2EMX_PLAIN_CHAR
527# define __MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
530# define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
534#define VLC_CLIP(v, min, max) __MIN(__MAX((v), (min)), (max))
544 return (v + (align - 1)) & ~(align - 1);
547#if defined __has_attribute
548# if __has_attribute(diagnose_if)
549static inline size_t vlc_align(
size_t v,
size_t align)
550 __attribute__((diagnose_if(((align & (align - 1)) || (align == 0)),
551 "align must be power of 2",
"error")));
557static inline int64_t
GCD ( int64_t a, int64_t b )
572 if( a&(~255) )
return (-a)>>31;
581#define VLC_INT_FUNC(basename) \
582 VLC_INT_FUNC_TYPE(basename, unsigned, ) \
583 VLC_INT_FUNC_TYPE(basename, unsigned long, l) \
584 VLC_INT_FUNC_TYPE(basename, unsigned long long, ll)
586#if defined (__GNUC__) || defined (__clang__)
587# define VLC_INT_FUNC_TYPE(basename,type,suffix) \
588VLC_USED static inline int vlc_##basename##suffix(type x) \
590 return __builtin_##basename##suffix(x); \
595 unsigned i =
sizeof (x) * 8;
607 for (
unsigned i = 4 *
sizeof (x); i > 0; i /= 2)
623# define VLC_INT_FUNC_TYPE(basename,type,suffix) \
624VLC_USED static inline int vlc_##basename##suffix(type x) \
626 return vlc_##basename##_generic(x); \
635# define VLC_INT_GENERIC(func,x) \
637 unsigned char: func(x), \
638 signed char: func(x), \
639 unsigned short: func(x), \
640 signed short: func(x), \
641 unsigned int: func(x), \
642 signed int: func(x), \
643 unsigned long: func##l(x), \
644 signed long: func##l(x), \
645 unsigned long long: func##ll(x), \
646 signed long long: func##ll(x))
658# define ctz(x) VLC_INT_GENERIC(vlc_ctz, x)
667# define parity(x) VLC_INT_GENERIC(vlc_parity, x)
676# define vlc_popcount(x) \
678 signed char: vlc_popcount((unsigned char)(x)), \
679 signed short: vlc_popcount((unsigned short)(x)), \
680 default: VLC_INT_GENERIC(vlc_popcount ,x))
707 return (x << 8) | (x >> 8);
714#if defined (__GNUC__) || defined(__clang__)
715 return __builtin_bswap32 (x);
717 return ((x & 0x000000FF) << 24)
718 | ((x & 0x0000FF00) << 8)
719 | ((x & 0x00FF0000) >> 8)
720 | ((x & 0xFF000000) >> 24);
728#if defined (__GNUC__) || defined(__clang__)
729 return __builtin_bswap64 (x);
730#elif !defined (__cplusplus)
731 return ((x & 0x00000000000000FF) << 56)
732 | ((x & 0x000000000000FF00) << 40)
733 | ((x & 0x0000000000FF0000) << 24)
734 | ((x & 0x00000000FF000000) << 8)
735 | ((x & 0x000000FF00000000) >> 8)
736 | ((x & 0x0000FF0000000000) >> 24)
737 | ((x & 0x00FF000000000000) >> 40)
738 | ((x & 0xFF00000000000000) >> 56);
740 return ((x & 0x00000000000000FFULL) << 56)
741 | ((x & 0x000000000000FF00ULL) << 40)
742 | ((x & 0x0000000000FF0000ULL) << 24)
743 | ((x & 0x00000000FF000000ULL) << 8)
744 | ((x & 0x000000FF00000000ULL) >> 8)
745 | ((x & 0x0000FF0000000000ULL) >> 24)
746 | ((x & 0x00FF000000000000ULL) >> 40)
747 | ((x & 0xFF00000000000000ULL) >> 56);
758#if defined(__GNUC__) || defined(__clang__)
759 return __builtin_uadd_overflow(a, b, res);
769#if defined(__GNUC__) || defined(__clang__)
770 return __builtin_uaddl_overflow(a, b, res);
778 unsigned long long *res)
780#if defined(__GNUC__) || defined(__clang__)
781 return __builtin_uaddll_overflow(a, b, res);
802# define add_overflow(a,b,r) \
804 unsigned: uadd_overflow(a, b, (unsigned *)(r)), \
805 unsigned long: uaddl_overflow(a, b, (unsigned long *)(r)), \
806 unsigned long long: uaddll_overflow(a, b, (unsigned long long *)(r)))
808static inline bool add_overflow(
unsigned a,
unsigned b,
unsigned *res)
813static inline bool add_overflow(
unsigned long a,
unsigned long b,
819static inline bool add_overflow(
unsigned long long a,
unsigned long long b,
820 unsigned long long *res)
826#if !(defined(__GNUC__) || defined(__clang__))
832#if defined(__GNUC__) || defined(__clang__)
833 return __builtin_umul_overflow(a, b, res);
836 return b > 0 && a > (UINT_MAX / b);
843#if defined(__GNUC__) || defined(__clang__)
844 return __builtin_umull_overflow(a, b, res);
847 return b > 0 && a > (ULONG_MAX / b);
852 unsigned long long *res)
854#if defined(__GNUC__) || defined(__clang__)
855 return __builtin_umulll_overflow(a, b, res);
858 return b > 0 && a > (ULLONG_MAX / b);
876#define mul_overflow(a,b,r) \
878 unsigned: umul_overflow(a, b, (unsigned *)(r)), \
879 unsigned long: umull_overflow(a, b, (unsigned long *)(r)), \
880 unsigned long long: umulll_overflow(a, b, (unsigned long long *)(r)))
882static inline bool mul_overflow(
unsigned a,
unsigned b,
unsigned *res)
887static inline bool mul_overflow(
unsigned long a,
unsigned long b,
893static inline bool mul_overflow(
unsigned long long a,
unsigned long long b,
894 unsigned long long *res)
903#define FREENULL(a) do { free( a ); a = NULL; } while(0)
905#define EMPTY_STR(str) (!str || !*str)
907#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
912#ifdef WORDS_BIGENDIAN
913# define hton16(i) ((uint16_t)(i))
914# define hton32(i) ((uint32_t)(i))
915# define hton64(i) ((uint64_t)(i))
917# define hton16(i) vlc_bswap16(i)
918# define hton32(i) vlc_bswap32(i)
919# define hton64(i) vlc_bswap64(i)
921#define ntoh16(i) hton16(i)
922#define ntoh32(i) hton32(i)
923#define ntoh64(i) hton64(i)
931 memcpy (&x,
p,
sizeof (x));
941 memcpy (&x,
p,
sizeof (x));
951 memcpy (&x,
p,
sizeof (x));
955#define GetWBE(p) U16_AT(p)
956#define GetDWBE(p) U32_AT(p)
957#define GetQWBE(p) U64_AT(p)
965 memcpy (&x,
p,
sizeof (x));
966#ifdef WORDS_BIGENDIAN
978 memcpy (&x,
p,
sizeof (x));
979#ifdef WORDS_BIGENDIAN
991 memcpy (&x,
p,
sizeof (x));
992#ifdef WORDS_BIGENDIAN
999static inline void SetWBE (
void *
p, uint16_t w)
1002 memcpy (
p, &w,
sizeof (w));
1009 memcpy (
p, &dw,
sizeof (dw));
1016 memcpy (
p, &qw,
sizeof (qw));
1022#ifdef WORDS_BIGENDIAN
1025 memcpy (
p, &w,
sizeof (w));
1031#ifdef WORDS_BIGENDIAN
1034 memcpy (
p, &dw,
sizeof (dw));
1040#ifdef WORDS_BIGENDIAN
1043 memcpy (
p, &qw,
sizeof (qw));
1047#define VLC_UNUSED(x) (void)(x)
1054# define O_NONBLOCK 0
1059# define swab(a,b,c) _swab((char*) (a), (char*) (b), (c))
1069#define container_of(ptr, type, member) \
1070 ((type *)(((char *)(ptr)) - offsetof(type, member)))
1091#define vlc_pgettext( ctx, id ) \
1092 vlc_pgettext_aux( ctx "\004" id, id )
1098 return (tr == ctx) ? id : tr;
1106 void *ptr = malloc(len);
1107 if (
unlikely(ptr == NULL && len > 0))
1114 void *nptr = realloc(ptr, len);
1115 if (
unlikely(nptr == NULL && len > 0))
1122 char *ptr =
strdup (str);
1142#if defined( _WIN32 ) || defined( __OS2__ )
1143# define DIR_SEP_CHAR '\\'
1144# define DIR_SEP "\\"
1145# define PATH_SEP_CHAR ';'
1146# define PATH_SEP ";"
1148# define DIR_SEP_CHAR '/'
1150# define PATH_SEP_CHAR ':'
1151# define PATH_SEP ":"
1154#define LICENSE_MSG \
1155 _("This program comes with NO WARRANTY, to the extent permitted by " \
1156 "law.\nYou may redistribute it under the terms of the GNU General " \
1157 "Public License;\nsee the file named COPYING for details.\n" \
1158 "Written by the VideoLAN team; see the AUTHORS file.\n")
1160#if defined(__cplusplus) || defined(_MSC_VER)
1161#define ARRAY_STATIC_SIZE
1163#define ARRAY_STATIC_SIZE static
size_t count
Definition core.c:403
uint32_t vlc_fourcc_t
Definition fourcc_gen.c:33
static uint32_t vlc_bswap32(uint32_t x)
Byte swap (32 bits)
Definition vlc_common.h:712
#define ctz(x)
Count trailing zeroes.
Definition vlc_common.h:658
#define vlc_popcount(x)
Bit weight / population count.
Definition vlc_common.h:676
static int vlc_popcountl(unsigned long x)
Definition vlc_common.h:632
#define parity(x)
Parity.
Definition vlc_common.h:667
static uint64_t vlc_bswap64(uint64_t x)
Byte swap (64 bits)
Definition vlc_common.h:726
static int vlc_parity_generic(unsigned long long x)
Definition vlc_common.h:605
static int vlc_popcountll(unsigned long long x)
Definition vlc_common.h:632
static int vlc_popcount_generic(unsigned long long x)
Definition vlc_common.h:612
static int vlc_ctz_generic(unsigned long long x)
Definition vlc_common.h:593
static uint16_t vlc_bswap16(uint16_t x)
Byte swap (16 bits)
Definition vlc_common.h:705
#define VLC_INT_FUNC(basename)
Definition vlc_common.h:581
#define unlikely(p)
Predicted false condition.
Definition vlc_common.h:248
#define VLC_USED
Definition vlc_common.h:156
#define VLC_API
Exported API call annotation.
Definition vlc_common.h:316
#define VLC_MALLOC
Definition vlc_common.h:157
#define VLC_FORMAT_ARG(x)
Format string translation function annotation.
Definition vlc_common.h:204
static int64_t GCD(int64_t a, int64_t b)
Greatest common divisor.
Definition vlc_common.h:557
static uint8_t clip_uint8_vlc(int32_t a)
Definition vlc_common.h:570
static size_t vlc_align(size_t v, size_t align)
Make integer v a multiple of align.
Definition vlc_common.h:542
static bool umulll_overflow(unsigned long long a, unsigned long long b, unsigned long long *res)
Definition vlc_common.h:851
static bool uaddll_overflow(unsigned long long a, unsigned long long b, unsigned long long *res)
Definition vlc_common.h:777
static bool umull_overflow(unsigned long a, unsigned long b, unsigned long *res)
Definition vlc_common.h:840
#define add_overflow(a, b, r)
Overflowing addition.
Definition vlc_common.h:802
static bool umul_overflow(unsigned a, unsigned b, unsigned *res)
Definition vlc_common.h:830
static bool uadd_overflow(unsigned a, unsigned b, unsigned *res)
Definition vlc_common.h:756
#define mul_overflow(a, b, r)
Overflowing multiplication.
Definition vlc_common.h:876
static bool uaddl_overflow(unsigned long a, unsigned long b, unsigned long *res)
Definition vlc_common.h:766
Definition vlc_addons.h:73
Audio output object.
Definition vlc_aout.h:155
Definition vlc_config_cat.h:152
Definition vlc_configuration.h:340
Timestamps without long-term rounding errors.
Definition vlc_tick.h:238
Definition vlc_codec.h:102
Definition vlc_codec.h:255
Definition vlc_es_out.h:140
Structure describing a filter.
Definition vlc_filter.h:213
Definition vlc_image.h:40
Definition vlc_input_item.h:55
Definition vlc_input_item.h:46
Definition vlc_iso_lang.h:31
Definition vlc_objects.h:103
Configuration item.
Definition vlc_configuration.h:70
Internal module descriptor.
Definition modules.h:76
Video picture.
Definition vlc_picture.h:128
Definition vlc_input.h:51
Main service discovery structure to build a SD module.
Definition vlc_services_discovery.h:60
Stream output access_output.
Definition vlc_sout.h:56
Muxer structure.
Definition vlc_sout.h:104
Definition vlc_sout.h:274
Subpicture unit descriptor.
Definition vlc_spu.h:51
stream_t definition
Definition vlc_stream.h:135
Video subtitle region.
Definition vlc_subpicture.h:71
Video subtitle.
Definition vlc_subpicture.h:248
The update object.
Definition update.h:159
Opaque structure representing an ES (Elementary Stream) track.
Definition es_out.c:105
Internal state for block queues.
Definition fifo.c:39
Definition vlc_frame.h:122
MD5 hash context.
Definition vlc_hash.h:86
VLC object common members.
Definition vlc_objects.h:53
Definition fourcc_gen.c:34
Definition vlc_renderer_discovery.h:170
Definition renderer_discovery.c:36
Viewpoints.
Definition vlc_viewpoint.h:41
Definition vlm_internal.h:76
Video output thread descriptor.
Definition vlc_vout.h:54
static void * xrealloc(void *ptr, size_t len)
Definition vlc_common.h:1112
static void SetDWBE(void *p, uint32_t dw)
Writes 32 bits in network byte order.
Definition vlc_common.h:1006
static uint32_t GetDWLE(const void *p)
Reads 32 bits in little-endian order.
Definition vlc_common.h:974
static void SetWLE(void *p, uint16_t w)
Writes 16 bits in little endian order.
Definition vlc_common.h:1020
#define hton16(i)
Definition vlc_common.h:917
const char * VLC_CompileHost(void)
Definition version.c:44
audio_format_t audio_sample_format_t
Definition vlc_common.h:402
static uint32_t U32_AT(const void *p)
Reads 32 bits in network byte order.
Definition vlc_common.h:937
static uint16_t U16_AT(const void *p)
Reads 16 bits in network byte order.
Definition vlc_common.h:927
static char * xstrdup(const char *str)
Definition vlc_common.h:1120
static void SetDWLE(void *p, uint32_t dw)
Writes 32 bits in little endian order.
Definition vlc_common.h:1029
#define hton64(i)
Definition vlc_common.h:919
#define ntoh32(i)
Definition vlc_common.h:922
struct vod_t vod_t
Definition vlc_common.h:459
static void SetWBE(void *p, uint16_t w)
Writes 16 bits in network byte order.
Definition vlc_common.h:999
static void * vlc_reallocarray(void *ptr, size_t count, size_t size)
Definition vlc_common.h:1079
static uint64_t U64_AT(const void *p)
Reads 64 bits in network byte order.
Definition vlc_common.h:947
const char * VLC_Compiler(void)
Definition version.c:45
struct vod_media_t vod_media_t
Definition vlc_common.h:460
const char * vlc_gettext(const char *msgid)
In-tree plugins share their gettext domain with LibVLC.
Definition textdomain.c:80
static uint64_t GetQWLE(const void *p)
Reads 64 bits in little-endian order.
Definition vlc_common.h:987
bool vlc_ureduce(unsigned *, unsigned *, uint64_t, uint64_t, uint64_t)
static void SetQWBE(void *p, uint64_t qw)
Writes 64 bits in network byte order.
Definition vlc_common.h:1013
static void * xmalloc(size_t len)
Definition vlc_common.h:1104
video_format_t video_frame_format_t
Definition vlc_common.h:408
static void * vlc_alloc(size_t count, size_t size)
Definition vlc_common.h:1073
static void SetQWLE(void *p, uint64_t qw)
Writes 64 bits in little endian order.
Definition vlc_common.h:1038
#define hton32(i)
Definition vlc_common.h:918
const char * vlc_ngettext(const char *s, const char *p, unsigned long n)
Definition textdomain.c:89
static const char * vlc_pgettext_aux(const char *ctx, const char *id)
Definition vlc_common.h:1095
const char * VLC_CompileBy(void)
Definition version.c:43
#define ntoh64(i)
Definition vlc_common.h:923
uint32_t vlc_fourcc_t
The vlc_fourcc_t type.
Definition vlc_common.h:328
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:353
static uint16_t GetWLE(const void *p)
Reads 16 bits in little-endian order.
Definition vlc_common.h:961
#define ntoh16(i)
Definition vlc_common.h:921
This file defines of values used in interface, vout, aout and vlc core functions.
char * strdup(const char *)
Common VLC object definitions.
VLC object variables and callbacks interface.