Fix: sample builder test always returns data

Wrap around issue caused backup of packets in sample builder.
This commit is contained in:
Robin Raymond
2021-07-12 11:52:25 -04:00
parent ee255e8956
commit 36cf39516f
2 changed files with 36 additions and 1 deletions

View File

@@ -203,7 +203,7 @@ func (s *SampleBuilder) buildSample(purgingBuffers bool) *media.Sample {
var consume sampleSequenceLocation
for i := s.active.head; s.buffer[i] != nil && i < s.active.tail; i++ {
for i := s.active.head; s.buffer[i] != nil && s.active.compare(i) != slCompareAfter; i++ {
if s.depacketizer.IsDetectedFinalPacketInSequence(s.buffer[i].Marker) {
consume.head = s.active.head
consume.tail = i + 1

View File

@@ -388,3 +388,38 @@ func TestPopWithTimestamp(t *testing.T) {
assert.Equal(t, uint32(0), timestamp)
})
}
type truePartitionHeadChecker struct{}
func (f *truePartitionHeadChecker) IsPartitionHead(payload []byte) bool {
return true
}
func TestSampleBuilderData(t *testing.T) {
s := New(10, &fakeDepacketizer{}, 1,
WithPartitionHeadChecker(&truePartitionHeadChecker{}),
)
j := 0
for i := 0; i < 0x20000; i++ {
p := rtp.Packet{
Header: rtp.Header{
SequenceNumber: uint16(i),
Timestamp: uint32(i + 42),
},
Payload: []byte{byte(i)},
}
s.Push(&p)
for {
sample, ts := s.PopWithTimestamp()
if sample == nil {
break
}
assert.Equal(t, ts, uint32(j+42), "timestamp")
assert.Equal(t, len(sample.Data), 1, "data length")
assert.Equal(t, byte(j), sample.Data[0], "data")
j++
}
}
// only the last packet should be dropped
assert.Equal(t, j, 0x1FFFF)
}