1
0
mirror of https://gitlab.crans.org/nounous/ghostream.git synced 2025-06-28 05:32:33 +02:00

Send SRT stream to WebRTC package

This commit is contained in:
Alexandre Iooss
2020-10-04 18:22:10 +02:00
parent 3bf27fb0b1
commit ad934516a9
4 changed files with 39 additions and 7 deletions

View File

@ -6,7 +6,7 @@ import (
"github.com/haivision/srtgo"
)
func handleStreamer(s *srtgo.SrtSocket, name string, clientDataChannels *[]chan Packet, forwardingChannel chan Packet) {
func handleStreamer(s *srtgo.SrtSocket, name string, clientDataChannels *[]chan Packet, forwardingChannel, webrtcChannel chan Packet) {
log.Printf("New SRT streamer for stream %s", name)
// Create a new buffer
@ -15,6 +15,7 @@ func handleStreamer(s *srtgo.SrtSocket, name string, clientDataChannels *[]chan
// Setup stream forwarding
forwardingChannel <- Packet{StreamName: name, PacketType: "register", Data: nil}
webrtcChannel <- Packet{StreamName: name, PacketType: "register", Data: nil}
// Read RTP packets forever and send them to the WebRTC Client
for {
@ -36,12 +37,14 @@ func handleStreamer(s *srtgo.SrtSocket, name string, clientDataChannels *[]chan
data := make([]byte, n)
copy(data, buff[:n])
forwardingChannel <- Packet{StreamName: name, PacketType: "sendData", Data: data}
webrtcChannel <- Packet{StreamName: name, PacketType: "sendData", Data: data}
for _, dataChannel := range *clientDataChannels {
dataChannel <- Packet{StreamName: name, PacketType: "sendData", Data: data}
}
}
forwardingChannel <- Packet{StreamName: name, PacketType: "close", Data: nil}
webrtcChannel <- Packet{StreamName: name, PacketType: "close", Data: nil}
}
func handleViewer(s *srtgo.SrtSocket, name string, dataChannel chan Packet, dataChannels *[]chan Packet) {

View File

@ -43,7 +43,7 @@ func splitHostPort(hostport string) (string, uint16) {
}
// Serve SRT server
func Serve(cfg *Options, authBackend auth.Backend, forwardingChannel chan Packet) {
func Serve(cfg *Options, authBackend auth.Backend, forwardingChannel, webrtcChannel chan Packet) {
// Start SRT in listening mode
log.Printf("SRT server listening on %s", cfg.ListenAddress)
host, port := splitHostPort(cfg.ListenAddress)
@ -82,7 +82,7 @@ func Serve(cfg *Options, authBackend auth.Backend, forwardingChannel chan Packet
}
}
go handleStreamer(s, name, &clientDataChannels, forwardingChannel)
go handleStreamer(s, name, &clientDataChannels, forwardingChannel, webrtcChannel)
} else {
// password was not provided so it is a viewer
name := split[0]