From 4b22e189d5700207b5da3a4e744a0b38d91f6624 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Sat, 2 Jan 2021 22:32:13 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BD=AE=E6=B5=81=E5=8F=91=E9=80=81rtcp?= =?UTF-8?q?=E4=B8=8EGET=5FPARAMETER=E4=BF=9D=E6=B4=BB:#642?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtsp/RtspPlayer.cpp | 35 ++++++++++++++++++++--------------- src/Rtsp/RtspPlayer.h | 8 +++++--- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/src/Rtsp/RtspPlayer.cpp b/src/Rtsp/RtspPlayer.cpp index f692d54a..e7f8e601 100644 --- a/src/Rtsp/RtspPlayer.cpp +++ b/src/Rtsp/RtspPlayer.cpp @@ -385,7 +385,7 @@ void RtspPlayer::sendOptions(){ } void RtspPlayer::sendKeepAlive(){ - _on_response = [this](const Parser& parser){}; + _on_response = [](const Parser &parser) {}; if(_supported_cmd.find("GET_PARAMETER") != _supported_cmd.end()){ //支持GET_PARAMETER,用此命令保活 sendRtspRequest("GET_PARAMETER", _content_base); @@ -728,20 +728,25 @@ void RtspPlayer::onRecvRTP_l(const RtpPacket::Ptr &rtp, const SdpTrack::Ptr &tra RtcpCounter &counter = _rtcp_counter[track_idx]; counter.pktCnt = rtp->sequence; auto &ticker = _rtcp_send_ticker[track_idx]; - if (ticker.elapsedTime() > 5 * 1000) { - //send rtcp every 5 second - counter.lastTimeStamp = counter.timeStamp; - //直接保存网络字节序 - memcpy(&counter.timeStamp, rtp->data() + 8, 4); - if (counter.lastTimeStamp != 0) { - sendReceiverReport(_rtp_type == Rtsp::RTP_TCP, track_idx); - ticker.resetTime(); - } - - //有些rtsp服务器需要rtcp保活,有些需要发送信令保活 - if (track_idx == 0) { - //只需要发送一次心跳信令包 - sendKeepAlive(); + if (ticker.elapsedTime() > 3 * 1000) { + //每3秒发送一次心跳,rtcp与rtsp信令轮流心跳,该特性用于兼容issue:642 + if (_send_rtcp) { + counter.lastTimeStamp = counter.timeStamp; + //直接保存网络字节序 + memcpy(&counter.timeStamp, rtp->data() + 8, 4); + if (counter.lastTimeStamp != 0) { + sendReceiverReport(_rtp_type == Rtsp::RTP_TCP, track_idx); + ticker.resetTime(); + _send_rtcp = false; + } + } else { + //有些rtsp服务器需要rtcp保活,有些需要发送信令保活 + if (track_idx == 0) { + //只需要发送一次心跳信令包 + sendKeepAlive(); + ticker.resetTime(); + _send_rtcp = true; + } } } } diff --git a/src/Rtsp/RtspPlayer.h b/src/Rtsp/RtspPlayer.h index e6529a23..14a58766 100644 --- a/src/Rtsp/RtspPlayer.h +++ b/src/Rtsp/RtspPlayer.h @@ -109,6 +109,11 @@ private: void createUdpSockIfNecessary(int track_idx); private: + //是否为性能测试模式 + bool _benchmark_mode = false; + //轮流发送rtcp与GET_PARAMETER保活 + bool _send_rtcp = true; + string _play_url; vector _sdp_track; function _on_response; @@ -143,9 +148,6 @@ private: //rtcp发送时间,trackid idx 为数组下标 Ticker _rtcp_send_ticker[2]; - //是否为性能测试模式 - bool _benchmark_mode = false; - //服务器支持的命令 set _supported_cmd; };