RTSP - RTP over TCP


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.

通常來說,RTSP提供UDP方式發送RTP流。當然,發送流媒體時,UDP往往是更好的選擇。但是,在互聯網上使用UDP方式發送流是不可能的。
 
Some issues with UDP are
下面是使用UDP時的一些問題:
 
1. RTSP/RTP over UDP requires many UDP ports to be opened (each media stream requires 2 UDP port for data and control).
1. UDP協議上的RTSP/RTP需要打開許多UDP端口(每一路流媒體都需要2個UDP端口,一個用於接收數據,一個用於接收控制信息);
2. Point 1 is a real problem as routers in the Internet may not open these ports.
2.當因特網上的路由器沒有打開這些端口的時候,上述第一點將會存在問題;
3. It is normal for intermediate Internet router to filter and ignore UDP packets.
3. 中間網絡路由器很容易就過濾或者忽略掉UDP數據包;
4. UDP is unreliable. Media packets may be lost when travelling along the Internet
4. UDP是不可靠傳輸協議,媒體包在因特網上傳輸時會面臨着丟包。
 
RTSP/RTP over TCP may resolve this issue.
但是我們如果在TCP傳輸協議上承載RTSP/RTP將解決這些問題。
 
1. RTSP/RTP will communicate via 1 port for command and data. That is the RTSP port.
1. RTSP/RTP的控制命令和數據都通過一個端口,即RTSP的端口(默認為554),進行交互。
2. TCP provide reliable streaming
2. TCP協議提供可靠的流傳輸。
3. It is more likely that the intermediate Internet router allow these TCP packets to go through.
3. TCP包更容易穿透中間網絡路由器。
 
Using RTSP/RTP over TCP come with a price.
但是,使用TCP傳輸協議承載RTSP/RTP需要花更多的功夫。
 
1. It complicated the packetization and depacketization process due to binary interleave.
1. 由於二元交織,會使得RTP包封包和解包的過程變得更加復雜。
2. TCP is reliable but have overhead. It may cause delay in real time media.
2. TCP是可靠的傳輸協議,但正是因為如此,會導致在實時流媒體中的延時。
So, now I will talk about how to setup RTSP/RTP over TCP
接下來讓我們來了解一下怎么使用TCP承載RTSP/RTP。
 
RTSP/RTP over TCP
TCP承載RTSP/RTP
 
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
當使用TCP協議承載RTSP/RTP時,所有的命令和媒體數據都將通過RTSP端口,通常是554,進行發送。同時,數據將經過二元交織格式化之后才能發
RTSP/RTP over TCP, the data will be sent via binary interleave format.
送。
 
Below will describe the essential for using RTSP/RTP over TCP
接下來我們將描述使用TCP承載RTSP/RTP的主要要素:
 
SETUP
 
To use TCP communication, you need to request TCP connection during RTSP SETUP. You have to sent SETUP command with
要使用TCP連接,RTSP客戶端需要在SETUP階段請求TCP連接。SETUP命令中應該包括如下格式的Transport:
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
上述Transport將告訴服務端使用TCP協議發送媒體數據,並且使用信道 0 和 1 對流數據以及控制信息進行交織。詳細說來,使用偶數信道作為數據
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.
傳輸信道,使用奇數信道作為控制信道(數據信道 + 1)。所以,如果你設定數據信道為 0 ,那控制信道應該是 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
SETUP之后,RTP數據將通過用來發送RTSP命令的TCP Socket進行發送。RTP數據將以如下格式進行封裝:
| magic number | channel number | embedded data length | data |
magic number - 1 byte value of hex 0x24
RTP數據標識符,"$"
channel number - 1 byte value to denote the channel
信道數字 - 1個字節,用來指示信道
embedded data length - 2 bytes to denote the embedded data length
數據長度 - 2個字節,用來指示插入數據長度
data - data packet, ie RTP packet, with the total length of the embedded data length
數據 - 數據包,比如說RTP包,總長度與上面的數據長度相同
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 
然而,由於RTSP是應用協議,沒有辦法控制TCP連接的超時。所以,在RTSP的SETUP階段,新建一個會話(SESSION)用於標識已連接的流。
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
一旦會話(SESSION)被創建,接下來的每一個RTSP命令都必須加上session_id,否則服務端無法識別命令對應的流。另外,"timeout"的值是可選
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
的。"timeout"的默認值是60秒。所以,建議每隔60秒向服務端發送一個RTSP命令以保持TCP連接的存活。
60 second to keep the TCP connection alive.
 
Read RFC 2326 Section 10.12 Embedded (Interleaved) Binary Data for more details
RFC 2326 第10.12節說明了插入二進制數據的細節。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM