重新设置获取逻辑
This commit is contained in:
parent
3aaf9b77b3
commit
fa4e4fa3b1
8
main.go
8
main.go
|
|
@ -6,6 +6,7 @@ import (
|
||||||
"VideoStream/proto"
|
"VideoStream/proto"
|
||||||
"VideoStream/service"
|
"VideoStream/service"
|
||||||
"VideoStream/worker"
|
"VideoStream/worker"
|
||||||
|
"fmt"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/golang-jwt/jwt"
|
"github.com/golang-jwt/jwt"
|
||||||
"github.com/robfig/cron/v3"
|
"github.com/robfig/cron/v3"
|
||||||
|
|
@ -17,7 +18,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
gin.SetMode(gin.ReleaseMode)
|
gin.SetMode(gin.DebugMode) //设置为debug模式
|
||||||
r := gin.Default()
|
r := gin.Default()
|
||||||
//数据库初始
|
//数据库初始
|
||||||
err0 := dao.Init()
|
err0 := dao.Init()
|
||||||
|
|
@ -64,7 +65,7 @@ func init() {
|
||||||
for _, device := range proto.Config.DeviceInfo {
|
for _, device := range proto.Config.DeviceInfo {
|
||||||
service.DeviceRWMap[device.ID] = sync.RWMutex{}
|
service.DeviceRWMap[device.ID] = sync.RWMutex{}
|
||||||
service.DeviceCurrentFrameMap[device.ID] = gocv.NewMat()
|
service.DeviceCurrentFrameMap[device.ID] = gocv.NewMat()
|
||||||
service.DeviceIsStop[device.ID] = true
|
service.DeviceIsGettingFrame[device.ID] = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,8 +83,9 @@ func ReadConfigAndSetSystem() {
|
||||||
}
|
}
|
||||||
//检测是否需要获取设备流,如果需要则开启
|
//检测是否需要获取设备流,如果需要则开启
|
||||||
for _, device := range proto.Config.DeviceInfo {
|
for _, device := range proto.Config.DeviceInfo {
|
||||||
if service.DeviceIsStop[device.ID] == false {
|
if service.DeviceIsGettingFrame[device.ID] == false && device.NextStop == false { //如果设备流已经停止且不暂停,则开启
|
||||||
go service.GetVideoStream(device.ID)
|
go service.GetVideoStream(device.ID)
|
||||||
|
fmt.Println("device:", device.ID, " has started!")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ import (
|
||||||
var DeviceRWMap = make(map[int]sync.RWMutex)
|
var DeviceRWMap = make(map[int]sync.RWMutex)
|
||||||
var DeviceCurrentFrameMap = make(map[int]gocv.Mat)
|
var DeviceCurrentFrameMap = make(map[int]gocv.Mat)
|
||||||
var DeviceFrameCount = make(map[int]int)
|
var DeviceFrameCount = make(map[int]int)
|
||||||
var DeviceIsStop = make(map[int]bool)
|
var DeviceIsGettingFrame = make(map[int]bool)
|
||||||
|
|
||||||
func SetDeviceCurrentFrame(frame gocv.Mat, device_id int) error {
|
func SetDeviceCurrentFrame(frame gocv.Mat, device_id int) error {
|
||||||
//获取读写锁
|
//获取读写锁
|
||||||
|
|
@ -109,7 +109,7 @@ func Get(url string) int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetVideoStream(id int) {
|
func GetVideoStream(id int) {
|
||||||
if DeviceIsStop[id] == false {
|
if DeviceIsGettingFrame[id] == true {
|
||||||
fmt.Println("device:", id, " is running!")
|
fmt.Println("device:", id, " is running!")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
@ -130,15 +130,15 @@ func GetVideoStream(id int) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
if device.NextStop {
|
if device.NextStop {
|
||||||
DeviceIsStop[id] = true
|
DeviceIsGettingFrame[id] = false
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
//设置设备控制信息
|
//设置设备控制信息
|
||||||
status := Get(device.Control)
|
status := Get(device.Control)
|
||||||
DeviceIsStop[id] = false
|
DeviceIsGettingFrame[id] = true
|
||||||
log.Println("device:", device.ID, " set control info status:", status)
|
log.Println("device:", device.ID, " set control info status:", status)
|
||||||
getVideoFrame(device)
|
getVideoFrame(device)
|
||||||
DeviceIsStop[id] = true //停止之后,设置已停止信息
|
DeviceIsGettingFrame[id] = false //停止之后,设置已停止信息
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue