bytewriter: Add unchecked variants of the writing functions

These don't check if there's enough free space available and are
available as inline functions only.

API: gst_byte_writer_put_int8_unchecked
API: gst_byte_writer_put_int16_be_unchecked
API: gst_byte_writer_put_int16_le_unchecked
API: gst_byte_writer_put_int24_be_unchecked
API: gst_byte_writer_put_int24_le_unchecked
API: gst_byte_writer_put_int32_be_unchecked
API: gst_byte_writer_put_int32_le_unchecked
API: gst_byte_writer_put_int64_be_unchecked
API: gst_byte_writer_put_int64_le_unchecked
API: gst_byte_writer_put_uint8_unchecked
API: gst_byte_writer_put_uint16_be_unchecked
API: gst_byte_writer_put_uint16_le_unchecked
API: gst_byte_writer_put_uint24_be_unchecked
API: gst_byte_writer_put_uint24_le_unchecked
API: gst_byte_writer_put_uint32_be_unchecked
API: gst_byte_writer_put_uint32_le_unchecked
API: gst_byte_writer_put_uint64_be_unchecked
API: gst_byte_writer_put_uint64_le_unchecked
API: gst_byte_writer_put_float32_be_unchecked
API: gst_byte_writer_put_float32_le_unchecked
API: gst_byte_writer_put_float64_be_unchecked
API: gst_byte_writer_put_float64_le_unchecked
API: gst_byte_writer_put_data_unchecked
API: gst_byte_writer_fill_unchecked
This commit is contained in:
Sebastian Dröge 2010-10-08 12:18:23 +02:00
parent 9bd4432d08
commit 69ef479ce4
3 changed files with 60 additions and 13 deletions

View file

@ -614,6 +614,33 @@ gst_byte_writer_put_string_utf8
gst_byte_writer_put_data
gst_byte_writer_fill
gst_byte_writer_put_int8_unchecked
gst_byte_writer_put_int16_be_unchecked
gst_byte_writer_put_int16_le_unchecked
gst_byte_writer_put_int24_be_unchecked
gst_byte_writer_put_int24_le_unchecked
gst_byte_writer_put_int32_be_unchecked
gst_byte_writer_put_int32_le_unchecked
gst_byte_writer_put_int64_be_unchecked
gst_byte_writer_put_int64_le_unchecked
gst_byte_writer_put_uint8_unchecked
gst_byte_writer_put_uint16_be_unchecked
gst_byte_writer_put_uint16_le_unchecked
gst_byte_writer_put_uint24_be_unchecked
gst_byte_writer_put_uint24_le_unchecked
gst_byte_writer_put_uint32_be_unchecked
gst_byte_writer_put_uint32_le_unchecked
gst_byte_writer_put_uint64_be_unchecked
gst_byte_writer_put_uint64_le_unchecked
gst_byte_writer_put_float32_be_unchecked
gst_byte_writer_put_float32_le_unchecked
gst_byte_writer_put_float64_be_unchecked
gst_byte_writer_put_float64_le_unchecked
gst_byte_writer_put_data_unchecked
gst_byte_writer_fill_unchecked
<SUBSECTION Private>
GST_BYTE_WRITER
</SECTION>

View file

@ -37,6 +37,7 @@ libgstbase_@GST_MAJORMINOR@include_HEADERS = \
noinst_HEADERS = \
gstbytereader-docs.h \
gstbytewriter-docs.h \
gstbitreader-docs.h
CLEANFILES = *.gcno *.gcda *.gcov

View file

@ -203,20 +203,26 @@ _gst_byte_writer_ensure_free_space_inline (GstByteWriter * writer, guint size)
}
#define __GST_BYTE_WRITER_CREATE_WRITE_FUNC(bits,type,name,write_func) \
static inline gboolean \
_gst_byte_writer_put_##name##_inline (GstByteWriter *writer, type val) \
static inline void \
gst_byte_writer_put_##name##_unchecked (GstByteWriter *writer, type val) \
{ \
guint8 *write_data; \
\
g_return_val_if_fail (writer != NULL, FALSE); \
\
if (G_UNLIKELY (!_gst_byte_writer_ensure_free_space_inline(writer, bits/8))) \
return FALSE; \
\
write_data = (guint8 *) writer->parent.data + writer->parent.byte; \
write_func (write_data, val); \
writer->parent.byte += bits/8; \
writer->parent.size = MAX (writer->parent.size, writer->parent.byte); \
} \
\
static inline gboolean \
_gst_byte_writer_put_##name##_inline (GstByteWriter *writer, type val) \
{ \
g_return_val_if_fail (writer != NULL, FALSE); \
\
if (G_UNLIKELY (!_gst_byte_writer_ensure_free_space_inline(writer, bits/8))) \
return FALSE; \
\
gst_byte_writer_put_##name##_unchecked (writer, val); \
\
return TRUE; \
}
@ -247,6 +253,15 @@ __GST_BYTE_WRITER_CREATE_WRITE_FUNC (64, gdouble, float64_le, GST_WRITE_DOUBLE_L
#undef __GST_BYTE_WRITER_CREATE_WRITE_FUNC
static inline void
gst_byte_writer_put_data_unchecked (GstByteWriter * writer, const guint8 * data,
guint size)
{
memcpy ((guint8 *) & writer->parent.data[writer->parent.byte], data, size);
writer->parent.byte += size;
writer->parent.size = MAX (writer->parent.size, writer->parent.byte);
}
static inline gboolean
_gst_byte_writer_put_data_inline (GstByteWriter * writer, const guint8 * data,
guint size)
@ -256,13 +271,19 @@ _gst_byte_writer_put_data_inline (GstByteWriter * writer, const guint8 * data,
if (G_UNLIKELY (!_gst_byte_writer_ensure_free_space_inline (writer, size)))
return FALSE;
memcpy ((guint8 *) & writer->parent.data[writer->parent.byte], data, size);
writer->parent.byte += size;
writer->parent.size = MAX (writer->parent.size, writer->parent.byte);
gst_byte_writer_put_data_unchecked (writer, data, size);
return TRUE;
}
static inline void
gst_byte_writer_fill_unchecked (GstByteWriter * writer, guint8 value, guint size)
{
memset ((guint8 *) & writer->parent.data[writer->parent.byte], value, size);
writer->parent.byte += size;
writer->parent.size = MAX (writer->parent.size, writer->parent.byte);
}
static inline gboolean
_gst_byte_writer_fill_inline (GstByteWriter * writer, guint8 value, guint size)
{
@ -271,9 +292,7 @@ _gst_byte_writer_fill_inline (GstByteWriter * writer, guint8 value, guint size)
if (G_UNLIKELY (!_gst_byte_writer_ensure_free_space_inline (writer, size)))
return FALSE;
memset ((guint8 *) & writer->parent.data[writer->parent.byte], value, size);
writer->parent.byte += size;
writer->parent.size = MAX (writer->parent.size, writer->parent.byte);
gst_byte_writer_fill_unchecked (writer, value, size);
return TRUE;
}