From b00537b5ecadb6dfef024e649940b363881a5aae Mon Sep 17 00:00:00 2001 From: lijun Date: Sun, 19 Jan 2025 15:13:51 +0800 Subject: [PATCH] =?UTF-8?q?release=E7=89=88=E6=9C=AC=EF=BC=8C=E8=BE=93?= =?UTF-8?q?=E5=87=BA=E6=AF=8F=E5=B0=8F=E6=97=B6=E4=B8=80=E6=AC=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- handler/tool.go | 8 +++++++- service/tool.go | 9 +++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/handler/tool.go b/handler/tool.go index 362c3f3..5e5043d 100644 --- a/handler/tool.go +++ b/handler/tool.go @@ -120,8 +120,9 @@ func GetVideoStream(c *gin.Context) { return false } cnt := service.GetDeviceCurrentFrameV2(&frame, deviceID) - if cnt == count { + if cnt == count || cnt == -1 { time.Sleep(50 * time.Millisecond) + log.Printf("stream device:%d ,cnt =%d,count=%d,errCount=%d", deviceID, cnt, count, errCount) errCount++ continue } @@ -203,6 +204,11 @@ func subscribeAndHandleMessagesV3(ws *websocket.Conn, device_id int) { //从service获取当前帧 c := service.GetDeviceCurrentFrameV2(&img, device_id) if c != count { + if c == -1 { + log.Printf("device:%d get frame err!", device_id) + worker.SetRedisSetRemove(online_conn_key, con_id) + break + } //将img转[]byte if img.Empty() { log.Printf("device:%d img is empty! count = %d \n", device_id, c) diff --git a/service/tool.go b/service/tool.go index a2b2869..b51236d 100644 --- a/service/tool.go +++ b/service/tool.go @@ -115,16 +115,25 @@ func GetDeviceCurrentFrameV2(frame *gocv.Mat, deviceId int) int { if (*frame).Empty() { *frame = gocv.NewMatWithSize(Device1CurrentFrame.Rows(), Device1CurrentFrame.Cols(), Device1CurrentFrame.Type()) } + if Device1CurrentFrame.Empty() { + return -1 + } Device1CurrentFrame.CopyTo(frame) case 50: if (*frame).Empty() { *frame = gocv.NewMatWithSize(Device50CurrentFrame.Rows(), Device50CurrentFrame.Cols(), Device50CurrentFrame.Type()) } + if Device50CurrentFrame.Empty() { + return -1 + } Device50CurrentFrame.CopyTo(frame) case 73: if (*frame).Empty() { *frame = gocv.NewMatWithSize(Device73CurrentFrame.Rows(), Device73CurrentFrame.Cols(), Device73CurrentFrame.Type()) } + if Device73CurrentFrame.Empty() { + return -1 + } Device73CurrentFrame.CopyTo(frame) }