summaryrefslogtreecommitdiff
path: root/chromium/third_party/ffmpeg/libavutil/common.h
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-12 14:27:29 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-13 09:35:20 +0000
commitc30a6232df03e1efbd9f3b226777b07e087a1122 (patch)
treee992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/third_party/ffmpeg/libavutil/common.h
parent7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff)
downloadqtwebengine-chromium-85-based.tar.gz
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/third_party/ffmpeg/libavutil/common.h')
-rw-r--r--chromium/third_party/ffmpeg/libavutil/common.h46
1 files changed, 46 insertions, 0 deletions
diff --git a/chromium/third_party/ffmpeg/libavutil/common.h b/chromium/third_party/ffmpeg/libavutil/common.h
index 142ff9abe7e..2777cea9f9b 100644
--- a/chromium/third_party/ffmpeg/libavutil/common.h
+++ b/chromium/third_party/ffmpeg/libavutil/common.h
@@ -292,6 +292,46 @@ static av_always_inline int av_sat_dsub32_c(int a, int b)
}
/**
+ * Add two signed 64-bit values with saturation.
+ *
+ * @param a one value
+ * @param b another value
+ * @return sum with signed saturation
+ */
+static av_always_inline int64_t av_sat_add64_c(int64_t a, int64_t b) {
+#if (!defined(__INTEL_COMPILER) && AV_GCC_VERSION_AT_LEAST(5,1)) || AV_HAS_BUILTIN(__builtin_add_overflow)
+ int64_t tmp;
+ return !__builtin_add_overflow(a, b, &tmp) ? tmp : (tmp < 0 ? INT64_MAX : INT64_MIN);
+#else
+ if (b >= 0 && a >= INT64_MAX - b)
+ return INT64_MAX;
+ if (b <= 0 && a <= INT64_MIN - b)
+ return INT64_MIN;
+ return a + b;
+#endif
+}
+
+/**
+ * Subtract two signed 64-bit values with saturation.
+ *
+ * @param a one value
+ * @param b another value
+ * @return difference with signed saturation
+ */
+static av_always_inline int64_t av_sat_sub64_c(int64_t a, int64_t b) {
+#if (!defined(__INTEL_COMPILER) && AV_GCC_VERSION_AT_LEAST(5,1)) || AV_HAS_BUILTIN(__builtin_sub_overflow)
+ int64_t tmp;
+ return !__builtin_sub_overflow(a, b, &tmp) ? tmp : (tmp < 0 ? INT64_MAX : INT64_MIN);
+#else
+ if (b <= 0 && a >= INT64_MAX + b)
+ return INT64_MAX;
+ if (b >= 0 && a <= INT64_MIN + b)
+ return INT64_MIN;
+ return a - b;
+#endif
+}
+
+/**
* Clip a float value into the amin-amax range.
* @param a value to clip
* @param amin minimum value of the clip range
@@ -545,6 +585,12 @@ static av_always_inline av_const int av_parity_c(uint32_t v)
#ifndef av_sat_dsub32
# define av_sat_dsub32 av_sat_dsub32_c
#endif
+#ifndef av_sat_add64
+# define av_sat_add64 av_sat_add64_c
+#endif
+#ifndef av_sat_sub64
+# define av_sat_sub64 av_sat_sub64_c
+#endif
#ifndef av_clipf
# define av_clipf av_clipf_c
#endif