Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow adjustment of opus encoding & resampling quality fields in AudioConfiguration #699

Merged
merged 3 commits into from
Jul 30, 2022
Merged
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
5 changes: 4 additions & 1 deletion LavalinkServer/application.yml.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ lavalink:
local: false
bufferDurationMs: 400 # The duration of the NAS buffer. Higher values fare better against longer GC pauses. Minimum of 40ms, lower values may introduce pauses.
frameBufferDurationMs: 5000 # How many milliseconds of audio to keep buffered
trackStuckThresholdMs: 10000 # The threshold for how long a track can be stuck. A track is stuck if does not return any audio data.
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.
resamplingQuality: LOW # Quality of resampling operations. Valid values are LOW, MEDIUM and HIGH, where HIGH uses the most CPU.
trackStuckThresholdMs: 10000 # The threshold for how long a track can be stuck. A track is stuck if does not return any audio data.
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.
youtubePlaylistLoadLimit: 6 # Number of pages at 100 each
playerUpdateInterval: 5 # How frequently to send player updates to clients, in seconds
youtubeSearchEnabled: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package lavalink.server.config

import com.sedmelluq.discord.lavaplayer.container.MediaContainerProbe
import com.sedmelluq.discord.lavaplayer.container.MediaContainerRegistry
import com.sedmelluq.discord.lavaplayer.player.AudioConfiguration
import com.sedmelluq.discord.lavaplayer.player.AudioConfiguration.ResamplingQuality
import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager
import com.sedmelluq.discord.lavaplayer.source.AudioSourceManager
Expand Down Expand Up @@ -65,6 +67,24 @@ class AudioPlayerConfiguration {
audioPlayerManager.frameBufferDuration = bufferDuration
}

val defaultOpusEncodingQuality = AudioConfiguration.OPUS_QUALITY_MAX
audioPlayerManager.configuration.let {
serverConfig.opusEncodingQuality?.let { opusQuality ->
if (opusQuality !in 0..10) {
log.warn("Opus encoding quality {} is not within the range of 0 to 10. Defaulting to {}", opusQuality, defaultOpusEncodingQuality)
}

val qualitySetting = opusQuality.takeIf { it in 0..10 } ?: defaultOpusEncodingQuality
log.debug("Setting opusEncodingQuality to {}", qualitySetting)
it.opusEncodingQuality = qualitySetting
}

serverConfig.resamplingQuality?.let { resamplingQuality ->
log.debug("Setting resamplingQuality to {}", resamplingQuality)
it.resamplingQuality = resamplingQuality
}
}

val defaultTrackStuckThresholdMs = TimeUnit.NANOSECONDS.toMillis(audioPlayerManager.trackStuckThresholdNanos)
serverConfig.trackStuckThresholdMs?.let {
if (it < 100) {
Expand All @@ -76,6 +96,11 @@ class AudioPlayerConfiguration {
audioPlayerManager.setTrackStuckThreshold(trackStuckThresholdMs)
}

serverConfig.useSeekGhosting?.let { seekGhosting ->
log.debug("Setting useSeekGhosting to {}", seekGhosting)
audioPlayerManager.setUseSeekGhosting(seekGhosting)
}

val mcr: MediaContainerRegistry = MediaContainerRegistry.extended(*mediaContainerProbes.toTypedArray())

if (sources.isYoutube) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

package lavalink.server.config

import com.sedmelluq.discord.lavaplayer.player.AudioConfiguration.ResamplingQuality
import org.springframework.boot.context.properties.ConfigurationProperties
import org.springframework.stereotype.Component

Expand All @@ -33,7 +34,10 @@ class ServerConfig {
var sentryDsn = ""
var bufferDurationMs: Int? = null
var frameBufferDurationMs: Int? = null
var opusEncodingQuality: Int? = null
var resamplingQuality: ResamplingQuality? = null
var trackStuckThresholdMs: Long? = null
var useSeekGhosting: Boolean? = null
var youtubePlaylistLoadLimit: Int? = null
var playerUpdateInterval: Int = 5
var isGcWarnings = true
Expand Down