1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2025-06-27 20:22:16 +02:00

Better error handling in stream forwarder

This commit is contained in:
Alexandre Iooss
2020-09-30 15:28:19 +02:00
parent 2550d75c57
commit 8883c878bf
3 changed files with 35 additions and 26 deletions

View File

@ -57,21 +57,23 @@ func Serve(cfg *Options) {
buff := make([]byte, 2048)
// Setup stream forwarding
forwarding.RegisterStream("demo") // FIXME Replace with real stream key
// 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
}
// 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)
forwarding.CloseConnection("demo")
break
}
if n == 0 {
// End of stream
log.Printf("Received no bytes, stopping stream.")
forwarding.CloseConnection("demo")
break
}
@ -84,5 +86,9 @@ func Serve(cfg *Options) {
// 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)
}
}
}