mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 19:00:01 +08:00
完善nack/srtp相关代码
This commit is contained in:
parent
80ab84cbb5
commit
5c52c636a3
@ -192,7 +192,7 @@ uint64_t NackContext::reSendNack() {
|
|||||||
it = _nack_send_status.erase(it);
|
it = _nack_send_status.erase(it);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (now - it->second.update_stamp < 2 * _rtt) {
|
if (now - it->second.update_stamp < kNackIntervalRatio * _rtt) {
|
||||||
//距离上次nack不足2倍的rtt,不用再发送nack
|
//距离上次nack不足2倍的rtt,不用再发送nack
|
||||||
++it;
|
++it;
|
||||||
continue;
|
continue;
|
||||||
|
@ -39,11 +39,13 @@ public:
|
|||||||
using Ptr = std::shared_ptr<NackContext>;
|
using Ptr = std::shared_ptr<NackContext>;
|
||||||
using onNack = function<void(const FCI_NACK &nack)>;
|
using onNack = function<void(const FCI_NACK &nack)>;
|
||||||
//最大保留的rtp丢包状态个数
|
//最大保留的rtp丢包状态个数
|
||||||
static constexpr auto kNackMaxSize = 100;
|
static constexpr auto kNackMaxSize = 1024;
|
||||||
//rtp丢包状态最长保留时间
|
//rtp丢包状态最长保留时间
|
||||||
static constexpr auto kNackMaxMS = 3 * 1000;
|
static constexpr auto kNackMaxMS = 3 * 1000;
|
||||||
//nack最多请求重传10次
|
//nack最多请求重传10次
|
||||||
static constexpr auto kNackMaxCount = 10;
|
static constexpr auto kNackMaxCount = 10;
|
||||||
|
//nack重传频率,rtt的倍数
|
||||||
|
static constexpr auto kNackIntervalRatio = 2.0f;
|
||||||
|
|
||||||
NackContext() = default;
|
NackContext() = default;
|
||||||
~NackContext() = default;
|
~NackContext() = default;
|
||||||
|
@ -97,12 +97,7 @@ void WebRtcTransport::OnDtlsTransportConnected(
|
|||||||
std::string &remoteCert) {
|
std::string &remoteCert) {
|
||||||
InfoL;
|
InfoL;
|
||||||
_srtp_session_send = std::make_shared<RTC::SrtpSession>(RTC::SrtpSession::Type::OUTBOUND, srtpCryptoSuite, srtpLocalKey, srtpLocalKeyLen);
|
_srtp_session_send = std::make_shared<RTC::SrtpSession>(RTC::SrtpSession::Type::OUTBOUND, srtpCryptoSuite, srtpLocalKey, srtpLocalKeyLen);
|
||||||
|
_srtp_session_recv = std::make_shared<RTC::SrtpSession>(RTC::SrtpSession::Type::INBOUND, srtpCryptoSuite, srtpRemoteKey, srtpRemoteKeyLen);
|
||||||
string srtpRemoteKey_str((char *) srtpRemoteKey, srtpRemoteKeyLen);
|
|
||||||
_srtp_session_recv_alloc = [srtpCryptoSuite, srtpRemoteKey_str]() {
|
|
||||||
return std::make_shared<RTC::SrtpSession>(RTC::SrtpSession::Type::INBOUND, srtpCryptoSuite,
|
|
||||||
(uint8_t *) srtpRemoteKey_str.data(), srtpRemoteKey_str.size());
|
|
||||||
};
|
|
||||||
onStartWebRTC();
|
onStartWebRTC();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -255,19 +250,14 @@ void WebRtcTransport::inputSockData(char *buf, size_t len, RTC::TransportTuple *
|
|||||||
_dtls_transport->ProcessDtlsData((uint8_t *) buf, len);
|
_dtls_transport->ProcessDtlsData((uint8_t *) buf, len);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
RtpHeader *rtp = (RtpHeader *) buf;
|
|
||||||
auto it = _srtp_session_recv.find(rtp->pt);
|
|
||||||
if (it == _srtp_session_recv.end()) {
|
|
||||||
it = _srtp_session_recv.emplace((uint8_t) rtp->pt, _srtp_session_recv_alloc()).first;
|
|
||||||
}
|
|
||||||
if (is_rtp(buf)) {
|
if (is_rtp(buf)) {
|
||||||
if (it->second->DecryptSrtp((uint8_t *) buf, &len)) {
|
if (_srtp_session_recv->DecryptSrtp((uint8_t *) buf, &len)) {
|
||||||
onRtp(buf, len);
|
onRtp(buf, len);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (is_rtcp(buf)) {
|
if (is_rtcp(buf)) {
|
||||||
if (it->second->DecryptSrtcp((uint8_t *) buf, &len)) {
|
if (_srtp_session_recv->DecryptSrtcp((uint8_t *) buf, &len)) {
|
||||||
onRtcp(buf, len);
|
onRtcp(buf, len);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
@ -122,10 +122,9 @@ private:
|
|||||||
std::shared_ptr<RTC::IceServer> _ice_server;
|
std::shared_ptr<RTC::IceServer> _ice_server;
|
||||||
std::shared_ptr<RTC::DtlsTransport> _dtls_transport;
|
std::shared_ptr<RTC::DtlsTransport> _dtls_transport;
|
||||||
std::shared_ptr<RTC::SrtpSession> _srtp_session_send;
|
std::shared_ptr<RTC::SrtpSession> _srtp_session_send;
|
||||||
|
std::shared_ptr<RTC::SrtpSession> _srtp_session_recv;
|
||||||
RtcSession::Ptr _offer_sdp;
|
RtcSession::Ptr _offer_sdp;
|
||||||
RtcSession::Ptr _answer_sdp;
|
RtcSession::Ptr _answer_sdp;
|
||||||
function<std::shared_ptr<RTC::SrtpSession>() > _srtp_session_recv_alloc;
|
|
||||||
std::unordered_map<uint8_t /*pt*/, std::shared_ptr<RTC::SrtpSession> > _srtp_session_recv;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class RtpChannel;
|
class RtpChannel;
|
||||||
|
Loading…
Reference in New Issue
Block a user