Fix timing issue with cleanup

This commit is contained in:
Zoe Roux 2024-01-17 15:43:46 +01:00
parent 7b13733c9e
commit d630f29753
3 changed files with 12 additions and 7 deletions

View File

@ -143,9 +143,9 @@ func GetKeyframes(path string) ([]float64, bool, error) {
func (fs *FileStream) Destroy() {
fs.vlock.Lock()
defer fs.vlock.Lock()
defer fs.vlock.Unlock()
fs.alock.Lock()
defer fs.alock.Lock()
defer fs.alock.Unlock()
for _, s := range fs.streams {
s.Kill()

View File

@ -151,7 +151,6 @@ func (ts *Stream) run(start int32) error {
ts.lock.Lock()
ts.heads[encoder_id] = segment
log.Printf("encode %d finished %d", encoder_id, segment)
if ts.isSegmentReady(segment) {
// the current segment is already marked at done so another process has already gone up to here.
cmd.Process.Signal(os.Interrupt)

View File

@ -47,8 +47,8 @@ func (t *Tracker) start() {
}
old, ok := t.clients[info.client]
// First fixup the info. Most routes ruturn partial infos
if ok && old.path == info.path {
// First fixup the info. Most routes ruturn partial infos
if info.quality == nil {
info.quality = old.quality
}
@ -58,7 +58,13 @@ func (t *Tracker) start() {
if info.head == -1 {
info.head = old.head
}
}
t.clients[info.client] = info
t.visitDate[info.client] = time.Now()
// now that the new info is stored and fixed, kill old streams
if ok && old.path == info.path {
if old.audio != info.audio && old.audio != -1 {
t.KillAudioIfDead(old.path, old.audio)
}
@ -72,9 +78,6 @@ func (t *Tracker) start() {
t.KillStreamIfDead(old.path)
}
t.clients[info.client] = info
t.visitDate[info.client] = time.Now()
case <-timer:
timer = time.After(inactive_time)
// Purge old clients
@ -106,6 +109,7 @@ func (t *Tracker) KillStreamIfDead(path string) bool {
return false
}
}
log.Printf("Nobody is watching %s. Killing it", path)
t.transcoder.mutex.Lock()
defer t.transcoder.mutex.Unlock()
t.transcoder.streams[path].Destroy()
@ -119,6 +123,7 @@ func (t *Tracker) KillAudioIfDead(path string, audio int32) bool {
return false
}
}
log.Printf("Nobody is listening audio %d of %s. Killing it", audio, path)
t.transcoder.mutex.RLock()
stream := t.transcoder.streams[path]
t.transcoder.mutex.RUnlock()
@ -135,6 +140,7 @@ func (t *Tracker) KillQualityIfDead(path string, quality Quality) bool {
return false
}
}
log.Printf("Nobody is watching quality %s of %s. Killing it", quality, path)
t.transcoder.mutex.RLock()
stream := t.transcoder.streams[path]
t.transcoder.mutex.RUnlock()