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

Rename multicast to stream forwarding

This commit is contained in:
Alexandre Iooss
2020-09-30 15:07:36 +02:00
parent 6ba297bf96
commit 8f7384ba35
9 changed files with 33 additions and 43 deletions

View File

@ -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)})
}
}
}