1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2024-12-23 10:52:19 +00:00
ghostream/stream/srt/srt.go

49 lines
892 B
Go
Raw Normal View History

2020-09-27 09:14:22 +00:00
package srt
import (
"log"
2020-09-27 18:43:00 +00:00
"github.com/haivision/srtgo"
2020-09-27 09:14:22 +00:00
)
// Options holds web package configuration
type Options struct {
ListenAddress string
}
// Serve SRT server
func Serve(cfg *Options) {
log.Printf("SRT server listening on %s", cfg.ListenAddress)
2020-09-27 18:43:00 +00:00
options := make(map[string]string)
options["transtype"] = "file"
// FIXME: cfg.ListenAddress -> host and port
sck := srtgo.NewSrtSocket("0.0.0.0", 9710, options)
sck.Listen(1)
2020-09-27 09:14:22 +00:00
2020-09-27 18:43:00 +00:00
for {
2020-09-27 20:10:47 +00:00
s, err := sck.Accept()
if err != nil {
log.Println("Error occured while accepting request:", err)
2020-09-27 20:27:18 +00:00
continue
2020-09-27 18:43:00 +00:00
}
2020-09-27 20:10:47 +00:00
2020-09-27 20:32:49 +00:00
go func(s *srtgo.SrtSocket) {
2020-09-27 20:10:47 +00:00
buff := make([]byte, 2048)
for {
n, err := s.Read(buff, 10000)
if err != nil {
log.Println("Error occured while reading SRT socket:", err)
break
}
if n == 0 {
// End of stream
break
}
log.Printf("Received %d bytes", n)
}
2020-09-27 20:27:18 +00:00
}(s)
2020-09-27 09:14:22 +00:00
}
}