Module: sems Branch: rco/multihomed Commit: 8ae6840ec380a637bcfdc967ece9cb7a863a2612 URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=8ae6840ec380a637bcfdc967ece9cb7a863a2612
Author: Raphael Coeffic <[email protected]> Committer: Raphael Coeffic <[email protected]> Date: Mon Feb 14 15:41:14 2011 +0100 adds multihomed support for RTP streams --- core/AmConfig.cpp | 32 ++++++++++++++++++++++++++++++++ core/AmConfig.h | 8 ++++++++ core/AmRtpAudio.cpp | 4 ++-- core/AmRtpAudio.h | 2 +- core/AmRtpStream.cpp | 32 ++++++-------------------------- core/AmRtpStream.h | 11 +++++------ core/AmSession.h | 2 +- 7 files changed, 55 insertions(+), 36 deletions(-) diff --git a/core/AmConfig.cpp b/core/AmConfig.cpp index d35d793..446c0f6 100644 --- a/core/AmConfig.cpp +++ b/core/AmConfig.cpp @@ -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; diff --git a/core/AmConfig.h b/core/AmConfig.h index a8b1a9d..b38fa85 100644 --- a/core/AmConfig.h +++ b/core/AmConfig.h @@ -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; diff --git a/core/AmRtpAudio.cpp b/core/AmRtpAudio.cpp index 496dbb0..b6eee05 100644 --- a/core/AmRtpAudio.cpp +++ b/core/AmRtpAudio.cpp @@ -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) diff --git a/core/AmRtpAudio.h b/core/AmRtpAudio.h index ac6f9c4..359490a 100644 --- a/core/AmRtpAudio.h +++ b/core/AmRtpAudio.h @@ -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); diff --git a/core/AmRtpStream.cpp b/core/AmRtpStream.cpp index f94d4f0..2669006 100644 --- a/core/AmRtpStream.cpp +++ b/core/AmRtpStream.cpp @@ -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), diff --git a/core/AmRtpStream.h b/core/AmRtpStream.h index f78f768..c982934 100644 --- a/core/AmRtpStream.h +++ b/core/AmRtpStream.h @@ -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(); diff --git a/core/AmSession.h b/core/AmSession.h index 642921b..b4a2c6f 100644 --- a/core/AmSession.h +++ b/core/AmSession.h @@ -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(); } _______________________________________________ Semsdev mailing list [email protected] http://lists.iptel.org/mailman/listinfo/semsdev
