mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2024-12-22 10:22:19 +00:00
Rename multicast to stream forwarding
This commit is contained in:
parent
6ba297bf96
commit
8f7384ba35
@ -16,6 +16,7 @@ Features:
|
||||
- SRT stream input, supported by FFMpeg, OBS and Gstreamer.
|
||||
- Low-latency streaming, sub-second with web player.
|
||||
- Authentification of incoming stream using LDAP server.
|
||||
- Possibility to forward stream to other streaming servers.
|
||||
|
||||
## Installation on Debian/Ubuntu
|
||||
|
||||
|
@ -17,6 +17,13 @@ auth:
|
||||
# uri: ldap://127.0.0.1:389
|
||||
# userdn: cn=users,dc=example,dc=com
|
||||
|
||||
# Configure stream forwarding
|
||||
forwarding:
|
||||
# Example to forward a stream named "demo" to Twitch and YouTube
|
||||
#demo:
|
||||
# - rtmp://live-cdg.twitch.tv/app/STREAM_KEY
|
||||
# - rtmp://a.rtmp.youtube.com/live2/STREAM_KEY
|
||||
|
||||
# Prometheus monitoring endpoint
|
||||
monitoring:
|
||||
listenAddress: 127.0.0.1:2112
|
||||
@ -46,9 +53,3 @@ webrtc:
|
||||
# STUN servers, you should host your own Coturn instance
|
||||
STUNServers:
|
||||
- stun:stun.l.google.com:19302
|
||||
|
||||
# Configuration for the multicast feature
|
||||
multicast:
|
||||
outputs:
|
||||
# demo:
|
||||
# - rtmp://localhost:1925
|
||||
|
@ -4,7 +4,6 @@ After=syslog.target
|
||||
|
||||
[Service]
|
||||
User=www-data
|
||||
EnvironmentFile=-/etc/default/ghostream
|
||||
ExecStart=/usr/bin/ghostream
|
||||
Restart=on-failure
|
||||
|
||||
|
12
main.go
12
main.go
@ -3,13 +3,13 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"gitlab.crans.org/nounous/ghostream/stream/multicast"
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"gitlab.crans.org/nounous/ghostream/auth"
|
||||
"gitlab.crans.org/nounous/ghostream/internal/monitoring"
|
||||
"gitlab.crans.org/nounous/ghostream/stream/forwarding"
|
||||
"gitlab.crans.org/nounous/ghostream/stream/srt"
|
||||
"gitlab.crans.org/nounous/ghostream/stream/webrtc"
|
||||
"gitlab.crans.org/nounous/ghostream/web"
|
||||
@ -58,7 +58,7 @@ func loadConfiguration() {
|
||||
viper.SetDefault("WebRTC.MinPortUDP", 10000)
|
||||
viper.SetDefault("WebRTC.MaxPortUDP", 10005)
|
||||
viper.SetDefault("WebRTC.STUNServers", []string{"stun:stun.l.google.com:19302"})
|
||||
viper.SetDefault("Multicast.Outputs", make(map[string][]string))
|
||||
viper.SetDefault("Forwarding", make(map[string][]string))
|
||||
|
||||
// Copy STUN configuration to clients
|
||||
viper.Set("Web.STUNServers", viper.Get("WebRTC.STUNServers"))
|
||||
@ -69,8 +69,8 @@ func main() {
|
||||
loadConfiguration()
|
||||
cfg := struct {
|
||||
Auth auth.Options
|
||||
Forwarding forwarding.Options
|
||||
Monitoring monitoring.Options
|
||||
Multicast multicast.Options
|
||||
Srt srt.Options
|
||||
Web web.Options
|
||||
WebRTC webrtc.Options
|
||||
@ -96,10 +96,10 @@ func main() {
|
||||
go web.Serve(remoteSdpChan, localSdpChan, &cfg.Web)
|
||||
go webrtc.Serve(remoteSdpChan, localSdpChan, &cfg.WebRTC)
|
||||
|
||||
// Init multicast
|
||||
err = multicast.New(&cfg.Multicast)
|
||||
// Init stream forwarding
|
||||
err = forwarding.New(&cfg.Forwarding)
|
||||
if err != nil {
|
||||
log.Fatalln("Failed to load multicast app:", err)
|
||||
log.Fatalln("Failed to init stream forwarding:", err)
|
||||
}
|
||||
|
||||
// Wait for routines
|
||||
|
@ -1,14 +1,15 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/spf13/viper"
|
||||
"gitlab.crans.org/nounous/ghostream/auth"
|
||||
"gitlab.crans.org/nounous/ghostream/internal/monitoring"
|
||||
"gitlab.crans.org/nounous/ghostream/stream/multicast"
|
||||
"gitlab.crans.org/nounous/ghostream/stream/forwarding"
|
||||
"gitlab.crans.org/nounous/ghostream/stream/srt"
|
||||
"gitlab.crans.org/nounous/ghostream/stream/webrtc"
|
||||
"gitlab.crans.org/nounous/ghostream/web"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestLoadConfiguration tests the configuration file loading and the init of some parameters
|
||||
@ -16,8 +17,8 @@ func TestLoadConfiguration(t *testing.T) {
|
||||
loadConfiguration()
|
||||
cfg := struct {
|
||||
Auth auth.Options
|
||||
Forwarding forwarding.Options
|
||||
Monitoring monitoring.Options
|
||||
Multicast multicast.Options
|
||||
Srt srt.Options
|
||||
Web web.Options
|
||||
WebRTC webrtc.Options
|
||||
|
@ -1,4 +1,4 @@
|
||||
package multicast
|
||||
package forwarding
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
@ -7,11 +7,9 @@ import (
|
||||
"os/exec"
|
||||
)
|
||||
|
||||
// Options to configure the multicast:
|
||||
//for each stream key, we can have several additional stream URL where the main stream is redirected to
|
||||
type Options struct {
|
||||
Outputs map[string][]string
|
||||
}
|
||||
// Options to configure the stream forwarding.
|
||||
// For each stream name, user can provide several URL to forward stream to
|
||||
type Options map[string][]string
|
||||
|
||||
var (
|
||||
options Options
|
||||
@ -27,12 +25,12 @@ func New(cfg *Options) error {
|
||||
|
||||
// RegisterStream Declare a new open stream and create ffmpeg instances
|
||||
func RegisterStream(streamKey string) {
|
||||
if len(options.Outputs[streamKey]) == 0 {
|
||||
if len(options[streamKey]) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
params := []string{"-re", "-i", "pipe:0"}
|
||||
for _, stream := range options.Outputs[streamKey] {
|
||||
for _, stream := range options[streamKey] {
|
||||
params = append(params, "-f", "flv", "-preset", "ultrafast", "-tune", "zerolatency",
|
||||
"-c", "copy", stream)
|
||||
}
|
1
stream/forwarding/forwarding_test.go
Normal file
1
stream/forwarding/forwarding_test.go
Normal file
@ -0,0 +1 @@
|
||||
package forwarding
|
@ -1 +0,0 @@
|
||||
package multicast
|
@ -1,13 +1,12 @@
|
||||
package srt
|
||||
|
||||
import (
|
||||
"gitlab.crans.org/nounous/ghostream/stream/multicast"
|
||||
"log"
|
||||
"net"
|
||||
"strconv"
|
||||
|
||||
"github.com/haivision/srtgo"
|
||||
"github.com/pion/rtp"
|
||||
"gitlab.crans.org/nounous/ghostream/stream/forwarding"
|
||||
)
|
||||
|
||||
// Options holds web package configuration
|
||||
@ -57,42 +56,33 @@ func Serve(cfg *Options) {
|
||||
// Create a new buffer
|
||||
buff := make([]byte, 2048)
|
||||
|
||||
// Setup linked multicasts
|
||||
multicast.RegisterStream("demo") // FIXME Replace with real stream key
|
||||
// Setup stream forwarding
|
||||
forwarding.RegisterStream("demo") // FIXME Replace with real stream key
|
||||
|
||||
// Read RTP packets forever and send them to the WebRTC Client
|
||||
for {
|
||||
n, err := s.Read(buff, 10000)
|
||||
if err != nil {
|
||||
log.Println("Error occured while reading SRT socket:", err)
|
||||
multicast.CloseConnection("demo")
|
||||
forwarding.CloseConnection("demo")
|
||||
break
|
||||
}
|
||||
|
||||
if n == 0 {
|
||||
// End of stream
|
||||
log.Printf("Received no bytes, stopping stream.")
|
||||
multicast.CloseConnection("demo")
|
||||
forwarding.CloseConnection("demo")
|
||||
break
|
||||
}
|
||||
|
||||
log.Printf("Received %d bytes", n)
|
||||
|
||||
// Send raw packet to other streams
|
||||
multicast.SendPacket("demo", buff[:n])
|
||||
|
||||
// Unmarshal incoming packet
|
||||
packet := &rtp.Packet{}
|
||||
if err := packet.Unmarshal(buff[:n]); err != nil {
|
||||
log.Println("Error occured while unmarshaling SRT:", err)
|
||||
multicast.CloseConnection("demo")
|
||||
break
|
||||
}
|
||||
forwarding.SendPacket("demo", buff[:n])
|
||||
|
||||
// TODO: Send to WebRTC
|
||||
//payloadType := uint8(22) // FIXME put vp8 payload
|
||||
//packet.Header.PayloadType = payloadType
|
||||
//err := videoTrack.WriteRTP(packet)
|
||||
// See https://github.com/ebml-go/webm/blob/master/reader.go
|
||||
//err := videoTrack.WriteSample(media.Sample{Data: data, Samples: uint32(sampleCount)})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user