diff --git a/cmd/streams/stream.go b/cmd/streams/stream.go index ac998cb5..ce44e40a 100644 --- a/cmd/streams/stream.go +++ b/cmd/streams/stream.go @@ -18,6 +18,7 @@ type Stream struct { producers []*Producer consumers []*Consumer mu sync.Mutex + wg sync.WaitGroup } func NewStream(source interface{}) *Stream { @@ -59,6 +60,9 @@ func (s *Stream) AddConsumer(cons streamer.Consumer) (err error) { var codecs string + // support for multiple simultaneous requests from different consumers + s.wg.Add(1) + // Step 1. Get consumer medias for icc, consMedia := range cons.GetMedias() { log.Trace().Stringer("media", consMedia). @@ -97,6 +101,9 @@ func (s *Stream) AddConsumer(cons streamer.Consumer) (err error) { } } + s.wg.Done() + s.wg.Wait() + if len(producers) == 0 { s.stopProducers()