2020-09-28 15:36:40 +00:00
|
|
|
//go:generate pkger
|
|
|
|
|
2020-10-09 20:36:02 +00:00
|
|
|
// Package main provides the full-featured server with configuration loading
|
|
|
|
// and communication between routines.
|
2020-09-21 15:29:50 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2020-09-21 17:59:41 +00:00
|
|
|
"log"
|
|
|
|
|
2020-09-22 09:42:57 +00:00
|
|
|
"gitlab.crans.org/nounous/ghostream/auth"
|
2020-10-11 19:35:43 +00:00
|
|
|
"gitlab.crans.org/nounous/ghostream/internal/config"
|
2020-09-21 19:38:11 +00:00
|
|
|
"gitlab.crans.org/nounous/ghostream/internal/monitoring"
|
2020-09-30 13:07:36 +00:00
|
|
|
"gitlab.crans.org/nounous/ghostream/stream/forwarding"
|
2020-09-27 09:14:22 +00:00
|
|
|
"gitlab.crans.org/nounous/ghostream/stream/srt"
|
2020-09-29 15:04:23 +00:00
|
|
|
"gitlab.crans.org/nounous/ghostream/stream/webrtc"
|
2020-09-21 15:47:31 +00:00
|
|
|
"gitlab.crans.org/nounous/ghostream/web"
|
2020-09-21 15:29:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2020-10-05 09:38:17 +00:00
|
|
|
// Configure logger
|
|
|
|
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
|
|
|
|
|
2020-09-21 17:59:41 +00:00
|
|
|
// Load configuration
|
2020-10-11 19:35:43 +00:00
|
|
|
cfg, err := config.Load()
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln("Failed to load configuration:", err)
|
2020-09-21 17:59:41 +00:00
|
|
|
}
|
|
|
|
|
2020-09-22 10:54:12 +00:00
|
|
|
// Init authentification
|
2020-09-22 12:16:52 +00:00
|
|
|
authBackend, err := auth.New(&cfg.Auth)
|
|
|
|
if err != nil {
|
|
|
|
log.Fatalln("Failed to load authentification backend:", err)
|
|
|
|
}
|
2020-10-09 20:06:30 +00:00
|
|
|
if authBackend != nil {
|
|
|
|
defer authBackend.Close()
|
|
|
|
}
|
2020-09-22 10:54:12 +00:00
|
|
|
|
2020-09-24 09:24:13 +00:00
|
|
|
// WebRTC session description channels
|
2020-10-05 20:00:08 +00:00
|
|
|
remoteSdpChan := make(chan struct {
|
|
|
|
StreamID string
|
|
|
|
RemoteDescription webrtc.SessionDescription
|
|
|
|
})
|
2020-09-24 09:24:13 +00:00
|
|
|
localSdpChan := make(chan webrtc.SessionDescription)
|
2020-09-21 19:05:45 +00:00
|
|
|
|
2020-10-04 16:22:10 +00:00
|
|
|
// SRT channel for forwarding and webrtc
|
2020-10-02 22:08:32 +00:00
|
|
|
forwardingChannel := make(chan srt.Packet, 65536)
|
2020-10-04 16:22:10 +00:00
|
|
|
webrtcChannel := make(chan srt.Packet, 65536)
|
2020-10-01 10:00:59 +00:00
|
|
|
|
2020-10-11 19:35:43 +00:00
|
|
|
// Start routines
|
2020-10-04 18:16:29 +00:00
|
|
|
go forwarding.Serve(forwardingChannel, cfg.Forwarding)
|
2020-09-29 15:04:23 +00:00
|
|
|
go monitoring.Serve(&cfg.Monitoring)
|
2020-10-04 16:22:10 +00:00
|
|
|
go srt.Serve(&cfg.Srt, authBackend, forwardingChannel, webrtcChannel)
|
2020-09-24 09:24:13 +00:00
|
|
|
go web.Serve(remoteSdpChan, localSdpChan, &cfg.Web)
|
2020-10-04 16:22:10 +00:00
|
|
|
go webrtc.Serve(remoteSdpChan, localSdpChan, webrtcChannel, &cfg.WebRTC)
|
2020-09-21 19:33:32 +00:00
|
|
|
|
2020-09-21 19:05:45 +00:00
|
|
|
// Wait for routines
|
|
|
|
select {}
|
2020-09-21 15:29:50 +00:00
|
|
|
}
|