[asterisk-dev] f->offset - How should it be used ?

Kevin P. Fleming kpfleming at digium.com
Thu Apr 20 06:42:27 MST 2006


Jacob Tinning wrote:

> I don't quite undestand. If I want to read a frame and whatever gave me
> the frame, has placed something ahead of the actual data, I thought I
> should start from f->data + f->offset and read f->datalen bytes.

I don't believe there are currently any situations where you will be
handed a frame with data added in before the audio/video data. The
'offset' is there so that the final consumer of the frame can add
header(s) before performing its final action on the frame (sending
across the network, storing into a file, etc). Its sole purpose is to
keep that final consumer from having to copy the frame's data into
another buffer just to be able to prepend headers.

In any case: f->offset tells you how many bytes of space have been
allocated to the frame _before_ the point that f->data points to. If the
frame was created to hold a 20ms sample of ulaw data, with the standard
AST_FRIENDLY_OFFSET, then the _true_ data buffer will be 160 +
AST_FRIENDLY_OFFSET bytes, f->data will point to the beginning of that
buffer + AST_FRIENDLY_OFFSET, f->datalen will be 160 and f->offset will
be AST_FRIENDLY_OFFSET.



More information about the asterisk-dev mailing list