mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-23 08:46:40 +00:00
bytewriter: add method to write out a buffer
In 0.10, this can be done with a one-liner by using GST_BUFFER_DATA/SIZE with put_data. A 0.11 user has to resort to gst_buffer_map, which is less convenient and might require a memcpy internally. API: gst_byte_writer_put_buffer()
This commit is contained in:
parent
31b79556b8
commit
e694f5e71c
2 changed files with 40 additions and 0 deletions
|
@ -750,3 +750,42 @@ CREATE_WRITE_STRING_FUNC (32, guint32);
|
||||||
*
|
*
|
||||||
* Since: 0.10.27
|
* Since: 0.10.27
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gst_byte_writer_put_buffer:
|
||||||
|
* @writer: #GstByteWriter instance
|
||||||
|
* @buffer: (transfer none): source #GstBuffer
|
||||||
|
* @offset: offset to copy from
|
||||||
|
* @size: total size to copy. If -1, all data is copied
|
||||||
|
*
|
||||||
|
* Writes @size bytes of @data to @writer.
|
||||||
|
*
|
||||||
|
* Returns: %TRUE if the data could be written
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
gboolean
|
||||||
|
gst_byte_writer_put_buffer (GstByteWriter * writer, GstBuffer * buffer,
|
||||||
|
gsize offset, gssize size)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail (writer != NULL, FALSE);
|
||||||
|
g_return_val_if_fail (size >= -1, FALSE);
|
||||||
|
|
||||||
|
if (size == -1) {
|
||||||
|
size = gst_buffer_get_size (buffer);
|
||||||
|
|
||||||
|
if (offset >= (gsize) size)
|
||||||
|
return TRUE;
|
||||||
|
|
||||||
|
size -= offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (G_UNLIKELY (!_gst_byte_writer_ensure_free_space_inline (writer, size)))
|
||||||
|
return FALSE;
|
||||||
|
|
||||||
|
gst_buffer_extract (buffer, offset,
|
||||||
|
(guint8 *) & writer->parent.data[writer->parent.byte], size);
|
||||||
|
writer->parent.byte += size;
|
||||||
|
writer->parent.size = MAX (writer->parent.size, writer->parent.byte);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
|
@ -152,6 +152,7 @@ gboolean gst_byte_writer_fill (GstByteWriter *writer, guint8
|
||||||
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);
|
||||||
|
gboolean gst_byte_writer_put_buffer (GstByteWriter *writer, GstBuffer * buffer, gsize offset, gssize size);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* gst_byte_writer_put_string:
|
* gst_byte_writer_put_string:
|
||||||
|
|
Loading…
Reference in a new issue