使用分离方式,修改视频流返回方式

This commit is contained in:
lijun 2025-01-18 20:04:50 +08:00
parent d69e02115f
commit abea9bd374
3 changed files with 8 additions and 4 deletions

View File

@ -143,11 +143,11 @@ func GetRealTimeImage(c *gin.Context) {
return return
} }
//查看设备是否在获取 //查看设备是否在获取
is_get, ok := service.DeviceIsGettingFrame.Load(device.ID) isGet, ok := service.DeviceIsGettingFrame.Load(device.ID)
if !ok || is_get == false { if !ok || isGet == false {
//直接返回 //直接返回
c.JSON(http.StatusOK, gin.H{"code": 4, "message": "device not getting frame or not exist"}) c.JSON(http.StatusOK, gin.H{"code": 4, "message": "device not getting frame or not exist"})
log.Printf("device:%d not found", device.ID) log.Printf("device:%d not found,isGet:%v , ok = %v", device.ID, isGet, ok)
return return
} }
ws, err := upgrader.Upgrade(c.Writer, c.Request, nil) ws, err := upgrader.Upgrade(c.Writer, c.Request, nil)

View File

@ -110,6 +110,8 @@ func ReadConfigAndSetSystem() {
service.Device1CurrentFrame = gocv.NewMat() service.Device1CurrentFrame = gocv.NewMat()
case 50: case 50:
service.Device50CurrentFrame = gocv.NewMat() service.Device50CurrentFrame = gocv.NewMat()
case 73:
service.Device73CurrentFrame = gocv.NewMat()
} }
go service.GetVideoStream(device.ID) go service.GetVideoStream(device.ID)
log.Printf("device:%d has started!\n", device.ID) log.Printf("device:%d has started!\n", device.ID)

View File

@ -161,7 +161,9 @@ func GetDeviceCurrentFrameV3(deviceId int) (gocv.Mat, int) {
Device50CurrentFrame.CopyTo(&frame) Device50CurrentFrame.CopyTo(&frame)
//查看帧状态 //查看帧状态
//log.Printf("frame:%v,Device50CurrentFrame:%v\n", frame.Empty(), Device50CurrentFrame.Empty()) //log.Printf("frame:%v,Device50CurrentFrame:%v\n", frame.Empty(), Device50CurrentFrame.Empty())
case 73:
frame = gocv.NewMatWithSize(Device73CurrentFrame.Rows(), Device73CurrentFrame.Cols(), Device73CurrentFrame.Type())
Device73CurrentFrame.CopyTo(&frame)
} }
frameCount, ok := DeviceFrameCount[deviceId] frameCount, ok := DeviceFrameCount[deviceId]