Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Increment rtx rtp packet sequence number only when trasmitted #285

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions internal/rtpbuffer/packet_factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const rtxSsrcByteLength = 2
// The NoOpPacketFactory doesn't copy packets, while the RetainablePacket will take a copy before adding
type PacketFactory interface {
NewPacket(header *rtp.Header, payload []byte, rtxSsrc uint32, rtxPayloadType uint8) (*RetainablePacket, error)
FillSequenceNumber(packet *RetainablePacket)
}

// PacketFactoryCopy is PacketFactory that takes a copy of packets when added to the RTPBuffer
Expand Down Expand Up @@ -94,8 +95,6 @@ func (m *PacketFactoryCopy) NewPacket(header *rtp.Header, payload []byte, rtxSsr
p.header.SSRC = rtxSsrc
// Rewrite the payload type.
p.header.PayloadType = rtxPayloadType
// Rewrite the sequence number.
p.header.SequenceNumber = m.rtxSequencer.NextSequenceNumber()
// Remove padding if present.
if p.header.Padding && p.payload != nil && len(p.payload) > 0 {
paddingLength := int(p.payload[len(p.payload)-1])
Expand All @@ -107,6 +106,10 @@ func (m *PacketFactoryCopy) NewPacket(header *rtp.Header, payload []byte, rtxSsr
return p, nil
}

func (m *PacketFactoryCopy) FillSequenceNumber(packet *RetainablePacket) {
packet.header.SequenceNumber = m.rtxSequencer.NextSequenceNumber()
}

func (m *PacketFactoryCopy) releasePacket(header *rtp.Header, payload *[]byte) {
m.headerPool.Put(header)
if payload != nil {
Expand All @@ -128,6 +131,9 @@ func (f *PacketFactoryNoOp) NewPacket(header *rtp.Header, payload []byte, _ uint
}, nil
}

func (m *PacketFactoryNoOp) FillSequenceNumber(packet *RetainablePacket) {
}

func (f *PacketFactoryNoOp) releasePacket(_ *rtp.Header, _ *[]byte) {
// no-op
}
1 change: 1 addition & 0 deletions pkg/nack/responder_interceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ func (n *ResponderInterceptor) resendPackets(nack *rtcp.TransportLayerNack) {
defer stream.rtpBufferMutex.Unlock()

if p := stream.rtpBuffer.Get(seq); p != nil {
n.packetFactory.FillSequenceNumber(p)
if _, err := stream.rtpWriter.Write(p.Header(), p.Payload(), interceptor.Attributes{}); err != nil {
n.log.Warnf("failed resending nacked packet: %+v", err)
}
Expand Down