Commit 3c40f171 by xiongziliang

组播地址改成字符串

parent 5ed2ce40
...@@ -210,20 +210,16 @@ onceToken token([](){ ...@@ -210,20 +210,16 @@ onceToken token([](){
namespace MultiCast { namespace MultiCast {
#define MULTI_FIELD "multicast." #define MULTI_FIELD "multicast."
//组播分配起始地址 //组播分配起始地址
#define MULTI_ADDR_MIN (0xE00000FF + 10)
const char kAddrMin[] = MULTI_FIELD"addrMin"; const char kAddrMin[] = MULTI_FIELD"addrMin";
//组播分配截止地址 //组播分配截止地址
#define MULTI_ADDR_MAX (0xEFFFFFFF)
const char kAddrMax[] = MULTI_FIELD"addrMax"; const char kAddrMax[] = MULTI_FIELD"addrMax";
//组播TTL //组播TTL
#define MULTI_UDP_TTL 64 #define MULTI_UDP_TTL 64
const char kUdpTTL[] = MULTI_FIELD"udpTTL"; const char kUdpTTL[] = MULTI_FIELD"udpTTL";
onceToken token([](){ onceToken token([](){
mINI::Instance()[kAddrMin] = MULTI_ADDR_MIN; mINI::Instance()[kAddrMin] = "239.0.0.0";
mINI::Instance()[kAddrMax] = MULTI_ADDR_MAX; mINI::Instance()[kAddrMax] = "239.255.255.255";
mINI::Instance()[kUdpTTL] = MULTI_UDP_TTL; mINI::Instance()[kUdpTTL] = MULTI_UDP_TTL;
},nullptr); },nullptr);
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <list> #include <list>
#include <type_traits> #include <type_traits>
#include <arpa/inet.h>
#include "RtpBroadCaster.h" #include "RtpBroadCaster.h"
#include "Util/util.h" #include "Util/util.h"
#include "Network/sockutil.h" #include "Network/sockutil.h"
...@@ -36,12 +37,20 @@ using namespace std; ...@@ -36,12 +37,20 @@ using namespace std;
namespace ZL { namespace ZL {
namespace Rtsp { 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<uint32_t> MultiCastAddressMaker::obtain(uint32_t iTry) { std::shared_ptr<uint32_t> MultiCastAddressMaker::obtain(uint32_t iTry) {
lock_guard<recursive_mutex> lck(m_mtx); lock_guard<recursive_mutex> lck(m_mtx);
static uint32_t addrMin = mINI::Instance()[Config::MultiCast::kAddrMin].as<uint32_t>(); static uint32_t addrMin = addressToInt(mINI::Instance()[Config::MultiCast::kAddrMin]);
static uint32_t addrMax = mINI::Instance()[Config::MultiCast::kAddrMax].as<uint32_t>(); static uint32_t addrMax = addressToInt(mINI::Instance()[Config::MultiCast::kAddrMax]);
if(m_iAddr > addrMax){
if(m_iAddr > addrMax || m_iAddr == 0){
m_iAddr = addrMin; m_iAddr = addrMin;
} }
auto iGotAddr = m_iAddr++; auto iGotAddr = m_iAddr++;
...@@ -56,8 +65,7 @@ std::shared_ptr<uint32_t> MultiCastAddressMaker::obtain(uint32_t iTry) { ...@@ -56,8 +65,7 @@ std::shared_ptr<uint32_t> MultiCastAddressMaker::obtain(uint32_t iTry) {
} }
m_setBadAddr.emplace(iGotAddr); m_setBadAddr.emplace(iGotAddr);
std::shared_ptr<uint32_t> ret(new uint32_t(iGotAddr),[](uint32_t *ptr){ std::shared_ptr<uint32_t> ret(new uint32_t(iGotAddr),[](uint32_t *ptr){
auto val = *ptr; MultiCastAddressMaker::Instance().release(*ptr);
MultiCastAddressMaker::Instance().release(val);
delete ptr; delete ptr;
}); });
return ret; return ret;
......
...@@ -65,7 +65,7 @@ public: ...@@ -65,7 +65,7 @@ public:
private: private:
MultiCastAddressMaker(){}; MultiCastAddressMaker(){};
void release(uint32_t iAddr); void release(uint32_t iAddr);
uint32_t m_iAddr = mINI::Instance()[Config::MultiCast::kAddrMin].as<uint32_t>(); uint32_t m_iAddr = 0;
recursive_mutex m_mtx; recursive_mutex m_mtx;
unordered_set<uint32_t> m_setBadAddr; unordered_set<uint32_t> m_setBadAddr;
}; };
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论