From aae10542e03a8af3c96309dbd8a35f14eb50b3fb Mon Sep 17 00:00:00 2001
From: Emmanuel Milou <emmanuel.milou@savoirfairelinux.com>
Date: Wed, 4 Mar 2009 15:19:26 -0500
Subject: [PATCH] Implement SIP Re-Invite

---
 src/audio/audiortp.cpp |  2 +-
 src/call.cpp           | 14 --------------
 src/call.h             | 34 +---------------------------------
 src/iaxcall.cpp        | 13 +++++++++++++
 src/iaxcall.h          | 32 ++++++++++++++++++++++++++++++++
 src/sdp.cpp            |  1 +
 src/sdp.h              |  4 +++-
 src/sipvoiplink.cpp    |  5 ++---
 8 files changed, 53 insertions(+), 52 deletions(-)

diff --git a/src/audio/audiortp.cpp b/src/audio/audiortp.cpp
index 24042f7d2f..d60367ad91 100644
--- a/src/audio/audiortp.cpp
+++ b/src/audio/audiortp.cpp
@@ -187,7 +187,7 @@ AudioRtpRTX::initAudioRtpSession (void)
 {
     try {
         if (_ca == 0) { return; }
-        _audiocodec = Manager::instance().getCodecDescriptorMap().getCodec( _ca->getAudioCodec() );
+        _audiocodec = Manager::instance().getCodecDescriptorMap().getCodec( _ca->getLocalSDP()->getAudioCodec() );
         _codecSampleRate = _audiocodec->getClockRate();	
 
         _debug("Init audio RTP session\n");
diff --git a/src/call.cpp b/src/call.cpp
index 32cc4d7bcd..36496be7da 100644
--- a/src/call.cpp
+++ b/src/call.cpp
@@ -22,8 +22,6 @@
 
 Call::Call(const CallID& id, Call::CallType type)
            : _callMutex()
-           , _codecMap()
-           , _audioCodec()
            , _audioStarted(false)    
            , _localIPAddress("") 
            , _localAudioPort(0)
@@ -85,12 +83,6 @@ Call::getState()
   return _callState;
 }
 
-CodecDescriptor& 
-Call::getCodecMap()
-{
-  return _codecMap;
-}
-
 const std::string& 
 Call::getLocalIp()
 {
@@ -119,12 +111,6 @@ Call::getRemoteIp()
   return _remoteIPAddress;
 }
 
-AudioCodecType 
-Call::getAudioCodec()
-{
-  return _audioCodec;  
-}
-
 void 
 Call::setAudioStart(bool start)
 {
diff --git a/src/call.h b/src/call.h
index 6b247e0360..5fac0b23a7 100644
--- a/src/call.h
+++ b/src/call.h
@@ -23,7 +23,6 @@
 #include <cc++/thread.h> // for mutex
 #include <sstream>
 
-#include "audio/codecDescriptor.h"
 #include "plug-in/audiorecorder/audiorecord.h"
 
 /* 
@@ -145,20 +144,7 @@ class Call{
      */
     bool isAudioStarted();
 
-    // AUDIO
-    /** 
-     * Set internal codec Map: initialization only, not protected 
-     * @param map The codec map
-     */
-    void setCodecMap(const CodecDescriptor& map) { _codecMap = map; } 
-
-    /** 
-     * Get internal codec Map: initialization only, not protected 
-     * @return CodecDescriptor	The codec map
-     */
-    CodecDescriptor& getCodecMap();
-
-    /** 
+        /** 
      * Set my IP [not protected] 
      * @param ip  The local IP address
      */
@@ -206,12 +192,6 @@ class Call{
      */
     const std::string& getRemoteIp();
 
-    /** 
-     * Return audio codec [mutex protected]
-     * @return AudioCodecType The payload of the codec
-     */
-    AudioCodecType getAudioCodec();
-
     /**
      * @return Return the file name for this call
      */
@@ -258,18 +238,6 @@ class Call{
      */
     void setRemoteAudioPort(unsigned int port) { _remoteAudioPort = port; }
 
-    /** 
-     * Set the audio codec used.  [not protected] 
-     * @param audioCodec  The payload of the codec
-     */
-    void setAudioCodec(AudioCodecType audioCodec) { _audioCodec = audioCodec; }
-
-    /** Codec Map */
-    CodecDescriptor _codecMap;
-
-    /** Codec pointer */
-    AudioCodecType _audioCodec;
-
     bool _audioStarted;
 
     // Informations about call socket / audio
diff --git a/src/iaxcall.cpp b/src/iaxcall.cpp
index 05327d77d6..c2fc71c6ba 100644
--- a/src/iaxcall.cpp
+++ b/src/iaxcall.cpp
@@ -112,3 +112,16 @@ IAXCall::getFirstMatchingFormat(int needles)
   }
   return 0;
 }
+
+CodecDescriptor& IAXCall::getCodecMap()
+{
+  return _codecMap;
+}
+
+AudioCodecType IAXCall::getAudioCodec()
+{
+  return _audioCodec;  
+}
+
+
+
diff --git a/src/iaxcall.h b/src/iaxcall.h
index b572a7418b..0a728248c9 100644
--- a/src/iaxcall.h
+++ b/src/iaxcall.h
@@ -21,6 +21,8 @@
 #define IAXCALL_H
 
 #include "call.h"
+#include "audio/codecDescriptor.h"
+
 #include <iax2/iax-client.h>
 #include <iax2/frame.h>
 
@@ -90,11 +92,41 @@ public:
      */
     int getFirstMatchingFormat(int needles);
 
+    // AUDIO
+    /** 
+     * Set internal codec Map: initialization only, not protected 
+     * @param map The codec map
+     */
+    void setCodecMap(const CodecDescriptor& map) { _codecMap = map; } 
+
+    /** 
+     * Get internal codec Map: initialization only, not protected 
+     * @return CodecDescriptor	The codec map
+     */
+    CodecDescriptor& getCodecMap();
+
+    /** 
+     * Return audio codec [mutex protected]
+     * @return AudioCodecType The payload of the codec
+     */
+    AudioCodecType getAudioCodec();
 
 private:
     /** Each call is associated with an iax_session */
     struct iax_session* _session;
 
+    /** 
+     * Set the audio codec used.  [not protected] 
+     * @param audioCodec  The payload of the codec
+     */
+    void setAudioCodec(AudioCodecType audioCodec) { _audioCodec = audioCodec; }
+
+    /** Codec Map */
+    CodecDescriptor _codecMap;
+
+    /** Codec pointer */
+    AudioCodecType _audioCodec;
+
     /**
      * Format currently in use in the conversation,
      * sent in each outgoing voice packet.
diff --git a/src/sdp.cpp b/src/sdp.cpp
index c9bdc1468c..b7dc1d1f6d 100644
--- a/src/sdp.cpp
+++ b/src/sdp.cpp
@@ -28,6 +28,7 @@
     Sdp::Sdp( pj_pool_t *pool ) :  _localSDP(NULL)
     , _negociator(NULL)
     , _codecMap()
+    , _audioCodec()
     , _ipAddr("")
 {
     _pool = pool;
diff --git a/src/sdp.h b/src/sdp.h
index 33ab231aca..9ddc0ebcc5 100644
--- a/src/sdp.h
+++ b/src/sdp.h
@@ -89,7 +89,7 @@ class Sdp {
          * Get internal codec Map: initialization only, not protected 
          * @return CodecDescriptor	The codec map
          */
-        CodecDescriptor& getCodecMap();
+        CodecDescriptor& getCodecMap(){ return _codecMap; }
         
         void  setLocalExternAudioPort(int port){ _localPort = port; }
         
@@ -99,6 +99,8 @@ class Sdp {
 
         void toString (void);
 
+        AudioCodecType getAudioCodec (void) { return _audioCodec; }
+         
     private:
         /** 
          * Set the audio codec used.  [not protected] 
diff --git a/src/sipvoiplink.cpp b/src/sipvoiplink.cpp
index e44bae1337..33e738f345 100644
--- a/src/sipvoiplink.cpp
+++ b/src/sipvoiplink.cpp
@@ -431,7 +431,6 @@ SIPVoIPLink::newOutgoingCall(const CallID& id, const std::string& toUrl)
 
         _debug("Try to make a call to: %s with call ID: %s\n", toUrl.data(), id.data());
         // we have to add the codec before using it in SIPOutgoingInvite...
-        call->setCodecMap(Manager::instance().getCodecDescriptorMap());
         call->getLocalSDP()->setCodecMap(Manager::instance().getCodecDescriptorMap());
         if ( SIPOutgoingInvite(call) ) {
             call->setConnectionState(Call::Progressing);
@@ -814,7 +813,7 @@ SIPVoIPLink::getCurrentCodecName()
 
   SIPCall *call = getSIPCall(Manager::instance().getCurrentCallId());  
 
-  AudioCodec *ac = call->getCodecMap().getCodec(call->getAudioCodec());
+  AudioCodec *ac = call->getLocalSDP()->getCodecMap().getCodec(call->getLocalSDP()->getAudioCodec());
 
   return ac->getCodecName();
 }
@@ -2324,7 +2323,6 @@ void SIPVoIPLink::setStunServer( const std::string &server )
     }
 
     void on_rx_offer( pjsip_inv_session *inv, const pjmedia_sdp_session *offer ){
-            PJ_UNUSED_ARG( inv );
 
 #ifdef CAN_REINVITE
             
@@ -2338,6 +2336,7 @@ void SIPVoIPLink::setStunServer( const std::string &server )
                 return;
 
             call->getLocalSDP()->receiving_initial_offer( (pjmedia_sdp_session*)offer);
+            _debug("audio codec stté dans l'objet call: %i\n", call->getLocalSDP()->getAudioCodec());
             status=pjsip_inv_set_sdp_answer( call->getInvSession(), call->getLocalSDP()->getLocalSDPSession() );
 #endif
 
-- 
GitLab