codec order priority patch ba juha.

git-svn-id: http://svn.berlios.de/svnroot/repos/sems/trunk@315 8eb893ce-cfd4-0310-b710-fb5ebe64c474
sayer/1.4-spce2.6
Stefan Sayer 19 years ago
parent e75cecf3d3
commit a1d2158b6f

@ -35,6 +35,7 @@
#include "sems.h"
#include "log.h"
#include "AmConfigReader.h"
#include "AmUtils.h"
string AmConfig::ConfigurationFile = CONFIG_FILE;
string AmConfig::ModConfigPath = MOD_CFG_PATH;
@ -57,6 +58,7 @@ string AmConfig::LocalSIPIP = "";
string AmConfig::Signature = "";
bool AmConfig::SingleCodecInOK = false;
unsigned int AmConfig::DeadRtpTime = DEAD_RTP_TIME;
vector <string> AmConfig::CodecOrder;
AmSessionTimerConfig AmConfig::defaultSessionTimerConfig;
@ -247,11 +249,14 @@ int AmConfig::readConfiguration()
return -1;
}
}
// single codec in 200 OK
if(cfg.hasParameter("single_codec_in_ok")){
SingleCodecInOK = (cfg.getParameter("single_codec_in_ok") == "yes");
}
// codec_order
CodecOrder = explode(cfg.getParameter("codec_order"), ",");
// dead_rtp_time
if(cfg.hasParameter("dead_rtp_time")){
@ -337,5 +342,3 @@ int AmSessionTimerConfig::setMinimumTimer(const string& minse) {
return 1;
}
/* end Session Timer: -ssa */

@ -87,6 +87,7 @@ struct AmConfig
static string Signature;
/** If 200 OK reply should be limited to preferred codec only */
static bool SingleCodecInOK;
static vector <string> CodecOrder;
/** Time of no RTP after which Session is regarded as dead, 0 for no Timeout */
static unsigned int DeadRtpTime;

@ -502,6 +502,7 @@ int AmPlugIn::addCodec(amci_codec_t* c)
int AmPlugIn::addPayload(amci_payload_t* p)
{
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);
return -1;
@ -512,14 +513,27 @@ int AmPlugIn::addPayload(amci_payload_t* p)
return -1;
}
payloads.insert(std::make_pair(p->payload_id,p));
DBG("payload '%s'inserted with id %i \n",p->name,p->payload_id);
id = p->payload_id;
}
else {
payloads.insert(std::make_pair(dynamic_pl,p));
DBG("payload '%s'inserted with id %i \n",p->name,dynamic_pl);
id = dynamic_pl;
dynamic_pl++;
}
for (i = 0; i < AmConfig::CodecOrder.size(); i++) {
if (p->name == AmConfig::CodecOrder[i]) break;
}
if (i >= AmConfig::CodecOrder.size()) {
payload_order.insert(std::make_pair(id + 100, id));
DBG("payload '%s' inserted with id %i and order %i\n",
p->name, id, id + 100);
} else {
payload_order.insert(std::make_pair(i, id));
DBG("payload '%s' inserted with id %i and order %i\n",
p->name, id, i);
}
return 0;
}

@ -66,6 +66,7 @@ class AmPlugIn
map<int,amci_codec_t*> codecs;
map<int,amci_payload_t*> payloads;
map<int,int> payload_order;
map<string,amci_inoutfmt_t*> file_formats;
map<string,AmSessionFactory*> name2app;
@ -108,6 +109,8 @@ class AmPlugIn
amci_payload_t* payload(int payload_id);
/** @return the suported payloads. */
const map<int,amci_payload_t*>& getPayloads() { return payloads; }
/** @return the order of payloads. */
const map<int,int>& getPayloadOrder() { return payload_order; }
/**
* File format lookup according to the
* format name and/or file extension.

@ -245,7 +245,8 @@ int AmSdp::genRequest(const string& localip,int localport, string& out_buf)
{
AmPlugIn* plugin = AmPlugIn::instance();
const map<int,amci_payload_t*>& payloads = plugin->getPayloads();
const map<int,int>& payload_order = plugin->getPayloadOrder();
if(payloads.empty()){
ERROR("no payload plugin loaded.\n");
return -1;
@ -266,22 +267,25 @@ int AmSdp::genRequest(const string& localip,int localport, string& out_buf)
"t=0 0\r\n"
"m=audio " + int2str(localport) + " RTP/AVP ";
map<int,amci_payload_t*>::const_iterator it = payloads.begin();
out_buf += int2str((it++)->first);
map<int,int>::const_iterator it = payload_order.begin();
out_buf += int2str((it++)->second);
for(;it != payloads.end();++it)
out_buf += string(" ") + int2str(it->first);
for(; it != payload_order.end(); ++it)
out_buf += string(" ") + int2str(it->second);
out_buf += "\r\n";
for(it = payloads.begin();it != payloads.end();++it) {
//if(it->first >= 96) {
out_buf += "a=rtpmap:" + int2str(it->first)
+ " " + string(it->second->name)
+ "/" + int2str(it->second->sample_rate)
+ "\r\n";
//}
for (it = payload_order.begin(); it != payload_order.end(); ++it) {
map<int,amci_payload_t*>::const_iterator it2 = payloads.find(it->second);
if (it2 != payloads.end()) {
out_buf += "a=rtpmap:" + int2str(it2->first)
+ " " + string(it2->second->name)
+ "/" + int2str(it2->second->sample_rate)
+ "\r\n";
} else {
ERROR("Payload %d was not found in payloads map!\n", it->second);
return -1;
}
}
return 0;

@ -841,6 +841,21 @@ unsigned int get_random()
return r;
}
// Explode string by a separator to a vector
vector <string> explode(string s, string e) {
vector <string> ret;
int iPos = s.find(e, 0);
int iLen = e.length();
while (iPos > -1) {
if (iPos != 0)
ret.push_back(s.substr(0, iPos));
s.erase(0, iPos+iLen);
iPos = s.find(e, 0);
}
if (s != "")
ret.push_back(s);
return ret;
}
// Warning: static var is not mutexed
@ -848,29 +863,29 @@ unsigned int get_random()
//
void add_env_path(const char* name, const string& path)
{
string var(path);
char* old_path=0;
string var(path);
char* old_path=0;
regex_t path_reg;
regex_t path_reg;
assert(name);
if((old_path = getenv(name)) != 0) {
if(strlen(old_path)){
assert(name);
if((old_path = getenv(name)) != 0) {
if(strlen(old_path)){
if(regcomp(&path_reg,("[:|^]" + path + "[:|$]").c_str(),REG_NOSUB)){
ERROR("could not compile regex\n");
return;
}
if(regcomp(&path_reg,("[:|^]" + path + "[:|$]").c_str(),REG_NOSUB)){
ERROR("could not compile regex\n");
return;
}
if(!regexec(&path_reg,old_path,0,0,0)) { // match
if(!regexec(&path_reg,old_path,0,0,0)) { // match
return; // do nothing
}
return; // do nothing
}
var += ":" + string(old_path);
}
var += ":" + string(old_path);
}
}
DBG("setting %s to: '%s'\n",name,var.c_str());
setenv("PYTHONPATH",var.c_str(),1);
DBG("setting %s to: '%s'\n",name,var.c_str());
setenv("PYTHONPATH",var.c_str(),1);
}

@ -35,6 +35,8 @@
#include <string>
using std::string;
#include <vector>
#define FIFO_PERM S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH
#define PARAM_HDR "P-App-Param"
@ -263,6 +265,9 @@ string get_session_param(const string& hdrs, const string& name);
void init_random();
unsigned int get_random();
// Explode string by a separator to a vector
std::vector <string> explode(string s, string e);
// add a directory to an environement variable
void add_env_path(const char* name, const string& path);

@ -165,3 +165,13 @@ media_processor_threads=1
# default=no
#
# single_codec_in_ok=no
# optional parameter: codec_order=codec_name_1,codec_name2,...
#
# - Codec order used when sending INVITE requests. Codecs in codec_order
# will be on the top of the list followed by other supported codecs
# (if any).
#
# default=empty
#
# codec_order=iLBC,GSM

Loading…
Cancel
Save