-
Notifications
You must be signed in to change notification settings - Fork 141
discarding buffered packets at the start of the stream #570
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
base: main
Are you sure you want to change the base?
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 |
|---|---|---|
|
|
@@ -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") | ||
| go p.rtpReadLoop(tid, log, r) | ||
| } | ||
| } | ||
|
|
@@ -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{} | ||
|
|
@@ -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. | ||
|
Contributor
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. 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 So why is this necessary? |
||
| // We need to discard all of it. | ||
| now := time.Now() | ||
| if lastPacketTime.IsZero() || now.Sub(lastPacketTime) < time.Millisecond { | ||
|
Contributor
Author
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. Note, for inbound calls, we will discard the first packet as well, even if there isn't anything buffered in there. |
||
| 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 { | ||
|
|
||
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.
Moved to include discarded packets number, and first RTP seq