rtc: parse each remote offer once per negotiation (#4904)

This commit is contained in:
Raja Subramanian
2026-09-25 05:01:30 +05:30
committed by GitHub
parent 6b2e3ece69
commit f52b0e2bd5
7 changed files with 235 additions and 60 deletions
+12 -6
View File
@@ -319,9 +319,8 @@ func (p *ParticipantImpl) setCodecPreferencesOpusRedForPublisher(
// configure publisher answer for audio track's dtx and stereo settings
func (p *ParticipantImpl) configurePublisherAnswer(answer webrtc.SessionDescription) webrtc.SessionDescription {
offer := p.TransportManager.LastPublisherOffer()
parsedOffer, err := offer.Unmarshal()
if err != nil {
parsedOffer := p.TransportManager.LastPublisherOfferParsed()
if parsedOffer == nil {
return answer
}
@@ -330,6 +329,9 @@ func (p *ParticipantImpl) configurePublisherAnswer(answer webrtc.SessionDescript
return answer
}
// payload type lookup scans the whole answer, resolve it once
opusPT, opusPTErr := parsedAnswer.GetPayloadTypeForCodec(sdp.Codec{Name: mime.MimeTypeCodecOpus.String()})
changed := false
for _, m := range parsedAnswer.MediaDescriptions {
switch m.MediaName.Media {
case "audio":
@@ -371,9 +373,8 @@ func (p *ParticipantImpl) configurePublisherAnswer(answer webrtc.SessionDescript
continue
}
opusPT, err := parsedAnswer.GetPayloadTypeForCodec(sdp.Codec{Name: mime.MimeTypeCodecOpus.String()})
if err != nil {
p.pubLogger.Infow("failed to get opus payload type", "error", err, "trackID", ti.Sid)
if opusPTErr != nil {
p.pubLogger.Infow("failed to get opus payload type", "error", opusPTErr, "trackID", ti.Sid)
continue
}
@@ -390,6 +391,7 @@ func (p *ParticipantImpl) configurePublisherAnswer(answer webrtc.SessionDescript
attr.Value = strings.ReplaceAll(attr.Value, ";stereo=1", "")
}
m.Attributes[i] = attr
changed = true
}
}
@@ -398,6 +400,10 @@ func (p *ParticipantImpl) configurePublisherAnswer(answer webrtc.SessionDescript
}
}
if !changed {
return answer
}
bytes, err := parsedAnswer.Marshal()
if err != nil {
p.pubLogger.Infow("failed to marshal answer", "error", err)