bytewriter: add _fill function

Adds a new function to GstByteWriter that writes
a constant value to a memory area (aka memset).
Useful for adding padding to buffers.

Also updates .def file and docs.

API: gst_byte_writer_fill()
This commit is contained in:
Thiago Santos 2010-01-22 09:19:31 -03:00
parent 51d382e2ee
commit bfff7a1b4e
4 changed files with 30 additions and 0 deletions

View file

@ -595,6 +595,7 @@ gst_byte_writer_put_string_utf32
gst_byte_writer_put_string_utf8 gst_byte_writer_put_string_utf8
gst_byte_writer_put_data gst_byte_writer_put_data
gst_byte_writer_fill
<SUBSECTION Private> <SUBSECTION Private>
GST_BYTE_WRITER GST_BYTE_WRITER

View file

@ -492,6 +492,21 @@ gst_byte_writer_put_data (GstByteWriter * writer, const guint8 * data,
return TRUE; return TRUE;
} }
gboolean
gst_byte_writer_fill (GstByteWriter * writer, const guint8 value, guint size)
{
g_return_val_if_fail (writer != NULL, FALSE);
if (G_UNLIKELY (!gst_byte_writer_ensure_free_space (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);
return TRUE;
}
#define CREATE_WRITE_STRING_FUNC(bits,type) \ #define CREATE_WRITE_STRING_FUNC(bits,type) \
gboolean \ gboolean \
gst_byte_writer_put_string_utf##bits (GstByteWriter *writer, const type * data) \ gst_byte_writer_put_string_utf##bits (GstByteWriter *writer, const type * data) \
@ -806,3 +821,15 @@ CREATE_WRITE_STRING_FUNC (32, guint32);
* *
* Since: 0.10.26 * Since: 0.10.26
*/ */
/**
* gst_byte_writer_fill:
* @writer: #GstByteWriter instance
* @value: Value to be writen
* @size: Number of bytes to be writen
*
* Writes @size bytes containing @value to @writer.
*
* Returns: %TRUE if the value could be written
*
* Since: 0.10.26
*/

View file

@ -144,6 +144,7 @@ gboolean gst_byte_writer_put_double_be (GstByteWriter *writer, gdouble val);
gboolean gst_byte_writer_put_double_le (GstByteWriter *writer, gdouble val); gboolean gst_byte_writer_put_double_le (GstByteWriter *writer, gdouble val);
gboolean gst_byte_writer_put_data (GstByteWriter *writer, const guint8 *data, guint size); gboolean gst_byte_writer_put_data (GstByteWriter *writer, const guint8 *data, guint size);
gboolean gst_byte_writer_fill (GstByteWriter *writer, const guint8 value, guint size);
gboolean gst_byte_writer_put_string_utf8 (GstByteWriter *writer, const gchar *data); gboolean gst_byte_writer_put_string_utf8 (GstByteWriter *writer, const gchar *data);
gboolean gst_byte_writer_put_string_utf16 (GstByteWriter *writer, const guint16 *data); gboolean gst_byte_writer_put_string_utf16 (GstByteWriter *writer, const guint16 *data);
gboolean gst_byte_writer_put_string_utf32 (GstByteWriter *writer, const guint32 *data); gboolean gst_byte_writer_put_string_utf32 (GstByteWriter *writer, const guint32 *data);

View file

@ -142,6 +142,7 @@ EXPORTS
gst_byte_reader_skip_string_utf32 gst_byte_reader_skip_string_utf32
gst_byte_reader_skip_string_utf8 gst_byte_reader_skip_string_utf8
gst_byte_writer_ensure_free_space gst_byte_writer_ensure_free_space
gst_byte_writer_fill
gst_byte_writer_free gst_byte_writer_free
gst_byte_writer_free_and_get_buffer gst_byte_writer_free_and_get_buffer
gst_byte_writer_free_and_get_data gst_byte_writer_free_and_get_data