H264 Video Transmission, Codec--RTP/RTCP/RTSP Protocol Data Transfer Based on UDP or TCP

Keywords: Session network encoding socket

In a simple sentence: RTSP initiation/termination control streaming media, RTP transmission streaming media data, RTCP control and synchronization of RTP data.

Typically, the RTSP protocol uses TCP protocol to transmit instructions to control streaming media, and the RTP/RTCP protocol uses UDP mode to transmit instructions.But sometimes RTSP protocol data can also use UDP, or RTP/RTCP can also use TCP;

1. RTSP protocol uses TCP protocol to transmit instructions to control streaming media, RTP/RTCP protocol uses UDP mode to transmit instructions.

 

  • TCP protocol provides reliable services based on links and RTSP protocol control instructions can be sent/received successfully
  • UDP has no links, does not provide reliable services, and may lose packets.
  • RTSP protocol requires 1 pair of ports, RTP/RTCP requires 2 pairs of ports; (client and server)

 

2. RTSP/RTP/RTCP are all transmitted using UDP:

 

  • Three pairs of ports are required;
  • UDP has no links, does not provide reliable services, and may lose packets.

 

3. RTSP/RTP/RTCP are all transmitted by TCP

 

  • RTSP/RTP control commands and data interact through a port, the RTSP port (default is 554).RTCP uses a pair of ports;
  • TCP protocol provides reliable streaming and packet loss can be retransmitted.
  • TCP packets are easier to penetrate intermediate network routers.
  • This makes packaging and unpacking of RTSP/RTP/RTCP more complex, makes encoding more difficult, and requires additional protocol support for binary interleaving.
  • Slow startup speed, larger TCP header than UDP header, and bandwidth consumption will affect the real-time performance of RTP streaming media data, resulting in delays in real-time streaming.

However, using TCP to transfer RTSP/RTP still exists, see how this process is performed:

When RTSP/RTP is hosted using the TCP protocol, all RTSP commands and RTP streaming data are sent through the RTSP port (usually 554).At the same time, the data will be sent only after the protocol processing which can distinguish the two types of data.

Next, take a look at the main process of notifying a server to host RTSP/RTP using TCP

 

 

SETUP

To use a TCP connection, RTSP clients need to request a TCP connection during the SETUP phase.The SETUP command should include Transport in the following format:

Transport: RTP/AVP/TCP;interleaved=0-1

The above Transport will tell the server to send media data using the TCP protocol and interweave the streaming data and control information using Channel 0 and 1.More specifically, use even channel as data transmission channel RTP and odd channel as control channel (data channel + 1) RTSP.So if you set the data channel to 0, the control channel should be 0 + 1 = 1.

SETUP rtsp://192.168.100.123:554/mpeg4cif/track1 RTSP/1.0
CSeq: 4
User-Agent: LibVLC/2.2.4 (LIVE555 Streaming Media v2016.02.22)
Transport: RTP/AVP/TCP;unicast;interleaved=0-1  //RTP/AVP defaults to UDP

After SETUP, RTP data is sent through the TCP Socket used to send RTSP commands.RTP data will be encapsulated in the following formats:

 

| magic number | channel number | data length | data  | 

magic number: RTP data identifier, "$" a byte
 channel number: channel number - 1 byte to indicate channel
 Data length: data length - 2 bytes, indicating the length of inserted data
 Data: data - e.g. RTP packages, total length is the same as above

 

RTP, RTCP and RTSP data share TCP data channels, so there must be an identity to distinguish the three types of data.

RTP and RTCP data start with a $symbol + 1 byte channel number + 2 bytes of data length, a total of 4 bytes of prefix. RTSP data is not prefixed.The difference between RTP data and RTCP data is the channel number of the second byte.

Here is a complete interactive process:

 

OPTIONS rtsp://222.201.145.236/slamtv60.264 RTSP/1.0
CSeq: 2
User-Agent: LibVLC/1.1.11 (LIVE555 Streaming Media v2011.05.25)

RTSP/1.0 200 OK
CSeq: 2
Date: Wed, Mar 07 2012 03:48:07 GMT
Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER
DESCRIBE rtsp://222.201.145.236/slamtv60.264 RTSP/1.0
CSeq: 3
User-Agent: LibVLC/1.1.11 (LIVE555 Streaming Media v2011.05.25)
Accept: application/sdp

RTSP/1.0 200 OK
CSeq: 3
Date: Wed, Mar 07 2012 03:48:07 GMT
Content-Base: rtsp://222.201.145.236/slamtv60.264/
Content-Type: application/sdp
Content-Length: 527

v=0
o=- 1331092087436965 1 IN IP4 222.201.145.236 
s=H.264 Video, streamed by the LIVE555 Media Server
i=slamtv60.264//Media Name
a=type:broadcast  Broadcast mode
a=control:*
a=range:npt=0-
m=video 0 RTP/AVP 96 //Media Type+Port+Transport Protocol+Format List
c=IN IP4 0.0.0.0
b=AS:500
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;profile-level-id=4D4033;sprop-parameter-sets=Z01AM5JUDAS0IAAAAwBAAAAM0eMGVA==,aO48gA==
a=control:track1
SETUP rtsp://222.201.145.236/slamtv60.264/track1 RTSP/1.0
CSeq: 4
User-Agent: LibVLC/1.1.11 (LIVE555 Streaming Media v2011.05.25)
Transport: RTP/AVP/TCP;unicast; interleaved=0-1
//Transport: Transport Protocol + Propagation Mode (Unicast or Multicast) + Channel Number.

RTSP/1.0 200 OK
CSeq: 4
Date: Wed, Mar 07 2012 03:48:18 GMT
Transport: RTP/AVP/TCP;unicast;destination=125.216.243.188;source=222.201.145.236;interleaved=0-1
Session: 289BFEAERTP/AVP/TCP;unicast; interleaved=0-1
//Transport: Transport Protocol + Propagation Mode (Unicast or Multicast) + Channel Number.

RTSP/1.0 200 OK
CSeq: 4
Date: Wed, Mar 07 2012 03:48:18 GMT
Transport: RTP/AVP/TCP;unicast;destination=125.216.243.188;source=222.201.145.236;interleaved=0-1
Session: 289BFEAE
PLAY rtsp://222.201.145.236/slamtv60.264/ RTSP/1.0
CSeq: 5
User-Agent: LibVLC/1.1.11 (LIVE555 Streaming Media v2011.05.25)
Session: 289BFEAE
Range: npt=0.000-

RTSP/1.0 200 OK
CSeq: 5
Date: Wed, Mar 07 2012 03:48:18 GMT
Range: npt=0.000-
Session: 289BFEAE
RTP-Info: url=rtsp://222.201.145.236/slamtv60.264/track1;seq=61622;rtptime=1335382752

http://blog.csdn.net/machh

https://github.com/EasyDarwin/Course

 

Posted by kiss_FM on Thu, 16 May 2019 16:50:22 -0700