Browse code

AmB2BSession: avoid direct manipulation with media instance

Václav Kubart authored on 22/04/2013 05:32:04 • Raphael Coeffic committed on 22/05/2013 19:50:17
Showing 5 changed files
... ...
@@ -242,10 +242,10 @@ bool CallLeg::setOther(const string &id, bool use_initial_sdp)
242 242
       setOtherId(id);
243 243
       clearRtpReceiverRelay(); // release old media session if set
244 244
       setMediaSession(i->media_session);
245
-      if (media_session) {
245
+      if (i->media_session) {
246 246
         TRACE("connecting media session: %s to %s\n", 
247 247
             dlg->getLocalTag().c_str(), getOtherId().c_str());
248
-        media_session->changeSession(a_leg, this);
248
+        i->media_session->changeSession(a_leg, this);
249 249
         if (use_initial_sdp) updateRemoteSdp(initial_sdp);
250 250
       }
251 251
       else {
... ...
@@ -504,7 +504,7 @@ void CallLeg::onB2BReconnect(ReconnectLegEvent* ev)
504 504
   setRtpRelayMode(ev->rtp_mode);
505 505
   if (ev->media) {
506 506
     setMediaSession(ev->media);
507
-    media_session->changeSession(a_leg, this);
507
+    getMediaSession()->changeSession(a_leg, this);
508 508
   }
509 509
 
510 510
   MONITORING_LOG3(getLocalTag().c_str(),
... ...
@@ -639,9 +639,10 @@ void CallLeg::disconnect(bool hold_remote)
639 639
 
640 640
 void CallLeg::createHoldRequest(AmSdp &sdp)
641 641
 {
642
-  if (media_session) {
643
-    media_session->mute(a_leg);
644
-    media_session->createHoldRequest(sdp, a_leg, false /*mark_zero_connection*/, true /*mark_sendonly*/);
642
+  AmB2BMedia *ms = getMediaSession();
643
+  if (ms) {
644
+    ms->mute(a_leg);
645
+    ms->createHoldRequest(sdp, a_leg, false /*mark_zero_connection*/, true /*mark_sendonly*/);
645 646
   }
646 647
   else {
647 648
     sdp.clear();
... ...
@@ -680,7 +681,7 @@ void CallLeg::putOnHold()
680 681
 
681 682
   AmSdp sdp;
682 683
   createHoldRequest(sdp);
683
-  if (media_session) updateLocalSdp(sdp);
684
+  updateLocalSdp(sdp);
684 685
 
685 686
   // generate re-INVITE with hold request
686 687
   //reinvite(sdp, hold_request_cseq);
... ...
@@ -712,11 +713,9 @@ void CallLeg::resumeHeld(bool send_reinvite)
712 713
     return;
713 714
   }
714 715
 
715
-  if (media_session) {
716
-    AmSdp sdp;
717
-    if (sdp.parse((const char *)established_body.getPayload()) == 0)
718
-      updateLocalSdp(sdp);
719
-  }
716
+  AmSdp sdp;
717
+  if (sdp.parse((const char *)established_body.getPayload()) == 0)
718
+    updateLocalSdp(sdp);
720 719
 
721 720
   if (dlg->reinvite("", &established_body, SIP_FLAGS_VERBATIM) != 0) {
722 721
     ERROR("re-INVITE failed\n");
... ...
@@ -739,7 +738,8 @@ void CallLeg::handleHoldReply(bool succeeded)
739 738
     case ResumeRequested:
740 739
       if (succeeded) {
741 740
         hold_status = NotHeld; // call resumed successfully
742
-        if (media_session) media_session->unmute(a_leg);
741
+        AmB2BMedia *ms = getMediaSession();
742
+        if (ms) ms->unmute(a_leg);
743 743
       }
744 744
       break;
745 745
 
... ...
@@ -569,10 +569,11 @@ void SBCCallLeg::onOtherBye(const AmSipRequest& req)
569 569
 
570 570
 void SBCCallLeg::onDtmf(int event, int duration)
571 571
 {
572
-  if(media_session) {
572
+  AmB2BMedia *ms = getMediaSession();
573
+  if(ms) {
573 574
     DBG("received DTMF on %c-leg (%i;%i)\n",
574 575
 	a_leg ? 'A': 'B', event, duration);
575
-    media_session->sendDtmf(!a_leg,event,duration);
576
+    ms->sendDtmf(!a_leg,event,duration);
576 577
   }
577 578
 }
578 579
 
... ...
@@ -588,7 +589,8 @@ bool SBCCallLeg::updateRemoteSdp(AmSdp &sdp)
588 589
 {
589 590
   SBCRelayController rc(&call_profile.transcoder, a_leg);
590 591
   if (call_profile.transcoder.isActive()) {
591
-    if (media_session) return media_session->updateRemoteSdp(a_leg, sdp, &rc);
592
+    AmB2BMedia *ms = getMediaSession();
593
+    if (ms) return ms->updateRemoteSdp(a_leg, sdp, &rc);
592 594
   }
593 595
 
594 596
   // call original implementation because our special conditions above are not met
... ...
@@ -1602,7 +1604,7 @@ void SBCCallLeg::onB2BEvent(B2BEvent* ev)
1602 1604
       case RTP_Relay:
1603 1605
       case RTP_Transcoding:
1604 1606
           setMediaSession(e->media);
1605
-          media_session->changeSession(a_leg, this);
1607
+          if (e->media) getMediaSession()->changeSession(a_leg, this);
1606 1608
           break;
1607 1609
 
1608 1610
       case RTP_Direct:
... ...
@@ -155,7 +155,7 @@ class SBCCallLeg : public CallLeg, public CredentialHolder
155 155
   CallStatus getCallStatus() { return CallLeg::getCallStatus(); }
156 156
 
157 157
   // media interface must be accessible from CC modules
158
-  AmB2BMedia *getMediaSession() { return media_session; }
158
+  AmB2BMedia *getMediaSession() { return AmB2BSession::getMediaSession(); }
159 159
   virtual bool updateLocalSdp(AmSdp &sdp);
160 160
   virtual bool updateRemoteSdp(AmSdp &sdp);
161 161
   void changeRtpMode(RTPRelayMode new_mode);
... ...
@@ -1147,7 +1147,7 @@ void AmB2BCallerSession::initializeRTPRelay(AmB2BCalleeSession* callee_session)
1147 1147
 
1148 1148
   if ((rtp_relay_mode == RTP_Relay) || (rtp_relay_mode == RTP_Transcoding)) {
1149 1149
     setMediaSession(new AmB2BMedia(this, callee_session)); // we need to add our reference
1150
-    callee_session->setMediaSession(media_session);
1150
+    callee_session->setMediaSession(getMediaSession());
1151 1151
     
1152 1152
     // Misusing invite_req here, but seems to be better than misusing
1153 1153
     // invite_sdp. The best way would be to propagate SDP as parameter of
... ...
@@ -298,11 +298,12 @@ private:
298 298
 
299 299
   /* -------------- media processing -------------- */
300 300
 
301
-  protected:
301
+  private:
302 302
     AmB2BMedia *media_session;
303 303
 
304 304
   public:
305 305
     void setMediaSession(AmB2BMedia *new_session);
306
+    AmB2BMedia *getMediaSession() { return media_session; }
306 307
 };
307 308
 
308 309
 class AmB2BCalleeSession;