Commit 986e9511 by xiongziliang

完善rtt相关代码

parent 4c296488
...@@ -103,7 +103,7 @@ void RtcpContext::onRtcp(RtcpHeader *rtcp) { ...@@ -103,7 +103,7 @@ void RtcpContext::onRtcp(RtcpHeader *rtcp) {
//转换为毫秒 //转换为毫秒
auto ms_inc = ntpmsw_inc * 1000 + (ntplsw_inc / ((double) (((uint64_t) 1) << 32) * 1.0e-3)); auto ms_inc = ntpmsw_inc * 1000 + (ntplsw_inc / ((double) (((uint64_t) 1) << 32) * 1.0e-3));
auto rtt = (int) ((ms_inc - delay_ms) / 2); auto rtt = (int) (ms_inc - delay_ms);
_rtt[item->ssrc] = rtt; _rtt[item->ssrc] = rtt;
//InfoL << "ssrc:" << item->ssrc << ",rtt:" << rtt; //InfoL << "ssrc:" << item->ssrc << ",rtt:" << rtt;
} }
...@@ -113,6 +113,14 @@ void RtcpContext::onRtcp(RtcpHeader *rtcp) { ...@@ -113,6 +113,14 @@ void RtcpContext::onRtcp(RtcpHeader *rtcp) {
} }
} }
uint32_t RtcpContext::getRtt(uint32_t ssrc) const {
auto it = _rtt.find(ssrc);
if (it == _rtt.end()) {
return 0;
}
return it->second;
}
size_t RtcpContext::getExpectedPackets() const { size_t RtcpContext::getExpectedPackets() const {
if (!_is_receiver) { if (!_is_receiver) {
throw std::runtime_error("rtp发送者无法统计应收包数"); throw std::runtime_error("rtp发送者无法统计应收包数");
......
...@@ -71,6 +71,13 @@ public: ...@@ -71,6 +71,13 @@ public:
*/ */
void clear(); void clear();
/**
* 获取rtt
* @param ssrc rtp ssrc
* @return rtt,单位毫秒
*/
uint32_t getRtt(uint32_t ssrc) const;
private: private:
/** /**
* 上次结果与本次结果间应收包数 * 上次结果与本次结果间应收包数
......
...@@ -640,6 +640,7 @@ void WebRtcTransportImp::onRtcp(const char *buf, size_t len) { ...@@ -640,6 +640,7 @@ void WebRtcTransportImp::onRtcp(const char *buf, size_t len) {
auto it = _ssrc_to_track.find(item->ssrc); auto it = _ssrc_to_track.find(item->ssrc);
if (it != _ssrc_to_track.end()) { if (it != _ssrc_to_track.end()) {
auto &track = it->second; auto &track = it->second;
track->rtcp_context_send->onRtcp(rtcp);
auto sr = track->rtcp_context_send->createRtcpSR(track->answer_ssrc_rtp); auto sr = track->rtcp_context_send->createRtcpSR(track->answer_ssrc_rtp);
sendRtcpPacket(sr->data(), sr->size(), true); sendRtcpPacket(sr->data(), sr->size(), true);
} else { } else {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论