mirror of
https://github.com/YuzuZensai/TrollSSH.git
synced 2026-09-14 03:39:09 +00:00
♻️ refactor: split src into internal packages and cmd
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
// .tsf layout, little-endian: "TSFR" | version uint16 | fps float64 |
|
||||
// count uint32 | count × (colorLen uint32, color JPEG).
|
||||
package tsf
|
||||
|
||||
import "sync"
|
||||
|
||||
const (
|
||||
tsfMagic = "TSFR"
|
||||
tsfVersion = 1
|
||||
maxTSFFPS = 240
|
||||
maxTSFFrameCount = 10_000_000
|
||||
)
|
||||
|
||||
type FramesContainer struct {
|
||||
ColorFrames [][]byte
|
||||
FPS float64
|
||||
Name string
|
||||
}
|
||||
|
||||
type frameFile struct {
|
||||
data []byte
|
||||
cleanup func() error
|
||||
once sync.Once
|
||||
err error
|
||||
}
|
||||
|
||||
func (f *frameFile) Close() error {
|
||||
if f == nil {
|
||||
return nil
|
||||
}
|
||||
f.once.Do(func() {
|
||||
if f.cleanup != nil {
|
||||
f.err = f.cleanup()
|
||||
}
|
||||
f.data = nil
|
||||
})
|
||||
return f.err
|
||||
}
|
||||
|
||||
var frameFileOwners sync.Map // map[*FramesContainer]*frameFile
|
||||
|
||||
func (data *FramesContainer) Close() error {
|
||||
if data == nil {
|
||||
return nil
|
||||
}
|
||||
owner, ok := frameFileOwners.LoadAndDelete(data)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
data.ColorFrames = nil
|
||||
return owner.(*frameFile).Close()
|
||||
}
|
||||
Reference in New Issue
Block a user