Adaptive publishing improvements (#295)

* Adaptive publishing improvements

* fix tests

* proper comment sentence

* Address comments from David

* proper locking

* fix crash

* Do not start quality timer if not video
This commit is contained in:
Raja Subramanian
2021-12-30 09:50:53 +05:30
committed by GitHub
parent 7b0db1f344
commit 03000f88cb
6 changed files with 261 additions and 72 deletions
+25 -3
View File
@@ -38,6 +38,7 @@ type StreamTracker struct {
paused atomicBool
countSinceLast uint32 // number of packets received since last check
running chan struct{}
generation atomicUint32
initMu sync.Mutex
initialized bool
@@ -108,7 +109,7 @@ func (s *StreamTracker) init() {
return
}
s.running = make(chan struct{})
go s.detectWorker()
go s.detectWorker(s.generation.get())
}
func (s *StreamTracker) Start() {
@@ -121,6 +122,22 @@ func (s *StreamTracker) Stop() {
}
}
func (s *StreamTracker) Reset() {
s.generation.add(1)
s.Stop()
s.countSinceLast = 0
s.cycleCount = 0
s.initMu.Lock()
s.initialized = false
s.initMu.Unlock()
s.statusMu.Lock()
s.status = StreamStatusStopped
s.statusMu.Unlock()
}
func (s *StreamTracker) SetPaused(paused bool) {
s.paused.set(paused)
}
@@ -146,10 +163,12 @@ func (s *StreamTracker) Observe(sn uint16) {
s.initMu.Lock()
if !s.initialized {
// first packet
s.lastSN = sn
s.initialized = true
s.initMu.Unlock()
s.lastSN = sn
atomic.AddUint32(&s.countSinceLast, 1)
// declare stream active and start the detect worker
go s.init()
@@ -165,7 +184,7 @@ func (s *StreamTracker) Observe(sn uint16) {
atomic.AddUint32(&s.countSinceLast, 1)
}
func (s *StreamTracker) detectWorker() {
func (s *StreamTracker) detectWorker(generation uint32) {
ticker := time.NewTicker(s.cycleDuration)
for s.isRunning() {
@@ -173,6 +192,9 @@ func (s *StreamTracker) detectWorker() {
if !s.isRunning() {
return
}
if generation != s.generation.get() {
return
}
s.detectChanges()
}