diff --git a/mediaengine.go b/mediaengine.go index f2fb4d67b6d..1d4cefa46bb 100644 --- a/mediaengine.go +++ b/mediaengine.go @@ -1,3 +1,4 @@ +//go:build !js // +build !js package webrtc @@ -534,6 +535,19 @@ func (m *MediaEngine) getCodecsByKind(typ RTPCodecType) []RTPCodecParameters { return nil } +func (m *MediaEngine) getLocalCodecsByKind(typ RTPCodecType) []RTPCodecParameters { + m.mu.RLock() + defer m.mu.RUnlock() + + if typ == RTPCodecTypeVideo { + return m.videoCodecs + } else if typ == RTPCodecTypeAudio { + return m.audioCodecs + } + + return nil +} + func (m *MediaEngine) getRTPParametersByKind(typ RTPCodecType, directions []RTPTransceiverDirection) RTPParameters { m.mu.RLock() defer m.mu.RUnlock() diff --git a/sdp.go b/sdp.go index 54249e354aa..d0e030d5d9b 100644 --- a/sdp.go +++ b/sdp.go @@ -1,3 +1,4 @@ +//go:build !js // +build !js package webrtc @@ -326,13 +327,19 @@ func addTransceiverSDP(d *sdp.SessionDescription, isPlanB, shouldAddCandidates b WithPropertyAttribute(sdp.AttrKeyRTCPMux). WithPropertyAttribute(sdp.AttrKeyRTCPRsize) + localCodecs := mediaEngine.getLocalCodecsByKind(t.Kind()) codecs := t.getCodecs() for _, codec := range codecs { name := strings.TrimPrefix(codec.MimeType, "audio/") name = strings.TrimPrefix(name, "video/") media.WithCodec(uint8(codec.PayloadType), name, codec.ClockRate, codec.Channels, codec.SDPFmtpLine) - for _, feedback := range codec.RTPCodecCapability.RTCPFeedback { + rtcpFeedback := codec.RTPCodecCapability.RTCPFeedback + if c, matchType := codecParametersFuzzySearch(codec, localCodecs); matchType != codecMatchNone { + rtcpFeedback = c.RTCPFeedback + } + + for _, feedback := range rtcpFeedback { media.WithValueAttribute("rtcp-fb", fmt.Sprintf("%d %s %s", codec.PayloadType, feedback.Type, feedback.Parameter)) } }