Skip to content

Commit

Permalink
Fix findRtpSource for non-primary ssrc's. (#2269)
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanLennox authored Jan 7, 2025
1 parent dc53cfb commit db7d0b8
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<RtpLayerDesc> {
Expand Down Expand Up @@ -180,14 +181,20 @@ 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.
* @return `true` if the specified `ssrc` is the primary SSRC
* 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) }
}

/**
Expand All @@ -199,10 +206,14 @@ fun Array<MediaSourceDesc>.findRtpLayerDescs(packet: VideoRtpPacket): Collection
return this.flatMap { it.findRtpLayerDescs(packet) }
}

fun Array<MediaSourceDesc>.findRtpSource(ssrc: Long): MediaSourceDesc? {
fun Array<MediaSourceDesc>.findRtpSourceByPrimary(ssrc: Long): MediaSourceDesc? {
return this.find { it.matches(ssrc) }
}

fun Array<MediaSourceDesc>.findRtpSource(ssrc: Long): MediaSourceDesc? {
return this.find { it.hasSsrc(ssrc) }
}

fun Array<MediaSourceDesc>.findRtpSource(packet: RtpPacket): MediaSourceDesc? = findRtpSource(packet.ssrc)

fun Array<MediaSourceDesc>.findRtpEncodingId(packet: VideoRtpPacket): Int? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit db7d0b8

Please sign in to comment.