Add audio files and implement audio handling in ONVIF and backchannel components

This commit is contained in:
Cédric Verstraeten
2025-05-04 19:06:29 +00:00
parent f62410f267
commit e2bffd779a
6 changed files with 31 additions and 2 deletions
Binary file not shown.
Binary file not shown.
+13
View File
@@ -2,6 +2,7 @@ package components
import (
"context"
"fmt"
"os"
"strconv"
"sync/atomic"
@@ -297,6 +298,18 @@ func RunAgent(configDirectory string, configuration *models.Configuration, commu
communication.HasBackChannel = true
go WriteFileToBackChannel(communication, rtspBackChannelClient)
}
//go onvif.HandleAudioActions(configuration, communication, rtspBackChannelClient)
go func() {
for action := range communication.HandleAudio {
fmt.Println("onvif.HandleAudioActions(): action", action)
// Ensure cloud.WriteFileToBackChannel is implemented or replace with a valid function
if WriteFileToBackChannel != nil {
WriteFileToBackChannel(communication, rtspBackChannelClient)
} else {
fmt.Println("cloud.WriteFileToBackChannel is not defined")
}
}
}()
// If we reach this point, we have a working RTSP connection.
communication.CameraConnected = true
+1 -2
View File
@@ -75,7 +75,7 @@ func WriteFileToBackChannel(communication *models.Communication, rtspClient capt
sequenceNumber := uint16(0)
// Do the warmup!
file, err := os.Open("./aandacht.wav")
file, err := os.Open("./audio/air-raid.wav")
if err != nil {
fmt.Println("WriteFileToBackChannel: error opening audiofile.bye file")
}
@@ -94,7 +94,6 @@ func WriteFileToBackChannel(communication *models.Communication, rtspClient capt
if err != nil {
break
}
// Encode PCM to MULAW
bufferUlaw := g711.EncodeUlaw(buffer)
fmt.Println("WriteFileToBackChannel: bufferUlaw", bufferUlaw)
+6
View File
@@ -166,6 +166,12 @@ func ProcessMotion(motionCursor *packets.QueueCursor, configuration *models.Conf
NumberOfChanges: changesToReturn,
}
communication.HandleMotion <- dataToPass //Save data to the channel
audioToPass := models.AudioDataPartial{
Timestamp: time.Now().Unix(),
Data: []int16{},
}
communication.HandleAudio <- audioToPass //Save data to the channel
}
}
}
+11
View File
@@ -12,6 +12,7 @@ import (
onvifc "github.com/cedricve/go-onvif"
"github.com/gin-gonic/gin"
"github.com/kerberos-io/agent/machinery/src/capture"
"github.com/kerberos-io/agent/machinery/src/log"
"github.com/kerberos-io/agent/machinery/src/models"
"github.com/kerberos-io/onvif"
@@ -189,6 +190,16 @@ func HandleONVIFActions(configuration *models.Configuration, communication *mode
log.Log.Debug("onvif.HandleONVIFActions(): finished")
}
func HandleAudioActions(configuration *models.Configuration, communication *models.Communication, backchannel capture.RTSPClient) {
log.Log.Debug("onvif.HandleAudioActions(): started")
/*for action := range communication.HandleAudio {
fmt.Println("onvif.HandleAudioActions(): action", action)
cloud.WriteFileToBackChannel(communication, backchannel)
}*/
log.Log.Debug("onvif.HandleAudioActions(): finished")
}
func ConnectToOnvifDevice(cameraConfiguration *models.IPCamera) (*onvif.Device, device.GetCapabilitiesResponse, error) {
log.Log.Debug("onvif.ConnectToOnvifDevice(): started")
dev, err := onvif.NewDevice(onvif.DeviceParams{