summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas George <george@nsup.org>2020-04-16 21:36:00 +0200
committerNicolas George <george@nsup.org>2020-05-23 15:51:44 +0200
commit6b65c4ec54511871f345cfa76a499fa65d94c0b8 (patch)
tree189dc349ae343acf78b1b05de630a0bfb200b545
parentbeb98c0181b70c0d32cf19efe2a78d2c397b2508 (diff)
lavu: add av_gcd_q().
-rw-r--r--doc/APIchanges3
-rw-r--r--libavutil/rational.c9
-rw-r--r--libavutil/rational.h6
-rw-r--r--libavutil/version.h4
4 files changed, 20 insertions, 2 deletions
diff --git a/doc/APIchanges b/doc/APIchanges
index 34ca7ec1bb..b3de5df0b6 100644
--- a/doc/APIchanges
+++ b/doc/APIchanges
@@ -15,6 +15,9 @@ libavutil: 2017-10-21
API changes, most recent first:
+2020-05-23 - xxxxxxxxxx - lavu 56.47.100 - rational.h
+ Add av_gcd_q().
+
2020-05-22 - xxxxxxxxxx - lavu 56.46.101 - opt.h
Add AV_OPT_FLAG_CHILD_CONSTS.
diff --git a/libavutil/rational.c b/libavutil/rational.c
index 35ee08877f..eb148ddb12 100644
--- a/libavutil/rational.c
+++ b/libavutil/rational.c
@@ -182,3 +182,12 @@ uint32_t av_q2intfloat(AVRational q) {
return sign<<31 | (150-shift)<<23 | (n - (1<<23));
}
+
+AVRational av_gcd_q(AVRational a, AVRational b, int max_den, AVRational def)
+{
+ int64_t gcd, lcm;
+
+ gcd = av_gcd(a.den, b.den);
+ lcm = (a.den / gcd) * b.den;
+ return lcm < max_den ? av_make_q(av_gcd(a.num, b.num), lcm) : def;
+}
diff --git a/libavutil/rational.h b/libavutil/rational.h
index 5c6b67b4e9..cbb08a0baf 100644
--- a/libavutil/rational.h
+++ b/libavutil/rational.h
@@ -208,6 +208,12 @@ int av_find_nearest_q_idx(AVRational q, const AVRational* q_list);
uint32_t av_q2intfloat(AVRational q);
/**
+ * Return the best rational so that a and b are multiple of it.
+ * If the resulting denominator is larger than max_den, return def.
+ */
+AVRational av_gcd_q(AVRational a, AVRational b, int max_den, AVRational def);
+
+/**
* @}
*/
diff --git a/libavutil/version.h b/libavutil/version.h
index 20085dfde9..f63cd4ba79 100644
--- a/libavutil/version.h
+++ b/libavutil/version.h
@@ -79,8 +79,8 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 56
-#define LIBAVUTIL_VERSION_MINOR 46
-#define LIBAVUTIL_VERSION_MICRO 101
+#define LIBAVUTIL_VERSION_MINOR 47
+#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \
LIBAVUTIL_VERSION_MINOR, \