buffer, memory: make size arguments where -1 is allowed signed

This commit is contained in:
Tim-Philipp Müller 2011-11-11 01:47:30 +00:00
parent 327d83ba1a
commit 541d79d886
4 changed files with 33 additions and 31 deletions

View file

@ -456,7 +456,8 @@ gst_buffer_new (void)
/** /**
* gst_buffer_new_allocate: * gst_buffer_new_allocate:
* @allocator: the #GstAllocator to use * @allocator: (allow-none): the #GstAllocator to use, or NULL to use the
* default allocator
* @size: the size in bytes of the new buffer's data. * @size: the size in bytes of the new buffer's data.
* @align: the alignment of the buffer memory * @align: the alignment of the buffer memory
* *
@ -807,12 +808,12 @@ gst_buffer_get_sizes (GstBuffer * buffer, gsize * offset, gsize * maxsize)
* gst_buffer_resize: * gst_buffer_resize:
* @buffer: a #GstBuffer. * @buffer: a #GstBuffer.
* @offset: the offset adjustement * @offset: the offset adjustement
* @size: the new size * @size: the new size or -1 to just adjust the offset
* *
* Set the total size of the buffer * Set the total size of the buffer
*/ */
void void
gst_buffer_resize (GstBuffer * buffer, gssize offset, gsize size) gst_buffer_resize (GstBuffer * buffer, gssize offset, gssize size)
{ {
guint len; guint len;
guint i; guint i;
@ -824,8 +825,8 @@ gst_buffer_resize (GstBuffer * buffer, gssize offset, gsize size)
bufsize = gst_buffer_get_sizes (buffer, &bufoffs, &bufmax); bufsize = gst_buffer_get_sizes (buffer, &bufoffs, &bufmax);
GST_CAT_LOG (GST_CAT_BUFFER, "trim %p %" G_GSSIZE_FORMAT "-%" G_GSIZE_FORMAT GST_CAT_LOG (GST_CAT_BUFFER, "trim %p %" G_GSSIZE_FORMAT "-%" G_GSIZE_FORMAT
" size:%" G_GSIZE_FORMAT " offs:%" G_GSIZE_FORMAT " max:%" G_GSIZE_FORMAT, " size:%" G_GSIZE_FORMAT " offs:%" G_GSSIZE_FORMAT " max:%"
buffer, offset, size, bufsize, bufoffs, bufmax); G_GSIZE_FORMAT, buffer, offset, size, bufsize, bufoffs, bufmax);
/* we can't go back further than the current offset or past the end of the /* we can't go back further than the current offset or past the end of the
* buffer */ * buffer */
@ -987,7 +988,7 @@ not_writable:
* gst_buffer_unmap: * gst_buffer_unmap:
* @buffer: a #GstBuffer. * @buffer: a #GstBuffer.
* @data: the previously mapped data * @data: the previously mapped data
* @size: the size of @data * @size: the size of @data, or -1
* *
* Release the memory previously mapped with gst_buffer_map(). Pass -1 to size * Release the memory previously mapped with gst_buffer_map(). Pass -1 to size
* if no update is needed. * if no update is needed.
@ -996,12 +997,13 @@ not_writable:
* than the maxsize of the memory. * than the maxsize of the memory.
*/ */
gboolean gboolean
gst_buffer_unmap (GstBuffer * buffer, gpointer data, gsize size) gst_buffer_unmap (GstBuffer * buffer, gpointer data, gssize size)
{ {
gboolean result; gboolean result;
guint len; guint len;
g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE); g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE);
g_return_val_if_fail (size >= -1, FALSE);
len = GST_BUFFER_MEM_LEN (buffer); len = GST_BUFFER_MEM_LEN (buffer);

View file

@ -295,7 +295,7 @@ gsize gst_buffer_memset (GstBuffer *buffer, gsize offset,
guint8 val, gsize size); guint8 val, gsize size);
gsize gst_buffer_get_sizes (GstBuffer *buffer, gsize *offset, gsize *maxsize); gsize gst_buffer_get_sizes (GstBuffer *buffer, gsize *offset, gsize *maxsize);
void gst_buffer_resize (GstBuffer *buffer, gssize offset, gsize size); void gst_buffer_resize (GstBuffer *buffer, gssize offset, gssize size);
/** /**
* gst_buffer_get_size: * gst_buffer_get_size:
@ -317,7 +317,7 @@ void gst_buffer_resize (GstBuffer *buffer, gssize offset, gs
/* getting memory */ /* getting memory */
gpointer gst_buffer_map (GstBuffer *buffer, gsize *size, gsize *maxsize, gpointer gst_buffer_map (GstBuffer *buffer, gsize *size, gsize *maxsize,
GstMapFlags flags); GstMapFlags flags);
gboolean gst_buffer_unmap (GstBuffer *buffer, gpointer data, gsize size); gboolean gst_buffer_unmap (GstBuffer *buffer, gpointer data, gssize size);
/* refcounting */ /* refcounting */
/** /**

View file

@ -278,7 +278,7 @@ _default_mem_is_span (GstMemoryDefault * mem1, GstMemoryDefault * mem2,
} }
static GstMemory * static GstMemory *
_fallback_copy (GstMemory * mem, gssize offset, gsize size) _fallback_copy (GstMemory * mem, gssize offset, gssize size)
{ {
GstMemory *copy; GstMemory *copy;
guint8 *data, *dest; guint8 *data, *dest;
@ -465,7 +465,7 @@ gst_memory_map (GstMemory * mem, gsize * size, gsize * maxsize,
* gst_memory_unmap: * gst_memory_unmap:
* @mem: a #GstMemory * @mem: a #GstMemory
* @data: data to unmap * @data: data to unmap
* @size: new size of @mem * @size: new size of @mem, or -1
* *
* Release the memory pointer obtained with gst_memory_map() and set the size of * Release the memory pointer obtained with gst_memory_map() and set the size of
* the memory to @size. @size can be set to -1 when the size should not be * the memory to @size. @size can be set to -1 when the size should not be
@ -474,7 +474,7 @@ gst_memory_map (GstMemory * mem, gsize * size, gsize * maxsize,
* Returns: TRUE when the memory was release successfully. * Returns: TRUE when the memory was release successfully.
*/ */
gboolean gboolean
gst_memory_unmap (GstMemory * mem, gpointer data, gsize size) gst_memory_unmap (GstMemory * mem, gpointer data, gssize size)
{ {
g_return_val_if_fail (mem != NULL, FALSE); g_return_val_if_fail (mem != NULL, FALSE);
@ -485,7 +485,7 @@ gst_memory_unmap (GstMemory * mem, gpointer data, gsize size)
* gst_memory_copy: * gst_memory_copy:
* @mem: a #GstMemory * @mem: a #GstMemory
* @offset: an offset to copy * @offset: an offset to copy
* @size: size to copy * @size: size to copy or -1 to copy all bytes from offset
* *
* Return a copy of @size bytes from @mem starting from @offset. This copy is * Return a copy of @size bytes from @mem starting from @offset. This copy is
* guaranteed to be writable. @size can be set to -1 to return a copy all bytes * guaranteed to be writable. @size can be set to -1 to return a copy all bytes
@ -494,7 +494,7 @@ gst_memory_unmap (GstMemory * mem, gpointer data, gsize size)
* Returns: a new #GstMemory. * Returns: a new #GstMemory.
*/ */
GstMemory * GstMemory *
gst_memory_copy (GstMemory * mem, gssize offset, gsize size) gst_memory_copy (GstMemory * mem, gssize offset, gssize size)
{ {
g_return_val_if_fail (mem != NULL, NULL); g_return_val_if_fail (mem != NULL, NULL);
@ -505,17 +505,17 @@ gst_memory_copy (GstMemory * mem, gssize offset, gsize size)
* gst_memory_share: * gst_memory_share:
* @mem: a #GstMemory * @mem: a #GstMemory
* @offset: an offset to share * @offset: an offset to share
* @size: size to share * @size: size to share or -1 to share bytes from offset
* *
* Return a shared copy of @size bytes from @mem starting from @offset. No memory * Return a shared copy of @size bytes from @mem starting from @offset. No
* copy is performed and the memory region is simply shared. The result is * memory copy is performed and the memory region is simply shared. The result
* guaranteed to be not-writable. @size can be set to -1 to return a share all bytes * is guaranteed to be not-writable. @size can be set to -1 to return a share
* from @offset. * all bytes from @offset.
* *
* Returns: a new #GstMemory. * Returns: a new #GstMemory.
*/ */
GstMemory * GstMemory *
gst_memory_share (GstMemory * mem, gssize offset, gsize size) gst_memory_share (GstMemory * mem, gssize offset, gssize size)
{ {
g_return_val_if_fail (mem != NULL, NULL); g_return_val_if_fail (mem != NULL, NULL);

View file

@ -143,7 +143,7 @@ typedef gsize (*GstMemoryGetSizesFunction) (GstMemory *mem, gsize *offset
* GstMemoryResizeFunction: * GstMemoryResizeFunction:
* @mem: a #GstMemory * @mem: a #GstMemory
* @offset: the offset adjustement * @offset: the offset adjustement
* @size: the new size * @size: the new size or -1 to just adjust the offset
* *
* Adjust the size and offset of @mem. @offset bytes will be adjusted from the * Adjust the size and offset of @mem. @offset bytes will be adjusted from the
* current first byte in @mem as retrieved with gst_memory_map() and the new * current first byte in @mem as retrieved with gst_memory_map() and the new
@ -151,7 +151,7 @@ typedef gsize (*GstMemoryGetSizesFunction) (GstMemory *mem, gsize *offset
* *
* @size can be set to -1, which will only adjust the offset. * @size can be set to -1, which will only adjust the offset.
*/ */
typedef void (*GstMemoryResizeFunction) (GstMemory *mem, gssize offset, gsize size); typedef void (*GstMemoryResizeFunction) (GstMemory *mem, gssize offset, gssize size);
/** /**
* GstMemoryMapFunction: * GstMemoryMapFunction:
@ -175,7 +175,7 @@ typedef gpointer (*GstMemoryMapFunction) (GstMemory *mem, gsize *size,
* GstMemoryUnmapFunction: * GstMemoryUnmapFunction:
* @mem: a #GstMemory * @mem: a #GstMemory
* @data: the data pointer * @data: the data pointer
* @size: the new size * @size: the new size, or -1 to not modify the size
* *
* Return the pointer previously retrieved with gst_memory_map() and adjust the * Return the pointer previously retrieved with gst_memory_map() and adjust the
* size of the memory with @size. @size can optionally be set to -1 to not * size of the memory with @size. @size can optionally be set to -1 to not
@ -183,7 +183,7 @@ typedef gpointer (*GstMemoryMapFunction) (GstMemory *mem, gsize *size,
* *
* Returns: %TRUE on success. * Returns: %TRUE on success.
*/ */
typedef gboolean (*GstMemoryUnmapFunction) (GstMemory *mem, gpointer data, gsize size); typedef gboolean (*GstMemoryUnmapFunction) (GstMemory *mem, gpointer data, gssize size);
/** /**
* GstMemoryFreeFunction: * GstMemoryFreeFunction:
@ -198,7 +198,7 @@ typedef void (*GstMemoryFreeFunction) (GstMemory *mem);
* GstMemoryCopyFunction: * GstMemoryCopyFunction:
* @mem: a #GstMemory * @mem: a #GstMemory
* @offset: an offset * @offset: an offset
* @size: a size * @size: a size or -1
* *
* Copy @size bytes from @mem starting at @offset and return them wrapped in a * Copy @size bytes from @mem starting at @offset and return them wrapped in a
* new GstMemory object. * new GstMemory object.
@ -207,13 +207,13 @@ typedef void (*GstMemoryFreeFunction) (GstMemory *mem);
* Returns: a new #GstMemory object wrapping a copy of the requested region in * Returns: a new #GstMemory object wrapping a copy of the requested region in
* @mem. * @mem.
*/ */
typedef GstMemory * (*GstMemoryCopyFunction) (GstMemory *mem, gssize offset, gsize size); typedef GstMemory * (*GstMemoryCopyFunction) (GstMemory *mem, gssize offset, gssize size);
/** /**
* GstMemoryShareFunction: * GstMemoryShareFunction:
* @mem: a #GstMemory * @mem: a #GstMemory
* @offset: an offset * @offset: an offset
* @size: a size * @size: a size or -1
* *
* Share @size bytes from @mem starting at @offset and return them wrapped in a * Share @size bytes from @mem starting at @offset and return them wrapped in a
* new GstMemory object. If @size is set to -1, all bytes starting at @offset are * new GstMemory object. If @size is set to -1, all bytes starting at @offset are
@ -221,7 +221,7 @@ typedef GstMemory * (*GstMemoryCopyFunction) (GstMemory *mem, gssize offset
* *
* Returns: a new #GstMemory object sharing the requested region in @mem. * Returns: a new #GstMemory object sharing the requested region in @mem.
*/ */
typedef GstMemory * (*GstMemoryShareFunction) (GstMemory *mem, gssize offset, gsize size); typedef GstMemory * (*GstMemoryShareFunction) (GstMemory *mem, gssize offset, gssize size);
/** /**
* GstMemoryIsSpanFunction: * GstMemoryIsSpanFunction:
@ -291,11 +291,11 @@ void gst_memory_resize (GstMemory *mem, gssize offset, gsize size);
/* retrieving data */ /* retrieving data */
gpointer gst_memory_map (GstMemory *mem, gsize *size, gsize *maxsize, gpointer gst_memory_map (GstMemory *mem, gsize *size, gsize *maxsize,
GstMapFlags flags); GstMapFlags flags);
gboolean gst_memory_unmap (GstMemory *mem, gpointer data, gsize size); gboolean gst_memory_unmap (GstMemory *mem, gpointer data, gssize size);
/* copy and subregions */ /* copy and subregions */
GstMemory * gst_memory_copy (GstMemory *mem, gssize offset, gsize size); GstMemory * gst_memory_copy (GstMemory *mem, gssize offset, gssize size);
GstMemory * gst_memory_share (GstMemory *mem, gssize offset, gsize size); GstMemory * gst_memory_share (GstMemory *mem, gssize offset, gssize size);
/* span memory */ /* span memory */
gboolean gst_memory_is_span (GstMemory *mem1, GstMemory *mem2, gsize *offset); gboolean gst_memory_is_span (GstMemory *mem1, GstMemory *mem2, gsize *offset);