summaryrefslogtreecommitdiff
path: root/docs/gst/tmpl/gstbuffer.sgml
blob: 2f1da35ba99eae068f2670722eb1b3e05d158a7d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
<!-- ##### SECTION Title ##### -->
GstBuffer

<!-- ##### SECTION Short_Description ##### -->
Data-passing buffer type, supporting sub-buffers.

<!-- ##### SECTION Long_Description ##### -->
<para>
Buffers are the basic unit of data transfer in GStreamer.  The GstBuffer type
provides all the state necessary to define a region of memory as part of a
stream.  Sub-buffers are also supported, allowing a smaller region of a
buffer to become its own buffer, with mechanisms in place to ensure that
neither memory space goes away. 
</para>
<para>
Buffers are usually created with gst_buffer_new(). After a buffer has been 
created one will typically allocate memory for it and set the size of the 
buffer data.  The following example creates a buffer that can hold a given
video frame with a given width, height and bits per plane.
<programlisting>
  GstBuffer *buffer;
  gint size, width, height, bpp;

  ...

  size = width * height * bpp;

  buffer = gst_buffer_new ();
  GST_BUFFER_SIZE (buffer) = size;
  GST_BUFFER_DATA (buffer) = g_alloc (size);
  ...
</programlisting>
</para>
<para>
Alternatively, use gst_buffer_new_and_alloc() 
to create a buffer with preallocated
data of a given size.
</para>
<para>
gst_buffer_ref() is used to increase the refcount of a buffer. This must be
done when you want to keep a handle to the buffer after pushing it to the
next element.
</para>
<para>
To efficiently create a smaller buffer out of an existing one, you can
use gst_buffer_create_sub().
</para>
<para>
If the plug-in wants to modify the buffer in-place, it should first obtain
a buffer that is safe to modify by using gst_buffer_copy_on_write().  This
function is optimized so that a copy will only be made when it is necessary.
</para>
<para>
Several flags of the buffer can be set and unset with the GST_BUFFER_FLAG_SET()
and GST_BUFFER_FLAG_UNSET() macros. Use GST_BUFFER_FLAG_IS_SET() to test it
a certain #GstBufferFlag is set.
</para>
<para>
Buffers can be efficiently merged into a larger buffer with gst_buffer_merge() and
gst_buffer_span() if the gst_buffer_is_span_fast() function returns TRUE.
</para>
<para>
An element should either unref the buffer or push it out on a src pad
using gst_pad_push() (see #GstPad).

Buffers usually are freed by unreffing them with gst_buffer_unref().
Do not use gst_buffer_free() : this function effectively frees the buffer
regardless of the refcount, which is dangerous.
</para>

<para>
Last reviewed on August 30th, 2002 (0.4.0.1)
</para>

<!-- ##### SECTION See_Also ##### -->
<para>
#GstBufferPool, #GstPad, #GstData
</para>

<!-- ##### STRUCT GstBuffer ##### -->
<para>
The basic structure of a buffer.
</para>

@data_type: 
@data: 
@size: 
@maxsize: 
@timestamp: 
@duration: 
@offset: 
@offset_end: 
@free_data: 
@buffer_private: 
@_gst_reserved: 

<!-- ##### USER_FUNCTION GstBufferFreeDataFunc ##### -->
<para>

</para>

@buffer: 


<!-- ##### MACRO GST_BUFFER_TRACE_NAME ##### -->
<para>
The name used for tracing memory allocations
</para>



<!-- ##### MACRO GST_BUFFER_REFCOUNT ##### -->
<para>
Gets a handle to the refcount structure of the buffer.
</para>

@buf: a #GstBuffer to get the refcount structure of.


<!-- ##### MACRO GST_BUFFER_REFCOUNT_VALUE ##### -->
<para>
Gets the current refcount value of the buffer.
</para>

@buf: a #GstBuffer to get the refcount value of.


<!-- ##### MACRO GST_BUFFER_COPY_FUNC ##### -->
<para>
Calls the buffer-specific copy function on the given buffer.
</para>

@buf: a #GstBuffer to copy.


<!-- ##### MACRO GST_BUFFER_FREE_FUNC ##### -->
<para>
Calls the buffer-specific free function on the given buffer.
</para>

@buf: a #GstBuffer to free.


<!-- ##### MACRO GST_BUFFER_FLAGS ##### -->
<para>
Gets the flags from this buffer.
</para>

@buf: a #GstBuffer to retrieve the flags from.


<!-- ##### MACRO GST_BUFFER_FLAG_IS_SET ##### -->
<para>
Gives the status of a given flag of a buffer.
</para>

@buf: a #GstBuffer to query flags of.
@flag: the #GstBufferFlag to check.


<!-- ##### MACRO GST_BUFFER_FLAG_SET ##### -->
<para>
Sets a buffer flag.
</para>

@buf: a #GstBuffer to modify flags of.
@flag: the #GstBufferFlag to set.


<!-- ##### MACRO GST_BUFFER_FLAG_UNSET ##### -->
<para>
Clears a buffer flag.
</para>

@buf: a #GstBuffer to modify flags of.
@flag: the #GstBufferFlag to clear.


<!-- ##### MACRO GST_BUFFER_DATA ##### -->
<para>
Retrieves a pointer to the data element of this buffer.
</para>

@buf: a #GstBuffer to get data pointer of.
@Returns: the pointer to the actual data contents of the buffer.


<!-- ##### MACRO GST_BUFFER_SIZE ##### -->
<para>
Gets the size of the data in this buffer.
</para>

@buf: a #GstBuffer to get data size of.


<!-- ##### MACRO GST_BUFFER_MAXSIZE ##### -->
<para>
Gets the maximum size of this buffer.
</para>

@buf: a #GstBuffer to get maximum size of.


<!-- ##### MACRO GST_BUFFER_TIMESTAMP ##### -->
<para>
Gets the timestamp for this buffer.
</para>

@buf: a #GstBuffer to get timestamp of.


<!-- ##### MACRO GST_BUFFER_DURATION ##### -->
<para>

</para>

@buf: 


<!-- ##### MACRO GST_BUFFER_OFFSET ##### -->
<para>
Gets the offset in the source file of this buffer.
</para>

@buf: a #GstBuffer to get offset of.


<!-- ##### MACRO GST_BUFFER_OFFSET_END ##### -->
<para>

</para>

@buf: 


<!-- ##### MACRO GST_BUFFER_FREE_DATA_FUNC ##### -->
<para>

</para>

@buf: 


<!-- ##### MACRO GST_BUFFER_PRIVATE ##### -->
<para>

</para>

@buf: 


<!-- ##### MACRO GST_BUFFER_OFFSET_NONE ##### -->
<para>

</para>



<!-- ##### MACRO GST_BUFFER_MAXSIZE_NONE ##### -->
<para>

</para>



<!-- ##### MACRO GST_BUFFER_DURATION_IS_VALID ##### -->
<para>

</para>

@buffer: 


<!-- ##### MACRO GST_BUFFER_TIMESTAMP_IS_VALID ##### -->
<para>

</para>

@buffer: 


<!-- ##### MACRO GST_BUFFER_OFFSET_IS_VALID ##### -->
<para>

</para>

@buffer: 


<!-- ##### MACRO GST_BUFFER_OFFSET_END_IS_VALID ##### -->
<para>

</para>

@buffer: 


<!-- ##### MACRO GST_BUFFER_MAXSIZE_IS_VALID ##### -->
<para>

</para>

@buffer: 


<!-- ##### ENUM GstBufferFlag ##### -->
<para>
A set of buffer flags used to describe properties of a #GstBuffer.
</para>

@GST_BUFFER_READONLY: the buffer is read-only.
@GST_BUFFER_SUBBUFFER: the buffer is a subbuffer, the parent buffer can be 
                       found with the GST_BUFFER_POOL_PRIVATE() macro.
@GST_BUFFER_ORIGINAL: buffer is not a copy of another buffer.
@GST_BUFFER_DONTFREE: do not try to free the data when this buffer is 
                      unreferenced.
@GST_BUFFER_KEY_UNIT: the buffer holds a key unit, a unit that can be 
                      decoded independently of other buffers.
@GST_BUFFER_DONTKEEP: 
@GST_BUFFER_FLAG_LAST: additional flags can be added starting from this flag.

<!-- ##### FUNCTION gst_buffer_new ##### -->
<para>

</para>

@Returns: 


<!-- ##### FUNCTION gst_buffer_new_and_alloc ##### -->
<para>

</para>

@size: 
@Returns: 


<!-- ##### MACRO gst_buffer_set_data ##### -->
<para>
A convenience function to set the data and size on a buffer
</para>

@buf: The buffer to modify
@data: The data to set on the buffer
@size: The size to set on the buffer


<!-- ##### MACRO gst_buffer_ref ##### -->
<para>
Increases the refcount of the given buffer by one.
</para>

@buf: a #GstBuffer to increase the refcount of.


<!-- ##### MACRO gst_buffer_ref_by_count ##### -->
<para>
Increases the refcount of the buffer by the given value. 
</para>

@buf: a #GstBuffer to increase the refcount of.
@c: the value to add to the refcount.


<!-- ##### MACRO gst_buffer_unref ##### -->
<para>
Decreases the refcount of the buffer. If the refcount reaches 0, the buffer
will be freed.
</para>

@buf: a #GstBuffer to unref.


<!-- ##### FUNCTION gst_buffer_stamp ##### -->
<para>

</para>

@dest: 
@src: 


<!-- ##### MACRO gst_buffer_copy ##### -->
<para>
Copies the given buffer using the copy function of the parent GstData structure.
</para>

@buf: a #GstBuffer to copy.
@Returns: a new #GstBuffer copy of the buffer.


<!-- ##### MACRO gst_buffer_is_writable ##### -->
<para>

</para>

@buf: 


<!-- ##### MACRO gst_buffer_copy_on_write ##### -->
<para>
This function returns a buffer that is safe to write to.
Copy the buffer if the refcount > 1 so that the newly 
created buffer can be safely written to. 
If the refcount is 1, this function just returns the original buffer.
</para>

@buf: a #GstBuffer to copy
@Returns: the #GstBuffer that can safely be written to.


<!-- ##### FUNCTION gst_buffer_create_sub ##### -->
<para>

</para>

@parent: 
@offset: 
@size: 
@Returns: 


<!-- ##### FUNCTION gst_buffer_join ##### -->
<para>

</para>

@buf1: 
@buf2: 
@Returns: 


<!-- ##### FUNCTION gst_buffer_merge ##### -->
<para>

</para>

@buf1: 
@buf2: 
@Returns: 


<!-- ##### FUNCTION gst_buffer_is_span_fast ##### -->
<para>

</para>

@buf1: 
@buf2: 
@Returns: 


<!-- ##### FUNCTION gst_buffer_span ##### -->
<para>

</para>

@buf1: 
@offset: 
@buf2: 
@len: 
@Returns: 


<!-- ##### FUNCTION gst_buffer_default_free ##### -->
<para>

</para>

@buffer: 


<!-- ##### FUNCTION gst_buffer_default_copy ##### -->
<para>

</para>

@buffer: 
@Returns: