From 943509231e05cfbebdb58450176b661a02b3b860 Mon Sep 17 00:00:00 2001 From: Stefan Sayer Date: Thu, 10 Jan 2008 18:14:00 +0000 Subject: [PATCH] config option to selectively exclude some payloads (=codecs) git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@600 8eb893ce-cfd4-0310-b710-fb5ebe64c474 --- core/AmConfig.cpp | 4 ++++ core/AmConfig.h | 2 ++ core/AmPlugIn.cpp | 32 +++++++++++++++++++++++++------- core/AmPlugIn.h | 5 +++++ core/etc/sems.conf.sample | 13 +++++++++++++ core/sems.cpp | 1 + 6 files changed, 50 insertions(+), 7 deletions(-) diff --git a/core/AmConfig.cpp b/core/AmConfig.cpp index 7761f5d2..7024d2bf 100644 --- a/core/AmConfig.cpp +++ b/core/AmConfig.cpp @@ -44,6 +44,7 @@ unsigned int AmConfig::SmtpServerPort = SMTP_PORT; string AmConfig::PlugInPath = PLUG_IN_PATH; string AmConfig::LoadPlugins = ""; string AmConfig::ExcludePlugins = ""; +string AmConfig::ExcludePayloads = ""; int AmConfig::DaemonMode = DEFAULT_DAEMON_MODE; string AmConfig::LocalIP = ""; string AmConfig::PrefixSep = PREFIX_SEPARATOR; @@ -192,6 +193,9 @@ int AmConfig::readConfiguration() // exclude_plugins ExcludePlugins = cfg.getParameter("exclude_plugins"); + // exclude_plugins + ExcludePayloads = cfg.getParameter("exclude_payloads"); + // user_agent if (cfg.getParameter("use_default_signature")=="yes") Signature = DEFAULT_SIGNATURE; diff --git a/core/AmConfig.h b/core/AmConfig.h index 624f1969..ff905b9d 100644 --- a/core/AmConfig.h +++ b/core/AmConfig.h @@ -58,6 +58,8 @@ struct AmConfig static string LoadPlugins; /** semicolon separated list of plugins to exclude from loading */ static string ExcludePlugins; + /** semicolon separated list of payloads to exclude from loading */ + static string ExcludePayloads; //static unsigned int MaxRecordTime; /** run the programm in daemon mode? */ static int DaemonMode; diff --git a/core/AmPlugIn.cpp b/core/AmPlugIn.cpp index 3c62a1a2..9f5da3cf 100644 --- a/core/AmPlugIn.cpp +++ b/core/AmPlugIn.cpp @@ -101,13 +101,9 @@ amci_payload_t _payload_tevent = { AmPlugIn* AmPlugIn::_instance=0; AmPlugIn::AmPlugIn() - : dynamic_pl(DYNAMIC_PAYLOAD_TYPE_START) + : dynamic_pl(DYNAMIC_PAYLOAD_TYPE_START), + ctrlIface(NULL) { - DBG("adding built-in codecs...\n"); - addCodec(&_codec_pcm16); - addCodec(&_codec_tevent); - addPayload(&_payload_tevent); - ctrlIface = NULL; } AmPlugIn::~AmPlugIn() @@ -124,6 +120,20 @@ AmPlugIn* AmPlugIn::instance() return _instance; } +void AmPlugIn::init() { + vector excluded_payloads_v = + explode(AmConfig::ExcludePayloads, ";"); + for (vector::iterator it = + excluded_payloads_v.begin(); + it != excluded_payloads_v.end();it++) + excluded_payloads.insert(*it); + + DBG("adding built-in codecs...\n"); + addCodec(&_codec_pcm16); + addCodec(&_codec_tevent); + addPayload(&_payload_tevent); +} + int AmPlugIn::load(const string& directory, const string& plugins) { @@ -621,10 +631,18 @@ int AmPlugIn::addCodec(amci_codec_t* c) int AmPlugIn::addPayload(amci_payload_t* p) { + if (excluded_payloads.find(p->name) != + excluded_payloads.end()) { + DBG("Not enabling excluded payload '%s'\n", + p->name); + return 0; + } + amci_codec_t* c; unsigned int i, id; if( !(c = codec(p->codec_id)) ){ - ERROR("in payload '%s': codec id (%i) not supported\n",p->name,p->codec_id); + ERROR("in payload '%s': codec id (%i) not supported\n", + p->name, p->codec_id); return -1; } if(p->payload_id != -1){ diff --git a/core/AmPlugIn.h b/core/AmPlugIn.h index e23e154e..def537f5 100644 --- a/core/AmPlugIn.h +++ b/core/AmPlugIn.h @@ -32,9 +32,11 @@ #include #include #include +#include using std::string; using std::map; using std::vector; +using std::set; class AmPluginFactory; class AmSessionFactory; @@ -80,6 +82,7 @@ class AmPlugIn AmCtrlInterface *ctrlIface; int dynamic_pl; // range: 96->127, see RFC 1890 + set excluded_payloads; // don't load these payloads (named) AmPlugIn(); ~AmPlugIn(); @@ -104,6 +107,8 @@ class AmPlugIn static AmPlugIn* instance(); + void init(); + /** * Loads all plug-ins from the directory given as parameter. * @return -1 if failed, else 0. diff --git a/core/etc/sems.conf.sample b/core/etc/sems.conf.sample index c6ac63a4..e8c8a433 100644 --- a/core/etc/sems.conf.sample +++ b/core/etc/sems.conf.sample @@ -67,6 +67,19 @@ plugin_path=/usr/local/lib/sems/plug-in/ # exclude_plugins=binrpcctrl; + +# optional parameter: exclude_payloads= +# +# semicolon-separated list of payloads to exclude from loading +# ('blacklist'). +# +# For example, to only use low bandwidth codecs: +# exclude_payloads=PCMU;PCMA;G726-40;G726-32;G721; +# or, to use only codecs which are not CPU-intensive: +# exclude_payloads=iLBC;speex; +# only use G711 (exclude everything else): +# exclude_payloads=iLBC;speex;G726-40;G726-32;G721;G726-24;G726-16;GSM + # optional parameter: smtp_server= # # - sets address of smtp server diff --git a/core/sems.cpp b/core/sems.cpp index 833b798d..6c6d3efc 100644 --- a/core/sems.cpp +++ b/core/sems.cpp @@ -361,6 +361,7 @@ int main(int argc, char* argv[]) return -1; DBG("Loading plug-ins\n"); + AmPlugIn::instance()->init(); if(AmPlugIn::instance()->load(AmConfig::PlugInPath, AmConfig::LoadPlugins)) return -1;