mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-22 23:10:35 -04:00
Add basic cache clearing
This commit is contained in:
parent
46cf60a3b9
commit
b0c0ca0e0f
@ -90,10 +90,15 @@ func GetKeyframes(path string) ([]float64, bool, error) {
|
|||||||
func (fs *FileStream) IsDead() bool {
|
func (fs *FileStream) IsDead() bool {
|
||||||
for _, s := range fs.streams {
|
for _, s := range fs.streams {
|
||||||
if len(s.Clients) > 0 {
|
if len(s.Clients) > 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO: Also check how long this stream has been unused. We dont want to kill streams created 2min ago
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false
|
func (fs *FileStream) Destroy() {
|
||||||
|
// TODO: kill child process and delete data
|
||||||
}
|
}
|
||||||
|
|
||||||
func (fs *FileStream) GetMaster() string {
|
func (fs *FileStream) GetMaster() string {
|
||||||
|
@ -30,6 +30,7 @@ func (t *Transcoder) GetMaster(path string, client string) (string, error) {
|
|||||||
} else if !ok {
|
} else if !ok {
|
||||||
t.mutex.Lock()
|
t.mutex.Lock()
|
||||||
t.preparing[path] = true
|
t.preparing[path] = true
|
||||||
|
t.cleanUnused()
|
||||||
t.mutex.Unlock()
|
t.mutex.Unlock()
|
||||||
|
|
||||||
stream, err := NewFileStream(path)
|
stream, err := NewFileStream(path)
|
||||||
@ -49,5 +50,17 @@ func (t *Transcoder) GetMaster(path string, client string) (string, error) {
|
|||||||
|
|
||||||
t.channel <- stream
|
t.channel <- stream
|
||||||
}
|
}
|
||||||
|
|
||||||
return stream.GetMaster(), nil
|
return stream.GetMaster(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This method assume the lock is already taken.
|
||||||
|
func (t *Transcoder) cleanUnused() {
|
||||||
|
for path, stream := range t.streams {
|
||||||
|
if !stream.IsDead() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
stream.Destroy()
|
||||||
|
delete(t.streams, path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user