mirror of
https://github.com/kerberos-io/agent.git
synced 2025-10-03 15:26:28 +08:00
do not read if not needed
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
|||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"image"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -689,25 +690,28 @@ func HandleLiveStreamSD(livestreamCursor *packets.QueueCursor, configuration *mo
|
|||||||
var pkt packets.Packet
|
var pkt packets.Packet
|
||||||
|
|
||||||
for cursorError == nil {
|
for cursorError == nil {
|
||||||
pkt, cursorError = livestreamCursor.ReadPacket()
|
|
||||||
if len(pkt.Data) == 0 || !pkt.IsKeyFrame {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
now := time.Now().Unix()
|
now := time.Now().Unix()
|
||||||
select {
|
select {
|
||||||
case <-communication.HandleLiveSD:
|
case <-communication.HandleLiveSD:
|
||||||
lastLivestreamRequest = now
|
lastLivestreamRequest = now
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
|
|
||||||
if now-lastLivestreamRequest > 3 {
|
if now-lastLivestreamRequest > 3 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pkt, cursorError = livestreamCursor.ReadPacket()
|
||||||
|
if len(pkt.Data) == 0 || !pkt.IsKeyFrame {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
log.Log.Info("cloud.HandleLiveStreamSD(): Sending base64 encoded images to MQTT.")
|
log.Log.Info("cloud.HandleLiveStreamSD(): Sending base64 encoded images to MQTT.")
|
||||||
img, err := rtspClient.DecodePacket(pkt)
|
img, err := rtspClient.DecodePacket(pkt)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
bytes, _ := utils.ImageToBytes(&img)
|
bytes, _ := utils.ImageToBytes(&img)
|
||||||
encoded := base64.StdEncoding.EncodeToString(bytes)
|
encoded := base64.StdEncoding.EncodeToString(bytes)
|
||||||
|
|
||||||
valueMap := make(map[string]interface{})
|
valueMap := make(map[string]interface{})
|
||||||
valueMap["image"] = encoded
|
valueMap["image"] = encoded
|
||||||
message := models.Message{
|
message := models.Message{
|
||||||
@@ -724,6 +728,8 @@ func HandleLiveStreamSD(livestreamCursor *packets.QueueCursor, configuration *mo
|
|||||||
log.Log.Info("cloud.HandleLiveStreamSD(): something went wrong while sending acknowledge config to hub: " + string(payload))
|
log.Log.Info("cloud.HandleLiveStreamSD(): something went wrong while sending acknowledge config to hub: " + string(payload))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Cleaning image
|
||||||
|
img = image.YCbCr{}
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user