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

Avoid dropping packets for simulcast probes #2777

Open
wants to merge 1 commit into
base: v3
Choose a base branch
from
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
38 changes: 17 additions & 21 deletions peerconnection.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
"crypto/rand"
"errors"
"fmt"
"io"
"strconv"
"strings"
"sync"
Expand Down Expand Up @@ -1480,7 +1479,7 @@
}
}

func (pc *PeerConnection) handleUndeclaredSSRC(ssrc SSRC, remoteDescription *SessionDescription) (handled bool, err error) {
func (pc *PeerConnection) handleUndeclaredSSRC(ssrc SSRC, payloadType PayloadType, remoteDescription *SessionDescription) (handled bool, err error) {
if len(remoteDescription.parsed.MediaDescriptions) != 1 {
return false, nil
}
Expand Down Expand Up @@ -1534,7 +1533,7 @@
return true, nil
}

func (pc *PeerConnection) handleIncomingSSRC(rtpStream io.Reader, ssrc SSRC) error { //nolint:gocognit
func (pc *PeerConnection) handleIncomingSSRC(rtpStream *srtp.ReadStreamSRTP, ssrc SSRC, payloadType PayloadType) error { //nolint:gocognit
remoteDescription := pc.RemoteDescription()
if remoteDescription == nil {
return errPeerConnRemoteDescriptionNil
Expand All @@ -1553,7 +1552,7 @@
}

// If the remote SDP was only one media section the ssrc doesn't have to be explicitly declared
if handled, err := pc.handleUndeclaredSSRC(ssrc, remoteDescription); handled || err != nil {
if handled, err := pc.handleUndeclaredSSRC(ssrc, payloadType, remoteDescription); handled || err != nil {
return err
}

Expand All @@ -1569,18 +1568,6 @@

repairStreamIDExtensionID, _, _ := pc.api.mediaEngine.getHeaderExtensionID(RTPHeaderExtensionCapability{sdesRepairRTPStreamIDURI})

b := make([]byte, pc.api.settingEngine.getReceiveMTU())

i, err := rtpStream.Read(b)
if err != nil {
return err
}

if i < 4 {
return errRTPTooShort
}

payloadType := PayloadType(b[1] & 0x7f)
params, err := pc.api.mediaEngine.getRTPParametersByPayloadType(payloadType)
if err != nil {
return err
Expand All @@ -1592,16 +1579,24 @@
return err
}

b := make([]byte, pc.api.settingEngine.getReceiveMTU())
var mid, rid, rsid string
var paddingOnly bool
firstPacket := true
for readCount := 0; readCount <= simulcastProbeCount; readCount++ {
if mid == "" || (rid == "" && rsid == "") {
// skip padding only packets for probing
if paddingOnly {
readCount--
}

i, _, err := interceptor.Read(b, nil)
if !firstPacket {
// Consume the packet that we peeked last time
if _, err := readStream.Read([]byte{}); err != nil {
return err
}
}
i, err := readStream.Peek(b)

Check failure on line 1599 in peerconnection.go

View workflow job for this annotation

GitHub Actions / lint / Go

readStream.Peek undefined (type *srtp.ReadStreamSRTP has no field or method Peek)

Check failure on line 1599 in peerconnection.go

View workflow job for this annotation

GitHub Actions / lint / Go

readStream.Peek undefined (type *srtp.ReadStreamSRTP has no field or method Peek)

Check failure on line 1599 in peerconnection.go

View workflow job for this annotation

GitHub Actions / test (1.20) / Go 1.20

readStream.Peek undefined (type *srtp.ReadStreamSRTP has no field or method Peek)
if err != nil {
return err
}
Expand All @@ -1610,6 +1605,7 @@
return err
}

firstPacket = false
continue
}

Expand Down Expand Up @@ -1653,7 +1649,7 @@
return
}

stream, ssrc, err := srtpSession.AcceptStream()
stream, ssrc, payloadType, err := srtpSession.AcceptStreamWithPayloadType()

Check failure on line 1652 in peerconnection.go

View workflow job for this annotation

GitHub Actions / lint / Go

srtpSession.AcceptStreamWithPayloadType undefined (type *srtp.SessionSRTP has no field or method AcceptStreamWithPayloadType)) (typecheck)

Check failure on line 1652 in peerconnection.go

View workflow job for this annotation

GitHub Actions / lint / Go

srtpSession.AcceptStreamWithPayloadType undefined (type *srtp.SessionSRTP has no field or method AcceptStreamWithPayloadType)) (typecheck)

Check failure on line 1652 in peerconnection.go

View workflow job for this annotation

GitHub Actions / test (1.20) / Go 1.20

srtpSession.AcceptStreamWithPayloadType undefined (type *srtp.SessionSRTP has no field or method AcceptStreamWithPayloadType)
if err != nil {
pc.log.Warnf("Failed to accept RTP %v", err)
return
Expand All @@ -1674,12 +1670,12 @@
continue
}

go func(rtpStream io.Reader, ssrc SSRC) {
if err := pc.handleIncomingSSRC(rtpStream, ssrc); err != nil {
go func(rtpStream *srtp.ReadStreamSRTP, ssrc SSRC, payloadType PayloadType) {
if err := pc.handleIncomingSSRC(rtpStream, ssrc, payloadType); err != nil {
pc.log.Errorf(incomingUnhandledRTPSsrc, ssrc, err)
}
atomic.AddUint64(&simulcastRoutineCount, ^uint64(0))
}(stream, SSRC(ssrc))
}(stream, SSRC(ssrc), PayloadType(payloadType))
}
}

Expand Down
Loading