X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=gst%2Fgstbuffer.c;h=8aef1c206e84266f92b876e3de1e6fa91272a7a7;hb=e10266e3f3cf9b05b69198b1ac6faa9a62840e30;hp=b35fd7c071df3ce526139736bd84bfcafaaae19f;hpb=659785d896914f5e659af5ea2f24efe56ed36099;p=platform%2Fupstream%2Fgstreamer.git diff --git a/gst/gstbuffer.c b/gst/gstbuffer.c index b35fd7c..8aef1c2 100644 --- a/gst/gstbuffer.c +++ b/gst/gstbuffer.c @@ -33,9 +33,7 @@ * created one will typically allocate memory for it and add it to the buffer. * The following example creates a buffer that can hold a given video frame * with a given width, height and bits per plane. - * - * Creating a buffer for a video frame - * + * |[ * GstBuffer *buffer; * GstMemory *memory; * gint size, width, height, bpp; @@ -45,11 +43,10 @@ * memory = gst_allocator_alloc (NULL, size, NULL); * gst_buffer_insert_memory (buffer, -1, memory); * ... - * - * + * ]| * - * Alternatively, use gst_buffer_new_allocate() - * to create a buffer with preallocated data of a given size. + * Alternatively, use gst_buffer_new_allocate() to create a buffer with + * preallocated data of a given size. * * Buffers can contain a list of #GstMemory objects. You can retrieve how many * memory objects with gst_buffer_n_memory() and you can get a pointer @@ -107,8 +104,6 @@ * the refcount drops to 0, any memory and metadata pointed to by the buffer is * unreffed as well. Buffers allocated from a #GstBufferPool will be returned to * the pool when the refcount drops to 0. - * - * Last reviewed on 2012-03-28 (0.11.3) */ #include "gst_private.h" @@ -286,7 +281,7 @@ _replace_memory (GstBuffer * buffer, guint len, guint idx, guint length, &GST_BUFFER_MEM_PTR (buffer, end), (len - end) * sizeof (gpointer)); } GST_BUFFER_MEM_LEN (buffer) = len - length; - GST_BUFFER_FLAG_UNSET (buffer, GST_BUFFER_FLAG_TAG_MEMORY); + GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY); } static inline void @@ -322,7 +317,7 @@ _memory_add (GstBuffer * buffer, gint idx, GstMemory * mem, gboolean lock) GST_BUFFER_MEM_PTR (buffer, idx) = mem; GST_BUFFER_MEM_LEN (buffer) = len + 1; - GST_BUFFER_FLAG_UNSET (buffer, GST_BUFFER_FLAG_TAG_MEMORY); + GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY); } GST_DEFINE_MINI_OBJECT_TYPE (GstBuffer, gst_buffer); @@ -522,7 +517,8 @@ _gst_buffer_copy (GstBuffer * buffer) if (!gst_buffer_copy_into (copy, buffer, GST_BUFFER_COPY_ALL, 0, -1)) gst_buffer_replace (©, NULL); - GST_BUFFER_FLAG_SET (copy, GST_BUFFER_FLAG_TAG_MEMORY); + if (copy) + GST_BUFFER_FLAG_UNSET (copy, GST_BUFFER_FLAG_TAG_MEMORY); return copy; } @@ -639,22 +635,22 @@ gst_buffer_new (void) /** * gst_buffer_new_allocate: - * @allocator: (transfer none) (allow-none): the #GstAllocator to use, or NULL to use the + * @allocator: (transfer none) (allow-none): the #GstAllocator to use, or %NULL to use the * default allocator * @size: the size in bytes of the new buffer's data. * @params: (transfer none) (allow-none): optional parameters * * Tries to create a newly allocated buffer with data of the given size and * extra parameters from @allocator. If the requested amount of memory can't be - * allocated, NULL will be returned. The allocated buffer memory is not cleared. + * allocated, %NULL will be returned. The allocated buffer memory is not cleared. * - * When @allocator is NULL, the default memory allocator will be used. + * When @allocator is %NULL, the default memory allocator will be used. * * Note that when @size == 0, the buffer will not have memory associated with it. * * MT safe. * - * Returns: (transfer full): a new #GstBuffer, or NULL if the memory couldn't + * Returns: (transfer full): a new #GstBuffer, or %NULL if the memory couldn't * be allocated. */ GstBuffer * @@ -728,7 +724,7 @@ gst_buffer_new_allocate (GstAllocator * allocator, gsize size, if (size > 0) _memory_add (newbuf, -1, gst_memory_ref (mem), TRUE); #endif - GST_BUFFER_FLAG_SET (newbuf, GST_BUFFER_FLAG_TAG_MEMORY); + GST_BUFFER_FLAG_UNSET (newbuf, GST_BUFFER_FLAG_TAG_MEMORY); return newbuf; @@ -775,7 +771,7 @@ gst_buffer_new_wrapped_full (GstMemoryFlags flags, gpointer data, gst_memory_new_wrapped (flags, data, maxsize, offset, size, user_data, notify); _memory_add (newbuf, -1, mem, TRUE); - GST_BUFFER_FLAG_SET (newbuf, GST_BUFFER_FLAG_TAG_MEMORY); + GST_BUFFER_FLAG_UNSET (newbuf, GST_BUFFER_FLAG_TAG_MEMORY); return newbuf; } @@ -890,7 +886,7 @@ _get_mapped (GstBuffer * buffer, guint idx, GstMapInfo * info, GST_BUFFER_MEM_PTR (buffer, idx) = mapped; /* unlock old memory */ gst_memory_unlock (mem, GST_LOCK_FLAG_EXCLUSIVE); - GST_BUFFER_FLAG_UNSET (buffer, GST_BUFFER_FLAG_TAG_MEMORY); + GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY); } gst_memory_unref (mem); @@ -1196,19 +1192,22 @@ gst_buffer_is_memory_range_writable (GstBuffer * buffer, guint idx, gint length) { guint i, len; - g_return_if_fail (GST_IS_BUFFER (buffer)); + g_return_val_if_fail (GST_IS_BUFFER (buffer), FALSE); GST_CAT_DEBUG (GST_CAT_BUFFER, "idx %u, length %d", idx, length); len = GST_BUFFER_MEM_LEN (buffer); - g_return_if_fail ((len == 0 && idx == 0 && length == -1) || - (length == -1 && idx < len) || (length > 0 && length + idx <= len)); + g_return_val_if_fail ((len == 0 && idx == 0 && length == -1) || + (length == -1 && idx < len) || (length > 0 && length + idx <= len), + FALSE); if (length == -1) - length = len - idx; + len -= idx; + else + len = length; for (i = 0; i < len; i++) { - if (!gst_memory_is_writable (GST_BUFFER_MEM_PTR (buffer, i))) + if (!gst_memory_is_writable (GST_BUFFER_MEM_PTR (buffer, i + idx))) return FALSE; } return TRUE; @@ -1461,8 +1460,8 @@ gst_buffer_resize_range (GstBuffer * buffer, guint idx, gint length, gst_memory_unlock (mem, GST_LOCK_FLAG_EXCLUSIVE); gst_memory_unref (mem); + GST_BUFFER_FLAG_SET (buffer, GST_BUFFER_FLAG_TAG_MEMORY); } - GST_BUFFER_FLAG_UNSET (buffer, GST_BUFFER_FLAG_TAG_MEMORY); } offset = noffs; @@ -1582,21 +1581,20 @@ not_writable: { GST_WARNING_OBJECT (buffer, "write map requested on non-writable buffer"); g_critical ("write map requested on non-writable buffer"); + memset (info, 0, sizeof (GstMapInfo)); return FALSE; } no_memory: { /* empty buffer, we need to return NULL */ GST_DEBUG_OBJECT (buffer, "can't get buffer memory"); - info->memory = NULL; - info->data = NULL; - info->size = 0; - info->maxsize = 0; + memset (info, 0, sizeof (GstMapInfo)); return TRUE; } cannot_map: { GST_DEBUG_OBJECT (buffer, "cannot map memory"); + memset (info, 0, sizeof (GstMapInfo)); return FALSE; } } @@ -1844,7 +1842,7 @@ gst_buffer_memset (GstBuffer * buffer, gsize offset, guint8 val, gsize size) * * MT safe. * - * Returns: (transfer full): the new #GstBuffer or NULL if the arguments were + * Returns: (transfer full): the new #GstBuffer or %NULL if the arguments were * invalid. */ GstBuffer * @@ -1922,7 +1920,7 @@ gst_buffer_append_region (GstBuffer * buf1, GstBuffer * buf2, gssize offset, } GST_BUFFER_MEM_LEN (buf2) = 0; - GST_BUFFER_FLAG_UNSET (buf2, GST_BUFFER_FLAG_TAG_MEMORY); + GST_BUFFER_FLAG_SET (buf2, GST_BUFFER_FLAG_TAG_MEMORY); gst_buffer_unref (buf2); return buf1; @@ -1934,7 +1932,7 @@ gst_buffer_append_region (GstBuffer * buf1, GstBuffer * buf2, gssize offset, * @api: the #GType of an API * * Get the metadata for @api on buffer. When there is no such - * metadata, NULL is returned. + * metadata, %NULL is returned. * * Returns: (transfer none): the metadata for @api on @buffer. */