Browse code

sbc b/f: always call parent's updateRemoteSdp instead of direct call to B2B media

Václav Kubart authored on 31/10/2013 09:07:43
Showing 6 changed files
... ...
@@ -62,69 +62,6 @@ static bool containsPayload(const std::vector<SdpPayload>& payloads, const SdpPa
62 62
 
63 63
 ///////////////////////////////////////////////////////////////////////////////////////////
64 64
 
65
-class SBCRelayController: public RelayController {
66
-  private:
67
-    SBCCallProfile::TranscoderSettings *transcoder_settings;
68
-    bool aleg;
69
-
70
-  public:
71
-    SBCRelayController(SBCCallProfile::TranscoderSettings *t, bool _aleg): transcoder_settings(t), aleg(_aleg) { }
72
-
73
-    virtual void computeRelayMask(const SdpMedia &m, bool &enable, PayloadMask &mask);
74
-};
75
-
76
-void SBCRelayController::computeRelayMask(const SdpMedia &m, bool &enable, PayloadMask &mask)
77
-{
78
-  TRACE("entering SBCRelayController::computeRelayMask(%s)\n", aleg ? "A leg" : "B leg");
79
-
80
-  PayloadMask m1, m2;
81
-  bool use_m1 = false;
82
-
83
-  /* if "m" contains only "norelay" codecs, relay is enabled for them (main idea
84
-   * of these codecs is to limit network bandwidth and it makes not much sense
85
-   * to transcode between codecs 'which are better to avoid', right?)
86
-   *
87
-   * if "m" contains other codecs, relay is enabled as well
88
-   *
89
-   * => if m contains at least some codecs, relay is enabled */
90
-  enable = !m.payloads.empty();
91
-
92
-  vector<SdpPayload> &norelay_payloads =
93
-    aleg ? transcoder_settings->audio_codecs_norelay_aleg : transcoder_settings->audio_codecs_norelay;
94
-
95
-  vector<SdpPayload>::const_iterator p;
96
-  for (p = m.payloads.begin(); p != m.payloads.end(); ++p) {
97
-
98
-    // do not mark telephone-event payload for relay (and do not use it for
99
-    // transcoding as well)
100
-    if(strcasecmp("telephone-event",p->encoding_name.c_str()) == 0) continue;
101
-
102
-    // mark every codec for relay in m2
103
-    TRACE("m2: marking payload %d for relay\n", p->payload_type);
104
-    m2.set(p->payload_type);
105
-
106
-    if (!containsPayload(norelay_payloads, *p, m.transport)) {
107
-      // this payload can be relayed
108
-
109
-      TRACE("m1: marking payload %d for relay\n", p->payload_type);
110
-      m1.set(p->payload_type);
111
-
112
-      if (!use_m1 && containsPayload(transcoder_settings->audio_codecs, *p, m.transport)) {
113
-        // the remote SDP contains transcodable codec which can be relayed (i.e.
114
-        // the one with higher "priority" so we want to disable relaying of the
115
-        // payloads which should not be ralyed if possible)
116
-        use_m1 = true;
117
-      }
118
-    }
119
-  }
120
-
121
-  TRACE("using %s\n", use_m1 ? "m1" : "m2");
122
-  if (use_m1) mask = m1;
123
-  else mask = m2;
124
-}
125
-
126
-///////////////////////////////////////////////////////////////////////////////////////////
127
-
128 65
 // map stream index and transcoder payload index (two dimensions) into one under
129 66
 // presumption that there will be less than 128 payloads for transcoding
130 67
 // (might be handy to remember mapping only for dynamic ones (96-127)
... ...
@@ -670,19 +607,8 @@ void SBCCallLeg::updateLocalSdp(AmSdp &sdp)
670 607
   CallLeg::updateLocalSdp(sdp);
671 608
 }
672 609
 
673
-
674 610
 void SBCCallLeg::updateRemoteSdp(AmSdp &sdp)
675 611
 {
676
-  SBCRelayController rc(&call_profile.transcoder, a_leg);
677
-  if (call_profile.transcoder.isActive()) {
678
-    AmB2BMedia *ms = getMediaSession();
679
-    if (ms) {
680
-      ms->updateRemoteSdp(a_leg, sdp, &rc);
681
-      return;
682
-    }
683
-  }
684
-
685
-  // call original implementation because our special conditions above are not met
686 612
   CallLeg::updateRemoteSdp(sdp);
687 613
 }
688 614
 
... ...
@@ -1679,3 +1605,60 @@ void SBCCallLeg::setLogger(msg_logger *_logger)
1679 1605
     else m->setRtpLogger(NULL);
1680 1606
   }
1681 1607
 }
1608
+
1609
+void SBCCallLeg::computeRelayMask(const SdpMedia &m, bool &enable, PayloadMask &mask)
1610
+{
1611
+  if (call_profile.transcoder.isActive()) {
1612
+    TRACE("entering transcoder's computeRelayMask(%s)\n", a_leg ? "A leg" : "B leg");
1613
+
1614
+    SBCCallProfile::TranscoderSettings &transcoder_settings = call_profile.transcoder;
1615
+    PayloadMask m1, m2;
1616
+    bool use_m1 = false;
1617
+
1618
+    /* if "m" contains only "norelay" codecs, relay is enabled for them (main idea
1619
+     * of these codecs is to limit network bandwidth and it makes not much sense
1620
+     * to transcode between codecs 'which are better to avoid', right?)
1621
+     *
1622
+     * if "m" contains other codecs, relay is enabled as well
1623
+     *
1624
+     * => if m contains at least some codecs, relay is enabled */
1625
+    enable = !m.payloads.empty();
1626
+
1627
+    vector<SdpPayload> &norelay_payloads =
1628
+      a_leg ? transcoder_settings.audio_codecs_norelay_aleg : transcoder_settings.audio_codecs_norelay;
1629
+
1630
+    vector<SdpPayload>::const_iterator p;
1631
+    for (p = m.payloads.begin(); p != m.payloads.end(); ++p) {
1632
+
1633
+      // do not mark telephone-event payload for relay (and do not use it for
1634
+      // transcoding as well)
1635
+      if(strcasecmp("telephone-event",p->encoding_name.c_str()) == 0) continue;
1636
+
1637
+      // mark every codec for relay in m2
1638
+      TRACE("m2: marking payload %d for relay\n", p->payload_type);
1639
+      m2.set(p->payload_type);
1640
+
1641
+      if (!containsPayload(norelay_payloads, *p, m.transport)) {
1642
+        // this payload can be relayed
1643
+
1644
+        TRACE("m1: marking payload %d for relay\n", p->payload_type);
1645
+        m1.set(p->payload_type);
1646
+
1647
+        if (!use_m1 && containsPayload(transcoder_settings.audio_codecs, *p, m.transport)) {
1648
+          // the remote SDP contains transcodable codec which can be relayed (i.e.
1649
+          // the one with higher "priority" so we want to disable relaying of the
1650
+          // payloads which should not be ralyed if possible)
1651
+          use_m1 = true;
1652
+        }
1653
+      }
1654
+    }
1655
+
1656
+    TRACE("using %s\n", use_m1 ? "m1" : "m2");
1657
+    if (use_m1) mask = m1;
1658
+    else mask = m2;
1659
+  }
1660
+  else {
1661
+    // for non-transcoding modes use default
1662
+    CallLeg::computeRelayMask(m, enable, mask);
1663
+  }
1664
+}
... ...
@@ -171,6 +171,7 @@ class SBCCallLeg : public CallLeg, public CredentialHolder
171 171
   int startTimer(double timeout) { setTimer(ext_cc_timer_id, timeout); return ext_cc_timer_id++; }
172 172
 
173 173
   virtual void setMediaSession(AmB2BMedia *new_session);
174
+  virtual void computeRelayMask(const SdpMedia &m, bool &enable, PayloadMask &mask);
174 175
 
175 176
  protected:
176 177
   /** set to true once CCStart passed to call CCEnd implicitly (from onStop)
... ...
@@ -17,13 +17,7 @@ using namespace std;
17 17
 
18 18
 /** class for computing payloads for relay the simpliest way - allow relaying of
19 19
  * all payloads supported by remote party */
20
-class SimpleRelayController: public RelayController {
21
-  public:
22
-    virtual void computeRelayMask(const SdpMedia &m, bool &enable, PayloadMask &mask);
23
-};
24
-
25 20
 static B2BMediaStatistics b2b_stats;
26
-static SimpleRelayController simple_relay_ctrl;
27 21
 
28 22
 static const string zero_ip("0.0.0.0");
29 23
 
... ...
@@ -46,40 +40,6 @@ static void replaceRtcpAttr(SdpMedia &m, const string& relay_address, int rtcp_p
46 40
 
47 41
 //////////////////////////////////////////////////////////////////////////////////
48 42
 
49
-void SimpleRelayController::computeRelayMask(const SdpMedia &m, bool &enable, PayloadMask &mask)
50
-{
51
-  int te_pl = -1;
52
-  enable = false;
53
-
54
-  mask.clear();
55
-
56
-  // walk through the media lines and find the telephone-event payload
57
-  for (std::vector<SdpPayload>::const_iterator i = m.payloads.begin();
58
-      i != m.payloads.end(); ++i)
59
-  {
60
-    // do not mark telephone-event payload for relay
61
-    if(!strcasecmp("telephone-event",i->encoding_name.c_str())){
62
-      te_pl = i->payload_type;
63
-    }
64
-    else {
65
-      enable = true;
66
-    }
67
-  }
68
-
69
-  if(!enable)
70
-    return;
71
-
72
-  if(te_pl > 0) { 
73
-    TRACE("unmarking telephone-event payload %d for relay\n", te_pl);
74
-    mask.set(te_pl);
75
-  }
76
-
77
-  TRACE("marking all other payloads for relay\n");
78
-  mask.invert();
79
-}
80
-
81
-//////////////////////////////////////////////////////////////////////////////////
82
-
83 43
 void B2BMediaStatistics::incCodecWriteUsage(const string &codec_name)
84 44
 {
85 45
   if (codec_name.empty()) return;
... ...
@@ -970,8 +930,6 @@ static void updateRelayStream(AmRtpStream *stream,
970 930
 
971 931
 void AmB2BMedia::updateRemoteSdp(bool a_leg, const AmSdp &remote_sdp, RelayController *ctrl)
972 932
 {
973
-  if (!ctrl) ctrl = &simple_relay_ctrl; // use default controller if none given
974
-
975 933
   AmLock lock(mutex);
976 934
 
977 935
   // save SDP
... ...
@@ -372,7 +372,7 @@ class AmB2BMedia: public AmMediaSession
372 372
 				  const string& relay_public_address);
373 373
 
374 374
     /** Store remote SDP for given leg and update media session appropriately. */
375
-    void updateRemoteSdp(bool a_leg, const AmSdp &remote_sdp, RelayController *ctrl = NULL);
375
+    void updateRemoteSdp(bool a_leg, const AmSdp &remote_sdp, RelayController *ctrl);
376 376
     
377 377
     /** Store local SDP for given leg and update media session appropriately. */
378 378
     void updateLocalSdp(bool a_leg, const AmSdp &local_sdp);
... ...
@@ -447,7 +447,7 @@ void AmB2BSession::updateRemoteSdp(AmSdp &sdp)
447 447
     ERROR("BUG: media session is missing, can't update remote SDP\n");
448 448
     return; // FIXME: throw an exception here?
449 449
   }
450
-  media_session->updateRemoteSdp(a_leg, sdp);
450
+  media_session->updateRemoteSdp(a_leg, sdp, this);
451 451
 }
452 452
 
453 453
 void AmB2BSession::updateLocalSdp(AmSdp &sdp)
... ...
@@ -984,7 +984,40 @@ void AmB2BSession::clearRtpReceiverRelay() {
984 984
       break;
985 985
   }
986 986
 }
987
-  
987
+
988
+void AmB2BSession::computeRelayMask(const SdpMedia &m, bool &enable, PayloadMask &mask)
989
+{
990
+  int te_pl = -1;
991
+  enable = false;
992
+
993
+  mask.clear();
994
+
995
+  // walk through the media lines and find the telephone-event payload
996
+  for (std::vector<SdpPayload>::const_iterator i = m.payloads.begin();
997
+      i != m.payloads.end(); ++i)
998
+  {
999
+    // do not mark telephone-event payload for relay
1000
+    if(!strcasecmp("telephone-event",i->encoding_name.c_str())){
1001
+      te_pl = i->payload_type;
1002
+    }
1003
+    else {
1004
+      enable = true;
1005
+    }
1006
+  }
1007
+
1008
+  if(!enable)
1009
+    return;
1010
+
1011
+  if(te_pl > 0) {
1012
+    DBG("unmarking telephone-event payload %d for relay\n", te_pl);
1013
+    mask.set(te_pl);
1014
+  }
1015
+
1016
+  DBG("marking all other payloads for relay\n");
1017
+  mask.invert();
1018
+}
1019
+
1020
+
988 1021
 // 
989 1022
 // AmB2BCallerSession methods
990 1023
 //
... ...
@@ -113,7 +113,7 @@ struct B2BConnectEvent: public B2BEvent
113 113
  * It has two legs as independent sessions:
114 114
  * Callee- and caller-leg.
115 115
  */
116
-class AmB2BSession: public AmSession
116
+class AmB2BSession: public AmSession, private RelayController
117 117
 {
118 118
  public:
119 119
 
... ...
@@ -326,6 +326,9 @@ private:
326 326
   public:
327 327
     virtual void setMediaSession(AmB2BMedia *new_session);
328 328
     AmB2BMedia *getMediaSession() { return media_session; }
329
+
330
+    // see RelayController
331
+    virtual void computeRelayMask(const SdpMedia &m, bool &enable, PayloadMask &mask);
329 332
 };
330 333
 
331 334
 class AmB2BCalleeSession;