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# define unreachable() __builtin_unreachable()
225#elif defined(_MSC_VER)
226# define likely(p) (!!(p))
227# define unlikely(p) (!!(p))
228# define unreachable() (__assume(0))
237# define likely(p) (!!(p))
246# define unlikely(p) (!!(p))
258# define unreachable() ((void)0)
272#define vlc_assert_unreachable() (vlc_assert(!"unreachable"), unreachable())
287#ifdef LIBVLC_INTERNAL_
288# define vlc_assert(pred) assert(pred)
290# define vlc_assert(pred) ((void)0)
295# define VLC_EXTERN extern "C"
300#if defined (_WIN32) && defined (VLC_DLL_EXPORT)
301# define VLC_EXPORT __declspec(dllexport)
302#elif defined (__GNUC__)
303# define VLC_EXPORT __attribute__((visibility("default")))
314#define VLC_API VLC_EXTERN VLC_EXPORT
328#ifdef WORDS_BIGENDIAN
329# define VLC_FOURCC( a, b, c, d ) \
330 ( ((uint32_t)d) | ( ((uint32_t)c) << 8 ) \
331 | ( ((uint32_t)b) << 16 ) | ( ((uint32_t)a) << 24 ) )
332# define VLC_TWOCC( a, b ) \
333 ( (uint16_t)(b) | ( (uint16_t)(a) << 8 ) )
336# define VLC_FOURCC( a, b, c, d ) \
337 ( ((uint32_t)a) | ( ((uint32_t)b) << 8 ) \
338 | ( ((uint32_t)c) << 16 ) | ( ((uint32_t)d) << 24 ) )
339# define VLC_TWOCC( a, b ) \
340 ( (uint16_t)(a) | ( (uint16_t)(b) << 8 ) )
353 memcpy( psz_fourcc, &fcc, 4 );
480#define VLC_EGENERIC (-2 * (1 << (sizeof (int) * 8 - 2)))
482#define VLC_ENOMEM (-ENOMEM)
484#define VLC_ETIMEOUT (-ETIMEDOUT)
486#define VLC_ENOENT (-ENOENT)
488#define VLC_EINVAL (-EINVAL)
490#define VLC_EACCES (-EACCES)
492#define VLC_ENOTSUP (-ENOTSUP)
504#include <sys/syslimits.h>
505#include <AvailabilityMacros.h>
509# define OS2EMX_PLAIN_CHAR
525# define __MAX(a, b) ( ((a) > (b)) ? (a) : (b) )
528# define __MIN(a, b) ( ((a) < (b)) ? (a) : (b) )
532#define VLC_CLIP(v, min, max) __MIN(__MAX((v), (min)), (max))
542 return (v + (align - 1)) & ~(align - 1);
545#if defined __has_attribute
546# if __has_attribute(diagnose_if)
547static inline size_t vlc_align(
size_t v,
size_t align)
548 __attribute__((diagnose_if(((align & (align - 1)) || (align == 0)),
549 "align must be power of 2",
"error")));
555static inline int64_t
GCD ( int64_t a, int64_t b )
570 if( a&(~255) )
return (-a)>>31;
579#define VLC_INT_FUNC(basename) \
580 VLC_INT_FUNC_TYPE(basename, unsigned, ) \
581 VLC_INT_FUNC_TYPE(basename, unsigned long, l) \
582 VLC_INT_FUNC_TYPE(basename, unsigned long long, ll)
584#if defined (__GNUC__) || defined (__clang__)
585# define VLC_INT_FUNC_TYPE(basename,type,suffix) \
586VLC_USED static inline int vlc_##basename##suffix(type x) \
588 return __builtin_##basename##suffix(x); \
593 unsigned i =
sizeof (x) * 8;
605 for (
unsigned i = 4 *
sizeof (x); i > 0; i /= 2)
621# define VLC_INT_FUNC_TYPE(basename,type,suffix) \
622VLC_USED static inline int vlc_##basename##suffix(type x) \
624 return vlc_##basename##_generic(x); \
633# define VLC_INT_GENERIC(func,x) \
635 unsigned char: func(x), \
636 signed char: func(x), \
637 unsigned short: func(x), \
638 signed short: func(x), \
639 unsigned int: func(x), \
640 signed int: func(x), \
641 unsigned long: func##l(x), \
642 signed long: func##l(x), \
643 unsigned long long: func##ll(x), \
644 signed long long: func##ll(x))
656# define ctz(x) VLC_INT_GENERIC(vlc_ctz, x)
665# define parity(x) VLC_INT_GENERIC(vlc_parity, x)
674# define vlc_popcount(x) \
676 signed char: vlc_popcount((unsigned char)(x)), \
677 signed short: vlc_popcount((unsigned short)(x)), \
678 default: VLC_INT_GENERIC(vlc_popcount ,x))
705 return (x << 8) | (x >> 8);
712#if defined (__GNUC__) || defined(__clang__)
713 return __builtin_bswap32 (x);
715 return ((x & 0x000000FF) << 24)
716 | ((x & 0x0000FF00) << 8)
717 | ((x & 0x00FF0000) >> 8)
718 | ((x & 0xFF000000) >> 24);
726#if defined (__GNUC__) || defined(__clang__)
727 return __builtin_bswap64 (x);
728#elif !defined (__cplusplus)
729 return ((x & 0x00000000000000FF) << 56)
730 | ((x & 0x000000000000FF00) << 40)
731 | ((x & 0x0000000000FF0000) << 24)
732 | ((x & 0x00000000FF000000) << 8)
733 | ((x & 0x000000FF00000000) >> 8)
734 | ((x & 0x0000FF0000000000) >> 24)
735 | ((x & 0x00FF000000000000) >> 40)
736 | ((x & 0xFF00000000000000) >> 56);
738 return ((x & 0x00000000000000FFULL) << 56)
739 | ((x & 0x000000000000FF00ULL) << 40)
740 | ((x & 0x0000000000FF0000ULL) << 24)
741 | ((x & 0x00000000FF000000ULL) << 8)
742 | ((x & 0x000000FF00000000ULL) >> 8)
743 | ((x & 0x0000FF0000000000ULL) >> 24)
744 | ((x & 0x00FF000000000000ULL) >> 40)
745 | ((x & 0xFF00000000000000ULL) >> 56);
756#if defined(__GNUC__) || defined(__clang__)
757 return __builtin_uadd_overflow(a, b, res);
767#if defined(__GNUC__) || defined(__clang__)
768 return __builtin_uaddl_overflow(a, b, res);
776 unsigned long long *res)
778#if defined(__GNUC__) || defined(__clang__)
779 return __builtin_uaddll_overflow(a, b, res);
800# define add_overflow(a,b,r) \
802 unsigned: uadd_overflow(a, b, (unsigned *)(r)), \
803 unsigned long: uaddl_overflow(a, b, (unsigned long *)(r)), \
804 unsigned long long: uaddll_overflow(a, b, (unsigned long long *)(r)))
806static inline bool add_overflow(
unsigned a,
unsigned b,
unsigned *res)
811static inline bool add_overflow(
unsigned long a,
unsigned long b,
817static inline bool add_overflow(
unsigned long long a,
unsigned long long b,
818 unsigned long long *res)
824#if !(defined(__GNUC__) || defined(__clang__))
830#if defined(__GNUC__) || defined(__clang__)
831 return __builtin_umul_overflow(a, b, res);
834 return b > 0 && a > (UINT_MAX / b);
841#if defined(__GNUC__) || defined(__clang__)
842 return __builtin_umull_overflow(a, b, res);
845 return b > 0 && a > (ULONG_MAX / b);
850 unsigned long long *res)
852#if defined(__GNUC__) || defined(__clang__)
853 return __builtin_umulll_overflow(a, b, res);
856 return b > 0 && a > (ULLONG_MAX / b);
874#define mul_overflow(a,b,r) \
876 unsigned: umul_overflow(a, b, (unsigned *)(r)), \
877 unsigned long: umull_overflow(a, b, (unsigned long *)(r)), \
878 unsigned long long: umulll_overflow(a, b, (unsigned long long *)(r)))
880static inline bool mul_overflow(
unsigned a,
unsigned b,
unsigned *res)
885static inline bool mul_overflow(
unsigned long a,
unsigned long b,
891static inline bool mul_overflow(
unsigned long long a,
unsigned long long b,
892 unsigned long long *res)
901#define FREENULL(a) do { free( a ); a = NULL; } while(0)
903#define EMPTY_STR(str) (!str || !*str)
905#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
910#ifdef WORDS_BIGENDIAN
911# define hton16(i) ((uint16_t)(i))
912# define hton32(i) ((uint32_t)(i))
913# define hton64(i) ((uint64_t)(i))
915# define hton16(i) vlc_bswap16(i)
916# define hton32(i) vlc_bswap32(i)
917# define hton64(i) vlc_bswap64(i)
919#define ntoh16(i) hton16(i)
920#define ntoh32(i) hton32(i)
921#define ntoh64(i) hton64(i)
929 memcpy (&x,
p,
sizeof (x));
939 memcpy (&x,
p,
sizeof (x));
949 memcpy (&x,
p,
sizeof (x));
953#define GetWBE(p) U16_AT(p)
954#define GetDWBE(p) U32_AT(p)
955#define GetQWBE(p) U64_AT(p)
963 memcpy (&x,
p,
sizeof (x));
964#ifdef WORDS_BIGENDIAN
976 memcpy (&x,
p,
sizeof (x));
977#ifdef WORDS_BIGENDIAN
989 memcpy (&x,
p,
sizeof (x));
990#ifdef WORDS_BIGENDIAN
997static inline void SetWBE (
void *
p, uint16_t w)
1000 memcpy (
p, &w,
sizeof (w));
1007 memcpy (
p, &dw,
sizeof (dw));
1014 memcpy (
p, &qw,
sizeof (qw));
1020#ifdef WORDS_BIGENDIAN
1023 memcpy (
p, &w,
sizeof (w));
1029#ifdef WORDS_BIGENDIAN
1032 memcpy (
p, &dw,
sizeof (dw));
1038#ifdef WORDS_BIGENDIAN
1041 memcpy (
p, &qw,
sizeof (qw));
1045#define VLC_UNUSED(x) (void)(x)
1052# define O_NONBLOCK 0
1057# define swab(a,b,c) _swab((char*) (a), (char*) (b), (c))
1067#define container_of(ptr, type, member) \
1068 ((type *)(((char *)(ptr)) - offsetof(type, member)))
1089#define vlc_pgettext( ctx, id ) \
1090 vlc_pgettext_aux( ctx "\004" id, id )
1096 return (tr == ctx) ? id : tr;
1104 void *ptr = malloc(len);
1105 if (
unlikely(ptr == NULL && len > 0))
1112 void *nptr = realloc(ptr, len);
1113 if (
unlikely(nptr == NULL && len > 0))
1120 char *ptr =
strdup (str);
1140#if defined( _WIN32 ) || defined( __OS2__ )
1141# define DIR_SEP_CHAR '\\'
1142# define DIR_SEP "\\"
1143# define PATH_SEP_CHAR ';'
1144# define PATH_SEP ";"
1146# define DIR_SEP_CHAR '/'
1148# define PATH_SEP_CHAR ':'
1149# define PATH_SEP ":"
1152#define LICENSE_MSG \
1153 _("This program comes with NO WARRANTY, to the extent permitted by " \
1154 "law.\nYou may redistribute it under the terms of the GNU General " \
1155 "Public License;\nsee the file named COPYING for details.\n" \
1156 "Written by the VideoLAN team; see the AUTHORS file.\n")
1158#if defined(__cplusplus) || defined(_MSC_VER)
1159#define ARRAY_STATIC_SIZE
1161#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:710
#define ctz(x)
Count trailing zeroes.
Definition vlc_common.h:656
#define vlc_popcount(x)
Bit weight / population count.
Definition vlc_common.h:674
static int vlc_popcountl(unsigned long x)
Definition vlc_common.h:630
#define parity(x)
Parity.
Definition vlc_common.h:665
static uint64_t vlc_bswap64(uint64_t x)
Byte swap (64 bits)
Definition vlc_common.h:724
static int vlc_parity_generic(unsigned long long x)
Definition vlc_common.h:603
static int vlc_popcountll(unsigned long long x)
Definition vlc_common.h:630
static int vlc_popcount_generic(unsigned long long x)
Definition vlc_common.h:610
static int vlc_ctz_generic(unsigned long long x)
Definition vlc_common.h:591
static uint16_t vlc_bswap16(uint16_t x)
Byte swap (16 bits)
Definition vlc_common.h:703
#define VLC_INT_FUNC(basename)
Definition vlc_common.h:579
#define unlikely(p)
Predicted false condition.
Definition vlc_common.h:246
#define VLC_USED
Definition vlc_common.h:156
#define VLC_API
Exported API call annotation.
Definition vlc_common.h:314
#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:555
static uint8_t clip_uint8_vlc(int32_t a)
Definition vlc_common.h:568
static size_t vlc_align(size_t v, size_t align)
Make integer v a multiple of align.
Definition vlc_common.h:540
static bool umulll_overflow(unsigned long long a, unsigned long long b, unsigned long long *res)
Definition vlc_common.h:849
static bool uaddll_overflow(unsigned long long a, unsigned long long b, unsigned long long *res)
Definition vlc_common.h:775
static bool umull_overflow(unsigned long a, unsigned long b, unsigned long *res)
Definition vlc_common.h:838
#define add_overflow(a, b, r)
Overflowing addition.
Definition vlc_common.h:800
static bool umul_overflow(unsigned a, unsigned b, unsigned *res)
Definition vlc_common.h:828
static bool uadd_overflow(unsigned a, unsigned b, unsigned *res)
Definition vlc_common.h:754
#define mul_overflow(a, b, r)
Overflowing multiplication.
Definition vlc_common.h:874
static bool uaddl_overflow(unsigned long a, unsigned long b, unsigned long *res)
Definition vlc_common.h:764
Definition vlc_addons.h:73
Audio output object.
Definition vlc_aout.h:155
Definition vlc_config_cat.h:152
Definition vlc_configuration.h:320
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:138
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:130
Definition vlc_input.h:52
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:52
stream_t definition
Definition vlc_stream.h:135
Video subtitle region.
Definition vlc_subpicture.h:72
Video subtitle.
Definition vlc_subpicture.h:234
The update object.
Definition update.h:159
Opaque structure representing an ES (Elementary Stream) track.
Definition es_out.c:104
Internal state for block queues.
Definition fifo.c:39
Definition vlc_frame.h:123
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:1110
static void SetDWBE(void *p, uint32_t dw)
Writes 32 bits in network byte order.
Definition vlc_common.h:1004
static uint32_t GetDWLE(const void *p)
Reads 32 bits in little-endian order.
Definition vlc_common.h:972
static void SetWLE(void *p, uint16_t w)
Writes 16 bits in little endian order.
Definition vlc_common.h:1018
#define hton16(i)
Definition vlc_common.h:915
const char * VLC_CompileHost(void)
Definition version.c:44
audio_format_t audio_sample_format_t
Definition vlc_common.h:400
static uint32_t U32_AT(const void *p)
Reads 32 bits in network byte order.
Definition vlc_common.h:935
static uint16_t U16_AT(const void *p)
Reads 16 bits in network byte order.
Definition vlc_common.h:925
static char * xstrdup(const char *str)
Definition vlc_common.h:1118
static void SetDWLE(void *p, uint32_t dw)
Writes 32 bits in little endian order.
Definition vlc_common.h:1027
#define hton64(i)
Definition vlc_common.h:917
#define ntoh32(i)
Definition vlc_common.h:920
struct vod_t vod_t
Definition vlc_common.h:457
static void SetWBE(void *p, uint16_t w)
Writes 16 bits in network byte order.
Definition vlc_common.h:997
static void * vlc_reallocarray(void *ptr, size_t count, size_t size)
Definition vlc_common.h:1077
static uint64_t U64_AT(const void *p)
Reads 64 bits in network byte order.
Definition vlc_common.h:945
const char * VLC_Compiler(void)
Definition version.c:45
struct vod_media_t vod_media_t
Definition vlc_common.h:458
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:985
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:1011
static void * xmalloc(size_t len)
Definition vlc_common.h:1102
video_format_t video_frame_format_t
Definition vlc_common.h:406
static void * vlc_alloc(size_t count, size_t size)
Definition vlc_common.h:1071
static void SetQWLE(void *p, uint64_t qw)
Writes 64 bits in little endian order.
Definition vlc_common.h:1036
#define hton32(i)
Definition vlc_common.h:916
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:1093
const char * VLC_CompileBy(void)
Definition version.c:43
#define ntoh64(i)
Definition vlc_common.h:921
uint32_t vlc_fourcc_t
The vlc_fourcc_t type.
Definition vlc_common.h:326
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:351
static uint16_t GetWLE(const void *p)
Reads 16 bits in little-endian order.
Definition vlc_common.h:959
#define ntoh16(i)
Definition vlc_common.h:919
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.