mediamtx/internal/path/readersmap.go

47 lines
779 B
Go
Raw Normal View History

2020-10-19 20:17:48 +00:00
package path
import (
"sync"
"github.com/aler9/gortsplib"
2020-11-15 16:56:54 +00:00
"github.com/aler9/gortsplib/pkg/base"
2020-10-19 20:17:48 +00:00
)
2020-11-05 11:30:25 +00:00
type reader interface {
2020-10-19 20:17:48 +00:00
OnReaderFrame(int, base.StreamType, []byte)
}
type readersMap struct {
mutex sync.RWMutex
2020-11-05 11:30:25 +00:00
ma map[reader]struct{}
2020-10-19 20:17:48 +00:00
}
func newReadersMap() *readersMap {
return &readersMap{
2020-11-05 11:30:25 +00:00
ma: make(map[reader]struct{}),
2020-10-19 20:17:48 +00:00
}
}
2020-11-05 11:30:25 +00:00
func (m *readersMap) add(reader reader) {
2020-10-19 20:17:48 +00:00
m.mutex.Lock()
defer m.mutex.Unlock()
m.ma[reader] = struct{}{}
}
2020-11-05 11:30:25 +00:00
func (m *readersMap) remove(reader reader) {
2020-10-19 20:17:48 +00:00
m.mutex.Lock()
defer m.mutex.Unlock()
delete(m.ma, reader)
}
func (m *readersMap) forwardFrame(trackId int, streamType gortsplib.StreamType, buf []byte) {
m.mutex.RLock()
defer m.mutex.RUnlock()
for c := range m.ma {
c.OnReaderFrame(trackId, streamType, buf)
}
}