Skip to content

Commit

Permalink
SampleBuilder: Remove PopWithTimestamp
Browse files Browse the repository at this point in the history
Use Sample.PacketTimestamp field instead.

Migration example:
- sample, timestamp := s.PopWithTimestamp()
+ sample := s.Pop()
+ timestamp := sample.PacketTimestamp
  • Loading branch information
at-wat committed Feb 29, 2024
1 parent 09a4f60 commit a92fa8c
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 22 deletions.
11 changes: 0 additions & 11 deletions pkg/media/samplebuilder/samplebuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
13 changes: 2 additions & 11 deletions pkg/media/samplebuilder/samplebuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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++
Expand Down

0 comments on commit a92fa8c

Please sign in to comment.