From a92fa8c71350e00994f01a5d13bd95feb2060057 Mon Sep 17 00:00:00 2001 From: Atsushi Watanabe Date: Thu, 29 Feb 2024 10:25:18 +0900 Subject: [PATCH] SampleBuilder: Remove PopWithTimestamp Use Sample.PacketTimestamp field instead. Migration example: - sample, timestamp := s.PopWithTimestamp() + sample := s.Pop() + timestamp := sample.PacketTimestamp --- pkg/media/samplebuilder/samplebuilder.go | 11 ----------- pkg/media/samplebuilder/samplebuilder_test.go | 13 ++----------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/pkg/media/samplebuilder/samplebuilder.go b/pkg/media/samplebuilder/samplebuilder.go index a096f5ae949..0608d170941 100644 --- a/pkg/media/samplebuilder/samplebuilder.go +++ b/pkg/media/samplebuilder/samplebuilder.go @@ -330,17 +330,6 @@ func (s *SampleBuilder) Pop() *media.Sample { return result } -// PopWithTimestamp compiles pushed RTP packets into media samples and then -// returns the next valid sample with its associated RTP timestamp (or nil, 0 if -// no sample is compiled). -func (s *SampleBuilder) PopWithTimestamp() (*media.Sample, uint32) { - sample := s.Pop() - if sample == nil { - return nil, 0 - } - return sample, sample.PacketTimestamp -} - // seqnumDistance computes the distance between two sequence numbers func seqnumDistance(x, y uint16) uint16 { diff := int16(x - y) diff --git a/pkg/media/samplebuilder/samplebuilder_test.go b/pkg/media/samplebuilder/samplebuilder_test.go index 9bd86f0e841..6aa8ef23180 100644 --- a/pkg/media/samplebuilder/samplebuilder_test.go +++ b/pkg/media/samplebuilder/samplebuilder_test.go @@ -465,15 +465,6 @@ func TestSampleBuilderWithPacketHeadHandler(t *testing.T) { assert.Equal(t, 2, headCount, "two sample heads should have been inspected") } -func TestPopWithTimestamp(t *testing.T) { - t.Run("Crash on nil", func(t *testing.T) { - s := New(0, &fakeDepacketizer{}, 1) - sample, timestamp := s.PopWithTimestamp() - assert.Nil(t, sample) - assert.Equal(t, uint32(0), timestamp) - }) -} - type truePartitionHeadChecker struct{} func (f *truePartitionHeadChecker) IsPartitionHead([]byte) bool { @@ -495,11 +486,11 @@ func TestSampleBuilderData(t *testing.T) { } s.Push(&p) for { - sample, ts := s.PopWithTimestamp() + sample := s.Pop() if sample == nil { break } - assert.Equal(t, ts, uint32(j+42), "timestamp") + assert.Equal(t, sample.PacketTimestamp, uint32(j+42), "timestamp") assert.Equal(t, len(sample.Data), 1, "data length") assert.Equal(t, byte(j), sample.Data[0], "data") j++