[gst-cvs] gstreamer: utils: move common correction code in a macro
Wim Taymans
wtay at kemper.freedesktop.org
Fri Aug 28 03:46:03 PDT 2009
Module: gstreamer
Branch: master
Commit: 2b66b29355662f5beb98602917057b69d4a613b8
URL: http://cgit.freedesktop.org/gstreamer/gstreamer/commit/?id=2b66b29355662f5beb98602917057b69d4a613b8
Author: Wim Taymans <wim.taymans at collabora.co.uk>
Date: Fri Aug 28 12:19:34 2009 +0200
utils: move common correction code in a macro
---
gst/gstutils.c | 44 ++++++++++++++++----------------------------
1 files changed, 16 insertions(+), 28 deletions(-)
diff --git a/gst/gstutils.c b/gst/gstutils.c
index ff46eec..390c8b7 100644
--- a/gst/gstutils.c
+++ b/gst/gstutils.c
@@ -349,6 +349,18 @@ gst_util_div96_32 (guint64 c1, guint64 c0, guint32 denom)
return ((c1 / denom) << 32) + (c0 / denom);
}
+/* add correction with carry */
+#define CORRECT(c0,c1,val) \
+ if (val) { \
+ if (G_MAXUINT64 - c0.ll < val) { \
+ if (G_UNLIKELY (c1.ll == G_MAXUINT64)) \
+ /* overflow */ \
+ return G_MAXUINT64; \
+ c1.ll++; \
+ } \
+ c0.ll += val; \
+ }
+
static guint64
gst_util_uint64_scale_uint64_unchecked (guint64 val, guint64 num,
guint64 denom, GstRoundingMode mode)
@@ -362,24 +374,12 @@ gst_util_uint64_scale_uint64_unchecked (guint64 val, guint64 num,
switch (mode) {
case GST_ROUND_TONEAREST:
/* add 1/2 the denominator to the numerator with carry */
- if (G_MAXUINT64 - c0.ll < denom / 2) {
- if (G_UNLIKELY (c1.ll == G_MAXUINT64))
- /* overflow */
- return G_MAXUINT64;
- c1.ll++;
- }
- c0.ll += denom / 2;
+ CORRECT (c0, c1, denom / 2);
break;
case GST_ROUND_UP:
/* add denominator - 1 to the numerator with carry */
- if (G_MAXUINT64 - c0.ll < denom - 1) {
- if (G_UNLIKELY (c1.ll == G_MAXUINT64))
- /* overflow */
- return G_MAXUINT64;
- c1.ll++;
- }
- c0.ll += denom - 1;
+ CORRECT (c0, c1, denom - 1);
break;
case GST_ROUND_DOWN:
@@ -408,24 +408,12 @@ gst_util_uint64_scale_uint32_unchecked (guint64 val, guint32 num,
switch (mode) {
case GST_ROUND_TONEAREST:
/* add 1/2 the denominator to the numerator with carry */
- if (G_MAXUINT64 - c0.ll < denom / 2) {
- if (G_UNLIKELY (c1.ll == G_MAXUINT64))
- /* overflow */
- return G_MAXUINT64;
- c1.ll++;
- }
- c0.ll += denom / 2;
+ CORRECT (c0, c1, denom / 2);
break;
case GST_ROUND_UP:
/* add denominator - 1 to the numerator with carry */
- if (G_MAXUINT64 - c0.ll < denom - 1) {
- if (G_UNLIKELY (c1.ll == G_MAXUINT64))
- /* overflow */
- return G_MAXUINT64;
- c1.ll++;
- }
- c0.ll += denom - 1;
+ CORRECT (c0, c1, denom - 1);
break;
case GST_ROUND_DOWN:
More information about the Gstreamer-commits
mailing list