feat(rtsp): add option to limit packetsize for clients that cannot configure it (#5153)

Signed-off-by: Georgi Valkov <gvalkov@gmail.com>
This commit is contained in:
Georgi Valkov
2026-05-21 18:43:53 +03:00
committed by GitHub
parent 2db7176f73
commit 3a69acefa0
7 changed files with 99 additions and 0 deletions
+2
View File
@@ -544,6 +544,7 @@ namespace config {
ENCRYPTION_MODE_NEVER, // lan_encryption_mode
ENCRYPTION_MODE_OPPORTUNISTIC, // wan_encryption_mode
0, // packetsize
};
nvhttp_t nvhttp {
@@ -1252,6 +1253,7 @@ namespace config {
int_between_f(vars, "lan_encryption_mode", stream.lan_encryption_mode, {0, 2});
int_between_f(vars, "wan_encryption_mode", stream.wan_encryption_mode, {0, 2});
int_between_f(vars, "packetsize", stream.packetsize, {0, PACKETSIZE_MAX});
path_f(vars, "file_apps", stream.file_apps);
#ifndef __ANDROID__
+9
View File
@@ -16,6 +16,12 @@
#include "nvenc/nvenc_config.h"
namespace config {
// Valid range for the packetsize limit
constexpr int PACKETSIZE_MIN = 200;
constexpr int PACKETSIZE_MAX = 65535;
constexpr int PACKETSIZE_SMALL = 500;
constexpr int PACKETSIZE_LARGE = 1456;
// track modified config options
inline std::unordered_map<std::string, std::string> modified_config_settings;
@@ -177,6 +183,9 @@ namespace config {
// Video encryption settings for LAN and WAN streams
int lan_encryption_mode;
int wan_encryption_mode;
// Limit the packetsize to avoid fragmentation on a low MTU link
int packetsize;
};
struct nvhttp_t {
+17
View File
@@ -1004,6 +1004,23 @@ namespace rtsp_stream {
config.encryptionFlagsEnabled |= SS_ENC_AUDIO;
}
// Limit the packetsize to avoid fragmentation with clients that cannot configure this value
if (config::stream.packetsize && config::stream.packetsize < config.packetsize) {
if (config::stream.packetsize < config::PACKETSIZE_MIN || config::stream.packetsize > config::PACKETSIZE_MAX) {
BOOST_LOG(warning) << "packetsize range: ["sv << config::PACKETSIZE_MIN << "-"sv << config::PACKETSIZE_MAX
<< "] invalid value: "sv << config::stream.packetsize;
} else {
if (config::stream.packetsize < config::PACKETSIZE_SMALL) {
BOOST_LOG(info) << "packetsize is small < "sv << config::PACKETSIZE_SMALL << " bytes, reduce bitrate if the stream breaks"sv;
} else if (config::stream.packetsize > config::PACKETSIZE_LARGE) {
BOOST_LOG(info) << "packetsize is large > "sv << config::PACKETSIZE_LARGE << " bytes, jumbo frames may be used"sv;
}
BOOST_LOG(info) << "packetsize limit: "sv << config.packetsize << " -> "sv << config::stream.packetsize << " bytes"sv;
config.packetsize = config::stream.packetsize;
}
}
config.monitor.height = (int) util::from_view(args.at("x-nv-video[0].clientViewportHt"sv));
config.monitor.width = (int) util::from_view(args.at("x-nv-video[0].clientViewportWd"sv));
config.monitor.framerate = (int) util::from_view(args.at("x-nv-video[0].maxFPS"sv));