1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2024-12-22 10:22:19 +00:00

Restructure projet and add webrtc settings

This commit is contained in:
Alexandre Iooss 2020-09-29 17:04:23 +02:00
parent 29eeb2c0fd
commit 1c98754624
No known key found for this signature in database
GPG Key ID: 6C79278F3FCDCC02
5 changed files with 39 additions and 18 deletions

View File

@ -21,7 +21,14 @@ auth:
monitoring:
listenAddress: 127.0.0.1:2112
# Customize web server
# Configure SRT server
srt:
listenAddress: 127.0.0.1:9710
# Max number of active SRT connections
maxClients: 64
# Configure web server
web:
listenAddress: 127.0.0.1:8080
name: Demo
@ -29,8 +36,8 @@ web:
favicon: https://www.crans.org/images/favicon.ico
widgetURL: https://example.com/
srt:
listenAddress: 127.0.0.1:9710
# Max number of active SRT connections
maxClients: 64
# Configure WebRTC server
webrtc:
# UDP port range used to stream
minPortUDP: 10000
maxPortUDP: 10005

14
main.go
View File

@ -6,12 +6,11 @@ import (
"log"
"strings"
"github.com/pion/webrtc/v3"
"github.com/spf13/viper"
"gitlab.crans.org/nounous/ghostream/auth"
"gitlab.crans.org/nounous/ghostream/internal/monitoring"
"gitlab.crans.org/nounous/ghostream/stream"
"gitlab.crans.org/nounous/ghostream/stream/srt"
"gitlab.crans.org/nounous/ghostream/stream/webrtc"
"gitlab.crans.org/nounous/ghostream/web"
)
@ -49,11 +48,13 @@ func loadConfiguration() {
viper.SetDefault("Auth.LDAP.UserDn", "cn=users,dc=example,dc=com")
viper.SetDefault("Monitoring.ListenAddress", ":2112")
viper.SetDefault("Srt.ListenAddress", ":9710")
viper.SetDefault("Srt.MaxClients", "64")
viper.SetDefault("Srt.MaxClients", 64)
viper.SetDefault("Web.ListenAddress", ":8080")
viper.SetDefault("Web.Name", "Ghostream")
viper.SetDefault("Web.Hostname", "localhost")
viper.SetDefault("Web.Favicon", "/favicon.ico")
viper.SetDefault("WebRTC.MinPortUDP", 10000)
viper.SetDefault("WebRTC.MaxPortUDP", 10005)
}
func main() {
@ -64,6 +65,7 @@ func main() {
Monitoring monitoring.Options
Srt srt.Options
Web web.Options
WebRTC webrtc.Options
}{}
if err := viper.Unmarshal(&cfg); err != nil {
log.Fatalln("Failed to load settings", err)
@ -81,10 +83,10 @@ func main() {
localSdpChan := make(chan webrtc.SessionDescription)
// Start stream, web and monitoring server
go srt.Serve(&cfg.Srt)
go stream.Serve(remoteSdpChan, localSdpChan)
go web.Serve(remoteSdpChan, localSdpChan, &cfg.Web)
go monitoring.Serve(&cfg.Monitoring)
go srt.Serve(&cfg.Srt)
go web.Serve(remoteSdpChan, localSdpChan, &cfg.Web)
go webrtc.Serve(remoteSdpChan, localSdpChan, &cfg.WebRTC)
// Wait for routines
select {}

View File

@ -1 +0,0 @@
package stream

View File

@ -1,4 +1,4 @@
package stream
package webrtc
import (
"fmt"
@ -14,6 +14,16 @@ import (
"github.com/pion/webrtc/v3/pkg/media/oggreader"
)
// Options holds web package configuration
type Options struct {
MinPortUDP uint16
MaxPortUDP uint16
}
// SessionDescription contains SDP data
// to initiate a WebRTC connection between one client and this app
type SessionDescription = webrtc.SessionDescription
const (
audioFileName = "output.ogg"
videoFileName = "output.ivf"
@ -36,7 +46,7 @@ func removeTrack(tracks []*webrtc.Track, track *webrtc.Track) []*webrtc.Track {
// newPeerHandler is called when server receive a new session description
// this initiates a WebRTC connection and return server description
func newPeerHandler(remoteSdp webrtc.SessionDescription) webrtc.SessionDescription {
func newPeerHandler(remoteSdp webrtc.SessionDescription, cfg *Options) webrtc.SessionDescription {
// Create media engine using client SDP
mediaEngine := webrtc.MediaEngine{}
if err := mediaEngine.PopulateFromSDP(remoteSdp); err != nil {
@ -46,7 +56,7 @@ func newPeerHandler(remoteSdp webrtc.SessionDescription) webrtc.SessionDescripti
// Create a new PeerConnection
settingsEngine := webrtc.SettingEngine{}
if err := settingsEngine.SetEphemeralUDPPortRange(10000, 10005); err != nil {
if err := settingsEngine.SetEphemeralUDPPortRange(cfg.MinPortUDP, cfg.MaxPortUDP); err != nil {
log.Println("Failed to set min/max UDP ports", err)
return webrtc.SessionDescription{}
}
@ -227,7 +237,9 @@ func getPayloadType(m webrtc.MediaEngine, codecType webrtc.RTPCodecType, codecNa
}
// Serve WebRTC media streaming server
func Serve(remoteSdpChan chan webrtc.SessionDescription, localSdpChan chan webrtc.SessionDescription) {
func Serve(remoteSdpChan, localSdpChan chan webrtc.SessionDescription, cfg *Options) {
log.Printf("WebRTC server using UDP from %d to %d", cfg.MinPortUDP, cfg.MaxPortUDP)
go playVideo()
go playAudio()
@ -236,6 +248,6 @@ func Serve(remoteSdpChan chan webrtc.SessionDescription, localSdpChan chan webrt
// Wait for incoming session description
// then send the local description to browser
offer := <-remoteSdpChan
localSdpChan <- newPeerHandler(offer)
localSdpChan <- newPeerHandler(offer, cfg)
}
}

View File

@ -0,0 +1 @@
package webrtc