summaryrefslogtreecommitdiff
path: root/libavutil/macros.h
diff options
context:
space:
mode:
authorAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-07-23 18:52:27 +0200
committerAndreas Rheinhardt <andreas.rheinhardt@outlook.com>2021-07-29 22:02:05 +0200
commit2dd8acbe800f6ea3b72ebe730f8ed95a5c3dd407 (patch)
treeba5e38d364e6ad272ee5e0ffd26d5b96ba064a92 /libavutil/macros.h
parentfd101c9c3bcdeb2d74274aaeaa968fe8ead3622d (diff)
downloadffmpeg-2dd8acbe800f6ea3b72ebe730f8ed95a5c3dd407.tar.gz
avutil/common, macros: Move several macros from common.h to macros.h
common.h currently contains several things: Math macros, UTF-8 macros, other fundamental macros; furthermore it also contains miscellaneous math functions and it (directly and indirectly) includes lots of other headers. This commit moves the "other fundamental macros" to macros.h which is a more fitting place. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Diffstat (limited to 'libavutil/macros.h')
-rw-r--r--libavutil/macros.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/libavutil/macros.h b/libavutil/macros.h
index 2007ee5619..2a7567c3ea 100644
--- a/libavutil/macros.h
+++ b/libavutil/macros.h
@@ -25,6 +25,36 @@
#ifndef AVUTIL_MACROS_H
#define AVUTIL_MACROS_H
+#include "libavutil/avconfig.h"
+
+#if AV_HAVE_BIGENDIAN
+# define AV_NE(be, le) (be)
+#else
+# define AV_NE(be, le) (le)
+#endif
+
+/**
+ * Comparator.
+ * For two numerical expressions x and y, gives 1 if x > y, -1 if x < y, and 0
+ * if x == y. This is useful for instance in a qsort comparator callback.
+ * Furthermore, compilers are able to optimize this to branchless code, and
+ * there is no risk of overflow with signed types.
+ * As with many macros, this evaluates its argument multiple times, it thus
+ * must not have a side-effect.
+ */
+#define FFDIFFSIGN(x,y) (((x)>(y)) - ((x)<(y)))
+
+#define FFMAX(a,b) ((a) > (b) ? (a) : (b))
+#define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c)
+#define FFMIN(a,b) ((a) > (b) ? (b) : (a))
+#define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c)
+
+#define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0)
+#define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0]))
+
+#define MKTAG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((unsigned)(d) << 24))
+#define MKBETAG(a,b,c,d) ((d) | ((c) << 8) | ((b) << 16) | ((unsigned)(a) << 24))
+
/**
* @addtogroup preproc_misc Preprocessor String Macros
*