mirror of
https://github.com/pion/mediadevices.git
synced 2025-11-02 04:43:22 +08:00
Completely rearchitect the overall project structure
This commit is contained in:
28
sampler.go
Normal file
28
sampler.go
Normal 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}
|
||||
}
|
||||
Reference in New Issue
Block a user