Module: sems
Branch: master
Commit: 3b10b09c177e9567aecdbad7edb53c3389b5f6c7
URL:    
http://git.sip-router.org/cgi-bin/gitweb.cgi/sems/?a=commit;h=3b10b09c177e9567aecdbad7edb53c3389b5f6c7

Author: Raphael Coeffic <[email protected]>
Committer: Raphael Coeffic <[email protected]>
Date:   Fri Mar  2 19:41:33 2012 +0100

b/f: default codec selection fixed.

---

 core/AmRtpAudio.cpp  |    8 +++++++-
 core/AmRtpStream.cpp |   37 ++++++++++++++++++++++++++++++++++---
 core/AmRtpStream.h   |    6 ++++++
 3 files changed, 47 insertions(+), 4 deletions(-)

diff --git a/core/AmRtpAudio.cpp b/core/AmRtpAudio.cpp
index 77d5732..ee39aa9 100644
--- a/core/AmRtpAudio.cpp
+++ b/core/AmRtpAudio.cpp
@@ -167,7 +167,13 @@ int AmRtpAudio::init(const AmSdp& local,
   }
 
   AmAudioRtpFormat* fmt_p = new AmAudioRtpFormat();
-  fmt_p->setCurrentPayload(payloads[0]);
+
+  PayloadMappingTable::iterator pl_it = pl_map.find(payload);
+  if ((pl_it == pl_map.end()) || (pl_it->second.remote_pt < 0)) {
+    ERROR("no default payload has been set\n");
+    return -1;
+  }
+  fmt_p->setCurrentPayload(payloads[pl_it->second.index]);
   fmt.reset(fmt_p);
 
   fec.reset(new LowcFE(fmt->rate));
diff --git a/core/AmRtpStream.cpp b/core/AmRtpStream.cpp
index cb49e5a..21c7390 100644
--- a/core/AmRtpStream.cpp
+++ b/core/AmRtpStream.cpp
@@ -36,6 +36,7 @@
 
 #include "AmDtmfDetector.h"
 #include "rtp/telephone_event.h"
+#include "amci/codecs.h"
 #include "AmJitterBuffer.h"
 
 #include "sip/resolver.h"
@@ -557,6 +558,10 @@ int AmRtpStream::init(const AmSdp& local,
   sdp_it = remote_media.payloads.begin();
   while(sdp_it != remote_media.payloads.end()) {
 
+    // TODO: match not only on encoding name
+    //       but also on parameters, if necessary
+    //       Some codecs define multiple payloads
+    //       with different encoding parameters
     PayloadMappingTable::iterator pmt_it = pl_map.end();
     if(sdp_it->encoding_name.empty()){ // must be a static payload
 
@@ -573,6 +578,9 @@ int AmRtpStream::init(const AmSdp& local,
       }
     }
 
+    // TODO: remove following code once proper 
+    //       payload matching is implemented
+    //
     // initialize remote_pt if not already there
     if(pmt_it != pl_map.end() && (pmt_it->second.remote_pt < 0)){
       pmt_it->second.remote_pt = sdp_it->payload_type;
@@ -584,15 +592,18 @@ int AmRtpStream::init(const AmSdp& local,
   setPassiveMode(remote_media.dir == SdpMedia::DirActive);
   setRAddr(remote.conn.address, remote_media.port);
 
-  // TODO: take the first *supported* payload
-  //       (align with the SDP answer algo)
   if(local_media.payloads.empty()) {
 
     ERROR("local_media.payloads.empty()\n");
     return -1;
   }
 
-  payload = local_media.payloads[0].payload_type;
+  payload = getDefaultPT();
+  if(payload < 0) {
+    ERROR("could not set a default payload\n");
+    return -1;
+  }
+  DBG("default payload selected = %i\n",payload);
   last_payload = payload;
 
   remote_telephone_event_pt.reset(remote.telephoneEventPayload());
@@ -758,6 +769,26 @@ void AmRtpStream::clearRTPTimeout() {
   gettimeofday(&last_recv_time,NULL);
 }
 
+int AmRtpStream::getDefaultPT()
+{
+  for(PayloadCollection::iterator it = payloads.begin();
+      it != payloads.end(); ++it){
+
+    // skip telephone-events payload
+    if(it->codec_id == CODEC_TELEPHONE_EVENT)
+      continue;
+
+    // skip incompatible payloads
+    PayloadMappingTable::iterator pl_it = pl_map.find(it->pt);
+    if ((pl_it == pl_map.end()) || (pl_it->second.remote_pt < 0))
+      continue;
+
+    return it->pt;
+  }
+
+  return -1;
+}
+
 int AmRtpStream::nextPacket(AmRtpPacket*& p)
 {
   if (!receiving && !passive)
diff --git a/core/AmRtpStream.h b/core/AmRtpStream.h
index f4d7513..6aeebe2 100644
--- a/core/AmRtpStream.h
+++ b/core/AmRtpStream.h
@@ -249,6 +249,12 @@ protected:
   /** Clear RTP timeout at time recv_time */
   void clearRTPTimeout(struct timeval* recv_time);
 
+  /** 
+   * Select a compatible default payload 
+   * @return -1 if none available.
+   */
+  int getDefaultPT();
+
 public:
 
   /** Mute */

_______________________________________________
Semsdev mailing list
[email protected]
http://lists.iptel.org/mailman/listinfo/semsdev

Reply via email to