From 3c40f171c153959a8f4d15120958caf70121099b Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Wed, 7 Feb 2018 13:43:44 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E6=92=AD=E5=9C=B0=E5=9D=80=E6=94=B9?= =?UTF-8?q?=E6=88=90=E5=AD=97=E7=AC=A6=E4=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/config.cpp | 8 ++------ src/Rtsp/RtpBroadCaster.cpp | 18 +++++++++++++----- src/Rtsp/RtpBroadCaster.h | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/Common/config.cpp b/src/Common/config.cpp index 909631b7..73b2d405 100644 --- a/src/Common/config.cpp +++ b/src/Common/config.cpp @@ -210,20 +210,16 @@ onceToken token([](){ namespace MultiCast { #define MULTI_FIELD "multicast." //组播分配起始地址 -#define MULTI_ADDR_MIN (0xE00000FF + 10) const char kAddrMin[] = MULTI_FIELD"addrMin"; - //组播分配截止地址 -#define MULTI_ADDR_MAX (0xEFFFFFFF) const char kAddrMax[] = MULTI_FIELD"addrMax"; - //组播TTL #define MULTI_UDP_TTL 64 const char kUdpTTL[] = MULTI_FIELD"udpTTL"; onceToken token([](){ - mINI::Instance()[kAddrMin] = MULTI_ADDR_MIN; - mINI::Instance()[kAddrMax] = MULTI_ADDR_MAX; + mINI::Instance()[kAddrMin] = "239.0.0.0"; + mINI::Instance()[kAddrMax] = "239.255.255.255"; mINI::Instance()[kUdpTTL] = MULTI_UDP_TTL; },nullptr); diff --git a/src/Rtsp/RtpBroadCaster.cpp b/src/Rtsp/RtpBroadCaster.cpp index 6f36f995..c6823f45 100644 --- a/src/Rtsp/RtpBroadCaster.cpp +++ b/src/Rtsp/RtpBroadCaster.cpp @@ -26,6 +26,7 @@ #include #include +#include #include "RtpBroadCaster.h" #include "Util/util.h" #include "Network/sockutil.h" @@ -36,12 +37,20 @@ using namespace std; namespace ZL { namespace Rtsp { +static uint32_t addressToInt(const string &ip){ + struct in_addr addr; + bzero(&addr,sizeof(addr)); + + inet_aton(ip.data(),&addr); + return (uint32_t)ntohl((uint32_t &)addr.s_addr); +} std::shared_ptr MultiCastAddressMaker::obtain(uint32_t iTry) { lock_guard lck(m_mtx); - static uint32_t addrMin = mINI::Instance()[Config::MultiCast::kAddrMin].as(); - static uint32_t addrMax = mINI::Instance()[Config::MultiCast::kAddrMax].as(); - if(m_iAddr > addrMax){ + static uint32_t addrMin = addressToInt(mINI::Instance()[Config::MultiCast::kAddrMin]); + static uint32_t addrMax = addressToInt(mINI::Instance()[Config::MultiCast::kAddrMax]); + + if(m_iAddr > addrMax || m_iAddr == 0){ m_iAddr = addrMin; } auto iGotAddr = m_iAddr++; @@ -56,8 +65,7 @@ std::shared_ptr MultiCastAddressMaker::obtain(uint32_t iTry) { } m_setBadAddr.emplace(iGotAddr); std::shared_ptr ret(new uint32_t(iGotAddr),[](uint32_t *ptr){ - auto val = *ptr; - MultiCastAddressMaker::Instance().release(val); + MultiCastAddressMaker::Instance().release(*ptr); delete ptr; }); return ret; diff --git a/src/Rtsp/RtpBroadCaster.h b/src/Rtsp/RtpBroadCaster.h index 135903bd..0f318d39 100644 --- a/src/Rtsp/RtpBroadCaster.h +++ b/src/Rtsp/RtpBroadCaster.h @@ -65,7 +65,7 @@ public: private: MultiCastAddressMaker(){}; void release(uint32_t iAddr); - uint32_t m_iAddr = mINI::Instance()[Config::MultiCast::kAddrMin].as(); + uint32_t m_iAddr = 0; recursive_mutex m_mtx; unordered_set m_setBadAddr; };