Use nanosecond instead of Millisecond precision

media.SampleBuilder would round time and was breaking audio samples that
required higher precision. This was seen only with alaw/ulaw that needed
microsecond precision. v3 had only been used with Opus so far.

Resolves #1640
This commit is contained in:
Sean DuBois
2021-01-17 16:02:55 -08:00
parent dc1d46404b
commit 91935c7d5b

View File

@@ -76,6 +76,8 @@ func (s *SampleBuilder) Push(p *rtp.Packet) {
s.lastPush = p.SequenceNumber
}
const secondToNanoseconds = 1000000000
// We have a valid collection of RTP Packets
// walk forwards building a sample if everything looks good clear and update buffer+values
func (s *SampleBuilder) buildSample(firstBuffer uint16) (*media.Sample, uint32) {
@@ -102,7 +104,7 @@ func (s *SampleBuilder) buildSample(firstBuffer uint16) (*media.Sample, uint32)
s.releasePacket(j)
}
return &media.Sample{Data: data, Duration: time.Duration((float64(samples)/float64(s.sampleRate))*1000) * time.Millisecond}, s.lastPopTimestamp
return &media.Sample{Data: data, Duration: time.Duration((float64(samples)/float64(s.sampleRate))*secondToNanoseconds) * time.Nanosecond}, s.lastPopTimestamp
}
p, err := s.depacketizer.Unmarshal(s.buffer[i].Payload)