1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2025-06-27 11:28:51 +02:00

Make webrtc and forwarding work with new messaging

This commit is contained in:
Alexandre Iooss
2020-10-18 16:05:28 +02:00
parent 37d944621b
commit b9da2ab3a7
6 changed files with 144 additions and 120 deletions

View File

@ -2,12 +2,10 @@
package forwarding
import (
"bufio"
"io"
"log"
"os/exec"
"time"
"gitlab.crans.org/nounous/ghostream/stream/srt"
"gitlab.crans.org/nounous/ghostream/stream"
)
// Options to configure the stream forwarding.
@ -15,21 +13,46 @@ import (
type Options map[string][]string
// Serve handles incoming packets from SRT and forward them to other external services
func Serve(inputChannel chan srt.Packet, cfg Options) {
func Serve(streams map[string]*stream.Stream, cfg Options) {
if len(cfg) < 1 {
// No forwarding, ignore
for {
<-inputChannel // Clear input channel
}
return
}
log.Printf("Stream forwarding initialized")
ffmpegInstances := make(map[string]*exec.Cmd)
for {
for name, st := range streams {
fwdCfg, ok := cfg[name]
if !ok {
// Not configured
continue
}
// Start forwarding
log.Printf("Starting forwarding for '%s'", name)
go forward(st, fwdCfg)
}
// Regulary pull stream list,
// it may be better to tweak the messaging system
// to get an event on a new stream.
time.Sleep(time.Second)
}
}
func forward(st *stream.Stream, fwdCfg []string) {
// FIXME
/*ffmpegInstances := make(map[string]*exec.Cmd)
ffmpegInputStreams := make(map[string]*io.WriteCloser)
for {
var err error = nil
// Wait for packets
packet := <-inputChannel
// FIXME packet := <-inputChannel
packet := srt.Packet{
Data: []byte{},
PacketType: "nothing",
StreamName: "demo",
}
switch packet.PacketType {
case "register":
err = registerStream(packet.StreamName, ffmpegInstances, ffmpegInputStreams, cfg)
@ -47,9 +70,10 @@ func Serve(inputChannel chan srt.Packet, cfg Options) {
if err != nil {
log.Printf("Error occurred while receiving SRT packet of type %s: %s", packet.PacketType, err)
}
}
}*/
}
/*
// registerStream creates ffmpeg instance associated with newly created stream
func registerStream(name string, ffmpegInstances map[string]*exec.Cmd, ffmpegInputStreams map[string]*io.WriteCloser, cfg Options) error {
streams, exist := cfg[name]
@ -119,3 +143,4 @@ func close(name string, ffmpegInstances map[string]*exec.Cmd, ffmpegInputStreams
delete(ffmpegInputStreams, name)
return nil
}
*/

View File

@ -6,6 +6,7 @@ import (
"testing"
"time"
"gitlab.crans.org/nounous/ghostream/stream"
"gitlab.crans.org/nounous/ghostream/stream/srt"
)
@ -30,16 +31,15 @@ func TestForwardStream(t *testing.T) {
}
}()
forwardingList := make(map[string][]string)
forwardingList["demo"] = []string{"rtmp://127.0.0.1:1936/live/app"}
forwardingChannel := make(chan srt.Packet)
cfg := make(map[string][]string)
cfg["demo"] = []string{"rtmp://127.0.0.1:1936/live/app"}
// Register forwarding stream list
go Serve(forwardingChannel, forwardingList)
streams := make(map[string]*stream.Stream)
go Serve(streams, cfg)
// Serve SRT Server without authentification backend
go srt.Serve(&srt.Options{Enabled: true, ListenAddress: ":9712", MaxClients: 2}, nil, forwardingChannel, nil)
go srt.Serve(streams, nil, &srt.Options{Enabled: true, ListenAddress: ":9712", MaxClients: 2})
ffmpeg := exec.Command("ffmpeg", "-hide_banner", "-loglevel", "error",
"-re", "-f", "lavfi", "-i", "testsrc=size=640x480:rate=10",