Skip to content

Commit

Permalink
Update for ktlint 1.0.0 (ktlint-maven-plugin 3.0.0).
Browse files Browse the repository at this point in the history
  • Loading branch information
JonathanLennox committed Oct 2, 2023
1 parent 30dcf51 commit af2d04b
Show file tree
Hide file tree
Showing 97 changed files with 788 additions and 897 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,19 +87,21 @@ class MediaSourceDesc
private fun updateLayerCache() {
layersById.clear()
layersByIndex.clear()
val layers_ = ArrayList<RtpLayerDesc>()
val tempLayers = ArrayList<RtpLayerDesc>()

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
Expand All @@ -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? {
Expand All @@ -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<RtpLayerDesc>, ssrc: Long) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)}"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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<String, String>
) {
private fun verifyAndValidateCertificate(certificate: Certificate, remoteFingerprints: Map<String, String>) {
// 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ class TlsClientImpl(
logger.cinfo { "Negotiated DTLS version $serverVersion" }
}

override fun getSupportedVersions(): Array<ProtocolVersion> =
arrayOf<ProtocolVersion>(ProtocolVersion.DTLSv12)
override fun getSupportedVersions(): Array<ProtocolVersion> = arrayOf<ProtocolVersion>(ProtocolVersion.DTLSv12)

override fun notifyAlertRaised(alertLevel: Short, alertDescription: Short, message: String?, cause: Throwable?) =
logger.notifyAlertRaised(alertLevel, alertDescription, message, cause)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,17 @@ class RedAudioRtpPacket(
removed = true
}

fun removeRedAndGetRedundancyPackets(): List<AudioRtpPacket> =
if (removed) {
throw IllegalStateException("RED encapsulation already removed.")
} else {
parser.decapsulate(this, parseRedundancy = true).also { removed = true }
}
fun removeRedAndGetRedundancyPackets(): List<AudioRtpPacket> = 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,9 @@ class TransportCcEngine(
* [PacketDetailState] is the state of a [PacketDetail]
*/
private enum class PacketDetailState {
Unreported, ReportedLost, ReportedReceived
Unreported,
ReportedLost,
ReportedReceived
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ class PipelineBuilder {
}

fun node(node: Node, condition: () -> Boolean = { true }) {
if (condition()) { addNode(node) }
if (condition()) {
addNode(node)
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit af2d04b

Please sign in to comment.