mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2024-12-22 20:52:20 +00:00
More code for SRT handling
This commit is contained in:
parent
a552b48730
commit
92f44c981d
1
go.mod
1
go.mod
@ -5,6 +5,7 @@ go 1.13
|
||||
require (
|
||||
github.com/go-ldap/ldap/v3 v3.2.3
|
||||
github.com/haivision/srtgo v0.0.0-20200731151239-e00427ae473a
|
||||
github.com/pion/rtp v1.6.0
|
||||
github.com/pion/webrtc/v3 v3.0.0-beta.5
|
||||
github.com/prometheus/client_golang v1.7.1
|
||||
github.com/spf13/viper v1.7.1
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"log"
|
||||
|
||||
"github.com/haivision/srtgo"
|
||||
"github.com/pion/rtp"
|
||||
)
|
||||
|
||||
// Options holds web package configuration
|
||||
@ -16,7 +17,7 @@ func Serve(cfg *Options) {
|
||||
log.Printf("SRT server listening on %s", cfg.ListenAddress)
|
||||
|
||||
options := make(map[string]string)
|
||||
options["transtype"] = "file"
|
||||
options["transtype"] = "live"
|
||||
|
||||
// FIXME: cfg.ListenAddress -> host and port
|
||||
sck := srtgo.NewSrtSocket("0.0.0.0", 9710, options)
|
||||
@ -25,24 +26,48 @@ func Serve(cfg *Options) {
|
||||
for {
|
||||
s, err := sck.Accept()
|
||||
if err != nil {
|
||||
log.Println("Error occured while accepting request:", err)
|
||||
log.Println("Error occurred while accepting request:", err)
|
||||
continue
|
||||
}
|
||||
|
||||
go func(s *srtgo.SrtSocket) {
|
||||
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)
|
||||
buff := make([]byte, 2048)
|
||||
n, err := s.Read(buff, 10000)
|
||||
if err != nil {
|
||||
log.Println("Error occurred while reading SRT socket:", err)
|
||||
break
|
||||
}
|
||||
if n == 0 {
|
||||
// End of stream
|
||||
break
|
||||
}
|
||||
|
||||
// Unmarshal the incoming packet
|
||||
packet := &rtp.Packet{}
|
||||
if err = packet.Unmarshal(buff[:n]); err != nil {
|
||||
log.Println("Error occured while unmarshaling SRT:", err)
|
||||
break
|
||||
}
|
||||
|
||||
// videoTrack, err := peerConnection.NewTrack(payloadType, packet.SSRC, "video", "pion")
|
||||
|
||||
// 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)
|
||||
break
|
||||
}
|
||||
}(s)
|
||||
|
||||
log.Printf("Received %d bytes", n)
|
||||
|
||||
packet := &rtp.Packet{}
|
||||
if err := packet.Unmarshal(buff[:n]); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
payloadType := uint8(22) // FIXME put vp8 payload
|
||||
packet.Header.PayloadType = payloadType
|
||||
|
||||
//err := videoTrack.WriteRTP(packet)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user