Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SampleBuilder: Remove deprecated functions #2684

Merged
merged 2 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 0 additions & 17 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 All @@ -364,12 +353,6 @@ func timestampDistance(x, y uint32) uint32 {
// An Option configures a SampleBuilder.
type Option func(o *SampleBuilder)

// WithPartitionHeadChecker is obsolete, it does nothing.
func WithPartitionHeadChecker(interface{}) Option {
return func(o *SampleBuilder) {
}
}

// WithPacketReleaseHandler set a callback when the builder is about to release
// some packet.
func WithPacketReleaseHandler(h func(*rtp.Packet)) Option {
Expand Down
31 changes: 11 additions & 20 deletions pkg/media/samplebuilder/samplebuilder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
type fakeDepacketizer struct {
headChecker bool
headBytes []byte
alwaysHead bool
}

func (f *fakeDepacketizer) Unmarshal(r []byte) ([]byte, error) {
Expand All @@ -44,6 +45,10 @@
return false
}

if f.alwaysHead {
return true
}

for _, b := range f.headBytes {
if payload[0] == b {
return true
Expand Down Expand Up @@ -443,7 +448,7 @@
}

headCount := 0
s := New(10, &fakeDepacketizer{}, 1, WithPacketHeadHandler(func(headPacket interface{}) interface{} {

Check warning on line 451 in pkg/media/samplebuilder/samplebuilder_test.go

View workflow job for this annotation

GitHub Actions / lint / Go

unused-parameter: parameter 'headPacket' seems to be unused, consider removing or renaming it as _ (revive)

Check warning on line 451 in pkg/media/samplebuilder/samplebuilder_test.go

View workflow job for this annotation

GitHub Actions / lint / Go

unused-parameter: parameter 'headPacket' seems to be unused, consider removing or renaming it as _ (revive)
headCount++
return true
}))
Expand All @@ -465,25 +470,11 @@
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 {
return true
}

func TestSampleBuilderData(t *testing.T) {
s := New(10, &fakeDepacketizer{}, 1,
WithPartitionHeadChecker(&truePartitionHeadChecker{}),
)
s := New(10, &fakeDepacketizer{
headChecker: true,
alwaysHead: true,
}, 1)
j := 0
for i := 0; i < 0x20000; i++ {
p := rtp.Packet{
Expand All @@ -495,11 +486,11 @@
}
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
Loading