新增rtp udp收流增加丢包率

This commit is contained in:
dingcan 2022-07-26 11:21:19 +08:00
parent e7cb05d3b4
commit ed6c80cf07
3 changed files with 19 additions and 1 deletions

View File

@ -280,6 +280,18 @@ std::shared_ptr<SockInfo> RtpProcess::getOriginSock(MediaSource &sender) const {
toolkit::EventPoller::Ptr RtpProcess::getOwnerPoller(MediaSource &sender) {
return _sock ? _sock->getPoller() : nullptr;
}
void RtpProcess::setHelper(const std::weak_ptr<RtcpContext> &help)
{
_help=help;
}
int RtpProcess::getLossRate(MediaSource &sender, TrackType type)
{
auto help = _help.lock();
auto expected = help->getExpectedPacketsInterval();
if (!expected) {
return 0;
}
return help->geLostInterval() * 100 / expected;
}
}//namespace mediakit
#endif//defined(ENABLE_RTPPROXY)

View File

@ -13,6 +13,7 @@
#if defined(ENABLE_RTPPROXY)
#include "ProcessInterface.h"
#include "Rtcp/RtcpContext.h"
#include "Common/MultiMediaSourceMuxer.h"
namespace mediakit {
@ -66,6 +67,8 @@ public:
int getTotalReaderCount();
void setListener(const std::weak_ptr<MediaSourceEvent> &listener);
void setHelper(const std::weak_ptr<RtcpContext> &help);
int getLossRate(MediaSource &sender, TrackType type) override;
protected:
bool inputFrame(const Frame::Ptr &frame) override;
bool addTrack(const Track::Ptr & track) override;
@ -99,6 +102,8 @@ private:
toolkit::Ticker _last_check_alive;
std::recursive_mutex _func_mtx;
std::deque<std::function<void()> > _cached_func;
std::weak_ptr<RtcpContext> _help;
};
}//namespace mediakit

View File

@ -127,6 +127,7 @@ void RtpServer::start(uint16_t local_port, const string &stream_id, bool enable_
//指定了流id那么一个端口一个流(不管是否包含多个ssrc的多个流绑定rtp源后会筛选掉ip端口不匹配的流)
process = RtpSelector::Instance().getProcess(stream_id, true);
RtcpHelper::Ptr helper = std::make_shared<RtcpHelper>(std::move(rtcp_socket), 90000);
process->setHelper(helper);
helper->startRtcp();
rtp_socket->setOnRead([rtp_socket, process, helper, ssrc](const Buffer::Ptr &buf, struct sockaddr *addr, int addr_len) {
RtpHeader *header = (RtpHeader *)buf->data();