diff --git a/packetizer.go b/packetizer.go index 7ecebde..7a6a46d 100644 --- a/packetizer.go +++ b/packetizer.go @@ -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) } @@ -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) {