Skip to content

Commit

Permalink
feat: Read initial-last-n from jingle, set it in colibri2. (jitsi#1052)
Browse files Browse the repository at this point in the history
* feat: Read initial-last-n from jingle, set it in colibri2.

* chore: Update jitsi-xmpp-extensions.
  • Loading branch information
bgrozev authored Mar 16, 2023
1 parent 841569f commit eab721e
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import org.jitsi.xmpp.extensions.colibri2.Colibri2Relay
import org.jitsi.xmpp.extensions.colibri2.ConferenceModifiedIQ
import org.jitsi.xmpp.extensions.colibri2.ConferenceModifyIQ
import org.jitsi.xmpp.extensions.colibri2.Endpoints
import org.jitsi.xmpp.extensions.colibri2.InitialLastN
import org.jitsi.xmpp.extensions.colibri2.Media
import org.jitsi.xmpp.extensions.colibri2.Sctp
import org.jitsi.xmpp.extensions.colibri2.Transport
Expand Down Expand Up @@ -117,9 +118,10 @@ class Colibri2Session(
/** The transport info to set for the colibri2 endpoint, or null if it is not to be modified. */
transport: IceUdpTransportPacketExtension?,
/** The sources to set for the colibri2 endpoint, or null if the sources are not to be modified. */
sources: EndpointSourceSet?
sources: EndpointSourceSet?,
initialLastN: InitialLastN?
) {
if (transport == null && sources == null) {
if (transport == null && sources == null && initialLastN == null) {
logger.info("Nothing to update.")
return
}
Expand All @@ -138,6 +140,10 @@ class Colibri2Session(
endpoint.setSources(sources.toColibriMediaSources(participant.id))
}

initialLastN?.let {
endpoint.setInitialLastN(it)
}

request.addEndpoint(endpoint.build())
sendRequest(request.build(), "updateParticipant")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.jitsi.jicofo.bridge.Bridge
import org.jitsi.jicofo.conference.source.EndpointSourceSet
import org.jitsi.utils.MediaType
import org.jitsi.utils.OrderedJsonObject
import org.jitsi.xmpp.extensions.colibri2.InitialLastN
import org.jitsi.xmpp.extensions.colibri2.Media
import org.jitsi.xmpp.extensions.jingle.IceUdpTransportPacketExtension

Expand All @@ -42,19 +43,14 @@ interface ColibriSessionManager {
@Throws(ColibriAllocationFailedException::class, BridgeSelectionFailedException::class)
fun allocate(participant: ParticipantAllocationParameters): ColibriAllocation

/** For use in java because @JvmOverloads is not available for interfaces. */
fun updateParticipant(
participantId: String,
transport: IceUdpTransportPacketExtension? = null,
sources: EndpointSourceSet? = null,
) = updateParticipant(participantId, transport, sources, false)

fun updateParticipant(
participantId: String,
transport: IceUdpTransportPacketExtension? = null,
sources: EndpointSourceSet? = null,
initialLastN: InitialLastN? = null,
suppressLocalBridgeUpdate: Boolean = false
)

fun getBridgeSessionId(participantId: String): String?

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import org.jitsi.utils.logging2.Logger
import org.jitsi.utils.logging2.createChildLogger
import org.jitsi.xmpp.extensions.colibri2.Colibri2Error
import org.jitsi.xmpp.extensions.colibri2.ConferenceModifiedIQ
import org.jitsi.xmpp.extensions.colibri2.InitialLastN
import org.jitsi.xmpp.extensions.jingle.IceUdpTransportPacketExtension
import org.jivesoftware.smack.AbstractXMPPConnection
import org.jivesoftware.smack.StanzaCollector
Expand Down Expand Up @@ -518,6 +519,7 @@ class ColibriV2SessionManager(
participantId: String,
transport: IceUdpTransportPacketExtension?,
sources: EndpointSourceSet?,
initialLastN: InitialLastN?,
suppressLocalBridgeUpdate: Boolean
) = synchronized(syncRoot) {
logger.info("Updating $participantId with transport=$transport, sources=$sources")
Expand All @@ -530,7 +532,7 @@ class ColibriV2SessionManager(
return
}
if (!suppressLocalBridgeUpdate) {
participantInfo.session.updateParticipant(participantInfo, transport, sources)
participantInfo.session.updateParticipant(participantInfo, transport, sources, initialLastN)
}
if (sources != null) {
participantInfo.sources = sources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.jitsi.utils.*;
import org.jitsi.utils.logging2.*;
import org.jitsi.utils.logging2.Logger;
import org.jitsi.xmpp.extensions.colibri2.*;
import org.jitsi.xmpp.extensions.jibri.*;
import org.jitsi.xmpp.extensions.jingle.*;

Expand Down Expand Up @@ -1047,7 +1048,9 @@ public void updateTransport(@NotNull Participant participant, @NotNull IceUdpTra
getColibriSessionManager().updateParticipant(
participant.getEndpointId(),
transport,
null /* no change in sources, just transport */);
null /* no change in sources, just transport */,
null,
false);
}

/**
Expand Down Expand Up @@ -1092,7 +1095,12 @@ public void addSource(
// Updates source groups on the bridge
// We may miss the notification, but the state will be synced up after conference has been relocated to the new
// bridge
getColibriSessionManager().updateParticipant(participant.getEndpointId(), null, participant.getSources());
getColibriSessionManager().updateParticipant(
participant.getEndpointId(),
null,
participant.getSources(),
null,
false);
propagateNewSources(participant, sourcesAccepted);
}

Expand Down Expand Up @@ -1126,6 +1134,7 @@ public void removeSources(
participant.getEndpointId(),
null,
participant.getSources(),
null,
false);

sendSourceRemove(new ConferenceSourceMap(participantId, sourcesAcceptedToBeRemoved), participant);
Expand All @@ -1137,7 +1146,8 @@ public void removeSources(
void acceptSession(
@NotNull Participant participant,
@NotNull EndpointSourceSet sourcesAdvertised,
IceUdpTransportPacketExtension transport)
IceUdpTransportPacketExtension transport,
@Nullable InitialLastN initialLastN)
throws ValidationFailedException
{
String participantId = participant.getEndpointId();
Expand All @@ -1148,7 +1158,12 @@ void acceptSession(
sourcesAccepted = conferenceSources.tryToAdd(participantId, sourcesAdvertised);
}

getColibriSessionManager().updateParticipant(participantId, transport, getSourcesForParticipant(participant));
getColibriSessionManager().updateParticipant(
participantId,
transport,
getSourcesForParticipant(participant),
initialLastN,
false);

if (!sourcesAccepted.isEmpty())
{
Expand Down Expand Up @@ -1182,6 +1197,7 @@ private void removeParticipantSources(@NotNull Participant participant, boolean
participant.getEndpointId(),
null,
participant.getSources(),
null,
true);

if (sendSourceRemove)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import org.jitsi.jicofo.xmpp.muc.hasModeratorRights
import org.jitsi.utils.OrderedJsonObject
import org.jitsi.utils.logging2.Logger
import org.jitsi.utils.logging2.LoggerImpl
import org.jitsi.xmpp.extensions.colibri2.InitialLastN
import org.jitsi.xmpp.extensions.jingle.ContentPacketExtension
import org.jitsi.xmpp.extensions.jingle.JingleAction
import org.jitsi.xmpp.extensions.jingle.JingleIQ
Expand Down Expand Up @@ -205,27 +206,38 @@ open class Participant @JvmOverloads constructor(

/** Return `true` if this participant supports source name signaling. */
fun hasSourceNameSupport() = supportedFeatures.contains(Features.SOURCE_NAMES)

/** Return `true` if this participant supports SSRC rewriting functionality. */
fun hasSsrcRewritingSupport() = supportedFeatures.contains(Features.SSRC_REWRITING_V1)

/** Return `true` if SSRC rewriting should be used for this participant. */
fun useSsrcRewriting() = ConferenceConfig.config.useSsrcRewriting && hasSsrcRewritingSupport()

/** Return `true` if this participant supports receiving Jingle sources encoded in JSON. */
fun supportsJsonEncodedSources() = supportedFeatures.contains(Features.JSON_SOURCES)
fun supportsReceivingMultipleVideoStreams() = supportedFeatures.contains(Features.RECEIVE_MULTIPLE_STREAMS)

/** Returns `true` iff this participant supports REMB. */
fun hasRembSupport() = supportedFeatures.contains(Features.REMB)

/** Returns `true` iff this participant supports TCC. */
fun hasTccSupport() = supportedFeatures.contains(Features.TCC)

/** Returns `true` iff this participant supports RTX. */
fun hasRtxSupport() = supportedFeatures.contains(Features.RTX)

/** Returns `true` iff this participant supports RED for opus. */
fun hasOpusRedSupport() = supportedFeatures.contains(Features.OPUS_RED)

/** Returns true if RTP audio is supported by this peer. */
fun hasAudioSupport() = supportedFeatures.contains(Features.AUDIO)

/** Returns true if RTP video is supported by this peer. */
fun hasVideoSupport() = supportedFeatures.contains(Features.VIDEO)

/** Returns true if RTP audio can be muted for this peer. */
fun hasAudioMuteSupport() = supportedFeatures.contains(Features.AUDIO_MUTE)

/** Returns <tt>true</tt> if this peer supports DTLS/SCTP. */
fun hasSctpSupport() = supportedFeatures.contains(Features.SCTP)

Expand Down Expand Up @@ -339,6 +351,7 @@ open class Participant @JvmOverloads constructor(
* support unmuting).
*/
fun shouldSuppressForceMute() = (chatMember.isJigasi && !hasAudioMuteSupport()) || chatMember.isJibri

/** Checks whether this [Participant]'s role has moderator rights. */
fun hasModeratorRights() = chatMember.role.hasModeratorRights()
override fun toString() = "Participant[$mucJid]"
Expand Down Expand Up @@ -447,9 +460,11 @@ open class Participant @JvmOverloads constructor(
if (!sourcesAdvertised.isEmpty() && this@Participant.chatMember.role == MemberRole.VISITOR) {
return StanzaError.from(StanzaError.Condition.forbidden, "sources not allowed for visitors").build()
}
val initialLastN: InitialLastN? =
contents.find { it.name == "video" }?.getChildExtension(InitialLastN::class.java)

try {
conference.acceptSession(this@Participant, sourcesAdvertised, contents.getTransport())
conference.acceptSession(this@Participant, sourcesAdvertised, contents.getTransport(), initialLastN)
} catch (e: ValidationFailedException) {
return StanzaError.from(StanzaError.Condition.bad_request, e.message).build()
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>jitsi-xmpp-extensions</artifactId>
<version>1.0-64-gf221325</version>
<version>1.0-71-g8c6cdeb</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
Expand Down

0 comments on commit eab721e

Please sign in to comment.