Commit 6fd20711 by 夏楚 Committed by GitHub

Merge pull request #1829 from dcan123/master

新增rtp udp收流增加丢包率
parents e7cb05d3 23e0abde
...@@ -281,5 +281,21 @@ toolkit::EventPoller::Ptr RtpProcess::getOwnerPoller(MediaSource &sender) { ...@@ -281,5 +281,21 @@ toolkit::EventPoller::Ptr RtpProcess::getOwnerPoller(MediaSource &sender) {
return _sock ? _sock->getPoller() : nullptr; return _sock ? _sock->getPoller() : nullptr;
} }
void RtpProcess::setHelper(std::weak_ptr<RtcpContext> help) {
_help = std::move(help);
}
int RtpProcess::getLossRate(MediaSource &sender, TrackType type) {
auto help = _help.lock();
if (!help) {
return -1;
}
auto expected = help->getExpectedPacketsInterval();
if (!expected) {
return 0;
}
return help->geLostInterval() * 100 / expected;
}
}//namespace mediakit }//namespace mediakit
#endif//defined(ENABLE_RTPPROXY) #endif//defined(ENABLE_RTPPROXY)
\ No newline at end of file
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
#if defined(ENABLE_RTPPROXY) #if defined(ENABLE_RTPPROXY)
#include "ProcessInterface.h" #include "ProcessInterface.h"
#include "Rtcp/RtcpContext.h"
#include "Common/MultiMediaSourceMuxer.h" #include "Common/MultiMediaSourceMuxer.h"
namespace mediakit { namespace mediakit {
...@@ -66,6 +67,8 @@ public: ...@@ -66,6 +67,8 @@ public:
int getTotalReaderCount(); int getTotalReaderCount();
void setListener(const std::weak_ptr<MediaSourceEvent> &listener); void setListener(const std::weak_ptr<MediaSourceEvent> &listener);
void setHelper(const std::weak_ptr<RtcpContext> help);
int getLossRate(MediaSource &sender, TrackType type) override;
protected: protected:
bool inputFrame(const Frame::Ptr &frame) override; bool inputFrame(const Frame::Ptr &frame) override;
bool addTrack(const Track::Ptr & track) override; bool addTrack(const Track::Ptr & track) override;
...@@ -99,6 +102,7 @@ private: ...@@ -99,6 +102,7 @@ private:
toolkit::Ticker _last_check_alive; toolkit::Ticker _last_check_alive;
std::recursive_mutex _func_mtx; std::recursive_mutex _func_mtx;
std::deque<std::function<void()> > _cached_func; std::deque<std::function<void()> > _cached_func;
std::weak_ptr<RtcpContext> _help;
}; };
}//namespace mediakit }//namespace mediakit
......
...@@ -127,6 +127,7 @@ void RtpServer::start(uint16_t local_port, const string &stream_id, bool enable_ ...@@ -127,6 +127,7 @@ void RtpServer::start(uint16_t local_port, const string &stream_id, bool enable_
//指定了流id,那么一个端口一个流(不管是否包含多个ssrc的多个流,绑定rtp源后,会筛选掉ip端口不匹配的流) //指定了流id,那么一个端口一个流(不管是否包含多个ssrc的多个流,绑定rtp源后,会筛选掉ip端口不匹配的流)
process = RtpSelector::Instance().getProcess(stream_id, true); process = RtpSelector::Instance().getProcess(stream_id, true);
RtcpHelper::Ptr helper = std::make_shared<RtcpHelper>(std::move(rtcp_socket), 90000); RtcpHelper::Ptr helper = std::make_shared<RtcpHelper>(std::move(rtcp_socket), 90000);
process->setHelper(helper);
helper->startRtcp(); helper->startRtcp();
rtp_socket->setOnRead([rtp_socket, process, helper, ssrc](const Buffer::Ptr &buf, struct sockaddr *addr, int addr_len) { rtp_socket->setOnRead([rtp_socket, process, helper, ssrc](const Buffer::Ptr &buf, struct sockaddr *addr, int addr_len) {
RtpHeader *header = (RtpHeader *)buf->data(); RtpHeader *header = (RtpHeader *)buf->data();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论