Browse code

b/f:b2b: remember 'receiving' in AudioStreamData, to restore after re-init

also removed dsm sbc mute/unmute functions, as they need to use other proper functions

Stefan Sayer authored on 17/12/2013 13:18:37
Showing 7 changed files
... ...
@@ -59,11 +59,7 @@ MOD_ACTIONEXPORT_BEGIN(MOD_CLS_NAME) {
59 59
   DEF_CMD("sbc.addToMediaProcessor", MODSBCAddToMediaProcessor);
60 60
   DEF_CMD("sbc.removeFromMediaProcessor", MODSBCRemoveFromMediaProcessor);
61 61
 
62
-  DEF_CMD("sbc.pauseRtpStreams", MODSBCPauseRtpStreams);
63
-  DEF_CMD("sbc.resumeRtpStreams", MODSBCResumeRtpStreams);
64
-
65
-  DEF_CMD("sbc.muteRtpStreams", MODSBCMuteRtpStreams);
66
-  DEF_CMD("sbc.unmuteRtpStreams", MODSBCUnmuteRtpStreams);
62
+  DEF_CMD("sbc.streamsSetReceiving", MODSBCRtpStreamsSetReceiving);
67 63
 
68 64
 } MOD_ACTIONEXPORT_END;
69 65
 
... ...
@@ -494,46 +490,13 @@ EXEC_ACTION_START(MODSBCRemoveFromMediaProcessor) {
494 490
   AmMediaProcessor::instance()->removeSession(call_leg);
495 491
 } EXEC_ACTION_END;
496 492
 
497
-CONST_ACTION_2P(MODSBCPauseRtpStreams, ',', false);
498
-EXEC_ACTION_START(MODSBCPauseRtpStreams) {
499
-  bool p_a = (resolveVars(par1, sess, sc_sess, event_params)==DSM_TRUE);
500
-  bool p_b = (resolveVars(par2, sess, sc_sess, event_params)==DSM_TRUE);
501
-
502
-  GET_SBC_CALL_LEG(PauseRtpStream);
503
-  GET_B2B_MEDIA;
504
-
505
-  b2b_media->pauseStreams(p_a, p_b);
506
-} EXEC_ACTION_END;
507
-
508
-CONST_ACTION_2P(MODSBCResumeRtpStreams, ',', false);
509
-EXEC_ACTION_START(MODSBCResumeRtpStreams) {
510
-  bool p_a = (resolveVars(par1, sess, sc_sess, event_params)==DSM_TRUE);
511
-  bool p_b = (resolveVars(par2, sess, sc_sess, event_params)==DSM_TRUE);
512
-
513
-  GET_SBC_CALL_LEG(ResumeRtpStream);
514
-
515
-  GET_B2B_MEDIA;
516
-  b2b_media->resumeStreams(p_a, p_b);
517
-} EXEC_ACTION_END;
518
-
519
-CONST_ACTION_2P(MODSBCMuteRtpStreams, ',', false);
520
-EXEC_ACTION_START(MODSBCMuteRtpStreams) {
521
-  bool p_a = (resolveVars(par1, sess, sc_sess, event_params)==DSM_TRUE);
522
-  bool p_b = (resolveVars(par2, sess, sc_sess, event_params)==DSM_TRUE);
523
-
524
-  GET_SBC_CALL_LEG(muteRtpStreams);
525
-  GET_B2B_MEDIA;
526
-
527
-  b2b_media->muteStreams(p_a, p_b);
528
-} EXEC_ACTION_END;
529
-
530
-CONST_ACTION_2P(MODSBCUnmuteRtpStreams, ',', false);
531
-EXEC_ACTION_START(MODSBCUnmuteRtpStreams) {
493
+CONST_ACTION_2P(MODSBCRtpStreamsSetReceiving, ',', false);
494
+EXEC_ACTION_START(MODSBCRtpStreamsSetReceiving) {
532 495
   bool p_a = (resolveVars(par1, sess, sc_sess, event_params)==DSM_TRUE);
533 496
   bool p_b = (resolveVars(par2, sess, sc_sess, event_params)==DSM_TRUE);
534 497
 
535
-  GET_SBC_CALL_LEG(unmuteRtpStreams);
498
+  GET_SBC_CALL_LEG(RtpStreamsSetReceiving);
536 499
   GET_B2B_MEDIA;
537 500
 
538
-  b2b_media->unmuteStreams(p_a, p_b);
501
+  b2b_media->setReceiving(p_a, p_b);
539 502
 } EXEC_ACTION_END;
... ...
@@ -54,10 +54,6 @@ DEF_ACTION_1P(MODSBCEnableRelayDTMFReceiving);
54 54
 DEF_ACTION_1P(MODSBCAddToMediaProcessor);
55 55
 DEF_ACTION_1P(MODSBCRemoveFromMediaProcessor);
56 56
 
57
-DEF_ACTION_2P(MODSBCPauseRtpStreams);
58
-DEF_ACTION_2P(MODSBCResumeRtpStreams);
59
-
60
-DEF_ACTION_2P(MODSBCMuteRtpStreams);
61
-DEF_ACTION_2P(MODSBCUnmuteRtpStreams);
57
+DEF_ACTION_2P(MODSBCRtpStreamsSetReceiving);
62 58
 
63 59
 #endif
... ...
@@ -184,7 +184,7 @@ AudioStreamData::AudioStreamData(AmB2BSession *session):
184 184
   incoming_payload(UNDEFINED_PAYLOAD),
185 185
   force_symmetric_rtp(false),
186 186
   enable_dtmf_transcoding(false),
187
-  muted(false), relay_paused(false)
187
+  muted(false), relay_paused(false), receiving(true)
188 188
 {
189 189
   if (session) initialize(session);
190 190
   else stream = NULL; // not initialized yet
... ...
@@ -359,6 +359,7 @@ bool AudioStreamData::initStream(PlayoutType playout_type,
359 359
     // to be relayed this needs not to be an error)
360 360
   }
361 361
   stream->setOnHold(muted);
362
+  stream->setReceiving(receiving);
362 363
 
363 364
   return initialized;
364 365
 }
... ...
@@ -472,12 +473,23 @@ int AudioStreamData::writeStream(unsigned long long ts, unsigned char *buffer, A
472 473
 
473 474
 void AudioStreamData::mute(bool set_mute)
474 475
 {
476
+  DBG("mute(%s) - RTP stream [%p]\n", set_mute?"true":"false", stream);
477
+ 
475 478
   if (stream) {
476 479
     stream->setOnHold(set_mute);
477 480
     if (muted != set_mute) stream->clearRTPTimeout();
478 481
   }
479 482
   muted = set_mute;
480 483
 }
484
+
485
+void AudioStreamData::setReceiving(bool r) {
486
+  DBG("setReceiving(%s) - RTP stream [%p]\n", r?"true":"false", stream);
487
+  if (stream) {
488
+    stream->setReceiving(r);
489
+  }
490
+  receiving = r;
491
+}
492
+
481 493
 //////////////////////////////////////////////////////////////////////////////////
482 494
 
483 495
 AmB2BMedia::RelayStreamPair::RelayStreamPair(AmB2BSession *_a, AmB2BSession *_b)
... ...
@@ -1182,36 +1194,26 @@ void AmB2BMedia::setRelayDTMFReceiving(bool enabled) {
1182 1194
   }
1183 1195
 }
1184 1196
 
1185
-#define ALL_STREAMS_OP(op_name, op_action)				\
1186
-  void AmB2BMedia::op_name(bool pause_a, bool pause_b) {		\
1187
-    DBG("relay_streams.size() = %zd, audio_streams.size() = %zd\n", relay_streams.size(), audio.size()); \
1188
-    for (RelayStreamIterator j = relay_streams.begin(); j != relay_streams.end(); j++) { \
1189
-      if (pause_a) {							\
1190
-	DBG(#op_name " A relay stream [%p]\n", &(*j)->a);		\
1191
-	(*j)->a.op_action;						\
1192
-      }									\
1193
-      if (pause_b) {							\
1194
-	DBG(#op_name " B relay stream [%p]\n", &(*j)->b);		\
1195
-	(*j)->b.op_action;						\
1196
-      }									\
1197
-    }									\
1198
-									\
1199
-    for (AudioStreamIterator j = audio.begin(); j != audio.end(); j++) { \
1200
-      if (pause_a && NULL != j->a.getStream()) {			\
1201
-	DBG(#op_name " A audio stream [%p]\n", j->a.getStream());	\
1202
-	j->a.getStream()->op_action;					\
1203
-      }									\
1204
-      if (pause_b && NULL != j->b.getStream()) {			\
1205
-	DBG(#op_name " B audio stream [%p]\n", j->b.getStream());	\
1206
-	j->b.getStream()->op_action;					\
1207
-      }									\
1208
-    }									\
1209
-  }
1210
-
1211
-ALL_STREAMS_OP(pauseStreams, pause());
1212
-ALL_STREAMS_OP(resumeStreams, resume());
1213
-ALL_STREAMS_OP(muteStreams, mute=true);
1214
-ALL_STREAMS_OP(unmuteStreams, mute=false);
1197
+/** set receving of RTP/relay streams (not receiving=drop incoming packets) */
1198
+void AmB2BMedia::setReceiving(bool receiving_a, bool receiving_b) {
1199
+  AmLock lock(mutex); // TODO: is this necessary?
1200
+
1201
+  DBG("relay_streams.size() = %zd, audio_streams.size() = %zd\n", relay_streams.size(), audio.size());
1202
+  for (RelayStreamIterator j = relay_streams.begin(); j != relay_streams.end(); j++) {
1203
+    DBG("setReceiving(%s) A relay stream [%p]\n", receiving_a?"true":"false", &(*j)->a);
1204
+    (*j)->a.setReceiving(receiving_a);
1205
+    DBG("setReceiving(%s) B relay stream [%p]\n", receiving_b?"true":"false", &(*j)->b);
1206
+    (*j)->b.setReceiving(receiving_b);
1207
+  }
1208
+
1209
+  for (AudioStreamIterator j = audio.begin(); j != audio.end(); j++) {
1210
+    DBG("setReceiving(%s) A audio stream [%p]\n", receiving_a?"true":"false", j->a.getStream());
1211
+    j->a.setReceiving(receiving_a);
1212
+    DBG("setReceiving(%s) B audio stream [%p]\n", receiving_b?"true":"false", j->b.getStream());
1213
+    j->b.setReceiving(receiving_b);
1214
+  }
1215
+
1216
+}
1215 1217
 
1216 1218
 void AmB2BMedia::pauseRelay() {
1217 1219
   DBG("relay_streams.size() = %zd, audio_streams.size() = %zd\n", relay_streams.size(), audio.size());
... ...
@@ -97,6 +97,8 @@ class AudioStreamData {
97 97
 
98 98
     bool muted;
99 99
 
100
+    bool receiving;
101
+
100 102
     // for performance monitoring
101 103
     int outgoing_payload;
102 104
     int incoming_payload;
... ...
@@ -205,6 +207,7 @@ class AudioStreamData {
205 207
     void getSdpOffer(int media_idx, SdpMedia &m) { if (stream) stream->getSdpOffer(media_idx, m); }
206 208
     void getSdpAnswer(int media_idx, const SdpMedia &offer, SdpMedia &answer) { if (stream) stream->getSdpAnswer(media_idx, offer, answer); }
207 209
     void mute(bool set_mute);
210
+    void setReceiving(bool r);
208 211
     void setInput(AmAudio *_in) { in = _in; }
209 212
     AmAudio *getInput() { return in; }
210 213
 
... ...
@@ -339,6 +342,7 @@ class AmB2BMedia: public AmMediaSession
339 342
     std::vector<RelayStreamPair*> relay_streams;
340 343
 
341 344
     bool a_leg_muted, b_leg_muted;
345
+    bool a_leg_receiving, b_leg_receiving;
342 346
 
343 347
     bool relay_paused;
344 348
 
... ...
@@ -479,17 +483,8 @@ class AmB2BMedia: public AmMediaSession
479 483
     /** restart relaying on streams */
480 484
     void restartRelay();
481 485
 
482
-    /** set RTP/relay streams to 'paused' (= not receiving, drop incoming packets) */
483
-    void pauseStreams(bool pause_a, bool pause_b);
484
-
485
-    /** resume RTP/relay streams from 'paused' (= receiving) */
486
-    void resumeStreams(bool resume_a, bool resume_b);
487
-
488
-    /** set RTP/relay streams to muted (don't send RTP packets) */
489
-    void muteStreams(bool mute_a, bool mute_b);
490
-
491
-    /** set RTP/relay streams to unmuted (do send RTP packets) */
492
-    void unmuteStreams(bool unmute_a, bool unmute_b);
486
+    /** set 'receving' property of RTP/relay streams (not receiving=drop incoming packets) */
487
+    void setReceiving(bool receiving_a, bool receiving_b);
493 488
 
494 489
     // print debug info
495 490
     void debug();
... ...
@@ -758,13 +758,20 @@ int AmRtpStream::init(const AmSdp& local,
758 758
   return 0;
759 759
 }
760 760
 
761
+void AmRtpStream::setReceiving(bool r) {
762
+  DBG("RTP stream instance [%p] set receiving=%s\n", this, r?"true":"false");
763
+  receiving = r;
764
+}
765
+
761 766
 void AmRtpStream::pause()
762 767
 {
768
+  DBG("RTP Stream instance [%p] pausing (receiving=false)\n", this);
763 769
   receiving = false;
764 770
 }
765 771
 
766 772
 void AmRtpStream::resume()
767 773
 {
774
+  DBG("RTP Stream instance [%p] resuming (receiving=true, clearing biffers/TS/TO)\n", this);
768 775
   clearRTPTimeout();
769 776
   receive_mut.lock();
770 777
   mem.clear();
... ...
@@ -311,6 +311,11 @@ protected:
311 311
 
312 312
 public:
313 313
 
314
+  /**
315
+   * Set whether RTP stream will receive RTP packets internally (received packets will be dropped or not).
316
+   */
317
+  void setReceiving(bool r);
318
+
314 319
   /**
315 320
    * Stops RTP stream receiving RTP packets internally (received packets will be dropped).
316 321
    */
... ...
@@ -226,8 +226,4 @@ sbc.addToMediaProcessor      - add sbc session to media processor (no playlist s
226 226
 
227 227
 sbc.removeFromMediaProcessor - remove sbc session from media processor
228 228
 
229
-sbc.pauseRtpStreams(bool pause_a, bool pause_b)     - pause A/B streams: drop received packets 
230
-sbc.resumeRtpStreams(bool resume_a, bool resume_b)  - resume A/B streams: process received packets 
231
-
232
-sbc.muteRtpStreams(bool mute_a, bool mute_b)        - mute A/B streams: don't send packets
233
-sbc.unmuteRtpStreams(bool unmute_a, bool unmute_b)  - unmute A/B streams: do send packets
229
+sbc.streamsSetReceiving(bool receiving_a, bool receiving_b)     - pause A/B streams: drop received packets