mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-03 15:06:34 +00:00
API: Move float endianness conversion macros from libgstfloatcast to core as it's useful in general, even in core. Fi...
Original commit message from CVS: * docs/gst/gstreamer-sections.txt: * gst/gstutils.h: API: Move float endianness conversion macros from libgstfloatcast to core as it's useful in general, even in core. Fixes bug #555196. This adds GDOUBLE_FROM_BE, GDOUBLE_FROM_LE, GDOUBLE_TO_BE, GDOUBLE_TO_LE, GDOUBLE_SWAP_LE_BE, GFLOAT_FROM_BE, GFLOAT_FROM_LE, GFLOAT_TO_BE, GFLOAT_TO_LE, GFLOAT_SWAP_LE_BE. Also add GST_READ_ and GST_WRITE_ macros for floats and doubles: GST_READ_FLOAT_LE, GST_READ_FLOAT_BE, GST_READ_DOUBLE_LE, GST_READ_DOUBLE_BE, GST_WRITE_FLOAT_LE, GST_WRITE_FLOAT_BE, GST_WRITE_DOUBLE_LE, GST_WRITE_DOUBLE_BE.
This commit is contained in:
parent
61ee0f414a
commit
5644be89d7
3 changed files with 368 additions and 0 deletions
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
|||
2008-10-23 Sebastian Dröge <sebastian.droege@collabora.co.uk>
|
||||
|
||||
* docs/gst/gstreamer-sections.txt:
|
||||
* gst/gstutils.h:
|
||||
API: Move float endianness conversion macros from libgstfloatcast
|
||||
to core as it's useful in general, even in core. Fixes bug #555196.
|
||||
This adds GDOUBLE_FROM_BE, GDOUBLE_FROM_LE, GDOUBLE_TO_BE,
|
||||
GDOUBLE_TO_LE, GDOUBLE_SWAP_LE_BE, GFLOAT_FROM_BE, GFLOAT_FROM_LE,
|
||||
GFLOAT_TO_BE, GFLOAT_TO_LE, GFLOAT_SWAP_LE_BE.
|
||||
|
||||
Also add GST_READ_ and GST_WRITE_ macros for floats and doubles:
|
||||
GST_READ_FLOAT_LE, GST_READ_FLOAT_BE, GST_READ_DOUBLE_LE,
|
||||
GST_READ_DOUBLE_BE, GST_WRITE_FLOAT_LE, GST_WRITE_FLOAT_BE,
|
||||
GST_WRITE_DOUBLE_LE, GST_WRITE_DOUBLE_BE.
|
||||
|
||||
2008-10-22 Sebastian Dröge <slomo@circular-chaos.org>
|
||||
|
||||
* docs/libs/gstreamer-libs-sections.txt:
|
||||
|
|
|
@ -2273,6 +2273,16 @@ GST_BOILERPLATE_FULL
|
|||
GST_BOILERPLATE
|
||||
GST_CALL_PARENT
|
||||
GST_CALL_PARENT_WITH_DEFAULT
|
||||
GDOUBLE_FROM_BE
|
||||
GDOUBLE_FROM_LE
|
||||
GDOUBLE_TO_BE
|
||||
GDOUBLE_TO_LE
|
||||
GDOUBLE_SWAP_LE_BE
|
||||
GFLOAT_FROM_BE
|
||||
GFLOAT_FROM_LE
|
||||
GFLOAT_TO_BE
|
||||
GFLOAT_TO_LE
|
||||
GFLOAT_SWAP_LE_BE
|
||||
GST_READ_UINT8
|
||||
GST_READ_UINT16_LE
|
||||
GST_READ_UINT16_BE
|
||||
|
@ -2282,6 +2292,10 @@ GST_READ_UINT32_LE
|
|||
GST_READ_UINT32_BE
|
||||
GST_READ_UINT64_LE
|
||||
GST_READ_UINT64_BE
|
||||
GST_READ_FLOAT_LE
|
||||
GST_READ_FLOAT_BE
|
||||
GST_READ_DOUBLE_LE
|
||||
GST_READ_DOUBLE_BE
|
||||
GST_WRITE_UINT8
|
||||
GST_WRITE_UINT16_LE
|
||||
GST_WRITE_UINT16_BE
|
||||
|
@ -2291,6 +2305,10 @@ GST_WRITE_UINT32_LE
|
|||
GST_WRITE_UINT32_BE
|
||||
GST_WRITE_UINT64_LE
|
||||
GST_WRITE_UINT64_BE
|
||||
GST_WRITE_FLOAT_LE
|
||||
GST_WRITE_FLOAT_BE
|
||||
GST_WRITE_DOUBLE_LE
|
||||
GST_WRITE_DOUBLE_BE
|
||||
GST_ROUND_UP_2
|
||||
GST_ROUND_UP_4
|
||||
GST_ROUND_UP_8
|
||||
|
|
335
gst/gstutils.h
335
gst/gstutils.h
|
@ -510,6 +510,341 @@ GST_BOILERPLATE_FULL (type, type_as_function, parent_type, \
|
|||
_GST_PUT (data, 0, 8, 0, num); \
|
||||
} while (0)
|
||||
|
||||
/* Float endianess conversion macros */
|
||||
|
||||
/* FIXME: Remove this once we depend on a GLib version with this */
|
||||
#ifndef GFLOAT_FROM_LE
|
||||
/**
|
||||
* GFLOAT_SWAP_LE_BE:
|
||||
* @in: input value
|
||||
*
|
||||
* Swap byte order of a 32-bit floating point value (float).
|
||||
*
|
||||
* Since: 0.10.22
|
||||
*
|
||||
*/
|
||||
inline static gfloat
|
||||
GFLOAT_SWAP_LE_BE(gfloat in)
|
||||
{
|
||||
union
|
||||
{
|
||||
guint32 i;
|
||||
gfloat f;
|
||||
} u;
|
||||
|
||||
u.f = in;
|
||||
u.i = GUINT32_SWAP_LE_BE (u.i);
|
||||
return u.f;
|
||||
}
|
||||
|
||||
/**
|
||||
* GDOUBLE_SWAP_LE_BE:
|
||||
* @in: input value
|
||||
*
|
||||
* Swap byte order of a 64-bit floating point value (double).
|
||||
*
|
||||
* Since: 0.10.22
|
||||
*
|
||||
*/
|
||||
inline static gdouble
|
||||
GDOUBLE_SWAP_LE_BE(gdouble in)
|
||||
{
|
||||
union
|
||||
{
|
||||
guint64 i;
|
||||
gdouble d;
|
||||
} u;
|
||||
|
||||
u.d = in;
|
||||
u.i = GUINT64_SWAP_LE_BE (u.i);
|
||||
return u.d;
|
||||
}
|
||||
|
||||
/**
|
||||
* GDOUBLE_TO_LE:
|
||||
* @val: value
|
||||
*
|
||||
* Convert 64-bit floating point value (double) from native byte order into
|
||||
* little endian byte order.
|
||||
*
|
||||
* Since: 0.10.22
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* GDOUBLE_TO_BE:
|
||||
* @val: value
|
||||
*
|
||||
* Convert 64-bit floating point value (double) from native byte order into
|
||||
* big endian byte order.
|
||||
*
|
||||
* Since: 0.10.22
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* GDOUBLE_FROM_LE:
|
||||
* @val: value
|
||||
*
|
||||
* Convert 64-bit floating point value (double) from little endian byte order
|
||||
* into native byte order.
|
||||
*
|
||||
* Since: 0.10.22
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* GDOUBLE_FROM_BE:
|
||||
* @val: value
|
||||
*
|
||||
* Convert 64-bit floating point value (double) from big endian byte order
|
||||
* into native byte order.
|
||||
*
|
||||
* Since: 0.10.22
|
||||
*
|
||||
*/
|
||||
|
||||
/**
|
||||
* GFLOAT_TO_LE:
|
||||
* @val: value
|
||||
*
|
||||
* Convert 32-bit floating point value (float) from native byte order into
|
||||
* little endian byte order.
|
||||
*
|
||||
* Since: 0.10.22
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* GFLOAT_TO_BE:
|
||||
* @val: value
|
||||
*
|
||||
* Convert 32-bit floating point value (float) from native byte order into
|
||||
* big endian byte order.
|
||||
*
|
||||
* Since: 0.10.22
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* GFLOAT_FROM_LE:
|
||||
* @val: value
|
||||
*
|
||||
* Convert 32-bit floating point value (float) from little endian byte order
|
||||
* into native byte order.
|
||||
*
|
||||
* Since: 0.10.22
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* GFLOAT_FROM_BE:
|
||||
* @val: value
|
||||
*
|
||||
* Convert 32-bit floating point value (float) from big endian byte order
|
||||
* into native byte order.
|
||||
*
|
||||
* Since: 0.10.22
|
||||
*
|
||||
*/
|
||||
|
||||
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
|
||||
#define GFLOAT_TO_LE(val) ((gfloat) (val))
|
||||
#define GFLOAT_TO_BE(val) (GFLOAT_SWAP_LE_BE (val))
|
||||
#define GDOUBLE_TO_LE(val) ((gdouble) (val))
|
||||
#define GDOUBLE_TO_BE(val) (GDOUBLE_SWAP_LE_BE (val))
|
||||
|
||||
#elif G_BYTE_ORDER == G_BIG_ENDIAN
|
||||
#define GFLOAT_TO_LE(val) (GFLOAT_SWAP_LE_BE (val))
|
||||
#define GFLOAT_TO_BE(val) ((gfloat) (val))
|
||||
#define GDOUBLE_TO_LE(val) (GDOUBLE_SWAP_LE_BE (val))
|
||||
#define GDOUBLE_TO_BE(val) ((gdouble) (val))
|
||||
|
||||
#else /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
|
||||
#error unknown ENDIAN type
|
||||
#endif /* !G_LITTLE_ENDIAN && !G_BIG_ENDIAN */
|
||||
|
||||
#define GFLOAT_FROM_LE(val) (GFLOAT_TO_LE (val))
|
||||
#define GFLOAT_FROM_BE(val) (GFLOAT_TO_BE (val))
|
||||
#define GDOUBLE_FROM_LE(val) (GDOUBLE_TO_LE (val))
|
||||
#define GDOUBLE_FROM_BE(val) (GDOUBLE_TO_BE (val))
|
||||
|
||||
#endif /* !defined(GFLOAT_FROM_LE) */
|
||||
|
||||
/**
|
||||
* GST_READ_FLOAT_LE:
|
||||
* @data: memory location
|
||||
*
|
||||
* Read a 32 bit float value in little endian format from the memory buffer.
|
||||
*
|
||||
* Since: 0.10.22
|
||||
*
|
||||
*/
|
||||
inline static gfloat
|
||||
GST_READ_FLOAT_LE(const guint8 *data)
|
||||
{
|
||||
union
|
||||
{
|
||||
guint32 i;
|
||||
gfloat f;
|
||||
} u;
|
||||
|
||||
u.i = GST_READ_UINT32_LE (data);
|
||||
return u.f;
|
||||
}
|
||||
|
||||
/**
|
||||
* GST_READ_FLOAT_BE:
|
||||
* @data: memory location
|
||||
*
|
||||
* Read a 32 bit float value in big endian format from the memory buffer.
|
||||
*
|
||||
* Since: 0.10.22
|
||||
*
|
||||
*/
|
||||
inline static gfloat
|
||||
GST_READ_FLOAT_BE(const guint8 *data)
|
||||
{
|
||||
union
|
||||
{
|
||||
guint32 i;
|
||||
gfloat f;
|
||||
} u;
|
||||
|
||||
u.i = GST_READ_UINT32_BE (data);
|
||||
return u.f;
|
||||
}
|
||||
|
||||
/**
|
||||
* GST_READ_DOUBLE_LE:
|
||||
* @data: memory location
|
||||
*
|
||||
* Read a 64 bit double value in little endian format from the memory buffer.
|
||||
*
|
||||
* Since: 0.10.22
|
||||
*
|
||||
*/
|
||||
inline static gdouble
|
||||
GST_READ_DOUBLE_LE(const guint8 *data)
|
||||
{
|
||||
union
|
||||
{
|
||||
guint64 i;
|
||||
gdouble d;
|
||||
} u;
|
||||
|
||||
u.i = GST_READ_UINT64_LE (data);
|
||||
return u.d;
|
||||
}
|
||||
|
||||
/**
|
||||
* GST_READ_DOUBLE_BE:
|
||||
* @data: memory location
|
||||
*
|
||||
* Read a 64 bit double value in big endian format from the memory buffer.
|
||||
*
|
||||
* Since: 0.10.22
|
||||
*
|
||||
*/
|
||||
inline static gdouble
|
||||
GST_READ_DOUBLE_BE(const guint8 *data)
|
||||
{
|
||||
union
|
||||
{
|
||||
guint64 i;
|
||||
gdouble d;
|
||||
} u;
|
||||
|
||||
u.i = GST_READ_UINT64_BE (data);
|
||||
return u.d;
|
||||
}
|
||||
|
||||
/**
|
||||
* GST_WRITE_FLOAT_LE:
|
||||
* @data: memory location
|
||||
* @num: value to store
|
||||
*
|
||||
* Store a 32 bit float value in little endian format into the memory buffer.
|
||||
*
|
||||
* Since: 0.10.22
|
||||
*
|
||||
*/
|
||||
inline static void
|
||||
GST_WRITE_FLOAT_LE(guint8 *data, gfloat num)
|
||||
{
|
||||
union
|
||||
{
|
||||
guint32 i;
|
||||
gfloat f;
|
||||
} u;
|
||||
|
||||
u.f = num;
|
||||
GST_WRITE_UINT32_LE (data, u.i);
|
||||
}
|
||||
|
||||
/**
|
||||
* GST_WRITE_FLOAT_BE:
|
||||
* @data: memory location
|
||||
* @num: value to store
|
||||
*
|
||||
* Store a 32 bit float value in big endian format into the memory buffer.
|
||||
*
|
||||
* Since: 0.10.22
|
||||
*
|
||||
*/
|
||||
inline static void
|
||||
GST_WRITE_FLOAT_BE(guint8 *data, gfloat num)
|
||||
{
|
||||
union
|
||||
{
|
||||
guint32 i;
|
||||
gfloat f;
|
||||
} u;
|
||||
|
||||
u.f = num;
|
||||
GST_WRITE_UINT32_BE (data, u.i);
|
||||
}
|
||||
|
||||
/**
|
||||
* GST_WRITE_DOUBLE_LE:
|
||||
* @data: memory location
|
||||
* @num: value to store
|
||||
*
|
||||
* Store a 64 bit double value in little endian format into the memory buffer.
|
||||
*
|
||||
* Since: 0.10.22
|
||||
*
|
||||
*/
|
||||
inline static void
|
||||
GST_WRITE_DOUBLE_LE(guint8 *data, gdouble num)
|
||||
{
|
||||
union
|
||||
{
|
||||
guint64 i;
|
||||
gdouble d;
|
||||
} u;
|
||||
|
||||
u.d = num;
|
||||
GST_WRITE_UINT64_LE (data, u.i);
|
||||
}
|
||||
|
||||
/**
|
||||
* GST_WRITE_DOUBLE_BE:
|
||||
* @data: memory location
|
||||
* @num: value to store
|
||||
*
|
||||
* Store a 64 bit double value in big endian format into the memory buffer.
|
||||
*
|
||||
* Since: 0.10.22
|
||||
*
|
||||
*/
|
||||
inline static void
|
||||
GST_WRITE_DOUBLE_BE(guint8 *data, gdouble num)
|
||||
{
|
||||
union
|
||||
{
|
||||
guint64 i;
|
||||
gdouble d;
|
||||
} u;
|
||||
|
||||
u.d = num;
|
||||
GST_WRITE_UINT64_BE (data, u.i);
|
||||
}
|
||||
|
||||
/* Miscellaneous utility macros */
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue