-
Notifications
You must be signed in to change notification settings - Fork 995
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for the VLA RTP header extension (#2263)
* feat: Add BitReader utilities and tests. * feat: Add a parser for the VLA RTP header extension. * ref: Remove unused function. * feat: Update layers with info found in VLA. * feat: Add an option to use targetBitrate instead of measured bitrate for allocation * feat: Warn if replacing width/frameRate. * test: Add tests for invalid VLAs. * ref: Simplify code, add a comment. * feat: Retain the VLA extension between relays.
- Loading branch information
Showing
17 changed files
with
858 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/node/incoming/VlaReaderNode.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
/* | ||
* Copyright @ 2024-Present 8x8, Inc | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jitsi.nlj.transform.node.incoming | ||
|
||
import org.jitsi.nlj.Event | ||
import org.jitsi.nlj.MediaSourceDesc | ||
import org.jitsi.nlj.PacketInfo | ||
import org.jitsi.nlj.SetMediaSourcesEvent | ||
import org.jitsi.nlj.findRtpSource | ||
import org.jitsi.nlj.rtp.RtpExtensionType.VLA | ||
import org.jitsi.nlj.transform.node.ObserverNode | ||
import org.jitsi.nlj.util.ReadOnlyStreamInformationStore | ||
import org.jitsi.nlj.util.kbps | ||
import org.jitsi.rtp.rtp.RtpPacket | ||
import org.jitsi.rtp.rtp.header_extensions.VlaExtension | ||
import org.jitsi.utils.logging2.Logger | ||
import org.jitsi.utils.logging2.LoggerImpl | ||
import org.jitsi.utils.logging2.cdebug | ||
import org.jitsi.utils.logging2.createChildLogger | ||
|
||
/** | ||
* A node which reads the Video Layers Allocation (VLA) RTP header extension and updates the media sources. | ||
*/ | ||
class VlaReaderNode( | ||
streamInformationStore: ReadOnlyStreamInformationStore, | ||
parentLogger: Logger = LoggerImpl(VlaReaderNode::class.simpleName) | ||
) : ObserverNode("Video Layers Allocation reader") { | ||
private val logger = createChildLogger(parentLogger) | ||
private var vlaExtId: Int? = null | ||
private var mediaSourceDescs: Array<MediaSourceDesc> = arrayOf() | ||
|
||
init { | ||
streamInformationStore.onRtpExtensionMapping(VLA) { | ||
vlaExtId = it | ||
logger.debug("VLA extension ID set to $it") | ||
} | ||
} | ||
|
||
override fun handleEvent(event: Event) { | ||
when (event) { | ||
is SetMediaSourcesEvent -> { | ||
mediaSourceDescs = event.mediaSourceDescs.copyOf() | ||
logger.cdebug { "Media sources changed:\n${mediaSourceDescs.joinToString()}" } | ||
} | ||
} | ||
} | ||
|
||
override fun observe(packetInfo: PacketInfo) { | ||
val rtpPacket = packetInfo.packetAs<RtpPacket>() | ||
vlaExtId?.let { | ||
rtpPacket.getHeaderExtension(it)?.let { ext -> | ||
val vla = try { | ||
VlaExtension.parse(ext) | ||
} catch (e: Exception) { | ||
logger.warn("Failed to parse VLA extension", e) | ||
return | ||
} | ||
|
||
val sourceDesc = mediaSourceDescs.findRtpSource(rtpPacket) | ||
|
||
logger.debug("Found VLA=$vla for sourceDesc=$sourceDesc") | ||
|
||
vla.forEachIndexed { streamIdx, stream -> | ||
val rtpEncoding = sourceDesc?.rtpEncodings?.get(streamIdx) | ||
stream.spatialLayers.forEach { spatialLayer -> | ||
spatialLayer.targetBitratesKbps.forEachIndexed { tlIdx, targetBitrateKbps -> | ||
rtpEncoding?.layers?.find { | ||
// With VP8 simulcast all layers have sid -1 | ||
(it.sid == spatialLayer.id || it.sid == -1) && it.tid == tlIdx | ||
}?.let { layer -> | ||
logger.debug( | ||
"Setting target bitrate for rtpEncoding=$rtpEncoding layer=$layer to " + | ||
"${targetBitrateKbps.kbps} (res=${spatialLayer.res})" | ||
) | ||
layer.targetBitrate = targetBitrateKbps.kbps | ||
spatialLayer.res?.let { res -> | ||
if (layer.height > 0 && layer.height != res.height) { | ||
logger.warn("Updating layer height from ${layer.height} to ${res.height}") | ||
} | ||
layer.height = res.height | ||
layer.frameRate = res.maxFramerate.toDouble() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
override fun trace(f: () -> Unit) {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.