-
Notifications
You must be signed in to change notification settings - Fork 127
v3.3.21-onvif-0.0.7 #225
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
v3.3.21-onvif-0.0.7 #225
Conversation
…ONVIF device connection handling and optimize image processing for MQTT streaming
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR updates ONVIF device connection handling by removing the unused second return value from ConnectToOnvifDevice calls and temporarily disables ONVIF event subscription functionality. It also optimizes image processing for MQTT streaming by adding image resizing before transmission and implementing an optional chunking mechanism for large images.
- Updated
ConnectToOnvifDevicefunction calls to match its actual signature (returns 2 values, not 3) - Added image resizing before MQTT transmission to reduce payload size
- Implemented optional chunking for MQTT livestream to handle large images
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| cameraConfiguration := configuration.Config.Capture.IPCamera | ||
| device, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration) | ||
| device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration) | ||
| if err != nil { |
Copilot
AI
Nov 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error check logic is inverted. If ConnectToOnvifDevice returns an error (err != nil), the code should not proceed to create a pull point subscription. This should be if err == nil { to match the pattern used elsewhere in the file (e.g., line 265).
| if err != nil { | |
| if err == nil { |
| cameraConfiguration := configuration.Config.Capture.IPCamera | ||
| device, _, err := onvif.ConnectToOnvifDevice(&cameraConfiguration) | ||
| device, err := onvif.ConnectToOnvifDevice(&cameraConfiguration) | ||
| if err != nil { |
Copilot
AI
Nov 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error check logic is inverted. If ConnectToOnvifDevice returns an error (err != nil), the code should not proceed to unsubscribe. This should be if err == nil { to properly handle successful connections before cleanup.
| if err != nil { | |
| if err == nil { |
machinery/src/cloud/Cloud.go
Outdated
| log.Log.Info("cloud.HandleLiveStreamSD(): something went wrong while sending acknowledge config to hub: " + string(payload)) | ||
|
|
||
| valueMap := make(map[string]interface{}) | ||
| valueMap["image"] = bytes |
Copilot
AI
Nov 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the non-chunking path, the image is sent as raw bytes without base64 encoding, which is inconsistent with the previous implementation that used base64 encoding (removed at line 712). This could break compatibility with receivers expecting base64-encoded data. Consider adding base64 encoding: valueMap[\"image\"] = base64.StdEncoding.EncodeToString(bytes).
| valueMap["image"] = bytes | |
| valueMap["image"] = base64.StdEncoding.EncodeToString(bytes) |
machinery/src/cloud/Cloud.go
Outdated
| Payload: models.Payload{ | ||
| Version: "v1.0.0", | ||
| Action: "receive-sd-stream", | ||
| DeviceId: deviceId, |
Copilot
AI
Nov 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent use of DeviceId field. In the chunking path, deviceId (local variable) is used, but in the non-chunking path (line 771) and HandleRealtimeProcessing (line 880), configuration.Config.Key is used directly. This inconsistency could lead to different device identifiers being sent depending on the chunking setting.
machinery/src/cloud/Cloud.go
Outdated
| } | ||
| payload, err := models.PackageMQTTMessage(configuration, message) | ||
| if err == nil { | ||
| mqttClient.Publish("kerberos/hub/"+hubKey+"/"+deviceId, 1, false, payload) |
Copilot
AI
Nov 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MQTT topic pattern is inconsistent between chunking and non-chunking modes. Chunking uses \"kerberos/hub/\"+hubKey+\"/\"+deviceId (line 757) while non-chunking uses \"kerberos/hub/\"+hubKey (line 777). This means chunks and non-chunked messages will be published to different topics, likely breaking message reception.
machinery/src/cloud/Cloud.go
Outdated
| log.Log.Infof("cloud.HandleLiveStreamSD(): sent chunk %d/%d to MQTT topic kerberos/hub/%s/%s", i+1, len(chunks), hubKey, deviceId) | ||
| time.Sleep(33 * time.Millisecond) // Sleep to avoid flooding the MQTT broker with messages | ||
| } else { | ||
| log.Log.Info("cloud.HandleLiveStreamSD(): something went wrong while sending acknowledge config to hub: " + string(payload)) |
Copilot
AI
Nov 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message refers to 'acknowledge config' but this function is sending livestream chunks, not acknowledging config. The message should be more specific, e.g., 'error while packaging chunk message for MQTT' to accurately reflect the context.
machinery/src/cloud/Cloud.go
Outdated
| if err == nil { | ||
| mqttClient.Publish("kerberos/hub/"+hubKey, 0, false, payload) | ||
| } else { | ||
| log.Log.Info("cloud.HandleLiveStreamSD(): something went wrong while sending acknowledge config to hub: " + string(payload)) |
Copilot
AI
Nov 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message refers to 'acknowledge config' but this function is sending livestream images, not acknowledging config. The message should be corrected to reflect the actual operation, e.g., 'error while packaging livestream message for MQTT'.
machinery/src/cloud/Cloud.go
Outdated
| valueMap["chunkCount"] = len(chunks) | ||
| message := models.Message{ | ||
| Payload: models.Payload{ | ||
| Version: "v1.0.0", |
Copilot
AI
Nov 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Version field is only set in the chunking path but not in the non-chunking path (line 769). This inconsistency in the message structure could cause issues for consumers expecting this field to always be present.
machinery/src/cloud/Cloud.go
Outdated
| // By default, bytes are not encoded to base64 here; you are splitting the raw JPEG/PNG bytes. | ||
| // However, in MQTT and web contexts, binary data may not be handled well, so base64 is often used. | ||
| // To avoid base64 encoding, just send the raw []byte chunks as you do here. | ||
| // If you want to avoid base64, make sure the receiver can handle binary payloads. |
Copilot
AI
Nov 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment suggests sending raw bytes, but MQTT message payloads in Go are typically byte slices that get JSON-marshaled. Since valueMap is a map[string]interface{} that will be marshaled to JSON, the raw []byte in valueMap[\"chunk\"] will be base64-encoded automatically during JSON marshaling. The comment is misleading about avoiding base64 encoding.
| // By default, bytes are not encoded to base64 here; you are splitting the raw JPEG/PNG bytes. | |
| // However, in MQTT and web contexts, binary data may not be handled well, so base64 is often used. | |
| // To avoid base64 encoding, just send the raw []byte chunks as you do here. | |
| // If you want to avoid base64, make sure the receiver can handle binary payloads. | |
| // Note: When you include []byte in a map[string]interface{} and marshal to JSON (as is done for MQTT payloads), | |
| // the []byte will be base64-encoded automatically by Go's encoding/json package. | |
| // Therefore, the receiver must be able to handle base64-encoded data in the "chunk" field. | |
| // This is standard behavior for JSON in Go; you are not sending raw binary data here. |
machinery/src/cloud/Cloud.go
Outdated
| } | ||
| payload, err := models.PackageMQTTMessage(configuration, message) | ||
| if err == nil { | ||
| mqttClient.Publish("kerberos/hub/"+hubKey+"/"+deviceId, 1, false, payload) |
Copilot
AI
Nov 11, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The QoS level differs between chunking (QoS 1 - at least once) and non-chunking (QoS 0 - at most once, line 777). For chunked messages where order and delivery matter, using QoS 1 is appropriate, but the non-chunking mode should also use QoS 1 for consistency, or this difference should be documented.
…improve ONVIF device connection handling and optimize image processing for MQTT streaming" This reverts commit 3b1ec96.
Description
Pull Request: v3.3.21-onvif-0.0.7
Motivation and Improvement
This pull request aims to enhance the reliability and maintainability of the ONVIF integration within the cloud handling module. The key changes include:
Commenting Out Unused Code:
Improved Error Handling:
Live Stream Handling Enhancements:
Code Refactoring:
Sleep Intervals to Prevent Flooding:
These changes collectively enhance the stability, performance, and maintainability of the cloud handling module, especially in scenarios involving ONVIF devices and live streaming. By addressing potential error points and optimizing data handling, this update aims to provide a more robust and efficient system.