mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-07-06 03:28:09 +08:00
添加配置项ultraLowDelay,可选择是否低延时模式
This commit is contained in:
@@ -11,8 +11,6 @@ using namespace mediakit::Client;
|
||||
|
||||
namespace mediakit {
|
||||
|
||||
static int kSockFlags = SOCKET_DEFAULE_FLAGS | FLAG_MORE;
|
||||
|
||||
RtspPusher::RtspPusher(const EventPoller::Ptr &poller,const RtspMediaSource::Ptr &src) : TcpClient(poller){
|
||||
_pMediaSrc = src;
|
||||
}
|
||||
@@ -392,13 +390,21 @@ void RtspPusher::sendRecord() {
|
||||
},getPoller()));
|
||||
}
|
||||
onPublishResult(SockException(Err_success,"success"));
|
||||
//提高发送性能
|
||||
(*this) << SocketFlags(kSockFlags);
|
||||
SockUtil::setNoDelay(_sock->rawFD(),false);
|
||||
//提升发送性能
|
||||
setSocketFlags();
|
||||
};
|
||||
sendRtspRequest("RECORD",_strContentBase,{"Range","npt=0.000-"});
|
||||
}
|
||||
|
||||
void RtspPusher::setSocketFlags(){
|
||||
GET_CONFIG(bool,ultraLowDelay,General::kUltraLowDelay);
|
||||
if(!ultraLowDelay) {
|
||||
//提高发送性能
|
||||
(*this) << SocketFlags(SOCKET_DEFAULE_FLAGS | FLAG_MORE);
|
||||
SockUtil::setNoDelay(_sock->rawFD(), false);
|
||||
}
|
||||
}
|
||||
|
||||
void RtspPusher::sendRtspRequest(const string &cmd, const string &url, const std::initializer_list<string> &header,const string &sdp ) {
|
||||
string key;
|
||||
StrCaseMap header_map;
|
||||
|
||||
@@ -67,6 +67,7 @@ private:
|
||||
void sendRtspRequest(const string &cmd, const string &url ,const std::initializer_list<string> &header,const string &sdp = "");
|
||||
|
||||
void createUdpSockIfNecessary(int track_idx);
|
||||
void setSocketFlags();
|
||||
private:
|
||||
//rtsp鉴权相关
|
||||
string _rtspMd5Nonce;
|
||||
|
||||
@@ -71,7 +71,6 @@ namespace mediakit {
|
||||
static unordered_map<string, weak_ptr<RtspSession> > g_mapGetter;
|
||||
//对g_mapGetter上锁保护
|
||||
static recursive_mutex g_mtxGetter;
|
||||
static int kSockFlags = SOCKET_DEFAULE_FLAGS | FLAG_MORE;
|
||||
|
||||
RtspSession::RtspSession(const Socket::Ptr &pSock) : TcpSession(pSock) {
|
||||
DebugP(this);
|
||||
@@ -277,12 +276,11 @@ void RtspSession::handleReq_RECORD(const Parser &parser){
|
||||
|
||||
rtp_info.pop_back();
|
||||
sendRtspResponse("200 OK", {"RTP-Info",rtp_info});
|
||||
SockUtil::setNoDelay(_sock->rawFD(),false);
|
||||
if(_rtpType == Rtsp::RTP_TCP){
|
||||
//如果是rtsp推流服务器,并且是TCP推流,那么加大TCP接收缓存,这样能提升接收性能
|
||||
_sock->setReadBuffer(std::make_shared<BufferRaw>(256 * 1024));
|
||||
setSocketFlags();
|
||||
}
|
||||
(*this) << SocketFlags(kSockFlags);
|
||||
};
|
||||
|
||||
weak_ptr<RtspSession> weakSelf = dynamic_pointer_cast<RtspSession>(shared_from_this());
|
||||
@@ -780,10 +778,7 @@ void RtspSession::handleReq_Play(const Parser &parser) {
|
||||
});
|
||||
|
||||
_enableSendRtp = true;
|
||||
|
||||
//提高发送性能
|
||||
SockUtil::setNoDelay(_sock->rawFD(),false);
|
||||
(*this) << SocketFlags(kSockFlags);
|
||||
setSocketFlags();
|
||||
|
||||
if (!_pRtpReader && _rtpType != Rtsp::RTP_MULTICAST) {
|
||||
weak_ptr<RtspSession> weakSelf = dynamic_pointer_cast<RtspSession>(shared_from_this());
|
||||
@@ -1230,6 +1225,16 @@ void RtspSession::sendSenderReport(bool overTcp,int iTrackIndex) {
|
||||
}
|
||||
}
|
||||
|
||||
void RtspSession::setSocketFlags(){
|
||||
GET_CONFIG(bool,ultraLowDelay,General::kUltraLowDelay);
|
||||
if(!ultraLowDelay) {
|
||||
//推流模式下,关闭TCP_NODELAY会增加推流端的延时,但是服务器性能将提高
|
||||
SockUtil::setNoDelay(_sock->rawFD(), false);
|
||||
//播放模式下,开启MSG_MORE会增加延时,但是能提高发送性能
|
||||
(*this) << SocketFlags(SOCKET_DEFAULE_FLAGS | FLAG_MORE);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
/* namespace mediakit */
|
||||
|
||||
|
||||
@@ -183,6 +183,8 @@ private:
|
||||
bool sendRtspResponse(const string &res_code,const StrCaseMap &header = StrCaseMap(), const string &sdp = "",const char *protocol = "RTSP/1.0");
|
||||
//服务器发送rtcp
|
||||
void sendSenderReport(bool overTcp,int iTrackIndex);
|
||||
//设置socket标志
|
||||
void setSocketFlags();
|
||||
private:
|
||||
//用于判断客户端是否超时
|
||||
Ticker _ticker;
|
||||
|
||||
Reference in New Issue
Block a user