The structure of a RTP packet
The real-time media that is being transferred forms the 'RTP Payload'.
RTP header contains information related to the payload e.g. the source, size, encoding type etc.
However the RTP packet can't be transferred as it is over the network.
For transferring we use a transfer protocol called User Datagram Protocol (UDP).
To transfer the UDP packet over the IP network, we need to encapsulate it with a IP packet.
RTP Payload中存儲著被傳送的實時媒體數(shù)據(jù).
RTP Header
Sequence Number
The sequence number increments by one for each RTP data packet sent, and may be used by the receiver to detect packet loss and to restore packet sequence.
The loss or out-of-order delivery occurs due network problems.
- sequence number隨著發(fā)送依次增長+1.
- 可供receiver來判斷是否有數(shù)據(jù)丟失.
Timestamp
timestamp: 32 bits
The timestamp reflects the sampling instant of the first octet(八位字節(jié)) in the RTP data packet.
The sampling instant must be derived from a clock that increments monotonically and linearly in time to allow synchronization and jitter calculations.
- Timestamp: 該RTP包中第一個字節(jié)的采樣時刻.
- 時間戳有一個初始值伤锚,隨著時間而不斷增加.
- 即使此時沒有包被發(fā)出趋艘,時間戳也會不斷增加.
- 時間戳是實現(xiàn)去除抖動和實現(xiàn)同步必不可少的.
- 需要注意的是timestamp的位數(shù):32bit.
Several consecutive(連續(xù)的) RTP packets may have equal timestamps if they are (logically) generated at once, e.g., belong to the same video frame.
Consecutive RTP packets may contain timestamps that are not monotonic(無變化的) if the data is not transmitted in the order it was sampled, as in the case of MPEG interpolated video frames.
(The sequence numbers of the packets as transmitted will still be monotonic.)
So the sequence number is not enough for synchronization.
You already know that in a audio/video session audio and video data are transmitted using separate channels (if you don't know this, please go through applications of RTP).
The receiver matches the video data with corresponding audio data using timestamp.
- 一些連續(xù)的RTP包可能擁有相同的時間戳, 因為他們屬于同一幀.
- 音頻和視頻數(shù)據(jù)是分別傳輸?shù)?/strong>.
- 數(shù)據(jù)的接收者利用時間戳將視頻和音頻進行匹配.
References:
http://www.siptutorial.net/RTP/packetrtp.html
http://www.siptutorial.net/RTP/header.html
http://www.siptutorial.net/RTP/synchro.html
http://blog.csdn.net/ithzhang/article/details/38346557