Introduction to RTP protocol

Real-time transport protocol RTP (real-time Transport protocol) provides end-to-end transport for real-time applications, but does not provide any guarantee of service quality . The multimedia data blocks (audio / video) to be sent are compressed and encoded, and then sent to RTP encapsulation into RTP packets-> RTP packets are loaded into the UDP user datagram of the transport layer-> down to the IP layer-> Then hand over to the data link layer for processing. The receiving process is opposite to the sending process, the process is as follows:
Insert picture description here
In fact, RTP is just a protocol framework. It only contains some common functions of real-time applications. RTP does not do any processing on multimedia data blocks, but only provides some additional information to the application layer to let the application layer know how to handle it.. The RTP protocol can be classified as the application layer, because from the developer's point of view, at the sending and receiving ends of the application, the developer must write the program code that encapsulates the packet and obtains the data block using RTP. RTP can also be considered as a transport layer protocol, because RTP encapsulates the data blocks of multimedia applications and provides services (time stamps and sequence numbers) to multimedia applications, so RTP can also be regarded as a transport layer above UDP Sublayer protocol.
RTP provides end-to-end real-time transmission, and RTP packets only contain RTP data. The control is provided by another supporting RTCP protocol. The port used by RTP is the system port (that is, 1024 ~ 65535), except for an unused even UDP port number, and RTCP in the same session uses the next odd UDP port number, port numbers 5004 and 5005 are used as The default port numbers of RTP and RTCP. So in many places you can see a pair of ports and multicast group addresses .
In the header of the RTP packet, the first 12 bytes are required, and the part after 12 bytes is optional. The following briefly introduces the meaning of each field:

  • Payload type (7bit): This field indicates the format of the subsequent RTP data. The application layer that receives the RTP packet processes according to the type indicated in this field. For video payload: H.261 (31), MPEG1 (32), MPEG1 (33), etc.
  • Sequence number (16bit): Add 1 to the sequence number of each RTP packet sent. The initial sequence number at the beginning of an RTP session is randomly selected. The sequence number enables the receiving end to find the lost packets, and at the same time it can rearrange the out-of-sequence RTP packets in order .
  • Timestamp (32bit): reflects the sampling time of the first byte of data in the RTP packet. The initial value of the time stamp at the beginning of a session is also randomly selected. Even when there is no signal to send, the value of the timestamp must continuously increase with time. Time stamps can be used to eliminate jitter and synchronize audio and video.
  • Synchronization source identifier (32bit): The synchronization source identifier SSRC is used to mark the source of the RTP stream. It is also randomly generated at the beginning of the RTP stream. Because RTP uses UDP transmission, multiple RTP streams can be multiplexed into a UDP user datagram. SSRC can enable the receiving end to send the received RTP stream to their respective end points.
  • Participating source identifier: used to mark RTP streams originating from different locations. The mixing station mixes multiple RTP streams destined for the same location into one stream, and then separates the different RTP streams according to the value of CSRC at the destination station.
  • Number of participating sources (4bit): number of participating source identifiers
  • Version (2bit): currently using version 2
  • Padding P (1bit): In some special cases, the application data block needs to be encrypted, which often requires that each data block has a certain length. If this length requirement is not met, padding is required. Set to 1 indicates that the data of the RTP packet has several padding bytes, and the last byte in the data section is used to indicate the number of bytes filled.
  • Extension X (1bit): X set to 1 means that there is an extension header after this RTP header. The expansion header is rarely used.
  • Mark M (1bit): M set to 1 indicates that this RTP packet has special meaning. For example, when transmitting a video stream, it is used to indicate the start of each frame.
    As mentioned above, the RTP protocol only provides real-time transmission and does not guarantee the quality of service. The quality of service is provided by the Real Time Transport Control Protocol (RTP control Protocol). The main functions of the RTCP protocol are: service quality monitoring and feedback, synchronization between media, and the sign of multicast members. RTCP packets are also transmitted using UDP, but because RTCP packets are very short, multiple RTCP packets can be encapsulated in a UDP user datagram. RTCP packets are periodically transmitted on the Internet.
    RTCP uses five packet types:
  • End packet BYE (203): means to close a data stream
  • Application-specific grouping APP (204): Define a new grouping type to the application.
  • The receiving end reports the packet RR (201): used to enable the receiving end to periodically report to all points in a multicast manner. Each time the receiving end receives an RTP stream, it generates a receiving end report packet RR, which includes: SSRC of the received RTP stream, the packet loss rate, the sequence number of the last RTP packet in the RTP stream, and the packet arrival time Jitter, etc.
Published 35 original articles · Like1 · Visits 1870

Guess you like

Origin blog.csdn.net/lzj_linux188/article/details/104966941
RTP