From ed6c80cf077d5cdf07d7ba57f977351609f3104c Mon Sep 17 00:00:00 2001 From: dingcan Date: Tue, 26 Jul 2022 11:21:19 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E6=96=B0=E5=A2=9Ertp=20udp=E6=94=B6?= =?UTF-8?q?=E6=B5=81=E5=A2=9E=E5=8A=A0=E4=B8=A2=E5=8C=85=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtp/RtpProcess.cpp | 14 +++++++++++++- src/Rtp/RtpProcess.h | 5 +++++ src/Rtp/RtpServer.cpp | 1 + 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Rtp/RtpProcess.cpp b/src/Rtp/RtpProcess.cpp index e3767d7b..7ce5c507 100644 --- a/src/Rtp/RtpProcess.cpp +++ b/src/Rtp/RtpProcess.cpp @@ -280,6 +280,18 @@ std::shared_ptr RtpProcess::getOriginSock(MediaSource &sender) const { toolkit::EventPoller::Ptr RtpProcess::getOwnerPoller(MediaSource &sender) { return _sock ? _sock->getPoller() : nullptr; } - +void RtpProcess::setHelper(const std::weak_ptr &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) \ No newline at end of file diff --git a/src/Rtp/RtpProcess.h b/src/Rtp/RtpProcess.h index 93dd37fe..1241c21d 100644 --- a/src/Rtp/RtpProcess.h +++ b/src/Rtp/RtpProcess.h @@ -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 &listener); + void setHelper(const std::weak_ptr &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 > _cached_func; + + std::weak_ptr _help; }; }//namespace mediakit diff --git a/src/Rtp/RtpServer.cpp b/src/Rtp/RtpServer.cpp index 8cee24ff..0d47ff88 100644 --- a/src/Rtp/RtpServer.cpp +++ b/src/Rtp/RtpServer.cpp @@ -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(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(); From c1b4ccd04113653410ddfb98ba21164418a69610 Mon Sep 17 00:00:00 2001 From: dingcan <627403134@qq.com> Date: Tue, 26 Jul 2022 11:57:09 +0800 Subject: [PATCH 2/6] Update RtpProcess.cpp --- src/Rtp/RtpProcess.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Rtp/RtpProcess.cpp b/src/Rtp/RtpProcess.cpp index 7ce5c507..d004110b 100644 --- a/src/Rtp/RtpProcess.cpp +++ b/src/Rtp/RtpProcess.cpp @@ -291,6 +291,7 @@ int RtpProcess::getLossRate(MediaSource &sender, TrackType type) if (!expected) { return 0; } + return help->geLostInterval() * 100 / expected; } }//namespace mediakit From b8d17565d7d1e0e6d0a5640a28c8980c9f4bdb4d Mon Sep 17 00:00:00 2001 From: dingcan <627403134@qq.com> Date: Tue, 26 Jul 2022 14:42:42 +0800 Subject: [PATCH 3/6] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtp/RtpProcess.cpp | 15 +++++++++------ src/Rtp/RtpProcess.h | 2 +- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/Rtp/RtpProcess.cpp b/src/Rtp/RtpProcess.cpp index d004110b..b8c497a6 100644 --- a/src/Rtp/RtpProcess.cpp +++ b/src/Rtp/RtpProcess.cpp @@ -280,19 +280,22 @@ std::shared_ptr RtpProcess::getOriginSock(MediaSource &sender) const { toolkit::EventPoller::Ptr RtpProcess::getOwnerPoller(MediaSource &sender) { return _sock ? _sock->getPoller() : nullptr; } -void RtpProcess::setHelper(const std::weak_ptr &help) -{ - _help=help; + +void RtpProcess::setHelper(const std::weak_ptr help){ + _help = std::move(help); } -int RtpProcess::getLossRate(MediaSource &sender, TrackType type) -{ + +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 #endif//defined(ENABLE_RTPPROXY) \ No newline at end of file diff --git a/src/Rtp/RtpProcess.h b/src/Rtp/RtpProcess.h index 1241c21d..89e9b575 100644 --- a/src/Rtp/RtpProcess.h +++ b/src/Rtp/RtpProcess.h @@ -67,7 +67,7 @@ public: int getTotalReaderCount(); void setListener(const std::weak_ptr &listener); - void setHelper(const std::weak_ptr &help); + void setHelper(const std::weak_ptr help); int getLossRate(MediaSource &sender, TrackType type) override; protected: bool inputFrame(const Frame::Ptr &frame) override; From 532932fd2d23ad3e3acb8ad506aa457d7f352bfd Mon Sep 17 00:00:00 2001 From: dingcan <627403134@qq.com> Date: Tue, 26 Jul 2022 14:44:32 +0800 Subject: [PATCH 4/6] Update RtpProcess.h --- src/Rtp/RtpProcess.h | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Rtp/RtpProcess.h b/src/Rtp/RtpProcess.h index 89e9b575..e6f9b6bd 100644 --- a/src/Rtp/RtpProcess.h +++ b/src/Rtp/RtpProcess.h @@ -102,7 +102,6 @@ private: toolkit::Ticker _last_check_alive; std::recursive_mutex _func_mtx; std::deque > _cached_func; - std::weak_ptr _help; }; From 0a678661e37534aff2d4cb441b42aaf861d03ffa Mon Sep 17 00:00:00 2001 From: dingcan Date: Wed, 27 Jul 2022 10:02:15 +0800 Subject: [PATCH 5/6] Update RtpProcess.cpp --- src/Rtp/RtpProcess.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Rtp/RtpProcess.cpp b/src/Rtp/RtpProcess.cpp index b8c497a6..66ba1cc1 100644 --- a/src/Rtp/RtpProcess.cpp +++ b/src/Rtp/RtpProcess.cpp @@ -291,10 +291,10 @@ int RtpProcess::getLossRate(MediaSource &sender, TrackType type){ return -1; } auto expected = help->getExpectedPacketsInterval(); - if (!expected) { - return 0; - } - return help->geLostInterval() * 100 / expected; + if (!expected) { + return 0; + } + return help->geLostInterval() * 100 / expected; } }//namespace mediakit From 23e0abde04446caf006db1ddbca369bd8ef1d4bf Mon Sep 17 00:00:00 2001 From: dingcan Date: Wed, 27 Jul 2022 14:13:54 +0800 Subject: [PATCH 6/6] Update RtpProcess.cpp --- src/Rtp/RtpProcess.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Rtp/RtpProcess.cpp b/src/Rtp/RtpProcess.cpp index 66ba1cc1..d224a3ee 100644 --- a/src/Rtp/RtpProcess.cpp +++ b/src/Rtp/RtpProcess.cpp @@ -281,13 +281,13 @@ toolkit::EventPoller::Ptr RtpProcess::getOwnerPoller(MediaSource &sender) { return _sock ? _sock->getPoller() : nullptr; } -void RtpProcess::setHelper(const std::weak_ptr help){ +void RtpProcess::setHelper(std::weak_ptr help) { _help = std::move(help); } -int RtpProcess::getLossRate(MediaSource &sender, TrackType type){ +int RtpProcess::getLossRate(MediaSource &sender, TrackType type) { auto help = _help.lock(); - if(!help){ + if (!help) { return -1; } auto expected = help->getExpectedPacketsInterval();