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 committed Mar 18, 2024
1 parent 7dc2af5 commit 1f351cb
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
}

Check warning on line 107 in packetizer.go

View check run for this annotation

Codecov / codecov/patch

packetizer.go#L103-L107

Added lines #L103 - L107 were not covered by tests

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,
}
}

Check warning on line 129 in packetizer.go

View check run for this annotation

Codecov / codecov/patch

packetizer.go#L109-L129

Added lines #L109 - L129 were not covered by tests

return packets

Check warning on line 131 in packetizer.go

View check run for this annotation

Codecov / codecov/patch

packetizer.go#L131

Added line #L131 was not covered by tests
}

// 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 1f351cb

Please sign in to comment.