diff --git a/main.go b/main.go index 150bc3e0..11683be8 100644 --- a/main.go +++ b/main.go @@ -111,8 +111,6 @@ func (h *Handler) watchClose() { if id == "" { return } - - log.Println("Closing stream", id) h.removeManager(id) } } diff --git a/manager.go b/manager.go index 85b41940..bc89894e 100644 --- a/manager.go +++ b/manager.go @@ -94,6 +94,12 @@ func NewManager(c *Config, path string, id string, close chan string) (*Manager, defer t.Stop() for { <-t.C + + if m.inactive == -1 { + t.Stop() + return + } + m.inactive++ // Check if any stream is active @@ -105,8 +111,8 @@ func NewManager(c *Config, path string, id string, close chan string) (*Manager, } // Nothing done for 5 minutes - if m.inactive >= 60 { - log.Printf("%s: inactive, closing", m.id) + if m.inactive >= 4 { + t.Stop() m.Destroy() m.close <- m.id return @@ -119,6 +125,9 @@ func NewManager(c *Config, path string, id string, close chan string) (*Manager, // Destroys streams. DOES NOT emit on the close channel. func (m *Manager) Destroy() { + log.Printf("%s: destroying manager", m.id) + m.inactive = -1 + for _, stream := range m.streams { stream.Stop() } diff --git a/stream.go b/stream.go index 13592744..a315aead 100644 --- a/stream.go +++ b/stream.go @@ -69,16 +69,13 @@ func (s *Stream) Run() { s.inactive++ // Nothing done for 2 minutes - if s.inactive >= 24 { + if s.inactive >= 3 && s.coder != nil { t.Stop() s.clear() - s.mutex.Unlock() - return } s.mutex.Unlock() case <-s.stop: - log.Printf("%s-%s: received stop signal", s.m.id, s.quality) t.Stop() s.mutex.Lock() s.clear() @@ -106,7 +103,10 @@ func (s *Stream) clear() { } func (s *Stream) Stop() { - s.stop <- true + select { + case s.stop <- true: + default: + } } func (s *Stream) ServeList(w http.ResponseWriter) error {