Replace timer-based SMA with a timer-less implementation

This commit is contained in:
Ingo Oppermann
2024-10-23 11:08:13 +02:00
parent 2dda47b81f
commit df30a6b8e3
17 changed files with 543 additions and 371 deletions

View File

@@ -3,23 +3,23 @@ package parse
import (
"time"
"github.com/prep/average"
"github.com/datarhei/core/v16/math/average"
)
type averager struct {
fps *average.SlidingWindow
pps *average.SlidingWindow
bitrate *average.SlidingWindow
fps *average.SMA
pps *average.SMA
bitrate *average.SMA
}
func (a *averager) init(window, granularity time.Duration) {
a.fps, _ = average.New(window, granularity)
a.pps, _ = average.New(window, granularity)
a.bitrate, _ = average.New(window, granularity)
a.fps, _ = average.NewSMA(window, granularity)
a.pps, _ = average.NewSMA(window, granularity)
a.bitrate, _ = average.NewSMA(window, granularity)
}
func (a *averager) stop() {
a.fps.Stop()
a.pps.Stop()
a.bitrate.Stop()
a.fps.Reset()
a.pps.Reset()
a.bitrate.Reset()
}