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_MALLOCDATA (buffer) = g_alloc (size);
33 GST_BUFFER_DATA (buffer) = GST_BUFFER_MALLOCDATA (buffer);
39 Alternatively, use gst_buffer_new_and_alloc()
40 to create a buffer with preallocated data of a given size.
43 If an element knows what pad you will push the buffer out on, it should use
44 gst_pad_alloc_buffer() instead to create a buffer. This allows downstream
45 elements to provide special buffers to write in, like hardware buffers.
48 gst_buffer_ref() is used to increase the refcount of a buffer. This must be
49 done when you want to keep a handle to the buffer after pushing it to the
53 To efficiently create a smaller buffer out of an existing one, you can
54 use gst_buffer_create_sub().
57 If the plug-in wants to modify the buffer in-place, it should first obtain
58 a buffer that is safe to modify by using gst_buffer_make_writable(). This
59 function is optimized so that a copy will only be made when it is necessary.
62 Several flags of the buffer can be set and unset with the GST_BUFFER_FLAG_SET()
63 and GST_BUFFER_FLAG_UNSET() macros. Use GST_BUFFER_FLAG_IS_SET() to test it
64 a certain #GstBufferFlag is set.
67 Buffers can be efficiently merged into a larger buffer with gst_buffer_merge() and
68 gst_buffer_span() if the gst_buffer_is_span_fast() function returns TRUE.
71 An element should either unref the buffer or push it out on a src pad
72 using gst_pad_push() (see #GstPad).
74 Buffers usually are freed by unreffing them with gst_buffer_unref().
75 Do not use gst_buffer_free() : this function effectively frees the buffer
76 regardless of the refcount, which is dangerous.
80 Last reviewed on August 12th, 2004 (0.8.5)
83 <!-- ##### SECTION See_Also ##### -->
85 #GstPad, #GstMiniObject
88 <!-- ##### STRUCT GstBuffer ##### -->
90 The basic structure of a buffer.
102 <!-- ##### FUNCTION gst_buffer_new ##### -->
110 <!-- ##### FUNCTION gst_buffer_new_and_alloc ##### -->
119 <!-- ##### ENUM GstBufferFlag ##### -->
124 @GST_BUFFER_FLAG_READONLY:
125 @GST_BUFFER_FLAG_ORIGINAL:
126 @GST_BUFFER_FLAG_PREROLL:
127 @GST_BUFFER_FLAG_DISCONT:
128 @GST_BUFFER_FLAG_IN_CAPS:
129 @GST_BUFFER_FLAG_GAP:
130 @GST_BUFFER_FLAG_DELTA_UNIT:
131 @GST_BUFFER_FLAG_LAST:
133 <!-- ##### MACRO GST_BUFFER_FLAGS ##### -->
135 Gets the flags from this buffer.
138 @buf: a #GstBuffer to retrieve the flags from.
141 <!-- ##### MACRO GST_BUFFER_FLAG_IS_SET ##### -->
143 Gives the status of a given flag of a buffer.
146 @buf: a #GstBuffer to query flags of.
147 @flag: the #GstBufferFlag to check.
150 <!-- ##### MACRO GST_BUFFER_FLAG_SET ##### -->
155 @buf: a #GstBuffer to modify flags of.
156 @flag: the #GstBufferFlag to set.
159 <!-- ##### MACRO GST_BUFFER_FLAG_UNSET ##### -->
161 Clears a buffer flag.
164 @buf: a #GstBuffer to modify flags of.
165 @flag: the #GstBufferFlag to clear.
168 <!-- ##### MACRO gst_buffer_set_data ##### -->
170 A convenience function to set the data and size on a buffer
173 @buf: The buffer to modify
174 @data: The data to set on the buffer
175 @size: The size to set on the buffer
178 <!-- ##### MACRO GST_BUFFER_DATA ##### -->
180 Retrieves a pointer to the data element of this buffer.
183 @buf: a #GstBuffer to get data pointer of.
184 @Returns: the pointer to the actual data contents of the buffer.
187 <!-- ##### MACRO GST_BUFFER_SIZE ##### -->
189 Gets the size of the data in this buffer.
192 @buf: a #GstBuffer to get data size of.
195 <!-- ##### MACRO GST_BUFFER_TIMESTAMP ##### -->
197 Gets the timestamp for this buffer.
200 @buf: a #GstBuffer to get timestamp of.
203 <!-- ##### MACRO GST_BUFFER_DURATION ##### -->
205 Gets the duration in nanoseconds of the data in the buffer.
206 Value will be GST_CLOCK_TIME_NONE if the duration is unknown.
209 @buf: a #GstBuffer to get the duration from.
212 <!-- ##### MACRO GST_BUFFER_OFFSET ##### -->
214 Gets the offset in the source file of the beinning of this buffer.
217 @buf: a #GstBuffer to get offset of.
220 <!-- ##### MACRO GST_BUFFER_OFFSET_END ##### -->
222 Gets the offset in the source file of the end of this buffer.
225 @buf: a #GstBuffer to get offset of.
228 <!-- ##### MACRO gst_buffer_ref ##### -->
230 Increases the refcount of the given buffer by one.
233 @buf: a #GstBuffer to increase the refcount of.
236 <!-- ##### MACRO gst_buffer_unref ##### -->
238 Decreases the refcount of the buffer. If the refcount reaches 0, the buffer
242 @buf: a #GstBuffer to unref.
245 <!-- ##### MACRO gst_buffer_copy ##### -->
247 Copies the given buffer using the copy function of the parent GstData structure.
250 @buf: a #GstBuffer to copy.
251 @Returns: a new #GstBuffer copy of the buffer.
254 <!-- ##### MACRO gst_buffer_is_writable ##### -->
256 Tests if you can safely write data into a buffer's data array.
259 @buf: a #GstBuffer to check
262 <!-- ##### MACRO gst_buffer_make_writable ##### -->
270 <!-- ##### MACRO gst_buffer_replace ##### -->
279 <!-- ##### FUNCTION gst_buffer_get_caps ##### -->
288 <!-- ##### FUNCTION gst_buffer_set_caps ##### -->
297 <!-- ##### FUNCTION gst_buffer_create_sub ##### -->
308 <!-- ##### FUNCTION gst_buffer_is_span_fast ##### -->
318 <!-- ##### FUNCTION gst_buffer_span ##### -->
330 <!-- ##### MACRO GST_BUFFER_TRACE_NAME ##### -->
332 The name used for tracing memory allocations
337 <!-- ##### MACRO GST_BUFFER_OFFSET_NONE ##### -->
344 <!-- ##### MACRO GST_BUFFER_DURATION_IS_VALID ##### -->
346 Tests if the duration is known.
349 @buffer: the #GstBuffer to check for the duration
352 <!-- ##### MACRO GST_BUFFER_TIMESTAMP_IS_VALID ##### -->
354 Tests if the timestamp is known.
357 @buffer: the #GstBuffer to check for the timestamp
360 <!-- ##### MACRO GST_BUFFER_OFFSET_IS_VALID ##### -->
368 <!-- ##### MACRO GST_BUFFER_OFFSET_END_IS_VALID ##### -->
376 <!-- ##### FUNCTION gst_buffer_stamp ##### -->
385 <!-- ##### FUNCTION gst_buffer_join ##### -->
395 <!-- ##### FUNCTION gst_buffer_merge ##### -->