AMR over RTP:
RTP Packet Size 1389
RTP header size 12
--------
1377
-----------
(1377 / Frame Size) - 1 = Number of ToC Entries; each frame has ToC entry in RTP
Or just count the number of bytes (ToC entries) to identify the frames available in a RTP packet;
How can we extract the AMR mode information from the RTP packet?
First check the CMR (Codec Mode Request) .
It is having bandwidth. For Each bandwidth, the frame size is fixed;
CMR Mode Frame size (bytes)
0 AMR 4.75 13
1 AMR 5.15 14
2 AMR 5.9 16
3 AMR 6.7 18
4 AMR 7.4 20
5 AMR 7.95 21
6 AMR 10.2 27
7 AMR 12.2 32
Every AMR frame is having 20 ms of audio data;
So if 40 frames are available means
40 * 20 = 800 milli seconds (play time of that frames);
1000 milliseconds = 1 second
From Source Filter, Based on Number of Frames we need to set the Start and Stop timestamps.
AMR over RTP is as follows:
+----------------+-------------------+----------------
| payload header | table of contents | speech data ...
+----------------+-------------------+----------------
Payload header is 4 bits;
First 4 bits are CMR (Codec Mode Request); From Codec Mode Request value, we can identify the frame size;
ToC (Table of contents) -
Each and every frame has an entry for the ToC;
If RTP packet is having 43 audio frames means that much of Toc Bytes must be available.
After F0, Remove the same types of bytes; (this byte indicates the audio bit rate information)
But How can we know the Frame Type?
1011 1100 (BC) 12.2 kbps
1011 0100 (B4) 10.2 kbps
1010 1100 (AC) 7.95 kbps
RTP packet:
---------------
If a terminal has no preference in which mode to receive, it SHOULD set CMR=15 in all its outbound payloads
Each RTP AMR data begins with F0 and then ToC entries like 0xac, 0xbc, 0xb4 as repetitive.
If the RTP packet has N frames, RTP packet is having N number of TOC Entries.
From the TOC Entry we can define the frame size of the audio frame;
TOC Entry will be in the following form:
---------------------------------------------
F (1 bit) | FT (4 bits) | 1 (1 bit)
---------------------------------------------
1 0111 1 00 -12.2 kbps ( 0x BC)
1 0110 1 00 -10.2 kbps ( 0x B4)
1 0101 1 00 - 7.95 kbps ( 0x AC)
------------------------------------------------
FO BC BC BC BC BC BC BC BC BC 3C
After the TOC contents, the First start code acts as a frame header;
3C is the frame header available in an audio frame and every audio frame must begins with 3C;
From the bit rate, we can determine the Frame Size;
CMR Mode Frame size (bytes)
0 AMR 4.75 13
1 AMR 5.15 14
2 AMR 5.9 16
3 AMR 6.7 18
4 AMR 7.4 20
5 AMR 7.95 21
6 AMR 10.2 27
7 AMR 12.2 32
Frame Size is including a frame header;
But RTP packet is having the frames as follows:
First Frame alone has the 1 byte audio frame header; rest of the frames will not have header; we need to add it manually;
Ac 12 20 39 40 29 20 39 33
Ac is a frame header and from the header onwards we can identify the number of bytes per frame; assume that if the frame header info as 4.75kbps having frame size 13 means from the frame header, count the 13 bytes; then next insert the First frame’s frame header and count the 13 bytes from the header and then insert the frame header for 3rd frame;
1st Frame Header bytes After 13 bytes insert the First Frame’s header, then next insert the frame header after the 26 bytes and next insert the frame header after the 39 bytes. Do it repeatedly.
If we have not inserted the frame header at the every frame start, then it will be decoded by the AMR decoder but u will not have any hearable audio.
1 Comments:
Excellent post. Helped me a lot. Keep up the good work!
Post a Comment
<< Home