Skip to content

Commit 39052f8

Browse files
Alex PokotiloSean-Der
Alex Pokotilo
authored andcommittedMar 18, 2024·
Add padding support to Packetizer
To add padding-only samples call GeneratePadding
1 parent 057eda3 commit 39052f8

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
 

Diff for: ‎packetizer.go

+33
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type Payloader interface {
1515
// Packetizer packetizes a payload
1616
type Packetizer interface {
1717
Packetize(payload []byte, samples uint32) []*Packet
18+
GeneratePadding(samples uint32) []*Packet
1819
EnableAbsSendTime(value int)
1920
SkipSamples(skippedSamples uint32)
2021
}
@@ -98,6 +99,38 @@ func (p *packetizer) Packetize(payload []byte, samples uint32) []*Packet {
9899
return packets
99100
}
100101

102+
// GeneratePadding returns required padding-only packages
103+
func (p *packetizer) GeneratePadding(samples uint32) []*Packet {
104+
// Guard against an empty payload
105+
if samples == 0 {
106+
return nil
107+
}
108+
109+
packets := make([]*Packet, samples)
110+
111+
for i := 0; i < int(samples); i++ {
112+
pp := make([]byte, 255)
113+
pp[254] = 255
114+
115+
packets[i] = &Packet{
116+
Header: Header{
117+
Version: 2,
118+
Padding: true,
119+
Extension: false,
120+
Marker: false,
121+
PayloadType: p.PayloadType,
122+
SequenceNumber: p.Sequencer.NextSequenceNumber(),
123+
Timestamp: p.Timestamp, // Use latest timestamp
124+
SSRC: p.SSRC,
125+
CSRC: []uint32{},
126+
},
127+
Payload: pp,
128+
}
129+
}
130+
131+
return packets
132+
}
133+
101134
// SkipSamples causes a gap in sample count between Packetize requests so the
102135
// RTP payloads produced have a gap in timestamps
103136
func (p *packetizer) SkipSamples(skippedSamples uint32) {

0 commit comments

Comments
 (0)
Please sign in to comment.