adds multihomed support for RTP streams

sayer/1.4-spce2.6
Raphael Coeffic 16 years ago
parent 35cc7601a5
commit e3f48aba8c

@ -101,6 +101,38 @@ bool AmConfig::IgnoreSIGPIPE = true;
static int readInterfaces(AmConfigReader& cfg);
AmConfig::IP_interface::IP_interface()
: LocalSIPIP(),
LocalSIPPort(5060),
LocalIP(),
PublicIP(),
RtpLowPort(RTP_LOWPORT),
RtpHighPort(RTP_HIGHPORT)
{
}
int AmConfig::IP_interface::getNextRtpPort()
{
int port=0;
next_rtp_port_mut.lock();
if(next_rtp_port < 0){
next_rtp_port = RtpLowPort;
}
port = next_rtp_port & 0xfffe;
next_rtp_port += 2;
if(next_rtp_port >= RtpHighPort){
next_rtp_port = RtpLowPort;
}
next_rtp_port_mut.unlock();
return port;
}
int AmConfig::setLogLevel(const string& level, bool apply)
{
int n;

@ -98,6 +98,14 @@ struct AmConfig
string LocalSIPIP;
/** the port SIP requests are sent from - optional (default 5060) */
int LocalSIPPort;
IP_interface();
int getNextRtpPort();
private:
int next_rtp_port;
AmMutex next_rtp_port_mut;
};
static vector<IP_interface> Ifs;

@ -31,8 +31,8 @@
#include "AmSession.h"
#include "AmPlayoutBuffer.h"
AmRtpAudio::AmRtpAudio(AmSession* _s)
: AmRtpStream(_s), AmAudio(0),
AmRtpAudio::AmRtpAudio(AmSession* _s, int _if)
: AmRtpStream(_s,_if), AmAudio(0),
/*last_ts_i(false),*/ use_default_plc(true),
send_only(false), playout_buffer(new AmPlayoutBuffer(this)),
last_check(0),last_check_i(false),send_int(false)

@ -93,7 +93,7 @@ class AmRtpAudio: public AmRtpStream, public AmAudio, public AmPLCBuffer
unsigned int rate);
public:
AmRtpAudio(AmSession* _s=0);
AmRtpAudio(AmSession* _s, int _if);
~AmRtpAudio();
bool checkInterval(unsigned int ts, unsigned int frame_size);

@ -75,35 +75,14 @@ void AmRtpStream::setLocalIP(const string& ip)
#endif
}
int AmRtpStream::next_port = -1;
AmMutex AmRtpStream::port_mut;
int AmRtpStream::getNextPort()
{
int port=0;
port_mut.lock();
if(next_port < 0){
next_port = AmConfig::RtpLowPort();
}
port = next_port & 0xfffe;
next_port += 2;
if(next_port >= AmConfig::RtpHighPort()){
next_port = AmConfig::RtpLowPort();
}
port_mut.unlock();
return port;
}
void AmRtpStream::setLocalPort()
{
if(l_port)
return;
assert(l_if >= 0);
assert(l_if < (int)AmConfig::Ifs.size());
int sd=0;
#ifdef SUPPORT_IPV6
if((sd = socket(l_saddr.ss_family,SOCK_DGRAM,0)) == -1)
@ -125,7 +104,7 @@ void AmRtpStream::setLocalPort()
unsigned short port = 0;
for(;retry; --retry){
port = getNextPort();
port = AmConfig::Ifs[l_if].getNextRtpPort();
#ifdef SUPPORT_IPV6
set_port_v6(&l_saddr,port);
if(!bind(sd,(const struct sockaddr*)&l_saddr,
@ -424,8 +403,9 @@ int AmRtpStream::receive( unsigned char* buffer, unsigned int size,
return res;
}
AmRtpStream::AmRtpStream(AmSession* _s)
AmRtpStream::AmRtpStream(AmSession* _s, int _if)
: r_port(0),
l_if(_if),
l_port(0),
l_sd(0),
r_ssrc_i(false),

@ -87,11 +87,6 @@ struct PacketMem {
class AmRtpStream
{
protected:
static int next_port;
static AmMutex port_mut;
static int getNextPort();
/**
Remote payload (only different from
int_payload if using dynamic payloads)
@ -108,6 +103,10 @@ protected:
string r_host;
unsigned short r_port;
/* local interface */
int l_if;
#ifdef SUPPORT_IPV6
struct sockaddr_storage r_saddr;
struct sockaddr_storage l_saddr;
@ -191,7 +190,7 @@ public:
int ping();
/** Allocates resources for future use of RTP. */
AmRtpStream(AmSession* _s=0);
AmRtpStream(AmSession* _s, int _if);
/** Stops the stream and frees all resources. */
virtual ~AmRtpStream();

@ -620,7 +620,7 @@ inline AmRtpAudio* AmSession::RTPStream() {
if (NULL == _rtp_str.get()) {
DBG("creating RTP stream instance for session [%p]\n",
this);
_rtp_str.reset(new AmRtpAudio(this));
_rtp_str.reset(new AmRtpAudio(this,rtp_interface));
}
return _rtp_str.get();
}

Loading…
Cancel
Save