1 <chapter id="cha-buffers">
4 Buffers contain the data that will flow through the pipeline you have
5 created. A source element will typically create a new buffer and pass
6 it through a pad to the next element in the chain. When using the
7 GStreamer infrastructure to create a media pipeline you will not have
8 to deal with buffers yourself; the elements will do that for you.
11 The most important information in the buffer is:
16 A pointer to a piece of memory.
21 The size of the memory.
26 A refcount that indicates how many elements are using this
27 buffer. This refcount will be used to destroy the buffer when no
28 element is having a reference to it.
35 GStreamer provides functions to create custom buffer create/destroy algorithms, called
36 a <classname>GstBufferPool</classname>. This makes it possible to efficiently
37 allocate and destroy buffer memory. It also makes it possible to exchange memory between
38 elements by passing the <classname>GstBufferPool</classname>. A video element can,
39 for example, create a custom buffer allocation algorithm that creates buffers with XSHM
40 as the buffer memory. An element can use this algorithm to create and fill the buffer
45 The simple case is that a buffer is created, memory allocated, data put
46 in it, and passed to the next element. That element reads the data, does
47 something (like creating a new buffer and decoding into it), and
48 unreferences the buffer. This causes the data to be freed and the buffer
49 to be destroyed. A typical MPEG audio decoder works like this.
53 A more complex case is when the filter modifies the data in place. It
54 does so and simply passes on the buffer to the next element. This is just
55 as easy to deal with. An element that works in place has to be careful when
56 the buffer is used in more than one element; a copy on write has to made in this