1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2025-06-29 07:30:54 +02:00

Use channels to send SRT packets to forwarded streams

This commit is contained in:
Yohann D'ANELLO
2020-10-01 12:00:59 +02:00
parent dc7a3fef9f
commit efa44488c0
5 changed files with 54 additions and 21 deletions

View File

@ -14,6 +14,12 @@ type Options struct {
MaxClients int
}
type Packet struct {
Data []byte
PacketType string
StreamName string
}
// Split host and port from listen address
func splitHostPort(hostport string) (string, uint16) {
host, portS, err := net.SplitHostPort(hostport)
@ -31,7 +37,7 @@ func splitHostPort(hostport string) (string, uint16) {
}
// Serve SRT server
func Serve(cfg *Options) {
func Serve(cfg *Options, forwardingChannel chan Packet) {
options := make(map[string]string)
options["transtype"] = "live"
@ -59,10 +65,7 @@ func Serve(cfg *Options) {
// Setup stream forwarding
// FIXME: demo should be replaced by stream name
/* if err := forwarding.RegisterStream("demo"); err != nil {
log.Println("Error occurred during forward stream init:", err)
break
} */
forwardingChannel <- Packet{StreamName: "demo", PacketType: "register", Data: nil}
// Read RTP packets forever and send them to the WebRTC Client
for {
@ -81,15 +84,13 @@ func Serve(cfg *Options) {
// log.Printf("Received %d bytes", n)
// Send raw packet to other streams
// forwarding.SendPacket("demo", buff[:n])
forwardingChannel <- Packet{StreamName: "demo", PacketType: "sendData", Data: buff[:n]}
// TODO: Send to WebRTC
// See https://github.com/ebml-go/webm/blob/master/reader.go
//err := videoTrack.WriteSample(media.Sample{Data: data, Samples: uint32(sampleCount)})
}
/* if err := forwarding.CloseConnection("demo"); err != nil {
log.Printf("Failed to close forward stream: %s", err)
} */
forwardingChannel <- Packet{StreamName: "demo", PacketType: "close", Data: nil}
}
}

View File

@ -36,7 +36,7 @@ func TestServeSRT(t *testing.T) {
t.Skip("WARNING: FFMPEG is not installed. Skipping stream test")
}
go Serve(&Options{ListenAddress: ":9711", MaxClients: 2})
go Serve(&Options{ListenAddress: ":9711", MaxClients: 2}, nil)
ffmpeg := exec.Command("ffmpeg",
"-i", "http://ftp.crans.org/events/Blender%20OpenMovies/big_buck_bunny_480p_stereo.ogg",