Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Call conference.addEndpoints() a single time when adding RelayedEndpoints. #2010

Merged
merged 2 commits into from
Apr 10, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import org.jitsi.nlj.util.SsrcAssociation
import org.jitsi.utils.MediaType
import org.jitsi.utils.logging2.Logger
import org.jitsi.utils.logging2.createChildLogger
import org.jitsi.videobridge.AbstractEndpoint
import org.jitsi.videobridge.Conference
import org.jitsi.videobridge.relay.AudioSourceDesc
import org.jitsi.videobridge.relay.Relay
Expand Down Expand Up @@ -436,13 +437,18 @@ class Colibri2ConferenceHandler(
/* No need to put media in conference-modified. */
}

// Calls to conference.addEndpoint re-run bandwidth allocation for the existing endpoints in the conference,
// so call it only once.
val newEndpoints = mutableSetOf<AbstractEndpoint>()
c2relay.endpoints?.endpoints?.forEach { endpoint ->
if (endpoint.expire) {
relay.removeRemoteEndpoint(endpoint.id)
} else {
val sources = endpoint.parseSourceDescs()
if (endpoint.create) {
relay.addRemoteEndpoint(endpoint.id, endpoint.statsId, sources.first, sources.second)
relay.addRemoteEndpoint(endpoint.id, endpoint.statsId, sources.first, sources.second)?.let {
newEndpoints.add(it)
}
} else {
relay.updateRemoteEndpoint(endpoint.id, sources.first, sources.second)
}
Expand All @@ -455,6 +461,7 @@ class Colibri2ConferenceHandler(
}
}
}
conference.addEndpoints(newEndpoints)

/* TODO: handle the rest of the relay's fields: feedback sources. */
return respBuilder.build()
Expand Down
11 changes: 7 additions & 4 deletions jvb/src/main/kotlin/org/jitsi/videobridge/relay/Relay.kt
Original file line number Diff line number Diff line change
Expand Up @@ -733,18 +733,22 @@ class Relay @JvmOverloads constructor(
fun dtlsAppPacketReceived(data: ByteArray, off: Int, len: Int) =
sctpHandler.processPacket(PacketInfo(UnparsedPacket(data, off, len)))

/**
* Return the newly created endpoint, or null if an endpoint with that ID already existed. Note that the new
* endpoint has to be added to the [Conference] separately.
*/
fun addRemoteEndpoint(
id: String,
statsId: String?,
audioSources: Collection<AudioSourceDesc>,
videoSources: Collection<MediaSourceDesc>
) {
): RelayedEndpoint? {
val ep: RelayedEndpoint
synchronized(endpointsLock) {
if (relayedEndpoints.containsKey(id)) {
logger.warn("Relay already contains remote endpoint with ID $id")
updateRemoteEndpoint(id, audioSources, videoSources)
return
return null
}
ep = RelayedEndpoint(
conference,
Expand All @@ -765,8 +769,6 @@ class Relay @JvmOverloads constructor(
ep.ssrcs.forEach { ssrc -> endpointsBySsrc[ssrc] = ep }
}

conference.addEndpoints(setOf(ep))

srtpTransformers?.let { ep.setSrtpInformation(it) }
payloadTypes.forEach { payloadType -> ep.addPayloadType(payloadType) }
rtpExtensions.forEach { rtpExtension -> ep.addRtpExtension(rtpExtension) }
Expand All @@ -775,6 +777,7 @@ class Relay @JvmOverloads constructor(
setEndpointMediaSources(ep, audioSources, videoSources)

ep.setFeature(Features.TRANSCEIVER_PCAP_DUMP, transceiver.isFeatureEnabled(Features.TRANSCEIVER_PCAP_DUMP))
return ep
}

fun updateRemoteEndpoint(
Expand Down