libs/gst/controller/: Use gst_guint64_to_gdouble() when converting from a uint64 or

Original commit message from CVS:
Patch by: Sebastien Moutte <sebastien at moutte dot net>
* libs/gst/controller/gstinterpolation.c:
* libs/gst/controller/gstlfocontrolsource.c:
Use gst_guint64_to_gdouble() when converting from a uint64 or
GstClockTime to double to fix the build on win32. Fixes #474371.
This commit is contained in:
Sebastien Moutte 2007-09-13 09:08:23 +00:00 committed by Sebastian Dröge
parent 93634c30c2
commit e332c34902
3 changed files with 105 additions and 92 deletions

View file

@ -1,3 +1,12 @@
2007-09-13 Sebastian Dröge <slomo@circular-chaos.org>
Patch by: Sebastien Moutte <sebastien at moutte dot net>
* libs/gst/controller/gstinterpolation.c:
* libs/gst/controller/gstlfocontrolsource.c:
Use gst_guint64_to_gdouble() when converting from a uint64 or
GstClockTime to double to fix the build on win32. Fixes #474371.
2007-09-13 Sebastian Dröge <slomo@circular-chaos.org>
* gst/gstbuffer.c: (gst_buffer_finalize):

View file

@ -31,6 +31,8 @@
#define GST_CAT_DEFAULT gst_controller_debug
GST_DEBUG_CATEGORY_EXTERN (GST_CAT_DEFAULT);
#define EMPTY(x) (x)
/* common helper */
/*
@ -533,7 +535,7 @@ static GstInterpolateMethod interpolate_trigger = {
/* linear interpolation */
/* smoothes inbetween values */
#define DEFINE_LINEAR_GET(type,round) \
#define DEFINE_LINEAR_GET(type,round,convert) \
static inline gboolean \
_interpolate_linear_get_##type (GstInterpolationControlSource *self, GstClockTime timestamp, g##type *ret) \
{ \
@ -551,12 +553,12 @@ _interpolate_linear_get_##type (GstInterpolationControlSource *self, GstClockTim
\
value1 = g_value_get_##type (&cp1->value); \
value2 = g_value_get_##type (&cp2->value); \
slope = (gdouble) (value2 - value1) / gst_guint64_to_gdouble (cp2->timestamp - cp1->timestamp); \
slope = (gdouble) convert (value2 - value1) / gst_guint64_to_gdouble (cp2->timestamp - cp1->timestamp); \
\
if (round) \
*ret = (g##type) (value1 + gst_guint64_to_gdouble (timestamp - cp1->timestamp) * slope + 0.5); \
*ret = (g##type) (convert (value1) + gst_guint64_to_gdouble (timestamp - cp1->timestamp) * slope + 0.5); \
else \
*ret = (g##type) (value1 + gst_guint64_to_gdouble (timestamp - cp1->timestamp) * slope); \
*ret = (g##type) (convert (value1) + gst_guint64_to_gdouble (timestamp - cp1->timestamp) * slope); \
} \
else { \
*ret = g_value_get_##type (&cp1->value); \
@ -606,16 +608,16 @@ interpolate_linear_get_##type##_value_array (GstInterpolationControlSource *self
return TRUE; \
}
DEFINE_LINEAR_GET (int, TRUE);
DEFINE_LINEAR_GET (int, TRUE, EMPTY);
DEFINE_LINEAR_GET (uint, TRUE);
DEFINE_LINEAR_GET (long, TRUE);
DEFINE_LINEAR_GET (uint, TRUE, EMPTY);
DEFINE_LINEAR_GET (long, TRUE, EMPTY);
DEFINE_LINEAR_GET (ulong, TRUE);
DEFINE_LINEAR_GET (int64, TRUE);
DEFINE_LINEAR_GET (uint64, TRUE);
DEFINE_LINEAR_GET (float, FALSE);
DEFINE_LINEAR_GET (double, FALSE);
DEFINE_LINEAR_GET (ulong, TRUE, EMPTY);
DEFINE_LINEAR_GET (int64, TRUE, EMPTY);
DEFINE_LINEAR_GET (uint64, TRUE, gst_util_guint64_to_gdouble);
DEFINE_LINEAR_GET (float, FALSE, EMPTY);
DEFINE_LINEAR_GET (double, FALSE, EMPTY);
static GstInterpolateMethod interpolate_linear = {
(GstControlSourceGetValue) interpolate_linear_get_int,
@ -659,7 +661,7 @@ static GstInterpolateMethod interpolate_linear = {
* . . . . .
*/
#define DEFINE_CUBIC_GET(type,round) \
#define DEFINE_CUBIC_GET(type,round, convert) \
static void \
_interpolate_cubic_update_cache_##type (GstInterpolationControlSource *self) \
{ \
@ -706,7 +708,7 @@ _interpolate_cubic_update_cache_##type (GstInterpolationControlSource *self) \
o[i] = h[i-1]; \
p[i] = 2.0 * (h[i-1] + h[i]); \
q[i] = h[i]; \
b[i] = (y_next - y) / h[i] - (y - y_prev) / h[i-1]; \
b[i] = convert (y_next - y) / h[i] - convert (y - y_prev) / h[i-1]; \
} \
p[n-1] = 1.0; \
\
@ -772,8 +774,8 @@ _interpolate_cubic_get_##type (GstInterpolationControlSource *self, GstClockTime
diff2 = gst_guint64_to_gdouble (cp2->timestamp - timestamp); \
\
out = (cp2->cache.cubic.z * diff1 * diff1 * diff1 + cp1->cache.cubic.z * diff2 * diff2 * diff2) / cp1->cache.cubic.h; \
out += (value2 / cp1->cache.cubic.h - cp1->cache.cubic.h * cp2->cache.cubic.z) * diff1; \
out += (value1 / cp1->cache.cubic.h - cp1->cache.cubic.h * cp1->cache.cubic.z) * diff2; \
out += (convert (value2) / cp1->cache.cubic.h - cp1->cache.cubic.h * cp2->cache.cubic.z) * diff1; \
out += (convert (value1) / cp1->cache.cubic.h - cp1->cache.cubic.h * cp1->cache.cubic.z) * diff2; \
\
if (round) \
*ret = (g##type) (out + 0.5); \
@ -828,16 +830,16 @@ interpolate_cubic_get_##type##_value_array (GstInterpolationControlSource *self,
return TRUE; \
}
DEFINE_CUBIC_GET (int, TRUE);
DEFINE_CUBIC_GET (int, TRUE, EMPTY);
DEFINE_CUBIC_GET (uint, TRUE);
DEFINE_CUBIC_GET (long, TRUE);
DEFINE_CUBIC_GET (uint, TRUE, EMPTY);
DEFINE_CUBIC_GET (long, TRUE, EMPTY);
DEFINE_CUBIC_GET (ulong, TRUE);
DEFINE_CUBIC_GET (int64, TRUE);
DEFINE_CUBIC_GET (uint64, TRUE);
DEFINE_CUBIC_GET (float, FALSE);
DEFINE_CUBIC_GET (double, FALSE);
DEFINE_CUBIC_GET (ulong, TRUE, EMPTY);
DEFINE_CUBIC_GET (int64, TRUE, EMPTY);
DEFINE_CUBIC_GET (uint64, TRUE, gst_util_guint64_to_gdouble);
DEFINE_CUBIC_GET (float, FALSE, EMPTY);
DEFINE_CUBIC_GET (double, FALSE, EMPTY);
static GstInterpolateMethod interpolate_cubic = {
(GstControlSourceGetValue) interpolate_cubic_get_int,

View file

@ -45,6 +45,8 @@
#include "math.h"
#define EMPTY(x) (x)
/* FIXME: as % in C is not the modulo operator we need here for
* negative numbers implement our own. Are there better ways? */
static inline GstClockTime
@ -59,7 +61,7 @@ _calculate_pos (GstClockTime timestamp, GstClockTime timeshift,
return timestamp % period;
}
#define DEFINE_SINE(type,round) \
#define DEFINE_SINE(type,round,convert) \
\
static inline g##type \
_sine_get_##type (GstLFOControlSource *self, GstClockTime timestamp) \
@ -67,18 +69,18 @@ _sine_get_##type (GstLFOControlSource *self, GstClockTime timestamp) \
gdouble ret; \
g##type max = g_value_get_##type (&self->priv->maximum_value); \
g##type min = g_value_get_##type (&self->priv->minimum_value); \
gdouble amp = g_value_get_##type (&self->priv->amplitude); \
gdouble off = g_value_get_##type (&self->priv->offset); \
gdouble amp = convert (g_value_get_##type (&self->priv->amplitude)); \
gdouble off = convert (g_value_get_##type (&self->priv->offset)); \
GstClockTime pos = _calculate_pos (timestamp, self->priv->timeshift, self->priv->period); \
\
ret = sin (2.0 * M_PI * (self->priv->frequency / GST_SECOND) * pos); \
ret = sin (2.0 * M_PI * (self->priv->frequency / GST_SECOND) * gst_util_guint64_to_gdouble (pos)); \
ret *= amp; \
ret += off; \
\
if (round) \
ret += 0.5; \
\
return (g##type) CLAMP (ret, min, max); \
return (g##type) CLAMP (ret, convert (min), convert (max)); \
} \
\
static gboolean \
@ -111,15 +113,15 @@ waveform_sine_get_##type##_value_array (GstLFOControlSource *self, \
return TRUE; \
}
DEFINE_SINE (int, TRUE);
DEFINE_SINE (uint, TRUE);
DEFINE_SINE (long, TRUE);
DEFINE_SINE (int, TRUE, EMPTY);
DEFINE_SINE (uint, TRUE, EMPTY);
DEFINE_SINE (long, TRUE, EMPTY);
DEFINE_SINE (ulong, TRUE);
DEFINE_SINE (int64, TRUE);
DEFINE_SINE (uint64, TRUE);
DEFINE_SINE (float, FALSE);
DEFINE_SINE (double, FALSE);
DEFINE_SINE (ulong, TRUE, EMPTY);
DEFINE_SINE (int64, TRUE, EMPTY);
DEFINE_SINE (uint64, TRUE, gst_util_guint64_to_gdouble);
DEFINE_SINE (float, FALSE, EMPTY);
DEFINE_SINE (double, FALSE, EMPTY);
static GstWaveformImplementation waveform_sine = {
(GstControlSourceGetValue) waveform_sine_get_int,
@ -140,15 +142,15 @@ static GstWaveformImplementation waveform_sine = {
(GstControlSourceGetValueArray) waveform_sine_get_double_value_array
};
#define DEFINE_SQUARE(type,round) \
#define DEFINE_SQUARE(type,round, convert) \
\
static inline g##type \
_square_get_##type (GstLFOControlSource *self, GstClockTime timestamp) \
{ \
g##type max = g_value_get_##type (&self->priv->maximum_value); \
g##type min = g_value_get_##type (&self->priv->minimum_value); \
gdouble amp = g_value_get_##type (&self->priv->amplitude); \
gdouble off = g_value_get_##type (&self->priv->offset); \
gdouble amp = convert (g_value_get_##type (&self->priv->amplitude)); \
gdouble off = convert (g_value_get_##type (&self->priv->offset)); \
GstClockTime period = self->priv->period; \
GstClockTime pos = _calculate_pos (timestamp, self->priv->timeshift, period); \
gdouble ret; \
@ -163,7 +165,7 @@ _square_get_##type (GstLFOControlSource *self, GstClockTime timestamp) \
if (round) \
ret += 0.5; \
\
return (g##type) CLAMP (ret, min, max); \
return (g##type) CLAMP (ret, convert (min), convert (max)); \
} \
\
static gboolean \
@ -196,16 +198,16 @@ waveform_square_get_##type##_value_array (GstLFOControlSource *self, \
return TRUE; \
}
DEFINE_SQUARE (int, TRUE);
DEFINE_SQUARE (int, TRUE, EMPTY);
DEFINE_SQUARE (uint, TRUE);
DEFINE_SQUARE (long, TRUE);
DEFINE_SQUARE (uint, TRUE, EMPTY);
DEFINE_SQUARE (long, TRUE, EMPTY);
DEFINE_SQUARE (ulong, TRUE);
DEFINE_SQUARE (int64, TRUE);
DEFINE_SQUARE (uint64, TRUE);
DEFINE_SQUARE (float, FALSE);
DEFINE_SQUARE (double, FALSE);
DEFINE_SQUARE (ulong, TRUE, EMPTY);
DEFINE_SQUARE (int64, TRUE, EMPTY);
DEFINE_SQUARE (uint64, TRUE, gst_util_guint64_to_gdouble);
DEFINE_SQUARE (float, FALSE, EMPTY);
DEFINE_SQUARE (double, FALSE, EMPTY);
static GstWaveformImplementation waveform_square = {
(GstControlSourceGetValue) waveform_square_get_int,
@ -226,27 +228,27 @@ static GstWaveformImplementation waveform_square = {
(GstControlSourceGetValueArray) waveform_square_get_double_value_array
};
#define DEFINE_SAW(type,round) \
#define DEFINE_SAW(type,round,convert) \
\
static inline g##type \
_saw_get_##type (GstLFOControlSource *self, GstClockTime timestamp) \
{ \
g##type max = g_value_get_##type (&self->priv->maximum_value); \
g##type min = g_value_get_##type (&self->priv->minimum_value); \
gdouble amp = g_value_get_##type (&self->priv->amplitude); \
gdouble off = g_value_get_##type (&self->priv->offset); \
gdouble amp = convert (g_value_get_##type (&self->priv->amplitude)); \
gdouble off = convert (g_value_get_##type (&self->priv->offset)); \
GstClockTime period = self->priv->period; \
GstClockTime pos = _calculate_pos (timestamp, self->priv->timeshift, period); \
gdouble ret; \
\
ret = - ((pos - period / 2.0) * ((2.0 * amp) / period));\
ret = - ((gst_util_guint64_to_gdouble (pos) - gst_util_guint64_to_gdouble (period) / 2.0) * ((2.0 * amp) / gst_util_guint64_to_gdouble (period)));\
\
ret += off; \
\
if (round) \
ret += 0.5; \
\
return (g##type) CLAMP (ret, min, max); \
return (g##type) CLAMP (ret, convert (min), convert (max)); \
} \
\
static gboolean \
@ -279,16 +281,16 @@ waveform_saw_get_##type##_value_array (GstLFOControlSource *self, \
return TRUE; \
}
DEFINE_SAW (int, TRUE);
DEFINE_SAW (int, TRUE, EMPTY);
DEFINE_SAW (uint, TRUE);
DEFINE_SAW (long, TRUE);
DEFINE_SAW (uint, TRUE, EMPTY);
DEFINE_SAW (long, TRUE, EMPTY);
DEFINE_SAW (ulong, TRUE);
DEFINE_SAW (int64, TRUE);
DEFINE_SAW (uint64, TRUE);
DEFINE_SAW (float, FALSE);
DEFINE_SAW (double, FALSE);
DEFINE_SAW (ulong, TRUE, EMPTY);
DEFINE_SAW (int64, TRUE, EMPTY);
DEFINE_SAW (uint64, TRUE, gst_util_guint64_to_gdouble);
DEFINE_SAW (float, FALSE, EMPTY);
DEFINE_SAW (double, FALSE, EMPTY);
static GstWaveformImplementation waveform_saw = {
(GstControlSourceGetValue) waveform_saw_get_int,
@ -309,27 +311,27 @@ static GstWaveformImplementation waveform_saw = {
(GstControlSourceGetValueArray) waveform_saw_get_double_value_array
};
#define DEFINE_RSAW(type,round) \
#define DEFINE_RSAW(type,round,convert) \
\
static inline g##type \
_rsaw_get_##type (GstLFOControlSource *self, GstClockTime timestamp) \
{ \
g##type max = g_value_get_##type (&self->priv->maximum_value); \
g##type min = g_value_get_##type (&self->priv->minimum_value); \
gdouble amp = g_value_get_##type (&self->priv->amplitude); \
gdouble off = g_value_get_##type (&self->priv->offset); \
gdouble amp = convert (g_value_get_##type (&self->priv->amplitude)); \
gdouble off = convert (g_value_get_##type (&self->priv->offset)); \
GstClockTime period = self->priv->period; \
GstClockTime pos = _calculate_pos (timestamp, self->priv->timeshift, period); \
gdouble ret; \
\
ret = ((pos - period / 2.0) * ((2.0 * amp) / period));\
ret = ((gst_util_guint64_to_gdouble (pos) - gst_util_guint64_to_gdouble (period) / 2.0) * ((2.0 * amp) / gst_util_guint64_to_gdouble (period)));\
\
ret += off; \
\
if (round) \
ret += 0.5; \
\
return (g##type) CLAMP (ret, min, max); \
return (g##type) CLAMP (ret, convert (min), convert (max)); \
} \
\
static gboolean \
@ -362,16 +364,16 @@ waveform_rsaw_get_##type##_value_array (GstLFOControlSource *self, \
return TRUE; \
}
DEFINE_RSAW (int, TRUE);
DEFINE_RSAW (int, TRUE, EMPTY);
DEFINE_RSAW (uint, TRUE);
DEFINE_RSAW (long, TRUE);
DEFINE_RSAW (uint, TRUE, EMPTY);
DEFINE_RSAW (long, TRUE, EMPTY);
DEFINE_RSAW (ulong, TRUE);
DEFINE_RSAW (int64, TRUE);
DEFINE_RSAW (uint64, TRUE);
DEFINE_RSAW (float, FALSE);
DEFINE_RSAW (double, FALSE);
DEFINE_RSAW (ulong, TRUE, EMPTY);
DEFINE_RSAW (int64, TRUE, EMPTY);
DEFINE_RSAW (uint64, TRUE, gst_util_guint64_to_gdouble);
DEFINE_RSAW (float, FALSE, EMPTY);
DEFINE_RSAW (double, FALSE, EMPTY);
static GstWaveformImplementation waveform_rsaw = {
(GstControlSourceGetValue) waveform_rsaw_get_int,
@ -392,32 +394,32 @@ static GstWaveformImplementation waveform_rsaw = {
(GstControlSourceGetValueArray) waveform_rsaw_get_double_value_array
};
#define DEFINE_TRIANGLE(type,round) \
#define DEFINE_TRIANGLE(type,round,convert) \
\
static inline g##type \
_triangle_get_##type (GstLFOControlSource *self, GstClockTime timestamp) \
{ \
g##type max = g_value_get_##type (&self->priv->maximum_value); \
g##type min = g_value_get_##type (&self->priv->minimum_value); \
gdouble amp = g_value_get_##type (&self->priv->amplitude); \
gdouble off = g_value_get_##type (&self->priv->offset); \
gdouble amp = convert (g_value_get_##type (&self->priv->amplitude)); \
gdouble off = convert (g_value_get_##type (&self->priv->offset)); \
GstClockTime period = self->priv->period; \
GstClockTime pos = _calculate_pos (timestamp, self->priv->timeshift, period); \
gdouble ret; \
\
if (pos <= period / 4.0) \
ret = pos * ((4.0 * amp) / period); \
else if (pos <= (3.0 * period) / 4.0) \
ret = -(pos - period / 2.0) * ((4.0 * amp) / period); \
if (gst_util_guint64_to_gdouble (pos) <= gst_util_guint64_to_gdouble (period) / 4.0) \
ret = gst_util_guint64_to_gdouble (pos) * ((4.0 * amp) / gst_util_guint64_to_gdouble (period)); \
else if (gst_util_guint64_to_gdouble (pos) <= (3.0 * gst_util_guint64_to_gdouble (period)) / 4.0) \
ret = -(gst_util_guint64_to_gdouble (pos) - gst_util_guint64_to_gdouble (period) / 2.0) * ((4.0 * amp) / gst_util_guint64_to_gdouble (period)); \
else \
ret = (period - pos) * ((4.0 * amp) / period); \
ret = gst_util_guint64_to_gdouble (period) - gst_util_guint64_to_gdouble (pos) * ((4.0 * amp) / gst_util_guint64_to_gdouble (period)); \
\
ret += off; \
\
if (round) \
ret += 0.5; \
\
return (g##type) CLAMP (ret, min, max); \
return (g##type) CLAMP (ret, convert (min), convert (max)); \
} \
\
static gboolean \
@ -450,16 +452,16 @@ waveform_triangle_get_##type##_value_array (GstLFOControlSource *self, \
return TRUE; \
}
DEFINE_TRIANGLE (int, TRUE);
DEFINE_TRIANGLE (int, TRUE, EMPTY);
DEFINE_TRIANGLE (uint, TRUE);
DEFINE_TRIANGLE (long, TRUE);
DEFINE_TRIANGLE (uint, TRUE, EMPTY);
DEFINE_TRIANGLE (long, TRUE, EMPTY);
DEFINE_TRIANGLE (ulong, TRUE);
DEFINE_TRIANGLE (int64, TRUE);
DEFINE_TRIANGLE (uint64, TRUE);
DEFINE_TRIANGLE (float, FALSE);
DEFINE_TRIANGLE (double, FALSE);
DEFINE_TRIANGLE (ulong, TRUE, EMPTY);
DEFINE_TRIANGLE (int64, TRUE, EMPTY);
DEFINE_TRIANGLE (uint64, TRUE, gst_util_guint64_to_gdouble);
DEFINE_TRIANGLE (float, FALSE, EMPTY);
DEFINE_TRIANGLE (double, FALSE, EMPTY);
static GstWaveformImplementation waveform_triangle = {
(GstControlSourceGetValue) waveform_triangle_get_int,