Exemplo n.º 1
0
int AmSdp::getDynPayload(const string& name, int rate)
{
  AmPlugIn* pi = AmPlugIn::instance();
  const map<int, amci_payload_t*>& ref_payloads = pi->getPayloads();

  for(map<int, amci_payload_t*>::const_iterator pl_it = ref_payloads.begin();
      pl_it != ref_payloads.end(); ++pl_it)
    if( (name == pl_it->second->name) 
	&&  (rate == pl_it->second->sample_rate) )
      return pl_it->first;
    
  return -1;
}
Exemplo n.º 2
0
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;
  }

  string l_ip = "IP4 " + localip;

#ifdef SUPPORT_IPV6
  if(localip.find('.') == string::npos)
    l_ip = "IP6 " + localip;
#endif

  out_buf = 
    "v=0\r\n"
    "o=username 0 0 IN " + l_ip + "\r\n"
    "s=session\r\n"
    "c=IN " + l_ip + "\r\n"
    "t=0 0\r\n"
    "m=audio " + int2str(localport) + " RTP/AVP ";
    
  map<int,int>::const_iterator it = payload_order.begin();
  out_buf += int2str((it++)->second);

  for(; it != payload_order.end(); ++it)
      out_buf += string(" ") + int2str(it->second);

  out_buf += "\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;
}
Exemplo n.º 3
0
const vector<SdpPayload *>& AmSdp::getCompatiblePayloads(int media_type, string& addr, int& port)
{
  vector<SdpMedia>::iterator   m_it;
  SdpPayload *payload;
  sup_pl.clear();

  AmPlugIn* pi = AmPlugIn::instance();

  for( m_it = media.begin(); m_it != media.end(); ++m_it ){

    if( (media_type != m_it->type) )
      continue;

    vector<SdpPayload>::iterator it = m_it->payloads.begin();
    for(; it != m_it->payloads.end(); ++it ) {

      amci_payload_t* a_pl = NULL;
      if(it->payload_type < DYNAMIC_PAYLOAD_TYPE_START){
	// try static payloads
	a_pl = pi->payload(it->payload_type);
      }

      if( a_pl ) {
		    
	payload = &(*it);
	payload->int_pt = a_pl->payload_id;
	payload->encoding_name = a_pl->name;
	payload->clock_rate = a_pl->sample_rate;
	sup_pl.push_back(payload);
      }
      else { 
	// Try dynamic payloads
	// and give a chance to broken 
	// implementation using a static payload number
	// for dynamic ones.
		
	if(it->encoding_name == "telephone-event")
	  continue;

	int int_pt = getDynPayload(it->encoding_name,
				   it->clock_rate);
		
	if(int_pt != -1){
		    
	  payload = &(*it);
	  payload->int_pt = int_pt;
	  sup_pl.push_back(payload);
	}
      }
    }
    if (sup_pl.size() > 0)
    {
      if (m_it->conn.address.empty())
      {
	DBG("using global address: %s\n",conn.address.c_str());
	addr = conn.address;
      }
      else {
	DBG("using media specific address: %s\n",m_it->conn.address.c_str());
	addr = m_it->conn.address;
      }
      
      if(m_it->dir == SdpMedia::DirActive)
	remote_active = true;
      
      port = (int)m_it->port;
    }
    break;
  }
  return sup_pl;
}
Exemplo n.º 4
0
/**
 * Loads python script path and default script file from configuration file
 */
int IvrFactory::onLoad()
{
  if(cfg.loadFile(add2path(AmConfig::ModConfigPath,1,MOD_NAME ".conf")))
    return -1;

  // get application specific global parameters
  configureModule(cfg);

  //setScriptPath(cfg.getParameter("script_path"));
  string script_path = cfg.getParameter("script_path");
  init_python_interpreter(script_path);

  DBG("** IVR compile time configuration:\n");
  DBG("**     built with PYTHON support.\n");

#ifdef IVR_WITH_TTS
  DBG("**     Text-To-Speech enabled\n");
#else
  DBG("**     Text-To-Speech disabled\n");
#endif

  DBG("** IVR run time configuration:\n");
  DBG("**     script path:         \'%s\'\n", script_path.c_str());

  regex_t reg;
  if(regcomp(&reg,PYFILE_REGEX,REG_EXTENDED)){
    ERROR("while compiling regular expression\n");
    return -1;
  }

  DIR* dir = opendir(script_path.c_str());
  if(!dir){
    regfree(&reg);
    ERROR("Ivr: script pre-loader (%s): %s\n",
	  script_path.c_str(),strerror(errno));
    return -1;
  }

  DBG("directory '%s' opened\n",script_path.c_str());

  std::set<string> unique_entries;
  regmatch_t  pmatch[2];

  struct dirent* entry=0;
  while((entry = readdir(dir)) != NULL){

    if(!regexec(&reg,entry->d_name,2,pmatch,0)){

      string name(entry->d_name + pmatch[1].rm_so,
		  pmatch[1].rm_eo - pmatch[1].rm_so);

      unique_entries.insert(name);
    }
  }
  closedir(dir);
  regfree(&reg);

  AmPlugIn* plugin = AmPlugIn::instance();
  for(std::set<string>::iterator it = unique_entries.begin();
      it != unique_entries.end(); it++) {

    if(loadScript(*it)){
      bool res = plugin->registerFactory4App(*it,this);
      if(res)
	INFO("Application script registered: %s.\n",
	     it->c_str());
    }
  }

  if(cfg.hasParameter("enable_session_timer") &&
     (cfg.getParameter("enable_session_timer") == string("yes")) ){
    DBG("enabling session timers\n");
    session_timer_f = AmPlugIn::instance()->getFactory4Seh("session_timer");
    if(session_timer_f == NULL){
      ERROR("Could not load the session_timer module: disabling session timers.\n");
    }
  }

  start_deferred_threads();

  return 0; // don't stop sems from starting up
}
Exemplo n.º 5
0
/**
 * Loads python script path and default script file from configuration file
 */
int PySemsFactory::onLoad()
{
  user_timer_fact = AmPlugIn::instance()->getFactory4Di("user_timer");
  if(!user_timer_fact){
	
    ERROR("could not load user_timer from session_timer plug-in\n");
    return -1;
  }

  AmConfigReader cfg;

  if(cfg.loadFile(add2path(AmConfig::ModConfigPath,1,MOD_NAME ".conf")))
    return -1;

  // get application specific global parameters
  configureModule(cfg);

  string script_path = cfg.getParameter("script_path");
  init_python_interpreter(script_path);

#ifdef PY_SEMS_WITH_TTS
  DBG("** PY_SEMS Text-To-Speech enabled\n");
#else
  DBG("** PY_SEMS Text-To-Speech disabled\n");
#endif

  DBG("** PY_SEMS script path: \'%s\'\n", script_path.c_str());

  regex_t reg;
  if(regcomp(&reg,PYFILE_REGEX,REG_EXTENDED)){
    ERROR("while compiling regular expression\n");
    return -1;
  }

  DIR* dir = opendir(script_path.c_str());
  if(!dir){
    regfree(&reg);
    ERROR("PySems: script pre-loader (%s): %s\n",
	  script_path.c_str(),strerror(errno));
    return -1;
  }

  DBG("directory '%s' opened\n",script_path.c_str());

  set<string> unique_entries;
  regmatch_t  pmatch[2];

  struct dirent* entry=0;
  while((entry = readdir(dir)) != NULL){

    if(!regexec(&reg,entry->d_name,2,pmatch,0)){

      string name(entry->d_name + pmatch[1].rm_so,
		  pmatch[1].rm_eo - pmatch[1].rm_so);

      unique_entries.insert(name);
    }
  }
  closedir(dir);
  regfree(&reg);

  AmPlugIn* plugin = AmPlugIn::instance();
  for(set<string>::iterator it = unique_entries.begin();
      it != unique_entries.end(); it++) {

    if(loadScript(*it)){
      bool res = plugin->registerFactory4App(*it,this);
      if(res)
	INFO("Application script registered: %s.\n",
	     it->c_str());
    }
  }

  return 0; // don't stop sems from starting up
}