Skip to content

Commit b90ab1e

Browse files
authored
Allow adjustment of opus encoding & resampling quality fields in AudioConfiguration (#699)
* Allow setting opusEncoding & resampling quality * Mark resamplingQuality as nullable so it can be omitted * Support useSeekGhosting setting.
1 parent 7e21b71 commit b90ab1e

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

LavalinkServer/application.yml.example

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ lavalink:
1414
local: false
1515
bufferDurationMs: 400 # The duration of the NAS buffer. Higher values fare better against longer GC pauses. Minimum of 40ms, lower values may introduce pauses.
1616
frameBufferDurationMs: 5000 # How many milliseconds of audio to keep buffered
17-
trackStuckThresholdMs: 10000 # The threshold for how long a track can be stuck. A track is stuck if does not return any audio data.
17+
opusEncodingQuality: 10 # Opus encoder quality. Valid values range from 0 to 10, where 10 is best quality but is the most expensive on the CPU.
18+
resamplingQuality: LOW # Quality of resampling operations. Valid values are LOW, MEDIUM and HIGH, where HIGH uses the most CPU.
19+
trackStuckThresholdMs: 10000 # The threshold for how long a track can be stuck. A track is stuck if does not return any audio data.
20+
useSeekGhosting: true # Seek ghosting is the effect where whilst a seek is in progress, the audio buffer is read from until empty, or until seek is ready.
1821
youtubePlaylistLoadLimit: 6 # Number of pages at 100 each
1922
playerUpdateInterval: 5 # How frequently to send player updates to clients, in seconds
2023
youtubeSearchEnabled: true

LavalinkServer/src/main/java/lavalink/server/config/AudioPlayerConfiguration.kt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package lavalink.server.config
22

33
import com.sedmelluq.discord.lavaplayer.container.MediaContainerProbe
44
import com.sedmelluq.discord.lavaplayer.container.MediaContainerRegistry
5+
import com.sedmelluq.discord.lavaplayer.player.AudioConfiguration
6+
import com.sedmelluq.discord.lavaplayer.player.AudioConfiguration.ResamplingQuality
57
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager
68
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager
79
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManager
@@ -65,6 +67,24 @@ class AudioPlayerConfiguration {
6567
audioPlayerManager.frameBufferDuration = bufferDuration
6668
}
6769

70+
val defaultOpusEncodingQuality = AudioConfiguration.OPUS_QUALITY_MAX
71+
audioPlayerManager.configuration.let {
72+
serverConfig.opusEncodingQuality?.let { opusQuality ->
73+
if (opusQuality !in 0..10) {
74+
log.warn("Opus encoding quality {} is not within the range of 0 to 10. Defaulting to {}", opusQuality, defaultOpusEncodingQuality)
75+
}
76+
77+
val qualitySetting = opusQuality.takeIf { it in 0..10 } ?: defaultOpusEncodingQuality
78+
log.debug("Setting opusEncodingQuality to {}", qualitySetting)
79+
it.opusEncodingQuality = qualitySetting
80+
}
81+
82+
serverConfig.resamplingQuality?.let { resamplingQuality ->
83+
log.debug("Setting resamplingQuality to {}", resamplingQuality)
84+
it.resamplingQuality = resamplingQuality
85+
}
86+
}
87+
6888
val defaultTrackStuckThresholdMs = TimeUnit.NANOSECONDS.toMillis(audioPlayerManager.trackStuckThresholdNanos)
6989
serverConfig.trackStuckThresholdMs?.let {
7090
if (it < 100) {
@@ -76,6 +96,11 @@ class AudioPlayerConfiguration {
7696
audioPlayerManager.setTrackStuckThreshold(trackStuckThresholdMs)
7797
}
7898

99+
serverConfig.useSeekGhosting?.let { seekGhosting ->
100+
log.debug("Setting useSeekGhosting to {}", seekGhosting)
101+
audioPlayerManager.setUseSeekGhosting(seekGhosting)
102+
}
103+
79104
val mcr: MediaContainerRegistry = MediaContainerRegistry.extended(*mediaContainerProbes.toTypedArray())
80105

81106
if (sources.isYoutube) {

LavalinkServer/src/main/java/lavalink/server/config/ServerConfig.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
package lavalink.server.config
2424

25+
import com.sedmelluq.discord.lavaplayer.player.AudioConfiguration.ResamplingQuality
2526
import org.springframework.boot.context.properties.ConfigurationProperties
2627
import org.springframework.stereotype.Component
2728

@@ -33,7 +34,10 @@ class ServerConfig {
3334
var sentryDsn = ""
3435
var bufferDurationMs: Int? = null
3536
var frameBufferDurationMs: Int? = null
37+
var opusEncodingQuality: Int? = null
38+
var resamplingQuality: ResamplingQuality? = null
3639
var trackStuckThresholdMs: Long? = null
40+
var useSeekGhosting: Boolean? = null
3741
var youtubePlaylistLoadLimit: Int? = null
3842
var playerUpdateInterval: Int = 5
3943
var isGcWarnings = true

0 commit comments

Comments
 (0)