Clear stereo=1 if stereo is not enabled. (#4101)

This commit is contained in:
Raja Subramanian
2025-11-24 21:31:56 +05:30
committed by GitHub
parent 70f6def39d
commit 402936324c
+10 -6
View File
@@ -325,12 +325,12 @@ func (p *ParticipantImpl) configurePublisherAnswer(answer webrtc.SessionDescript
return answer return answer
} }
parsed, err := answer.Unmarshal() parsedAnswer, err := answer.Unmarshal()
if err != nil { if err != nil {
return answer return answer
} }
for _, m := range parsed.MediaDescriptions { for _, m := range parsedAnswer.MediaDescriptions {
switch m.MediaName.Media { switch m.MediaName.Media {
case "audio": case "audio":
_, ok := m.Attribute(sdp.AttrKeyInactive) _, ok := m.Attribute(sdp.AttrKeyInactive)
@@ -366,12 +366,12 @@ func (p *ParticipantImpl) configurePublisherAnswer(answer webrtc.SessionDescript
} }
} }
if ti == nil || (ti.DisableDtx && !slices.Contains(ti.AudioFeatures, livekit.AudioTrackFeature_TF_STEREO)) { if ti == nil {
// no need to configure // no need to configure
continue continue
} }
opusPT, err := parsed.GetPayloadTypeForCodec(sdp.Codec{Name: mime.MimeTypeCodecOpus.String()}) opusPT, err := parsedAnswer.GetPayloadTypeForCodec(sdp.Codec{Name: mime.MimeTypeCodecOpus.String()})
if err != nil { if err != nil {
p.pubLogger.Infow("failed to get opus payload type", "error", err, "trackID", ti.Sid) p.pubLogger.Infow("failed to get opus payload type", "error", err, "trackID", ti.Sid)
continue continue
@@ -379,11 +379,15 @@ func (p *ParticipantImpl) configurePublisherAnswer(answer webrtc.SessionDescript
for i, attr := range m.Attributes { for i, attr := range m.Attributes {
if strings.HasPrefix(attr.String(), fmt.Sprintf("fmtp:%d", opusPT)) { if strings.HasPrefix(attr.String(), fmt.Sprintf("fmtp:%d", opusPT)) {
if !ti.DisableDtx { if !slices.Contains(ti.AudioFeatures, livekit.AudioTrackFeature_TF_NO_DTX) {
attr.Value += ";usedtx=1" attr.Value += ";usedtx=1"
} else {
attr.Value = strings.ReplaceAll(attr.Value, ";usedtx=1", "")
} }
if slices.Contains(ti.AudioFeatures, livekit.AudioTrackFeature_TF_STEREO) { if slices.Contains(ti.AudioFeatures, livekit.AudioTrackFeature_TF_STEREO) {
attr.Value += ";stereo=1;maxaveragebitrate=510000" attr.Value += ";stereo=1;maxaveragebitrate=510000"
} else {
attr.Value = strings.ReplaceAll(attr.Value, ";stereo=1", "")
} }
m.Attributes[i] = attr m.Attributes[i] = attr
} }
@@ -394,7 +398,7 @@ func (p *ParticipantImpl) configurePublisherAnswer(answer webrtc.SessionDescript
} }
} }
bytes, err := parsed.Marshal() bytes, err := parsedAnswer.Marshal()
if err != nil { if err != nil {
p.pubLogger.Infow("failed to marshal answer", "error", err) p.pubLogger.Infow("failed to marshal answer", "error", err)
return answer return answer