Skip to content

Commit

Permalink
Merge pull request #1676 from pedroSG94/feature/custom-latency-srt
Browse files Browse the repository at this point in the history
allow set custom latency in SRT url
  • Loading branch information
pedroSG94 authored Jan 16, 2025
2 parents fd83890 + 2205b43 commit 9e17d64
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ class SrtStreamClient(
private val streamClientListener: StreamClientListener?
): StreamBaseClient() {

/**
* Set latency in micro. By default 120_000.
*/
fun setLatency(latency: Int) {
srtClient.setLatency(latency)
}

/**
* Set passphrase for encrypt. Use empty value to disable it.
*/
Expand Down
8 changes: 8 additions & 0 deletions srt/src/main/java/com/pedro/srt/srt/SrtClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ class SrtClient(private val connectChecker: ConnectChecker) {
get() = srtSender.getSentAudioFrames()
val sentVideoFrames: Long
get() = srtSender.getSentVideoFrames()
private var latency = 120_000 //in micro

fun setVideoCodec(videoCodec: VideoCodec) {
if (!isStreaming) {
Expand All @@ -115,6 +116,10 @@ class SrtClient(private val connectChecker: ConnectChecker) {
}
}

fun setLatency(latency: Int) {
this.latency = latency
}

fun setAuthorization(user: String?, password: String?) {
TODO("unimplemented")
}
Expand Down Expand Up @@ -196,6 +201,7 @@ class SrtClient(private val connectChecker: ConnectChecker) {
val host = urlParser.host
val port = urlParser.port ?: 8888
val path = urlParser.getQuery("streamid") ?: urlParser.getFullPath()
latency = urlParser.getQuery("latency")?.toIntOrNull() ?: latency
if (path.isEmpty()) {
isStreaming = false
onMainThread {
Expand All @@ -221,6 +227,8 @@ class SrtClient(private val connectChecker: ConnectChecker) {
flags = ExtensionContentFlag.TSBPDSND.value or ExtensionContentFlag.TSBPDRCV.value or
ExtensionContentFlag.CRYPT.value or ExtensionContentFlag.TLPKTDROP.value or
ExtensionContentFlag.PERIODICNAK.value or ExtensionContentFlag.REXMITFLG.value,
receiverDelay = latency / 1000,
senderDelay = latency / 1000,
path = path,
encryptInfo = commandsManager.getEncryptInfo()
)))
Expand Down

0 comments on commit 9e17d64

Please sign in to comment.