[asterisk-dev] f->offset - How should it be used ?
Jacob Tinning
tinning at sifira.dk
Thu Apr 20 00:29:20 MST 2006
On Wed, 19 Apr 2006, Kevin P. Fleming wrote:
> Jacob Tinning wrote:
>> I have a question about the offset field in the frame structure.
>> It seems to me that to read the data from a frame, I need these three fields:
>>
>> 1. f->data
>> 2. f->datalen
>> 3. f->offset
>
> The offset tells you how many bytes exist in the buffer _prior_ to the
> data, and are not included in datalen.
>
> or Do I start from f->data and read f->datalen bytes ?
>
> Yes. 'offset' is there in case you need to place some data ahead of the
> actual frame contents (RTP headers, for example), in which case you can
> decrement 'data' and increment 'datalen' by the amount of data you place
> in the buffer ahead of the normal contents.
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.
Also, if placing extra data means 'decrement data and increment datalen',
I think datalen includes the extra data.
It is indeed confusing. Lets try an example:
An imaginary buffer looks like this: |e|e|e|d|d|d|d|d|d|d|
There is a total of 10 bytes. 'e' is extra bytes and 'd' is
the actual frame data (usually audio).
So I would:
buf[0]='e'; buf[1]='e'; buf[2]='e';
buf[3]='d'; buf[4]='d'; buf[5]='d'; buf[6]='d'; buf[7]='d'; buf[8]='d'; buf[9]='d';
f->datalen = 10
f->data = buf;
f->offset = 3;
If this isn't correct, how should it be done then ?
Mvh. Jacob
--
Jacob Tinning
System Developer SIFIRA A/S
More information about the asterisk-dev
mailing list