[FFmpeg-devel] [PATCH] lavu/rational: add syntactic sugar.

Nicolas George george at nsup.org
Tue Dec 31 17:24:21 CET 2013


Add a function to create a rational
and macros for common values.

Signed-off-by: Nicolas George <george at nsup.org>
---
 libavutil/rational.h |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/libavutil/rational.h b/libavutil/rational.h
index b9800ee..363d18c 100644
--- a/libavutil/rational.h
+++ b/libavutil/rational.h
@@ -46,6 +46,22 @@ typedef struct AVRational{
 } AVRational;
 
 /**
+ * Create a rational.
+ * Useful for compilers that do not support compound literals.
+ * @note  The return value is not reduced.
+ */
+static inline AVRational av_make_q(int num, int den)
+{
+    AVRational r = { num, den };
+    return r;
+}
+
+#define AV_ZERO_Q         (av_make_q(0, 1))
+#define AV_ONE_Q          (av_make_q(1, 1))
+#define AV_UNDEF_Q        (av_make_q(1, 0))
+#define AV_INVALID_Q      (av_make_q(0, 0))
+
+/**
  * Compare two rationals.
  * @param a first rational
  * @param b second rational
-- 
1.7.10.4



More information about the ffmpeg-devel mailing list