mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2024-12-22 15:02:19 +00:00
Restructure projet and add webrtc settings
This commit is contained in:
parent
29eeb2c0fd
commit
1c98754624
@ -21,7 +21,14 @@ auth:
|
|||||||
monitoring:
|
monitoring:
|
||||||
listenAddress: 127.0.0.1:2112
|
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:
|
web:
|
||||||
listenAddress: 127.0.0.1:8080
|
listenAddress: 127.0.0.1:8080
|
||||||
name: Demo
|
name: Demo
|
||||||
@ -29,8 +36,8 @@ web:
|
|||||||
favicon: https://www.crans.org/images/favicon.ico
|
favicon: https://www.crans.org/images/favicon.ico
|
||||||
widgetURL: https://example.com/
|
widgetURL: https://example.com/
|
||||||
|
|
||||||
srt:
|
# Configure WebRTC server
|
||||||
listenAddress: 127.0.0.1:9710
|
webrtc:
|
||||||
|
# UDP port range used to stream
|
||||||
# Max number of active SRT connections
|
minPortUDP: 10000
|
||||||
maxClients: 64
|
maxPortUDP: 10005
|
||||||
|
14
main.go
14
main.go
@ -6,12 +6,11 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/pion/webrtc/v3"
|
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
"gitlab.crans.org/nounous/ghostream/auth"
|
"gitlab.crans.org/nounous/ghostream/auth"
|
||||||
"gitlab.crans.org/nounous/ghostream/internal/monitoring"
|
"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/srt"
|
||||||
|
"gitlab.crans.org/nounous/ghostream/stream/webrtc"
|
||||||
"gitlab.crans.org/nounous/ghostream/web"
|
"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("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("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")
|
||||||
viper.SetDefault("Web.Favicon", "/favicon.ico")
|
viper.SetDefault("Web.Favicon", "/favicon.ico")
|
||||||
|
viper.SetDefault("WebRTC.MinPortUDP", 10000)
|
||||||
|
viper.SetDefault("WebRTC.MaxPortUDP", 10005)
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -64,6 +65,7 @@ func main() {
|
|||||||
Monitoring monitoring.Options
|
Monitoring monitoring.Options
|
||||||
Srt srt.Options
|
Srt srt.Options
|
||||||
Web web.Options
|
Web web.Options
|
||||||
|
WebRTC webrtc.Options
|
||||||
}{}
|
}{}
|
||||||
if err := viper.Unmarshal(&cfg); err != nil {
|
if err := viper.Unmarshal(&cfg); err != nil {
|
||||||
log.Fatalln("Failed to load settings", err)
|
log.Fatalln("Failed to load settings", err)
|
||||||
@ -81,10 +83,10 @@ func main() {
|
|||||||
localSdpChan := make(chan webrtc.SessionDescription)
|
localSdpChan := make(chan webrtc.SessionDescription)
|
||||||
|
|
||||||
// Start stream, web and monitoring server
|
// 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 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
|
// Wait for routines
|
||||||
select {}
|
select {}
|
||||||
|
@ -1 +0,0 @@
|
|||||||
package stream
|
|
@ -1,4 +1,4 @@
|
|||||||
package stream
|
package webrtc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@ -14,6 +14,16 @@ import (
|
|||||||
"github.com/pion/webrtc/v3/pkg/media/oggreader"
|
"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 (
|
const (
|
||||||
audioFileName = "output.ogg"
|
audioFileName = "output.ogg"
|
||||||
videoFileName = "output.ivf"
|
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
|
// newPeerHandler is called when server receive a new session description
|
||||||
// this initiates a WebRTC connection and return server 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
|
// Create media engine using client SDP
|
||||||
mediaEngine := webrtc.MediaEngine{}
|
mediaEngine := webrtc.MediaEngine{}
|
||||||
if err := mediaEngine.PopulateFromSDP(remoteSdp); err != nil {
|
if err := mediaEngine.PopulateFromSDP(remoteSdp); err != nil {
|
||||||
@ -46,7 +56,7 @@ func newPeerHandler(remoteSdp webrtc.SessionDescription) webrtc.SessionDescripti
|
|||||||
|
|
||||||
// Create a new PeerConnection
|
// Create a new PeerConnection
|
||||||
settingsEngine := webrtc.SettingEngine{}
|
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)
|
log.Println("Failed to set min/max UDP ports", err)
|
||||||
return webrtc.SessionDescription{}
|
return webrtc.SessionDescription{}
|
||||||
}
|
}
|
||||||
@ -227,7 +237,9 @@ func getPayloadType(m webrtc.MediaEngine, codecType webrtc.RTPCodecType, codecNa
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Serve WebRTC media streaming server
|
// 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 playVideo()
|
||||||
go playAudio()
|
go playAudio()
|
||||||
|
|
||||||
@ -236,6 +248,6 @@ func Serve(remoteSdpChan chan webrtc.SessionDescription, localSdpChan chan webrt
|
|||||||
// Wait for incoming session description
|
// Wait for incoming session description
|
||||||
// then send the local description to browser
|
// then send the local description to browser
|
||||||
offer := <-remoteSdpChan
|
offer := <-remoteSdpChan
|
||||||
localSdpChan <- newPeerHandler(offer)
|
localSdpChan <- newPeerHandler(offer, cfg)
|
||||||
}
|
}
|
||||||
}
|
}
|
1
stream/webrtc/webrtc_test.go
Normal file
1
stream/webrtc/webrtc_test.go
Normal file
@ -0,0 +1 @@
|
|||||||
|
package webrtc
|
Loading…
Reference in New Issue
Block a user