Compare commits
2 Commits
75d8492618
...
6a63d53117
| Author | SHA1 | Date |
|---|---|---|
|
|
6a63d53117 | |
|
|
647def1279 |
|
|
@ -40,35 +40,41 @@ func SetDeviceCurrentFrame(frame gocv.Mat, device_id int) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetDeviceCurrentFrame(device_id int) (gocv.Mat, int) {
|
func GetDeviceCurrentFrame(deviceId int) (gocv.Mat, int) {
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
log.Printf("设备:%d 错误: %v\n", deviceId, err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
//获取读写锁
|
//获取读写锁
|
||||||
mutex_, ok := DeviceRWMap.Load(device_id)
|
mutex_, ok := DeviceRWMap.Load(deviceId)
|
||||||
if !ok {
|
if !ok {
|
||||||
return gocv.NewMat(), -1
|
return gocv.NewMat(), -1
|
||||||
}
|
}
|
||||||
mutex, ok := mutex_.(*sync.RWMutex)
|
mutex, ok := mutex_.(*sync.RWMutex)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Printf("DeviceRWMap 存储的不是 *sync.RWMutex 类型,device_id: %d", device_id)
|
log.Printf("DeviceRWMap 存储的不是 *sync.RWMutex 类型,device_id: %d", deviceId)
|
||||||
return gocv.NewMat(), -1
|
return gocv.NewMat(), -1
|
||||||
}
|
}
|
||||||
mutex.RLock()
|
mutex.RLock()
|
||||||
defer mutex.RUnlock()
|
defer mutex.RUnlock()
|
||||||
//获取当前帧
|
//获取当前帧
|
||||||
frameIface, ok := DeviceCurrentFrameMap.Load(device_id)
|
frameIface, ok := DeviceCurrentFrameMap.Load(deviceId)
|
||||||
if !ok {
|
if !ok {
|
||||||
return gocv.NewMat(), -1
|
return gocv.NewMat(), -1
|
||||||
}
|
}
|
||||||
frame, ok := frameIface.(gocv.Mat)
|
frame, ok := frameIface.(gocv.Mat)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Printf("DeviceCurrentFrameMap 存储的不是 gocv.Mat 类型,device_id: %d", device_id)
|
log.Printf("DeviceCurrentFrameMap 存储的不是 gocv.Mat 类型,device_id: %d", deviceId)
|
||||||
}
|
}
|
||||||
frame_countIface, ok := DeviceFrameCount.Load(device_id)
|
frame_countIface, ok := DeviceFrameCount.Load(deviceId)
|
||||||
if !ok {
|
if !ok {
|
||||||
return gocv.NewMat(), -1
|
return gocv.NewMat(), -1
|
||||||
}
|
}
|
||||||
frame_count, ok := frame_countIface.(int)
|
frame_count, ok := frame_countIface.(int)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Printf("DeviceFrameCount 存储的不是 int 类型,device_id: %d", device_id)
|
log.Printf("DeviceFrameCount 存储的不是 int 类型,device_id: %d", deviceId)
|
||||||
}
|
}
|
||||||
return frame, frame_count
|
return frame, frame_count
|
||||||
}
|
}
|
||||||
|
|
@ -153,6 +159,11 @@ func Get(url string) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetVideoStream(id int) {
|
func GetVideoStream(id int) {
|
||||||
|
defer func() {
|
||||||
|
if err := recover(); err != nil {
|
||||||
|
log.Printf("设备:%d 错误: %v\n", id, err)
|
||||||
|
}
|
||||||
|
}()
|
||||||
is_get, ok := DeviceIsGettingFrame.Load(id)
|
is_get, ok := DeviceIsGettingFrame.Load(id)
|
||||||
if !ok {
|
if !ok {
|
||||||
log.Printf("device: %d not found", id)
|
log.Printf("device: %d not found", id)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue