Skip to content

Commit 8efd17e

Browse files
committed
Do not create receiver for ealy media in offerer
For offerer, if the remote side sends early media before the remote description (answer) is received, the undeclared SSRC processor can create a receiver and that receiver could be left dangling as transceiver `mid` is not updated from remote description answer. Still leaving the simulcast probe path and only avoiding creating a receiver for non-simulcast path. Add a flag `handleUndeclaredSSRCWithoutAnswer` to control handling of early media without SDP answer for non-simulcast tracks. The default behaviour is to not process early media without SDP answer.
1 parent 29e1e00 commit 8efd17e

File tree

3 files changed

+22
-4
lines changed

3 files changed

+22
-4
lines changed

errors.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ var (
231231
errPeerConnSetIdentityProviderNotImplemented = errors.New("TODO SetIdentityProvider")
232232
errPeerConnWriteRTCPOpenWriteStream = errors.New("WriteRTCP failed to open WriteStream")
233233
errPeerConnTranscieverMidNil = errors.New("cannot find transceiver with mid")
234+
errPeerConnEarlyMediaWithoutAnswer = errors.New(
235+
"cannot process early media without SDP answer," +
236+
"use SettingEngine.SetHandleUndeclaredSSRCWithoutAnswer(true) to process without answer",
237+
)
234238

235239
errRTPReceiverDTLSTransportNil = errors.New("DTLSTransport must not be nil")
236240
errRTPReceiverReceiveAlreadyCalled = errors.New("Receive has already been called")

peerconnection.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1719,10 +1719,12 @@ func (pc *PeerConnection) handleIncomingSSRC(rtpStream io.Reader, ssrc SSRC) err
17191719
// (urn:ietf:params:rtp-hdrext:sdes:rtp-stream-id and urn:ietf:params:rtp-hdrext:sdes:mid)
17201720
// and even if the RTP stream contains an incorrect MID or RID.
17211721
// while this can be incorrect, this is done to maintain compatibility with older behavior.
1722-
if len(remoteDescription.parsed.MediaDescriptions) == 1 {
1723-
mediaSection := remoteDescription.parsed.MediaDescriptions[0]
1724-
if handled, err := pc.handleUndeclaredSSRC(ssrc, mediaSection); handled || err != nil {
1725-
return err
1722+
if remoteDescription.Type != SDPTypeAnswer || pc.api.settingEngine.handleUndeclaredSSRCWithoutAnswer {
1723+
if len(remoteDescription.parsed.MediaDescriptions) == 1 {
1724+
mediaSection := remoteDescription.parsed.MediaDescriptions[0]
1725+
if handled, err := pc.handleUndeclaredSSRC(ssrc, mediaSection); handled || err != nil {
1726+
return err
1727+
}
17261728
}
17271729
}
17281730

@@ -1748,6 +1750,11 @@ func (pc *PeerConnection) handleIncomingSSRC(rtpStream io.Reader, ssrc SSRC) err
17481750
RTPHeaderExtensionCapability{sdp.SDESMidURI},
17491751
)
17501752
if !audioSupported && !videoSupported {
1753+
if remoteDescription.Type == SDPTypeAnswer && !pc.api.settingEngine.handleUndeclaredSSRCWithoutAnswer {
1754+
// if we are offerer, wait for answer with media setion to process this SSRC
1755+
return errPeerConnEarlyMediaWithoutAnswer
1756+
}
1757+
17511758
// try to find media section by payload type as a last resort for legacy clients.
17521759
mediaSection, ok := pc.findMediaSectionByPayloadType(payloadType, remoteDescription)
17531760
if ok {

settingengine.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ type SettingEngine struct {
109109
fireOnTrackBeforeFirstRTP bool
110110
disableCloseByDTLS bool
111111
dataChannelBlockWrite bool
112+
handleUndeclaredSSRCWithoutAnswer bool
112113
}
113114

114115
func (e *SettingEngine) getSCTPMaxMessageSize() uint32 {
@@ -570,3 +571,9 @@ func (e *SettingEngine) SetFireOnTrackBeforeFirstRTP(fireOnTrackBeforeFirstRTP b
570571
func (e *SettingEngine) DisableCloseByDTLS(isEnabled bool) {
571572
e.disableCloseByDTLS = isEnabled
572573
}
574+
575+
// SetHandleUndeclaredSSRCWithoutAnswer controls if an SDP answer is required for
576+
// processing early media of non-simulcast tracks.
577+
func (e *SettingEngine) SetHandleUndeclaredSSRCWithoutAnswer(handleUndeclaredSSRCWithoutAnswer bool) {
578+
e.handleUndeclaredSSRCWithoutAnswer = handleUndeclaredSSRCWithoutAnswer
579+
}

0 commit comments

Comments
 (0)