rtsp/rtmp超时时间可配置

This commit is contained in:
xiongziliang 2019-05-29 18:24:35 +08:00
parent a39c4c1344
commit e9e21e11a2
4 changed files with 27 additions and 6 deletions

View File

@ -158,10 +158,13 @@ onceToken token([](){
namespace Rtsp { namespace Rtsp {
#define RTSP_FIELD "rtsp." #define RTSP_FIELD "rtsp."
const char kAuthBasic[] = RTSP_FIELD"authBasic"; const char kAuthBasic[] = RTSP_FIELD"authBasic";
const char kHandshakeSecond[] = RTSP_FIELD"handshakeSecond";
const char kKeepAliveSecond[] = RTSP_FIELD"keepAliveSecond";
onceToken token([](){ onceToken token([](){
//默认Md5方式认证 //默认Md5方式认证
mINI::Instance()[kAuthBasic] = 0; mINI::Instance()[kAuthBasic] = 0;
mINI::Instance()[kHandshakeSecond] = 15;
mINI::Instance()[kKeepAliveSecond] = 15;
},nullptr); },nullptr);
} //namespace Rtsp } //namespace Rtsp
@ -170,10 +173,15 @@ onceToken token([](){
namespace Rtmp { namespace Rtmp {
#define RTMP_FIELD "rtmp." #define RTMP_FIELD "rtmp."
const char kModifyStamp[] = RTMP_FIELD"modifyStamp"; const char kModifyStamp[] = RTMP_FIELD"modifyStamp";
const char kHandshakeSecond[] = RTMP_FIELD"handshakeSecond";
const char kKeepAliveSecond[] = RTMP_FIELD"keepAliveSecond";
onceToken token([](){ onceToken token([](){
mINI::Instance()[kModifyStamp] = true; mINI::Instance()[kModifyStamp] = true;
mINI::Instance()[kHandshakeSecond] = 15;
mINI::Instance()[kKeepAliveSecond] = 15;
},nullptr); },nullptr);
} //namespace RTMP } //namespace RTMP

View File

@ -194,12 +194,19 @@ extern const char kMaxReqSize[];
namespace Rtsp { namespace Rtsp {
//是否优先base64方式认证默认Md5方式认证 //是否优先base64方式认证默认Md5方式认证
extern const char kAuthBasic[]; extern const char kAuthBasic[];
//握手超时时间默认15秒
extern const char kHandshakeSecond[];
//维持链接超时时间默认15秒
extern const char kKeepAliveSecond[];
} //namespace Rtsp } //namespace Rtsp
////////////RTMP服务器配置/////////// ////////////RTMP服务器配置///////////
namespace Rtmp { namespace Rtmp {
extern const char kModifyStamp[]; extern const char kModifyStamp[];
//握手超时时间默认15秒
extern const char kHandshakeSecond[];
//维持链接超时时间默认15秒
extern const char kKeepAliveSecond[];
} //namespace RTMP } //namespace RTMP

View File

@ -63,14 +63,17 @@ void RtmpSession::onError(const SockException& err) {
} }
void RtmpSession::onManager() { void RtmpSession::onManager() {
if (_ticker.createdTime() > 15 * 1000) { GET_CONFIG(uint32_t,handshake_sec,Rtmp::kKeepAliveSecond);
GET_CONFIG(uint32_t,keep_alive_sec,Rtmp::kKeepAliveSecond);
if (_ticker.createdTime() > handshake_sec * 1000) {
if (!_pRingReader && !_pPublisherSrc) { if (!_pRingReader && !_pPublisherSrc) {
shutdown(SockException(Err_timeout,"illegal connection")); shutdown(SockException(Err_timeout,"illegal connection"));
} }
} }
if (_pPublisherSrc) { if (_pPublisherSrc) {
//publisher //publisher
if (_ticker.elapsedTime() > 15 * 1000) { if (_ticker.elapsedTime() > keep_alive_sec * 1000) {
shutdown(SockException(Err_timeout,"recv data from rtmp pusher timeout")); shutdown(SockException(Err_timeout,"recv data from rtmp pusher timeout"));
} }
} }

View File

@ -111,7 +111,10 @@ void RtspSession::onError(const SockException& err) {
} }
void RtspSession::onManager() { void RtspSession::onManager() {
if (_ticker.createdTime() > 15 * 1000) { GET_CONFIG(uint32_t,handshake_sec,Rtsp::kKeepAliveSecond);
GET_CONFIG(uint32_t,keep_alive_sec,Rtsp::kKeepAliveSecond);
if (_ticker.createdTime() > handshake_sec * 1000) {
if (_strSession.size() == 0) { if (_strSession.size() == 0) {
shutdown(SockException(Err_timeout,"illegal connection")); shutdown(SockException(Err_timeout,"illegal connection"));
return; return;
@ -119,7 +122,7 @@ void RtspSession::onManager() {
} }
if ((_rtpType == Rtsp::RTP_UDP || _pushSrc ) && _ticker.elapsedTime() > 15 * 1000) { if ((_rtpType == Rtsp::RTP_UDP || _pushSrc ) && _ticker.elapsedTime() > keep_alive_sec * 1000) {
//如果是推流端或者rtp over udp类型的播放端那么就做超时检测 //如果是推流端或者rtp over udp类型的播放端那么就做超时检测
shutdown(SockException(Err_timeout,"rtp over udp session timeouted")); shutdown(SockException(Err_timeout,"rtp over udp session timeouted"));
return; return;