added mutex to SaveStreamInstant to prevent weirdness
This commit is contained in:
parent
8f4d46bc3f
commit
69d30587cb
1 changed files with 4 additions and 0 deletions
|
@ -8,6 +8,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gocv.io/x/gocv"
|
"gocv.io/x/gocv"
|
||||||
|
@ -18,6 +19,7 @@ type Stream struct {
|
||||||
URL string `json:"url"`
|
URL string `json:"url"`
|
||||||
Base64 string `json:"base64"`
|
Base64 string `json:"base64"`
|
||||||
Interval int `json:"interval"`
|
Interval int `json:"interval"`
|
||||||
|
FileLock sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewStream creates a new Stream Object
|
// NewStream creates a new Stream Object
|
||||||
|
@ -80,6 +82,7 @@ func (s Stream) GetStreamInstant() gocv.Mat {
|
||||||
|
|
||||||
// SaveStreamInstant writes the img to the CurrentStreamInstantPath, moves existing instant to PreviousStreamInstantPath
|
// SaveStreamInstant writes the img to the CurrentStreamInstantPath, moves existing instant to PreviousStreamInstantPath
|
||||||
func (s Stream) SaveStreamInstant(mat gocv.Mat) {
|
func (s Stream) SaveStreamInstant(mat gocv.Mat) {
|
||||||
|
s.FileLock.Lock()
|
||||||
streamStoreDir := s.GetStreamStoreDirPath()
|
streamStoreDir := s.GetStreamStoreDirPath()
|
||||||
os.MkdirAll(streamStoreDir, os.ModePerm)
|
os.MkdirAll(streamStoreDir, os.ModePerm)
|
||||||
|
|
||||||
|
@ -95,6 +98,7 @@ func (s Stream) SaveStreamInstant(mat gocv.Mat) {
|
||||||
if swap {
|
if swap {
|
||||||
s.SwapInstants(s.GetPreviousInstantPath(), s.GetCurrentInstantPath(), s.GetNextInstantPath())
|
s.SwapInstants(s.GetPreviousInstantPath(), s.GetCurrentInstantPath(), s.GetNextInstantPath())
|
||||||
}
|
}
|
||||||
|
s.FileLock.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
// SwapInstants swaps the file location, first current -> previous and then next -> current
|
// SwapInstants swaps the file location, first current -> previous and then next -> current
|
||||||
|
|
Loading…
Add table
Reference in a new issue