Skip to content

Commit db7d0b8

Browse files
Fix findRtpSource for non-primary ssrc's. (#2269)
1 parent dc53cfb commit db7d0b8

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

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

Lines changed: 14 additions & 3 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)
@@ -146,7 +147,7 @@ class MediaSourceDesc
146147
}
147148

148149
@Synchronized
149-
fun findRtpEncodingDesc(ssrc: Long): RtpEncodingDesc? = rtpEncodings.find { it.matches(ssrc) }
150+
fun findRtpEncodingDesc(ssrc: Long): RtpEncodingDesc? = rtpEncodings.find { it.hasSsrc(ssrc) }
150151

151152
@Synchronized
152153
fun getEncodingLayers(ssrc: Long): Array<RtpLayerDesc> {
@@ -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.hasSsrc(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/RtpEncodingDesc.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,12 @@ constructor(
154154
}
155155

156156
/**
157-
* Gets a boolean indicating whether or not the SSRC specified in the
158-
* arguments matches this encoding or not.
157+
* Gets a boolean indicating whether the SSRC specified in the
158+
* arguments is used by this encoding.
159159
*
160160
* @param ssrc the SSRC to match.
161161
*/
162-
fun matches(ssrc: Long): Boolean {
162+
fun hasSsrc(ssrc: Long): Boolean {
163163
return if (primarySSRC == ssrc) {
164164
true
165165
} else {

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)