diff --git a/conf/config.ini b/conf/config.ini index bc2286b4..8c1a771c 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -155,6 +155,10 @@ on_server_started=https://127.0.0.1/index/hook/on_server_started on_server_keepalive=https://127.0.0.1/index/hook/on_server_keepalive #发送rtp(startSendRtp)被动关闭时回调 on_send_rtp_stopped=https://127.0.0.1/index/hook/on_send_rtp_stopped + +#rtp server 超时未收到数据 +on_rtp_server_timeout=https://127.0.0.1/index/hook/on_rtp_server_timeout + #hook api最大等待回复时间,单位秒 timeoutSec=10 #keepalive hook触发间隔,单位秒,float类型 diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 148a5992..df34cd5f 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -1761,6 +1761,11 @@ void installWebApi() { api_regist("/index/hook/on_server_keepalive",[](API_ARGS_JSON){ //心跳hook }); + + api_regist("/index/hook/on_rtp_server_timeout",[](API_ARGS_JSON){ + //rtp server 超时 + TraceL < cb) { if (_process) { @@ -55,8 +63,7 @@ public: if (!_process) { _process = RtpSelector::Instance().getProcess(_stream_id, true); _process->setOnDetach(std::move(_on_detach)); - _delay_task->cancel(); - _delay_task = nullptr; + cancelDelayTask(); } _process->inputRtp(true, sock, buf->data(), buf->size(), addr); @@ -91,11 +98,21 @@ public: if (!process && strong_self->_on_detach) { strong_self->_on_detach(); } + if(!process){ // process 未创建,触发rtp server 超时事件 + NoticeCenter::Instance().emitEvent(Broadcast::KBroadcastRtpServerTimeout,strong_self->_local_port,strong_self->_stream_id,(int)strong_self->_tcp_mode,strong_self->_re_use_port,strong_self->_ssrc); + } } return 0; }); } + void cancelDelayTask(){ + if(_delay_task){ + _delay_task->cancel(); + _delay_task = nullptr; + } + } + private: void sendRtcp(uint32_t rtp_ssrc, struct sockaddr *addr) { // 每5秒发送一次rtcp @@ -118,6 +135,12 @@ private: } private: + uint16_t _local_port = 0; + RtpServer::TcpMode _tcp_mode = RtpServer::NONE; + bool _re_use_port = false; + uint32_t _ssrc = 0; + + Ticker _ticker; Socket::Ptr _rtcp_sock; RtpProcess::Ptr _process; @@ -169,6 +192,7 @@ void RtpServer::start(uint16_t local_port, const string &stream_id, TcpMode tcp_ //指定了流id,那么一个端口一个流(不管是否包含多个ssrc的多个流,绑定rtp源后,会筛选掉ip端口不匹配的流) helper = std::make_shared(std::move(rtcp_socket), stream_id); helper->startRtcp(); + helper->setRtpServerInfo(local_port,tcp_mode,re_use_port,ssrc); rtp_socket->setOnRead([rtp_socket, helper, ssrc](const Buffer::Ptr &buf, struct sockaddr *addr, int addr_len) { RtpHeader *header = (RtpHeader *)buf->data(); auto rtp_ssrc = ntohl(header->ssrc);