Skip to content

Commit

Permalink
Add padding support to Packetizer
Browse files Browse the repository at this point in the history
To add padding-only samples call GeneratePadding
  • Loading branch information
Alex Pokotilo authored and Sean-Der committed Mar 18, 2024
1 parent 057eda3 commit 39052f8
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packetizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Payloader interface {
// Packetizer packetizes a payload
type Packetizer interface {
Packetize(payload []byte, samples uint32) []*Packet
GeneratePadding(samples uint32) []*Packet
EnableAbsSendTime(value int)
SkipSamples(skippedSamples uint32)
}
Expand Down Expand Up @@ -98,6 +99,38 @@ func (p *packetizer) Packetize(payload []byte, samples uint32) []*Packet {
return packets
}

// GeneratePadding returns required padding-only packages
func (p *packetizer) GeneratePadding(samples uint32) []*Packet {
// Guard against an empty payload
if samples == 0 {
return nil
}

packets := make([]*Packet, samples)

for i := 0; i < int(samples); i++ {
pp := make([]byte, 255)
pp[254] = 255

packets[i] = &Packet{
Header: Header{
Version: 2,
Padding: true,
Extension: false,
Marker: false,
PayloadType: p.PayloadType,
SequenceNumber: p.Sequencer.NextSequenceNumber(),
Timestamp: p.Timestamp, // Use latest timestamp
SSRC: p.SSRC,
CSRC: []uint32{},
},
Payload: pp,
}
}

return packets
}

// SkipSamples causes a gap in sample count between Packetize requests so the
// RTP payloads produced have a gap in timestamps
func (p *packetizer) SkipSamples(skippedSamples uint32) {
Expand Down

0 comments on commit 39052f8

Please sign in to comment.