From 83d75c9a720476ee7e760a79e6f09a14b362554f Mon Sep 17 00:00:00 2001 From: xiongguangjie Date: Mon, 6 Jun 2022 19:55:47 +0800 Subject: [PATCH] add srt config for lantency multiplier --- conf/config.ini | 3 +++ srt/SrtTransport.cpp | 6 +++--- srt/SrtTransport.hpp | 6 ++++-- srt/SrtTransportImp.cpp | 5 +++++ srt/SrtTransportImp.hpp | 1 + 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/conf/config.ini b/conf/config.ini index 7a199215..21931088 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -291,6 +291,9 @@ timeoutSec=5 #该端口是多线程的,同时支持客户端网络切换导致的连接迁移 port=9000 +#srt 协议中延迟缓存的估算参数,在握手阶段估算rtt ,然后lantencyMul*rtt 为最大缓存时长,此参数越大,表示等待重传的时长就越大 +lantencyMul=4 + [rtsp] #rtsp专有鉴权方式是采用base64还是md5方式 diff --git a/srt/SrtTransport.cpp b/srt/SrtTransport.cpp index b127092d..e7a84bf3 100644 --- a/srt/SrtTransport.cpp +++ b/srt/SrtTransport.cpp @@ -11,6 +11,8 @@ const std::string kTimeOutSec = SRT_FIELD"timeoutSec"; //srt 单端口udp服务器 const std::string kPort = SRT_FIELD"port"; +const std::string kLantencyMul = SRT_FIELD"lantencyMul"; + static std::atomic s_srt_socket_id_generate{125}; //////////// SrtTransport ////////////////////////// SrtTransport::SrtTransport(const EventPoller::Ptr &poller) @@ -155,7 +157,7 @@ void SrtTransport::handleHandshakeConclusion(HandshakePacket &pkt, struct sockad HSExtMessage::Ptr req; HSExtStreamID::Ptr sid; uint32_t srt_flag = 0xbf; - uint16_t delay = DurationCountMicroseconds(_now - _induction_ts)*4/1000; + uint16_t delay = DurationCountMicroseconds(_now - _induction_ts)*getLantencyMul()/1000; for (auto ext : pkt.ext_list) { //TraceL << getIdentifier() << " ext " << ext->dump(); @@ -210,8 +212,6 @@ void SrtTransport::handleHandshakeConclusion(HandshakePacket &pkt, struct sockad } _last_ack_pkt_seq_num = _init_seq_number; } -void SrtTransport::bufCheckInterval(){ -} void SrtTransport::handleHandshake(uint8_t *buf, int len, struct sockaddr_storage *addr){ HandshakePacket pkt; assert(pkt.loadFromData(buf,len)); diff --git a/srt/SrtTransport.hpp b/srt/SrtTransport.hpp index 4f9c20cd..c055dd62 100644 --- a/srt/SrtTransport.hpp +++ b/srt/SrtTransport.hpp @@ -21,6 +21,7 @@ using namespace toolkit; extern const std::string kPort; extern const std::string kTimeOutSec; +extern const std::string kLantencyMul; class SrtTransport : public std::enable_shared_from_this { public: @@ -81,13 +82,14 @@ private: void sendShutDown(); void sendMsgDropReq(uint32_t first ,uint32_t last); - void bufCheckInterval(); - size_t getPayloadSize(); protected: void sendDataPacket(DataPacket::Ptr pkt,char* buf,int len,bool flush = false); void sendControlPacket(ControlPacket::Ptr pkt,bool flush = true); virtual void sendPacket(Buffer::Ptr pkt,bool flush = true); + virtual int getLantencyMul(){ + return 4; + }; private: //当前选中的udp链接 Session::Ptr _selected_session; diff --git a/srt/SrtTransportImp.cpp b/srt/SrtTransportImp.cpp index b12e6e7c..9425e2e7 100644 --- a/srt/SrtTransportImp.cpp +++ b/srt/SrtTransportImp.cpp @@ -273,5 +273,10 @@ void SrtTransportImp::doCachedFunc() { _cached_func.clear(); } +int SrtTransportImp::getLantencyMul(){ + GET_CONFIG(int, lantencyMul, kLantencyMul); + return lantencyMul; +} + } // namespace SRT \ No newline at end of file diff --git a/srt/SrtTransportImp.hpp b/srt/SrtTransportImp.hpp index 36a07e01..5e259632 100644 --- a/srt/SrtTransportImp.hpp +++ b/srt/SrtTransportImp.hpp @@ -38,6 +38,7 @@ protected: void onHandShakeFinished(std::string& streamid,struct sockaddr_storage *addr) override; void onSRTData(DataPacket::Ptr pkt) override; void onShutdown(const SockException &ex) override; + int getLantencyMul() override; void sendPacket(Buffer::Ptr pkt,bool flush = true) override{ _total_bytes += pkt->size();