From af2d04bc95c455a2c885594beeba7f12f6682967 Mon Sep 17 00:00:00 2001 From: Jonathan Lennox Date: Mon, 2 Oct 2023 15:19:36 -0400 Subject: [PATCH] Update for ktlint 1.0.0 (ktlint-maven-plugin 3.0.0). --- .editorconfig | 1 + .../kotlin/org/jitsi/nlj/MediaSourceDesc.kt | 19 +- .../main/kotlin/org/jitsi/nlj/PacketInfo.kt | 1 + .../kotlin/org/jitsi/nlj/RtpEncodingDesc.kt | 10 +- .../main/kotlin/org/jitsi/nlj/RtpLayerDesc.kt | 15 +- .../main/kotlin/org/jitsi/nlj/Transceiver.kt | 3 +- .../org/jitsi/nlj/codec/vp8/Vp8Utils.kt | 22 +- .../org/jitsi/nlj/codec/vpx/VpxUtils.kt | 6 +- .../kotlin/org/jitsi/nlj/dtls/DtlsUtils.kt | 10 +- .../org/jitsi/nlj/dtls/TlsClientImpl.kt | 3 +- .../org/jitsi/nlj/rtcp/RtcpRrGenerator.kt | 4 +- .../org/jitsi/nlj/rtp/AudioRtpPacket.kt | 11 +- .../org/jitsi/nlj/rtp/PaddingVideoPacket.kt | 3 +- .../org/jitsi/nlj/rtp/RedAudioRtpPacket.kt | 22 +- .../kotlin/org/jitsi/nlj/rtp/RtpExtensions.kt | 3 +- .../org/jitsi/nlj/rtp/TransportCcEngine.kt | 4 +- .../org/jitsi/nlj/rtp/codec/vp8/Vp8Packet.kt | 1 + .../org/jitsi/nlj/rtp/codec/vp9/Vp9Packet.kt | 7 +- .../kotlin/org/jitsi/nlj/srtp/SrtpUtil.kt | 24 +- .../org/jitsi/nlj/transform/PipelineDsl.kt | 4 +- .../org/jitsi/nlj/transform/node/Node.kt | 3 + .../incoming/IncomingStatisticsTracker.kt | 8 +- .../node/incoming/RemoteBandwidthEstimator.kt | 3 +- .../outgoing/OutgoingStatisticsTracker.kt | 2 +- .../kotlin/org/jitsi/nlj/util/ArrayCache.kt | 47 +- .../kotlin/org/jitsi/nlj/util/Bandwidth.kt | 21 +- .../kotlin/org/jitsi/nlj/util/DataSize.kt | 9 +- .../kotlin/org/jitsi/nlj/util/InstantUtils.kt | 3 +- .../kotlin/org/jitsi/nlj/util/PacketCache.kt | 9 +- .../kotlin/org/jitsi/nlj/util/RateUtils.kt | 1 + .../jitsi/nlj/util/SsrcAssociationStore.kt | 3 +- .../org/jitsi/nlj/util/StreamInformation.kt | 9 +- .../org/jitsi/nlj/MediaSourceDescTest.kt | 10 +- .../module_tests/SrtpTransformerFactory.kt | 3 +- .../org/jitsi/nlj/test_utils/TimelineTest.kt | 3 +- .../node/incoming/SrtpDecryptTest.kt | 3 +- .../node/outgoing/SrtpEncryptTest.kt | 3 +- .../org/jitsi/videobridge/AbstractEndpoint.kt | 13 +- .../kotlin/org/jitsi/videobridge/Endpoint.kt | 12 +- .../kotlin/org/jitsi/videobridge/SsrcCache.kt | 10 +- .../cc/allocation/BandwidthAllocation.kt | 19 +- .../cc/allocation/BandwidthAllocator.kt | 39 +- .../cc/allocation/BitrateController.kt | 5 +- .../cc/allocation/PacketHandler.kt | 4 +- .../videobridge/cc/allocation/Prioritize.kt | 6 +- .../cc/allocation/SingleSourceAllocation.kt | 5 +- .../cc/allocation/VideoConstraints.kt | 3 +- .../vp9/Vp9AdaptiveSourceProjectionContext.kt | 24 +- .../org/jitsi/videobridge/cc/vp9/Vp9Frame.kt | 4 +- .../jitsi/videobridge/cc/vp9/Vp9Picture.kt | 3 +- .../videobridge/cc/vp9/Vp9QualityFilter.kt | 5 +- .../colibri2/Colibri2ConferenceHandler.kt | 5 +- .../load_management/JvbLoadManager.kt | 3 +- .../message/BridgeChannelMessage.kt | 21 +- .../relay/RelayMessageTransport.kt | 3 +- .../videobridge/relay/RelayedEndpoint.kt | 6 +- .../transport/dtls/DtlsTransport.kt | 6 +- .../videobridge/transport/ice/IceTransport.kt | 11 +- .../jitsi/videobridge/util/PayloadTypeUtil.kt | 5 +- .../videobridge/version/JvbVersionService.kt | 8 +- .../websocket/ColibriWebSocketService.kt | 5 +- .../jitsi/videobridge/xmpp/XmppConnection.kt | 9 +- .../EndpointConnectionStatusMonitorTest.kt | 2 +- .../allocation/BitrateControllerPerfTest.kt | 3 +- .../cc/allocation/BitrateControllerTest.kt | 669 +++++++++--------- .../allocation/BitrateControllerTraceTest.kt | 38 +- .../cc/allocation/EffectiveConstraintsTest.kt | 6 +- .../allocation/SingleSourceAllocationTest.kt | 109 +-- .../cc/vp9/Vp9AdaptiveSourceProjectionTest.kt | 39 +- .../cc/vp9/Vp9QualityFilterTest.kt | 9 +- pom.xml | 2 +- .../kotlin/org/jitsi/rtp/UnparsedPacket.kt | 11 +- .../org/jitsi/rtp/extensions/ByteBuffer.kt | 3 +- .../bytearray/ByteArrayExtensions.kt | 3 +- .../org/jitsi/rtp/rtcp/RtcpReportBlock.kt | 9 +- .../kotlin/org/jitsi/rtp/rtcp/RtcpRrPacket.kt | 3 +- .../org/jitsi/rtp/rtcp/RtcpSdesPacket.kt | 9 +- .../kotlin/org/jitsi/rtp/rtcp/RtcpSrPacket.kt | 9 +- .../jitsi/rtp/rtcp/UnsupportedRtcpPacket.kt | 3 +- .../org/jitsi/rtp/rtcp/rtcpfb/RtcpFbPacket.kt | 3 +- .../rtcp/rtcpfb/UnsupportedRtcpFbPacket.kt | 3 +- .../payload_specific_fb/RtcpFbFirPacket.kt | 3 +- .../payload_specific_fb/RtcpFbRembPacket.kt | 6 +- .../transport_layer_fb/tcc/LastChunk.kt | 4 +- .../transport_layer_fb/tcc/RtcpFbTccPacket.kt | 10 +- .../org/jitsi/rtp/rtp/RedPacketParser.kt | 16 +- .../kotlin/org/jitsi/rtp/rtp/RtpHeader.kt | 37 +- .../org/jitsi/rtp/rtp/RtpSequenceNumber.kt | 3 +- .../AbsSendTimeHeaderExtension.kt | 8 +- .../AudioLevelHeaderExtension.kt | 6 +- .../HeaderExtensionHelpers.kt | 22 +- .../header_extensions/TccHeaderExtension.kt | 6 +- .../kotlin/org/jitsi/rtp/util/FieldParsers.kt | 12 +- .../kotlin/org/jitsi/rtp/util/RtpUtils.kt | 59 +- .../extensions/ByteBufferExtensionsTest.kt | 4 +- .../tcc/RtcpFbTccPacketTest.kt | 6 +- .../kotlin/org/jitsi/rtp/rtp/RtpPacketTest.kt | 3 +- 97 files changed, 788 insertions(+), 897 deletions(-) diff --git a/.editorconfig b/.editorconfig index fbe6d50b34..9c60a17f53 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1,5 +1,6 @@ [*.{kt,kts}] max_line_length=120 +ktlint_code_style = intellij_idea # I find trailing commas annoying ktlint_standard_trailing-comma-on-call-site = disabled diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/MediaSourceDesc.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/MediaSourceDesc.kt index 3da9ba9bb9..e09c7f2ee7 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/MediaSourceDesc.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/MediaSourceDesc.kt @@ -87,19 +87,21 @@ class MediaSourceDesc private fun updateLayerCache() { layersById.clear() layersByIndex.clear() - val layers_ = ArrayList() + val tempLayers = ArrayList() for (encoding in rtpEncodings) { for (layer in encoding.layers) { layersById[encoding.encodingId(layer)] = layer layersByIndex[layer.index] = layer - layers_.add(layer) + tempLayers.add(layer) } } - layers = Collections.unmodifiableList(layers_) + layers = Collections.unmodifiableList(tempLayers) } - init { updateLayerCache() } + init { + updateLayerCache() + } /** * Gets the last "stable" bitrate (in bps) of the encoding of the specified @@ -126,15 +128,13 @@ class MediaSourceDesc fun hasRtpLayers(): Boolean = layers.isNotEmpty() @Synchronized - fun numRtpLayers(): Int = - layersByIndex.size + fun numRtpLayers(): Int = layersByIndex.size val primarySSRC: Long get() = rtpEncodings[0].primarySSRC @Synchronized - fun getRtpLayerByQualityIdx(idx: Int): RtpLayerDesc? = - layersByIndex[idx] + fun getRtpLayerByQualityIdx(idx: Int): RtpLayerDesc? = layersByIndex[idx] @Synchronized fun findRtpLayerDesc(videoRtpPacket: VideoRtpPacket): RtpLayerDesc? { @@ -147,8 +147,7 @@ class MediaSourceDesc } @Synchronized - fun findRtpEncodingDesc(ssrc: Long): RtpEncodingDesc? = - rtpEncodings.find { it.matches(ssrc) } + fun findRtpEncodingDesc(ssrc: Long): RtpEncodingDesc? = rtpEncodings.find { it.matches(ssrc) } @Synchronized fun setEncodingLayers(layers: Array, ssrc: Long) { diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/PacketInfo.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/PacketInfo.kt index 0adcd480ac..f23e064045 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/PacketInfo.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/PacketInfo.kt @@ -215,6 +215,7 @@ open class PacketInfo @JvmOverloads constructor( /** * If this is enabled all [Node]s will verify that the payload didn't unexpectedly change. This is expensive. */ + @field:Suppress("ktlint:standard:property-naming") var ENABLE_PAYLOAD_VERIFICATION = false } } diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/RtpEncodingDesc.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/RtpEncodingDesc.kt index 1533589e85..8cfee2f807 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/RtpEncodingDesc.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/RtpEncodingDesc.kt @@ -69,7 +69,9 @@ constructor( require(layer.eid == eid) { "Cannot add layer with EID ${layer.eid} to encoding with EID $eid" } } } - init { validateLayerEids(initialLayers) } + init { + validateLayerEids(initialLayers) + } internal var layers = initialLayers set(newLayers) { @@ -97,8 +99,7 @@ constructor( * rid). This server-side id is used in the layer lookup table that is * maintained in [MediaSourceDesc]. */ - fun encodingId(layer: RtpLayerDesc): Long = - calcEncodingId(primarySSRC, layer.layerId) + fun encodingId(layer: RtpLayerDesc): Long = calcEncodingId(primarySSRC, layer.layerId) /** * Get the secondary ssrc for this encoding that corresponds to the given @@ -162,8 +163,7 @@ constructor( } companion object { - fun calcEncodingId(ssrc: Long, layerId: Int) = - ssrc or (layerId.toLong() shl 32) + fun calcEncodingId(ssrc: Long, layerId: Int) = ssrc or (layerId.toLong() shl 32) } } diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/RtpLayerDesc.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/RtpLayerDesc.kt index 4d52c322e9..2f7019b06d 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/RtpLayerDesc.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/RtpLayerDesc.kt @@ -49,9 +49,9 @@ constructor( /** * The max height of the bitstream that this instance represents. The actual * height may be less due to bad network or system load. + * + * XXX we should be able to sniff the actual height from the RTP packets. */ - // XXX we should be able to sniff the actual height from the RTP - // packets. val height: Int, /** * The max frame rate (in fps) of the bitstream that this instance @@ -287,11 +287,10 @@ constructor( * Get a string description of a layer index. */ @JvmStatic - fun indexString(index: Int): String = - if (index == SUSPENDED_INDEX) { - "SUSP" - } else { - "E${getEidFromIndex(index)}S${getSidFromIndex(index)}T${getTidFromIndex(index)}" - } + fun indexString(index: Int): String = if (index == SUSPENDED_INDEX) { + "SUSP" + } else { + "E${getEidFromIndex(index)}S${getSidFromIndex(index)}T${getTidFromIndex(index)}" + } } } diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/Transceiver.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/Transceiver.kt index afa45577b0..d2302cf63f 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/Transceiver.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/Transceiver.kt @@ -299,8 +299,7 @@ class Transceiver( internalTransformers = internal } - fun setSrtpInformation(srtpTransformers: SrtpTransformers) = - setSrtpInformationInternal(srtpTransformers, false) + fun setSrtpInformation(srtpTransformers: SrtpTransformers) = setSrtpInformationInternal(srtpTransformers, false) /** * Forcibly mute or unmute the incoming audio stream diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/codec/vp8/Vp8Utils.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/codec/vp8/Vp8Utils.kt index ae861dc87e..1f189ef0dc 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/codec/vp8/Vp8Utils.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/codec/vp8/Vp8Utils.kt @@ -79,18 +79,16 @@ class Vp8Utils { } } - fun getTemporalLayerIdOfFrame(vp8Payload: ByteBuffer) = - DePacketizer.VP8PayloadDescriptor.getTemporalLayerIndex( - vp8Payload.array(), - vp8Payload.arrayOffset(), - vp8Payload.limit() - ) + fun getTemporalLayerIdOfFrame(vp8Payload: ByteBuffer) = DePacketizer.VP8PayloadDescriptor.getTemporalLayerIndex( + vp8Payload.array(), + vp8Payload.arrayOffset(), + vp8Payload.limit() + ) - fun getTemporalLayerIdOfFrame(vp8Packet: RtpPacket) = - DePacketizer.VP8PayloadDescriptor.getTemporalLayerIndex( - vp8Packet.buffer, - vp8Packet.payloadOffset, - vp8Packet.payloadLength - ) + fun getTemporalLayerIdOfFrame(vp8Packet: RtpPacket) = DePacketizer.VP8PayloadDescriptor.getTemporalLayerIndex( + vp8Packet.buffer, + vp8Packet.payloadOffset, + vp8Packet.payloadLength + ) } } diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/codec/vpx/VpxUtils.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/codec/vpx/VpxUtils.kt index 09a670af30..bac5d7c1cc 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/codec/vpx/VpxUtils.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/codec/vpx/VpxUtils.kt @@ -54,8 +54,7 @@ class VpxUtils { * @return the extended picture ID resulting from doing "start + delta" */ @JvmStatic - fun applyExtendedPictureIdDelta(start: Int, delta: Int): Int = - (start + delta) and EXTENDED_PICTURE_ID_MASK + fun applyExtendedPictureIdDelta(start: Int, delta: Int): Int = (start + delta) and EXTENDED_PICTURE_ID_MASK /** * Returns the delta between two VP8/VP9 Tl0PicIdx values, taking into account @@ -86,7 +85,6 @@ class VpxUtils { * @return the Tl0PicIdx resulting from doing "start + delta" */ @JvmStatic - fun applyTl0PicIdxDelta(start: Int, delta: Int): Int = - (start + delta) and TL0PICIDX_MASK + fun applyTl0PicIdxDelta(start: Int, delta: Int): Int = (start + delta) and TL0PICIDX_MASK } } diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/dtls/DtlsUtils.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/dtls/DtlsUtils.kt index ce41481594..c1259c3ba1 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/dtls/DtlsUtils.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/dtls/DtlsUtils.kt @@ -100,10 +100,7 @@ class DtlsUtils { * * TODO: make the algorithm dynamic (passed in) to support older dtls versions/clients */ - private fun generateCertificate( - subject: X500Name, - keyPair: KeyPair - ): Certificate { + private fun generateCertificate(subject: X500Name, keyPair: KeyPair): Certificate { val now = System.currentTimeMillis() val startDate = Date(now - Duration.ofDays(1).toMillis()) val expiryDate = Date(now + Duration.ofDays(7).toMillis()) @@ -182,10 +179,7 @@ class DtlsUtils { * and validate against the fingerprints presented by the remote endpoint * via the signaling path. */ - private fun verifyAndValidateCertificate( - certificate: Certificate, - remoteFingerprints: Map - ) { + private fun verifyAndValidateCertificate(certificate: Certificate, remoteFingerprints: Map) { // RFC 4572 "Connection-Oriented Media Transport over the Transport // Layer Security (TLS) Protocol in the Session Description Protocol // (SDP)" defines that "[a] certificate fingerprint MUST be computed diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/dtls/TlsClientImpl.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/dtls/TlsClientImpl.kt index 8ee1c76ba0..10423a5087 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/dtls/TlsClientImpl.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/dtls/TlsClientImpl.kt @@ -169,8 +169,7 @@ class TlsClientImpl( logger.cinfo { "Negotiated DTLS version $serverVersion" } } - override fun getSupportedVersions(): Array = - arrayOf(ProtocolVersion.DTLSv12) + override fun getSupportedVersions(): Array = arrayOf(ProtocolVersion.DTLSv12) override fun notifyAlertRaised(alertLevel: Short, alertDescription: Short, message: String?, cause: Throwable?) = logger.notifyAlertRaised(alertLevel, alertDescription, message, cause) diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtcp/RtcpRrGenerator.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtcp/RtcpRrGenerator.kt index 5146541621..18aa740e4d 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtcp/RtcpRrGenerator.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtcp/RtcpRrGenerator.kt @@ -127,7 +127,9 @@ class RtcpRrGenerator( when (packets.size) { 0 -> {} 1 -> rtcpSender(packets.first()) - else -> for (packet in CompoundRtcpPacket.createWithMtu(packets)) { rtcpSender(packet) } + else -> for (packet in CompoundRtcpPacket.createWithMtu(packets)) { + rtcpSender(packet) + } } backgroundExecutor.schedule(this::doWork, reportingInterval) } diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/AudioRtpPacket.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/AudioRtpPacket.kt index a425a3c003..65c1269da6 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/AudioRtpPacket.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/AudioRtpPacket.kt @@ -23,10 +23,9 @@ open class AudioRtpPacket( length: Int ) : RtpPacket(buffer, offset, length) { - override fun clone(): AudioRtpPacket = - AudioRtpPacket( - cloneBuffer(BYTES_TO_LEAVE_AT_START_OF_PACKET), - BYTES_TO_LEAVE_AT_START_OF_PACKET, - length - ) + override fun clone(): AudioRtpPacket = AudioRtpPacket( + cloneBuffer(BYTES_TO_LEAVE_AT_START_OF_PACKET), + BYTES_TO_LEAVE_AT_START_OF_PACKET, + length + ) } diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/PaddingVideoPacket.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/PaddingVideoPacket.kt index aa8abb2b5b..12a4dbfbd8 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/PaddingVideoPacket.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/PaddingVideoPacket.kt @@ -25,8 +25,7 @@ class PaddingVideoPacket private constructor( length: Int ) : VideoRtpPacket(buffer, offset, length) { - override fun clone(): PaddingVideoPacket = - throw NotImplementedError("clone() not supported for padding packets.") + override fun clone(): PaddingVideoPacket = throw NotImplementedError("clone() not supported for padding packets.") companion object { /** diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/RedAudioRtpPacket.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/RedAudioRtpPacket.kt index 6da1e747c0..ff0e028561 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/RedAudioRtpPacket.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/RedAudioRtpPacket.kt @@ -33,19 +33,17 @@ class RedAudioRtpPacket( removed = true } - fun removeRedAndGetRedundancyPackets(): List = - if (removed) { - throw IllegalStateException("RED encapsulation already removed.") - } else { - parser.decapsulate(this, parseRedundancy = true).also { removed = true } - } + fun removeRedAndGetRedundancyPackets(): List = if (removed) { + throw IllegalStateException("RED encapsulation already removed.") + } else { + parser.decapsulate(this, parseRedundancy = true).also { removed = true } + } - override fun clone(): RedAudioRtpPacket = - RedAudioRtpPacket( - cloneBuffer(BYTES_TO_LEAVE_AT_START_OF_PACKET), - BYTES_TO_LEAVE_AT_START_OF_PACKET, - length - ) + override fun clone(): RedAudioRtpPacket = RedAudioRtpPacket( + cloneBuffer(BYTES_TO_LEAVE_AT_START_OF_PACKET), + BYTES_TO_LEAVE_AT_START_OF_PACKET, + length + ) companion object { val parser = RedPacketParser(::AudioRtpPacket) diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/RtpExtensions.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/RtpExtensions.kt index dc730843ee..1e869642ec 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/RtpExtensions.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/RtpExtensions.kt @@ -100,7 +100,6 @@ enum class RtpExtensionType(val uri: String) { companion object { private val uriMap = RtpExtensionType.values().associateBy(RtpExtensionType::uri) - fun createFromUri(uri: String): RtpExtensionType? = - uriMap.getOrDefault(uri, null) + fun createFromUri(uri: String): RtpExtensionType? = uriMap.getOrDefault(uri, null) } } diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/TransportCcEngine.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/TransportCcEngine.kt index a2b648ce06..8e43a057e7 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/TransportCcEngine.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/TransportCcEngine.kt @@ -256,7 +256,9 @@ class TransportCcEngine( * [PacketDetailState] is the state of a [PacketDetail] */ private enum class PacketDetailState { - Unreported, ReportedLost, ReportedReceived + Unreported, + ReportedLost, + ReportedReceived } /** diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/codec/vp8/Vp8Packet.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/codec/vp8/Vp8Packet.kt index ca822b4250..93ea7b741a 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/codec/vp8/Vp8Packet.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/codec/vp8/Vp8Packet.kt @@ -79,6 +79,7 @@ class Vp8Packet private constructor( val hasTL0PICIDX = DePacketizer.VP8PayloadDescriptor.hasTL0PICIDX(buffer, payloadOffset, payloadLength) + @field:Suppress("ktlint:standard:property-naming") private var _TL0PICIDX = TL0PICIDX ?: DePacketizer.VP8PayloadDescriptor.getTL0PICIDX(buffer, payloadOffset, payloadLength) diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/codec/vp9/Vp9Packet.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/codec/vp9/Vp9Packet.kt index 52038026d1..bacff0b341 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/codec/vp9/Vp9Packet.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/rtp/codec/vp9/Vp9Packet.kt @@ -94,6 +94,7 @@ class Vp9Packet private constructor( val isInterPicturePredicted = DePacketizer.VP9PayloadDescriptor.isInterPicturePredicted(buffer, payloadOffset, payloadLength) + @field:Suppress("ktlint:standard:property-naming") private var _TL0PICIDX = TL0PICIDX ?: DePacketizer.VP9PayloadDescriptor.getTL0PICIDX(buffer, payloadOffset, payloadLength) @@ -153,10 +154,8 @@ class Vp9Packet private constructor( val usesInterLayerDependency: Boolean = DePacketizer.VP9PayloadDescriptor.usesInterLayerDependency(buffer, payloadOffset, payloadLength) - fun getScalabilityStructure( - eid: Int = 0, - baseFrameRate: Double = 30.0 - ) = Companion.getScalabilityStructure(buffer, payloadOffset, payloadLength, ssrc, eid, baseFrameRate) + fun getScalabilityStructure(eid: Int = 0, baseFrameRate: Double = 30.0) = + Companion.getScalabilityStructure(buffer, payloadOffset, payloadLength, ssrc, eid, baseFrameRate) val scalabilityStructureNumSpatial: Int get() { diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/srtp/SrtpUtil.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/srtp/SrtpUtil.kt index 1eefb1bff8..550d3a0365 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/srtp/SrtpUtil.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/srtp/SrtpUtil.kt @@ -34,12 +34,24 @@ class SrtpUtil { fun getSrtpProtectionProfileFromName(profileName: String): Int { return when (profileName) { - "SRTP_AES128_CM_HMAC_SHA1_80" -> { SRTPProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_80 } - "SRTP_AES128_CM_HMAC_SHA1_32" -> { SRTPProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_32 } - "SRTP_NULL_HMAC_SHA1_32" -> { SRTPProtectionProfile.SRTP_NULL_HMAC_SHA1_32 } - "SRTP_NULL_HMAC_SHA1_80" -> { SRTPProtectionProfile.SRTP_NULL_HMAC_SHA1_80 } - "SRTP_AEAD_AES_128_GCM" -> { SRTPProtectionProfile.SRTP_AEAD_AES_128_GCM } - "SRTP_AEAD_AES_256_GCM" -> { SRTPProtectionProfile.SRTP_AEAD_AES_256_GCM } + "SRTP_AES128_CM_HMAC_SHA1_80" -> { + SRTPProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_80 + } + "SRTP_AES128_CM_HMAC_SHA1_32" -> { + SRTPProtectionProfile.SRTP_AES128_CM_HMAC_SHA1_32 + } + "SRTP_NULL_HMAC_SHA1_32" -> { + SRTPProtectionProfile.SRTP_NULL_HMAC_SHA1_32 + } + "SRTP_NULL_HMAC_SHA1_80" -> { + SRTPProtectionProfile.SRTP_NULL_HMAC_SHA1_80 + } + "SRTP_AEAD_AES_128_GCM" -> { + SRTPProtectionProfile.SRTP_AEAD_AES_128_GCM + } + "SRTP_AEAD_AES_256_GCM" -> { + SRTPProtectionProfile.SRTP_AEAD_AES_256_GCM + } else -> throw IllegalArgumentException("Unsupported SRTP protection profile: $profileName") } } diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/PipelineDsl.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/PipelineDsl.kt index 47acd7f473..c276353079 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/PipelineDsl.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/PipelineDsl.kt @@ -48,7 +48,9 @@ class PipelineBuilder { } fun node(node: Node, condition: () -> Boolean = { true }) { - if (condition()) { addNode(node) } + if (condition()) { + addNode(node) + } } /** diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/node/Node.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/node/Node.kt index 7e75e9d719..a2ece3eacd 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/node/Node.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/node/Node.kt @@ -130,7 +130,10 @@ sealed class Node( abstract fun trace(f: () -> Unit) companion object { + @field:Suppress("ktlint:standard:property-naming") var TRACE_ENABLED = false + + @field:Suppress("ktlint:standard:property-naming") var PLUGINS_ENABLED = false // 'Plugins' are observers which, when enabled, will be passed every packet that passes through diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/node/incoming/IncomingStatisticsTracker.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/node/incoming/IncomingStatisticsTracker.kt index a9136d7af7..e2059a1e94 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/node/incoming/IncomingStatisticsTracker.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/node/incoming/IncomingStatisticsTracker.kt @@ -99,7 +99,7 @@ class IncomingStatisticsSnapshot( val ssrcStats: Map ) { fun toJson(): OrderedJsonObject = OrderedJsonObject().apply { - ssrcStats.forEach() { (ssrc, snapshot) -> + ssrcStats.forEach { (ssrc, snapshot) -> put(ssrc, snapshot.toJson()) } } @@ -233,11 +233,7 @@ class IncomingSsrcStats( * raw RTP timestamp, but the 'translated' timestamp which is a function of the RTP timestamp and the clockrate) * and was received at [packetReceivedTime] */ - fun packetReceived( - packet: RtpPacket, - packetSentTimestamp: Instant, - packetReceivedTime: Instant - ) { + fun packetReceived(packet: RtpPacket, packetSentTimestamp: Instant, packetReceivedTime: Instant) { val packetSequenceNumber = packet.sequenceNumber synchronized(statsLock) { activitySinceLastSnapshot = true diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/node/incoming/RemoteBandwidthEstimator.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/node/incoming/RemoteBandwidthEstimator.kt index 3d94ec3cd0..323961c198 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/node/incoming/RemoteBandwidthEstimator.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/node/incoming/RemoteBandwidthEstimator.kt @@ -71,7 +71,8 @@ class RemoteBandwidthEstimator( Collections.synchronizedSet( LRUCache.lruSet( MAX_SSRCS, - true // accessOrder + // accessOrder + true ) ) private var numRembsCreated = 0 diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/node/outgoing/OutgoingStatisticsTracker.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/node/outgoing/OutgoingStatisticsTracker.kt index 2f2c56403a..d2d07bec5f 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/node/outgoing/OutgoingStatisticsTracker.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/transform/node/outgoing/OutgoingStatisticsTracker.kt @@ -84,7 +84,7 @@ class OutgoingStatisticsSnapshot( val ssrcStats: Map ) { fun toJson() = OrderedJsonObject().apply { - ssrcStats.forEach() { (ssrc, snapshot) -> + ssrcStats.forEach { (ssrc, snapshot) -> put(ssrc, snapshot.toJson()) } } diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/ArrayCache.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/ArrayCache.kt index 958a8874c0..f68ed72874 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/ArrayCache.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/ArrayCache.kt @@ -69,21 +69,19 @@ open class ArrayCache( /** * Inserts an item with a specific index in the cache. Stores a copy. */ - fun insertItem(item: T, index: Int, timeAdded: Long): Boolean = - if (synchronize) { - synchronized(syncRoot) { - doInsert(item, index, timeAdded) - } - } else { + fun insertItem(item: T, index: Int, timeAdded: Long): Boolean = if (synchronize) { + synchronized(syncRoot) { doInsert(item, index, timeAdded) } + } else { + doInsert(item, index, timeAdded) + } /** * Inserts an item with a specific index in the cache, computing time * from [clock]. Stores a copy. */ - fun insertItem(item: T, index: Int): Boolean = - insertItem(item, index, clock.millis()) + fun insertItem(item: T, index: Int): Boolean = insertItem(item, index, clock.millis()) private fun doInsert(item: T, index: Int, timeAdded: Long): Boolean { val diff = if (head == -1) -1 else index - cache[head].index @@ -187,14 +185,13 @@ open class ArrayCache( /** * Updates the [timeAdded] value of an item with a particular index, if it is in the cache. */ - protected fun updateTimeAdded(index: Int, timeAdded: Long) = - if (synchronize) { - synchronized(syncRoot) { - doUpdateTimeAdded(index, timeAdded) - } - } else { + protected fun updateTimeAdded(index: Int, timeAdded: Long) = if (synchronize) { + synchronized(syncRoot) { doUpdateTimeAdded(index, timeAdded) } + } else { + doUpdateTimeAdded(index, timeAdded) + } private fun doUpdateTimeAdded(index: Int, timeAdded: Long) { if (head == -1 || index > cache[head].index) { @@ -213,14 +210,13 @@ open class ArrayCache( * iteration and returns. Note that if the caller must clone the item on their own if they want to keep or modify * it in any way. */ - fun forEachDescending(predicate: (T) -> Boolean) = - if (synchronize) { - synchronized(syncRoot) { - doForEachDescending(predicate) - } - } else { + fun forEachDescending(predicate: (T) -> Boolean) = if (synchronize) { + synchronized(syncRoot) { doForEachDescending(predicate) } + } else { + doForEachDescending(predicate) + } private fun doForEachDescending(predicate: (T) -> Boolean) { if (head == -1) return @@ -240,14 +236,13 @@ open class ArrayCache( /** * Removes all items stored in the cache, calling [discardItem] for each one. */ - fun flush() = - if (synchronize) { - synchronized(syncRoot) { - doFlush() - } - } else { + fun flush() = if (synchronize) { + synchronized(syncRoot) { doFlush() } + } else { + doFlush() + } private fun doFlush() { for (container in cache) { diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/Bandwidth.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/Bandwidth.kt index 5790a51066..f1d7c33200 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/Bandwidth.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/Bandwidth.kt @@ -30,11 +30,9 @@ value class Bandwidth(val bps: Double) : Comparable { val mbps: Double get() = bps / (1000 * 1000) - operator fun minus(other: Bandwidth): Bandwidth = - Bandwidth(bps - other.bps) + operator fun minus(other: Bandwidth): Bandwidth = Bandwidth(bps - other.bps) - operator fun plus(other: Bandwidth): Bandwidth = - Bandwidth(bps + other.bps) + operator fun plus(other: Bandwidth): Bandwidth = Bandwidth(bps + other.bps) /** * For multiplication, we support multiplying against @@ -45,25 +43,20 @@ value class Bandwidth(val bps: Double) : Comparable { * * to reduce 'currentBandwidth' by 5% */ - operator fun times(other: Double): Bandwidth = - Bandwidth(bps * other) + operator fun times(other: Double): Bandwidth = Bandwidth(bps * other) - operator fun times(other: Int): Bandwidth = - Bandwidth(bps * other) + operator fun times(other: Int): Bandwidth = Bandwidth(bps * other) /** * For division, we support both dividing by * a normal number (giving a bandwidth), and dividing * by another bandwidth, giving a number */ - operator fun div(other: Double): Bandwidth = - Bandwidth(bps / other) + operator fun div(other: Double): Bandwidth = Bandwidth(bps / other) - operator fun div(other: Int): Bandwidth = - Bandwidth(bps / other) + operator fun div(other: Int): Bandwidth = Bandwidth(bps / other) - operator fun div(other: Bandwidth): Double = - bps / other.bps + operator fun div(other: Bandwidth): Double = bps / other.bps override fun compareTo(other: Bandwidth): Int = sign(bps - other.bps).toInt() diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/DataSize.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/DataSize.kt index 66cc539bfa..4cfab6ff4e 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/DataSize.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/DataSize.kt @@ -32,22 +32,19 @@ class DataSize( val kiloBytes: Double = bytes / 1000.0 val megaBytes: Double = kiloBytes / 1000.0 - operator fun minus(other: DataSize): DataSize = - DataSize(bits - other.bits) + operator fun minus(other: DataSize): DataSize = DataSize(bits - other.bits) operator fun minusAssign(other: DataSize) { bits -= other.bits } - operator fun plus(other: DataSize): DataSize = - DataSize(bits + other.bits) + operator fun plus(other: DataSize): DataSize = DataSize(bits + other.bits) operator fun plusAssign(other: DataSize) { bits += other.bits } - operator fun times(other: Int): DataSize = - DataSize(bits * other) + operator fun times(other: Int): DataSize = DataSize(bits * other) operator fun timesAssign(other: Int) { bits *= other diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/InstantUtils.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/InstantUtils.kt index 4507f75628..8d1701e41b 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/InstantUtils.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/InstantUtils.kt @@ -18,5 +18,4 @@ package org.jitsi.nlj.util import java.time.Instant -fun latest(vararg instants: Instant): Instant = - instants.reduce { a, b -> maxOf(a, b) } +fun latest(vararg instants: Instant): Instant = instants.reduce { a, b -> maxOf(a, b) } diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/PacketCache.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/PacketCache.kt index a9a3ed426a..9d5a5ff7a9 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/PacketCache.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/PacketCache.kt @@ -39,9 +39,12 @@ class PacketCache( LinkedHashMap( // These are the default values of initialCapacity and loadFactor - we have to set them to be able to set // accessOrder - 16, // initialCapacity - 0.75F, // loadFactor - true // accessOrder + // initialCapacity + 16, + // loadFactor + 0.75F, + // accessOrder + true ) ) diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/RateUtils.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/RateUtils.kt index ece26c21dc..ace6beeb99 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/RateUtils.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/RateUtils.kt @@ -36,6 +36,7 @@ infix fun DataSize.atRate(bw: Bandwidth): Duration { fun howMuchCanISendAtRate(bw: Bandwidth): Bandwidth = bw +@Suppress("ktlint:standard:function-naming") infix fun Bandwidth.`in`(time: Duration): DataSize { return DataSize((bps * (time.seconds + time.nano / 1e9)).toLong()) } diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/SsrcAssociationStore.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/SsrcAssociationStore.kt index f1ef149ec7..2a8799d459 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/SsrcAssociationStore.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/SsrcAssociationStore.kt @@ -59,8 +59,7 @@ class SsrcAssociationStore( ssrcAssociationsBySecondarySsrc = ssrcAssociations.associateBy(SsrcAssociation::secondarySsrc) } - fun getPrimarySsrc(secondarySsrc: Long): Long? = - ssrcAssociationsBySecondarySsrc[secondarySsrc]?.primarySsrc + fun getPrimarySsrc(secondarySsrc: Long): Long? = ssrcAssociationsBySecondarySsrc[secondarySsrc]?.primarySsrc fun getSecondarySsrc(primarySsrc: Long, associationType: SsrcAssociationType): Long? = ssrcAssociationsByPrimarySsrc[primarySsrc]?.find { it.type == associationType }?.secondarySsrc diff --git a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/StreamInformation.kt b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/StreamInformation.kt index fbb99da5d5..23de158830 100644 --- a/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/StreamInformation.kt +++ b/jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/util/StreamInformation.kt @@ -205,8 +205,7 @@ class StreamInformationStoreImpl : StreamInformationStore { // NOTE(brian): Currently, we only have a use case to do a mapping of // secondary -> primary for local SSRCs and primary -> secondary for // remote SSRCs - override fun getLocalPrimarySsrc(secondarySsrc: Long): Long? = - localSsrcAssociations.getPrimarySsrc(secondarySsrc) + override fun getLocalPrimarySsrc(secondarySsrc: Long): Long? = localSsrcAssociations.getPrimarySsrc(secondarySsrc) override fun getRemoteSecondarySsrc(primarySsrc: Long, associationType: SsrcAssociationType): Long? = remoteSsrcAssociations.getSecondarySsrc(primarySsrc, associationType) @@ -218,11 +217,9 @@ class StreamInformationStoreImpl : StreamInformationStore { } } - override fun addReceiveSsrc(ssrc: Long, mediaType: MediaType) = - receiveSsrcStore.addReceiveSsrc(ssrc, mediaType) + override fun addReceiveSsrc(ssrc: Long, mediaType: MediaType) = receiveSsrcStore.addReceiveSsrc(ssrc, mediaType) - override fun removeReceiveSsrc(ssrc: Long) = - receiveSsrcStore.removeReceiveSsrc(ssrc) + override fun removeReceiveSsrc(ssrc: Long) = receiveSsrcStore.removeReceiveSsrc(ssrc) override fun getNodeStats(): NodeStatsBlock = NodeStatsBlock("Stream Information Store").apply { addBlock( diff --git a/jitsi-media-transform/src/test/kotlin/org/jitsi/nlj/MediaSourceDescTest.kt b/jitsi-media-transform/src/test/kotlin/org/jitsi/nlj/MediaSourceDescTest.kt index 25f144afe1..b1526978bc 100644 --- a/jitsi-media-transform/src/test/kotlin/org/jitsi/nlj/MediaSourceDescTest.kt +++ b/jitsi-media-transform/src/test/kotlin/org/jitsi/nlj/MediaSourceDescTest.kt @@ -113,8 +113,7 @@ class MediaSourceDescTest : ShouldSpec() { * @return the subjective quality index of the flow specified in the * arguments. */ -private fun idx(spatialIdx: Int, temporalIdx: Int, temporalLen: Int) = - spatialIdx * temporalLen + temporalIdx +private fun idx(spatialIdx: Int, temporalIdx: Int, temporalLen: Int) = spatialIdx * temporalLen + temporalIdx /* * Creates layers for an encoding. @@ -124,12 +123,7 @@ private fun idx(spatialIdx: Int, temporalIdx: Int, temporalLen: Int) = * @param height the maximum height of the top spatial layer * @return an array that holds the layer descriptions. */ -private fun createRTPLayerDescs( - spatialLen: Int, - temporalLen: Int, - encodingIdx: Int, - height: Int -): Array { +private fun createRTPLayerDescs(spatialLen: Int, temporalLen: Int, encodingIdx: Int, height: Int): Array { val rtpLayers = arrayOfNulls(spatialLen * temporalLen) for (spatialIdx in 0 until spatialLen) { var frameRate = 30.toDouble() / (1 shl temporalLen - 1) diff --git a/jitsi-media-transform/src/test/kotlin/org/jitsi/nlj/module_tests/SrtpTransformerFactory.kt b/jitsi-media-transform/src/test/kotlin/org/jitsi/nlj/module_tests/SrtpTransformerFactory.kt index 2bc1e2f9a0..4818d9516b 100644 --- a/jitsi-media-transform/src/test/kotlin/org/jitsi/nlj/module_tests/SrtpTransformerFactory.kt +++ b/jitsi-media-transform/src/test/kotlin/org/jitsi/nlj/module_tests/SrtpTransformerFactory.kt @@ -28,7 +28,8 @@ class SrtpTransformerFactory { srtpData.srtpProfileInformation, srtpData.keyingMaterial, srtpData.tlsRole, - cryptex = false, // TODO: add tests for the cryptex=true case + // TODO: add tests for the cryptex=true case + cryptex = false, StdoutLogger() ) } diff --git a/jitsi-media-transform/src/test/kotlin/org/jitsi/nlj/test_utils/TimelineTest.kt b/jitsi-media-transform/src/test/kotlin/org/jitsi/nlj/test_utils/TimelineTest.kt index 5f43c31f0c..4f7a07efb2 100644 --- a/jitsi-media-transform/src/test/kotlin/org/jitsi/nlj/test_utils/TimelineTest.kt +++ b/jitsi-media-transform/src/test/kotlin/org/jitsi/nlj/test_utils/TimelineTest.kt @@ -40,5 +40,4 @@ internal class TimelineTest(private val clock: FakeClock) { } } -internal fun timeline(clock: FakeClock, block: TimelineTest.() -> Unit): TimelineTest = - TimelineTest(clock).apply(block) +internal fun timeline(clock: FakeClock, block: TimelineTest.() -> Unit): TimelineTest = TimelineTest(clock).apply(block) diff --git a/jitsi-media-transform/src/test/kotlin/org/jitsi/nlj/transform/node/incoming/SrtpDecryptTest.kt b/jitsi-media-transform/src/test/kotlin/org/jitsi/nlj/transform/node/incoming/SrtpDecryptTest.kt index e28bc9ea4c..736d463866 100644 --- a/jitsi-media-transform/src/test/kotlin/org/jitsi/nlj/transform/node/incoming/SrtpDecryptTest.kt +++ b/jitsi-media-transform/src/test/kotlin/org/jitsi/nlj/transform/node/incoming/SrtpDecryptTest.kt @@ -36,7 +36,8 @@ internal class SrtpDecryptTest : ShouldSpec() { SrtpSample.srtpProfileInformation, SrtpSample.keyingMaterial.array(), SrtpSample.tlsRole, - cryptex = false, // TODO: add tests for cryptex case + // TODO: add tests for cryptex case + cryptex = false, StdoutLogger() ) diff --git a/jitsi-media-transform/src/test/kotlin/org/jitsi/nlj/transform/node/outgoing/SrtpEncryptTest.kt b/jitsi-media-transform/src/test/kotlin/org/jitsi/nlj/transform/node/outgoing/SrtpEncryptTest.kt index c6db04be94..3496090d8e 100644 --- a/jitsi-media-transform/src/test/kotlin/org/jitsi/nlj/transform/node/outgoing/SrtpEncryptTest.kt +++ b/jitsi-media-transform/src/test/kotlin/org/jitsi/nlj/transform/node/outgoing/SrtpEncryptTest.kt @@ -41,7 +41,8 @@ internal class SrtpEncryptTest : ShouldSpec() { SrtpSample.srtpProfileInformation, SrtpSample.keyingMaterial.array(), SrtpSample.tlsRole, - cryptex = false, // TODO: add tests for cryptex case + // TODO: add tests for cryptex case + cryptex = false, StdoutLogger() ) diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/AbstractEndpoint.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/AbstractEndpoint.kt index 531dc1acb0..b52f121552 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/AbstractEndpoint.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/AbstractEndpoint.kt @@ -154,10 +154,9 @@ abstract class AbstractEndpoint protected constructor( protected val mediaSource: MediaSourceDesc? get() = mediaSources.firstOrNull() - fun findMediaSourceDesc(sourceName: String): MediaSourceDesc? = - mediaSources.firstOrNull { - sourceName == it.sourceName - } + fun findMediaSourceDesc(sourceName: String): MediaSourceDesc? = mediaSources.firstOrNull { + sourceName == it.sourceName + } fun addEventHandler(eventHandler: EventHandler) { eventEmitter.addHandler(eventHandler) @@ -296,11 +295,7 @@ abstract class AbstractEndpoint protected constructor( * @param sourceName the name of the media source for which the constraints are to be applied. * @param newVideoConstraints the video constraints that the receiver wishes to receive. */ - fun addReceiver( - receiverId: String, - sourceName: String, - newVideoConstraints: VideoConstraints - ) { + fun addReceiver(receiverId: String, sourceName: String, newVideoConstraints: VideoConstraints) { val sourceConstraints = receiverVideoConstraints.computeIfAbsent(sourceName) { ReceiverConstraintsMap() } val oldVideoConstraints = sourceConstraints.put(receiverId, newVideoConstraints) if (oldVideoConstraints == null || oldVideoConstraints != newVideoConstraints) { diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/Endpoint.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/Endpoint.kt index 9718a5f71a..011146144e 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/Endpoint.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/Endpoint.kt @@ -216,8 +216,7 @@ class Endpoint @JvmOverloads constructor( newEffectiveConstraints: EffectiveConstraintsMap, ) = this@Endpoint.effectiveVideoConstraintsChanged(oldEffectiveConstraints, newEffectiveConstraints) - override fun keyframeNeeded(endpointId: String?, ssrc: Long) = - conference.requestKeyframe(endpointId, ssrc) + override fun keyframeNeeded(endpointId: String?, ssrc: Long) = conference.requestKeyframe(endpointId, ssrc) }, { getOrderedEndpoints() }, diagnosticContext, @@ -242,8 +241,7 @@ class Endpoint @JvmOverloads constructor( /** * Gets the endpoints in the conference in LastN order, with this {@link Endpoint} removed. */ - fun getOrderedEndpoints(): List = - conference.orderedEndpoints.filterNot { it == this } + fun getOrderedEndpoints(): List = conference.orderedEndpoints.filterNot { it == this } /** * Listen for RTT updates from [transceiver] and update the ICE stats the first time an RTT is available. Note that @@ -601,7 +599,7 @@ class Endpoint @JvmOverloads constructor( } /** - * Create an SCTP connection for this Endpoint. If [openDataChannelLocally] is true, + * Create an SCTP connection for this Endpoint. If [OPEN_DATA_CHANNEL_LOCALLY] is true, * we will create the data channel locally, otherwise we will wait for the remote side * to open it. */ @@ -632,7 +630,7 @@ class Endpoint @JvmOverloads constructor( messageTransport.setDataChannel(dataChannel) } dataChannelHandler.setDataChannelStack(dataChannelStack!!) - if (openDataChannelLocally) { + if (OPEN_DATA_CHANNEL_LOCALLY) { // This logic is for opening the data channel locally logger.info("Will open the data channel.") val dataChannel = dataChannelStack!!.createDataChannel( @@ -1170,7 +1168,7 @@ class Endpoint @JvmOverloads constructor( * Whether or not the bridge should be the peer which opens the data channel * (as opposed to letting the far peer/client open it). */ - private const val openDataChannelLocally = false + private const val OPEN_DATA_CHANNEL_LOCALLY = false /** * Count the number of dropped packets and exceptions. diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/SsrcCache.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/SsrcCache.kt index 297693bc0f..5189d7f391 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/SsrcCache.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/SsrcCache.kt @@ -220,7 +220,9 @@ class SendSource(val props: SourceDesc, val send1: SendSsrc, val send2: SendSsrc * Fix SSRC and timestamps in an RTCP packet. * For packets in the same direction as media flow; feedback messages handled separately. */ - fun rewriteRtcp(packet: RtcpPacket) { getSender(packet.senderSsrc).rewriteRtcp(packet) } + fun rewriteRtcp(packet: RtcpPacket) { + getSender(packet.senderSsrc).rewriteRtcp(packet) + } /** * {@inheritDoc} @@ -275,7 +277,8 @@ abstract class SsrcCache(val size: Int, val ep: SsrcRewriter, val parentLogger: */ private val sendSources = LRUCache( size, - true // accessOrder + // accessOrder + true ) /** @@ -569,8 +572,7 @@ class VideoSsrcCache(size: Int, ep: SsrcRewriter, parentLogger: Logger) : /** * {@inheritDoc} */ - override fun findSourceProps(ssrc: Long): SourceDesc? = - ep.findVideoSourceProps(ssrc)?.let { SourceDesc(it) } + override fun findSourceProps(ssrc: Long): SourceDesc? = ep.findVideoSourceProps(ssrc)?.let { SourceDesc(it) } /** * {@inheritDoc} diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/BandwidthAllocation.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/BandwidthAllocation.kt index c029bdcfbf..ebca3fd157 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/BandwidthAllocation.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/BandwidthAllocation.kt @@ -40,17 +40,16 @@ class BandwidthAllocation @JvmOverloads constructor( /** * Whether the two allocations have the same endpoints and same layers. */ - fun isTheSameAs(other: BandwidthAllocation) = - allocations.size == other.allocations.size && - oversending == other.oversending && - allocations.all { allocation -> - other.allocations.any { otherAllocation -> - allocation.endpointId == otherAllocation.endpointId && - allocation.mediaSource?.primarySSRC == - otherAllocation.mediaSource?.primarySSRC && - allocation.targetLayer?.index == otherAllocation.targetLayer?.index - } + fun isTheSameAs(other: BandwidthAllocation) = allocations.size == other.allocations.size && + oversending == other.oversending && + allocations.all { allocation -> + other.allocations.any { otherAllocation -> + allocation.endpointId == otherAllocation.endpointId && + allocation.mediaSource?.primarySSRC == + otherAllocation.mediaSource?.primarySSRC && + allocation.targetLayer?.index == otherAllocation.targetLayer?.index } + } override fun toString(): String = "oversending=$oversending " + allocations.joinToString() diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/BandwidthAllocator.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/BandwidthAllocator.kt index 4d4eb0341e..b26e141600 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/BandwidthAllocator.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/BandwidthAllocator.kt @@ -297,26 +297,25 @@ internal class BandwidthAllocator( } @Synchronized - private fun createAllocations( - conferenceMediaSources: List - ): List = conferenceMediaSources.map { source -> - SingleSourceAllocation( - source.owner, - source, - // Note that we use the effective constraints and not the receiver's constraints - // directly. This means we never even try to allocate bitrate to sources "outside - // lastN". For example, if LastN=1 and the first endpoint sends a non-scalable - // stream with bitrate higher that the available bandwidth, we will forward no - // video at all instead of going to the second endpoint in the list. - // I think this is not desired behavior. However, it is required for the "effective - // constraints" to work as designed. - effectiveConstraints[source]!!, - allocationSettings.onStageSources.contains(source.sourceName), - diagnosticContext, - clock, - logger - ) - }.toList() + private fun createAllocations(conferenceMediaSources: List): List = + conferenceMediaSources.map { source -> + SingleSourceAllocation( + source.owner, + source, + // Note that we use the effective constraints and not the receiver's constraints + // directly. This means we never even try to allocate bitrate to sources "outside + // lastN". For example, if LastN=1 and the first endpoint sends a non-scalable + // stream with bitrate higher that the available bandwidth, we will forward no + // video at all instead of going to the second endpoint in the list. + // I think this is not desired behavior. However, it is required for the "effective + // constraints" to work as designed. + effectiveConstraints[source]!!, + allocationSettings.onStageSources.contains(source.sourceName), + diagnosticContext, + clock, + logger + ) + }.toList() /** * Expire this bandwidth allocator. diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/BitrateController.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/BitrateController.kt index f21f02751d..851468a01c 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/BitrateController.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/BitrateController.kt @@ -181,9 +181,8 @@ class BitrateController @JvmOverloads constructor( * Query whether this source is on stage or selected, as of the most recent * video constraints */ - fun isOnStageOrSelected(source: MediaSourceDesc) = - allocationSettings.onStageSources.contains(source.sourceName) || - allocationSettings.selectedSources.contains(source.sourceName) + fun isOnStageOrSelected(source: MediaSourceDesc) = allocationSettings.onStageSources.contains(source.sourceName) || + allocationSettings.selectedSources.contains(source.sourceName) /** * Query whether this allocator has non-zero effective constraints for a given source diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/PacketHandler.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/PacketHandler.kt index 59f9ebe2f0..ed0d2c040c 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/PacketHandler.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/PacketHandler.kt @@ -173,7 +173,9 @@ internal class PacketHandler( fun timeSinceFirstMedia(): Duration = firstMedia?.let { Duration.between(it, clock.instant()) } ?: Duration.ZERO - fun addPayloadType(payloadType: PayloadType) { payloadTypes[payloadType.pt] = payloadType } + fun addPayloadType(payloadType: PayloadType) { + payloadTypes[payloadType.pt] = payloadType + } val debugState: JSONObject get() = JSONObject().apply { diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/Prioritize.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/Prioritize.kt index d265c8ac1b..e76a5be00b 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/Prioritize.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/Prioritize.kt @@ -60,8 +60,10 @@ fun prioritize( /** * Return the "effective" constraints for the given media sources, i.e. the constraints adjusted for LastN. */ -fun getEffectiveConstraints(sources: List, allocationSettings: AllocationSettings): - EffectiveConstraintsMap { +fun getEffectiveConstraints( + sources: List, + allocationSettings: AllocationSettings +): EffectiveConstraintsMap { // FIXME figure out before merge - is using source count instead of endpoints // Add 1 for the receiver endpoint, which is not in the list. val effectiveLastN = effectiveLastN(allocationSettings.lastN, sources.size + 1) diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/SingleSourceAllocation.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/SingleSourceAllocation.kt index 44a171a83b..509b42616d 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/SingleSourceAllocation.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/SingleSourceAllocation.kt @@ -285,10 +285,7 @@ internal class SingleSourceAllocation( * require a high frame rate, with preconfigured values for the "preferred" height and frame rate, and we do not allow * oversending. */ - private fun selectLayersForCamera( - layers: List, - constraints: VideoConstraints, - ): Layers { + private fun selectLayersForCamera(layers: List, constraints: VideoConstraints): Layers { val minHeight = layers.map { it.layer.height }.minOrNull() ?: return Layers.noLayers val noActiveLayers = layers.none { (_, bitrate) -> bitrate > 0 } val (preferredHeight, preferredFps) = getPreferred(constraints) diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/VideoConstraints.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/VideoConstraints.kt index 1e76700348..7e1e8ecc60 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/VideoConstraints.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/allocation/VideoConstraints.kt @@ -46,5 +46,4 @@ data class VideoConstraints @JvmOverloads constructor( } } -fun Map.prettyPrint(): String = - entries.joinToString { "${it.key}->${it.value.maxHeight}" } +fun Map.prettyPrint(): String = entries.joinToString { "${it.key}->${it.value.maxHeight}" } diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/vp9/Vp9AdaptiveSourceProjectionContext.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/vp9/Vp9AdaptiveSourceProjectionContext.kt index 57376b0bdb..1fe7d7b1e8 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/vp9/Vp9AdaptiveSourceProjectionContext.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/vp9/Vp9AdaptiveSourceProjectionContext.kt @@ -81,11 +81,7 @@ class Vp9AdaptiveSourceProjectionContext( private var lastPicIdIndexResumption = -1 @Synchronized - override fun accept( - packetInfo: PacketInfo, - incomingIndex: Int, - targetIndex: Int - ): Boolean { + override fun accept(packetInfo: PacketInfo, incomingIndex: Int, targetIndex: Int): Boolean { val packet = packetInfo.packet if (packet !is Vp9Packet) { logger.warn("Packet is not Vp9 packet") @@ -203,42 +199,36 @@ class Vp9AdaptiveSourceProjectionContext( return seqGap } - private fun frameIsNewSsrc(frame: Vp9Frame): Boolean = - lastVp9FrameProjection.vp9Frame?.matchesSSRC(frame) != true + private fun frameIsNewSsrc(frame: Vp9Frame): Boolean = lastVp9FrameProjection.vp9Frame?.matchesSSRC(frame) != true /** * Find the previous frame before the given one. */ @Synchronized - private fun prevFrame(frame: Vp9Frame) = - vp9PictureMaps.get(frame.ssrc)?.prevFrame(frame) + private fun prevFrame(frame: Vp9Frame) = vp9PictureMaps.get(frame.ssrc)?.prevFrame(frame) /** * Find the next frame after the given one. */ @Synchronized - private fun nextFrame(frame: Vp9Frame) = - vp9PictureMaps.get(frame.ssrc)?.nextFrame(frame) + private fun nextFrame(frame: Vp9Frame) = vp9PictureMaps.get(frame.ssrc)?.nextFrame(frame) /** * Find the previous accepted frame before the given one. */ - private fun findPrevAcceptedFrame(frame: Vp9Frame) = - vp9PictureMaps.get(frame.ssrc)?.findPrevAcceptedFrame(frame) + private fun findPrevAcceptedFrame(frame: Vp9Frame) = vp9PictureMaps.get(frame.ssrc)?.findPrevAcceptedFrame(frame) /** * Find the next accepted frame after the given one. */ - private fun findNextAcceptedFrame(frame: Vp9Frame) = - vp9PictureMaps.get(frame.ssrc)?.findNextAcceptedFrame(frame) + private fun findNextAcceptedFrame(frame: Vp9Frame) = vp9PictureMaps.get(frame.ssrc)?.findNextAcceptedFrame(frame) /** * Find a subsequent base-layer TL0 frame after the given frame * @param frame The frame to query * @return A subsequent base-layer TL0 frame, or null */ - private fun findNextBaseTl0(frame: Vp9Frame) = - vp9PictureMaps.get(frame.ssrc)?.findNextBaseTl0(frame) + private fun findNextBaseTl0(frame: Vp9Frame) = vp9PictureMaps.get(frame.ssrc)?.findNextBaseTl0(frame) /** * Create a projection for this frame. diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/vp9/Vp9Frame.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/vp9/Vp9Frame.kt index 98387f0d7d..528e3debcd 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/vp9/Vp9Frame.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/vp9/Vp9Frame.kt @@ -185,7 +185,9 @@ class Vp9Frame internal constructor( get() = if (spatialLayer >= 0) spatialLayer else 0 // Validate that the index matches the pictureId - init { assert((index and 0x7fff) == pictureId) } + init { + assert((index and 0x7fff) == pictureId) + } constructor(packet: Vp9Packet, index: Int) : this( ssrc = packet.ssrc, diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/vp9/Vp9Picture.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/vp9/Vp9Picture.kt index fad626785e..7905db39f1 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/vp9/Vp9Picture.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/vp9/Vp9Picture.kt @@ -42,8 +42,7 @@ class Vp9Picture(packet: Vp9Packet, index: Int) { fun frame(packet: Vp9Packet) = frame(packet.effectiveSpatialLayerIndex) - private fun setFrameAtSid(frame: Vp9Frame, sid: Int) = - frames.setAndExtend(sid, frame, null) + private fun setFrameAtSid(frame: Vp9Frame, sid: Int) = frames.setAndExtend(sid, frame, null) /** * Return the first (lowest-sid, earliest in decoding order) frame that we've received so far. diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/vp9/Vp9QualityFilter.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/vp9/Vp9QualityFilter.kt index 79ea8c63d7..c17e94665b 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/cc/vp9/Vp9QualityFilter.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/cc/vp9/Vp9QualityFilter.kt @@ -337,10 +337,7 @@ internal class Vp9QualityFilter(parentLogger: Logger) { * @return true to accept the VP9 keyframe, otherwise false. */ @Synchronized - private fun acceptKeyframe( - incomingIndex: Int, - receivedTime: Instant? - ): Boolean { + private fun acceptKeyframe(incomingIndex: Int, receivedTime: Instant?): Boolean { val encodingIdOfKeyframe = getEidFromIndex(incomingIndex) // This branch writes the {@link #currentSpatialLayerId} and it // determines whether or not we should switch to another simulcast diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/colibri2/Colibri2ConferenceHandler.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/colibri2/Colibri2ConferenceHandler.kt index 5a4860d3f2..ad51657edd 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/colibri2/Colibri2ConferenceHandler.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/colibri2/Colibri2ConferenceHandler.kt @@ -344,10 +344,7 @@ class Colibri2ConferenceHandler( * the conference-modified. */ @Throws(IqProcessingException::class) - private fun handleColibri2Relay( - c2relay: Colibri2Relay, - ignoreUnknownRelays: Boolean - ): Colibri2Relay { + private fun handleColibri2Relay(c2relay: Colibri2Relay, ignoreUnknownRelays: Boolean): Colibri2Relay { val respBuilder = Colibri2Relay.getBuilder() respBuilder.setId(c2relay.id) if (c2relay.expire) { diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/load_management/JvbLoadManager.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/load_management/JvbLoadManager.kt index 0e6b60c873..991b0ca5b6 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/load_management/JvbLoadManager.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/load_management/JvbLoadManager.kt @@ -89,8 +89,7 @@ class JvbLoadManager @JvmOverloads constructor( } } - fun getCurrentStressLevel(): Double = - mostRecentLoadMeasurement?.div(jvbLoadThreshold) ?: 0.0 + fun getCurrentStressLevel(): Double = mostRecentLoadMeasurement?.div(jvbLoadThreshold) ?: 0.0 fun getStats() = OrderedJsonObject().apply { put("state", state.toString()) diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/message/BridgeChannelMessage.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/message/BridgeChannelMessage.kt index 7ea41014e9..f7f887e84c 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/message/BridgeChannelMessage.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/message/BridgeChannelMessage.kt @@ -301,8 +301,7 @@ class EndpointConnectionStatusMessage( /** * Serialize manually because it's faster than Jackson. */ - override fun createJson(): String = - """{"colibriClass":"$TYPE","endpoint":"$endpoint","active":"$active"}""" + override fun createJson(): String = """{"colibriClass":"$TYPE","endpoint":"$endpoint","active":"$active"}""" companion object { const val TYPE = "EndpointConnectivityStatusChangeEvent" @@ -442,18 +441,19 @@ class SenderSourceConstraintsMessage( */ class AddReceiverMessage( val bridgeId: String, - val endpointId: String?, // Used in single stream per endpoint mode and wil be removed - val sourceName: String?, // Used in the multi-stream mode + // Used in single stream per endpoint mode and wil be removed + val endpointId: String?, + // Used in the multi-stream mode + val sourceName: String?, val videoConstraints: VideoConstraints ) : BridgeChannelMessage() { /** * Serialize manually because it's faster than Jackson. */ - override fun createJson(): String = - "{\"colibriClass\":\"$TYPE\",\"bridgeId\":\"$bridgeId\"," + - (if (endpointId != null) "\"endpointId\":\"$endpointId\"," else "") + - (if (sourceName != null) "\"sourceName\":\"$sourceName\"," else "") + - "\"videoConstraints\":$videoConstraints}" + override fun createJson(): String = "{\"colibriClass\":\"$TYPE\",\"bridgeId\":\"$bridgeId\"," + + (if (endpointId != null) "\"endpointId\":\"$endpointId\"," else "") + + (if (sourceName != null) "\"sourceName\":\"$sourceName\"," else "") + + "\"videoConstraints\":$videoConstraints}" companion object { const val TYPE = "AddReceiver" @@ -471,8 +471,7 @@ class RemoveReceiverMessage( /** * Serialize manually because it's faster than Jackson. */ - override fun createJson(): String = - """{"colibriClass":"$TYPE","bridgeId":"$bridgeId","endpointId":"$endpointId"}""" + override fun createJson(): String = """{"colibriClass":"$TYPE","bridgeId":"$bridgeId","endpointId":"$endpointId"}""" companion object { const val TYPE = "RemoveReceiver" diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/relay/RelayMessageTransport.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/relay/RelayMessageTransport.kt index 699dc17bd4..73c09aed94 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/relay/RelayMessageTransport.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/relay/RelayMessageTransport.kt @@ -446,7 +446,8 @@ class RelayMessageTransport( conference.sendMessage( message, listOf(targetEndpoint), - false // sendToRelays + // sendToRelays + false ) } return null diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/relay/RelayedEndpoint.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/relay/RelayedEndpoint.kt index 64abaa4e6e..079fe2dd8f 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/relay/RelayedEndpoint.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/relay/RelayedEndpoint.kt @@ -150,7 +150,8 @@ class RelayedEndpoint( AddReceiverMessage( RelayConfig.config.relayId, id, - null, // source name - used in multi-stream + // source name - used in multi-stream + null, maxVideoConstraints ) ) @@ -160,7 +161,8 @@ class RelayedEndpoint( relay.sendMessage( AddReceiverMessage( RelayConfig.config.relayId, - null, // Endpoint ID - will be removed + // Endpoint ID - will be removed + null, sourceName, maxVideoConstraints ) diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/transport/dtls/DtlsTransport.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/transport/dtls/DtlsTransport.kt index eb7ce55d96..ed9c2276a0 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/transport/dtls/DtlsTransport.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/transport/dtls/DtlsTransport.kt @@ -173,14 +173,12 @@ class DtlsTransport(parentLogger: Logger) { /** * Notify this layer that DTLS data has been received from the network */ - fun dtlsDataReceived(data: ByteArray, off: Int, len: Int) = - dtlsStack.processIncomingProtocolData(data, off, len) + fun dtlsDataReceived(data: ByteArray, off: Int, len: Int) = dtlsStack.processIncomingProtocolData(data, off, len) /** * Send out DTLS data */ - fun sendDtlsData(data: ByteArray, off: Int, len: Int) = - dtlsStack.sendApplicationData(data, off, len) + fun sendDtlsData(data: ByteArray, off: Int, len: Int) = dtlsStack.sendApplicationData(data, off, len) fun stop() { if (running.compareAndSet(true, false)) { diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/transport/ice/IceTransport.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/transport/ice/IceTransport.kt index a1fca51284..328e775991 100755 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/transport/ice/IceTransport.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/transport/ice/IceTransport.kt @@ -290,10 +290,7 @@ class IceTransport @JvmOverloads constructor( * @return the number of network reachable remote candidates contained in * the given list of candidates. */ - private fun addRemoteCandidates( - remoteCandidates: List, - iceAgentIsRunning: Boolean - ): Int { + private fun addRemoteCandidates(remoteCandidates: List, iceAgentIsRunning: Boolean): Int { var remoteCandidateCount = 0 // Sort the remote candidates (host < reflexive < relayed) in order to // create first the host, then the reflexive, the relayed candidates and @@ -497,11 +494,9 @@ private data class IceProcessingStateTransition( } } -private fun IceMediaStream.remoteUfragAndPasswordKnown(): Boolean = - remoteUfrag != null && remotePassword != null +private fun IceMediaStream.remoteUfragAndPasswordKnown(): Boolean = remoteUfrag != null && remotePassword != null -private fun CandidatePacketExtension.ipNeedsResolution(): Boolean = - !InetAddresses.isInetAddress(ip) +private fun CandidatePacketExtension.ipNeedsResolution(): Boolean = !InetAddresses.isInetAddress(ip) private fun TransportAddress.isPrivateAddress(): Boolean = address.isSiteLocalAddress || /* 0xfc00::/7 */ diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/util/PayloadTypeUtil.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/util/PayloadTypeUtil.kt index 24503bec86..026a07980c 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/util/PayloadTypeUtil.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/util/PayloadTypeUtil.kt @@ -60,10 +60,7 @@ class PayloadTypeUtil { * @param ext the XML extension which describes the payload type. */ @JvmStatic - fun create( - ext: PayloadTypePacketExtension, - mediaType: MediaType - ): PayloadType? { + fun create(ext: PayloadTypePacketExtension, mediaType: MediaType): PayloadType? { val parameters: MutableMap = ConcurrentHashMap() ext.parameters.forEach { parameter -> // In SDP, format parameters don't necessarily come in name=value pairs (see e.g. the format used in diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/version/JvbVersionService.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/version/JvbVersionService.kt index ca80831fc9..7d1ee13e28 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/version/JvbVersionService.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/version/JvbVersionService.kt @@ -35,8 +35,8 @@ class JvbVersionService : VersionService { override fun parseVersionString(version: String?): Version { val matcher = Pattern.compile("(\\d*)\\.(\\d*)-(.*)").matcher(version ?: "").apply { find() } - val majorVersion = matcher.groupOrNull(1)?.toInt() ?: defaultMajorVersion - val minorVersion = matcher.groupOrNull(2)?.toInt() ?: defaultMinorVersion + val majorVersion = matcher.groupOrNull(1)?.toInt() ?: DEFAULT_MAJOR_VERSION + val minorVersion = matcher.groupOrNull(2)?.toInt() ?: DEFAULT_MINOR_VERSION val buildId = matcher.groupOrNull(3) ?: defaultBuildId return VersionImpl( @@ -48,8 +48,8 @@ class JvbVersionService : VersionService { } companion object { - private const val defaultMajorVersion = 2 - private const val defaultMinorVersion = 1 + private const val DEFAULT_MAJOR_VERSION = 2 + private const val DEFAULT_MINOR_VERSION = 1 private val defaultBuildId: String? = null } } diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/websocket/ColibriWebSocketService.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/websocket/ColibriWebSocketService.kt index 6ed779a0f0..f4e0c56367 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/websocket/ColibriWebSocketService.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/websocket/ColibriWebSocketService.kt @@ -79,10 +79,7 @@ class ColibriWebSocketService( return relayBaseUrls.map { "$it/$conferenceId/$relayId?pwd=$pwd" } } - fun registerServlet( - servletContextHandler: ServletContextHandler, - videobridge: Videobridge - ) { + fun registerServlet(servletContextHandler: ServletContextHandler, videobridge: Videobridge) { if (config.enabled) { logger.info("Registering servlet with baseUrls = $baseUrls, relayBaseUrls = $relayBaseUrls") val holder = ServletHolder().apply { diff --git a/jvb/src/main/kotlin/org/jitsi/videobridge/xmpp/XmppConnection.kt b/jvb/src/main/kotlin/org/jitsi/videobridge/xmpp/XmppConnection.kt index f4367dd308..7833a4794d 100644 --- a/jvb/src/main/kotlin/org/jitsi/videobridge/xmpp/XmppConnection.kt +++ b/jvb/src/main/kotlin/org/jitsi/videobridge/xmpp/XmppConnection.kt @@ -139,11 +139,10 @@ class XmppConnection : IQListener { return true } - private fun MucClientConfiguration.matches(other: MucClientConfiguration) = - hostname == other.hostname && - port == other.port && - domain == other.domain && - username == other.username + private fun MucClientConfiguration.matches(other: MucClientConfiguration) = hostname == other.hostname && + port == other.port && + domain == other.domain && + username == other.username /** * Returns ids of [MucClient] that have been added. diff --git a/jvb/src/test/kotlin/org/jitsi/videobridge/EndpointConnectionStatusMonitorTest.kt b/jvb/src/test/kotlin/org/jitsi/videobridge/EndpointConnectionStatusMonitorTest.kt index 2784fd83bf..bd3cce7740 100644 --- a/jvb/src/test/kotlin/org/jitsi/videobridge/EndpointConnectionStatusMonitorTest.kt +++ b/jvb/src/test/kotlin/org/jitsi/videobridge/EndpointConnectionStatusMonitorTest.kt @@ -202,7 +202,7 @@ class EndpointConnectionStatusMonitorTest : ShouldSpec({ } } context("and then a new ep joins") { - every { conference.getLocalEndpoint("4") } returns mockk() { every { id } returns "4" } + every { conference.getLocalEndpoint("4") } returns mockk { every { id } returns "4" } monitor.endpointConnected("4") should("update the new endpoint of the other non-visitor endpoints' statuses") { sendMessageCalls shouldHaveSize 2 diff --git a/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/BitrateControllerPerfTest.kt b/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/BitrateControllerPerfTest.kt index 44d2c5b946..6b7058fbfd 100644 --- a/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/BitrateControllerPerfTest.kt +++ b/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/BitrateControllerPerfTest.kt @@ -79,7 +79,8 @@ class BitrateControllerPerfTest : StringSpec() { Supplier { endpoints.toList() }, DiagnosticContext(), createLogger(), - false, // TODO cover the case for true? + // TODO cover the case for true? + false, clock, ).apply { // The BC only starts working 10 seconds after it first received media, so fake that. diff --git a/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/BitrateControllerTest.kt b/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/BitrateControllerTest.kt index 494e5d6e6a..bd9435c513 100644 --- a/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/BitrateControllerTest.kt +++ b/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/BitrateControllerTest.kt @@ -56,10 +56,10 @@ class BitrateControllerTest : ShouldSpec() { private val logger = createLogger() private val clock = FakeClock() private val bc = BitrateControllerWrapper(createEndpoints("A", "B", "C", "D"), clock = clock) - private val A = bc.endpoints.find { it.id == "A" }!! as TestEndpoint - private val B = bc.endpoints.find { it.id == "B" }!! as TestEndpoint - private val C = bc.endpoints.find { it.id == "C" }!! as TestEndpoint - private val D = bc.endpoints.find { it.id == "D" }!! as TestEndpoint + private val a = bc.endpoints.find { it.id == "A" }!! as TestEndpoint + private val b = bc.endpoints.find { it.id == "B" }!! as TestEndpoint + private val c = bc.endpoints.find { it.id == "C" }!! as TestEndpoint + private val d = bc.endpoints.find { it.id == "D" }!! as TestEndpoint override suspend fun beforeSpec(spec: Spec) = super.beforeSpec(spec).also { // We disable the threshold, causing [BandwidthAllocator] to make a new decision every time BWE changes. This is @@ -131,9 +131,9 @@ class BitrateControllerTest : ShouldSpec() { listOf(true, false).forEach { screensharing -> context("With ${if (screensharing) "screensharing" else "camera"}") { if (screensharing) { - A.mediaSources[0].videoType = VideoType.DESKTOP + a.mediaSources[0].videoType = VideoType.DESKTOP } - bc.setEndpointOrdering(A, B, C, D) + bc.setEndpointOrdering(a, b, c, d) bc.setStageView("A-v0") bc.bc.allocationSettings.lastN shouldBe -1 @@ -147,7 +147,7 @@ class BitrateControllerTest : ShouldSpec() { } } context("and a non-dominant speaker is on stage") { - bc.setEndpointOrdering(B, A, C, D) + bc.setEndpointOrdering(b, a, c, d) bc.setStageView("A-v0") bc.bc.allocationSettings.lastN shouldBe -1 @@ -160,7 +160,7 @@ class BitrateControllerTest : ShouldSpec() { } context("When LastN=0") { // LastN=0 is used when the client goes in "audio-only" mode. - bc.setEndpointOrdering(A, B, C, D) + bc.setEndpointOrdering(a, b, c, d) bc.setStageView("A", lastN = 0) bc.bc.allocationSettings.lastN shouldBe 0 @@ -174,7 +174,7 @@ class BitrateControllerTest : ShouldSpec() { context("When LastN=1") { // LastN=1 is used when the client goes in "audio-only" mode, but someone starts a screenshare. context("and the dominant speaker is on-stage") { - bc.setEndpointOrdering(A, B, C, D) + bc.setEndpointOrdering(a, b, c, d) bc.setStageView("A-v0", lastN = 1) bc.bc.allocationSettings.lastN shouldBe 1 @@ -186,7 +186,7 @@ class BitrateControllerTest : ShouldSpec() { verifyStageViewLastN1() } context("and a non-dominant speaker is on stage") { - bc.setEndpointOrdering(B, A, C, D) + bc.setEndpointOrdering(b, a, c, d) bc.setStageView("A-v0", lastN = 1) bc.bc.allocationSettings.lastN shouldBe 1 @@ -200,7 +200,7 @@ class BitrateControllerTest : ShouldSpec() { } } context("Tile view") { - bc.setEndpointOrdering(A, B, C, D) + bc.setEndpointOrdering(a, b, c, d) bc.setTileView("A-v0", "B-v0", "C-v0", "D-v0") bc.bc.allocationSettings.lastN shouldBe -1 @@ -226,7 +226,7 @@ class BitrateControllerTest : ShouldSpec() { } } context("Tile view 360p") { - bc.setEndpointOrdering(A, B, C, D) + bc.setEndpointOrdering(a, b, c, d) bc.setTileView("A-v0", "B-v0", "C-v0", "D-v0", maxFrameHeight = 360) bc.bc.allocationSettings.lastN shouldBe -1 @@ -257,7 +257,7 @@ class BitrateControllerTest : ShouldSpec() { // A is dominant speaker, A and B are selected. With LastN=2 we should always forward the selected // sources regardless of who is speaking. // The exact flow of this scenario was taken from a (non-jitsi-meet) client. - bc.setEndpointOrdering(A, B, C, D) + bc.setEndpointOrdering(a, b, c, d) bc.bc.setBandwidthAllocationSettings( ReceiverVideoConstraintsMessage( selectedSources = listOf("A-v0", "B-v0"), @@ -289,7 +289,7 @@ class BitrateControllerTest : ShouldSpec() { clock.elapse(2.secs) // B becomes dominant speaker. - bc.setEndpointOrdering(B, A, C, D) + bc.setEndpointOrdering(b, a, c, d) bc.forwardedSourcesHistory.last().event.shouldBe(setOf("A-v0", "B-v0")) clock.elapse(2.secs) @@ -334,7 +334,7 @@ class BitrateControllerTest : ShouldSpec() { clock.elapse(2.secs) // D is now dominant speaker, but it should not override the selected endpoints. - bc.setEndpointOrdering(D, B, A, C) + bc.setEndpointOrdering(d, b, a, c) bc.forwardedSourcesHistory.last().event.shouldBe(setOf("A-v0", "B-v0")) bc.bwe = 10.mbps @@ -348,7 +348,7 @@ class BitrateControllerTest : ShouldSpec() { clock.elapse(2.secs) // C is now dominant speaker, but it should not override the selected endpoints. - bc.setEndpointOrdering(C, D, A, B) + bc.setEndpointOrdering(c, d, a, b) bc.forwardedSourcesHistory.last().event.shouldBe(setOf("A-v0", "B-v0")) } } @@ -391,10 +391,10 @@ class BitrateControllerTest : ShouldSpec() { 0.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = sd30), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = sd30), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ), oversending = true ) @@ -403,10 +403,10 @@ class BitrateControllerTest : ShouldSpec() { 160.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = hd7_5), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = hd7_5), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ), oversending = true ) @@ -415,10 +415,10 @@ class BitrateControllerTest : ShouldSpec() { 660.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = hd7_5), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = hd7_5), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ), oversending = false ) @@ -427,10 +427,10 @@ class BitrateControllerTest : ShouldSpec() { 1320.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = hd15), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = hd15), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ) ) ), @@ -438,10 +438,10 @@ class BitrateControllerTest : ShouldSpec() { 2000.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = hd30), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = hd30), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ) ) ), @@ -449,10 +449,10 @@ class BitrateControllerTest : ShouldSpec() { 2050.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = hd30), - SingleAllocation(B, targetLayer = ld7_5), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = hd30), + SingleAllocation(b, targetLayer = ld7_5), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ) ) ), @@ -460,10 +460,10 @@ class BitrateControllerTest : ShouldSpec() { 2100.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = hd30), - SingleAllocation(B, targetLayer = ld7_5), - SingleAllocation(C, targetLayer = ld7_5), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = hd30), + SingleAllocation(b, targetLayer = ld7_5), + SingleAllocation(c, targetLayer = ld7_5), + SingleAllocation(d, targetLayer = noVideo) ) ) ), @@ -471,10 +471,10 @@ class BitrateControllerTest : ShouldSpec() { 2150.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = hd30), - SingleAllocation(B, targetLayer = ld7_5), - SingleAllocation(C, targetLayer = ld7_5), - SingleAllocation(D, targetLayer = ld7_5) + SingleAllocation(a, targetLayer = hd30), + SingleAllocation(b, targetLayer = ld7_5), + SingleAllocation(c, targetLayer = ld7_5), + SingleAllocation(d, targetLayer = ld7_5) ) ) ), @@ -482,10 +482,10 @@ class BitrateControllerTest : ShouldSpec() { 2200.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = hd30), - SingleAllocation(B, targetLayer = ld15), - SingleAllocation(C, targetLayer = ld7_5), - SingleAllocation(D, targetLayer = ld7_5) + SingleAllocation(a, targetLayer = hd30), + SingleAllocation(b, targetLayer = ld15), + SingleAllocation(c, targetLayer = ld7_5), + SingleAllocation(d, targetLayer = ld7_5) ) ) ), @@ -493,10 +493,10 @@ class BitrateControllerTest : ShouldSpec() { 2250.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = hd30), - SingleAllocation(B, targetLayer = ld15), - SingleAllocation(C, targetLayer = ld15), - SingleAllocation(D, targetLayer = ld7_5) + SingleAllocation(a, targetLayer = hd30), + SingleAllocation(b, targetLayer = ld15), + SingleAllocation(c, targetLayer = ld15), + SingleAllocation(d, targetLayer = ld7_5) ) ) ), @@ -504,10 +504,10 @@ class BitrateControllerTest : ShouldSpec() { 2300.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = hd30), - SingleAllocation(B, targetLayer = ld15), - SingleAllocation(C, targetLayer = ld15), - SingleAllocation(D, targetLayer = ld15) + SingleAllocation(a, targetLayer = hd30), + SingleAllocation(b, targetLayer = ld15), + SingleAllocation(c, targetLayer = ld15), + SingleAllocation(d, targetLayer = ld15) ) ) ), @@ -515,10 +515,10 @@ class BitrateControllerTest : ShouldSpec() { 2350.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = hd30), - SingleAllocation(B, targetLayer = ld30), - SingleAllocation(C, targetLayer = ld15), - SingleAllocation(D, targetLayer = ld15) + SingleAllocation(a, targetLayer = hd30), + SingleAllocation(b, targetLayer = ld30), + SingleAllocation(c, targetLayer = ld15), + SingleAllocation(d, targetLayer = ld15) ) ) ), @@ -526,10 +526,10 @@ class BitrateControllerTest : ShouldSpec() { 2400.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = hd30), - SingleAllocation(B, targetLayer = ld30), - SingleAllocation(C, targetLayer = ld30), - SingleAllocation(D, targetLayer = ld15) + SingleAllocation(a, targetLayer = hd30), + SingleAllocation(b, targetLayer = ld30), + SingleAllocation(c, targetLayer = ld30), + SingleAllocation(d, targetLayer = ld15) ) ) ), @@ -537,10 +537,10 @@ class BitrateControllerTest : ShouldSpec() { 2460.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = hd30), - SingleAllocation(B, targetLayer = ld30), - SingleAllocation(C, targetLayer = ld30), - SingleAllocation(D, targetLayer = ld30) + SingleAllocation(a, targetLayer = hd30), + SingleAllocation(b, targetLayer = ld30), + SingleAllocation(c, targetLayer = ld30), + SingleAllocation(d, targetLayer = ld30) ) ) ) @@ -582,10 +582,10 @@ class BitrateControllerTest : ShouldSpec() { 50.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld7_5), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = ld7_5), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ), oversending = false ) @@ -594,10 +594,10 @@ class BitrateControllerTest : ShouldSpec() { 100.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld15), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = ld15), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ) ) ), @@ -605,10 +605,10 @@ class BitrateControllerTest : ShouldSpec() { 150.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld30), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = ld30), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ) ) ), @@ -616,10 +616,10 @@ class BitrateControllerTest : ShouldSpec() { 500.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = sd30), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = sd30), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ) ) ), @@ -627,10 +627,10 @@ class BitrateControllerTest : ShouldSpec() { 550.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = sd30), - SingleAllocation(B, targetLayer = ld7_5), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = sd30), + SingleAllocation(b, targetLayer = ld7_5), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ) ) ), @@ -638,10 +638,10 @@ class BitrateControllerTest : ShouldSpec() { 600.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = sd30), - SingleAllocation(B, targetLayer = ld7_5), - SingleAllocation(C, targetLayer = ld7_5), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = sd30), + SingleAllocation(b, targetLayer = ld7_5), + SingleAllocation(c, targetLayer = ld7_5), + SingleAllocation(d, targetLayer = noVideo) ) ) ), @@ -649,10 +649,10 @@ class BitrateControllerTest : ShouldSpec() { 650.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = sd30), - SingleAllocation(B, targetLayer = ld7_5), - SingleAllocation(C, targetLayer = ld7_5), - SingleAllocation(D, targetLayer = ld7_5) + SingleAllocation(a, targetLayer = sd30), + SingleAllocation(b, targetLayer = ld7_5), + SingleAllocation(c, targetLayer = ld7_5), + SingleAllocation(d, targetLayer = ld7_5) ) ) ), @@ -660,10 +660,10 @@ class BitrateControllerTest : ShouldSpec() { 700.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = sd30), - SingleAllocation(B, targetLayer = ld15), - SingleAllocation(C, targetLayer = ld7_5), - SingleAllocation(D, targetLayer = ld7_5) + SingleAllocation(a, targetLayer = sd30), + SingleAllocation(b, targetLayer = ld15), + SingleAllocation(c, targetLayer = ld7_5), + SingleAllocation(d, targetLayer = ld7_5) ) ) ), @@ -671,10 +671,10 @@ class BitrateControllerTest : ShouldSpec() { 750.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = sd30), - SingleAllocation(B, targetLayer = ld15), - SingleAllocation(C, targetLayer = ld15), - SingleAllocation(D, targetLayer = ld7_5) + SingleAllocation(a, targetLayer = sd30), + SingleAllocation(b, targetLayer = ld15), + SingleAllocation(c, targetLayer = ld15), + SingleAllocation(d, targetLayer = ld7_5) ) ) ), @@ -682,10 +682,10 @@ class BitrateControllerTest : ShouldSpec() { 800.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = sd30), - SingleAllocation(B, targetLayer = ld15), - SingleAllocation(C, targetLayer = ld15), - SingleAllocation(D, targetLayer = ld15) + SingleAllocation(a, targetLayer = sd30), + SingleAllocation(b, targetLayer = ld15), + SingleAllocation(c, targetLayer = ld15), + SingleAllocation(d, targetLayer = ld15) ) ) ), @@ -693,10 +693,10 @@ class BitrateControllerTest : ShouldSpec() { 850.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = sd30), - SingleAllocation(B, targetLayer = ld30), - SingleAllocation(C, targetLayer = ld15), - SingleAllocation(D, targetLayer = ld15) + SingleAllocation(a, targetLayer = sd30), + SingleAllocation(b, targetLayer = ld30), + SingleAllocation(c, targetLayer = ld15), + SingleAllocation(d, targetLayer = ld15) ) ) ), @@ -704,10 +704,10 @@ class BitrateControllerTest : ShouldSpec() { 900.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = sd30), - SingleAllocation(B, targetLayer = ld30), - SingleAllocation(C, targetLayer = ld30), - SingleAllocation(D, targetLayer = ld15) + SingleAllocation(a, targetLayer = sd30), + SingleAllocation(b, targetLayer = ld30), + SingleAllocation(c, targetLayer = ld30), + SingleAllocation(d, targetLayer = ld15) ) ) ), @@ -715,10 +715,10 @@ class BitrateControllerTest : ShouldSpec() { 960.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = sd30), - SingleAllocation(B, targetLayer = ld30), - SingleAllocation(C, targetLayer = ld30), - SingleAllocation(D, targetLayer = ld30) + SingleAllocation(a, targetLayer = sd30), + SingleAllocation(b, targetLayer = ld30), + SingleAllocation(c, targetLayer = ld30), + SingleAllocation(d, targetLayer = ld30) ) ) ), @@ -726,10 +726,10 @@ class BitrateControllerTest : ShouldSpec() { 2150.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = hd30), - SingleAllocation(B, targetLayer = ld7_5), - SingleAllocation(C, targetLayer = ld7_5), - SingleAllocation(D, targetLayer = ld7_5) + SingleAllocation(a, targetLayer = hd30), + SingleAllocation(b, targetLayer = ld7_5), + SingleAllocation(c, targetLayer = ld7_5), + SingleAllocation(d, targetLayer = ld7_5) ) ) ), @@ -737,10 +737,10 @@ class BitrateControllerTest : ShouldSpec() { 2200.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = hd30), - SingleAllocation(B, targetLayer = ld15), - SingleAllocation(C, targetLayer = ld7_5), - SingleAllocation(D, targetLayer = ld7_5) + SingleAllocation(a, targetLayer = hd30), + SingleAllocation(b, targetLayer = ld15), + SingleAllocation(c, targetLayer = ld7_5), + SingleAllocation(d, targetLayer = ld7_5) ) ) ), @@ -748,10 +748,10 @@ class BitrateControllerTest : ShouldSpec() { 2250.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = hd30), - SingleAllocation(B, targetLayer = ld15), - SingleAllocation(C, targetLayer = ld15), - SingleAllocation(D, targetLayer = ld7_5) + SingleAllocation(a, targetLayer = hd30), + SingleAllocation(b, targetLayer = ld15), + SingleAllocation(c, targetLayer = ld15), + SingleAllocation(d, targetLayer = ld7_5) ) ) ), @@ -759,10 +759,10 @@ class BitrateControllerTest : ShouldSpec() { 2300.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = hd30), - SingleAllocation(B, targetLayer = ld15), - SingleAllocation(C, targetLayer = ld15), - SingleAllocation(D, targetLayer = ld15) + SingleAllocation(a, targetLayer = hd30), + SingleAllocation(b, targetLayer = ld15), + SingleAllocation(c, targetLayer = ld15), + SingleAllocation(d, targetLayer = ld15) ) ) ), @@ -770,10 +770,10 @@ class BitrateControllerTest : ShouldSpec() { 2350.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = hd30), - SingleAllocation(B, targetLayer = ld30), - SingleAllocation(C, targetLayer = ld15), - SingleAllocation(D, targetLayer = ld15) + SingleAllocation(a, targetLayer = hd30), + SingleAllocation(b, targetLayer = ld30), + SingleAllocation(c, targetLayer = ld15), + SingleAllocation(d, targetLayer = ld15) ) ) ), @@ -781,10 +781,10 @@ class BitrateControllerTest : ShouldSpec() { 2400.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = hd30), - SingleAllocation(B, targetLayer = ld30), - SingleAllocation(C, targetLayer = ld30), - SingleAllocation(D, targetLayer = ld15) + SingleAllocation(a, targetLayer = hd30), + SingleAllocation(b, targetLayer = ld30), + SingleAllocation(c, targetLayer = ld30), + SingleAllocation(d, targetLayer = ld15) ) ) ), @@ -792,10 +792,10 @@ class BitrateControllerTest : ShouldSpec() { 2460.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = hd30), - SingleAllocation(B, targetLayer = ld30), - SingleAllocation(C, targetLayer = ld30), - SingleAllocation(D, targetLayer = ld30) + SingleAllocation(a, targetLayer = hd30), + SingleAllocation(b, targetLayer = ld30), + SingleAllocation(c, targetLayer = ld30), + SingleAllocation(d, targetLayer = ld30) ) ) ) @@ -817,10 +817,10 @@ class BitrateControllerTest : ShouldSpec() { bc.allocationHistory.last().event.shouldMatch( BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = noVideo), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = noVideo), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ) ) ) @@ -851,10 +851,10 @@ class BitrateControllerTest : ShouldSpec() { 50.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld7_5), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = ld7_5), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ) ) ), @@ -862,10 +862,10 @@ class BitrateControllerTest : ShouldSpec() { 100.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld15), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = ld15), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ) ) ), @@ -873,10 +873,10 @@ class BitrateControllerTest : ShouldSpec() { 150.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld30), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = ld30), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ) ) ), @@ -884,10 +884,10 @@ class BitrateControllerTest : ShouldSpec() { 500.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = sd30), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = sd30), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ) ) ), @@ -895,10 +895,10 @@ class BitrateControllerTest : ShouldSpec() { 2010.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = hd30), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = hd30), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ) ) ) @@ -921,10 +921,10 @@ class BitrateControllerTest : ShouldSpec() { (-1).bps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = noVideo), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = noVideo), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ) ) ), @@ -932,10 +932,10 @@ class BitrateControllerTest : ShouldSpec() { 50.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld7_5), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = ld7_5), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ) ) ), @@ -943,10 +943,10 @@ class BitrateControllerTest : ShouldSpec() { 100.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld7_5), - SingleAllocation(B, targetLayer = ld7_5), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = ld7_5), + SingleAllocation(b, targetLayer = ld7_5), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ) ) ), @@ -954,10 +954,10 @@ class BitrateControllerTest : ShouldSpec() { 150.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld7_5), - SingleAllocation(B, targetLayer = ld7_5), - SingleAllocation(C, targetLayer = ld7_5), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = ld7_5), + SingleAllocation(b, targetLayer = ld7_5), + SingleAllocation(c, targetLayer = ld7_5), + SingleAllocation(d, targetLayer = noVideo) ) ) ), @@ -965,10 +965,10 @@ class BitrateControllerTest : ShouldSpec() { 200.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld7_5), - SingleAllocation(B, targetLayer = ld7_5), - SingleAllocation(C, targetLayer = ld7_5), - SingleAllocation(D, targetLayer = ld7_5) + SingleAllocation(a, targetLayer = ld7_5), + SingleAllocation(b, targetLayer = ld7_5), + SingleAllocation(c, targetLayer = ld7_5), + SingleAllocation(d, targetLayer = ld7_5) ) ) ), @@ -976,10 +976,10 @@ class BitrateControllerTest : ShouldSpec() { 250.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld15), - SingleAllocation(B, targetLayer = ld7_5), - SingleAllocation(C, targetLayer = ld7_5), - SingleAllocation(D, targetLayer = ld7_5) + SingleAllocation(a, targetLayer = ld15), + SingleAllocation(b, targetLayer = ld7_5), + SingleAllocation(c, targetLayer = ld7_5), + SingleAllocation(d, targetLayer = ld7_5) ) ) ), @@ -987,10 +987,10 @@ class BitrateControllerTest : ShouldSpec() { 300.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld15), - SingleAllocation(B, targetLayer = ld15), - SingleAllocation(C, targetLayer = ld7_5), - SingleAllocation(D, targetLayer = ld7_5) + SingleAllocation(a, targetLayer = ld15), + SingleAllocation(b, targetLayer = ld15), + SingleAllocation(c, targetLayer = ld7_5), + SingleAllocation(d, targetLayer = ld7_5) ) ) ), @@ -998,10 +998,10 @@ class BitrateControllerTest : ShouldSpec() { 350.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld15), - SingleAllocation(B, targetLayer = ld15), - SingleAllocation(C, targetLayer = ld15), - SingleAllocation(D, targetLayer = ld7_5) + SingleAllocation(a, targetLayer = ld15), + SingleAllocation(b, targetLayer = ld15), + SingleAllocation(c, targetLayer = ld15), + SingleAllocation(d, targetLayer = ld7_5) ) ) ), @@ -1009,10 +1009,10 @@ class BitrateControllerTest : ShouldSpec() { 400.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld15), - SingleAllocation(B, targetLayer = ld15), - SingleAllocation(C, targetLayer = ld15), - SingleAllocation(D, targetLayer = ld15) + SingleAllocation(a, targetLayer = ld15), + SingleAllocation(b, targetLayer = ld15), + SingleAllocation(c, targetLayer = ld15), + SingleAllocation(d, targetLayer = ld15) ) ) ), @@ -1020,10 +1020,10 @@ class BitrateControllerTest : ShouldSpec() { 450.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld30), - SingleAllocation(B, targetLayer = ld15), - SingleAllocation(C, targetLayer = ld15), - SingleAllocation(D, targetLayer = ld15) + SingleAllocation(a, targetLayer = ld30), + SingleAllocation(b, targetLayer = ld15), + SingleAllocation(c, targetLayer = ld15), + SingleAllocation(d, targetLayer = ld15) ) ) ), @@ -1031,10 +1031,10 @@ class BitrateControllerTest : ShouldSpec() { 500.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld30), - SingleAllocation(B, targetLayer = ld30), - SingleAllocation(C, targetLayer = ld15), - SingleAllocation(D, targetLayer = ld15) + SingleAllocation(a, targetLayer = ld30), + SingleAllocation(b, targetLayer = ld30), + SingleAllocation(c, targetLayer = ld15), + SingleAllocation(d, targetLayer = ld15) ) ) ), @@ -1042,10 +1042,10 @@ class BitrateControllerTest : ShouldSpec() { 550.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld30), - SingleAllocation(B, targetLayer = ld30), - SingleAllocation(C, targetLayer = ld30), - SingleAllocation(D, targetLayer = ld15) + SingleAllocation(a, targetLayer = ld30), + SingleAllocation(b, targetLayer = ld30), + SingleAllocation(c, targetLayer = ld30), + SingleAllocation(d, targetLayer = ld15) ) ) ), @@ -1053,10 +1053,10 @@ class BitrateControllerTest : ShouldSpec() { 610.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld30), - SingleAllocation(B, targetLayer = ld30), - SingleAllocation(C, targetLayer = ld30), - SingleAllocation(D, targetLayer = ld30) + SingleAllocation(a, targetLayer = ld30), + SingleAllocation(b, targetLayer = ld30), + SingleAllocation(c, targetLayer = ld30), + SingleAllocation(d, targetLayer = ld30) ) ) ) @@ -1079,10 +1079,10 @@ class BitrateControllerTest : ShouldSpec() { (-1).bps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = noVideo), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = noVideo), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ) ) ), @@ -1090,10 +1090,10 @@ class BitrateControllerTest : ShouldSpec() { 50.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld7_5), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = ld7_5), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ), oversending = false ) @@ -1102,10 +1102,10 @@ class BitrateControllerTest : ShouldSpec() { 100.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld7_5), - SingleAllocation(B, targetLayer = ld7_5), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = ld7_5), + SingleAllocation(b, targetLayer = ld7_5), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ) ) ), @@ -1113,10 +1113,10 @@ class BitrateControllerTest : ShouldSpec() { 150.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld7_5), - SingleAllocation(B, targetLayer = ld7_5), - SingleAllocation(C, targetLayer = ld7_5), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = ld7_5), + SingleAllocation(b, targetLayer = ld7_5), + SingleAllocation(c, targetLayer = ld7_5), + SingleAllocation(d, targetLayer = noVideo) ) ) ), @@ -1124,10 +1124,10 @@ class BitrateControllerTest : ShouldSpec() { 200.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld7_5), - SingleAllocation(B, targetLayer = ld7_5), - SingleAllocation(C, targetLayer = ld7_5), - SingleAllocation(D, targetLayer = ld7_5) + SingleAllocation(a, targetLayer = ld7_5), + SingleAllocation(b, targetLayer = ld7_5), + SingleAllocation(c, targetLayer = ld7_5), + SingleAllocation(d, targetLayer = ld7_5) ) ) ), @@ -1135,10 +1135,10 @@ class BitrateControllerTest : ShouldSpec() { 250.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld15), - SingleAllocation(B, targetLayer = ld7_5), - SingleAllocation(C, targetLayer = ld7_5), - SingleAllocation(D, targetLayer = ld7_5) + SingleAllocation(a, targetLayer = ld15), + SingleAllocation(b, targetLayer = ld7_5), + SingleAllocation(c, targetLayer = ld7_5), + SingleAllocation(d, targetLayer = ld7_5) ) ) ), @@ -1146,10 +1146,10 @@ class BitrateControllerTest : ShouldSpec() { 300.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld15), - SingleAllocation(B, targetLayer = ld15), - SingleAllocation(C, targetLayer = ld7_5), - SingleAllocation(D, targetLayer = ld7_5) + SingleAllocation(a, targetLayer = ld15), + SingleAllocation(b, targetLayer = ld15), + SingleAllocation(c, targetLayer = ld7_5), + SingleAllocation(d, targetLayer = ld7_5) ) ) ), @@ -1157,10 +1157,10 @@ class BitrateControllerTest : ShouldSpec() { 350.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld15), - SingleAllocation(B, targetLayer = ld15), - SingleAllocation(C, targetLayer = ld15), - SingleAllocation(D, targetLayer = ld7_5) + SingleAllocation(a, targetLayer = ld15), + SingleAllocation(b, targetLayer = ld15), + SingleAllocation(c, targetLayer = ld15), + SingleAllocation(d, targetLayer = ld7_5) ) ) ), @@ -1168,10 +1168,10 @@ class BitrateControllerTest : ShouldSpec() { 400.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld15), - SingleAllocation(B, targetLayer = ld15), - SingleAllocation(C, targetLayer = ld15), - SingleAllocation(D, targetLayer = ld15) + SingleAllocation(a, targetLayer = ld15), + SingleAllocation(b, targetLayer = ld15), + SingleAllocation(c, targetLayer = ld15), + SingleAllocation(d, targetLayer = ld15) ) ) ), @@ -1179,10 +1179,10 @@ class BitrateControllerTest : ShouldSpec() { 450.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld30), - SingleAllocation(B, targetLayer = ld15), - SingleAllocation(C, targetLayer = ld15), - SingleAllocation(D, targetLayer = ld15) + SingleAllocation(a, targetLayer = ld30), + SingleAllocation(b, targetLayer = ld15), + SingleAllocation(c, targetLayer = ld15), + SingleAllocation(d, targetLayer = ld15) ) ) ), @@ -1190,10 +1190,10 @@ class BitrateControllerTest : ShouldSpec() { 500.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld30), - SingleAllocation(B, targetLayer = ld30), - SingleAllocation(C, targetLayer = ld15), - SingleAllocation(D, targetLayer = ld15) + SingleAllocation(a, targetLayer = ld30), + SingleAllocation(b, targetLayer = ld30), + SingleAllocation(c, targetLayer = ld15), + SingleAllocation(d, targetLayer = ld15) ) ) ), @@ -1201,10 +1201,10 @@ class BitrateControllerTest : ShouldSpec() { 550.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld30), - SingleAllocation(B, targetLayer = ld30), - SingleAllocation(C, targetLayer = ld30), - SingleAllocation(D, targetLayer = ld15) + SingleAllocation(a, targetLayer = ld30), + SingleAllocation(b, targetLayer = ld30), + SingleAllocation(c, targetLayer = ld30), + SingleAllocation(d, targetLayer = ld15) ) ) ), @@ -1212,10 +1212,10 @@ class BitrateControllerTest : ShouldSpec() { 610.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld30), - SingleAllocation(B, targetLayer = ld30), - SingleAllocation(C, targetLayer = ld30), - SingleAllocation(D, targetLayer = ld30) + SingleAllocation(a, targetLayer = ld30), + SingleAllocation(b, targetLayer = ld30), + SingleAllocation(c, targetLayer = ld30), + SingleAllocation(d, targetLayer = ld30) ) ) ), @@ -1223,10 +1223,10 @@ class BitrateControllerTest : ShouldSpec() { 960.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = sd30), - SingleAllocation(B, targetLayer = ld30), - SingleAllocation(C, targetLayer = ld30), - SingleAllocation(D, targetLayer = ld30) + SingleAllocation(a, targetLayer = sd30), + SingleAllocation(b, targetLayer = ld30), + SingleAllocation(c, targetLayer = ld30), + SingleAllocation(d, targetLayer = ld30) ) ) ), @@ -1234,10 +1234,10 @@ class BitrateControllerTest : ShouldSpec() { 1310.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = sd30), - SingleAllocation(B, targetLayer = sd30), - SingleAllocation(C, targetLayer = ld30), - SingleAllocation(D, targetLayer = ld30) + SingleAllocation(a, targetLayer = sd30), + SingleAllocation(b, targetLayer = sd30), + SingleAllocation(c, targetLayer = ld30), + SingleAllocation(d, targetLayer = ld30) ) ) ), @@ -1245,10 +1245,10 @@ class BitrateControllerTest : ShouldSpec() { 1660.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = sd30), - SingleAllocation(B, targetLayer = sd30), - SingleAllocation(C, targetLayer = sd30), - SingleAllocation(D, targetLayer = ld30) + SingleAllocation(a, targetLayer = sd30), + SingleAllocation(b, targetLayer = sd30), + SingleAllocation(c, targetLayer = sd30), + SingleAllocation(d, targetLayer = ld30) ) ) ), @@ -1256,10 +1256,10 @@ class BitrateControllerTest : ShouldSpec() { 2010.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = sd30), - SingleAllocation(B, targetLayer = sd30), - SingleAllocation(C, targetLayer = sd30), - SingleAllocation(D, targetLayer = sd30) + SingleAllocation(a, targetLayer = sd30), + SingleAllocation(b, targetLayer = sd30), + SingleAllocation(c, targetLayer = sd30), + SingleAllocation(d, targetLayer = sd30) ) ) ) @@ -1287,10 +1287,10 @@ class BitrateControllerTest : ShouldSpec() { (-1).bps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = noVideo), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = noVideo), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ), oversending = true ) @@ -1299,10 +1299,10 @@ class BitrateControllerTest : ShouldSpec() { 50.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld7_5), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = ld7_5), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ) ) ), @@ -1310,21 +1310,22 @@ class BitrateControllerTest : ShouldSpec() { 100.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld15), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = ld15), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ) ) ), Event( - 160.kbps, // TODO: why 160 instead of 150? weird. + // TODO: why 160 instead of 150? weird. + 160.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = ld30), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = ld30), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ) ) ) @@ -1336,10 +1337,10 @@ class BitrateControllerTest : ShouldSpec() { 510.kbps, BandwidthAllocation( setOf( - SingleAllocation(A, targetLayer = sd30), - SingleAllocation(B, targetLayer = noVideo), - SingleAllocation(C, targetLayer = noVideo), - SingleAllocation(D, targetLayer = noVideo) + SingleAllocation(a, targetLayer = sd30), + SingleAllocation(b, targetLayer = noVideo), + SingleAllocation(c, targetLayer = noVideo), + SingleAllocation(d, targetLayer = noVideo) ) ) ) @@ -1403,7 +1404,8 @@ class BitrateControllerWrapper(initialEndpoints: List, val Supplier { endpoints }, DiagnosticContext(), logger, - true, // TODO merge BitrateControllerNewTest with old and use this flag + // TODO merge BitrateControllerNewTest with old and use this flag + true, clock ) @@ -1423,11 +1425,7 @@ class BitrateControllerWrapper(initialEndpoints: List, val ) } - fun setTileView( - vararg selectedSources: String, - maxFrameHeight: Int = 180, - lastN: Int? = null - ) { + fun setTileView(vararg selectedSources: String, maxFrameHeight: Int = 180, lastN: Int? = null) { bc.setBandwidthAllocationSettings( ReceiverVideoConstraintsMessage( lastN = lastN, @@ -1481,21 +1479,16 @@ fun createSources(vararg ids: String): MutableList { } } -fun createSourceDesc( - ssrc1: Int, - ssrc2: Int, - ssrc3: Int, - sourceName: String, - owner: String -): MediaSourceDesc = MediaSourceDesc( - arrayOf( - RtpEncodingDesc(ssrc1.toLong(), arrayOf(ld7_5, ld15, ld30)), - RtpEncodingDesc(ssrc2.toLong(), arrayOf(sd7_5, sd15, sd30)), - RtpEncodingDesc(ssrc3.toLong(), arrayOf(hd7_5, hd15, hd30)) - ), - sourceName = sourceName, - owner = owner -) +fun createSourceDesc(ssrc1: Int, ssrc2: Int, ssrc3: Int, sourceName: String, owner: String): MediaSourceDesc = + MediaSourceDesc( + arrayOf( + RtpEncodingDesc(ssrc1.toLong(), arrayOf(ld7_5, ld15, ld30)), + RtpEncodingDesc(ssrc2.toLong(), arrayOf(sd7_5, sd15, sd30)), + RtpEncodingDesc(ssrc3.toLong(), arrayOf(hd7_5, hd15, hd30)) + ), + sourceName = sourceName, + owner = owner + ) val bitrateLd = 150.kbps val bitrateSd = 500.kbps diff --git a/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/BitrateControllerTraceTest.kt b/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/BitrateControllerTraceTest.kt index f4a0d20cdf..88b8003aef 100644 --- a/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/BitrateControllerTraceTest.kt +++ b/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/BitrateControllerTraceTest.kt @@ -38,13 +38,13 @@ class BitrateControllerTraceTest : ShouldSpec() { override fun isolationMode() = IsolationMode.InstancePerLeaf private val clock = FakeClock() - private val A = Endpoint("A") - private val B = Endpoint("B") - private val C = Endpoint("C") - private val D = Endpoint("D") - private val E = Endpoint("E") - private val F = Endpoint("F") - private val bc = BitrateControllerWrapper(listOf(A, B, C, D, E, F), clock = clock).apply { + private val a = Endpoint("A") + private val b = Endpoint("B") + private val c = Endpoint("C") + private val d = Endpoint("D") + private val e = Endpoint("E") + private val f = Endpoint("F") + private val bc = BitrateControllerWrapper(listOf(a, b, c, d, e, f), clock = clock).apply { bc.endpointOrderingChanged() } @@ -57,18 +57,18 @@ class BitrateControllerTraceTest : ShouldSpec() { println("Read ${parsedLines.size} events.") parsedLines.forEach { line -> clock.setTime(line.time) - A.layer7.bitrate = line.bps_a_7.bps - A.layer30.bitrate = line.bps_a_30.bps - B.layer7.bitrate = line.bps_b_7.bps - B.layer30.bitrate = line.bps_b_30.bps - C.layer7.bitrate = line.bps_c_7.bps - C.layer30.bitrate = line.bps_c_30.bps - D.layer7.bitrate = line.bps_d_7.bps - D.layer30.bitrate = line.bps_d_30.bps - E.layer7.bitrate = line.bps_e_7.bps - E.layer30.bitrate = line.bps_e_30.bps - F.layer7.bitrate = line.bps_f_7.bps - F.layer30.bitrate = line.bps_f_30.bps + a.layer7.bitrate = line.bps_a_7.bps + a.layer30.bitrate = line.bps_a_30.bps + b.layer7.bitrate = line.bps_b_7.bps + b.layer30.bitrate = line.bps_b_30.bps + c.layer7.bitrate = line.bps_c_7.bps + c.layer30.bitrate = line.bps_c_30.bps + d.layer7.bitrate = line.bps_d_7.bps + d.layer30.bitrate = line.bps_d_30.bps + e.layer7.bitrate = line.bps_e_7.bps + e.layer30.bitrate = line.bps_e_30.bps + f.layer7.bitrate = line.bps_f_7.bps + f.layer30.bitrate = line.bps_f_30.bps bc.bwe = line.bwe.bps } diff --git a/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/EffectiveConstraintsTest.kt b/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/EffectiveConstraintsTest.kt index b149d33672..0e572c3dfd 100644 --- a/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/EffectiveConstraintsTest.kt +++ b/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/EffectiveConstraintsTest.kt @@ -23,11 +23,7 @@ import org.jitsi.nlj.MediaSourceDesc import org.jitsi.nlj.VideoType import org.jitsi.videobridge.cc.config.BitrateControllerConfig -fun testSource( - endpointId: String, - sourceName: String, - videoType: VideoType = VideoType.CAMERA -): MediaSourceDesc { +fun testSource(endpointId: String, sourceName: String, videoType: VideoType = VideoType.CAMERA): MediaSourceDesc { return MediaSourceDesc( emptyArray(), endpointId, diff --git a/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/SingleSourceAllocationTest.kt b/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/SingleSourceAllocationTest.kt index 4868548329..209cff377c 100644 --- a/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/SingleSourceAllocationTest.kt +++ b/jvb/src/test/kotlin/org/jitsi/videobridge/cc/allocation/SingleSourceAllocationTest.kt @@ -35,15 +35,18 @@ class SingleSourceAllocationTest : ShouldSpec() { private val clock = FakeClock() private val diagnosticContext = DiagnosticContext() - private val ld7_5 = MockRtpLayerDesc(tid = 0, eid = 0, height = 180, frameRate = 7.5, bitrate = bitrateLd * 0.33) + private val ld7point5 = + MockRtpLayerDesc(tid = 0, eid = 0, height = 180, frameRate = 7.5, bitrate = bitrateLd * 0.33) private val ld15 = MockRtpLayerDesc(tid = 1, eid = 0, height = 180, frameRate = 15.0, bitrate = bitrateLd * 0.66) private val ld30 = MockRtpLayerDesc(tid = 2, eid = 0, height = 180, frameRate = 30.0, bitrate = bitrateLd) - private val sd7_5 = MockRtpLayerDesc(tid = 0, eid = 1, height = 360, frameRate = 7.5, bitrate = bitrateSd * 0.33) + private val sd7point5 = + MockRtpLayerDesc(tid = 0, eid = 1, height = 360, frameRate = 7.5, bitrate = bitrateSd * 0.33) private val sd15 = MockRtpLayerDesc(tid = 1, eid = 1, height = 360, frameRate = 15.0, bitrate = bitrateSd * 0.66) private val sd30 = MockRtpLayerDesc(tid = 2, eid = 1, height = 360, frameRate = 30.0, bitrate = bitrateSd) - private val hd7_5 = MockRtpLayerDesc(tid = 0, eid = 2, height = 720, frameRate = 7.5, bitrate = bitrateHd * 0.33) + private val hd7point5 = + MockRtpLayerDesc(tid = 0, eid = 2, height = 720, frameRate = 7.5, bitrate = bitrateHd * 0.33) private val hd15 = MockRtpLayerDesc(tid = 1, eid = 2, height = 720, frameRate = 15.0, bitrate = bitrateHd * 0.66) private val hd30 = MockRtpLayerDesc(tid = 2, eid = 2, height = 720, frameRate = 30.0, bitrate = bitrateHd) @@ -53,12 +56,12 @@ class SingleSourceAllocationTest : ShouldSpec() { val endpointId = "A" val mediaSource = MediaSourceDesc( arrayOf( - RtpEncodingDesc(1L, arrayOf(ld7_5, ld15, ld30)), - RtpEncodingDesc(1L, arrayOf(sd7_5, sd15, sd30)), - RtpEncodingDesc(1L, arrayOf(hd7_5, hd15, hd30)) + RtpEncodingDesc(1L, arrayOf(ld7point5, ld15, ld30)), + RtpEncodingDesc(1L, arrayOf(sd7point5, sd15, sd30)), + RtpEncodingDesc(1L, arrayOf(hd7point5, hd15, hd30)) ), - sourceName = sourceName, - owner = owner, + sourceName = SOURCE_NAME, + owner = OWNER, videoType = VideoType.CAMERA ) @@ -77,7 +80,7 @@ class SingleSourceAllocationTest : ShouldSpec() { // "preferred FPS") layers for higher resolutions. allocation.preferredLayer shouldBe sd30 allocation.oversendLayer shouldBe null - allocation.layers.map { it.layer } shouldBe listOf(ld7_5, ld15, ld30, sd30, hd30) + allocation.layers.map { it.layer } shouldBe listOf(ld7point5, ld15, ld30, sd30, hd30) } context("With constraints") { val allocation = @@ -94,16 +97,16 @@ class SingleSourceAllocationTest : ShouldSpec() { // "preferred FPS") layers for higher resolutions. allocation.preferredLayer shouldBe sd30 allocation.oversendLayer shouldBe null - allocation.layers.map { it.layer } shouldBe listOf(ld7_5, ld15, ld30, sd30) + allocation.layers.map { it.layer } shouldBe listOf(ld7point5, ld15, ld30, sd30) } context("With constraints unmet by any layer") { // Single high-res stream with 3 temporal layers. val endpointId = "A" val mediaSource = MediaSourceDesc( // No simulcast. - arrayOf(RtpEncodingDesc(1L, arrayOf(hd7_5, hd15, hd30))), - sourceName = sourceName, - owner = owner, + arrayOf(RtpEncodingDesc(1L, arrayOf(hd7point5, hd15, hd30))), + sourceName = SOURCE_NAME, + owner = OWNER, videoType = VideoType.CAMERA ) @@ -121,7 +124,7 @@ class SingleSourceAllocationTest : ShouldSpec() { // The receiver set 360p constraints, but we only have a 720p stream. allocation.preferredLayer shouldBe hd30 allocation.oversendLayer shouldBe null - allocation.layers.map { it.layer } shouldBe listOf(hd7_5, hd15, hd30) + allocation.layers.map { it.layer } shouldBe listOf(hd7point5, hd15, hd30) } context("Zero constraints") { val allocation = @@ -144,18 +147,18 @@ class SingleSourceAllocationTest : ShouldSpec() { context("When some layers are inactive") { // Override layers with bitrate=0. Simulate only up to 360p/15 being active. val sd30 = MockRtpLayerDesc(tid = 2, eid = 1, height = 360, frameRate = 30.0, bitrate = 0.bps) - val hd7_5 = MockRtpLayerDesc(tid = 0, eid = 2, height = 720, frameRate = 7.5, bitrate = 0.bps) + val hd7point5 = MockRtpLayerDesc(tid = 0, eid = 2, height = 720, frameRate = 7.5, bitrate = 0.bps) val hd15 = MockRtpLayerDesc(tid = 1, eid = 2, height = 720, frameRate = 15.0, bitrate = 0.bps) val hd30 = MockRtpLayerDesc(tid = 2, eid = 2, height = 720, frameRate = 30.0, bitrate = 0.bps) val endpointId = "A" val mediaSource = MediaSourceDesc( arrayOf( - RtpEncodingDesc(1L, arrayOf(ld7_5, ld15, ld30)), - RtpEncodingDesc(1L, arrayOf(sd7_5, sd15, sd30)), - RtpEncodingDesc(1L, arrayOf(hd7_5, hd15, hd30)) + RtpEncodingDesc(1L, arrayOf(ld7point5, ld15, ld30)), + RtpEncodingDesc(1L, arrayOf(sd7point5, sd15, sd30)), + RtpEncodingDesc(1L, arrayOf(hd7point5, hd15, hd30)) ), - sourceName = sourceName, - owner = owner, + sourceName = SOURCE_NAME, + owner = OWNER, videoType = VideoType.CAMERA ) @@ -173,7 +176,7 @@ class SingleSourceAllocationTest : ShouldSpec() { // "preferred FPS") layers for higher resolutions. allocation.preferredLayer shouldBe ld30 allocation.oversendLayer shouldBe null - allocation.layers.map { it.layer } shouldBe listOf(ld7_5, ld15, ld30) + allocation.layers.map { it.layer } shouldBe listOf(ld7point5, ld15, ld30) } } context("Screensharing") { @@ -181,12 +184,12 @@ class SingleSourceAllocationTest : ShouldSpec() { val endpointId = "A" val mediaSource = MediaSourceDesc( arrayOf( - RtpEncodingDesc(1L, arrayOf(ld7_5, ld15, ld30)), - RtpEncodingDesc(1L, arrayOf(sd7_5, sd15, sd30)), - RtpEncodingDesc(1L, arrayOf(hd7_5, hd15, hd30)) + RtpEncodingDesc(1L, arrayOf(ld7point5, ld15, ld30)), + RtpEncodingDesc(1L, arrayOf(sd7point5, sd15, sd30)), + RtpEncodingDesc(1L, arrayOf(hd7point5, hd15, hd30)) ), - sourceName = sourceName, - owner = owner, + sourceName = SOURCE_NAME, + owner = OWNER, videoType = VideoType.DESKTOP ) @@ -204,9 +207,9 @@ class SingleSourceAllocationTest : ShouldSpec() { // For screensharing the "preferred" layer should be the highest -- always prioritized over other // endpoints. allocation.preferredLayer shouldBe hd30 - allocation.oversendLayer shouldBe hd7_5 + allocation.oversendLayer shouldBe hd7point5 allocation.layers.map { it.layer } shouldBe - listOf(ld7_5, ld15, ld30, sd7_5, sd15, sd30, hd7_5, hd15, hd30) + listOf(ld7point5, ld15, ld30, sd7point5, sd15, sd30, hd7point5, hd15, hd30) } context("With 360p constraints") { val allocation = @@ -220,23 +223,23 @@ class SingleSourceAllocationTest : ShouldSpec() { ) allocation.preferredLayer shouldBe sd30 - allocation.oversendLayer shouldBe sd7_5 - allocation.layers.map { it.layer } shouldBe listOf(ld7_5, ld15, ld30, sd7_5, sd15, sd30) + allocation.oversendLayer shouldBe sd7point5 + allocation.layers.map { it.layer } shouldBe listOf(ld7point5, ld15, ld30, sd7point5, sd15, sd30) } } context("The high layers are inactive (send-side bwe restrictions)") { // Override layers with bitrate=0. Simulate only up to 360p/30 being active. - val hd7_5 = MockRtpLayerDesc(tid = 0, eid = 2, height = 720, frameRate = 7.5, bitrate = 0.bps) + val hd7point5 = MockRtpLayerDesc(tid = 0, eid = 2, height = 720, frameRate = 7.5, bitrate = 0.bps) val hd15 = MockRtpLayerDesc(tid = 1, eid = 2, height = 720, frameRate = 15.0, bitrate = 0.bps) val hd30 = MockRtpLayerDesc(tid = 2, eid = 2, height = 720, frameRate = 30.0, bitrate = 0.bps) val mediaSource = MediaSourceDesc( arrayOf( - RtpEncodingDesc(1L, arrayOf(ld7_5, ld15, ld30)), - RtpEncodingDesc(1L, arrayOf(sd7_5, sd15, sd30)), - RtpEncodingDesc(1L, arrayOf(hd7_5, hd15, hd30)) + RtpEncodingDesc(1L, arrayOf(ld7point5, ld15, ld30)), + RtpEncodingDesc(1L, arrayOf(sd7point5, sd15, sd30)), + RtpEncodingDesc(1L, arrayOf(hd7point5, hd15, hd30)) ), - sourceName = sourceName, - owner = owner, + sourceName = SOURCE_NAME, + owner = OWNER, videoType = VideoType.DESKTOP ) @@ -253,25 +256,25 @@ class SingleSourceAllocationTest : ShouldSpec() { // For screensharing the "preferred" layer should be the highest -- always prioritized over other // endpoints. allocation.preferredLayer shouldBe sd30 - allocation.oversendLayer shouldBe sd7_5 - allocation.layers.map { it.layer } shouldBe listOf(ld7_5, ld15, ld30, sd7_5, sd15, sd30) + allocation.oversendLayer shouldBe sd7point5 + allocation.layers.map { it.layer } shouldBe listOf(ld7point5, ld15, ld30, sd7point5, sd15, sd30) } context("The low layers are inactive (simulcast signaled but not used)") { // Override layers with bitrate=0. Simulate simulcast being signaled but effectively disabled. - val ld7_5 = MockRtpLayerDesc(tid = 0, eid = 2, height = 720, frameRate = 7.5, bitrate = 0.bps) + val ld7point5 = MockRtpLayerDesc(tid = 0, eid = 2, height = 720, frameRate = 7.5, bitrate = 0.bps) val ld15 = MockRtpLayerDesc(tid = 1, eid = 2, height = 720, frameRate = 15.0, bitrate = 0.bps) val ld30 = MockRtpLayerDesc(tid = 2, eid = 2, height = 720, frameRate = 30.0, bitrate = 0.bps) - val sd7_5 = MockRtpLayerDesc(tid = 0, eid = 1, height = 360, frameRate = 7.5, bitrate = 0.bps) + val sd7point5 = MockRtpLayerDesc(tid = 0, eid = 1, height = 360, frameRate = 7.5, bitrate = 0.bps) val sd15 = MockRtpLayerDesc(tid = 1, eid = 1, height = 360, frameRate = 15.0, bitrate = 0.bps) val sd30 = MockRtpLayerDesc(tid = 2, eid = 1, height = 360, frameRate = 30.0, bitrate = 0.bps) val mediaSource = MediaSourceDesc( arrayOf( - RtpEncodingDesc(1L, arrayOf(ld7_5, ld15, ld30)), - RtpEncodingDesc(1L, arrayOf(sd7_5, sd15, sd30)), - RtpEncodingDesc(1L, arrayOf(hd7_5, hd15, hd30)) + RtpEncodingDesc(1L, arrayOf(ld7point5, ld15, ld30)), + RtpEncodingDesc(1L, arrayOf(sd7point5, sd15, sd30)), + RtpEncodingDesc(1L, arrayOf(hd7point5, hd15, hd30)) ), - sourceName = sourceName, - owner = owner, + sourceName = SOURCE_NAME, + owner = OWNER, videoType = VideoType.DESKTOP ) @@ -289,8 +292,8 @@ class SingleSourceAllocationTest : ShouldSpec() { // For screensharing the "preferred" layer should be the highest -- always prioritized over other // endpoints. allocation.preferredLayer shouldBe hd30 - allocation.oversendLayer shouldBe hd7_5 - allocation.layers.map { it.layer } shouldBe listOf(hd7_5, hd15, hd30) + allocation.oversendLayer shouldBe hd7point5 + allocation.layers.map { it.layer } shouldBe listOf(hd7point5, hd15, hd30) } context("With 180p constraints") { val allocation = @@ -307,8 +310,8 @@ class SingleSourceAllocationTest : ShouldSpec() { // endpoints. Since no layers satisfy the resolution constraints, we consider layers from the // lowest available resolution (which is high). allocation.preferredLayer shouldBe hd30 - allocation.oversendLayer shouldBe hd7_5 - allocation.layers.map { it.layer } shouldBe listOf(hd7_5, hd15, hd30) + allocation.oversendLayer shouldBe hd7point5 + allocation.layers.map { it.layer } shouldBe listOf(hd7point5, hd15, hd30) } } context("VP9") { @@ -322,8 +325,8 @@ class SingleSourceAllocationTest : ShouldSpec() { RtpEncodingDesc(1L, arrayOf(l2)), RtpEncodingDesc(1L, arrayOf(l3)) ), - sourceName = sourceName, - owner = owner, + sourceName = SOURCE_NAME, + owner = OWNER, videoType = VideoType.DESKTOP ) @@ -381,5 +384,5 @@ class SingleSourceAllocationTest : ShouldSpec() { } } -private val sourceName = "sourceName" -private val owner = "owner" +private const val SOURCE_NAME = "sourceName" +private const val OWNER = "owner" diff --git a/jvb/src/test/kotlin/org/jitsi/videobridge/cc/vp9/Vp9AdaptiveSourceProjectionTest.kt b/jvb/src/test/kotlin/org/jitsi/videobridge/cc/vp9/Vp9AdaptiveSourceProjectionTest.kt index 174c814445..5c89fd6c36 100644 --- a/jvb/src/test/kotlin/org/jitsi/videobridge/cc/vp9/Vp9AdaptiveSourceProjectionTest.kt +++ b/jvb/src/test/kotlin/org/jitsi/videobridge/cc/vp9/Vp9AdaptiveSourceProjectionTest.kt @@ -1373,12 +1373,18 @@ class Vp9AdaptiveSourceProjectionTest { } } companion object { - private val vp9PacketTemplate = DatatypeConverter.parseHexBinary( // RTP Header - "80" + // V, P, X, CC - "60" + // M, PT - "0000" + // Seq - "00000000" + // TS - "cafebabe" + // SSRC + private val vp9PacketTemplate = DatatypeConverter.parseHexBinary( + // RTP Header + // V, P, X, CC + "80" + + // M, PT + "60" + + // Seq + "0000" + + // TS + "00000000" + + // SSRC + "cafebabe" + // VP9 Payload descriptor // I=1,P=0,L=0,F=0,B=1,E=0,V=0,Z=0 "88" + @@ -1563,12 +1569,18 @@ class Vp9AdaptiveSourceProjectionTest { } companion object { - private val vp9SvcPacketTemplate = DatatypeConverter.parseHexBinary( // RTP Header - "80" + // V, P, X, CC - "60" + // M, PT - "0000" + // Seq - "00000000" + // TS - "cafebabe" + // SSRC + private val vp9SvcPacketTemplate = DatatypeConverter.parseHexBinary( + // RTP Header + // V, P, X, CC + "80" + + // M, PT + "60" + + // Seq + "0000" + + // TS + "00000000" + + // SSRC + "cafebabe" + // VP9 Payload descriptor // I=1,P=0,L=1,F=0,B=1,E=0,V=0,Z=0 "a8" + @@ -1584,8 +1596,9 @@ class Vp9AdaptiveSourceProjectionTest { ) /* TODO: move this to jitsi-rtp */ + const val JAVA_TO_NTP_EPOCH_OFFSET_SECS = 2208988800L + fun setSIBuilderNtp(siBuilder: SenderInfoBuilder, wallTime: Long) { - val JAVA_TO_NTP_EPOCH_OFFSET_SECS = 2208988800L val wallSecs = wallTime / 1000 val wallMs = wallTime % 1000 siBuilder.ntpTimestampMsw = wallSecs + JAVA_TO_NTP_EPOCH_OFFSET_SECS diff --git a/jvb/src/test/kotlin/org/jitsi/videobridge/cc/vp9/Vp9QualityFilterTest.kt b/jvb/src/test/kotlin/org/jitsi/videobridge/cc/vp9/Vp9QualityFilterTest.kt index 07bb90c2d0..d32cb07ed5 100644 --- a/jvb/src/test/kotlin/org/jitsi/videobridge/cc/vp9/Vp9QualityFilterTest.kt +++ b/jvb/src/test/kotlin/org/jitsi/videobridge/cc/vp9/Vp9QualityFilterTest.kt @@ -416,7 +416,11 @@ internal class Vp9QualityFilterTest : ShouldSpec() { while (g.hasNext() && frames < numFrames) { val f = g.next() - ms = if (f.timestamp != lastTs) { f.timestamp / 90 } else { ms + 1 } + ms = if (f.timestamp != lastTs) { + f.timestamp / 90 + } else { + ms + 1 + } lastTs = f.timestamp val packetIndex = RtpLayerDesc.getIndex(f.ssrc.toInt(), f.spatialLayer, f.temporalLayer) @@ -645,7 +649,8 @@ private class SimulcastFrameGenerator : FrameGenerator() { val keyframePicture = (pictureCount % 48) == 0 val f = Vp9Frame( - ssrc = enc.toLong(), // Use the encoding ID as the SSRC to make testing easier. + // Use the encoding ID as the SSRC to make testing easier. + ssrc = enc.toLong(), timestamp = pictureCount * 3000L, earliestKnownSequenceNumber = pictureCount + (enc * 10000), latestKnownSequenceNumber = pictureCount + (enc * 10000), diff --git a/pom.xml b/pom.xml index 1d9a16b7f2..d6c757d636 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,7 @@ 1.0-127-g6c65524 1.1-127-gf49982f 1.13.8 - 2.0.0 + 3.0.0 3.5.1 4.6.0 3.0.10 diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/UnparsedPacket.kt b/rtp/src/main/kotlin/org/jitsi/rtp/UnparsedPacket.kt index 16bd5f738f..d839c4e14e 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/UnparsedPacket.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/UnparsedPacket.kt @@ -30,10 +30,9 @@ class UnparsedPacket( * Note that we leave the same space at the start as for RTP packets, because an [UnparsedPacket]'s buffer * might be used directly to create an [RtpPacket]. */ - override fun clone(): UnparsedPacket = - UnparsedPacket( - cloneBuffer(RtpPacket.BYTES_TO_LEAVE_AT_START_OF_PACKET), - RtpPacket.BYTES_TO_LEAVE_AT_START_OF_PACKET, - length - ) + override fun clone(): UnparsedPacket = UnparsedPacket( + cloneBuffer(RtpPacket.BYTES_TO_LEAVE_AT_START_OF_PACKET), + RtpPacket.BYTES_TO_LEAVE_AT_START_OF_PACKET, + length + ) } diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/extensions/ByteBuffer.kt b/rtp/src/main/kotlin/org/jitsi/rtp/extensions/ByteBuffer.kt index 629f4eb2d4..3b396176b9 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/extensions/ByteBuffer.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/extensions/ByteBuffer.kt @@ -151,8 +151,7 @@ fun ByteBuffer.subBuffer(startPosition: Int, size: Int): ByteBuffer { * and capacity will be the amount of bytes between [startPosition] and * the current buffer's [limit()] */ -fun ByteBuffer.subBuffer(startPosition: Int): ByteBuffer = - subBuffer(startPosition, limit() - startPosition) +fun ByteBuffer.subBuffer(startPosition: Int): ByteBuffer = subBuffer(startPosition, limit() - startPosition) /** * Put [buf] into this buffer starting at [index] diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/extensions/bytearray/ByteArrayExtensions.kt b/rtp/src/main/kotlin/org/jitsi/rtp/extensions/bytearray/ByteArrayExtensions.kt index c353b9baed..8c4e191e78 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/extensions/bytearray/ByteArrayExtensions.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/extensions/bytearray/ByteArrayExtensions.kt @@ -38,8 +38,7 @@ fun ByteArray.putBits(byteIndex: Int, destBitPos: Int, src: Byte, numBits: Int) set(byteIndex, byte) } -fun ByteArray.getBitAsBool(byteOffset: Int, bitOffset: Int): Boolean = - get(byteOffset).getBitAsBool(bitOffset) +fun ByteArray.getBitAsBool(byteOffset: Int, bitOffset: Int): Boolean = get(byteOffset).getBitAsBool(bitOffset) fun ByteArray.putBitAsBoolean(byteIndex: Int, destBitPos: Int, isSet: Boolean) { var byte = get(byteIndex) diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/RtcpReportBlock.kt b/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/RtcpReportBlock.kt index 3f1ed76522..85d66f8f02 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/RtcpReportBlock.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/RtcpReportBlock.kt @@ -115,13 +115,10 @@ class RtcpReportBlock( ) } - fun getSsrc(buffer: ByteArray, offset: Int): Long = - buffer.getIntAsLong(offset + SSRC_OFFSET) - fun setSsrc(buf: ByteArray, baseOffset: Int, value: Long) = - buf.putInt(baseOffset + SSRC_OFFSET, value.toInt()) + fun getSsrc(buffer: ByteArray, offset: Int): Long = buffer.getIntAsLong(offset + SSRC_OFFSET) + fun setSsrc(buf: ByteArray, baseOffset: Int, value: Long) = buf.putInt(baseOffset + SSRC_OFFSET, value.toInt()) - fun getFractionLost(buffer: ByteArray, offset: Int): Int = - buffer.getByteAsInt(offset + FRACTION_LOST_OFFSET) + fun getFractionLost(buffer: ByteArray, offset: Int): Int = buffer.getByteAsInt(offset + FRACTION_LOST_OFFSET) fun setFractionLost(buf: ByteArray, baseOffset: Int, value: Int) = buf.set(baseOffset + FRACTION_LOST_OFFSET, value.toByte()) diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/RtcpRrPacket.kt b/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/RtcpRrPacket.kt index 6f20d7dd93..2e76ab655f 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/RtcpRrPacket.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/RtcpRrPacket.kt @@ -76,8 +76,7 @@ data class RtcpRrPacketBuilder( require(reportBlocks.size <= 31) { "Too many report blocks ${reportBlocks.size}: RR can contain at most 31" } } - private fun getLengthValue(): Int = - RtpUtils.calculateRtcpLengthFieldValue(sizeBytes) + private fun getLengthValue(): Int = RtpUtils.calculateRtcpLengthFieldValue(sizeBytes) private val sizeBytes: Int get() = RtcpHeader.SIZE_BYTES + reportBlocks.size * RtcpReportBlock.SIZE_BYTES diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/RtcpSdesPacket.kt b/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/RtcpSdesPacket.kt index 30cca023a1..a400ce89ce 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/RtcpSdesPacket.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/RtcpSdesPacket.kt @@ -92,8 +92,7 @@ class SdesChunk( const val SSRC_OFFSET = 0 const val SDES_ITEMS_OFFSET = 4 - fun getSsrc(buf: ByteArray, baseOffset: Int): Long = - buf.getIntAsLong(baseOffset + SSRC_OFFSET) + fun getSsrc(buf: ByteArray, baseOffset: Int): Long = buf.getIntAsLong(baseOffset + SSRC_OFFSET) fun getSdesItems(buf: ByteArray, baseOffset: Int): List { var currOffset = baseOffset + SDES_ITEMS_OFFSET @@ -142,11 +141,9 @@ abstract class SdesItem( const val LENGTH_OFFSET = 1 const val DATA_OFFSET = 2 - fun getType(buf: ByteArray, baseOffset: Int): Int = - buf.getByteAsInt(baseOffset + TYPE_OFFSET) + fun getType(buf: ByteArray, baseOffset: Int): Int = buf.getByteAsInt(baseOffset + TYPE_OFFSET) - fun getLength(buf: ByteArray, baseOffset: Int): Int = - buf.getByteAsInt(baseOffset + LENGTH_OFFSET) + fun getLength(buf: ByteArray, baseOffset: Int): Int = buf.getByteAsInt(baseOffset + LENGTH_OFFSET) fun copyData(buf: ByteArray, baseOffset: Int, dataLength: Int): ByteArray { if (dataLength <= 0) { diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/RtcpSrPacket.kt b/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/RtcpSrPacket.kt index 7b2d08b167..750f92e590 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/RtcpSrPacket.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/RtcpSrPacket.kt @@ -46,18 +46,15 @@ class SenderInfoParser { const val SENDERS_PACKET_COUNT_OFFSET = 12 const val SENDERS_OCTET_COUNT_OFFSET = 16 - fun getNtpTimestampMsw(buf: ByteArray, baseOffset: Int): Long = - buf.getIntAsLong(baseOffset + NTP_TS_MSW_OFFSET) + fun getNtpTimestampMsw(buf: ByteArray, baseOffset: Int): Long = buf.getIntAsLong(baseOffset + NTP_TS_MSW_OFFSET) fun setNtpTimestampMsw(buf: ByteArray, baseOffset: Int, value: Long) = buf.putInt(baseOffset + NTP_TS_MSW_OFFSET, value.toInt()) - fun getNtpTimestampLsw(buf: ByteArray, baseOffset: Int): Long = - buf.getIntAsLong(baseOffset + NTP_TS_LSW_OFFSET) + fun getNtpTimestampLsw(buf: ByteArray, baseOffset: Int): Long = buf.getIntAsLong(baseOffset + NTP_TS_LSW_OFFSET) fun setNtpTimestampLsw(buf: ByteArray, baseOffset: Int, value: Long) = buf.putInt(baseOffset + NTP_TS_LSW_OFFSET, value.toInt()) - fun getRtpTimestamp(buf: ByteArray, baseOffset: Int): Long = - buf.getIntAsLong(baseOffset + RTP_TS_OFFSET) + fun getRtpTimestamp(buf: ByteArray, baseOffset: Int): Long = buf.getIntAsLong(baseOffset + RTP_TS_OFFSET) fun setRtpTimestamp(buf: ByteArray, baseOffset: Int, value: Long) = buf.putInt(baseOffset + RTP_TS_OFFSET, value.toInt()) diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/UnsupportedRtcpPacket.kt b/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/UnsupportedRtcpPacket.kt index 9b60438085..8a2f56e03e 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/UnsupportedRtcpPacket.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/UnsupportedRtcpPacket.kt @@ -25,6 +25,5 @@ class UnsupportedRtcpPacket( offset: Int, packetLengthBytes: Int ) : RtcpPacket(buf, offset, packetLengthBytes) { - override fun clone(): UnsupportedRtcpPacket = - UnsupportedRtcpPacket(cloneBuffer(0), 0, length) + override fun clone(): UnsupportedRtcpPacket = UnsupportedRtcpPacket(cloneBuffer(0), 0, length) } diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/RtcpFbPacket.kt b/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/RtcpFbPacket.kt index 9c97c521ff..99a2395557 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/RtcpFbPacket.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/RtcpFbPacket.kt @@ -62,8 +62,7 @@ abstract class RtcpFbPacket( const val HEADER_SIZE = RtcpHeader.SIZE_BYTES + 4 const val FCI_OFFSET = HEADER_SIZE - fun getFmt(buf: ByteArray, baseOffset: Int): Int = - RtcpHeader.getReportCount(buf, baseOffset) + fun getFmt(buf: ByteArray, baseOffset: Int): Int = RtcpHeader.getReportCount(buf, baseOffset) fun getMediaSourceSsrc(buf: ByteArray, baseOffset: Int): Long = buf.getInt(baseOffset + MEDIA_SOURCE_SSRC_OFFSET).toPositiveLong() fun setMediaSourceSsrc(buf: ByteArray, baseOffset: Int, value: Long) = diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/UnsupportedRtcpFbPacket.kt b/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/UnsupportedRtcpFbPacket.kt index 1fbededa16..b35c2e5fef 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/UnsupportedRtcpFbPacket.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/UnsupportedRtcpFbPacket.kt @@ -25,6 +25,5 @@ class UnsupportedRtcpFbPacket( offset: Int, packetLengthBytes: Int ) : RtcpFbPacket(buf, offset, packetLengthBytes) { - override fun clone(): UnsupportedRtcpFbPacket = - UnsupportedRtcpFbPacket(cloneBuffer(0), 0, length) + override fun clone(): UnsupportedRtcpFbPacket = UnsupportedRtcpFbPacket(cloneBuffer(0), 0, length) } diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/payload_specific_fb/RtcpFbFirPacket.kt b/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/payload_specific_fb/RtcpFbFirPacket.kt index a68dbed81c..51e97b7f5c 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/payload_specific_fb/RtcpFbFirPacket.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/payload_specific_fb/RtcpFbFirPacket.kt @@ -87,8 +87,7 @@ class RtcpFbFirPacket( fun setMediaSenderSsrc(buf: ByteArray, baseOffset: Int, value: Long) = buf.putInt(baseOffset + MEDIA_SENDER_SSRC_OFFSET, value.toInt()) - fun getSeqNum(buf: ByteArray, baseOffset: Int): Int = - buf.get(baseOffset + SEQ_NUM_OFFSET).toPositiveInt() + fun getSeqNum(buf: ByteArray, baseOffset: Int): Int = buf.get(baseOffset + SEQ_NUM_OFFSET).toPositiveInt() fun setSeqNum(buf: ByteArray, baseOffset: Int, value: Int) = buf.set(baseOffset + SEQ_NUM_OFFSET, value.toByte()) } diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/payload_specific_fb/RtcpFbRembPacket.kt b/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/payload_specific_fb/RtcpFbRembPacket.kt index e3cad2cc72..cc69313964 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/payload_specific_fb/RtcpFbRembPacket.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/payload_specific_fb/RtcpFbRembPacket.kt @@ -87,8 +87,7 @@ class RtcpFbRembPacket( const val BR_LEN = 3 const val SSRCS_OFF = BR_OFF + BR_LEN - fun getBrExp(buf: ByteArray, baseOffset: Int): Int = - buf.getBitsAsInt(baseOffset + BR_OFF, 0, 6) + fun getBrExp(buf: ByteArray, baseOffset: Int): Int = buf.getBitsAsInt(baseOffset + BR_OFF, 0, 6) fun getBrMantissa(buf: ByteArray, baseOffset: Int): Int = (buf.getBitsAsInt(baseOffset + BR_OFF, 6, 2) shl 16) + buf.getShortAsInt(baseOffset + BR_OFF + 1) fun getBitrate(buf: ByteArray, baseOffset: Int): Long { @@ -104,8 +103,7 @@ class RtcpFbRembPacket( return brBps } - fun getNumSsrc(buf: ByteArray, baseOffset: Int): Int = - buf.getByteAsInt(baseOffset + NUM_SSRC_OFF) + fun getNumSsrc(buf: ByteArray, baseOffset: Int): Int = buf.getByteAsInt(baseOffset + NUM_SSRC_OFF) fun getSsrc(buf: ByteArray, baseOffset: Int, ssrcIndex: Int) = buf.getIntAsLong(baseOffset + SSRCS_OFF + ssrcIndex * 4) diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/transport_layer_fb/tcc/LastChunk.kt b/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/transport_layer_fb/tcc/LastChunk.kt index 3522780c0a..9d23e0732b 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/transport_layer_fb/tcc/LastChunk.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/transport_layer_fb/tcc/LastChunk.kt @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +@file:Suppress("ktlint:standard:property-naming", "ktlint:standard:function-naming") package org.jitsi.rtp.rtcp.rtcpfb.transport_layer_fb.tcc @@ -145,8 +146,7 @@ class LastChunk { * S = symbol * Run Length = Unsigned integer denoting the run length of the symbol */ - private fun EncodeRunLength(): Chunk = - ((delta_sizes_[0] shl 13) or size_) + private fun EncodeRunLength(): Chunk = ((delta_sizes_[0] shl 13) or size_) private fun DecodeRunLength(chunk: Chunk, max_count: Int) { size_ = min(chunk and 0x1fff, max_count) diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/transport_layer_fb/tcc/RtcpFbTccPacket.kt b/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/transport_layer_fb/tcc/RtcpFbTccPacket.kt index bf44629206..8566f34421 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/transport_layer_fb/tcc/RtcpFbTccPacket.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/rtcp/rtcpfb/transport_layer_fb/tcc/RtcpFbTccPacket.kt @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +@file:Suppress("ktlint:standard:property-naming", "ktlint:standard:function-naming") package org.jitsi.rtp.rtcp.rtcpfb.transport_layer_fb.tcc @@ -142,8 +143,7 @@ class RtcpFbTccPacketBuilder( return true } - fun GetBaseTimeUs(): Long = - base_time_ticks_ * kBaseScaleFactor + fun GetBaseTimeUs(): Long = base_time_ticks_ * kBaseScaleFactor private fun AddDeltaSize(deltaSize: DeltaSize): Boolean { if (num_seq_no_ == kMaxReportedPackets) { @@ -416,8 +416,7 @@ class RtcpFbTccPacket( val feedbackSeqNum: Int = getFeedbackPacketCount(buffer, offset) - fun GetBaseTimeUs(): Long = - base_time_ticks_ * kBaseScaleFactor + fun GetBaseTimeUs(): Long = base_time_ticks_ * kBaseScaleFactor override fun iterator(): Iterator = packets_.iterator() @@ -456,8 +455,7 @@ class RtcpFbTccPacket( const val PACKET_CHUNKS_OFFSET = RtcpFbPacket.HEADER_SIZE + 8 // baseOffset in all of these refers to the start of the entire RTCP TCC packet - fun getBaseSeqNum(buf: ByteArray, baseOffset: Int): Int = - buf.getShortAsInt(baseOffset + BASE_SEQ_NUM_OFFSET) + fun getBaseSeqNum(buf: ByteArray, baseOffset: Int): Int = buf.getShortAsInt(baseOffset + BASE_SEQ_NUM_OFFSET) fun setBaseSeqNum(buf: ByteArray, baseOffset: Int, value: Int) = buf.putShort(baseOffset + BASE_SEQ_NUM_OFFSET, value.toShort()) diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/rtp/RedPacketParser.kt b/rtp/src/main/kotlin/org/jitsi/rtp/rtp/RedPacketParser.kt index 3e50868f45..6b7baafcdb 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/rtp/RedPacketParser.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/rtp/RedPacketParser.kt @@ -37,10 +37,7 @@ class RedPacketParser( * @param parseRedundancy whether to parse redundancy packets * @return The list of parsed redundancy packets. */ - fun decapsulate( - rtpPacket: RtpPacket, - parseRedundancy: Boolean - ): List = with(rtpPacket) { + fun decapsulate(rtpPacket: RtpPacket, parseRedundancy: Boolean): List = with(rtpPacket) { var currentOffset = payloadOffset val redundancyBlockHeaders = mutableListOf() @@ -214,12 +211,11 @@ class RedundancyBlockHeader( } internal class RtpRedPacket(buffer: ByteArray, offset: Int, length: Int) : RtpPacket(buffer, offset, length) { - override fun clone(): RtpRedPacket = - RtpRedPacket( - cloneBuffer(BYTES_TO_LEAVE_AT_START_OF_PACKET), - BYTES_TO_LEAVE_AT_START_OF_PACKET, - length - ) + override fun clone(): RtpRedPacket = RtpRedPacket( + cloneBuffer(BYTES_TO_LEAVE_AT_START_OF_PACKET), + BYTES_TO_LEAVE_AT_START_OF_PACKET, + length + ) companion object { val parser = RedPacketParser { b, o, l -> RtpPacket(b, o, l) } diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/rtp/RtpHeader.kt b/rtp/src/main/kotlin/org/jitsi/rtp/rtp/RtpHeader.kt index afa1b71c87..8f9477c07c 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/rtp/RtpHeader.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/rtp/RtpHeader.kt @@ -59,15 +59,13 @@ class RtpHeader { const val EXT_HEADER_SIZE_BYTES = 4 const val VERSION = 2 - fun getVersion(buf: ByteArray, baseOffset: Int): Int = - (buf[baseOffset].toInt() and 0xC0) ushr 6 + fun getVersion(buf: ByteArray, baseOffset: Int): Int = (buf[baseOffset].toInt() and 0xC0) ushr 6 fun setVersion(buf: ByteArray, baseOffset: Int, version: Int) { buf[baseOffset] = ((buf[baseOffset].toInt() and 0xC0.inv()) or ((version shl 6) and 0xC0)).toByte() } - fun hasPadding(buf: ByteArray, baseOffset: Int): Boolean = - (buf[baseOffset].toInt() and 0x20) == 0x20 + fun hasPadding(buf: ByteArray, baseOffset: Int): Boolean = (buf[baseOffset].toInt() and 0x20) == 0x20 fun setPadding(buf: ByteArray, baseOffset: Int, hasPadding: Boolean) { buf[baseOffset] = when (hasPadding) { true -> (buf[baseOffset].toInt() or 0x20).toByte() @@ -75,8 +73,7 @@ class RtpHeader { } } - fun hasExtensions(buf: ByteArray, baseOffset: Int): Boolean = - (buf[baseOffset].toInt() and 0x10) == 0x10 + fun hasExtensions(buf: ByteArray, baseOffset: Int): Boolean = (buf[baseOffset].toInt() and 0x10) == 0x10 fun setHasExtensions(buf: ByteArray, baseOffset: Int, hasExtension: Boolean) { buf[baseOffset] = when (hasExtension) { true -> (buf[baseOffset].toInt() or 0x10).toByte() @@ -84,14 +81,12 @@ class RtpHeader { } } - fun getCsrcCount(buf: ByteArray, baseOffset: Int): Int = - buf[baseOffset].toInt() and 0x0F + fun getCsrcCount(buf: ByteArray, baseOffset: Int): Int = buf[baseOffset].toInt() and 0x0F fun setCsrcCount(buf: ByteArray, baseOffset: Int, csrcCount: Int) { buf[baseOffset] = ((buf[baseOffset].toInt() and 0xF0) or ((csrcCount and 0x0F))).toByte() } - fun getMarker(buf: ByteArray, baseOffset: Int): Boolean = - (buf[baseOffset + 1].toInt() and 0x80) == 0x80 + fun getMarker(buf: ByteArray, baseOffset: Int): Boolean = (buf[baseOffset + 1].toInt() and 0x80) == 0x80 fun setMarker(buf: ByteArray, baseOffset: Int, isSet: Boolean) { buf[baseOffset + 1] = when (isSet) { true -> (buf[baseOffset + 1].toInt() or 0x80).toByte() @@ -105,20 +100,17 @@ class RtpHeader { buf[baseOffset + 1] = (buf[baseOffset + 1] and 0x80.toByte()) or (payloadType and 0x7F).toByte() } - fun getSequenceNumber(buf: ByteArray, baseOffset: Int): Int = - buf.getShortAsInt(baseOffset + 2) + fun getSequenceNumber(buf: ByteArray, baseOffset: Int): Int = buf.getShortAsInt(baseOffset + 2) fun setSequenceNumber(buf: ByteArray, baseOffset: Int, sequenceNumber: Int) { buf.putShort(baseOffset + 2, sequenceNumber.toShort()) } - fun getTimestamp(buf: ByteArray, baseOffset: Int): Long = - buf.getIntAsLong(baseOffset + 4) + fun getTimestamp(buf: ByteArray, baseOffset: Int): Long = buf.getIntAsLong(baseOffset + 4) fun setTimestamp(buf: ByteArray, baseOffset: Int, timestamp: Long) { buf.putInt(baseOffset + 4, timestamp.toInt()) } - fun getSsrc(buf: ByteArray, baseOffset: Int): Long = - buf.getIntAsLong(baseOffset + 8) + fun getSsrc(buf: ByteArray, baseOffset: Int): Long = buf.getIntAsLong(baseOffset + 8) fun setSsrc(buf: ByteArray, baseOffset: Int, ssrc: Long) { buf.putInt(baseOffset + 8, ssrc.toInt()) } @@ -162,12 +154,11 @@ class RtpHeader { * The "defined by profile" header extension field. Only valid if hasExtensions is true, otherwise * returns an invalid value (-1) */ - fun getExtensionsProfileType(buf: ByteArray, baseOffset: Int): Int = - if (hasExtensions(buf, baseOffset)) { - val extHeaderOffset = getFixedHeaderAndCcLength(buf, baseOffset) - HeaderExtensionHelpers.getExtensionsProfileType(buf, baseOffset + extHeaderOffset) - } else { - -1 - } + fun getExtensionsProfileType(buf: ByteArray, baseOffset: Int): Int = if (hasExtensions(buf, baseOffset)) { + val extHeaderOffset = getFixedHeaderAndCcLength(buf, baseOffset) + HeaderExtensionHelpers.getExtensionsProfileType(buf, baseOffset + extHeaderOffset) + } else { + -1 + } } } diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/rtp/RtpSequenceNumber.kt b/rtp/src/main/kotlin/org/jitsi/rtp/rtp/RtpSequenceNumber.kt index 1240c995ed..69f305e0ad 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/rtp/RtpSequenceNumber.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/rtp/RtpSequenceNumber.kt @@ -51,8 +51,7 @@ value class RtpSequenceNumber internal constructor(val value: Int) : Comparable< operator fun minus(num: Int): RtpSequenceNumber = plus(-num) operator fun minus(seqNum: RtpSequenceNumber): RtpSequenceNumber = plus(-seqNum.value) - override operator fun compareTo(other: RtpSequenceNumber): Int = - RtpUtils.getSequenceNumberDelta(value, other.value) + override operator fun compareTo(other: RtpSequenceNumber): Int = RtpUtils.getSequenceNumberDelta(value, other.value) operator fun rangeTo(other: RtpSequenceNumber) = RtpSequenceNumberProgression(this, other) diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/rtp/header_extensions/AbsSendTimeHeaderExtension.kt b/rtp/src/main/kotlin/org/jitsi/rtp/rtp/header_extensions/AbsSendTimeHeaderExtension.kt index 60de3e3264..f66eba0c31 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/rtp/header_extensions/AbsSendTimeHeaderExtension.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/rtp/header_extensions/AbsSendTimeHeaderExtension.kt @@ -38,14 +38,14 @@ class AbsSendTimeHeaderExtension { /** * One billion. */ - private const val b = 1_000_000_000 + private const val B = 1_000_000_000 fun setTime(ext: RtpPacket.HeaderExtension, timestampNanos: Long) = setTime(ext.buffer, ext.dataOffset, timestampNanos) private fun setTime(buf: ByteArray, offset: Int, timestampNanos: Long) { - val fraction = ((timestampNanos % b) * (1 shl 18) / b) - val seconds = ((timestampNanos / b) % 64) // 6 bits only + val fraction = ((timestampNanos % B) * (1 shl 18) / B) + val seconds = ((timestampNanos / B) % 64) // 6 bits only val timestamp = ((seconds shl 18) or fraction) and 0x00FFFFFF @@ -65,7 +65,7 @@ class AbsSendTimeHeaderExtension { ).toDouble() / 0x03ffff val instantMillis = Instant.ofEpochSecond(seconds.toLong()) - return instantMillis.plusNanos((fraction * b).toLong()) + return instantMillis.plusNanos((fraction * B).toLong()) } } } diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/rtp/header_extensions/AudioLevelHeaderExtension.kt b/rtp/src/main/kotlin/org/jitsi/rtp/rtp/header_extensions/AudioLevelHeaderExtension.kt index ab39a6e71d..807698df98 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/rtp/header_extensions/AudioLevelHeaderExtension.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/rtp/header_extensions/AudioLevelHeaderExtension.kt @@ -36,11 +36,9 @@ class AudioLevelHeaderExtension { fun getAudioLevel(ext: RtpPacket.HeaderExtension): Int = getAudioLevel(ext.buffer, ext.dataOffset) - private fun getAudioLevel(buf: ByteArray, offset: Int): Int = - (buf[offset] and AUDIO_LEVEL_MASK).toPositiveInt() + private fun getAudioLevel(buf: ByteArray, offset: Int): Int = (buf[offset] and AUDIO_LEVEL_MASK).toPositiveInt() fun getVad(ext: RtpPacket.HeaderExtension): Boolean = getVad(ext.buffer, ext.dataOffset) - private fun getVad(buf: ByteArray, offset: Int): Boolean = - (buf[offset].toInt() and 0x80) != 0 + private fun getVad(buf: ByteArray, offset: Int): Boolean = (buf[offset].toInt() and 0x80) != 0 } } diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/rtp/header_extensions/HeaderExtensionHelpers.kt b/rtp/src/main/kotlin/org/jitsi/rtp/rtp/header_extensions/HeaderExtensionHelpers.kt index f307182068..4cfe8a2b4a 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/rtp/header_extensions/HeaderExtensionHelpers.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/rtp/header_extensions/HeaderExtensionHelpers.kt @@ -44,8 +44,7 @@ abstract class HeaderExtensionParser { * Return the entire size, in bytes, of the extension in [buf] whose header * starts at [offset] */ - fun getEntireLengthBytes(buf: ByteArray, offset: Int): Int = - getDataLengthBytes(buf, offset) + extHeaderSizeBytes + fun getEntireLengthBytes(buf: ByteArray, offset: Int): Int = getDataLengthBytes(buf, offset) + extHeaderSizeBytes /** * Return the data size, in bytes, of the extension in [buf] whose header @@ -60,11 +59,9 @@ object OneByteHeaderExtensionParser : HeaderExtensionParser() { override val extHeaderSizeBytes = 1 override val minimumExtSizeBytes = 2 - override fun isMatchingType(profileField: Int): Boolean = - profileField == headerExtensionLabel + override fun isMatchingType(profileField: Int): Boolean = profileField == headerExtensionLabel - override fun getId(buf: ByteArray, offset: Int): Int = - (buf[offset].toInt() ushr 4) and 0x0F + override fun getId(buf: ByteArray, offset: Int): Int = (buf[offset].toInt() ushr 4) and 0x0F override fun writeIdAndLength(id: Int, dataLength: Int, buf: ByteArray, offset: Int) { require(id in 1..14) @@ -79,16 +76,15 @@ object OneByteHeaderExtensionParser : HeaderExtensionParser() { object TwoByteHeaderExtensionParser : HeaderExtensionParser() { /* We don't support "value 256", in the low four bits of the "defined by profile" field. */ override val headerExtensionLabel = 0x1000 - private const val headerExtensionMask = 0xFFF0 + private const val HEADER_EXTENSION_MASK = 0xFFF0 override val extHeaderSizeBytes = 2 override val minimumExtSizeBytes = 2 override fun isMatchingType(profileField: Int): Boolean = - (profileField and headerExtensionMask) == headerExtensionLabel + (profileField and HEADER_EXTENSION_MASK) == headerExtensionLabel - override fun getId(buf: ByteArray, offset: Int): Int = - buf[offset].toInt() + override fun getId(buf: ByteArray, offset: Int): Int = buf[offset].toInt() override fun writeIdAndLength(id: Int, dataLength: Int, buf: ByteArray, offset: Int) { require(id in 1..255) @@ -98,8 +94,7 @@ object TwoByteHeaderExtensionParser : HeaderExtensionParser() { buf[offset + 1] = dataLength.toByte() } - override fun getDataLengthBytes(buf: ByteArray, offset: Int): Int = - buf[offset + 1].toPositiveInt() + override fun getDataLengthBytes(buf: ByteArray, offset: Int): Int = buf[offset + 1].toPositiveInt() } private val headerExtensionParsers = arrayOf(OneByteHeaderExtensionParser, TwoByteHeaderExtensionParser) @@ -116,8 +111,7 @@ class HeaderExtensionHelpers { * only be called if it's been verified that the header held in [buf] * actually contains extensions */ - fun getExtensionsProfileType(buf: ByteArray, offset: Int) = - buf.getShortAsInt(offset) + fun getExtensionsProfileType(buf: ByteArray, offset: Int) = buf.getShortAsInt(offset) /** * Return the length of the entire header extensions block, including diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/rtp/header_extensions/TccHeaderExtension.kt b/rtp/src/main/kotlin/org/jitsi/rtp/rtp/header_extensions/TccHeaderExtension.kt index 5c2188f99a..a271129763 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/rtp/header_extensions/TccHeaderExtension.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/rtp/header_extensions/TccHeaderExtension.kt @@ -32,14 +32,12 @@ class TccHeaderExtension { companion object { const val DATA_SIZE_BYTES = 2 - fun getSequenceNumber(ext: RtpPacket.HeaderExtension): Int = - getSequenceNumber(ext.buffer, ext.dataOffset) + fun getSequenceNumber(ext: RtpPacket.HeaderExtension): Int = getSequenceNumber(ext.buffer, ext.dataOffset) fun setSequenceNumber(ext: RtpPacket.HeaderExtension, tccSeqNum: Int) { setSequenceNumber(ext.buffer, ext.dataOffset, tccSeqNum) } - private fun getSequenceNumber(buf: ByteArray, offset: Int): Int = - buf.getShortAsInt(offset) + private fun getSequenceNumber(buf: ByteArray, offset: Int): Int = buf.getShortAsInt(offset) private fun setSequenceNumber(buf: ByteArray, offset: Int, seqNum: Int) { buf.putShort(offset, seqNum.toShort()) } diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/util/FieldParsers.kt b/rtp/src/main/kotlin/org/jitsi/rtp/util/FieldParsers.kt index 5712e998cd..eef031e49e 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/util/FieldParsers.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/util/FieldParsers.kt @@ -33,14 +33,10 @@ fun ByteArray.getBitsAsInt(byteOffset: Int, bitStartPos: Int, numBits: Int): Int fun ByteArray.putNumberAsBits(byteOffset: Int, bitOffset: Int, numBits: Int, value: Number) { putBits(byteOffset, bitOffset, value.toByte(), numBits) } -fun ByteArray.getByteAsInt(offset: Int): Int = - get(offset).toPositiveInt() +fun ByteArray.getByteAsInt(offset: Int): Int = get(offset).toPositiveInt() -fun ByteArray.getShortAsInt(offset: Int): Int = - getShort(offset).toPositiveInt() +fun ByteArray.getShortAsInt(offset: Int): Int = getShort(offset).toPositiveInt() -fun ByteArray.get3BytesAsInt(offset: Int): Int = - get3Bytes(offset).toPositiveInt() +fun ByteArray.get3BytesAsInt(offset: Int): Int = get3Bytes(offset).toPositiveInt() -fun ByteArray.getIntAsLong(offset: Int): Long = - getInt(offset).toPositiveLong() +fun ByteArray.getIntAsLong(offset: Int): Long = getInt(offset).toPositiveLong() diff --git a/rtp/src/main/kotlin/org/jitsi/rtp/util/RtpUtils.kt b/rtp/src/main/kotlin/org/jitsi/rtp/util/RtpUtils.kt index e4f01bf373..c088ad7b2c 100644 --- a/rtp/src/main/kotlin/org/jitsi/rtp/util/RtpUtils.kt +++ b/rtp/src/main/kotlin/org/jitsi/rtp/util/RtpUtils.kt @@ -34,14 +34,13 @@ class RtpUtils { /** * Get the number of bytes needed to pad [dataSizeBytes] bytes to a 4-byte word boundary. */ - fun getNumPaddingBytes(dataSizeBytes: Int): Int = - when (dataSizeBytes % 4) { - 0 -> 0 - 1 -> 3 - 2 -> 2 - 3 -> 1 - else -> 0 // The above is exhaustive. - } + fun getNumPaddingBytes(dataSizeBytes: Int): Int = when (dataSizeBytes % 4) { + 0 -> 0 + 1 -> 3 + 2 -> 2 + 3 -> 1 + else -> 0 // The above is exhaustive. + } /** * Returns the delta between two RTP sequence numbers, taking into account @@ -52,8 +51,7 @@ class RtpUtils { * @return the delta between two RTP sequence numbers (modulo 2^16). */ @JvmStatic - fun getSequenceNumberDelta(a: Int, b: Int): Int = - getSequenceNumberDeltaAsShort(a, b).toInt() + fun getSequenceNumberDelta(a: Int, b: Int): Int = getSequenceNumberDeltaAsShort(a, b).toInt() /** * Like [getSequenceNumberDelta], but returning the delta as a [Short]. @@ -74,8 +72,7 @@ class RtpUtils { * @return the sequence number resulting from doing "start + delta" */ @JvmStatic - fun applySequenceNumberDelta(start: Int, delta: Int): Int = - (start + delta) and 0xffff + fun applySequenceNumberDelta(start: Int, delta: Int): Int = (start + delta) and 0xffff /** * Apply a delta to a given RTP timestamp and return the result (taking @@ -85,32 +82,26 @@ class RtpUtils { * @return the timestamp result from doing "start + delta" */ @JvmStatic - fun applyTimestampDelta(start: Long, delta: Long): Long = - (start + delta) and 0xffff_ffffL + fun applyTimestampDelta(start: Long, delta: Long): Long = (start + delta) and 0xffff_ffffL @JvmStatic - fun isNewerSequenceNumberThan(a: Int, b: Int): Boolean = - getSequenceNumberDeltaAsShort(a, b) > 0 + fun isNewerSequenceNumberThan(a: Int, b: Int): Boolean = getSequenceNumberDeltaAsShort(a, b) > 0 @JvmStatic - fun isOlderSequenceNumberThan(a: Int, b: Int): Boolean = - getSequenceNumberDeltaAsShort(a, b) < 0 + fun isOlderSequenceNumberThan(a: Int, b: Int): Boolean = getSequenceNumberDeltaAsShort(a, b) < 0 @JvmStatic - fun isNewerTimestampThan(a: Long, b: Long): Boolean = - getTimestampDiffAsInt(a, b) > 0 + fun isNewerTimestampThan(a: Long, b: Long): Boolean = getTimestampDiffAsInt(a, b) > 0 @JvmStatic - fun isOlderTimestampThan(a: Long, b: Long): Boolean = - getTimestampDiffAsInt(a, b) < 0 + fun isOlderTimestampThan(a: Long, b: Long): Boolean = getTimestampDiffAsInt(a, b) < 0 /** * Returns the difference between two RTP timestamps. * @return the difference between two RTP timestamps. */ @JvmStatic - fun getTimestampDiff(a: Long, b: Long): Long = - getTimestampDiffAsInt(a, b).toLong() + fun getTimestampDiff(a: Long, b: Long): Long = getTimestampDiffAsInt(a, b).toLong() /** * Returns the difference between two RTP timestamps as an [Int]. @@ -163,27 +154,21 @@ fun Byte.isPadding(): Boolean = this == 0x00.toByte() * Returns true if the RTP sequence number represented by [this] represents a more recent RTP packet than the one * represented by [otherSeqNum] */ -infix fun Int.isNewerThan(otherSeqNum: Int): Boolean = - RtpUtils.isNewerSequenceNumberThan(this, otherSeqNum) +infix fun Int.isNewerThan(otherSeqNum: Int): Boolean = RtpUtils.isNewerSequenceNumberThan(this, otherSeqNum) -infix fun Int.isOlderThan(otherSeqNum: Int): Boolean = - RtpUtils.isOlderSequenceNumberThan(this, otherSeqNum) +infix fun Int.isOlderThan(otherSeqNum: Int): Boolean = RtpUtils.isOlderSequenceNumberThan(this, otherSeqNum) -infix fun Long.isNewerTimestampThan(otherTimestamp: Long): Boolean = - RtpUtils.isNewerTimestampThan(this, otherTimestamp) +infix fun Long.isNewerTimestampThan(otherTimestamp: Long): Boolean = RtpUtils.isNewerTimestampThan(this, otherTimestamp) -infix fun Long.isOlderTimestampThan(otherTimestamp: Long): Boolean = - RtpUtils.isOlderTimestampThan(this, otherTimestamp) +infix fun Long.isOlderTimestampThan(otherTimestamp: Long): Boolean = RtpUtils.isOlderTimestampThan(this, otherTimestamp) /** * Returns true if getting to [otherSeqNum] from the current sequence number involves wrapping around */ infix fun Int.rolledOverTo(otherSeqNum: Int): Boolean = - /** - * If, according to [isOlderThan], [this] is older than [otherSeqNum] and - * yet [otherSeqNum] is less than [this], then we wrapped around to get from [this] to - * [otherSeqNum] - */ + // If, according to [isOlderThan], [this] is older than [otherSeqNum] and + // yet [otherSeqNum] is less than [this], then we wrapped around to get from [this] to + // [otherSeqNum] this isOlderThan otherSeqNum && otherSeqNum < this /** diff --git a/rtp/src/test/kotlin/org/jitsi/rtp/extensions/ByteBufferExtensionsTest.kt b/rtp/src/test/kotlin/org/jitsi/rtp/extensions/ByteBufferExtensionsTest.kt index ebfe0c3f82..47abbc2c02 100644 --- a/rtp/src/test/kotlin/org/jitsi/rtp/extensions/ByteBufferExtensionsTest.kt +++ b/rtp/src/test/kotlin/org/jitsi/rtp/extensions/ByteBufferExtensionsTest.kt @@ -191,7 +191,7 @@ class ByteBufferExtensionsTest : ShouldSpec() { } context("moving the data past the capacity") { val buf = byteBufferOf(0x01, 0x02, 0x03, 0x04, 0x00, 0x0, 0x00, 0x00) - shouldThrow() { + shouldThrow { buf.shiftDataRight(4, 6, 10) } } @@ -206,7 +206,7 @@ class ByteBufferExtensionsTest : ShouldSpec() { } context("moving the data past the start") { val buf = byteBufferOf(0x01, 0x02, 0x03, 0x04, 0x00, 0x0, 0x00, 0x00) - shouldThrow() { + shouldThrow { buf.shiftDataLeft(1, 2, 2) } } diff --git a/rtp/src/test/kotlin/org/jitsi/rtp/rtcp/rtcpfb/transport_layer_fb/tcc/RtcpFbTccPacketTest.kt b/rtp/src/test/kotlin/org/jitsi/rtp/rtcp/rtcpfb/transport_layer_fb/tcc/RtcpFbTccPacketTest.kt index 191a300f35..6144aa2230 100644 --- a/rtp/src/test/kotlin/org/jitsi/rtp/rtcp/rtcpfb/transport_layer_fb/tcc/RtcpFbTccPacketTest.kt +++ b/rtp/src/test/kotlin/org/jitsi/rtp/rtcp/rtcpfb/transport_layer_fb/tcc/RtcpFbTccPacketTest.kt @@ -53,7 +53,7 @@ class RtcpFbTccPacketTest : ShouldSpec() { /** * These correspond to the Deltas section above. */ - val expectedTccRlePacketInfo = mapOf ( + val expectedTccRlePacketInfo = mapOf( 0xfffa to 0xd8, 0xfffb to 0x00, 0xfffc to 0x18, @@ -94,7 +94,7 @@ class RtcpFbTccPacketTest : ShouldSpec() { // Recv delta padding 0x00, 0x00, 0x00 ) - val expectedTccMixedChunkTypePacketInfo = mapOf ( + val expectedTccMixedChunkTypePacketInfo = mapOf( 5376 to 2.toTicks(), 5377 to 0.toTicks(), 5378 to 0.toTicks(), @@ -129,7 +129,7 @@ class RtcpFbTccPacketTest : ShouldSpec() { // Recv delta padding 0x00 ) - val expectedTccSvChunkPacketInfo = mapOf ( + val expectedTccSvChunkPacketInfo = mapOf( 6227 to -1, 6228 to 107784064 + 27 ) diff --git a/rtp/src/test/kotlin/org/jitsi/rtp/rtp/RtpPacketTest.kt b/rtp/src/test/kotlin/org/jitsi/rtp/rtp/RtpPacketTest.kt index 2d5f96e00b..623154fda9 100644 --- a/rtp/src/test/kotlin/org/jitsi/rtp/rtp/RtpPacketTest.kt +++ b/rtp/src/test/kotlin/org/jitsi/rtp/rtp/RtpPacketTest.kt @@ -942,8 +942,7 @@ class PaddingOnlyPacket private constructor( length: Int ) : RtpPacket(buffer, offset, length) { - override fun clone(): PaddingOnlyPacket = - throw NotImplementedError("clone() not supported for padding packets.") + override fun clone(): PaddingOnlyPacket = throw NotImplementedError("clone() not supported for padding packets.") companion object { /**