From abddae152dd449f9d11d979ee7d4a9608e806978 Mon Sep 17 00:00:00 2001 From: Nicolas Dufresne Date: Tue, 14 Jan 2014 16:15:02 -0500 Subject: [PATCH] util: Add GST_ROUND_UP_N and GST_ROUND_DOWN_N These are generic rounding macro that works for any power of two. --- gst/gstutils.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/gst/gstutils.h b/gst/gstutils.h index 0dbaa00751..945add495b 100644 --- a/gst/gstutils.h +++ b/gst/gstutils.h @@ -822,6 +822,15 @@ GST_WRITE_DOUBLE_BE(guint8 *data, gdouble num) * Since: 1.4 */ #define GST_ROUND_UP_128(num) (((num)+127)&~127) +/** + * GST_ROUND_UP_N: + * @num: integrer value to round up + * @align: a power of two to round up to + * + * Rounds an integer value up to the next multiple of @align. @align MUST be a + * power of two. + */ +#define GST_ROUND_UP_N(num,align) ((((num) + ((align) - 1)) & ~((align) - 1))) /** @@ -874,6 +883,16 @@ GST_WRITE_DOUBLE_BE(guint8 *data, gdouble num) * Since: 1.4 */ #define GST_ROUND_DOWN_128(num) ((num)&(~127)) +/** + * GST_ROUND_DOWN_N: + * @num: integrer value to round down + * @align: a power of two to round down to + * + * Rounds an integer value down to the next multiple of @align. @align MUST be a + * power of two. + */ +#define GST_ROUND_DOWN_N(num,align) (((num) & ~((align) - 1))) + void gst_object_default_error (GstObject * source, const GError * error,