[Asterisk-video] if2 bit stuffing in app_h324m
Klaus Darilion
klaus.mailinglists at pernau.at
Tue Jul 31 11:21:20 CDT 2007
Francesco Emmi wrote:
> Klaus Darilion wrote:
>> Ok. Can you please help me to understand the bit encodings?
>>
>> I think I understand the RFC 4867 format - e.g: mode 7 uses 244 bits.
>> Network order with most significant byte/bit first. Thus
>>
> So, let' s suppose we are dealing with mode 7 and you have a IF1 frame.
> It's 244 bits long. So 31 bytes ( with 4 bits stuffing at the end ) + 1
> header byte containing amr mode (a total of 32 bytes):
>
> 3c 08 5a 5f 8c 44 50 44 4c cd 45 2f 25 75 43 13 80 00 01 19 e0 8a 22 10
> 00 00 de 51 3e 87 3d 80
>
> Suppose buf[32] contains this amr MIME frame. So
>
>
> mode = (buf[0] >> 3) & 0x0f = 7
> b0 = buf[1] & (1 << 7)
> b1 = buf[1] & (1 << 6)
> ...
> b6 = buf[1] & (1 << 1)
> b7 = buf[2] & (1 << 0)
> ...
> b243 = buf[31] & (1 << 5)
> b244 = buf[31] & (1 << 4)
I guess the end should be following (as we start from 0):
b242 = buf[31] & (1 << 5)
b243 = buf[31] & (1 << 4)
> Last 4 bits of buf[31] are zero suffing.
>
> This means that b0...b244 is just
> 08 5a 5f 8c 44 50 44 4c cd 45 2f 25 75 43 13 80 00 01 19 e0 8a 22 10
> 00 00 de 51 3e 87 3d 80 without last 4 bits.
OK.
>> Then, if this is transformed to if2 - I would think it should be following:
>>
>> AMR mode bit 0 -> buf[0] | (1 << 7)
>> AMR mode bit 1 -> buf[0] | (1 << 6)
>> AMR mode bit 2 -> buf[0] | (1 << 5)
>> AMR mode bit 3 -> buf[0] | (1 << 4)
>>
>> AMR bit 0 -> buf[0] | (1 << 3)
>> AMR bit 1 -> buf[0] | (1 << 2)
>> AMR bit 2 -> buf[0] | (1 << 1)
>> AMR bit 3 -> buf[0] | (1 << 0)
>> AMR bit 4 -> buf[1] | (1 << 7)
>> AMR bit 5 -> buf[1] | (1 << 6)
>> AMR bit 6 -> buf[1] | (1 << 5)
>> AMR bit 7 -> buf[1] | (1 << 4)
>> AMR bit 8 -> buf[1] | (1 << 3)
>> AMR bit 9 -> buf[1] | (1 << 2)
>> ...
>>
>> AMR bit 242 -> buf[30] | (1 << 1)
>> AMR bit 243 -> buf[30] | (1 << 0)
>>
>>
>> Is this correct?
>>
>>
> The Correct way is just a bit more complicated. Let say bn the n-th amr
> bit , buf an array containing MIME (if1) frame and REV(buf[i]) the bit
> reverse of buf[i]:
>
> if2[0] = ((b3 b2 b1 b0 )& 0xF0) | (mode & 0x0f) = (REV(buf[1]) & 0xF0) |
> (mode & 0x0f)
Thus, if2 does not use network bit order? Or is it only h324m which does
not use network bit order?
Now I know how it is done - but why? Is this somewhere specified in
standard?
btw: Why is the mode not bit-reversed? If it is about bit order in
general I would think that "mode" must be reversed too?
thanks
klaus
> if2[1] = (b11 b10 b9 b8 b7 b6 b5 b4)=(REV(buf[2]) & 0xF0) | REV(buf[1] &
> 0x0f)
> if2[2] =(b19 b18 b17 b16 b15 b14 b13 b12)=REV(buf[3]&0xF0) |
> REV(buf[2])&0x0f
> ...
> if2[29]=(b235 b234 b233 b232 b231 b230 b229 b228) = ...
>
> if2[30] = (b243 b242 b241 b240 b239 b238 b237 b236) =
> REV(b[31])&0xf0 | REV(b[30])&0x0f
>
> Notice that we are not using b[31]&0x0f as it contains only zero padding.
>
> I hope this helps you. (I believe it is simpler to do that to explain :-) )
>
> Regards
> Francesco
More information about the asterisk-video
mailing list