Fix trailing space in rtcp-fb with no Parameter

Media construction would always do "%s %s" even if no Parameter was
available. This commit fixes that by checking if Parameter is empty or
not.

Resolves #3207
This commit is contained in:
Sean DuBois
2025-09-04 10:34:47 -04:00
parent 457679c440
commit e9efed4d18
2 changed files with 42 additions and 2 deletions

6
sdp.go
View File

@@ -541,7 +541,7 @@ func addSenderSDP(
}
}
//nolint:cyclop
//nolint:cyclop, gocognit
func addTransceiverSDP(
descr *sdp.SessionDescription,
isPlanB bool,
@@ -575,9 +575,13 @@ func addTransceiverSDP(
media.WithCodec(uint8(codec.PayloadType), name, codec.ClockRate, codec.Channels, codec.SDPFmtpLine)
for _, feedback := range codec.RTPCodecCapability.RTCPFeedback {
if feedback.Parameter == "" {
media.WithValueAttribute("rtcp-fb", fmt.Sprintf("%d %s", codec.PayloadType, feedback.Type))
} else {
media.WithValueAttribute("rtcp-fb", fmt.Sprintf("%d %s %s", codec.PayloadType, feedback.Type, feedback.Parameter))
}
}
}
if len(codecs) == 0 {
// If we are sender and we have no codecs throw an error early
if transceiver.Sender() != nil {

View File

@@ -1057,6 +1057,42 @@ func TestPopulateSDP(t *testing.T) { //nolint:cyclop,maintidx
_, ok := offerSdp.Attribute(sdp.AttrKeyGroup)
assert.False(t, ok)
})
t.Run("rtcp-fb trailing space", func(t *testing.T) {
se := SettingEngine{}
me := &MediaEngine{}
assert.NoError(t, me.RegisterDefaultCodecs())
api := NewAPI(WithMediaEngine(me))
tr := &RTPTransceiver{kind: RTPCodecTypeVideo, api: api, codecs: me.videoCodecs}
mediaSections := []mediaSection{{id: "0", transceivers: []*RTPTransceiver{tr}}}
d := &sdp.SessionDescription{}
offerSdp, err := populateSDP(
d,
false,
[]DTLSFingerprint{},
se.sdpMediaLevelFingerprints,
se.candidates.ICELite,
true,
me,
connectionRoleFromDtlsRole(defaultDtlsRoleOffer),
[]ICECandidate{},
ICEParameters{},
mediaSections,
ICEGatheringStateComplete,
nil,
se.getSCTPMaxMessageSize(),
)
assert.Nil(t, err)
for _, desc := range offerSdp.MediaDescriptions {
for _, a := range desc.Attributes {
assert.False(t, strings.HasSuffix(a.String(), " "))
}
}
})
}
func TestGetRIDs(t *testing.T) {