From 4b9f789c798fc7fce66bc4609c747470ca57b841 Mon Sep 17 00:00:00 2001 From: xiongguangjie Date: Sat, 11 Jun 2022 22:51:11 +0800 Subject: [PATCH] add srt recv and send packet buf size --- conf/config.ini | 3 +++ srt/SrtTransport.cpp | 5 +++-- srt/SrtTransport.hpp | 2 ++ srt/SrtTransportImp.cpp | 6 ++++++ srt/SrtTransportImp.hpp | 1 + 5 files changed, 15 insertions(+), 2 deletions(-) diff --git a/conf/config.ini b/conf/config.ini index 5a468bd7..13729497 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -294,6 +294,9 @@ port=9000 #srt 协议中延迟缓存的估算参数,在握手阶段估算rtt ,然后latencyMul*rtt 为最大缓存时长,此参数越大,表示等待重传的时长就越大 latencyMul=4 +#包缓存的大小 +pktBufSize=8192 + [rtsp] #rtsp专有鉴权方式是采用base64还是md5方式 diff --git a/srt/SrtTransport.cpp b/srt/SrtTransport.cpp index 4714bc64..f30efb83 100644 --- a/srt/SrtTransport.cpp +++ b/srt/SrtTransport.cpp @@ -12,6 +12,7 @@ const std::string kTimeOutSec = SRT_FIELD "timeoutSec"; // srt 单端口udp服务器 const std::string kPort = SRT_FIELD "port"; const std::string kLatencyMul = SRT_FIELD "latencyMul"; +const std::string kPktBufSize = SRT_FIELD "pktBufSize"; static std::atomic s_srt_socket_id_generate { 125 }; //////////// SrtTransport ////////////////////////// @@ -207,8 +208,8 @@ void SrtTransport::handleHandshakeConclusion(HandshakePacket &pkt, struct sockad sendControlPacket(res, true); TraceL << " buf size = " << res->max_flow_window_size << " init seq =" << _init_seq_number << " latency=" << delay; - _recv_buf = std::make_shared(res->max_flow_window_size, _init_seq_number, delay * 1e3); - _send_buf = std::make_shared(res->max_flow_window_size, delay * 1e3); + _recv_buf = std::make_shared(getPktBufSize(), _init_seq_number, delay * 1e3); + _send_buf = std::make_shared(getPktBufSize(), delay * 1e3); _send_packet_seq_number = _init_seq_number; _buf_delay = delay; onHandShakeFinished(_stream_id, addr); diff --git a/srt/SrtTransport.hpp b/srt/SrtTransport.hpp index 27281063..eae99100 100644 --- a/srt/SrtTransport.hpp +++ b/srt/SrtTransport.hpp @@ -23,6 +23,7 @@ using namespace toolkit; extern const std::string kPort; extern const std::string kTimeOutSec; extern const std::string kLatencyMul; +extern const std::string kPktBufSize; class SrtTransport : public std::enable_shared_from_this { public: @@ -55,6 +56,7 @@ protected: virtual void onHandShakeFinished(std::string &streamid, struct sockaddr_storage *addr) {}; virtual void sendPacket(Buffer::Ptr pkt, bool flush = true); virtual int getLatencyMul() { return 4; }; + virtual int getPktBufSize() { return 8192; }; private: void registerSelf(); diff --git a/srt/SrtTransportImp.cpp b/srt/SrtTransportImp.cpp index 275b3ba3..1eb716c4 100644 --- a/srt/SrtTransportImp.cpp +++ b/srt/SrtTransportImp.cpp @@ -326,4 +326,10 @@ int SrtTransportImp::getLatencyMul() { return latencyMul; } +int SrtTransportImp::getPktBufSize() { + // kPktBufSize + GET_CONFIG(int, pktBufSize, kPktBufSize); + return pktBufSize; +} + } // namespace SRT \ No newline at end of file diff --git a/srt/SrtTransportImp.hpp b/srt/SrtTransportImp.hpp index e9df2024..73ee4a67 100644 --- a/srt/SrtTransportImp.hpp +++ b/srt/SrtTransportImp.hpp @@ -36,6 +36,7 @@ public: protected: ///////SrtTransport override/////// int getLatencyMul() override; + int getPktBufSize() override; void onSRTData(DataPacket::Ptr pkt) override; void onShutdown(const SockException &ex) override; void onHandShakeFinished(std::string &streamid, struct sockaddr_storage *addr) override;