Normally, RTSP provide streaming over UDP. By nature, UDP is a better choice as it provides robust streaming capability for media. However, it is unlikely to use UDP for streaming over the Internet.
Some issues with UDP are
1. RTSP/RTP over UDP requires many UDP ports to be opened (each media stream requires 2 UDP port for data and control).
2. Point 1 is a real problem as routers in the Internet may not open these ports.
3. It is normal for intermediate Internet router to filter and ignore UDP packets.
4. UDP is unreliable. Media packets may be lost when travelling along the Internet
RTSP/RTP over TCP may resolve this issue.
1. RTSP/RTP will communicate via 1 port for command and data. That is the RTSP port.
2. TCP provide reliable streaming
3. It is more likely that the intermediate Internet router allow these TCP packets to go through.
Using RTSP/RTP over TCP come with a price.
1. It complicated the packetization and depacketization process due to binary interleave.
2. TCP is reliable but have overhead. It may cause delay in real time media.
So, now I will talk about how to setup RTSP/RTP over TCP
RTSP/RTP over TCP
When you use RTSP/RTP over TCP, all command and media data will be sent through the RTSP port, normally, port 554. Also, when using RTSP/RTP over TCP, the data will be sent via binary interleave format.
Below will describe the essential for using RTSP/RTP over TCP
SETUP
To use TCP communication, you need to request TCP connection during RTSP SETUP. You have to sent SETUP command with
Transport: RTP/AVP/TCP;interleaved=0-1
This will tell the server to send media data with TCP and interleave the data in channel 0 and 1. Given in the specification, data channel is even number and control channel is odd (data_ch_num + 1). So, if you data channel is 0, your control channel will be 0 + 1 = 1.
Below is an example of TCP SETUP
RTP Data
After the setup, RTP data will be sent through the TCP socket that is used for RTSP commands. The RTP data will be encapsulate in the following format
| magic number | channel number | embedded data length | data |
magic number - 1 byte value of hex 0x24
channel number - 1 byte value to denote the channel
embedded data length - 2 bytes to denote the embedded data length
data - data packet, ie RTP packet, with the total length of the embedded data length
Below is a full example of the communication exchanged
Also, as RTSP is a application protocol, it has no way to control how TCP timeout the connection. Thus, during the RTSP SETUP, a Session is given to identify the connected stream
Session = "Session" ":" session-id [ ";" "timeout" "=" delta-seconds ]If Session is given, each subsequence RTSP command must be sent with the session so that the server can identify the stream. Also, please note that timeout is an optional value. The default value for timeout is 60 seconds. So, it is advisable to send a RTSP command to the server every 60 second to keep the TCP connection alive.
Read RFC 2326 Section 10.12 Embedded (Interleaved) Binary Data for more details
本文探讨了使用RTSP/RTP通过TCP而非UDP进行网络流媒体传输的原因、过程和注意事项。TCP提供可靠的数据传输,但会增加复杂性和延迟;而UDP则提供更流畅的实时体验但存在安全性问题。通过设置RTSP命令以使用TCP通道,可以解决中间互联网路由器过滤或忽略UDP包的问题,并确保实时媒体数据的安全传输。
1万+

被折叠的 条评论
为什么被折叠?



