Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -202,17 +202,13 @@ class MediaSourceDesc
*/
fun Array<MediaSourceDesc>.copy() = Array(this.size) { i -> this[i].copy() }

fun Array<MediaSourceDesc>.findRtpLayerDescs(packet: VideoRtpPacket): Collection<RtpLayerDesc> {
return this.flatMap { it.findRtpLayerDescs(packet) }
fun Array<MediaSourceDesc>.findRtpLayerDescs(packet: VideoRtpPacket): Collection<RtpLayerDesc> = this.flatMap {
it.findRtpLayerDescs(packet)
}

fun Array<MediaSourceDesc>.findRtpSourceByPrimary(ssrc: Long): MediaSourceDesc? {
return this.find { it.matches(ssrc) }
}
fun Array<MediaSourceDesc>.findRtpSourceByPrimary(ssrc: Long): MediaSourceDesc? = this.find { it.matches(ssrc) }

fun Array<MediaSourceDesc>.findRtpSource(ssrc: Long): MediaSourceDesc? {
return this.find { it.hasSsrc(ssrc) }
}
fun Array<MediaSourceDesc>.findRtpSource(ssrc: Long): MediaSourceDesc? = this.find { it.hasSsrc(ssrc) }

fun Array<MediaSourceDesc>.findRtpSource(packet: RtpPacket): MediaSourceDesc? = findRtpSource(packet.ssrc)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ interface PacketHandler {
/**
* A [PacketHandler] which tracks statistics about the packets it handles
*/
abstract class StatsKeepingPacketHandler : PacketHandler, NodeStatsProducer {
abstract class StatsKeepingPacketHandler :
PacketHandler,
NodeStatsProducer {
private val statistics = Statistics()

final override fun processPacket(packetInfo: PacketInfo) {
Expand Down
22 changes: 9 additions & 13 deletions jitsi-media-transform/src/main/kotlin/org/jitsi/nlj/PacketInfo.kt
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,16 @@ class EventTimeline(
} ?: Duration.ofMillis(-1)
}

override fun toString(): String {
return with(StringBuffer()) {
referenceTime?.let {
append("Reference time: $referenceTime; ")
synchronized(timeline) {
append(timeline.joinToString(separator = "; "))
}
} ?: run {
append("[No timeline]")
override fun toString(): String = with(StringBuffer()) {
referenceTime?.let {
append("Reference time: $referenceTime; ")
synchronized(timeline) {
append(timeline.joinToString(separator = "; "))
}
toString()
} ?: run {
append("[No timeline]")
}
toString()
}
}

Expand Down Expand Up @@ -183,9 +181,7 @@ open class PacketInfo @JvmOverloads constructor(
* Get the contained packet cast to [ExpectedPacketType]
*/
@Suppress("UNCHECKED_CAST")
fun <ExpectedPacketType : Packet> packetAs(): ExpectedPacketType {
return packet as ExpectedPacketType
}
fun <ExpectedPacketType : Packet> packetAs(): ExpectedPacketType = packet as ExpectedPacketType

/**
* Create a deep clone of this PacketInfo (both the contained packet and the metadata map
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,23 +149,19 @@ constructor(
/**
* {@inheritDoc}
*/
override fun toString(): String {
return "primary_ssrc=$primarySSRC,secondary_ssrcs=$secondarySsrcs," +
"layers=\n ${layers.joinToString(separator = "\n ")}"
}
override fun toString(): String = "primary_ssrc=$primarySSRC,secondary_ssrcs=$secondarySsrcs," +
"layers=\n ${layers.joinToString(separator = "\n ")}"

/**
* Gets a boolean indicating whether the SSRC specified in the
* arguments is used by this encoding.
*
* @param ssrc the SSRC to match.
*/
fun hasSsrc(ssrc: Long): Boolean {
return if (primarySSRC == ssrc) {
true
} else {
secondarySsrcs.containsKey(ssrc)
}
fun hasSsrc(ssrc: Long): Boolean = if (primarySSRC == ssrc) {
true
} else {
secondarySsrcs.containsKey(ssrc)
}

/**
Expand All @@ -186,9 +182,7 @@ constructor(
}
}

fun VideoRtpPacket.getEncodingIds(): Collection<Long> {
return this.layerIds.map { RtpEncodingDesc.calcEncodingId(ssrc, it) }
}
fun VideoRtpPacket.getEncodingIds(): Collection<Long> = this.layerIds.map { RtpEncodingDesc.calcEncodingId(ssrc, it) }

/**
* Get the "nominal" height of a set of layers - if they all indicate the same spatial layer and same height.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,15 +271,13 @@ class RtpReceiverImpl @JvmOverloads constructor(
}
}

private fun handleIncomingPacket(packet: PacketInfo): Boolean {
return if (running) {
packet.addEvent(PACKET_QUEUE_EXIT_EVENT)
processPacket(packet)
true
} else {
BufferPool.returnBuffer(packet.packet.buffer)
false
}
private fun handleIncomingPacket(packet: PacketInfo): Boolean = if (running) {
packet.addEvent(PACKET_QUEUE_EXIT_EVENT)
processPacket(packet)
true
} else {
BufferPool.returnBuffer(packet.packet.buffer)
false
}

override fun doProcessPacket(packetInfo: PacketInfo) = inputTreeRoot.processPacket(packetInfo)
Expand Down Expand Up @@ -333,10 +331,8 @@ class RtpReceiverImpl @JvmOverloads constructor(
}
}

override fun isFeatureEnabled(feature: Features): Boolean {
return when (feature) {
Features.TRANSCEIVER_PCAP_DUMP -> toggleablePcapWriter.isEnabled()
}
override fun isFeatureEnabled(feature: Features): Boolean = when (feature) {
Features.TRANSCEIVER_PCAP_DUMP -> toggleablePcapWriter.isEnabled()
}

override fun stop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,30 +281,26 @@ class RtpSenderImpl(
}
}

override fun isFeatureEnabled(feature: Features): Boolean {
return when (feature) {
Features.TRANSCEIVER_PCAP_DUMP -> toggleablePcapWriter.isEnabled()
}
override fun isFeatureEnabled(feature: Features): Boolean = when (feature) {
Features.TRANSCEIVER_PCAP_DUMP -> toggleablePcapWriter.isEnabled()
}

/**
* Handles packets that have gone through the incoming queue and sends them
* through the sender pipeline
*/
private fun handlePacket(packetInfo: PacketInfo): Boolean {
return if (running) {
packetInfo.addEvent(PACKET_QUEUE_EXIT_EVENT)
private fun handlePacket(packetInfo: PacketInfo): Boolean = if (running) {
packetInfo.addEvent(PACKET_QUEUE_EXIT_EVENT)

val root = when (packetInfo.packet) {
is RtcpPacket -> outgoingRtcpRoot
else -> outgoingRtpRoot
}
root.processPacket(packetInfo)
true
} else {
BufferPool.returnBuffer(packetInfo.packet.buffer)
false
val root = when (packetInfo.packet) {
is RtcpPacket -> outgoingRtcpRoot
else -> outgoingRtpRoot
}
root.processPacket(packetInfo)
true
} else {
BufferPool.returnBuffer(packetInfo.packet.buffer)
false
}

override fun getStreamStats() = statsTracker.getSnapshot()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -335,15 +335,13 @@ class Transceiver(
/**
* Get various media and network stats
*/
fun getTransceiverStats(): TransceiverStats {
return TransceiverStats(
endpointConnectionStats.getSnapshot(),
rtpReceiver.getStats(),
rtpSender.getStreamStats(),
rtpSender.getPacketStreamStats(),
rtpSender.getTransportCcEngineStats()
)
}
fun getTransceiverStats(): TransceiverStats = TransceiverStats(
endpointConnectionStats.getSnapshot(),
rtpReceiver.getStats(),
rtpSender.getStreamStats(),
rtpSender.getPacketStreamStats(),
rtpSender.getTransportCcEngineStats()
)

fun addEndpointConnectionStatsListener(listener: EndpointConnectionStats.EndpointConnectionStatsListener) =
endpointConnectionStats.addListener(listener)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ package org.jitsi.nlj.dtls

import org.jitsi.rtp.Packet

class DtlsProtocolPacket(
buf: ByteArray,
offset: Int,
length: Int
) : Packet(buf, offset, length) {
class DtlsProtocolPacket(buf: ByteArray, offset: Int, length: Int) : Packet(buf, offset, length) {

override fun clone(): DtlsProtocolPacket = DtlsProtocolPacket(cloneBuffer(0), 0, length)
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ import kotlin.math.min
* or server. This can be done by calling either the [actAsClient] or [actAsServer] methods. Once the role has
* been set, [start] can be called to start the negotiation.
*/
class DtlsStack(
parentLogger: Logger
) {
class DtlsStack(parentLogger: Logger) {
private val logger = createChildLogger(parentLogger)
private val roleSet = CountDownLatch(1)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,13 @@ class DtlsUtils {
* A helper which finds an SRTP protection profile present in both
* [ours] and [theirs]. Throws [DtlsException] if no common profile is found.
*/
fun chooseSrtpProtectionProfile(ours: Iterable<Int>, theirs: Iterable<Int>): Int {
return try {
ours.first(theirs::contains)
} catch (e: NoSuchElementException) {
throw DtlsException(
"No common SRTP protection profile found. Ours: ${ours.joinToString()} " +
"Theirs: ${theirs.joinToString()}"
)
}
fun chooseSrtpProtectionProfile(ours: Iterable<Int>, theirs: Iterable<Int>): Int = try {
ours.first(theirs::contains)
} catch (e: NoSuchElementException) {
throw DtlsException(
"No common SRTP protection profile found. Ours: ${ours.joinToString()} " +
"Theirs: ${theirs.joinToString()}"
)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,23 +100,19 @@ class TlsServerImpl(

override fun getCipherSuites() = DtlsConfig.config.cipherSuites.toIntArray()

override fun getRSAEncryptionCredentials(): TlsCredentialedDecryptor {
return BcDefaultTlsCredentialedDecryptor(
(context.crypto as BcTlsCrypto),
certificateInfo.certificate,
PrivateKeyFactory.createKey(certificateInfo.keyPair.private.encoded)
)
}

override fun getECDSASignerCredentials(): TlsCredentialedSigner {
return BcDefaultTlsCredentialedSigner(
TlsCryptoParameters(context),
(context.crypto as BcTlsCrypto),
PrivateKeyFactory.createKey(certificateInfo.keyPair.private.encoded),
certificateInfo.certificate,
SignatureAndHashAlgorithm(HashAlgorithm.sha256, SignatureAlgorithm.ecdsa)
)
}
override fun getRSAEncryptionCredentials(): TlsCredentialedDecryptor = BcDefaultTlsCredentialedDecryptor(
(context.crypto as BcTlsCrypto),
certificateInfo.certificate,
PrivateKeyFactory.createKey(certificateInfo.keyPair.private.encoded)
)

override fun getECDSASignerCredentials(): TlsCredentialedSigner = BcDefaultTlsCredentialedSigner(
TlsCryptoParameters(context),
(context.crypto as BcTlsCrypto),
PrivateKeyFactory.createKey(certificateInfo.keyPair.private.encoded),
certificateInfo.certificate,
SignatureAndHashAlgorithm(HashAlgorithm.sha256, SignatureAlgorithm.ecdsa)
)

override fun getCertificateRequest(): CertificateRequest {
val signatureAlgorithms = Vector<SignatureAndHashAlgorithm>(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,8 @@ class H264PayloadType(
rtcpFeedbackSet: RtcpFeedbackSet = emptySet()
) : VideoPayloadType(pt, PayloadTypeEncoding.H264, parameters = parameters, rtcpFeedbackSet = rtcpFeedbackSet)

class RtxPayloadType(
pt: Byte,
parameters: PayloadTypeParams = ConcurrentHashMap()
) : VideoPayloadType(pt, PayloadTypeEncoding.RTX, parameters = parameters) {
class RtxPayloadType(pt: Byte, parameters: PayloadTypeParams = ConcurrentHashMap()) :
VideoPayloadType(pt, PayloadTypeEncoding.RTX, parameters = parameters) {
val associatedPayloadType: Int =
parameters["apt"]?.toInt() ?: error("RtxPayloadType must contain 'apt'")
}
Expand All @@ -157,22 +155,14 @@ abstract class AudioPayloadType(
parameters: PayloadTypeParams = ConcurrentHashMap()
) : PayloadType(pt, encoding, MediaType.AUDIO, clockRate, parameters)

class OpusPayloadType(
pt: Byte,
parameters: PayloadTypeParams = ConcurrentHashMap()
) : AudioPayloadType(pt, PayloadTypeEncoding.OPUS, parameters = parameters)
class OpusPayloadType(pt: Byte, parameters: PayloadTypeParams = ConcurrentHashMap()) :
AudioPayloadType(pt, PayloadTypeEncoding.OPUS, parameters = parameters)

class TelephoneEventPayloadType(
pt: Byte,
clockRate: Int,
parameters: PayloadTypeParams = ConcurrentHashMap()
) : AudioPayloadType(pt, PayloadTypeEncoding.TELEPHONE_EVENT, clockRate, parameters)
class TelephoneEventPayloadType(pt: Byte, clockRate: Int, parameters: PayloadTypeParams = ConcurrentHashMap()) :
AudioPayloadType(pt, PayloadTypeEncoding.TELEPHONE_EVENT, clockRate, parameters)

class AudioRedPayloadType(
pt: Byte,
clockRate: Int = 48000,
parameters: PayloadTypeParams = ConcurrentHashMap()
) : AudioPayloadType(pt, PayloadTypeEncoding.RED, clockRate, parameters)
class AudioRedPayloadType(pt: Byte, clockRate: Int = 48000, parameters: PayloadTypeParams = ConcurrentHashMap()) :
AudioPayloadType(pt, PayloadTypeEncoding.RED, clockRate, parameters)

class VideoRedPayloadType(
pt: Byte,
Expand All @@ -181,14 +171,8 @@ class VideoRedPayloadType(
rtcpFeedbackSet: RtcpFeedbackSet = emptySet()
) : VideoPayloadType(pt, PayloadTypeEncoding.RED, clockRate, parameters, rtcpFeedbackSet)

class OtherAudioPayloadType(
pt: Byte,
clockRate: Int,
parameters: PayloadTypeParams = ConcurrentHashMap()
) : AudioPayloadType(pt, PayloadTypeEncoding.OTHER, clockRate, parameters)
class OtherAudioPayloadType(pt: Byte, clockRate: Int, parameters: PayloadTypeParams = ConcurrentHashMap()) :
AudioPayloadType(pt, PayloadTypeEncoding.OTHER, clockRate, parameters)

class OtherVideoPayloadType(
pt: Byte,
clockRate: Int,
parameters: PayloadTypeParams = ConcurrentHashMap()
) : VideoPayloadType(pt, PayloadTypeEncoding.OTHER, clockRate, parameters)
class OtherVideoPayloadType(pt: Byte, clockRate: Int, parameters: PayloadTypeParams = ConcurrentHashMap()) :
VideoPayloadType(pt, PayloadTypeEncoding.OTHER, clockRate, parameters)
Loading
Loading