mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-18 22:36:33 +00:00
utils: move common correction code in a macro
This commit is contained in:
parent
378594e520
commit
2b66b29355
1 changed files with 16 additions and 28 deletions
|
@ -349,6 +349,18 @@ gst_util_div96_32 (guint64 c1, guint64 c0, guint32 denom)
|
||||||
return ((c1 / denom) << 32) + (c0 / 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
|
static guint64
|
||||||
gst_util_uint64_scale_uint64_unchecked (guint64 val, guint64 num,
|
gst_util_uint64_scale_uint64_unchecked (guint64 val, guint64 num,
|
||||||
guint64 denom, GstRoundingMode mode)
|
guint64 denom, GstRoundingMode mode)
|
||||||
|
@ -362,24 +374,12 @@ gst_util_uint64_scale_uint64_unchecked (guint64 val, guint64 num,
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case GST_ROUND_TONEAREST:
|
case GST_ROUND_TONEAREST:
|
||||||
/* add 1/2 the denominator to the numerator with carry */
|
/* add 1/2 the denominator to the numerator with carry */
|
||||||
if (G_MAXUINT64 - c0.ll < denom / 2) {
|
CORRECT (c0, c1, denom / 2);
|
||||||
if (G_UNLIKELY (c1.ll == G_MAXUINT64))
|
|
||||||
/* overflow */
|
|
||||||
return G_MAXUINT64;
|
|
||||||
c1.ll++;
|
|
||||||
}
|
|
||||||
c0.ll += denom / 2;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GST_ROUND_UP:
|
case GST_ROUND_UP:
|
||||||
/* add denominator - 1 to the numerator with carry */
|
/* add denominator - 1 to the numerator with carry */
|
||||||
if (G_MAXUINT64 - c0.ll < denom - 1) {
|
CORRECT (c0, c1, denom - 1);
|
||||||
if (G_UNLIKELY (c1.ll == G_MAXUINT64))
|
|
||||||
/* overflow */
|
|
||||||
return G_MAXUINT64;
|
|
||||||
c1.ll++;
|
|
||||||
}
|
|
||||||
c0.ll += denom - 1;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GST_ROUND_DOWN:
|
case GST_ROUND_DOWN:
|
||||||
|
@ -408,24 +408,12 @@ gst_util_uint64_scale_uint32_unchecked (guint64 val, guint32 num,
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
case GST_ROUND_TONEAREST:
|
case GST_ROUND_TONEAREST:
|
||||||
/* add 1/2 the denominator to the numerator with carry */
|
/* add 1/2 the denominator to the numerator with carry */
|
||||||
if (G_MAXUINT64 - c0.ll < denom / 2) {
|
CORRECT (c0, c1, denom / 2);
|
||||||
if (G_UNLIKELY (c1.ll == G_MAXUINT64))
|
|
||||||
/* overflow */
|
|
||||||
return G_MAXUINT64;
|
|
||||||
c1.ll++;
|
|
||||||
}
|
|
||||||
c0.ll += denom / 2;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GST_ROUND_UP:
|
case GST_ROUND_UP:
|
||||||
/* add denominator - 1 to the numerator with carry */
|
/* add denominator - 1 to the numerator with carry */
|
||||||
if (G_MAXUINT64 - c0.ll < denom - 1) {
|
CORRECT (c0, c1, denom - 1);
|
||||||
if (G_UNLIKELY (c1.ll == G_MAXUINT64))
|
|
||||||
/* overflow */
|
|
||||||
return G_MAXUINT64;
|
|
||||||
c1.ll++;
|
|
||||||
}
|
|
||||||
c0.ll += denom - 1;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GST_ROUND_DOWN:
|
case GST_ROUND_DOWN:
|
||||||
|
|
Loading…
Reference in a new issue