Simple analysis of RTMP specification of RTMP protocol 01

Simple analysis of RTMP specification of RTMP protocol 01

Simple analysis of RTMP specification of RTMP protocol 01
Detailed explanation of RTMP specification of RTMP protocol 02

Overview:
RTMP protocol is an application layer protocol in the Internet TCP/IP four-layer system structure. The basic data unit in the RTMP protocol is called a message. When the RTMP protocol transmits data over the Internet, the message will be split into smaller units, called Chunks.

1 Message
Message is the basic data unit in the RTMP protocol. Different types of messages contain different Message Type IDs, representing different functions. A total of more than ten message types are stipulated in the RTMP protocol, which play different roles. For example, messages with Message Type IDs 1-7 are used for protocol control. These messages are generally used by the RTMP protocol itself for management, and users generally do not need to manipulate the data in them. Messages with Message Type ID 8 and 9 are used to transmit audio and video data respectively. Messages with Message Type ID 15-20 are used to send AMF-encoded commands and are responsible for the interaction between the user and the server, such as play, pause, etc.
The Message Header consists of four parts: the Message Type ID that identifies the message type, the Payload Length that identifies the message length, the Timestamp that identifies the timestamp, and the Stream ID that identifies the media stream to which the message belongs. The message structure of the message is shown in the figure (a line should be added after StreamID):
Insert picture description here

2 When the message block
transmits data on the network, the message needs to be split into smaller data blocks to be suitable for transmission on the corresponding network environment.
The RTMP protocol stipulates that a message is split into message chunks (Chunks) when it is transmitted over the network.
The message block header (Chunk Header) consists of three parts:
1) It is used to identify the Chunk Basic Header of this block. It is composed of chunk stream ID (CSID) and chunk type. CSID is the unique id that identifies the message block;
2) Chunk Message Header used to identify the message to which the load of this block belongs;
3) Extended Timestamp that only appears when the timestamp overflows.
The message structure of the message block is shown in the figure:
Insert picture description here

3 The process of message segmentation In the process of message segmentation
into several message blocks, the message body part is segmented into fixed-size data blocks (the default is 128 bytes, and the last data block can be less than the fixed length) , And add the Chunk Header to its header to form the corresponding message block, so our message block size is the message header block size + 128, or the message block header + end is less than 128 bytes.

The message block process is shown in the figure. A message with a size of 307 bytes is divided into 128-byte message blocks (except for the last one).
Insert picture description here
In the process of RTMP transmitting media data: the
sender first encapsulates the media data into messages, then divides the messages into message blocks, and finally sends the divided message blocks through the TCP protocol.
After receiving the data through the TCP protocol, the receiving end first reassembles the message blocks into a message, and then can recover the media data by decapsulating the message.

Guess you like

Origin blog.csdn.net/weixin_44517656/article/details/109150617