Browse code

SBC: B leg initialization moved from constructor into onStart method

... to be executed within the B leg's thread instead of the A leg's one

Václav Kubart authored on 02/08/2012 12:13:54
Showing 2 changed files
... ...
@@ -160,25 +160,71 @@ SBCCallLeg::SBCCallLeg(const SBCCallLeg* caller, const SBCCallProfile& _call_pro
160 160
     CallLeg(caller)
161 161
 {
162 162
   dlg.setRel100State(Am100rel::REL100_IGNORED);
163
+  dlg.setOAEnabled(false);
164
+}
165
+
166
+void SBCCallLeg::onStart()
167
+{
168
+  // this should be the first thing called in session's thread
169
+  CallLeg::onStart();
170
+  if (!a_leg) applyBProfile(); // A leg needs to evaluate profile first
171
+}
172
+
173
+void SBCCallLeg::applyAProfile()
174
+{
175
+  // apply A leg configuration (but most of the configuration is applied in
176
+  // SBCFactory::onInvite)
177
+
178
+  if (call_profile.rtprelay_enabled || call_profile.transcoder.isActive()) {
179
+    DBG("Enabling RTP relay mode for SBC call\n");
180
+
181
+    if (call_profile.force_symmetric_rtp_value) {
182
+      DBG("forcing symmetric RTP (passive mode)\n");
183
+      rtp_relay_force_symmetric_rtp = true;
184
+    }
185
+
186
+    if (call_profile.aleg_rtprelay_interface_value >= 0) {
187
+      setRtpRelayInterface(call_profile.aleg_rtprelay_interface_value);
188
+      DBG("using RTP interface %i for A leg\n", rtp_interface);
189
+    }
190
+
191
+    setRtpRelayTransparentSeqno(call_profile.rtprelay_transparent_seqno);
192
+    setRtpRelayTransparentSSRC(call_profile.rtprelay_transparent_ssrc);
193
+
194
+    setRtpRelayMode(RTP_Relay);
195
+
196
+    if(call_profile.transcoder.isActive()) {
197
+      switch(call_profile.transcoder.dtmf_mode) {
198
+      case SBCCallProfile::TranscoderSettings::DTMFAlways:
199
+        enable_dtmf_transcoding = true; break;
200
+      case SBCCallProfile::TranscoderSettings::DTMFNever:
201
+        enable_dtmf_transcoding = false; break;
202
+      case SBCCallProfile::TranscoderSettings::DTMFLowFiCodecs:
203
+        enable_dtmf_transcoding = false;
204
+        lowfi_payloads = call_profile.transcoder.lowfi_codecs;
205
+        break;
206
+      };
207
+    }
208
+  }
209
+}
210
+
211
+void SBCCallLeg::applyBProfile()
212
+{
163 213
 
164 214
   if (!call_profile.contact.empty()) {
165 215
     dlg.contact_uri = SIP_HDR_COLSP(SIP_HDR_CONTACT) + call_profile.contact + CRLF;
166 216
   }
167 217
 
168
-  // moved from createCalleeSession
169
-  // FIXME: Stefan wants to move to ConnectLegEvent handling to be done in
170
-  // callee's thread
171
-  
172 218
   if (call_profile.auth_enabled) {
173 219
     // adding auth handler
174
-    AmSessionEventHandlerFactory* uac_auth_f = 
220
+    AmSessionEventHandlerFactory* uac_auth_f =
175 221
       AmPlugIn::instance()->getFactory4Seh("uac_auth");
176 222
     if (NULL == uac_auth_f)  {
177 223
       INFO("uac_auth module not loaded. uac auth NOT enabled.\n");
178 224
     } else {
179 225
       AmSessionEventHandler* h = uac_auth_f->getHandler(this);
180
-      
181
-      // we cannot use the generic AmSessionEventHandler hooks, 
226
+
227
+      // we cannot use the generic AmSessionEventHandler hooks,
182 228
       // because the hooks don't work in AmB2BSession
183 229
       setAuthHandler(h);
184 230
       DBG("uac auth enabled for callee session.\n");
... ...
@@ -188,12 +234,14 @@ SBCCallLeg::SBCCallLeg(const SBCCallLeg* caller, const SBCCallProfile& _call_pro
188 234
   if (call_profile.sst_enabled_value) {
189 235
     if (NULL == SBCFactory::session_timer_fact) {
190 236
       ERROR("session_timer module not loaded - unable to create call with SST\n");
237
+      // FIXME: terminateOtherLeg?
191 238
       throw AmSession::Exception(500, SIP_REPLY_SERVER_INTERNAL_ERROR);
192 239
     }
193 240
 
194 241
     AmSessionEventHandler* h = SBCFactory::session_timer_fact->getHandler(this);
195 242
     if(!h) {
196 243
       ERROR("could not get a session timer event handler\n");
244
+      // FIXME: terminateOtherLeg?
197 245
       throw AmSession::Exception(500, SIP_REPLY_SERVER_INTERNAL_ERROR);
198 246
     }
199 247
 
... ...
@@ -209,7 +257,7 @@ SBCCallLeg::SBCCallLeg(const SBCCallLeg* caller, const SBCCallProfile& _call_pro
209 257
     dlg.outbound_proxy = call_profile.outbound_proxy;
210 258
     dlg.force_outbound_proxy = call_profile.force_outbound_proxy;
211 259
   }
212
-  
260
+
213 261
   if (!call_profile.next_hop.empty()) {
214 262
     dlg.next_hop = call_profile.next_hop;
215 263
   }
... ...
@@ -217,8 +265,6 @@ SBCCallLeg::SBCCallLeg(const SBCCallLeg* caller, const SBCCallProfile& _call_pro
217 265
   // was read from caller but reading directly from profile now
218 266
   if (call_profile.outbound_interface_value >= 0)
219 267
     dlg.outbound_interface = call_profile.outbound_interface_value;
220
-  
221
-  dlg.setOAEnabled(false); // ???
222 268
 
223 269
   // was read from caller but reading directly from profile now
224 270
   if (call_profile.rtprelay_enabled || call_profile.transcoder.isActive()) {
... ...
@@ -231,7 +277,6 @@ SBCCallLeg::SBCCallLeg(const SBCCallLeg* caller, const SBCCallProfile& _call_pro
231 277
 
232 278
   // was read from caller but reading directly from profile now
233 279
   if (!call_profile.callid.empty()) dlg.callid = call_profile.callid;
234
-  
235 280
 }
236 281
 
237 282
 int SBCCallLeg::relayEvent(AmEvent* ev)
... ...
@@ -644,6 +689,7 @@ void SBCCallLeg::onInvite(const AmSipRequest& req)
644 689
     throw AmSession::Exception(500, SIP_REPLY_SERVER_INTERNAL_ERROR);
645 690
   }
646 691
 
692
+  string ruri, to, from;
647 693
   ruri = call_profile.ruri.empty() ? req.r_uri : call_profile.ruri;
648 694
   if(!call_profile.ruri_host.empty()){
649 695
     ruri_parser.uri = ruri;
... ...
@@ -658,39 +704,8 @@ void SBCCallLeg::onInvite(const AmSipRequest& req)
658 704
   }
659 705
   from = call_profile.from.empty() ? req.from : call_profile.from;
660 706
   to = call_profile.to.empty() ? req.to : call_profile.to;
661
-  callid = call_profile.callid;
662 707
 
663
-  if (call_profile.rtprelay_enabled || call_profile.transcoder.isActive()) {
664
-    DBG("Enabling RTP relay mode for SBC call\n");
665
-
666
-    if (call_profile.force_symmetric_rtp_value) {
667
-      DBG("forcing symmetric RTP (passive mode)\n");
668
-      rtp_relay_force_symmetric_rtp = true;
669
-    }
670
-
671
-    if (call_profile.aleg_rtprelay_interface_value >= 0) {
672
-      setRtpRelayInterface(call_profile.aleg_rtprelay_interface_value);
673
-      DBG("using RTP interface %i for A leg\n", rtp_interface);
674
-    }
675
-
676
-    setRtpRelayTransparentSeqno(call_profile.rtprelay_transparent_seqno);
677
-    setRtpRelayTransparentSSRC(call_profile.rtprelay_transparent_ssrc);
678
-
679
-    setRtpRelayMode(RTP_Relay);
680
-
681
-    if(call_profile.transcoder.isActive()) {
682
-      switch(call_profile.transcoder.dtmf_mode) {
683
-      case SBCCallProfile::TranscoderSettings::DTMFAlways:
684
-	enable_dtmf_transcoding = true; break;
685
-      case SBCCallProfile::TranscoderSettings::DTMFNever:
686
-	enable_dtmf_transcoding = false; break;
687
-      case SBCCallProfile::TranscoderSettings::DTMFLowFiCodecs:
688
-	enable_dtmf_transcoding = false;
689
-	lowfi_payloads = call_profile.transcoder.lowfi_codecs;
690
-	break;
691
-      };
692
-    }
693
-  }
708
+  applyAProfile();
694 709
 
695 710
   m_state = BB_Dialing;
696 711
 
... ...
@@ -25,11 +25,6 @@ class SBCCallLeg : public CallLeg, public CredentialHolder
25 25
 
26 26
   int m_state;
27 27
 
28
-  string ruri;
29
-  string from;
30
-  string to;
31
-  string callid;
32
-
33 28
   map<int, double> call_timers;
34 29
 
35 30
   // call control
... ...
@@ -92,6 +87,12 @@ class SBCCallLeg : public CallLeg, public CredentialHolder
92 87
   void appendTranscoderCodecs(AmSdp &sdp);
93 88
   void savePayloadIDs(AmSdp &sdp);
94 89
 
90
+  /** apply A leg configuration from call profile */
91
+  void applyAProfile();
92
+
93
+  /** apply B leg configuration from call profile */
94
+  void applyBProfile();
95
+
95 96
  public:
96 97
 
97 98
   SBCCallLeg(const SBCCallProfile& call_profile);
... ...
@@ -107,6 +108,8 @@ class SBCCallLeg : public CallLeg, public CredentialHolder
107 108
 
108 109
   void onSystemEvent(AmSystemEvent* ev);
109 110
 
111
+  virtual void onStart();
112
+
110 113
   UACAuthCred* getCredentials();
111 114
 
112 115
   void setAuthHandler(AmSessionEventHandler* h) { auth = h; }