mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2024-12-22 19:42:20 +00:00
Load SRT host and port from configuration
This commit is contained in:
parent
c905eadc78
commit
29eeb2c0fd
@ -31,3 +31,6 @@ web:
|
|||||||
|
|
||||||
srt:
|
srt:
|
||||||
listenAddress: 127.0.0.1:9710
|
listenAddress: 127.0.0.1:9710
|
||||||
|
|
||||||
|
# Max number of active SRT connections
|
||||||
|
maxClients: 64
|
||||||
|
1
main.go
1
main.go
@ -49,6 +49,7 @@ func loadConfiguration() {
|
|||||||
viper.SetDefault("Auth.LDAP.UserDn", "cn=users,dc=example,dc=com")
|
viper.SetDefault("Auth.LDAP.UserDn", "cn=users,dc=example,dc=com")
|
||||||
viper.SetDefault("Monitoring.ListenAddress", ":2112")
|
viper.SetDefault("Monitoring.ListenAddress", ":2112")
|
||||||
viper.SetDefault("Srt.ListenAddress", ":9710")
|
viper.SetDefault("Srt.ListenAddress", ":9710")
|
||||||
|
viper.SetDefault("Srt.MaxClients", "64")
|
||||||
viper.SetDefault("Web.ListenAddress", ":8080")
|
viper.SetDefault("Web.ListenAddress", ":8080")
|
||||||
viper.SetDefault("Web.Name", "Ghostream")
|
viper.SetDefault("Web.Name", "Ghostream")
|
||||||
viper.SetDefault("Web.Hostname", "localhost")
|
viper.SetDefault("Web.Hostname", "localhost")
|
||||||
|
@ -2,6 +2,8 @@ package srt
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
"github.com/haivision/srtgo"
|
"github.com/haivision/srtgo"
|
||||||
"github.com/pion/rtp"
|
"github.com/pion/rtp"
|
||||||
@ -10,18 +12,34 @@ import (
|
|||||||
// Options holds web package configuration
|
// Options holds web package configuration
|
||||||
type Options struct {
|
type Options struct {
|
||||||
ListenAddress string
|
ListenAddress string
|
||||||
|
MaxClients int
|
||||||
|
}
|
||||||
|
|
||||||
|
// Split host and port from listen address
|
||||||
|
func splitHostPort(hostport string) (string, uint16) {
|
||||||
|
host, portS, err := net.SplitHostPort(hostport)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to split host and port from %s", hostport)
|
||||||
|
}
|
||||||
|
if host == "" {
|
||||||
|
host = "0.0.0.0"
|
||||||
|
}
|
||||||
|
port64, err := strconv.ParseUint(portS, 10, 16)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Port is not a integer: %s", err)
|
||||||
|
}
|
||||||
|
return host, uint16(port64)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Serve SRT server
|
// Serve SRT server
|
||||||
func Serve(cfg *Options) {
|
func Serve(cfg *Options) {
|
||||||
log.Printf("SRT server listening on %s", cfg.ListenAddress)
|
|
||||||
|
|
||||||
options := make(map[string]string)
|
options := make(map[string]string)
|
||||||
options["transtype"] = "live"
|
options["transtype"] = "live"
|
||||||
|
|
||||||
// FIXME: cfg.ListenAddress -> host and port
|
log.Printf("SRT server listening on %s", cfg.ListenAddress)
|
||||||
sck := srtgo.NewSrtSocket("0.0.0.0", 9710, options)
|
host, port := splitHostPort(cfg.ListenAddress)
|
||||||
sck.Listen(1)
|
sck := srtgo.NewSrtSocket(host, uint16(port), options)
|
||||||
|
sck.Listen(cfg.MaxClients)
|
||||||
|
|
||||||
for {
|
for {
|
||||||
s, err := sck.Accept()
|
s, err := sck.Accept()
|
||||||
|
Loading…
Reference in New Issue
Block a user