Trang chủ‎ > ‎IT‎ > ‎Video Processing‎ > ‎

Study of LIVE555 two RTSP, RTP/RTCP protocol

One, overview

RTSP(Real-Time Stream Protocol )Is an application layer protocol based on the text, in the aspect of grammar and some message parameters, similar to the RTSP protocol and HTTP protocol.

RTSP is used to transfer control media flow is established, it plays the role of "remote control" for multimedia services. RTSP itself is not used for streaming data. Delivery of media data can be done by RTP/RTCP protocol.

The basic process of RTSP operation

First of all, the client connects to the streaming server and send an OPTIONS command received from the server response query method provided by the server, sending DESCRIBE commands to query a media file of SDP information. The streaming server through a SDP description of response, response information including the flow quantity, the media type and other information. The client analysis described in the SDP, and for each flow sends aSETUP command in SETUP session, the command tells the server to the client for receiving media data port. Streaming media connection setup is completed, the client sends a PLAY command, the server begins streamingdata. During playback the client can play to the server to send PAUSE and other command and control flow. Communication is completed, the client can send the TERADOWN command to end a streaming session.

Is a complete client and server through Wireshark capture by RTSP interaction. Black font indicates that the client request, red font server response.

OPTIONS rtsp://10.34.3.80/D:/a.264 RTSP/1.0

CSeq: 2

User-Agent: LibVLC/2.0.7 (LIVE555 Streaming Media v2012.12.18)

RTSP/1.0 200 OK

CSeq: 2

Date: Tue, Jul 22 2014 02:41:21 GMT

Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER


DESCRIBE rtsp://10.34.3.80/D:/a.264 RTSP/1.0

CSeq: 3

User-Agent: LibVLC/2.0.7 (LIVE555 Streaming Media v2012.12.18)

Accept: application/sdp

RTSP/1.0 200 OK

CSeq: 3

Date: Tue, Jul 22 2014 02:41:21 GMT

Content-Base: rtsp://10.34.3.80/D:/a.264/

Content-Type: application/sdp

Content-Length: 494

 

v=0

o=- 1405995833260880 1 IN IP4 10.34.3.80

s=H.264 Video, streamed by the LIVE555 Media Server

i=D:/a.264

t=0 0

a=tool:LIVE555 Streaming Media v2014.07.04

a=type:broadcast

a=control:*

a=range:npt=0-

a=x-qt-text-nam:H.264 Video, streamed by the LIVE555 Media Server

a=x-qt-text-inf:D:/a.264

m=video 0 RTP/AVP 96

c=IN IP4 0.0.0.0

b=AS:500

a=rtpmap:96 H264/90000

a=fmtp:96 packetization-mode=1;profile-level-id=42001E;sprop-parameter-sets=Z0IAHpWoLQSZ,aM48gA==

a=control:track1


SETUP rtsp://10.34.3.80/D:/a.264/track1 RTSP/1.0

CSeq: 4

User-Agent: LibVLC/2.0.7 (LIVE555 Streaming Media v2012.12.18)

Transport: RTP/AVP;unicast;client_port=60094-60095

RTSP/1.0 200 OK

CSeq: 4

Date: Tue, Jul 22 2014 02:41:25 GMT

Transport: RTP/AVP;unicast;destination=10.34.3.80;source=10.34.3.80;client_port=60094-60095;server_port=6970-6971

Session: 54DAFD56;timeout=65


PLAY rtsp://10.34.3.80/D:/a.264/ RTSP/1.0

CSeq: 5

User-Agent: LibVLC/2.0.7 (LIVE555 Streaming Media v2012.12.18)

Session: 54DAFD56

Range: npt=0.000-

RTSP/1.0 200 OK

CSeq: 5

Date: Tue, Jul 22 2014 02:41:25 GMT

Range: npt=0.000-

Session: 54DAFD56

RTP-Info: url=rtsp://10.34.3.80/D:/a.264/track1;seq=10244;rtptime=2423329550


GET_PARAMETER rtsp://10.34.3.80/D:/a.264/ RTSP/1.0

CSeq: 6

User-Agent: LibVLC/2.0.7 (LIVE555 Streaming Media v2012.12.18)

Session: 54DAFD56

RTSP/1.0 200 OK

CSeq: 6

Date: Tue, Jul 22 2014 02:41:25 GMT

Session: 54DAFD56

Content-Length: 10

 


//Termination

TEARDOWN rtsp://10.34.3.80/D:/a.264/ RTSP/1.0

CSeq: 7

User-Agent: LibVLC/2.0.7 (LIVE555 Streaming Media v2012.12.18)

Session: 54DAFD56

RTSP/1.0 200 OK

CSeq: 7

Date: Wed, Jul 30 2014 07:13:35 GMT



Can be found in the format of RTSP protocol and HTTP protocol is very similar, are text based protocol, grammar is basically the same. But they are not the same, the main difference:

Firstly, the method name is different. RTSP added DESCRIBE, SETUP, PLAY etc.

Secondly, the HTTP protocol is stateless protocol, sending no method between the apparent order relation. While the RTSP is a state of the protocol, the existing order relation method.

In HTTP protocol, data can be transmitted within the belt load data, such as Webpage data. While the RTSP only provides streaming control, does not deliver streaming media data. Streaming media data can be transmitted by way of RTP/RTCP.

Two, the RTSP message

1 RTSP request message format

The method name URL RTSP version CRLF

Message header CRLF CRLF

Enter the message body

Method names including OPTIONS, DESCRIBE, SETUP, PLAY, TEARDOWN etc.

URL is the recipient's address, such as: RTSP://192.168.0.1/video1.3gp.

The RTSP version is RTSP/1.0

The message of each will end with a newline, in order to facilitate the identification of the message header, the last line of the two carriage return.

The message body sometimes is optional.

2 response message format

RTSP version of the state code corresponding to the text interpretation newline

Message header CRLF CRLF

Enter the message body

The RTSP version is RTSP/1.0.

Status code indicates the corresponding message execution results.

Partial status code and text explanation list as follows:

The status code text explanation

"200" The success of OK implementation

"400" Bad Request error request

"404" Not Found not found

"500" Internal Internal Server Error server error

3 different methods in detail

(1)OPTIONS

The client uses OPTION to query the server to provide. The server in the public field are given to provide their own set of methods. From the above data can be seen in this server provides OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, GET_PARAMETER, SET_PARAMETER, PAUSE,, etc.

The OPTIONS method is not necessary. The client can bypass the OPTIONS, directly to the server to send other messages.

The CSeq field represents the request number. Each client request will be assigned a number. Each request message will correspond to a same ordinal response message.

The OPTIONS message can be sent at any time. Some clients will timing OPTION to send the message to the server. While the server can also be whether the timing of received OPTIONS messages through judging whether the client online. But not all clients and servers to do so.

User Agent

The domain for user identification. Different companies or different client. The domain of different client message of content are not the same. Sometimes indicates the client version number, model and so on.

Using VLC as the client specified in the field below the dialogue, and to publish the number and use the LIVE555 version of the library.

OPTIONS rtsp://10.34.3.80/D:/a.264 RTSP/1.0

CSeq: 2                                                                                              //Request number

User-Agent: LibVLC/2.0.7 (LIVE555 Streaming Media v2012.12.18)

RTSP/1.0 200 OK

CSeq: 2                                                                                              //Reply No.

Date: Tue, Jul 22 2014 02:41:21 GMT

Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, GET_PARAMETER, SET_PARAMETER


(2)DESCRIBE

The DESCRIBE message is sent by the client to the server for the client, get relevant description request media filespecified in the link, is generally SDP information. SDP(Session Description Protocol)Contains a description, media encoding type, media session rate and other information. For streaming media services, the following domain is in the SDP must contain.

"a=control:"

"a=range:"

"a=rtpmap:"

"a=fmtp:"

When a video contains audio also includes video, there will be more than one of the above structure. Each media description starts with M. The green and yellow background font respectively on the video and audio media description. The Accept field in the request is used to specify the client can receive media description information types, here for the SDP information.

DESCRIBE rtsp://10.34.3.80/D:/a.264 RTSP/1.0

CSeq: 3

User-Agent: LibVLC/2.0.7 (LIVE555 Streaming Media v2012.12.18)

Accept: application/sdp                                //Request access to SDP information

RTSP/1.0 200 OK

CSeq: 3

Date: Tue, Jul 22 2014 02:41:21 GMT

Content-Base: rtsp://10.34.3.80/D:/a.264/                   //Specify a media description information

Content-Type: application/sdp                                   //The type of request

Content-Length: 494                                                //The length of SDP

 

v=0                                            //Version SDP protocol version

o=- 1405995833260880 1 IN IP4 10.34.3.80            //Origion session originator information

s=H.264 Video, streamed by the LIVE555 Media Server  //The session name

 

i=D:/a.264                                                              //Description information session

t=0 0                                                                      //The session start and end time

a=tool:LIVE555 Streaming Media v2014.07.04          //Attribute

a=type:broadcast

a=control:*                                                             //Control information

a=range:npt=0-

a=x-qt-text-nam:H.264 Video, streamed by the LIVE555 Media Server

a=x-qt-text-inf:D:/a.264

m=video 0 RTP/AVP 96            //Support the sender media types (video) information

c=IN IP4 0.0.0.0               //Session connection information, spending real media stream using the IP address. 

b=AS:500                                //Video bandwidth

a=rtpmap:96 H264/90000          //The media attribute, video (H264 video format, 90000 sampling rate)

a=fmtp:96 packetization-mode=1;profile-level-id=42001E;sprop-parameter-sets=Z0IAHpWoLQSZ,aM48gA==

a=control:track1                       //The video using track 1

 

m=audio 0 RTP/AVP 97         //Media type (audio) following are to describe the information of the audio

b=AS:19                              //Audio bandwidth

a=rtpmap:97 MP4A-LATM/11025/1     //Video format (MP4A-LATM video format, 11025 sampling rate)

a=fmtp:97 profile-level-id=15; object=2; cpresent=0; config=40002A103FC0

a=mpeg4-esid:101=x-envivio-verid:00011118

a=control:trackID=2               /The audio using track 2


M is also called the media, described the sender support media type and other information, to explain in detail.

m=audio 3458 RTP/AVP 0 96 97

The first parameter to audio for media name: show the audio type.

The second parameter is the port number 3488, showed that UE in the local port to send 3458 audio stream.

The third parameter RTP/AVP as the transport protocol, RTP protocol based on UDP.

Fourth to seven parameters for the four kinds of payload type number support.

a=rtpmap:0 PCMU

a=rtpmap:96 G726-32/8000

a=rtpmap:97 AMR-WB

Properties for a media, to attribute the name: attribute value method.

Format: a=rtpmap:<payload type > <encoding name>

Payload type 0 fixed assigned to PCMU,

Coding scheme payload type 96 corresponding to G.726, dynamic distribution.

Payload type 97 corresponding encoding for the adaptive multi rate wideband coding (AMR-WB), dynamic allocation.

For the video

m=video 3400 RTP/AVP 98 99

The first parameter to the video for the media name: show the video type.

The second parameter is the port number 3400, showed that UE in the local port 3400 send video stream.

The third parameter RTP/AVP as the transport protocol, said RTP over UDP.

Fourth, five parameters are given. Two kinds of payload type number

a=rtpmap:98 MPV

a=rtpmap:99 H.261

Coding scheme payload Type 98 corresponding to MPV, dynamic distribution.

Payload type 97 corresponding encoding for the H.261, as dynamic allocation.

(3)SETUP

The SETUP message is used to determine the transfer mechanism, establishing a RTSP session. The client can also set up RTSP again after sending a SETUP request to change the transmission parameters for playing streaming media server may agree with these parameters. If you do not agree, will respond "455 Method Not Valid In This State".

The head of the Transport Request field in the data transmission parameters specified acceptable to the client,

The Transport header field in Response contains the server after confirmation of transmission parameters.

If the request does not contain a SessionID, then the server will produce a SessionID.

SETUP rtsp://10.34.3.80/D:/a.264/track1 RTSP/1.0   //Track1 said to set the channel 1.

CSeq: 4

User-Agent: LibVLC/2.0.7 (LIVE555 Streaming Media v2012.12.18)   //The client version information

Transport: RTP/AVP;unicast;client_port=60094-60095       //RTP/AVP said the RTP agreement transmission parameters over, UDP, unicast unicast, multicast is used to distinguish. Client_port agreed by the client RTP RTCP port 60094, port 60095

RTSP/1.0 200 OK

CSeq: 4

Date: Tue, Jul 22 2014 02:41:25 GMT

Transport: RTP/AVP;unicast;destination=10.34.3.80;source=10.34.3.80;client_port=60094-60095;server_port=6970-6971 //The server specified by the transmission parameters

Session: 54DAFD56;timeout=65    //SessionID          

From the top of the SETUP session can be seen in the RTP port even said, RTCP for the TCP port adjacent odd port.

Shown above is RTP over UDP. The following for the use of RTP over TCP SETUP dialogue.

SETUP rtsp://10.34.3.80/D:/a.264/track1 RTSP/1.0   //Track1 said to set the channel 1.

CSeq: 4

User-Agent: LibVLC/2.0.7 (LIVE555 Streaming Media v2012.12.18)  

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

RTSP/1.0 200 OK

CSeq: 4

Date: Tue, Jul 22 2014 02:41:25 GMT

Transport:

 RTP/AVP/TCP;interleaved=0-1

Session: 54DAFD56;timeout=65

You can see the Transport SETUP command for the RTP/AVP/TCP field, and many a interleaved=0-1 field. Because the RTP over TCP RTP and RTCP packets are sent to the same TCP port, so use the interleaved value to distinguish whether the RTP or the RTCP package. Interleaved=0 said the RTP packet, RTCP packet interleaved=1.

(4)PLAY

The PLAY method notifies the server according to the mechanism of SETUP specified in the start data transfer. The server will PLAY message from the specified start time range to transmit data, until the end of. The server may be PLAY requests in the queue, after an PLAY request needs to wait before an PLAY request is completed can be implemented.

Range specifies the playback start time. If you receive a message in the specified time, so play immediately began.

Excluding the first Range PLAY request is legitimate, the media began to flow from the position in the world, until the media stream is suspended. If the media flow through PAUSE pause, media contribute at the point of suspension to transmission. If the media stream is playing, so the PLAY request will not work. The client can use this to test whether the server survival.

PLAY rtsp://10.34.3.80/D:/a.264/ RTSP/1.0

CSeq: 5

User-Agent: LibVLC/2.0.7 (LIVE555 Streaming Media v2012.12.18)

Session: 54DAFD56                 //SessionID, Returns the SETUP response

Range: npt=0.000-   /                /The specified start playing time

RTSP/1.0 200 OK

CSeq: 5

Date: Tue, Jul 22 2014 02:41:25 GMT

Range: npt=0.000- 

Session: 54DAFD56

RTP-Info: url=rtsp://10.34.3.80/D:/a.264/track1;seq=10244;rtptime=2423329550  //RTP information


The Url field is a streaming link address corresponds to the RTP parameter, the SEQ field of streaming media first packet sequence number, rtptime for the range domain corresponding to the RTP timestamp

(5)PAUSE

PAUSE message server paused transmission stream transmission. If the request URL specific media stream, then only the media player is suspended. You can specify only pause audio, then play will mute. If the request URL specifies a set of flow, then the transmission of all streams in the group will be suspended. The server may not support PAUSE message. For example, the real-time stream may not support pause. When a server does not support a message, will respond to the client"501 Not Implemented".

PAUSE request may contain a Range head, is used to specify the media stream pause time point, called the point of suspension. The head of the Range must contain a precise value, instead of a time range. If the Range header specifies a time beyond the scope of the PLAY request, the server will return"457 Invalid Range" . If Range is missing, then immediately suspend suspended in received news media stream transmission, and will pause point set to the current playback time.

(6) TEARDOWN

TEARDOWN for the termination of a given URL media streaming, and release the related resources and the media stream.

Three, RTP/RTCP protocol

RTP is the real time transport protocol (Real-Time Transport Protocol) abbreviation. The real time transport protocol for multimedia data flow. Usually based on UDP, can also be based on TCP. Some people will be classified as application layer protocol, also some people will return to its transport layer protocol, which can be. The Rtp protocol provides a timestamp and sequence number. Timestamp sender is arranged in sampling, after the receiver, in accordance with the time stamp are playing. RTP itself only to ensure the transmission of real-time data, and not for in order delivery of data packets for reliable transport mechanism, also do not provide flow and congestion control, it relies on RTCP to provide these services.

The version number (V): 0-1 2b is used to identify the version of RTP used in.

Fill bits (P): 2 1b if the bit is set to 1, the tail of the RTP package with padding bytes added.

Extended (X):3 1b if the bit is set to 1, the tail of the RTP packets with additional extension header.

CSRC counter (CC): the number of CSRC 4-7 4B fixed head following after.

The marked position (M): 8 1b interpretation of the bit by the configuration document.

Load type (PT): type 9-15 7b identifies the RTP load.

Serial number (SN): 16- 31 16b sender sending each a RTP package will be the domain value plus 1, the receiver can be detected by the sequence number to determine whether the RTP packet loss. Note: the initial sequence number value is random.

Time stamp: sampling time of the first byte of the packet in 32 32b. The time stamp is an initial value, and increased with the passage of time. Even if no packets are sent, the time stamp will not increase. The time stamp is removing jitter and synchronize the essential.

SSRC: synchronization source identifier: 32b RTP package source, cannot have the same two SSRC value in the same session of RTP. This field is based on the algorithm of randomly generated certain.

CSRC List: contribution to the source list 0-15, each 32B to all RTP package source new packet identifier for a RTP mixer's contribution.

The RTCP protocol

RTCP is the real time control protocol (Real-Time Control Protocol) abbreviation. RTCP is usually used in conjunction with the RTP, is used to manage the transmission quality in the current process between the exchange of information. During the RTP session, the participants periodically transmitting RTCP packet, RTCP packet contains the number of sent packets, the number of lost packets and other statistical data. The server can use to change the transmission rate of the dynamic information, or even change the payload type. With the use of RTP and RTCP, can effectively and with minimal cost to achieve the best transmission efficiency, very suitable for the transmission of real time flow.

RTSP usually uses RTP protocol to transport real-time streaming, RTP general use of even and odd port, port RTCP using adjacent, namely the RTP port number +1.

In the RTCP communication control, RTCP protocol function is realized by different types of RTCP packages. RTCP is also based on the UDP packet transmission, there are five main types of packets:

1.SR: The sender report, issued by the application sends a RTP datagram or end.

2.RR: The receiving end report, but the application is not accepted by sending a RTP datagram or from the end.

3.SDES: source description, the carrier identification information associated with the session members, such as user name, e-mail, phone etc.

4.BYE: notify other members left, back in the notice will exit the session.

5.APP: defined by the application itself, as an extension to the RTCP protocol.

Version (V) with the RTP Baotou: Department of

Fill (P) with the RTP Baotou: Department of.

The receiving report counter (RC): number of the receiving report of block 5B in the SR package.

Packet type (PT): 8bit SR packet type 200

Length (length) of:SR package to 32bit for 1 units of length minus 1

Synchrotron source (SSRC) synchronization source identifier:SR packet transmission. As with the corresponding RTP package SSRC.

NTP timestamp (Network Time Protocol): SR absolute time packets when. Used to synchronize different flow.

RTP timestamp: corresponding to the NTP timestamp, with the same initial value and the timestamp in the RTP package.

Send's Packet count: From the beginning of the total number of bytes of data to produce effective this time the SR package in the sender transmits data, excluding the head and filling, the sender SSRC, the domain to be cleared.

The SSRC identifier synchronization source n: contained in the report is the statistical information packets received from the source.

Loss rate: the last show from SR or RR packets sent according to the loss rate from the source n sends a RTP packet.

The cumulative loss of data: accept the total number of SSRC_n packets to send SR the time SSRC_n transmission loss of RTP from the beginning.

Extended maximum sequence number received from the maximum sequence number: data from the RTP package SSRC_n received.

Receiving jitter (Interarrival jitter):RTP packet reception time variance estimation.

The last time SR time stamp (Last SR): the latest from NTP timestamp SSRC_n received SR packets in the intermediate 32bit. If you have not received SR packet, is 0.

The last time dependent SR delay (Delay since Last SR): from the last SSRC_n received SR packet to the packet transmission delay.

Audio and video synchronization

Transmission of audio and video stream in two different RTP session, each RTP packet has its own time stamp, while the RTCP package in the NPT field (Network Protocol Time) absolute time saved can be used to set the audio and video are mapped to the same time axis, so as to realize the synchronization of audio and video.

The position of each protocol in TCP/IP

This article will introduce the LIVE555 Foundation.


2014.8.2 in Zhejiang Hangzhou

Comments