Skip to content

Commit 1f3a2a0

Browse files
Fix findRtpSource for non-primary ssrc's.
1 parent dc53cfb commit 1f3a2a0

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/MediaSourceDesc.kt

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ class MediaSourceDesc
115115
* @return the last "stable" bitrate (bps) of the encoding with a non-zero rate
116116
* at or below the specified index.
117117
*/
118+
@Synchronized
118119
fun getBitrate(nowMs: Long, idx: Int): Bandwidth {
119120
for (entry in layersByIndex.headMap(idx, true).descendingMap()) {
120121
val bitrate = entry.value.getBitrate(nowMs)
@@ -180,14 +181,20 @@ class MediaSourceDesc
180181
/**
181182
* Checks whether the given SSRC matches this source's [primarySSRC].
182183
* This is mostly useful only for determining quickly whether two source
183-
* descriptions describe the same source; other functions should be used
184+
* descriptions describe the same source; other functions (probably [hasSsrc]) should be used
184185
* to match received media packets.
185186
*
186187
* @param ssrc the SSRC to match.
187188
* @return `true` if the specified `ssrc` is the primary SSRC
188189
* for this source.
189190
*/
190191
fun matches(ssrc: Long) = rtpEncodings.getOrNull(0)?.primarySSRC == ssrc
192+
193+
/**
194+
* Checks whether any encoding of this source has this [ssrc]
195+
*/
196+
@Synchronized
197+
fun hasSsrc(ssrc: Long) = rtpEncodings.any { it.matches(ssrc) }
191198
}
192199

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

202-
fun Array<MediaSourceDesc>.findRtpSource(ssrc: Long): MediaSourceDesc? {
209+
fun Array<MediaSourceDesc>.findRtpSourceByPrimary(ssrc: Long): MediaSourceDesc? {
203210
return this.find { it.matches(ssrc) }
204211
}
205212

213+
fun Array<MediaSourceDesc>.findRtpSource(ssrc: Long): MediaSourceDesc? {
214+
return this.find { it.hasSsrc(ssrc) }
215+
}
216+
206217
fun Array<MediaSourceDesc>.findRtpSource(packet: RtpPacket): MediaSourceDesc? = findRtpSource(packet.ssrc)
207218

208219
fun Array<MediaSourceDesc>.findRtpEncodingId(packet: VideoRtpPacket): Int? {

jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/node/incoming/VideoParser.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import org.jitsi.nlj.MediaSourceDesc
2020
import org.jitsi.nlj.PacketInfo
2121
import org.jitsi.nlj.SetMediaSourcesEvent
2222
import org.jitsi.nlj.findRtpSource
23+
import org.jitsi.nlj.findRtpSourceByPrimary
2324
import org.jitsi.nlj.format.Vp8PayloadType
2425
import org.jitsi.nlj.format.Vp9PayloadType
2526
import org.jitsi.nlj.rtp.ParsedVideoPacket
@@ -228,7 +229,7 @@ class VideoParser(
228229
}
229230

230231
private fun resetSource(source: MediaSourceDesc) {
231-
val signaledSource = signaledSources.findRtpSource(source.primarySSRC)
232+
val signaledSource = signaledSources.findRtpSourceByPrimary(source.primarySSRC)
232233
if (signaledSource == null) {
233234
logger.warn("Unable to find signaled source corresponding to ${source.primarySSRC}")
234235
return

0 commit comments

Comments
 (0)