使用分离方式,修改视频流返回方式,使用redis存是否在获取
This commit is contained in:
parent
cead913af7
commit
8827fa0412
|
|
@ -34,7 +34,7 @@ func SetUpToolGroup(router *gin.Engine) {
|
|||
}
|
||||
|
||||
// 跨域访问:cross origin resource share
|
||||
func CrosHandler() gin.HandlerFunc {
|
||||
func CorsHandler() gin.HandlerFunc {
|
||||
return func(context *gin.Context) {
|
||||
//method := context.Request.Method
|
||||
context.Writer.Header().Set("Access-Control-Allow-Origin", "*")
|
||||
|
|
@ -105,14 +105,31 @@ func GetVideoStream(c *gin.Context) {
|
|||
//设备流
|
||||
c.Stream(func(w io.Writer) bool {
|
||||
var count int
|
||||
frame := gocv.NewMat()
|
||||
defer func() {
|
||||
//关闭帧
|
||||
err4 := frame.Close()
|
||||
if err4 != nil {
|
||||
log.Printf("device:%d frame close err:%v", deviceID, err4)
|
||||
}
|
||||
}()
|
||||
for {
|
||||
frame, cnt := service.GetDeviceCurrentFrame(deviceID)
|
||||
cnt := service.GetDeviceCurrentFrameV2(&frame, deviceID)
|
||||
if cnt == count {
|
||||
time.Sleep(50 * time.Millisecond)
|
||||
continue
|
||||
}
|
||||
if frame.Empty() {
|
||||
log.Printf("stream device:%d frame is empty", deviceID)
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
continue
|
||||
}
|
||||
//gocv.Matrix转为jpeg
|
||||
img, err := gocv.IMEncode(".jpg", frame)
|
||||
img, err2 := gocv.IMEncode(".jpg", frame)
|
||||
if err2 != nil {
|
||||
log.Printf("stream img encode err:%v", err2)
|
||||
return false
|
||||
}
|
||||
frame_ := img.GetBytes()
|
||||
|
||||
_, err = w.Write([]byte("--frame\r\nContent-Type: image/jpeg\r\n\r\n"))
|
||||
|
|
|
|||
Loading…
Reference in New Issue