mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2025-06-27 07:58:50 +02:00
Rename multicast to stream forwarding
This commit is contained in:
@ -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)})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user