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; };