mirror of
https://github.com/pion/mediadevices.git
synced 2025-09-27 04:46:10 +08:00
29 lines
524 B
Go
29 lines
524 B
Go
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}
|
|
}
|