From 83ba7baa4bd6dd5cf25754bbfc8065b4d8aad66d Mon Sep 17 00:00:00 2001 From: Cedric Verstraeten Date: Wed, 10 Jan 2024 17:06:49 +0100 Subject: [PATCH] [release] v3.1.4 - hot-fix: preserve width and height of both main and sub stream --- machinery/src/capture/Gortsplib.go | 12 +++++++-- machinery/src/components/Kerberos.go | 38 ++-------------------------- machinery/src/models/Config.go | 5 +++- machinery/src/routers/mqtt/main.go | 7 +++++ ui/src/App.jsx | 2 +- 5 files changed, 24 insertions(+), 40 deletions(-) diff --git a/machinery/src/capture/Gortsplib.go b/machinery/src/capture/Gortsplib.go index 3c1946a..f7a6a2d 100644 --- a/machinery/src/capture/Gortsplib.go +++ b/machinery/src/capture/Gortsplib.go @@ -497,10 +497,18 @@ func (g *Golibrtsp) Start(ctx context.Context, streamType string, queue *packets if errSPS == nil { // Get width g.Streams[g.VideoH264Index].Width = sps.Width() - configuration.Config.Capture.IPCamera.Width = sps.Width() + if streamType == "main" { + configuration.Config.Capture.IPCamera.Width = sps.Width() + } else if streamType == "sub" { + configuration.Config.Capture.IPCamera.SubWidth = sps.Width() + } // Get height g.Streams[g.VideoH264Index].Height = sps.Height() - configuration.Config.Capture.IPCamera.Height = sps.Height() + if streamType == "main" { + configuration.Config.Capture.IPCamera.Height = sps.Height() + } else if streamType == "sub" { + configuration.Config.Capture.IPCamera.SubHeight = sps.Height() + } // Get FPS g.Streams[g.VideoH264Index].FPS = sps.FPS() g.VideoH264Forma.SPS = nalu diff --git a/machinery/src/components/Kerberos.go b/machinery/src/components/Kerberos.go index bc48293..6c57ab6 100644 --- a/machinery/src/components/Kerberos.go +++ b/machinery/src/components/Kerberos.go @@ -206,42 +206,8 @@ func RunAgent(configDirectory string, configuration *models.Configuration, commu height := videoSubStream.Height // Set config values as well - configuration.Config.Capture.IPCamera.Width = width - configuration.Config.Capture.IPCamera.Height = height - } - - if cameraSettings.RTSP != rtspUrl || - cameraSettings.SubRTSP != subRtspUrl || - cameraSettings.Width != width || - cameraSettings.Height != height { - - // TODO: this condition is used to reset the decoder when the camera settings change. - // The main idea is that you only set the decoder once, and then reuse it on each restart (no new memory allocation). - // However the stream settings of the camera might have been changed, and so the decoder might need to be reloaded. - // .... Not used for the moment .... - - if cameraSettings.RTSP != "" && cameraSettings.SubRTSP != "" && cameraSettings.Initialized { - //decoder.Close() - //if subStreamEnabled { - // subDecoder.Close() - //} - } - - // At some routines we will need to decode the image. - // Make sure its properly locked as we only have a single decoder. - log.Log.Info("components.Kerberos.RunAgent(): camera settings changed, reloading decoder") - //capture.GetVideoDecoder(decoder, streams) - //if subStreamEnabled { - // capture.GetVideoDecoder(subDecoder, subStreams) - //} - - cameraSettings.RTSP = rtspUrl - cameraSettings.SubRTSP = subRtspUrl - cameraSettings.Width = width - cameraSettings.Height = height - cameraSettings.Initialized = true - } else { - log.Log.Info("components.Kerberos.RunAgent(): camera settings did not change, keeping decoder") + configuration.Config.Capture.IPCamera.SubWidth = width + configuration.Config.Capture.IPCamera.SubHeight = height } // We are creating a queue to store the RTSP frames in, these frames will be diff --git a/machinery/src/models/Config.go b/machinery/src/models/Config.go index 80394aa..a5f759f 100644 --- a/machinery/src/models/Config.go +++ b/machinery/src/models/Config.go @@ -72,11 +72,14 @@ type Capture struct { // IPCamera configuration, such as the RTSP url of the IPCamera and the FPS. // Also includes ONVIF integration type IPCamera struct { + RTSP string `json:"rtsp"` Width int `json:"width"` Height int `json:"height"` FPS string `json:"fps"` - RTSP string `json:"rtsp"` SubRTSP string `json:"sub_rtsp"` + SubWidth int `json:"sub_width"` + SubHeight int `json:"sub_height"` + SubFPS string `json:"sub_fps"` ONVIF string `json:"onvif,omitempty" bson:"onvif"` ONVIFXAddr string `json:"onvif_xaddr" bson:"onvif_xaddr"` ONVIFUsername string `json:"onvif_username" bson:"onvif_username"` diff --git a/machinery/src/routers/mqtt/main.go b/machinery/src/routers/mqtt/main.go index 32b9ce3..542784c 100644 --- a/machinery/src/routers/mqtt/main.go +++ b/machinery/src/routers/mqtt/main.go @@ -362,6 +362,13 @@ func HandleRequestConfig(mqttClient mqtt.Client, hubKey string, payload models.P // Copy the config, as we don't want to share the encryption part. deepCopy := configuration.Config + // We need a fix for the width and height if a substream. + // The ROI requires the width and height of the sub stream. + if configuration.Config.Capture.IPCamera.SubRTSP != "" { + deepCopy.Capture.IPCamera.Width = configuration.Config.Capture.IPCamera.SubWidth + deepCopy.Capture.IPCamera.Height = configuration.Config.Capture.IPCamera.SubHeight + } + var configMap map[string]interface{} inrec, _ := json.Marshal(deepCopy) json.Unmarshal(inrec, &configMap) diff --git a/ui/src/App.jsx b/ui/src/App.jsx index 7786517..5236138 100644 --- a/ui/src/App.jsx +++ b/ui/src/App.jsx @@ -100,7 +100,7 @@ class App extends React.Component { )}
- +