Completely rearchitect the overall project structure

This commit is contained in:
Lukas Herman
2019-12-24 22:43:38 -08:00
parent 254654e5f0
commit 709e56166f
15 changed files with 371 additions and 214 deletions

28
sampler.go Normal file
View File

@@ -0,0 +1,28 @@
package mediadevices
import (
"time"
"github.com/pion/webrtc/v2/pkg/media"
)
type sampler struct {
clockRate float64
lastTimestamp time.Time
}
func newSampler(clockRate uint32) *sampler {
return &sampler{
clockRate: float64(clockRate),
lastTimestamp: time.Now(),
}
}
func (s *sampler) sample(b []byte) media.Sample {
now := time.Now()
duration := now.Sub(s.lastTimestamp).Seconds()
samples := uint32(s.clockRate * duration)
s.lastTimestamp = now
return media.Sample{Data: b, Samples: samples}
}