diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/MediaSourceDesc.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/MediaSourceDesc.kt index b529791bcc..546386b2ae 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/MediaSourceDesc.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/MediaSourceDesc.kt @@ -115,6 +115,7 @@ class MediaSourceDesc * @return the last "stable" bitrate (bps) of the encoding with a non-zero rate * at or below the specified index. */ + @Synchronized fun getBitrate(nowMs: Long, idx: Int): Bandwidth { for (entry in layersByIndex.headMap(idx, true).descendingMap()) { val bitrate = entry.value.getBitrate(nowMs) @@ -146,7 +147,7 @@ class MediaSourceDesc } @Synchronized - fun findRtpEncodingDesc(ssrc: Long): RtpEncodingDesc? = rtpEncodings.find { it.matches(ssrc) } + fun findRtpEncodingDesc(ssrc: Long): RtpEncodingDesc? = rtpEncodings.find { it.hasSsrc(ssrc) } @Synchronized fun getEncodingLayers(ssrc: Long): Array { @@ -180,7 +181,7 @@ class MediaSourceDesc /** * Checks whether the given SSRC matches this source's [primarySSRC]. * This is mostly useful only for determining quickly whether two source - * descriptions describe the same source; other functions should be used + * descriptions describe the same source; other functions (probably [hasSsrc]) should be used * to match received media packets. * * @param ssrc the SSRC to match. @@ -188,6 +189,12 @@ class MediaSourceDesc * for this source. */ fun matches(ssrc: Long) = rtpEncodings.getOrNull(0)?.primarySSRC == ssrc + + /** + * Checks whether any encoding of this source has this [ssrc] + */ + @Synchronized + fun hasSsrc(ssrc: Long) = rtpEncodings.any { it.hasSsrc(ssrc) } } /** @@ -199,10 +206,14 @@ fun Array.findRtpLayerDescs(packet: VideoRtpPacket): Collection return this.flatMap { it.findRtpLayerDescs(packet) } } -fun Array.findRtpSource(ssrc: Long): MediaSourceDesc? { +fun Array.findRtpSourceByPrimary(ssrc: Long): MediaSourceDesc? { return this.find { it.matches(ssrc) } } +fun Array.findRtpSource(ssrc: Long): MediaSourceDesc? { + return this.find { it.hasSsrc(ssrc) } +} + fun Array.findRtpSource(packet: RtpPacket): MediaSourceDesc? = findRtpSource(packet.ssrc) fun Array.findRtpEncodingId(packet: VideoRtpPacket): Int? { diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/RtpEncodingDesc.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/RtpEncodingDesc.kt index 570c5dde53..494bd0310e 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/RtpEncodingDesc.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/RtpEncodingDesc.kt @@ -154,12 +154,12 @@ constructor( } /** - * Gets a boolean indicating whether or not the SSRC specified in the - * arguments matches this encoding or not. + * Gets a boolean indicating whether the SSRC specified in the + * arguments is used by this encoding. * * @param ssrc the SSRC to match. */ - fun matches(ssrc: Long): Boolean { + fun hasSsrc(ssrc: Long): Boolean { return if (primarySSRC == ssrc) { true } else { diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/node/incoming/VideoParser.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/node/incoming/VideoParser.kt index d38b3ffeb7..5c88eb4c31 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/node/incoming/VideoParser.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/node/incoming/VideoParser.kt @@ -20,6 +20,7 @@ import org.jitsi.nlj.MediaSourceDesc import org.jitsi.nlj.PacketInfo import org.jitsi.nlj.SetMediaSourcesEvent import org.jitsi.nlj.findRtpSource +import org.jitsi.nlj.findRtpSourceByPrimary import org.jitsi.nlj.format.Vp8PayloadType import org.jitsi.nlj.format.Vp9PayloadType import org.jitsi.nlj.rtp.ParsedVideoPacket @@ -228,7 +229,7 @@ class VideoParser( } private fun resetSource(source: MediaSourceDesc) { - val signaledSource = signaledSources.findRtpSource(source.primarySSRC) + val signaledSource = signaledSources.findRtpSourceByPrimary(source.primarySSRC) if (signaledSource == null) { logger.warn("Unable to find signaled source corresponding to ${source.primarySSRC}") return