Filter late retransmitted packets

This commit is contained in:
Nonoo 2020-10-26 17:43:22 +01:00
parent b9a8f627c3
commit c0afc17190
3 changed files with 18 additions and 5 deletions

View file

@ -20,7 +20,7 @@ type audioStream struct {
timeoutTimer *time.Timer timeoutTimer *time.Timer
receivedAudio bool receivedAudio bool
lastReceivedAudioSeq uint16 lastReceivedSeq uint16
rxSeqBuf seqBuf rxSeqBuf seqBuf
rxSeqBufEntryChan chan seqBufEntry rxSeqBufEntryChan chan seqBufEntry
@ -60,7 +60,13 @@ func (s *audioStream) sendPart2(pcmData []byte) error {
func (s *audioStream) handleRxSeqBufEntry(e seqBufEntry) { func (s *audioStream) handleRxSeqBufEntry(e seqBufEntry) {
gotSeq := uint16(e.seq) gotSeq := uint16(e.seq)
if s.receivedAudio { if s.receivedAudio {
expectedSeq := s.lastReceivedAudioSeq + 1 // Out of order packets can happen if we receive a retransmitted packet, but too late.
if s.rxSeqBuf.leftOrRightCloserToSeq(e.seq, seqNum(s.lastReceivedSeq)) != left {
log.Debug("got out of order pkt seq #", e.seq)
return
}
expectedSeq := s.lastReceivedSeq + 1
if expectedSeq != gotSeq { if expectedSeq != gotSeq {
var missingPkts int var missingPkts int
if gotSeq > expectedSeq { if gotSeq > expectedSeq {
@ -72,7 +78,7 @@ func (s *audioStream) handleRxSeqBufEntry(e seqBufEntry) {
log.Error("lost ", missingPkts, " audio packets") log.Error("lost ", missingPkts, " audio packets")
} }
} }
s.lastReceivedAudioSeq = gotSeq s.lastReceivedSeq = gotSeq
s.receivedAudio = true s.receivedAudio = true
s.audio.play <- e.data s.audio.play <- e.data

View file

@ -106,6 +106,7 @@ const (
type direction int type direction int
// Decides the direction of which seq is closer to whichSeq, considering the seq turnover at maxSeqNum. // Decides the direction of which seq is closer to whichSeq, considering the seq turnover at maxSeqNum.
// Basically left means seq is larger than whichSeq, and right means seq is smaller than whichSeq.
// Example: returns left for seq=2 whichSeq=1 // Example: returns left for seq=2 whichSeq=1
// returns right for seq=0 whichSeq=1 // returns right for seq=0 whichSeq=1
// returns right for seq=39 whichSeq=1 if maxSeqNum is 40 // returns right for seq=39 whichSeq=1 if maxSeqNum is 40

View file

@ -68,6 +68,12 @@ func (s *serialStream) sendOpenClose(close bool) error {
func (s *serialStream) handleRxSeqBufEntry(e seqBufEntry) { func (s *serialStream) handleRxSeqBufEntry(e seqBufEntry) {
gotSeq := uint16(e.seq) gotSeq := uint16(e.seq)
if s.receivedSerialData { if s.receivedSerialData {
// Out of order packets can happen if we receive a retransmitted packet, but too late.
if s.rxSeqBuf.leftOrRightCloserToSeq(e.seq, seqNum(s.lastReceivedSeq)) != left {
log.Debug("got out of order pkt seq #", e.seq)
return
}
expectedSeq := s.lastReceivedSeq + 1 expectedSeq := s.lastReceivedSeq + 1
if expectedSeq != gotSeq { if expectedSeq != gotSeq {
var missingPkts int var missingPkts int