Reworded example config, added afterburner and offset_start options
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
DataHoarder 2022-07-16 15:06:21 +02:00
parent b6dad55d31
commit 045b72dfa7
Signed by: DataHoarder
SSH key fingerprint: SHA256:OLTRf6Fl87G52SiR7sWLGNzlJt4WOX+tfI2yxo0z7xk
6 changed files with 31 additions and 9 deletions

View file

@ -76,6 +76,18 @@ func (s *StreamConfig) GetStringOption(name string, defaultValue string) string
return defaultValue
}
func (s *StreamConfig) GetBoolOption(name string, defaultValue bool) bool {
if v, ok := s.Options[name].(bool); ok {
return v
}
if v, ok := s.Options[name].(string); ok {
return v == "true"
}
return defaultValue
}
func (s *StreamConfig) GetOption(name string, defaultValue interface{}) interface{} {
if v, ok := s.Options[name]; ok {

View file

@ -80,18 +80,24 @@ private=false
# A list of streams to make available at [radio.port]/*(mount) follows. The
# following properties are available:
#
# mount: the HTTP address to serve the stream from
# mount: the HTTP address to serve the stream from.
#
# container: the container format to use (ogg, flac, aac/adts, or mp3). See Kirika's supported format list.
#
# codec: the audio codec to use (opus, flac, aac, or mp3)
#
# bitrate: the desired bitrate of the stream in Kb/s, if not specified (or 0) an appropriate
# bitrate will be automatically selected based on the container/codec
# MeteorLight extension: bitrate can be a string (for example, v0-v9 on MP3). codec can also be he-aacv2. No vorbis support.
#
#
# Additionally further options can be set on some codecs.
# - FLAC supports bitdepth (int), compression_level (int), block_size (int)
# - FLAC supports bitdepth (int) default 16, compression_level (int) default 8, block_size (int) default 0 = auto
# - AAC supports VBR bitrate (vbr1 - vbr5), mode (lc, he, hev2) and afterburner (bool)
# - MP3 supports VBR bitrate (v0 - v9)
# - All but Opus support setting samplerate
# - All support setting channels to 1 or 2
# - All but Opus support setting samplerate (int)
# - All but FLAC support setting offset_start (bool) default true, rewrites packets PTS to align with the client start time.
# - All support setting channels (int) to 1 or 2, default 2
[[streams]]
mount="stream128.mp3"
container="mp3"

2
go.mod
View file

@ -3,7 +3,7 @@ module git.gammaspectra.live/S.O.N.G/MeteorLight
go 1.18
require (
git.gammaspectra.live/S.O.N.G/Kirika v0.0.0-20220713142734-894d8db69758
git.gammaspectra.live/S.O.N.G/Kirika v0.0.0-20220715173911-915e8dd21372
github.com/BurntSushi/toml v1.1.0
github.com/dhowden/tag v0.0.0-20220618230019-adf36e896086
github.com/enriquebris/goconcurrentqueue v0.6.3

4
go.sum
View file

@ -1,5 +1,5 @@
git.gammaspectra.live/S.O.N.G/Kirika v0.0.0-20220713142734-894d8db69758 h1:e5mVs6gIje3hA4+Z2pEHvhxd8YC0CB9oiHP1PzKQ7bE=
git.gammaspectra.live/S.O.N.G/Kirika v0.0.0-20220713142734-894d8db69758/go.mod h1:HrYZb1M5dv2hOfpUhLOYkK4qQqBu+7hg7p14R19ebvs=
git.gammaspectra.live/S.O.N.G/Kirika v0.0.0-20220715173911-915e8dd21372 h1:Rc/vh6f5SPzqJpjTV77QMB6e355TK9sAuyFEZNG4jJw=
git.gammaspectra.live/S.O.N.G/Kirika v0.0.0-20220715173911-915e8dd21372/go.mod h1:HrYZb1M5dv2hOfpUhLOYkK4qQqBu+7hg7p14R19ebvs=
git.gammaspectra.live/S.O.N.G/go-alac v0.0.0-20220421115623-d0b3bfe57e0f h1:CxN7zlk5FdAieyRKQSbwBGBsvQ2cDF8JVCODZpzcRkA=
git.gammaspectra.live/S.O.N.G/go-alac v0.0.0-20220421115623-d0b3bfe57e0f/go.mod h1:f1+h7KOnuM9zcEQp7ri4UaVvgX4m1NFFIXgReIyjGMA=
git.gammaspectra.live/S.O.N.G/go-ebur128 v0.0.0-20220418202343-73a167e76255 h1:BWRx2ZFyhp5+rsXhdDZtk5Gld+L44lxlN9ASqB9Oj0M=

View file

@ -40,6 +40,7 @@ type StreamMount struct {
Options map[string]interface{}
SampleRate int
Channels int
OffsetStart bool
MetadataQueue *goconcurrentqueue.FIFO
listeners []*StreamListener
listenersLock sync.Mutex
@ -99,6 +100,7 @@ func NewStreamMount(source audio.Source, config *StreamConfig) *StreamMount {
options["bitrate"] = bitrate
}
options["mode"] = config.GetStringOption("mode", "lc")
options["afterburner"] = config.GetBoolOption("afterburner", true)
mimeType = "audio/aac;codecs=mp4a.40.2"
if options["mode"] == "he" || options["mode"] == "hev1" || options["bitrate"] == "vbr2" {
mimeType = "audio/aac;codecs=mp4a.40.5"
@ -140,6 +142,7 @@ func NewStreamMount(source audio.Source, config *StreamConfig) *StreamMount {
options["bitrate"] = bitrate
}
options["mode"] = config.GetStringOption("mode", "lc")
options["afterburner"] = config.GetBoolOption("afterburner", true)
mimeType = "audio/aac;codecs=mp4a.40.2"
if options["mode"] == "he" || options["mode"] == "hev1" || options["bitrate"] == "vbr2" {
mimeType = "audio/aac;codecs=mp4a.40.5"
@ -180,6 +183,7 @@ func NewStreamMount(source audio.Source, config *StreamConfig) *StreamMount {
FormatDescription: encoderFormat.Description(),
Packetizer: packetizerEntry,
SampleRate: sampleRate,
OffsetStart: config.GetBoolOption("offset_start", true),
Channels: channels,
Options: options,
MetadataQueue: goconcurrentqueue.NewFIFO(),

View file

@ -723,7 +723,7 @@ func (q *Queue) HandleRadioRequest(writer http.ResponseWriter, request *http.Req
}
var p []byte
if offsetable, ok := packet.(packetizer.OffsetablePacket); ok {
if offsetable, ok := packet.(packetizer.OffsetablePacket); mount.OffsetStart && ok {
if streamStartOffset <= -1 {
if offsetable.KeepMode() != packetizer.Keep {
streamStartOffset = offsetable.GetStartSampleNumber()
@ -776,7 +776,7 @@ func (q *Queue) HandleRadioRequest(writer http.ResponseWriter, request *http.Req
return requestDone
}
if offsetable, ok := packet.(packetizer.OffsetablePacket); ok {
if offsetable, ok := packet.(packetizer.OffsetablePacket); mount.OffsetStart && ok {
if streamStartOffset <= -1 {
if offsetable.KeepMode() != packetizer.Keep {
streamStartOffset = offsetable.GetStartSampleNumber()