组播地址改成字符串

This commit is contained in:
xiongziliang 2018-02-07 13:43:44 +08:00
parent 5ed2ce40fe
commit 3c40f171c1
3 changed files with 16 additions and 12 deletions

View File

@ -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);

View File

@ -26,6 +26,7 @@
#include <list>
#include <type_traits>
#include <arpa/inet.h>
#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<uint32_t> MultiCastAddressMaker::obtain(uint32_t iTry) {
lock_guard<recursive_mutex> lck(m_mtx);
static uint32_t addrMin = mINI::Instance()[Config::MultiCast::kAddrMin].as<uint32_t>();
static uint32_t addrMax = mINI::Instance()[Config::MultiCast::kAddrMax].as<uint32_t>();
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<uint32_t> MultiCastAddressMaker::obtain(uint32_t iTry) {
}
m_setBadAddr.emplace(iGotAddr);
std::shared_ptr<uint32_t> ret(new uint32_t(iGotAddr),[](uint32_t *ptr){
auto val = *ptr;
MultiCastAddressMaker::Instance().release(val);
MultiCastAddressMaker::Instance().release(*ptr);
delete ptr;
});
return ret;

View File

@ -65,7 +65,7 @@ public:
private:
MultiCastAddressMaker(){};
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;
unordered_set<uint32_t> m_setBadAddr;
};