-
Notifications
You must be signed in to change notification settings - Fork 64
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
Option to limit max NACKs per lost packet #208
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,12 +21,14 @@ | |
// NewInterceptor constructs a new ReceiverInterceptor | ||
func (g *GeneratorInterceptorFactory) NewInterceptor(_ string) (interceptor.Interceptor, error) { | ||
i := &GeneratorInterceptor{ | ||
size: 512, | ||
skipLastN: 0, | ||
interval: time.Millisecond * 100, | ||
receiveLogs: map[uint32]*receiveLog{}, | ||
close: make(chan struct{}), | ||
log: logging.NewDefaultLoggerFactory().NewLogger("nack_generator"), | ||
size: 512, | ||
skipLastN: 0, | ||
maxNacksPerPacket: 0, | ||
interval: time.Millisecond * 100, | ||
receiveLogs: map[uint32]*receiveLog{}, | ||
nackCountLogs: map[uint32]map[uint16]uint16{}, | ||
close: make(chan struct{}), | ||
log: logging.NewDefaultLoggerFactory().NewLogger("nack_generator"), | ||
} | ||
|
||
for _, opt := range g.opts { | ||
|
@@ -45,13 +47,15 @@ | |
// GeneratorInterceptor interceptor generates nack feedback messages. | ||
type GeneratorInterceptor struct { | ||
interceptor.NoOp | ||
size uint16 | ||
skipLastN uint16 | ||
interval time.Duration | ||
m sync.Mutex | ||
wg sync.WaitGroup | ||
close chan struct{} | ||
log logging.LeveledLogger | ||
size uint16 | ||
skipLastN uint16 | ||
maxNacksPerPacket uint16 | ||
interval time.Duration | ||
m sync.Mutex | ||
wg sync.WaitGroup | ||
close chan struct{} | ||
log logging.LeveledLogger | ||
nackCountLogs map[uint32]map[uint16]uint16 | ||
|
||
receiveLogs map[uint32]*receiveLog | ||
receiveLogsMu sync.Mutex | ||
|
@@ -131,6 +135,7 @@ | |
return nil | ||
} | ||
|
||
// nolint:gocognit | ||
func (n *GeneratorInterceptor) loop(rtcpWriter interceptor.RTCPWriter) { | ||
defer n.wg.Done() | ||
|
||
|
@@ -147,14 +152,43 @@ | |
|
||
for ssrc, receiveLog := range n.receiveLogs { | ||
missing := receiveLog.missingSeqNumbers(n.skipLastN) | ||
|
||
if len(missing) == 0 || n.nackCountLogs[ssrc] == nil { | ||
n.nackCountLogs[ssrc] = map[uint16]uint16{} | ||
} | ||
if len(missing) == 0 { | ||
continue | ||
} | ||
|
||
filteredMissing := []uint16{} | ||
if n.maxNacksPerPacket > 0 { | ||
for _, missingSeq := range missing { | ||
if n.nackCountLogs[ssrc][missingSeq] < n.maxNacksPerPacket { | ||
filteredMissing = append(filteredMissing, missingSeq) | ||
} | ||
n.nackCountLogs[ssrc][missingSeq]++ | ||
} | ||
} else { | ||
filteredMissing = missing | ||
} | ||
|
||
nack := &rtcp.TransportLayerNack{ | ||
SenderSSRC: senderSSRC, | ||
MediaSSRC: ssrc, | ||
Nacks: rtcp.NackPairsFromSequenceNumbers(missing), | ||
Nacks: rtcp.NackPairsFromSequenceNumbers(filteredMissing), | ||
} | ||
|
||
for nackSeq := range n.nackCountLogs[ssrc] { | ||
isMissing := false | ||
for _, missingSeq := range missing { | ||
if missingSeq == nackSeq { | ||
isMissing = true | ||
break | ||
} | ||
} | ||
if !isMissing { | ||
delete(n.nackCountLogs[ssrc], nackSeq) | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't think of an easy way to spread this load. Wondering if the N^2 would cause some performance issues. It could happen that a network brown out drops 100s of packets. Multiple SSRCs experiencing at the same time could generate a bunch of NACKs and all of them could be missing while running this loop. Don't think it is a huge concern, but also thinking about some way to amortising it. Maybe, handle only one SSRC for clean up in one loop kind of stuff, but makes code more complicated. Guess, this can be checked for any performance issues and improved later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I thought of this too but can't think of an easy improvement. |
||
|
||
if _, err := rtcpWriter.Write([]rtcp.Packet{nack}, interceptor.Attributes{}); err != nil { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the new map a concern on every loop? Majority case is going to be
len(missing) == 0
. So, re-creating a map for all ssrcs every 100ms. Is that okay?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding is that an empty map is actually nil internally (i.e. no allocation), so I think this is OK.