Caps and audio buffer layout

Sebastian Dröge sebastian at centricular.com
Wed Nov 6 02:35:40 PST 2013


On Mi, 2013-11-06 at 01:05 -0800, Blazej wrote:
> Hello,
> 
> First of all, sorry if the answer to my question was already posted here,
> but I couldn't find it. 
> 
> So, I need to access raw audio data. By following some tutorials I was able
> to create a simple pipeline with appsink in C (gstreamer-0.10), and I can
> access the data buffer from appsink's "new-buffer" callback. But I have no
> idea about the actual layout of the data in the buffer. I am using the
> following caps in appsink (copied from somewhere):
> 
> *"audio/x-raw-int,channels=2,rate=44100,signed=(boolean)true,width=16,depth=16,endianness=BYTE_ORDER"*
> 
> I assume I can get the data pointer with GST_BUFFER_DATA() and its size with
> GST_BUFFER_SIZE(). But I have some more questions:
> * how should I interpret 'width' and 'depth' parameter? 
> * Is the data interleaved since there are 2 channels there? 
> * what does the 'endianness=BYTE_ORDER' mean?

Ideally you would update to GStreamer 1.x, 0.10 is no longer maintained
since almost 2 years now and 1.x has improved/simplified the raw audio
caps a lot and made them more intuitive.

For your questions:
* width is the actual number of bits occupied by a single sample, so you
  have GST_BUFFER_SIZE (buf) / (width / 8) samples in a buffer (note:
  divide by the number of channels again to get the number of "frames").
* you have first a sample for the first channel, then a sample for the
  second channel, then the next sample for the first channel, etc.
  if no channel-layout (channel-mask in 1.x) is given on the caps and
  you have two channels, the first one is left and the second right.
* endianness=BYTE_ORDER means that the samples are in native byte order,
  i.e. in your case you can just read the samples as uint16_t and do
  arithmetic on them without converting from e.g. big endian to little
  endian (assuming you run on a little endian system).

-- 
Sebastian Dröge <sebastian at centricular.com>
Centricular Ltd - http://www.centricular.com
Expertise, Straight from the Source
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 966 bytes
Desc: This is a digitally signed message part
URL: <http://lists.freedesktop.org/archives/gstreamer-devel/attachments/20131106/1f7f3228/attachment-0001.pgp>


More information about the gstreamer-devel mailing list