@@ -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+
206217fun Array<MediaSourceDesc>.findRtpSource (packet : RtpPacket ): MediaSourceDesc ? = findRtpSource(packet.ssrc)
207218
208219fun Array<MediaSourceDesc>.findRtpEncodingId (packet : VideoRtpPacket ): Int? {
0 commit comments