mirror of
https://gitlab.crans.org/nounous/ghostream.git
synced 2024-12-23 00:22:19 +00:00
Use logger rather than panic in ingest
This commit is contained in:
parent
cbe6a00d1a
commit
76f009efe3
3
main.go
3
main.go
@ -79,6 +79,9 @@ func loadConfiguration() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
// Configure logger
|
||||||
|
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
|
||||||
|
|
||||||
// Load configuration
|
// Load configuration
|
||||||
loadConfiguration()
|
loadConfiguration()
|
||||||
cfg := struct {
|
cfg := struct {
|
||||||
|
@ -15,6 +15,7 @@ func ingestFrom(inputChannel chan srt.Packet) {
|
|||||||
// FIXME Clean code
|
// FIXME Clean code
|
||||||
var ffmpeg *exec.Cmd
|
var ffmpeg *exec.Cmd
|
||||||
var ffmpegInput io.WriteCloser
|
var ffmpegInput io.WriteCloser
|
||||||
|
|
||||||
for {
|
for {
|
||||||
var err error = nil
|
var err error = nil
|
||||||
packet := <-inputChannel
|
packet := <-inputChannel
|
||||||
@ -22,23 +23,23 @@ func ingestFrom(inputChannel chan srt.Packet) {
|
|||||||
case "register":
|
case "register":
|
||||||
log.Printf("WebRTC RegisterStream %s", packet.StreamName)
|
log.Printf("WebRTC RegisterStream %s", packet.StreamName)
|
||||||
|
|
||||||
// From https://github.com/pion/webrtc/blob/master/examples/rtp-to-webrtc/main.go
|
|
||||||
|
|
||||||
// Open a UDP Listener for RTP Packets on port 5004
|
// Open a UDP Listener for RTP Packets on port 5004
|
||||||
videoListener, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 5004})
|
videoListener, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 5004})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Printf("Faited to open UDP listener %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
audioListener, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 5005})
|
audioListener, err := net.ListenUDP("udp", &net.UDPAddr{IP: net.ParseIP("127.0.0.1"), Port: 5005})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Printf("Faited to open UDP listener %s", err)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
defer func() {
|
defer func() {
|
||||||
if err = videoListener.Close(); err != nil {
|
if err = videoListener.Close(); err != nil {
|
||||||
panic(err)
|
log.Printf("Faited to close UDP listener %s", err)
|
||||||
}
|
}
|
||||||
if err = audioListener.Close(); err != nil {
|
if err = audioListener.Close(); err != nil {
|
||||||
panic(err)
|
log.Printf("Faited to close UDP listener %s", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
@ -68,11 +69,13 @@ func ingestFrom(inputChannel chan srt.Packet) {
|
|||||||
inboundRTPPacket := make([]byte, 1500) // UDP MTU
|
inboundRTPPacket := make([]byte, 1500) // UDP MTU
|
||||||
n, _, err := videoListener.ReadFromUDP(inboundRTPPacket)
|
n, _, err := videoListener.ReadFromUDP(inboundRTPPacket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Printf("Failed to read from UDP: %s", err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
packet := &rtp.Packet{}
|
packet := &rtp.Packet{}
|
||||||
if err := packet.Unmarshal(inboundRTPPacket[:n]); err != nil {
|
if err := packet.Unmarshal(inboundRTPPacket[:n]); err != nil {
|
||||||
panic(err)
|
log.Printf("Failed to unmarshal RTP packet: %s", err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write RTP packet to all video tracks
|
// Write RTP packet to all video tracks
|
||||||
@ -81,7 +84,8 @@ func ingestFrom(inputChannel chan srt.Packet) {
|
|||||||
packet.Header.PayloadType = videoTrack.PayloadType()
|
packet.Header.PayloadType = videoTrack.PayloadType()
|
||||||
packet.Header.SSRC = videoTrack.SSRC()
|
packet.Header.SSRC = videoTrack.SSRC()
|
||||||
if writeErr := videoTrack.WriteRTP(packet); writeErr != nil {
|
if writeErr := videoTrack.WriteRTP(packet); writeErr != nil {
|
||||||
panic(err)
|
log.Printf("Failed to write to video track: %s", err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,11 +97,13 @@ func ingestFrom(inputChannel chan srt.Packet) {
|
|||||||
inboundRTPPacket := make([]byte, 1500) // UDP MTU
|
inboundRTPPacket := make([]byte, 1500) // UDP MTU
|
||||||
n, _, err := audioListener.ReadFromUDP(inboundRTPPacket)
|
n, _, err := audioListener.ReadFromUDP(inboundRTPPacket)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
log.Printf("Failed to read from UDP: %s", err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
packet := &rtp.Packet{}
|
packet := &rtp.Packet{}
|
||||||
if err := packet.Unmarshal(inboundRTPPacket[:n]); err != nil {
|
if err := packet.Unmarshal(inboundRTPPacket[:n]); err != nil {
|
||||||
panic(err)
|
log.Printf("Failed to unmarshal RTP packet: %s", err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Write RTP packet to all audio tracks
|
// Write RTP packet to all audio tracks
|
||||||
@ -106,7 +112,8 @@ func ingestFrom(inputChannel chan srt.Packet) {
|
|||||||
packet.Header.PayloadType = audioTrack.PayloadType()
|
packet.Header.PayloadType = audioTrack.PayloadType()
|
||||||
packet.Header.SSRC = audioTrack.SSRC()
|
packet.Header.SSRC = audioTrack.SSRC()
|
||||||
if writeErr := audioTrack.WriteRTP(packet); writeErr != nil {
|
if writeErr := audioTrack.WriteRTP(packet); writeErr != nil {
|
||||||
panic(err)
|
log.Printf("Failed to write to audio track: %s", err)
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -121,9 +128,8 @@ func ingestFrom(inputChannel chan srt.Packet) {
|
|||||||
break
|
break
|
||||||
case "sendData":
|
case "sendData":
|
||||||
// FIXME send to stream packet.StreamName
|
// FIXME send to stream packet.StreamName
|
||||||
_, err := ffmpegInput.Write(packet.Data)
|
if _, err := ffmpegInput.Write(packet.Data); err != nil {
|
||||||
if err != nil {
|
log.Printf("Failed to write data to ffmpeg input: %s", err)
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
break
|
break
|
||||||
case "close":
|
case "close":
|
||||||
|
Loading…
Reference in New Issue
Block a user