RTSP protocol and IGMP protocol

Regarding the learning of audio and video related aspects, we must first understand the corresponding commonly used protocols. This article briefly explains these two protocols without adding RTMP protocol.

RTSP protocol
1. Overview
1) RTSP (Real-Time Stream Protocol) is a text-based application layer protocol, RTSP is used to control the transmission of media streams established, and it plays the role of "network remote control" for multimedia services. RTSP itself is not used to transmit media streaming data. The transmission of media data can be accomplished through protocols such as RTP/RTCP.
2) Basic RTSP operation process
First , the client connects to the streaming server and sends an OPTIONS command to query the method provided by the server. After receiving the response from the server, it sends the DESCRIBE command to query the SDP information of a media file. The streaming server responds with an SDP description, and the response information includes information such as the number of streams and the media type. The client parses the SDP description and sends a SETUP command for each stream in the session. The SETUP command tells the server the port the client is using to receive media data. After the streaming media connection is established, the client sends a PLAY command, and the server starts to transmit media streaming data. During the playback process, the client can also send other commands such as PAUSE to the server to control the playback of the stream. After the communication is completed, the client can send a TERADOWN command to end the streaming session.

two. RTSP message
1) request message
Request: OPTIONS rtsp://192.168.48.113:8554/1 RTSP/1.0\r\nFormat
: method + URL + RTSP version + carriage return and line feed
Method : OPTIONS
URL: rtsp://192.168. 48.113:8554/1
RTSP version: RTSP version is generally RTSP/1.0
2)response message
Response: RTSP/1.0 200 OK\r\ nFormat
: version + status code + corresponding text explanation
Version : RTSP/1.0
Status code: 200
Corresponding text explanation: OK
In addition, there are some status codes + text explanation
as follows :

-

status code text interpretation meaning
“200” OK execution succeed
“400” Bad Request bad request
“404” Not Found not found
“500” Internal Server Error Server Error

three. Detailed introduction of each method
1) OPTIONS
Real Time Streaming Protocol
Request: OPTIONS rtsp://192.168.48.113:8554/1 RTSP/1.0\r\n
Method: OPTIONS
URL: rtsp://192.168.48.113:8554/1
CSeq : 2\r\n
User-Agent: LibVLC/2.2.4 (LIVE555 Streaming Media v2016.02.22)\r\n
\r\n
Real Time Streaming Protocol
Response: RTSP/1.0 200 OK\r\n
Status: 200
Server : VLC/2.2.4\r\n
Content-length: 0
Cseq: 2\r\n
Public: DESCRIBE,SETUP,TEARDOWN,PLAY,PAUSE,GET_PARAMETER\r\n
\r\nThe
client can be seen from the above Use the OPTIONS method to query the methods provided by the server, and the server also responds in the Public segment. What methods are there: Public:DESCRIBE,SETUP,TEARDOWN,PLAY,PAUSE,GET_PARAMETER\r\n
The Cseq field indicates the sequence number of the request. Each request from the client is assigned a sequence number, and the server also responds with the same sequence number.
User-Agent This field is used to identify different users to identify different companies or different clients.
At the same time, the above fields also indicate that VLC is used as the server segment, and the version number and LIVE555 library version used are indicated.
2) DESCRIBE
The DESCRIBE message is sent by the client to the server for the client to obtain the relevant description of the media file specified in the request link, generally SDP information. SDP is entirely a session description format, it is not a transport protocol.
It uses different appropriate transport protocols, including Session Notification Protocol (SAP), Session Initiation Protocol (SIP), Real Time Streaming Protocol (RTSP), MIME Extensions Email and Hypertext Transfer Protocol (HTTP).
The SDP protocol is also a text-based protocol, so that the scalability of the protocol can be ensured, so that it has a wide range of applications. SDP does not support negotiation of session content or media encoding, so it is only used to describe media information in streaming media. This piece of media negotiation is implemented with RTSP. For streaming media services, the following fields must be included in the SDP: "a=control:", "a=range:", "a=rtpmap:", "a=fmtp:"
The following are the servers The client responds to a message from the client:

Real Time Streaming Protocol
Response: RTSP/1.0 200 OK\r\n
Status: 200
Server: VLC/2.2.4\r\n
Date: Thu, 18 Aug 2016 08:20:40 GMT\r\n
Content-type: application/sdp //Request type
Content-Base: rtsp://192.168.48.113:8554/1\r\n //Indicate the description information for a certain media
Content-length: 570 //SDP length
Cache-Control: no- cache\r\n //Hidden protocol
Cseq: 3\r\n //Request sequence number
\r\n
Session Description Protocol
Session Description Protocol Version (v): 0 //SDP protocol version
Owner/Creator, Session Id (o) : - 15807615279986996655 15807615279986996655 IN IP4 DESKTOP-9ONQED0 //Session initiator information
Session Name (s): Unnamed //Session name
Session Information (i): N/A //Session information
Connection Information (c): IN IP4 0.0.0.0 //Session connection information, indicating the IP address used by the real media stream.
Time Description, active time (t): 0 0
Session Attribute (a): tool:vlc 2.2.4 //Some attributes of the
session Session Attribute (a): recvonly
Session Attribute (a): type:broadcast //Broadcast transmission type
Session Attribute (a): charset:UTF-8 //Character set, UTF-8 is a variable-length character encoding of UNICODE. UINCODE adds a unique number to each character.
Session Attribute (a): control:rtsp://192.168.48.113:8554/1 //Protocol
Media Description, name and address (m): audio 0 RTP/AVP 14 //Media type supported by the sender (video, etc. information).
Bandwidth Information (b): AS:128 //Video bandwidth information
Bandwidth Information (b): RR:0
Media Attribute (a): rtpmap:14 MPA/90000/2 //Media attribute, video format (MPA is video format, 90000 is the sampling rate).
Media Attribute (a): control:rtsp://192.168.48.113:8554/1/trackID=0//protocol, the track of this media is 0
Media Description, name and address (m): video 0 RTP/AVP 96/ /Media name, protocol and payload type
Bandwidth Information (b): RR:0
Media Attribute (a): rtpmap:96 H264/90000 //Payload type, supported media format, sampling rate
Media Attribute (a):fmtp :96 //The payload type is 96
packetization-mode=1;profile-level-id=64001e;sprop-parameter-sets=Z2QAHqzZQLQ9v/ACAAGxAAADAAEAAAMAMI8WLZY=,aOvjyyLA;
Media Attribute (a): control:rtsp://192.168. 48.113:8554/1/trackID=1//track is 1

3) SETUP
The SETUP message is used to determine the transfer mechanism and establish an RTSP session. The client can also issue a SETUP request again after establishing RTSP to change the transmission parameters for the media stream being played, and the server may agree to these parameters. If you do not agree, it will respond with "455 Method Not Valid In This State"
Real Time Streaming Protocol
Request: SETUP rtsp://192.168.48.113:8554/1/trackID=0 RTSP/1.0\r\n
Method: SETUP
URL: rtsp ://192.168.48.113:8554/1/trackID=0
CSeq: 4\r\n //Request number
User-Agent: LibVLC/2.2.4 (LIVE555 Streaming Media v2016.02.22)\r\n //Client Version information
Transport: RTP/AVP;unicast;client_port=57676-57677 //Transmission parameters, protocol, unicast, the agreed RTP client port is 57676-57677
\r\n

4) The PLAY
PLAY method informs the server to start transmitting data according to the mechanism specified in SETUP. The server will transmit data from the start time of the range specified in the PLAY message until the end of the range. The server may queue a PLAY request, and the latter PLAY request needs to wait for the previous PLAY request to complete before it can be executed.
Range specifies the time when playback starts. If a message is received after this specified time, playback begins immediately.
Real Time Streaming Protocol
Request: PLAY rtsp://192.168.48.113:8554/1 RTSP/1.0\r\n
Method: PLAY
URL: rtsp://192.168.48.113:8554/1
CSeq: 6\r\n
User- Agent: LibVLC/2.2.4 (LIVE555 Streaming Media v2016.02.22)\r\n
Session: 64c337542cde55b1
Range: npt=0.000-\r\n //Specify start time
\r\n

Real Time Streaming Protocol
Response: RTSP/1.0 200 OK\r\n
Status: 200
Server: VLC/2.2.4\r\n
Date: Thu, 18 Aug 2016 08:20:40 GMT\r\n
RTP-Info: //RTP information
url=rtsp://192.168.48.113:8554/1/trackID=0;seq=60996;rtptime=1736724464, url=rtsp://192.168.48.113:8554/1/trackID=1;seq= 54288;rtptime=1736724464\r\n
//URL is the link address corresponding to the streaming media, seq is the sequence number of the first packet of the streaming media, and rtptime is the timestamp corresponding to the range field.
//Timestamp is actually a time field. Every time data is added, the current time value is filled in for the incremental extraction model of the ETL part of the data warehouse, that is to say: "With the time stamp, I The data of last week has been loaded. Now I need to incrementally load the data of this week. What should I do? The best way is to load the time value of those timestamp fields that are greater than the time of last week and Sunday. No need to load other data!"
Range: npt=130.379780-\r\n
Session: 64c337542cde55b1;timeout=60
Content-length: 0
Cache-Control: no-cache\r\n
Cseq: 6\r\n
\r \n

5) TEARDOWN A
TEARDOWN request terminates the media streaming for the given URL and releases the resources associated with that media stream.

IGMP protocol

1. Overview
IGMP is the abbreviation of Internet Group Management Protocol (Internet Group Management Protocol). It is a protocol responsible for the management of IP multicast members in the TCP/IP protocol suite. It is used to establish and maintain multicast membership between IP hosts and their directly adjacent multicast routers.
So far, there are three versions of IGMP:
1. IGMPv1 (defined by RFC 1112)
2. IGMPv2 (defined by RFC 2236)
3. IGMPv3 (defined by RFC 3376)

two. IGMPv2
1) Message format:
version + type + maximum response time + header checksum + group address

IGMPv2抓包部分报文如下:
Internet Protocol Version 4, Src: 192.168.48.53, Dst: 234.1.1.1
0100 …. = Version: 4
…. 0110 = Header Length: 24 bytes
Differentiated Services Field: 0x00 (DSCP: CS0, ECN: Not-ECT)
Total Length: 32
Identification: 0x54ef (21743)
Flags: 0x00
Fragment offset: 0
Time to live: 1
Protocol: IGMP (2)
Header checksum: 0xf408 [validation disabled]
Source: 192.168.48.53
Destination: 234.1.1.1
[Source GeoIP: Unknown]
[Destination GeoIP: Unknown]
Options: (4 bytes), Router Alert
Internet Group Management Protocol //igmp
[IGMP Version: 2] //版本2
Type: Membership Report (0x16) //Membership report type
Max Resp Time: 0.0 sec (0x00) //Maximum response time
Header checksum: 0xfefc [correct] //Header checksum
Multicast Address: 234.1.1.1 //Multicast address

2) Group Member Joining Process
When a host joins a multicast group, it should immediately send one or more membership reports of each version 2 to the multicast group.
write picture description here

3) Query and response
The IGMP querier periodically sends membership query information to all hosts in the subnet (224.0.0.1 represents all hosts in the subnet).
All hosts receive the IGMPv2 membership query information, and a host first sends an IGMPv2 membership report to the multicast group.
Other members of the group suppress their own membership reports from being sent after listening to the report.

4)查询器选择过程

As can be seen from Figure 2, the
router starts and actively sends out IGMPv2 general query information to all multicast system groups (224.0.0.1).
The router that receives the regular query information will compare the source IP address of the information with the IP address of the receiving port, and the router with the lowest IP address is elected as the IGMP query router.

The non-querying router starts a query timer and periodically checks the status of the IGMP querying router.
The host sends a leave group message to 224.0.0.2 (the message contains the group address 224.1.1.1 to leave).
The router sends a specific group query to this group (224.1.1.1).
No report received for this group within 1 second, send a second query for a specific group.
No response is received from the host after two query messages, the group 224.1.1.1 times out and leaves the group.

Comparison of three versions of IGMP

IGMPv1 IGMPv2 IGMPv4
Querier election Relying on multicast routing protocols choose yourself choose yourself
How members leave leave silently Actively send outgoing message Actively send outgoing message
Specified group query not support support support
Specify source and group to join not support not support support

three. Multicast IP address
• Multicast address range
224.0.0.0-239.255.255.255
• Reserved multicast address
224.0.0.0-224.0.0.255 224.0.1.0-224.0.1.255
• Local management group address
239.0.0.0-239.255.255.255
• User group multicast address
224.0.2.0-238.255.255.255
• Multicast MAC address:
Ethernet: 01-00-5e-xx-xx-xx
• Commonly reserved multicast address Permanent group address meaning
224.0.0.1 All systems, including hosts and routers
224.0.0.2 All multicast routers
224.0.0.3 Unassigned
224.0.0.4 DVMRP (Distance Vector Multicast Routing Protocol)
router
224.0.0.5 OSPF (Open Shortest Path First, Open Shortest Path First) router
224.0.0.6 OSPF Designated Router/Standby Designated Router 224.0.0.7 ST (Shared Tree, Shared Tree) Router
224.0.0.8 ST Host
224.0.0.9 RIP-2 (Routing Information Protocol version 2, Routing Information Protocol version 2) Router
224.0.0.11 Mobility Agent
224.0.0.12 DHCP (Dynamic Host Configuration Protocol) server/
relay agent 224.0.0.13 All PIM (Protocol Independent Multicast, Protocol Independent Multicast) routers
224.0.0.14 RSVP (Resource Reservation Protocol, Resource reservation protocol) encapsulation
224.0.0.15 All CBT (Core-Based Tree, core tree) routers
224.0.0.16 Specify SBM (Subnetwork Bandwidth Management, subnet bandwidth management)
224.0.0.17 All SBM
224.0.0.18
VRRP (Virtual Router Redundancy ) Protocol, Virtual Router Redundancy Protocol)

四.IGMP snooping

4. Multicast IP address:
• Multicast address range
224.0.0.0-239.255.255.255
• Reserved multicast address
224.0.0.0-224.0.0.255 224.0.1.0-224.0.1.255
• Local management group address
239.0.0.0-239.255.255.255
• User multicast address
224.0.2.0-238.255.255.255
• Multicast MAC address:
Ethernet: 01-00-5e-xx-xx-xx
• Commonly reserved multicast address Permanent group address meaning
224.0.0.1 All systems, including Hosts and routers
224.0.0.2 All multicast routers
224.0.0.3 Unassigned
224.0.0.4 DVMRP (Distance Vector Multicast Routing Protocol)
routers
224.0.0.5 OSPF (Open Shortest Path First) routers
224.0.0.6 OSPF Designated Router/Alternate Designated Router 224.0.0.7 ST (Shared Tree, Shared Tree) Router
224.0.0.8 ST Host
224.0.0.9 RIP-2 (Routing Information Protocol version 2, Routing Information Protocol version 2) Router
224.0.0.11 Mobility Agent
224.0.0.12 DHCP (Dynamic Host Configuration Protocol) server/
relay agent 224.0.0.13 All PIM (Protocol Independent Multicast, Protocol Independent Multicast) routers
224.0.0.14 RSVP (Resource Reservation Protocol, Resource reservation protocol) encapsulation
224.0.0.15 All CBT (Core-Based Tree, core tree) routers
224.0.0.16 Specify SBM (Subnetwork Bandwidth Management, subnet bandwidth management)
224.0.0.17 All SBM
224.0.0.18
VRRP (Virtual Router Redundancy ) Protocol, Virtual Router Redundancy Protocol)

5. IGMP snooping
IGMP Snooping runs at the link layer and is a multicast constraint mechanism running on a Layer 2 Ethernet switch to manage and control multicast data forwarding.
When a Layer 2 Ethernet switch receives an IGMP packet transmitted between a host and a router, IGMP Snooping analyzes the information contained in the IGMP packet. When listening to the IGMP host report message sent by the host, the switch adds the host to the corresponding multicast MAC address table. When monitoring the IGMP leave message sent by the host, the switch will delete the multicast MAC address table corresponding to the host.
By constantly monitoring IGMP packets, the switch can establish and maintain a multicast MAC address table at Layer 2, and the switch can forward the multicast packets sent from the router according to the multicast MAC address table. When IGMP Snooping is not running, multicast packets will be broadcast at Layer 2.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325460494&siteId=291194637
Recommended