Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions src/main/java/org/jitsi/jigasi/AudioModeration.java
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,7 @@ else if (type.equalsIgnoreCase("muteRequest"))
{
this.raiseHand();
}
// Send request to jicofo
else if (this.requestAudioMuteByJicofo(bAudioMute))
else if (this.mute(bAudioMute))
{
// Send response through sip, respondRemoteAudioMute
this.gatewaySession.sendJson(
Expand Down Expand Up @@ -342,14 +341,14 @@ void setChatRoomAudioMuted(boolean muted)
}

/**
* Request Jicofo on behalf to mute/unmute us.
* Mute/unmute us.
*
* @param bMuted <tt>true</tt> if request is to mute audio,
* false otherwise
* @return <tt>true</tt> if request succeeded, false
* otherwise
*/
public boolean requestAudioMuteByJicofo(boolean bMuted)
public boolean mute(boolean bMuted)
{
ChatRoom mucRoom = this.jvbConference.getJvbRoom();

Expand All @@ -360,6 +359,13 @@ public boolean requestAudioMuteByJicofo(boolean bMuted)
return false;
}

this.gatewaySession.mute(bMuted);

if (!this.avModerationEnabled)
{
return true;
}

StanzaCollector collector = null;
try
{
Expand Down Expand Up @@ -421,11 +427,11 @@ && isMutingSupported()
// in case of startAudioMuted, we want jicofo to stop the bridge from sending our audio
// a specific case for jigasi as it doesn't do local muting
// in case of av-moderation jicofo has done that already for us
this.requestAudioMuteByJicofo(true);
this.mute(true);
}

// inform the sip side that our state is muted (av moderation or not)
mute();
muteViaSIPInfo();

// in case we reconnect start muted maybe no-longer set
this.startAudioMuted = false;
Expand All @@ -438,7 +444,7 @@ && isMutingSupported()
* When we receive confirmation for the announcement we will update
* our presence status in the conference.
*/
public void mute()
public void muteViaSIPInfo()
{
if (!isMutingSupported())
return;
Expand Down Expand Up @@ -601,7 +607,7 @@ private IQ handleMuteIq(MuteIq muteIq)

if (doMute)
{
mute();
muteViaSIPInfo();
}

return IQ.createResultIQ(muteIq);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@
* send hole punch packets. It can happen that the xmpp call is dropped and
* the sip call participant is waiting then there will be no media ot RTCP to
* keep alive the stream from the other side.
* Can be muted to stop forwarding packets coming from the sip side.
*
* @author Damian Minkov
*/
public class SipCallKeepAliveTransformer
public class SipCallTransformer
extends SinglePacketTransformerAdapter
implements TransformEngine
{
Expand Down Expand Up @@ -76,11 +77,21 @@ public class SipCallKeepAliveTransformer
*/
private final MediaStream stream;

/**
* If true we will mute the media, so we will not forward any media from the sip side.
*/
private boolean mute = false;

/**
* Counter for the number of packets received.
* Used for passing through a packet while being muted, one on every 1000.
*/
private long packetsCounter = 0;

/**
* Initializes a new {@link SsrcRewriter} instance.
*/
public SipCallKeepAliveTransformer(
CallPeerMediaHandler handler, MediaStream stream)
public SipCallTransformer(CallPeerMediaHandler handler, MediaStream stream)
{
super(RTPPacketPredicate.INSTANCE);

Expand Down Expand Up @@ -116,8 +127,15 @@ public RawPacket transform(RawPacket pkt)
@Override
public RawPacket reverseTransform(RawPacket pkt)
{
packetsCounter++;
seenSSRCs.add(pkt.getSSRCAsLong());

// if muted we want to pass one packet every 1000 packets
if (mute && packetsCounter % 1000 != 0)
{
return null;
}

return pkt;
}

Expand All @@ -141,6 +159,15 @@ public PacketTransformer getRTCPTransformer()
return rtcpTransformer;
}

/**
* Sets the mute state of this transformer.
* @param bMuted <tt>true</tt> to mute the media, <tt>false</tt> to unmute.
*/
public void mute(boolean bMuted)
{
this.mute = bMuted;
}

/**
* Checks and filters RTCP.BYE.
*/
Expand Down Expand Up @@ -236,7 +263,7 @@ public void run()
RawPacket.FIXED_HEADER_SIZE + 1);

stream.injectPacket(
packet, true, SipCallKeepAliveTransformer.this);
packet, true, SipCallTransformer.this);

ts += 160;
}
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/org/jitsi/jigasi/SipGatewaySession.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,9 @@ public class SipGatewaySession
* from the sip direction. Skips forwarding RTCP traffic which is not
* intended for that direction (particularly we had seen RTCP.BYE for
* to cause media to stop (even when ssrc is not matching)).
* Used for muting the media stream.
*/
private SipCallKeepAliveTransformer transformerMonitor;
private SipCallTransformer callTransformer;

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

if (this.transformerMonitor != null)
if (this.callTransformer != null)
{
this.transformerMonitor.dispose();
this.transformerMonitor = null;
this.callTransformer.dispose();
this.callTransformer = null;
}

this.soundNotificationManager.stop();
Expand Down Expand Up @@ -1155,11 +1156,16 @@ void notifyJvbRoomJoined()
if (this.jvbConference.getAudioModeration() != null)
{
// notify user that is muted
this.jvbConference.getAudioModeration().mute();
this.jvbConference.getAudioModeration().muteViaSIPInfo();
}
}
}

public void mute(boolean bMuted)
{
callTransformer.mute(bMuted);
}

/**
* {@inheritDoc}
*/
Expand Down Expand Up @@ -1236,9 +1242,8 @@ private boolean addSipCallTransformer(CallPeer peer)
MediaStream stream = mediaHandler.getStream(MediaType.AUDIO);
if (stream != null)
{
transformerMonitor = new SipCallKeepAliveTransformer(
peerMedia.getMediaHandler(), stream);
stream.setExternalTransformer(transformerMonitor);
callTransformer = new SipCallTransformer(peerMedia.getMediaHandler(), stream);
stream.setExternalTransformer(callTransformer);
return true;
}
}
Expand Down