示例#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;
}
示例#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;
}