Skip to content

Commit

Permalink
feat(transcription): Slow down leaving participants.
Browse files Browse the repository at this point in the history
Slow down events internally in the transcriber, so we give time for the service to return any pending transcriptions.
We also wait for all leave processing to finish before transcriber leaves the room, so any sent transcriptions to be processed.
  • Loading branch information
damencho committed Mar 18, 2024
1 parent 71b8a91 commit e479424
Showing 1 changed file with 54 additions and 18 deletions.
72 changes: 54 additions & 18 deletions src/main/java/org/jitsi/jigasi/TranscriptionGatewaySession.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import net.java.sip.communicator.service.protocol.*;
import net.java.sip.communicator.service.protocol.event.*;
import net.java.sip.communicator.service.protocol.media.*;
import org.jitsi.utils.concurrent.*;
import org.jitsi.xmpp.extensions.jitsimeet.*;
import org.jitsi.jigasi.transcription.*;
import org.jitsi.service.neomedia.*;
Expand All @@ -34,6 +35,7 @@
import org.jxmpp.stringprep.*;

import java.util.*;
import java.util.concurrent.*;

/**
* A TranscriptionGatewaySession is able to join a JVB conference and
Expand Down Expand Up @@ -68,7 +70,7 @@ public class TranscriptionGatewaySession
* How long the transcriber should wait until really leaving the conference
* when no participant is requesting transcription anymore.
*/
public final static int PRESENCE_UPDATE_WAIT_UNTIL_LEAVE_DURATION = 2500;
public final static int PRESENCE_UPDATE_WAIT_UNTIL_LEAVE_DURATION = 3000;

/**
* The TranscriptionService used by this session
Expand Down Expand Up @@ -113,6 +115,17 @@ public class TranscriptionGatewaySession
*/
private boolean isBackendTranscribingEnabled = false;

/**
* The thread pool to serve all leave operations.
*/
private static final ScheduledExecutorService leaveThreadPool = Executors.newScheduledThreadPool(
2, new CustomizableThreadFactory("participants-leaving", true));

/**
* Keeps the number of currently leaving participants.
*/
private int numberOfScheduledParticipantsLeaving = 0;

/**
* Create a TranscriptionGatewaySession which can handle the transcription
* of a JVB conference
Expand Down Expand Up @@ -307,7 +320,28 @@ void notifyChatRoomMemberLeft(ChatRoomMember chatMember)
super.notifyChatRoomMemberLeft(chatMember);

String identifier = getParticipantIdentifier(chatMember);
this.transcriber.participantLeft(identifier);
if ("focus".equals(identifier) || this.jvbConference.getResourceIdentifier().toString().equals(identifier))
{
return;
}

synchronized (this)
{
numberOfScheduledParticipantsLeaving++;
}

// give some time for the transcriptions for this participant to be ready
leaveThreadPool.schedule(() ->
{
this.transcriber.participantLeft(identifier);
synchronized (this)
{
numberOfScheduledParticipantsLeaving--;
}
},
PRESENCE_UPDATE_WAIT_UNTIL_LEAVE_DURATION,
TimeUnit.MILLISECONDS
);
}

@Override
Expand All @@ -332,22 +366,24 @@ private void maybeStopTranscription()
{
if (transcriber.isTranscribing() && !isTranscriptionRequested())
{
new Thread(() ->
{
try
{
Thread.sleep(PRESENCE_UPDATE_WAIT_UNTIL_LEAVE_DURATION);
}
catch (InterruptedException e)
{
logger.error(e);
}

if (!isTranscriptionRequested())
{
jvbConference.stop();
}
}).start();
// let's give some time for the transcriptions to finish
leaveThreadPool.schedule(() -> {
if (transcriber.isTranscribing() && !isTranscriptionRequested())
{
if (this.numberOfScheduledParticipantsLeaving == 0)
{
jvbConference.stop();
}
else
{
// there seems to be still participants leaving, give them time before transcriber leaves
maybeStopTranscription();
}
}
},
PRESENCE_UPDATE_WAIT_UNTIL_LEAVE_DURATION,
TimeUnit.MILLISECONDS
);
}
}

Expand Down

0 comments on commit e479424

Please sign in to comment.