Skip to content
Open
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
23 changes: 19 additions & 4 deletions pkg/sip/media_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,6 @@ func (p *MediaPort) rtpLoop(tid traceid.ID, sess rtp.Session) {
p.stats.Streams.Add(1)
p.mediaReceived.Break()
log := p.log.WithValues("ssrc", ssrc)
log.Infow("accepting RTP stream")
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to include discarded packets number, and first RTP seq

go p.rtpReadLoop(tid, log, r)
}
}
Expand All @@ -641,10 +640,13 @@ func (p *MediaPort) rtpReadLoop(tid traceid.ID, log logger.Logger, r rtp.ReadStr
const maxErrors = 50 // 1 sec, given 20 ms frames
buf := make([]byte, rtp.MTUSize+1)
overflow := false
catchup := true
var (
h rtp.Header
pipeline string
errorCnt int
h rtp.Header
pipeline string
errorCnt int
lastPacketTime time.Time
discardedPackets int
)
for {
h = rtp.Header{}
Expand All @@ -655,6 +657,19 @@ func (p *MediaPort) rtpReadLoop(tid traceid.ID, log logger.Logger, r rtp.ReadStr
log.Errorw("read RTP failed", err)
return
}
if catchup {
// When a remote writer has been sending data but the local stream didn't start the RTP loop,
// such as in outbound calls that take a sec to answer, we have a ton of junk in the stream.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I'm following here.

There's presumably some garbage sent before the call is established. But the code in the PR doesn't even check the RTP headers or the payload. Why are we dropping it unconditionally?

Assuming there's some audio there (silence? ringing?) or even just audio junk, it won't propagate through the media pipeline until it's actually enabled (we have multiple SwitchWriters in the pipeline that can cut the stream).

So why is this necessary?

// We need to discard all of it.
now := time.Now()
if lastPacketTime.IsZero() || now.Sub(lastPacketTime) < time.Millisecond {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note, for inbound calls, we will discard the first packet as well, even if there isn't anything buffered in there.
We can, of course introduce code to correct for that, but the added complexity was deemed not justified due to non-existing impact.

lastPacketTime = now
discardedPackets++
continue
}
catchup = false
log.Infow("accepting RTP stream", "sequenceNumber", h.SequenceNumber, "discarded", discardedPackets)
}
p.packetCount.Add(1)
p.stats.Packets.Add(1)
if n > rtp.MTUSize {
Expand Down
Loading