diff --git a/transcoder/src/filestream.go b/transcoder/src/filestream.go index aaf501c1..7c9d78cf 100644 --- a/transcoder/src/filestream.go +++ b/transcoder/src/filestream.go @@ -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() diff --git a/transcoder/src/stream.go b/transcoder/src/stream.go index 5b8e5df1..b22e20a3 100644 --- a/transcoder/src/stream.go +++ b/transcoder/src/stream.go @@ -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) diff --git a/transcoder/src/tracker.go b/transcoder/src/tracker.go index 46bb7aa3..c1d97110 100644 --- a/transcoder/src/tracker.go +++ b/transcoder/src/tracker.go @@ -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()