From bec1a6cee81aa3cc92b9af483904a2e0b4afe6af Mon Sep 17 00:00:00 2001
From: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
Date: Thu, 7 Feb 2008 13:51:50 -0500
Subject: [PATCH] SIP codecs negociation with user choices

---
 src/audio/codecDescriptor.cpp | 18 ++++++--------
 src/audio/codecDescriptor.h   |  2 +-
 src/sipcall.cpp               | 11 +++++----
 src/sipvoiplink.cpp           | 44 +++++++++++++++++------------------
 4 files changed, 36 insertions(+), 39 deletions(-)

diff --git a/src/audio/codecDescriptor.cpp b/src/audio/codecDescriptor.cpp
index a00720cda8..b1d5ef70b2 100644
--- a/src/audio/codecDescriptor.cpp
+++ b/src/audio/codecDescriptor.cpp
@@ -68,19 +68,15 @@ CodecDescriptor::getCodecName(CodecType payload)
 }
 
 bool 
-CodecDescriptor::isSupported(CodecType payload) 
+CodecDescriptor::isActive(CodecType payload) 
 {
-  CodecMap::iterator iter = _codecMap.begin();
-  while(iter!=_codecMap.end()) {
-      if (iter->first == payload) {
-	// codec is already in the map --> nothing to do
-	_debug("Codec with payload %i already in the map\n", payload);
-        //break;
-        return true;
-      }
-    iter++;
+  int i;
+  for(i=0 ; i < _codecOrder.size() ; i++)
+  {
+    if(_codecOrder[i] == payload)
+      return true;
   }
-   return false;
+  return false;
 }
 
 void 
diff --git a/src/audio/codecDescriptor.h b/src/audio/codecDescriptor.h
index 77da6e81dc..3fddfa191d 100644
--- a/src/audio/codecDescriptor.h
+++ b/src/audio/codecDescriptor.h
@@ -91,7 +91,7 @@ public:
    * @return true if the codec specified is supported
    * 	     false otherwise
    */
-  bool isSupported(CodecType payload);
+  bool isActive(CodecType payload);
 
  /**
   * Remove the codec with payload payload from the list
diff --git a/src/sipcall.cpp b/src/sipcall.cpp
index b81b0773b9..b839ca9f49 100644
--- a/src/sipcall.cpp
+++ b/src/sipcall.cpp
@@ -353,17 +353,18 @@ SIPCall::sdp_complete_message(sdp_message_t * remote_sdp, osip_message_t * msg)
       remote_med_m_payloads = &(remote_med->m_payloads);
       #endif
 
-      while (!osip_list_eol(remote_med_m_payloads, iPayload) && iPayload < 2) {
+      //while (!osip_list_eol(remote_med_m_payloads, iPayload) && iPayload < 2) {
+      while (!osip_list_eol(remote_med_m_payloads, iPayload)) {
         tmp = (char *)osip_list_get(remote_med_m_payloads, iPayload);
         if (tmp!=NULL) {
           int payload = atoi(tmp);
 	  _debug("remote payload = %s\n", tmp);
           CodecType audiocodec = (CodecType)payload;
-          //if (audiocodec != NULL && audiocodec->isActive()) {
-          if (audiocodec != (CodecType)-1 && _codecMap.isSupported(audiocodec))  { 
+          if (audiocodec != (CodecType)-1 && _codecMap.isActive(audiocodec))  { 
+	    _debug("PAYLOAD = %i", payload);
             listCodec << payload << " ";
             //listRtpMap << "a=rtpmap:" << payload << " " << audiocodec->getCodecName() << "/" << audiocodec->getClockRate();
-            listRtpMap << "a=rtpmap:" << payload << " " << _codecMap.getCodecName(audiocodec) << "/" << 8000;
+            listRtpMap << "a=rtpmap:" << payload << " " << _codecMap.getCodecName(audiocodec) << "/" << _codecMap.getSampleRate(audiocodec);
         // TODO: manage a way to get the channel infos    
 	/*if ( audiocodec->getChannel() != 1) {
               listRtpMap << "/" << audiocodec->getChannel();
@@ -586,7 +587,7 @@ SIPCall::setAudioCodecFromSDP(sdp_media_t* remote_med, int tid)
     if (tmp != NULL ) {
       int payload = atoi(tmp);
       // stop if we find a correct codec
-      if (_codecMap.isSupported((CodecType)payload)){
+      if (_codecMap.isActive((CodecType)payload)){
           break;
       }
     }
diff --git a/src/sipvoiplink.cpp b/src/sipvoiplink.cpp
index 45c00017be..4ee45841bd 100644
--- a/src/sipvoiplink.cpp
+++ b/src/sipvoiplink.cpp
@@ -943,32 +943,32 @@ SIPVoIPLink::SIPStartCall(SIPCall* call, const std::string& subject)
 
   std::ostringstream media_audio;
   std::ostringstream rtpmap_attr;
-  int payload;
+  CodecType payload;
   int nbChannel;
+  int iter;
 
   // Set rtpmap according to the supported codec order
-  CodecMap map = call->getCodecMap().getCodecMap();
-  //CodecMap map = Manager::instance().getCodecDescriptorMap();	
-  CodecMap::iterator iter = map.begin();
-
-  while(iter != map.end()) {
-    //if (iter->second!=0 && iter->second->isActive()) {
-      if(iter->first != -1){
-	payload = iter->first;
-      // add each payload in the list of payload
-      media_audio << payload << " ";
-
-      rtpmap_attr << "a=rtpmap:" << payload << " " << 
-      iter->second.data() << "/" << call->getCodecMap().getSampleRate(iter->first);
-
-      /*nbChannel = iter->second->getChannel();
-      if (nbChannel!=1) {
-        rtpmap_attr << "/" << nbChannel;
-      }*/
-      rtpmap_attr << "\r\n";
-    }
+  //CodecMap map = call->getCodecMap().getCodecMap();
+  CodecOrder map = call->getCodecMap().getActiveCodecs();
+ 
+  for(iter=0 ; iter < map.size() ; iter++){
+      if(map[iter] != -1){
+	payload = map[iter];
+        // add each payload in the list of payload
+        media_audio << payload << " ";
+
+        rtpmap_attr << "a=rtpmap:" << payload << " " << 
+        call->getCodecMap().getCodecName(payload) << "/" << call->getCodecMap().getSampleRate(payload);
+
+    	//TODO add channel infos
+        /*nbChannel = iter->second->getChannel();
+        if (nbChannel!=1) {
+          rtpmap_attr << "/" << nbChannel;
+        }*/
+        rtpmap_attr << "\r\n";
+      }
     // go to next codec
-    iter++;
+    //*iter++;
   }
 
   // http://www.antisip.com/documentation/eXosip2/group__howto1__initialize.html
-- 
GitLab