1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 Data-passing buffer type, supporting sub-buffers.
7 <!-- ##### SECTION Long_Description ##### -->
9 Buffers are the basic unit of data transfer in GStreamer. The GstBuffer type
10 provides all the state necessary to define a region of memory as part of a
11 stream. Sub-buffers are also supported, allowing a smaller region of a
12 buffer to become its own buffer, with mechanisms in place to ensure that
13 neither memory space goes away.
16 Buffers are usually created with gst_buffer_new(). After a buffer has been
17 created one will typically allocate memory for it and set the size of the
18 buffer data. The following example creates a buffer that can hold a given
19 video frame with a given width, height and bits per plane.
22 gint size, width, height, bpp;
26 size = width * height * bpp;
28 buffer = gst_buffer_new ();
29 GST_BUFFER_SIZE (buffer) = size;
30 GST_BUFFER_DATA (buffer) = g_alloc (size);
35 Alternatively, use gst_buffer_new_and_alloc()
36 to create a buffer with preallocated
40 gst_buffer_ref() is used to increase the refcount of a buffer. This must be
41 done when you want to keep a handle to the buffer after pushing it to the
45 To efficiently create a smaller buffer out of an existing one, you can
46 use gst_buffer_create_sub().
49 If the plug-in wants to modify the buffer in-place, it should first obtain
50 a buffer that is safe to modify by using gst_buffer_copy_on_write(). This
51 function is optimized so that a copy will only be made when it is necessary.
54 Several flags of the buffer can be set and unset with the GST_BUFFER_FLAG_SET()
55 and GST_BUFFER_FLAG_UNSET() macros. Use GST_BUFFER_FLAG_IS_SET() to test it
56 a certain #GstBufferFlag is set.
59 Buffers can be efficiently merged into a larger buffer with gst_buffer_merge() and
60 gst_buffer_span() if the gst_buffer_is_span_fast() function returns TRUE.
63 An element should either unref the buffer or push it out on a src pad
64 using gst_pad_push() (see #GstPad).
66 Buffers usually are freed by unreffing them with gst_buffer_unref().
67 Do not use gst_buffer_free() : this function effectively frees the buffer
68 regardless of the refcount, which is dangerous.
72 Last reviewed on August 30th, 2002 (0.4.0.1)
75 <!-- ##### SECTION See_Also ##### -->
77 #GstBufferPool, #GstPad, #GstData
80 <!-- ##### STRUCT GstBuffer ##### -->
82 The basic structure of a buffer.
97 <!-- ##### USER_FUNCTION GstBufferFreeDataFunc ##### -->
105 <!-- ##### MACRO GST_BUFFER_TRACE_NAME ##### -->
107 The name used for tracing memory allocations
112 <!-- ##### MACRO GST_BUFFER_REFCOUNT ##### -->
114 Gets a handle to the refcount structure of the buffer.
117 @buf: a #GstBuffer to get the refcount structure of.
120 <!-- ##### MACRO GST_BUFFER_REFCOUNT_VALUE ##### -->
122 Gets the current refcount value of the buffer.
125 @buf: a #GstBuffer to get the refcount value of.
128 <!-- ##### MACRO GST_BUFFER_COPY_FUNC ##### -->
130 Calls the buffer-specific copy function on the given buffer.
133 @buf: a #GstBuffer to copy.
136 <!-- ##### MACRO GST_BUFFER_FREE_FUNC ##### -->
138 Calls the buffer-specific free function on the given buffer.
141 @buf: a #GstBuffer to free.
144 <!-- ##### MACRO GST_BUFFER_FLAGS ##### -->
146 Gets the flags from this buffer.
149 @buf: a #GstBuffer to retrieve the flags from.
152 <!-- ##### MACRO GST_BUFFER_FLAG_IS_SET ##### -->
154 Gives the status of a given flag of a buffer.
157 @buf: a #GstBuffer to query flags of.
158 @flag: the #GstBufferFlag to check.
161 <!-- ##### MACRO GST_BUFFER_FLAG_SET ##### -->
166 @buf: a #GstBuffer to modify flags of.
167 @flag: the #GstBufferFlag to set.
170 <!-- ##### MACRO GST_BUFFER_FLAG_UNSET ##### -->
172 Clears a buffer flag.
175 @buf: a #GstBuffer to modify flags of.
176 @flag: the #GstBufferFlag to clear.
179 <!-- ##### MACRO GST_BUFFER_DATA ##### -->
181 Retrieves a pointer to the data element of this buffer.
184 @buf: a #GstBuffer to get data pointer of.
185 @Returns: the pointer to the actual data contents of the buffer.
188 <!-- ##### MACRO GST_BUFFER_SIZE ##### -->
190 Gets the size of the data in this buffer.
193 @buf: a #GstBuffer to get data size of.
196 <!-- ##### MACRO GST_BUFFER_MAXSIZE ##### -->
198 Gets the maximum size of this buffer.
201 @buf: a #GstBuffer to get maximum size of.
204 <!-- ##### MACRO GST_BUFFER_TIMESTAMP ##### -->
206 Gets the timestamp for this buffer.
209 @buf: a #GstBuffer to get timestamp of.
212 <!-- ##### MACRO GST_BUFFER_DURATION ##### -->
220 <!-- ##### MACRO GST_BUFFER_OFFSET ##### -->
222 Gets the offset in the source file of this buffer.
225 @buf: a #GstBuffer to get offset of.
228 <!-- ##### MACRO GST_BUFFER_OFFSET_END ##### -->
236 <!-- ##### MACRO GST_BUFFER_FREE_DATA_FUNC ##### -->
244 <!-- ##### MACRO GST_BUFFER_PRIVATE ##### -->
252 <!-- ##### MACRO GST_BUFFER_OFFSET_NONE ##### -->
259 <!-- ##### MACRO GST_BUFFER_MAXSIZE_NONE ##### -->
266 <!-- ##### MACRO GST_BUFFER_DURATION_IS_VALID ##### -->
274 <!-- ##### MACRO GST_BUFFER_TIMESTAMP_IS_VALID ##### -->
282 <!-- ##### MACRO GST_BUFFER_OFFSET_IS_VALID ##### -->
290 <!-- ##### MACRO GST_BUFFER_OFFSET_END_IS_VALID ##### -->
298 <!-- ##### MACRO GST_BUFFER_MAXSIZE_IS_VALID ##### -->
306 <!-- ##### ENUM GstBufferFlag ##### -->
308 A set of buffer flags used to describe properties of a #GstBuffer.
311 @GST_BUFFER_READONLY: the buffer is read-only.
312 @GST_BUFFER_SUBBUFFER: the buffer is a subbuffer, the parent buffer can be
313 found with the GST_BUFFER_POOL_PRIVATE() macro.
314 @GST_BUFFER_ORIGINAL: buffer is not a copy of another buffer.
315 @GST_BUFFER_DONTFREE: do not try to free the data when this buffer is
317 @GST_BUFFER_KEY_UNIT: the buffer holds a key unit, a unit that can be
318 decoded independently of other buffers.
319 @GST_BUFFER_DONTKEEP:
321 @GST_BUFFER_FLAG_LAST: additional flags can be added starting from this flag.
323 <!-- ##### FUNCTION gst_buffer_new ##### -->
331 <!-- ##### FUNCTION gst_buffer_new_and_alloc ##### -->
340 <!-- ##### MACRO gst_buffer_set_data ##### -->
342 A convenience function to set the data and size on a buffer
345 @buf: The buffer to modify
346 @data: The data to set on the buffer
347 @size: The size to set on the buffer
350 <!-- ##### MACRO gst_buffer_ref ##### -->
352 Increases the refcount of the given buffer by one.
355 @buf: a #GstBuffer to increase the refcount of.
358 <!-- ##### MACRO gst_buffer_ref_by_count ##### -->
360 Increases the refcount of the buffer by the given value.
363 @buf: a #GstBuffer to increase the refcount of.
364 @c: the value to add to the refcount.
367 <!-- ##### MACRO gst_buffer_unref ##### -->
369 Decreases the refcount of the buffer. If the refcount reaches 0, the buffer
373 @buf: a #GstBuffer to unref.
376 <!-- ##### FUNCTION gst_buffer_stamp ##### -->
385 <!-- ##### MACRO gst_buffer_copy ##### -->
387 Copies the given buffer using the copy function of the parent GstData structure.
390 @buf: a #GstBuffer to copy.
391 @Returns: a new #GstBuffer copy of the buffer.
394 <!-- ##### MACRO gst_buffer_is_writable ##### -->
402 <!-- ##### MACRO gst_buffer_copy_on_write ##### -->
404 This function returns a buffer that is safe to write to.
405 Copy the buffer if the refcount > 1 so that the newly
406 created buffer can be safely written to.
407 If the refcount is 1, this function just returns the original buffer.
410 @buf: a #GstBuffer to copy
411 @Returns: the #GstBuffer that can safely be written to.
414 <!-- ##### FUNCTION gst_buffer_create_sub ##### -->
425 <!-- ##### FUNCTION gst_buffer_join ##### -->
435 <!-- ##### FUNCTION gst_buffer_merge ##### -->
445 <!-- ##### FUNCTION gst_buffer_is_span_fast ##### -->
455 <!-- ##### FUNCTION gst_buffer_span ##### -->
467 <!-- ##### FUNCTION gst_buffer_default_free ##### -->
475 <!-- ##### FUNCTION gst_buffer_default_copy ##### -->