diff --git a/machinery/src/components/Kerberos.go b/machinery/src/components/Kerberos.go index bfa75ae..a975e32 100644 --- a/machinery/src/components/Kerberos.go +++ b/machinery/src/components/Kerberos.go @@ -2,7 +2,6 @@ package components import ( "context" - "fmt" "os" "strconv" "sync/atomic" @@ -296,10 +295,13 @@ func RunAgent(configDirectory string, configuration *models.Configuration, commu communication.HandleAudio = make(chan models.AudioDataPartial, 10) if rtspBackChannelClient.HasBackChannel { communication.HasBackChannel = true - go WriteFileToBackChannel(communication, rtspBackChannelClient) + for { + go WriteFileToBackChannel(communication, rtspBackChannelClient) + time.Sleep(3 * time.Second) + } } //go onvif.HandleAudioActions(configuration, communication, rtspBackChannelClient) - go func() { + /*go func() { for action := range communication.HandleAudio { fmt.Println("onvif.HandleAudioActions(): action", action) // Ensure cloud.WriteFileToBackChannel is implemented or replace with a valid function @@ -309,7 +311,7 @@ func RunAgent(configDirectory string, configuration *models.Configuration, commu fmt.Println("cloud.WriteFileToBackChannel is not defined") } } - }() + }()*/ // If we reach this point, we have a working RTSP connection. communication.CameraConnected = true diff --git a/machinery/src/components/backchannel.go b/machinery/src/components/backchannel.go index 269aa7e..0f333cd 100644 --- a/machinery/src/components/backchannel.go +++ b/machinery/src/components/backchannel.go @@ -2,6 +2,7 @@ package components import ( "bufio" + "context" "fmt" "os" "time" @@ -102,8 +103,8 @@ func WriteFileToBackChannel(communication *models.Communication, rtspClient capt Packet: &rtp.Packet{ Header: rtp.Header{ Version: 2, - Marker: true, // should be true - PayloadType: 0, //packet.PayloadType, // will be owerwriten + Marker: false, // should be true + PayloadType: 0, //packet.PayloadType, // will be owerwriten SequenceNumber: sequenceNumber, Timestamp: uint32(length), SSRC: ssrc, @@ -114,6 +115,20 @@ func WriteFileToBackChannel(communication *models.Communication, rtspClient capt err = rtspClient.WritePacket(pkt) if err != nil { log.Log.Error("Audio.WriteFileToBackChannel(): error writing packet to backchannel") + if err.Error() == "EOF" { + log.Log.Info("Audio.WriteFileToBackChannel(): EOF, restarting backchannel") + rtspClient.Close() + err = rtspClient.ConnectBackChannel(context.Background()) + if err != nil { + log.Log.Error("Audio.WriteFileToBackChannel(): error connecting to backchannel") + fmt.Println(err) + } + err = rtspClient.StartBackChannel(context.Background()) + if err != nil { + log.Log.Error("Audio.WriteFileToBackChannel(): error starting backchannel") + fmt.Println(err) + } + } } else { log.Log.Info("Audio.WriteFileToBackChannel(): wrote packet to backchannel") }