From 895e93cb6aae82f9fd6f19b0980c28062b6b9d2f Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Sun, 20 Aug 2023 12:07:04 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AB=AF=E5=8F=A3=E6=B1=A0=E5=88=86=E9=85=8D?= =?UTF-8?q?=E7=AB=AF=E5=8F=A3=E6=94=B9=E6=88=90=E6=97=A0=E5=BA=8F=E5=88=86?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解决zlmediakit重启后端口重复分配导致国标串流问题 --- src/Rtsp/Rtsp.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Rtsp/Rtsp.cpp b/src/Rtsp/Rtsp.cpp index b5b50360..579a881e 100644 --- a/src/Rtsp/Rtsp.cpp +++ b/src/Rtsp/Rtsp.cpp @@ -8,12 +8,13 @@ * may be found in the AUTHORS file in the root of the source tree. */ +#include +#include +#include #include "Rtsp.h" #include "Common/Parser.h" #include "Common/config.h" #include "Network/Socket.h" -#include -#include using namespace std; using namespace toolkit; @@ -392,9 +393,13 @@ public: private: void setRange(uint16_t start_pos, uint16_t end_pos) { + std::mt19937 rng(std::random_device {}()); lock_guard lck(_pool_mtx); + auto it = _port_pair_pool.begin(); while (start_pos < end_pos) { - _port_pair_pool.emplace_back(start_pos++); + // 随机端口排序,防止重启后导致分配的端口重复 + _port_pair_pool.insert(it, start_pos++); + it = _port_pair_pool.begin() + (rng() % (1 + _port_pair_pool.size())); } }