当前位置:网站首页>RTMP(3):Protocol Control Message
RTMP(3):Protocol Control Message
2022-04-21 20:29:00 【Time_ Limit】
When message type id yes 1,2,3,5,6 when , It means that we should message Is a protocol control message (Protocol Control Message).
These types of messages are used to control chunk Some behaviors of hierarchy , The specific type name is as follows :
- 1:Set Chunk Size
- 2:Abort Message
- 3:Acknowledgement
- 5:Windon Acknowledgement Size
- 6:Set Peer Bandwidth
Protocol control message There are several important rules :
- Chunk stream id Must be 2,message stream id Must be 0.
- The receiver is receiving protocol control message Must be dealt with immediately after , Only after processing can subsequent processing be received chunk.
- timestamp Fields are ignored .
Before the start , Let's agree on a few definitions :
- client: launch handshake On the side of .
- server:client The opposite end of .
- The sender : send out Protocol Control Message On the side of .
- The receiver : receive Protocol Control Message On the side of .
client/server, The sender / The receiver is two sets of concepts .client/server It's at the link level , After the link is established, it will not change . The sender / The receiving end is message level , It refers to the sender and receiver of a message .client or server It can be the sending end or the receiving end .
Set Chunk Size (1)
As mentioned before ,maximum chunk size It's a single chunk Of payload size Upper limit , The default value is 128, Company byte. The sending end can use Set Chunk Size Type of message adjustment maximum chunk size Size .

Set Chunk Size The message carries a 32-bit The integer of —— chunk size, The value range of this field is [1, 0x7FFFFFFF]. actually ,chunk size The value of should not exceed 0xFFFFFF . because message length The fields are only 24-bit, Its value cannot exceed 0xFFFFFF .
Be careful , Here is the sender and the receiver , After I send this message , follow-up chunk Of payload size The upper limit has been adjusted , But you sent me chunk Of payload size The upper limit will not change .
for instance , Suppose you want to send the following two message:
| Message Stream ID | Message Type ID | Timestamp | Length | |
|---|---|---|---|---|
| MSG # 1 | 10 | 8 | 1000 | 280 |
| MSG # 2 | 10 | 8 | 1020 | 150 |
stay maximum chunk size yes 128 when , Will be encapsulated as 5 individual chunk, As follows :
| Chunk Stream ID | Chunk Format | Timestamp(Delta) | Message Length | Message Type ID | Message Stream ID | Chunk Data Size | |
|---|---|---|---|---|---|---|---|
| CHK # 1 | 3 | 0 | 1000 | 280 | 8 | 10 | 128 |
| CHK # 2 | 3 | 3 | \ | \ | \ | \ | 128 |
| CHK # 3 | 3 | 3 | \ | \ | \ | \ | 24 |
| CHK # 4 | 3 | 1 | 20 | 150 | 8 | 10 | 128 |
| CHK # 5 | 3 | 3 | \ | \ | \ | \ | 22 |
If , The sender is at CHK#1 Then add a Set Chunk Size, The upper limit of the opposite end of the notification is adjusted to 152, As mentioned above chunk Turn into :
| Chunk Stream ID | Chunk Format | Timestamp(Delta) | Message Length | Message Type ID | Message Stream ID | Chunk Data Size | |
|---|---|---|---|---|---|---|---|
| CHK # 1 | 3 | 0 | 1000 | 280 | 8 | 10 | 128 |
| CHK # S | 2 | 0 | 0 | 4 | 1 | 0 | 4 ( The values are as follows 0,0,0,152) |
| CHK # 2 | 3 | 3 | \ | \ | \ | \ | 152 |
| CHK # 4 | 3 | 1 | 20 | 150 | 8 | 10 | 150 |
obviously , The receiver is receiving CHK#S after , According to maximum chunk size by 152 Read subsequent chunk La .
Abort Message (2)

The message carries a 32-bit The integer of —— chunk stream id, It is used to notify the receiving end to discard the message chunk stream Not yet received on message.
But the news seems to have been abandoned , There is also a delete line in the document .

FFmpeg The message type is also not supported , After receiving this type of message, it will return the error code AVERROR_UNKNOWN.
// libavformat/rtmpproto.c
434 } else if (pkt.type == RTMP_CTRL_ABORT_MESSAGE) {
435 av_log(s, AV_LOG_ERROR, "received abort message\n");
436 ff_rtmp_packet_destroy(&pkt);
437 return AVERROR_UNKNOWN;
438 } else if (pkt.type == RTMP_PT_BYTES_READ) {
Acknowledgement (3)

The message carries a 32-bit The integer of —— sequence number, Used to notify the receiving end of me ( The sender ) Number of bytes received .
A few small details :
- Statistics are in all chunk stream Number of bytes read on .
- chunk header Of size It will also be counted .
- Every time
wBytes , Just send it once .wFrom the opposite end through Window Acknowledgement Size Appoint . AboutwThe default value of , The document does not mention ,FFmpeg take 2 20 2^{20} 220 As default .
Window Acknowledgement Size (5)

The message carries a 32-bit The integer of —— window size, Used to set the receiver to send Acknowledgement The frequency of the message . Every time the receiving end receives window size Bytes , At least Send a Acknowledgement news .
send out - Waiting mechanism : The message that is expected to be sent by each end window size You get a message in a byte Acknowledgement news , If it is not received, it will stop sending data , until Acknowledgement arrival .
stay FFmpeg In the implementation of , Every time w i n d o w s i z e 2 \frac{window\ size}{2} 2window size Bytes , Just send it once Acknowledgement news , The specific code is as follows , The reason for this is also easy to understand , See also 1596 -1598 Comment on line .
// libavformat/rtmpproto.c
1578 static int handle_window_ack_size(URLContext *s, RTMPPacket *pkt)
1579 {
1580 RTMPContext *rt = s->priv_data;
1581
1582 if (pkt->size < 4) {
1583 av_log(s, AV_LOG_ERROR,
1584 "Too short window acknowledgement size packet (%d)\n",
1585 pkt->size);
1586 return AVERROR_INVALIDDATA;
1587 }
1588
1589 rt->receive_report_size = AV_RB32(pkt->data);
1590 if (rt->receive_report_size <= 0) {
1591 av_log(s, AV_LOG_ERROR, "Incorrect window acknowledgement size %d\n",
1592 rt->receive_report_size);
1593 return AVERROR_INVALIDDATA;
1594 }
1595 av_log(s, AV_LOG_DEBUG, "Window acknowledgement size = %d\n", rt->receive_report_size);
1596 // Send an Acknowledgement packet after receiving half the maximum
1597 // size, to make sure the peer can keep on sending without waiting
1598 // for acknowledgements.
1599 rt->receive_report_size >>= 1;
1600
1601 return 0;
1602 }
Set Peer Bandwidth (6)

The message contains two fields :
- Window size:32-bit The integer of .
- Limit type:8-bit Integers .
Limit type There are three values for :
- 0 - Hard: The receiving end shall use window size As a parameter for controlling bandwidth .
- 1 - Sort: Use window size And in effect window size Minimum of .
- 2 - Dynamic: If the previous one Limit Type yes Hard, Then the message is sent according to Hard The rules take effect , On the contrary, the message is discarded .
Set Peer Bandwidth Need to cooperate Acknowledgement And Window Acknowledgement Size Working together . There are two endpoints with successful handshake A and B, The workflow is as follows :
- A towards B send out Set Peer Bandwidth,window size = 1024.
- B After receipt of , towards A send out Window Acknowledgement Size,window size Need to be the same , It's also 1024.
- A received Window Acknowledgement Size after , Every time 1024 Bytes , Send at least once Acknowledgement.
- B Sending Window Acknowledgement Size after , Will trigger send out - Waiting mechanism To control the bandwidth .
3,5,6 Example
There are two endpoints A and B The handshake has been successful , Now? A To pass the Set Peer Bandwidth control B The transmission rate of , The process is as follows :

版权声明
本文为[Time_ Limit]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204212025202357.html
边栏推荐
- warning: LF will be replaced by CRLF in composer.json.
- RTMP(4):User Control Message
- Test while (U --); And while (U) U --; Differences between
- 华融融达期货这家公司怎么样?期货开户办理安全吗?
- 长安深蓝C385产品信息曝光 瞄准20万级别,头号目标Model 3!
- 【转】SSE2 SSE简介和C代码示例
- Introduction to WLAN qpower
- leetcode - 329. 矩阵中的最长递增路径
- The difference between PE P / E ratios
- 双链表插入、删除操作单步解析(十四)
猜你喜欢

< 2021SC@SDUSC > Application and practice of software engineering in Shandong University jpress code analysis (2)

CUDA02 - 访存优化和Unified Memory

上午面了个腾讯拿 38K 出来的,让我见识到了基础的天花板

MySQL集群解决方案

IoT平台如何实现业务配置中心

Jmeter如何设置参数化

Redis的两种基准性能测试方式

Know that Chuangyu issued a heavy strategic plan to build a practical defense system for continuous exchange of fire

ROS knowledge: how to realize camera access

如何确保API 的稳定性与正确性?你只需要这一招
随机推荐
高效c语言 内存拷贝. 测试结果 rand, loop, operator= % in x86-64 SUSE
单、双链表的循环链表(十五)
Android Development Internship interview questions, Android development interview basis
他98年的,我玩不过他...
<2021SC@SDUSC>山东大学软件工程应用与实践JPress代码分析(一)
How to use xUnit framework to maintain test cases?
微信服务端配置
3D 沙盒游戏之人物的点击行走移动
LeetCode_509 斐波那契数
My medical experience of "traditional Chinese medicine"
基于C的电子通讯录管理系统
JS monitor mobile phone screen rotation (horizontal screen or vertical screen)
Channel allocation don't use the four-color theorem
金山云前COO刘志刚加入白海科技担任总裁
IoT平台如何实现业务配置中心
Liu Zhigang, former COO of Jinshan cloud, joined Baihai technology as president
Employment of college students in the "most difficult employment season": more than half of the graduates have landed, and higher vocational colleges produce sweet pastries
英音与美音的区别【转】
华融融达期货这家公司怎么样?期货开户办理安全吗?
Im instant messaging development technology: 1-10 million high concurrency architecture evolution