From 019791dd090365eb10f0d72c7ffc0c4885e127ad Mon Sep 17 00:00:00 2001 From: Stefan Sayer Date: Wed, 1 Aug 2007 18:44:57 +0000 Subject: [PATCH] fixes o SEMS-7: RTP extension headers may be ignored if ignore_rtpxheaders=yes set in config file o if changing payload type fails, packet will not be processed o minor code beautification and comments added/corrected git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@418 8eb893ce-cfd4-0310-b710-fb5ebe64c474 --- core/AmAudio.cpp | 8 +++++--- core/AmAudio.h | 5 ++++- core/AmConfig.cpp | 7 +++++++ core/AmConfig.h | 3 +++ core/AmPlugIn.cpp | 3 ++- core/AmRtpAudio.cpp | 22 +++++++++++++++------- core/AmRtpAudio.h | 2 +- core/AmRtpPacket.cpp | 16 +++++++++++++--- core/AmSdp.cpp | 2 +- core/AmSdp.h | 2 ++ core/rtp/rtp.h | 5 +++++ core/sems.conf.sample | 18 +++++++++++++++--- 12 files changed, 73 insertions(+), 20 deletions(-) diff --git a/core/AmAudio.cpp b/core/AmAudio.cpp index 2bd1656a..51dc1694 100644 --- a/core/AmAudio.cpp +++ b/core/AmAudio.cpp @@ -59,7 +59,7 @@ AmAudioRtpFormat::AmAudioRtpFormat(const vector& payloads) setCurrentPayload(m_payloads[0]->payload_type); } -void AmAudioRtpFormat::setCurrentPayload(int payload) +int AmAudioRtpFormat::setCurrentPayload(int payload) { if (m_currentPayload != payload) { @@ -67,7 +67,7 @@ void AmAudioRtpFormat::setCurrentPayload(int payload) if (p == m_sdpPayloadByPayload.end()) { ERROR("Could not find payload <%i>\n", payload); - return; + return -1; } map::iterator pp = m_payloadPByPayload.find(payload); if (pp == m_payloadPByPayload.end()) @@ -76,7 +76,7 @@ void AmAudioRtpFormat::setCurrentPayload(int payload) if (m_currentPayloadP == NULL) { ERROR("Could not find payload <%i>\n", payload); - return; + return -1; } m_payloadPByPayload[payload] = m_currentPayloadP; } @@ -114,8 +114,10 @@ void AmAudioRtpFormat::setCurrentPayload(int payload) rate = m_currentPayloadP->sample_rate; } else { ERROR("Could not find payload <%i>\n", payload); + return -1; } } + return 0; } AmAudioRtpFormat::~AmAudioRtpFormat() diff --git a/core/AmAudio.h b/core/AmAudio.h index 59ba8a97..a0c1d61b 100644 --- a/core/AmAudio.h +++ b/core/AmAudio.h @@ -230,7 +230,10 @@ public: AmAudioRtpFormat(const vector& payloads); ~AmAudioRtpFormat(); - void setCurrentPayload(int payload); + /** + * changes payload. returns != 0 on error. + */ + int setCurrentPayload(int payload); }; /** diff --git a/core/AmConfig.cpp b/core/AmConfig.cpp index f01915fe..199ebd3a 100644 --- a/core/AmConfig.cpp +++ b/core/AmConfig.cpp @@ -58,6 +58,8 @@ string AmConfig::LocalSIPIP = ""; string AmConfig::Signature = ""; bool AmConfig::SingleCodecInOK = false; unsigned int AmConfig::DeadRtpTime = DEAD_RTP_TIME; +bool AmConfig::IgnoreRTPXHdrs = false; + vector AmConfig::CodecOrder; AmSessionTimerConfig AmConfig::defaultSessionTimerConfig; @@ -257,6 +259,11 @@ int AmConfig::readConfiguration() SingleCodecInOK = (cfg.getParameter("single_codec_in_ok") == "yes"); } + // single codec in 200 OK + if(cfg.hasParameter("ignore_rtpxheaders")){ + IgnoreRTPXHdrs = (cfg.getParameter("ignore_rtpxheaders") == "yes"); + } + // codec_order CodecOrder = explode(cfg.getParameter("codec_order"), ","); diff --git a/core/AmConfig.h b/core/AmConfig.h index e912f0db..3608e746 100644 --- a/core/AmConfig.h +++ b/core/AmConfig.h @@ -92,6 +92,9 @@ struct AmConfig /** Time of no RTP after which Session is regarded as dead, 0 for no Timeout */ static unsigned int DeadRtpTime; + /** Ignore RTP Extension headers? */ + static bool IgnoreRTPXHdrs; + /** Init function. Resolves SMTP server address. */ static int init(); diff --git a/core/AmPlugIn.cpp b/core/AmPlugIn.cpp index 28721dce..325ce178 100644 --- a/core/AmPlugIn.cpp +++ b/core/AmPlugIn.cpp @@ -31,6 +31,7 @@ #include "AmApi.h" #include "AmInterfaceHandler.h" #include "AmUtils.h" +#include "AmSdp.h" #include "amci/amci.h" #include "amci/codecs.h" @@ -96,7 +97,7 @@ amci_payload_t _payload_tevent = { AmPlugIn* AmPlugIn::_instance=0; AmPlugIn::AmPlugIn() - : dynamic_pl(96) // range: 96->127, see RFC 1890 + : dynamic_pl(DYNAMIC_PAYLOAD_TYPE_START) { DBG("adding built-in codecs...\n"); addCodec(&_codec_pcm16); diff --git a/core/AmRtpAudio.cpp b/core/AmRtpAudio.cpp index fe3508b5..a5ae442a 100644 --- a/core/AmRtpAudio.cpp +++ b/core/AmRtpAudio.cpp @@ -84,9 +84,13 @@ int AmRtpAudio::receive(unsigned int wallclock_ts) if(size <= 0) break; - setCurrentPayload(payload); - - if(send_only){ + if (// don't process if we don't need to + send_only || + // ignore CN + COMFORT_NOISE_PAYLOAD_TYPE == payload || + // ignore packet if payload not found + setCurrentPayload(payload) + ){ playout_buffer->clearLastTs(); continue; } @@ -133,11 +137,15 @@ void AmRtpAudio::init(const vector& sdp_payloads) fmt.reset(new AmAudioRtpFormat(sdp_payloads)); } -void AmRtpAudio::setCurrentPayload(int payload) +int AmRtpAudio::setCurrentPayload(int payload) { - ((AmAudioRtpFormat *) fmt.get())->setCurrentPayload(payload); - amci_codec_t* codec = fmt->getCodec(); - use_default_plc = !(codec && codec->plc); + int res = + ((AmAudioRtpFormat *) fmt.get())->setCurrentPayload(payload); + if (!res) { + amci_codec_t* codec = fmt->getCodec(); + use_default_plc = !(codec && codec->plc); + } + return res; } unsigned int AmRtpAudio::conceal_loss(unsigned int ts_diff, unsigned char *buffer) diff --git a/core/AmRtpAudio.h b/core/AmRtpAudio.h index 60628672..be193f99 100644 --- a/core/AmRtpAudio.h +++ b/core/AmRtpAudio.h @@ -88,7 +88,7 @@ public: bool checkInterval(unsigned int ts); bool sendIntReached(); - void setCurrentPayload(int payload); + int setCurrentPayload(int payload); int receive(unsigned int wallclock_ts); diff --git a/core/AmRtpPacket.cpp b/core/AmRtpPacket.cpp index ba7e574c..c61a1897 100644 --- a/core/AmRtpPacket.cpp +++ b/core/AmRtpPacket.cpp @@ -28,6 +28,7 @@ #include "AmRtpPacket.h" #include "rtp/rtp.h" #include "log.h" +#include "AmConfig.h" #include #include @@ -88,9 +89,19 @@ int AmRtpPacket::parse() return -1; } + data_offset = sizeof(rtp_hdr_t) + (hdr->cc*4); + if(hdr->x != 0){ - DBG("RTP extension headers not supported.\n"); - return -1; + if (AmConfig::IgnoreRTPXHdrs) { + // skip the extension header + if (b_size >= data_offset + 4) { + data_offset += + ntohs(((rtp_xhdr_t*) (buffer + data_offset))->len)*4; + } + } else { + DBG("RTP extension headers not supported.\n"); + return -1; + } } payload = hdr->pt; @@ -99,7 +110,6 @@ int AmRtpPacket::parse() timestamp = ntohl(hdr->ts); ssrc = ntohl(hdr->ssrc); - data_offset = sizeof(rtp_hdr_t) + (hdr->cc*4); if (data_offset >= b_size) { ERROR("bad rtp packet (header size too big) !\n"); return -1; diff --git a/core/AmSdp.cpp b/core/AmSdp.cpp index 7e954848..e55ea7a7 100644 --- a/core/AmSdp.cpp +++ b/core/AmSdp.cpp @@ -308,7 +308,7 @@ const vector& AmSdp::getCompatiblePayloads(int media_type, string& for(; it != m_it->payloads.end(); ++it ) { amci_payload_t* a_pl = NULL; - if(it->payload_type < 96){ + if(it->payload_type < DYNAMIC_PAYLOAD_TYPE_START){ // try static payloads a_pl = pi->payload(it->payload_type); } diff --git a/core/AmSdp.h b/core/AmSdp.h index ada0e672..77ee21b9 100644 --- a/core/AmSdp.h +++ b/core/AmSdp.h @@ -36,6 +36,8 @@ using std::map; using std::vector; +#define COMFORT_NOISE_PAYLOAD_TYPE 13 // RFC 3389 +#define DYNAMIC_PAYLOAD_TYPE_START 96 // range: 96->127, see RFC 1890 /** * @file AmSdp.h * Definitions for the SDP parser. diff --git a/core/rtp/rtp.h b/core/rtp/rtp.h index 696a409b..4c3c366c 100644 --- a/core/rtp/rtp.h +++ b/core/rtp/rtp.h @@ -70,4 +70,9 @@ typedef struct { u_int32 ssrc; /* synchronization source */ } rtp_hdr_t; +typedef struct { + u_int16 profile; /* xhdr type */ + u_int16 len; /* xhdr length */ +} rtp_xhdr_t; + #endif diff --git a/core/sems.conf.sample b/core/sems.conf.sample index 54a87ceb..22d243f8 100644 --- a/core/sems.conf.sample +++ b/core/sems.conf.sample @@ -81,12 +81,12 @@ smtp_port=25 # optional parameter: rtp_low_port= # -# - sets port of rtp lowest server +# - sets lowest for RTP used port rtp_low_port=10000 # optional parameter: rtp_high_port= # -# - sets port of rtp highest server +# - sets highest for RTP used port rtp_high_port=60000 # optional parameter: media_processor_threads= @@ -174,4 +174,16 @@ media_processor_threads=1 # # default=empty # -# codec_order=iLBC,GSM +# codec_order=iLBC,GSM + +# optional parameter: ignore_rtpxheaders={yes|no} +# +# - if this is set to yes, RTP extension headers (e.g. when using ZRTP) +# are ignored. If set to no, the whole RTP packets with extension +# headers will be ignored and a debug message is printed on every +# received packet. +# +# default=no +# +# ignore_rtpxheaders=yes +