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

Fix findRtpSource for non-primary ssrc's. #2269

Merged
merged 2 commits into from
Jan 7, 2025
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 @@ -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
Loading