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.
21 <title>Creating a buffer for a video frame</title>
24 gint size, width, height, bpp;
28 size = width * height * bpp;
30 buffer = gst_buffer_new ();
31 GST_BUFFER_SIZE (buffer) = size;
32 GST_BUFFER_DATA (buffer) = g_alloc (size);
38 Alternatively, use gst_buffer_new_and_alloc()
39 to create a buffer with preallocated data of a given size.
42 If an element knows what pad you will push the buffer out on, it should use
43 gst_pad_alloc_buffer() instead to create a buffer. This allows downstream
44 elements to provide special buffers to write in, like hardware buffers.
47 gst_buffer_ref() is used to increase the refcount of a buffer. This must be
48 done when you want to keep a handle to the buffer after pushing it to the
52 To efficiently create a smaller buffer out of an existing one, you can
53 use gst_buffer_create_sub().
56 If the plug-in wants to modify the buffer in-place, it should first obtain
57 a buffer that is safe to modify by using gst_buffer_copy_on_write(). This
58 function is optimized so that a copy will only be made when it is necessary.
61 Several flags of the buffer can be set and unset with the GST_BUFFER_FLAG_SET()
62 and GST_BUFFER_FLAG_UNSET() macros. Use GST_BUFFER_FLAG_IS_SET() to test it
63 a certain #GstBufferFlag is set.
66 Buffers can be efficiently merged into a larger buffer with gst_buffer_merge() and
67 gst_buffer_span() if the gst_buffer_is_span_fast() function returns TRUE.
70 An element should either unref the buffer or push it out on a src pad
71 using gst_pad_push() (see #GstPad).
73 Buffers usually are freed by unreffing them with gst_buffer_unref().
74 Do not use gst_buffer_free() : this function effectively frees the buffer
75 regardless of the refcount, which is dangerous.
79 Last reviewed on August 12th, 2004 (0.8.5)
82 <!-- ##### SECTION See_Also ##### -->
84 #GstBufferPool, #GstPad, #GstData
87 <!-- ##### STRUCT GstBuffer ##### -->
89 The basic structure of a buffer.
104 <!-- ##### FUNCTION gst_buffer_new ##### -->
112 <!-- ##### FUNCTION gst_buffer_new_and_alloc ##### -->
121 <!-- ##### ENUM GstBufferFlag ##### -->
126 @GST_BUFFER_READONLY:
127 @GST_BUFFER_SUBBUFFER:
128 @GST_BUFFER_ORIGINAL:
129 @GST_BUFFER_DONTFREE:
130 @GST_BUFFER_KEY_UNIT:
131 @GST_BUFFER_DONTKEEP:
133 @GST_BUFFER_DELTA_UNIT:
134 @GST_BUFFER_FLAG_LAST:
136 <!-- ##### MACRO GST_BUFFER_FLAGS ##### -->
138 Gets the flags from this buffer.
141 @buf: a #GstBuffer to retrieve the flags from.
144 <!-- ##### MACRO GST_BUFFER_FLAG_IS_SET ##### -->
146 Gives the status of a given flag of a buffer.
149 @buf: a #GstBuffer to query flags of.
150 @flag: the #GstBufferFlag to check.
153 <!-- ##### MACRO GST_BUFFER_FLAG_SET ##### -->
158 @buf: a #GstBuffer to modify flags of.
159 @flag: the #GstBufferFlag to set.
162 <!-- ##### MACRO GST_BUFFER_FLAG_UNSET ##### -->
164 Clears a buffer flag.
167 @buf: a #GstBuffer to modify flags of.
168 @flag: the #GstBufferFlag to clear.
171 <!-- ##### MACRO gst_buffer_set_data ##### -->
173 A convenience function to set the data and size on a buffer
176 @buf: The buffer to modify
177 @data: The data to set on the buffer
178 @size: The size to set on the buffer
181 <!-- ##### MACRO GST_BUFFER_DATA ##### -->
183 Retrieves a pointer to the data element of this buffer.
186 @buf: a #GstBuffer to get data pointer of.
187 @Returns: the pointer to the actual data contents of the buffer.
190 <!-- ##### MACRO GST_BUFFER_SIZE ##### -->
192 Gets the size of the data in this buffer.
195 @buf: a #GstBuffer to get data size of.
198 <!-- ##### MACRO GST_BUFFER_MAXSIZE ##### -->
200 Gets the maximum size of this buffer.
203 @buf: a #GstBuffer to get maximum size of.
206 <!-- ##### MACRO GST_BUFFER_TIMESTAMP ##### -->
208 Gets the timestamp for this buffer.
211 @buf: a #GstBuffer to get timestamp of.
214 <!-- ##### MACRO GST_BUFFER_DURATION ##### -->
216 Gets the duration in nanoseconds of the data in the buffer.
217 Value will be GST_CLOCK_TIME_NONE if the duration is unknown.
220 @buf: a #GstBuffer to get the duration from.
223 <!-- ##### MACRO GST_BUFFER_OFFSET ##### -->
225 Gets the offset in the source file of the beinning of this buffer.
228 @buf: a #GstBuffer to get offset of.
231 <!-- ##### MACRO GST_BUFFER_OFFSET_END ##### -->
233 Gets the offset in the source file of the end of this buffer.
236 @buf: a #GstBuffer to get offset of.
239 <!-- ##### MACRO gst_buffer_ref ##### -->
241 Increases the refcount of the given buffer by one.
244 @buf: a #GstBuffer to increase the refcount of.
247 <!-- ##### MACRO gst_buffer_ref_by_count ##### -->
249 Increases the refcount of the buffer by the given value.
252 @buf: a #GstBuffer to increase the refcount of.
253 @c: the value to add to the refcount.
256 <!-- ##### MACRO gst_buffer_unref ##### -->
258 Decreases the refcount of the buffer. If the refcount reaches 0, the buffer
262 @buf: a #GstBuffer to unref.
265 <!-- ##### FUNCTION gst_buffer_stamp ##### -->
274 <!-- ##### MACRO gst_buffer_copy ##### -->
276 Copies the given buffer using the copy function of the parent GstData structure.
279 @buf: a #GstBuffer to copy.
280 @Returns: a new #GstBuffer copy of the buffer.
283 <!-- ##### MACRO gst_buffer_is_writable ##### -->
291 <!-- ##### MACRO gst_buffer_copy_on_write ##### -->
293 This function returns a buffer that is safe to write to.
294 Copy the buffer if the refcount > 1 so that the newly
295 created buffer can be safely written to.
296 If the refcount is 1, this function just returns the original buffer.
299 @buf: a #GstBuffer to copy
300 @Returns: the #GstBuffer that can safely be written to.
303 <!-- ##### FUNCTION gst_buffer_create_sub ##### -->
314 <!-- ##### FUNCTION gst_buffer_join ##### -->
324 <!-- ##### FUNCTION gst_buffer_merge ##### -->
334 <!-- ##### FUNCTION gst_buffer_span ##### -->
346 <!-- ##### FUNCTION gst_buffer_is_span_fast ##### -->
356 <!-- ##### FUNCTION gst_buffer_default_free ##### -->
364 <!-- ##### FUNCTION gst_buffer_default_copy ##### -->
373 <!-- ##### MACRO GST_BUFFER_TRACE_NAME ##### -->
375 The name used for tracing memory allocations
380 <!-- ##### MACRO GST_BUFFER_REFCOUNT ##### -->
382 Gets a handle to the refcount structure of the buffer.
385 @buf: a #GstBuffer to get the refcount structure of.
388 <!-- ##### MACRO GST_BUFFER_REFCOUNT_VALUE ##### -->
390 Gets the current refcount value of the buffer.
393 @buf: a #GstBuffer to get the refcount value of.
396 <!-- ##### MACRO GST_BUFFER_COPY_FUNC ##### -->
398 Calls the buffer-specific copy function on the given buffer.
401 @buf: a #GstBuffer to copy.
404 <!-- ##### MACRO GST_BUFFER_FREE_FUNC ##### -->
406 Calls the buffer-specific free function on the given buffer.
409 @buf: a #GstBuffer to free.
412 <!-- ##### MACRO GST_BUFFER_FREE_DATA_FUNC ##### -->
414 A function that should be called if the buffer has no more references left.
415 Elements that utilize hardware memory could use this to re-queue
416 the buffer after it's been unreferenced. If no free_data_func has been
417 provided, the default will be used which simply deallocates the memory
418 region and the GstBuffer object. Manual implementations that want to
419 free their own memory but don't do anything special otherwise are
420 suggested to set the GST_BUFFER_DONTFREE flag on the buffer and call the
421 default data free function (gst_buffer_default_free()) from their manual
425 @buf: the #GstBuffer this function belongs to
428 <!-- ##### USER_FUNCTION GstBufferFreeDataFunc ##### -->
430 the type for the GST_BUFFER_FREE_DATA_FUNC
433 @buffer: the #GstBuffer on which it will operate, when called
436 <!-- ##### MACRO GST_BUFFER_PRIVATE ##### -->
438 Private data for the buffer. This can be used to store a pointer to the
439 object that can then be retrieved in something like the BUFFER_FREE_DATA_FUNC.
442 @buf: the #GstBuffer this data belongs to
445 <!-- ##### MACRO GST_BUFFER_OFFSET_NONE ##### -->
452 <!-- ##### MACRO GST_BUFFER_MAXSIZE_NONE ##### -->
459 <!-- ##### MACRO GST_BUFFER_DURATION_IS_VALID ##### -->
461 Tests if the duration is known.
464 @buffer: the #GstBuffer to check for the duration
467 <!-- ##### MACRO GST_BUFFER_TIMESTAMP_IS_VALID ##### -->
469 Tests if the timestamp is known.
472 @buffer: the #GstBuffer to check for the timestamp
475 <!-- ##### MACRO GST_BUFFER_OFFSET_IS_VALID ##### -->
483 <!-- ##### MACRO GST_BUFFER_OFFSET_END_IS_VALID ##### -->
491 <!-- ##### MACRO GST_BUFFER_MAXSIZE_IS_VALID ##### -->