Browse code

sbc b/f: release references to media sessions

Václav Kubart authored on 28/05/2013 14:09:34
Showing 4 changed files
... ...
@@ -107,6 +107,15 @@ CallLeg::CallLeg(AmSipDialog* p_dlg):
107 107
   set_sip_relay_only(false);
108 108
 }
109 109
     
110
+CallLeg::~CallLeg()
111
+{
112
+  // do necessary cleanup (might be needed if the call leg is destroyed other
113
+  // way then expected)
114
+  for (vector<OtherLegInfo>::iterator i = other_legs.begin(); i != other_legs.end(); ++i) {
115
+    i->releaseMediaSession();
116
+  }
117
+}
118
+
110 119
 void CallLeg::terminateOtherLeg()
111 120
 {
112 121
   if (call_status != Connected) {
... ...
@@ -118,6 +127,15 @@ void CallLeg::terminateOtherLeg()
118 127
   
119 128
   AmB2BSession::terminateOtherLeg();
120 129
 
130
+  // remove this one from the list of other legs
131
+  for (vector<OtherLegInfo>::iterator i = other_legs.begin(); i != other_legs.end(); ++i) {
132
+    if (i->id == getOtherId()) {
133
+      i->releaseMediaSession();
134
+      other_legs.erase(i);
135
+      break;
136
+    }
137
+  }
138
+
121 139
   // FIXME: call disconnect if connected (to put remote on hold)?
122 140
   updateCallStatus(Disconnected); // no B legs should be remaining
123 141
 }
... ...
@@ -369,6 +369,8 @@ class CallLeg: public AmB2BSession
369 369
 
370 370
     /** creates B leg using given session as A leg */
371 371
     CallLeg(const CallLeg* caller, AmSipDialog* dlg=NULL);
372
+
373
+    virtual ~CallLeg();
372 374
 };
373 375
 
374 376
 
... ...
@@ -1580,7 +1580,10 @@ void SBCCallLeg::createHoldRequest(AmSdp &sdp)
1580 1580
 
1581 1581
 void SBCCallLeg::setMediaSession(AmB2BMedia *new_session)
1582 1582
 {
1583
-  if (new_session && call_profile.log_rtp) new_session->setRtpLogger(logger);
1583
+  if (new_session) {
1584
+    if (call_profile.log_rtp) new_session->setRtpLogger(logger);
1585
+    else new_session->setRtpLogger(NULL);
1586
+  }
1584 1587
   CallLeg::setMediaSession(new_session);
1585 1588
 }
1586 1589
 
... ...
@@ -1606,9 +1609,13 @@ void SBCCallLeg::setLogger(msg_logger *_logger)
1606 1609
   logger = _logger;
1607 1610
   if (logger) inc_ref(logger);
1608 1611
   if (call_profile.log_sip) dlg->setMsgLogger(logger);
1612
+  else dlg->setMsgLogger(NULL);
1609 1613
 
1610 1614
   AmB2BMedia *m = getMediaSession();
1611
-  if (m && call_profile.log_rtp) m->setRtpLogger(logger);
1615
+  if (m) {
1616
+    if (call_profile.log_rtp) m->setRtpLogger(logger);
1617
+    else m->setRtpLogger(NULL);
1618
+  }
1612 1619
 }
1613 1620
 
1614 1621
 void SBCCallLeg::logRequest(const AmSipRequest &req)
... ...
@@ -1139,6 +1139,7 @@ AmB2BCalleeSession* AmB2BCallerSession::newCalleeSession()
1139 1139
 void AmB2BSession::setMediaSession(AmB2BMedia *new_session) 
1140 1140
 { 
1141 1141
   // FIXME: ignore old media_session? can it be already set here?
1142
+  if (media_session) ERROR("BUG: non-empty media session overwritten\n");
1142 1143
   media_session = new_session; 
1143 1144
   if (media_session) media_session->addReference(); // new reference for me
1144 1145
 }