From 9e6d659a54f58088bc1d2383f1c824cbc8f29411 Mon Sep 17 00:00:00 2001 From: Sean DuBois Date: Fri, 29 Jan 2021 11:17:24 -0800 Subject: [PATCH] SampleBuilder should Unmarshal after collecting Before we incorrectly ran Unmarshal on every RTP Payload. This worked for Opus and VP8 because it didn't care about the Payload Headers. However this would break H264. Relates to #1652 --- pkg/media/samplebuilder/samplebuilder.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/pkg/media/samplebuilder/samplebuilder.go b/pkg/media/samplebuilder/samplebuilder.go index eb4296ed34a..9132d0c7788 100644 --- a/pkg/media/samplebuilder/samplebuilder.go +++ b/pkg/media/samplebuilder/samplebuilder.go @@ -81,7 +81,7 @@ 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) { - data := []byte{} + payloadBuffer := []byte{} for i := firstBuffer; s.buffer[i] != nil; i++ { if s.buffer[i].Timestamp != s.buffer[firstBuffer].Timestamp { @@ -104,15 +104,15 @@ 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))*secondToNanoseconds) * time.Nanosecond}, s.lastPopTimestamp - } + data, err := s.depacketizer.Unmarshal(payloadBuffer) + if err != nil { + return nil, 0 + } - p, err := s.depacketizer.Unmarshal(s.buffer[i].Payload) - if err != nil { - return nil, 0 + return &media.Sample{Data: data, Duration: time.Duration((float64(samples)/float64(s.sampleRate))*secondToNanoseconds) * time.Nanosecond}, s.lastPopTimestamp } - data = append(data, p...) + payloadBuffer = append(payloadBuffer, s.buffer[i].Payload...) } return nil, 0 }