Skip to content

Commit 3bb4143

Browse files
committed
fix: Fixes mute to stop forwarding stream.
This works only in the case when a streams are being forwarded (no transcoding).
1 parent 37d0eab commit 3bb4143

File tree

3 files changed

+58
-20
lines changed

3 files changed

+58
-20
lines changed

src/main/java/org/jitsi/jigasi/AudioModeration.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,7 @@ else if (type.equalsIgnoreCase("muteRequest"))
281281
{
282282
this.raiseHand();
283283
}
284-
// Send request to jicofo
285-
else if (this.requestAudioMuteByJicofo(bAudioMute))
284+
else if (this.mute(bAudioMute))
286285
{
287286
// Send response through sip, respondRemoteAudioMute
288287
this.gatewaySession.sendJson(
@@ -342,14 +341,14 @@ void setChatRoomAudioMuted(boolean muted)
342341
}
343342

344343
/**
345-
* Request Jicofo on behalf to mute/unmute us.
344+
* Mute/unmute us.
346345
*
347346
* @param bMuted <tt>true</tt> if request is to mute audio,
348347
* false otherwise
349348
* @return <tt>true</tt> if request succeeded, false
350349
* otherwise
351350
*/
352-
public boolean requestAudioMuteByJicofo(boolean bMuted)
351+
public boolean mute(boolean bMuted)
353352
{
354353
ChatRoom mucRoom = this.jvbConference.getJvbRoom();
355354

@@ -360,6 +359,13 @@ public boolean requestAudioMuteByJicofo(boolean bMuted)
360359
return false;
361360
}
362361

362+
this.gatewaySession.mute(bMuted);
363+
364+
if (!this.avModerationEnabled)
365+
{
366+
return true;
367+
}
368+
363369
StanzaCollector collector = null;
364370
try
365371
{
@@ -421,11 +427,11 @@ && isMutingSupported()
421427
// in case of startAudioMuted, we want jicofo to stop the bridge from sending our audio
422428
// a specific case for jigasi as it doesn't do local muting
423429
// in case of av-moderation jicofo has done that already for us
424-
this.requestAudioMuteByJicofo(true);
430+
this.mute(true);
425431
}
426432

427433
// inform the sip side that our state is muted (av moderation or not)
428-
mute();
434+
muteViaSIPInfo();
429435

430436
// in case we reconnect start muted maybe no-longer set
431437
this.startAudioMuted = false;
@@ -438,7 +444,7 @@ && isMutingSupported()
438444
* When we receive confirmation for the announcement we will update
439445
* our presence status in the conference.
440446
*/
441-
public void mute()
447+
public void muteViaSIPInfo()
442448
{
443449
if (!isMutingSupported())
444450
return;
@@ -601,7 +607,7 @@ private IQ handleMuteIq(MuteIq muteIq)
601607

602608
if (doMute)
603609
{
604-
mute();
610+
muteViaSIPInfo();
605611
}
606612

607613
return IQ.createResultIQ(muteIq);

src/main/java/org/jitsi/jigasi/SipCallKeepAliveTransformer.java renamed to src/main/java/org/jitsi/jigasi/SipCallTransformer.java

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@
3535
* send hole punch packets. It can happen that the xmpp call is dropped and
3636
* the sip call participant is waiting then there will be no media ot RTCP to
3737
* keep alive the stream from the other side.
38+
* Can be muted to stop forwarding packets coming from the sip side.
3839
*
3940
* @author Damian Minkov
4041
*/
41-
public class SipCallKeepAliveTransformer
42+
public class SipCallTransformer
4243
extends SinglePacketTransformerAdapter
4344
implements TransformEngine
4445
{
@@ -76,11 +77,21 @@ public class SipCallKeepAliveTransformer
7677
*/
7778
private final MediaStream stream;
7879

80+
/**
81+
* If true we will mute the media, so we will not forward any media from the sip side.
82+
*/
83+
private boolean mute = false;
84+
85+
/**
86+
* Counter for the number of packets received.
87+
* Used for passing through a packet while being muted, one on every 1000.
88+
*/
89+
private long packetsCounter = 0;
90+
7991
/**
8092
* Initializes a new {@link SsrcRewriter} instance.
8193
*/
82-
public SipCallKeepAliveTransformer(
83-
CallPeerMediaHandler handler, MediaStream stream)
94+
public SipCallTransformer(CallPeerMediaHandler handler, MediaStream stream)
8495
{
8596
super(RTPPacketPredicate.INSTANCE);
8697

@@ -116,8 +127,15 @@ public RawPacket transform(RawPacket pkt)
116127
@Override
117128
public RawPacket reverseTransform(RawPacket pkt)
118129
{
130+
packetsCounter++;
119131
seenSSRCs.add(pkt.getSSRCAsLong());
120132

133+
// if muted we want to pass one packet every 1000 packets
134+
if (mute && packetsCounter % 1000 != 0)
135+
{
136+
return null;
137+
}
138+
121139
return pkt;
122140
}
123141

@@ -141,6 +159,15 @@ public PacketTransformer getRTCPTransformer()
141159
return rtcpTransformer;
142160
}
143161

162+
/**
163+
* Sets the mute state of this transformer.
164+
* @param bMuted <tt>true</tt> to mute the media, <tt>false</tt> to unmute.
165+
*/
166+
public void mute(boolean bMuted)
167+
{
168+
this.mute = bMuted;
169+
}
170+
144171
/**
145172
* Checks and filters RTCP.BYE.
146173
*/
@@ -236,7 +263,7 @@ public void run()
236263
RawPacket.FIXED_HEADER_SIZE + 1);
237264

238265
stream.injectPacket(
239-
packet, true, SipCallKeepAliveTransformer.this);
266+
packet, true, SipCallTransformer.this);
240267

241268
ts += 160;
242269
}

src/main/java/org/jitsi/jigasi/SipGatewaySession.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,9 @@ public class SipGatewaySession
290290
* from the sip direction. Skips forwarding RTCP traffic which is not
291291
* intended for that direction (particularly we had seen RTCP.BYE for
292292
* to cause media to stop (even when ssrc is not matching)).
293+
* Used for muting the media stream.
293294
*/
294-
private SipCallKeepAliveTransformer transformerMonitor;
295+
private SipCallTransformer callTransformer;
295296

296297
/**
297298
* Whether we had sent indication that XMPP connection terminated and
@@ -716,10 +717,10 @@ private void sipCallEnded()
716717
if (peerStateListener != null)
717718
peerStateListener.unregister();
718719

719-
if (this.transformerMonitor != null)
720+
if (this.callTransformer != null)
720721
{
721-
this.transformerMonitor.dispose();
722-
this.transformerMonitor = null;
722+
this.callTransformer.dispose();
723+
this.callTransformer = null;
723724
}
724725

725726
this.soundNotificationManager.stop();
@@ -1155,11 +1156,16 @@ void notifyJvbRoomJoined()
11551156
if (this.jvbConference.getAudioModeration() != null)
11561157
{
11571158
// notify user that is muted
1158-
this.jvbConference.getAudioModeration().mute();
1159+
this.jvbConference.getAudioModeration().muteViaSIPInfo();
11591160
}
11601161
}
11611162
}
11621163

1164+
public void mute(boolean bMuted)
1165+
{
1166+
callTransformer.mute(bMuted);
1167+
}
1168+
11631169
/**
11641170
* {@inheritDoc}
11651171
*/
@@ -1236,9 +1242,8 @@ private boolean addSipCallTransformer(CallPeer peer)
12361242
MediaStream stream = mediaHandler.getStream(MediaType.AUDIO);
12371243
if (stream != null)
12381244
{
1239-
transformerMonitor = new SipCallKeepAliveTransformer(
1240-
peerMedia.getMediaHandler(), stream);
1241-
stream.setExternalTransformer(transformerMonitor);
1245+
callTransformer = new SipCallTransformer(peerMedia.getMediaHandler(), stream);
1246+
stream.setExternalTransformer(callTransformer);
12421247
return true;
12431248
}
12441249
}

0 commit comments

Comments
 (0)