stream listener count <0 handling.

This commit is contained in:
Miroslav Šedivý 2021-09-29 00:21:53 +02:00
parent 5bb2da2732
commit 18fbdb2ff8

View File

@ -29,7 +29,7 @@ type StreamManagerCtx struct {
listeners map[uintptr]*func(sample types.Sample) listeners map[uintptr]*func(sample types.Sample)
listenersMu sync.Mutex listenersMu sync.Mutex
listenersCount uint32 listenersCount int
} }
func streamNew(codec codec.RTPCodec, pipelineStr func() string, video_id string) *StreamManagerCtx { func streamNew(codec codec.RTPCodec, pipelineStr func() string, video_id string) *StreamManagerCtx {
@ -142,11 +142,15 @@ func (manager *StreamManagerCtx) RemoveListener(listener *func(sample types.Samp
manager.mu.Lock() manager.mu.Lock()
defer manager.mu.Unlock() defer manager.mu.Unlock()
if manager.listenersCount == 0 { if manager.listenersCount <= 0 {
manager.destroyPipeline() manager.destroyPipeline()
manager.listenersCount = 0
manager.logger.Info().Msgf("last listener, stopping") manager.logger.Info().Msgf("last listener, stopping")
} }
if manager.listenersCount < 0 {
manager.listenersCount = 0
manager.logger.Error().Int("listeners-count", manager.listenersCount).Msgf("listener counter is < 0, something is wrong")
}
}() }()
} }