Skip to content

Commit f5d98ce

Browse files
committed
Updated Test_TrackLocalStatic_Padding test
Use custom packetizer in Test_TrackLocalStatic_Padding to verify that padding added in different ways works.
1 parent 6f6038b commit f5d98ce

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

track_local_static_test.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,37 @@ func BenchmarkTrackLocalWrite(b *testing.B) {
271271
}
272272
}
273273

274+
type TestPacketizer struct {
275+
rtp.Packetizer
276+
checked [3]bool
277+
}
278+
279+
func (p *TestPacketizer) GeneratePadding(samples uint32) []*rtp.Packet {
280+
packets := p.Packetizer.GeneratePadding(samples)
281+
for _, packet := range packets {
282+
// Reset padding to ensure we control it
283+
packet.Header.PaddingSize = 0
284+
packet.PaddingSize = 0
285+
packet.Payload = nil
286+
287+
p.checked[packet.SequenceNumber%3] = true
288+
switch packet.SequenceNumber % 3 {
289+
case 0:
290+
// Recommended way to add padding
291+
packet.Header.PaddingSize = 255
292+
case 1:
293+
// This was used as a workaround so has to be supported too
294+
packet.Payload = make([]byte, 255)
295+
packet.Payload[254] = 255
296+
case 2:
297+
// This field is deprecated but still used by some clients
298+
packet.PaddingSize = 255
299+
}
300+
}
301+
302+
return packets
303+
}
304+
274305
func Test_TrackLocalStatic_Padding(t *testing.T) {
275306
mediaEngineOne := &MediaEngine{}
276307
assert.NoError(t, mediaEngineOne.RegisterCodec(RTPCodecParameters{
@@ -333,6 +364,10 @@ func Test_TrackLocalStatic_Padding(t *testing.T) {
333364

334365
exit := false
335366

367+
// Use a custom packetizer that generates packets with padding in a few different ways
368+
packetizer := &TestPacketizer{Packetizer: track.packetizer}
369+
track.packetizer = packetizer
370+
336371
for !exit {
337372
select {
338373
case <-time.After(1 * time.Millisecond):
@@ -343,6 +378,8 @@ func Test_TrackLocalStatic_Padding(t *testing.T) {
343378
}
344379

345380
closePairNow(t, offerer, answerer)
381+
382+
assert.Equal(t, [3]bool{true, true, true}, packetizer.checked)
346383
}
347384

348385
func Test_TrackLocalStatic_RTX(t *testing.T) {

0 commit comments

Comments
 (0)