match codecs from remote description, used when remote is offerer and creating a transceiver from remote description with the aim of keeping order of codecs in remote description.
(media *sdp.MediaDescription)
| 95 | // match codecs from remote description, used when remote is offerer and creating a transceiver |
| 96 | // from remote description with the aim of keeping order of codecs in remote description. |
| 97 | func (t *RTPTransceiver) setCodecPreferencesFromRemoteDescription(media *sdp.MediaDescription) { //nolint:cyclop |
| 98 | remoteCodecs, err := codecsFromMediaDescription(media) |
| 99 | if err != nil { |
| 100 | return |
| 101 | } |
| 102 | |
| 103 | // make a copy as this slice is modified |
| 104 | leftCodecs := append([]RTPCodecParameters{}, t.api.mediaEngine.getCodecsByKind(t.kind)...) |
| 105 | |
| 106 | // find codec matches between what is in remote description and |
| 107 | // the transceivers codecs and use payload type registered to |
| 108 | // media engine. |
| 109 | payloadMapping := make(map[PayloadType]PayloadType) // for RTX re-mapping later |
| 110 | filterByMatchType := func(matchFilter codecMatchType) []RTPCodecParameters { |
| 111 | filteredCodecs := []RTPCodecParameters{} |
| 112 | for remoteCodecIdx := len(remoteCodecs) - 1; remoteCodecIdx >= 0; remoteCodecIdx-- { |
| 113 | remoteCodec := remoteCodecs[remoteCodecIdx] |
| 114 | if strings.EqualFold(remoteCodec.RTPCodecCapability.MimeType, MimeTypeRTX) { |
| 115 | continue |
| 116 | } |
| 117 | |
| 118 | matchCodec, matchType := codecParametersFuzzySearch( |
| 119 | remoteCodec, |
| 120 | leftCodecs, |
| 121 | ) |
| 122 | if matchType == matchFilter { |
| 123 | payloadMapping[remoteCodec.PayloadType] = matchCodec.PayloadType |
| 124 | |
| 125 | remoteCodec.PayloadType = matchCodec.PayloadType |
| 126 | filteredCodecs = append([]RTPCodecParameters{remoteCodec}, filteredCodecs...) |
| 127 | |
| 128 | // removed matched codec for next round |
| 129 | remoteCodecs = append(remoteCodecs[:remoteCodecIdx], remoteCodecs[remoteCodecIdx+1:]...) |
| 130 | |
| 131 | needleFmtp := fmtp.Parse( |
| 132 | matchCodec.RTPCodecCapability.MimeType, |
| 133 | matchCodec.RTPCodecCapability.ClockRate, |
| 134 | matchCodec.RTPCodecCapability.Channels, |
| 135 | matchCodec.RTPCodecCapability.SDPFmtpLine, |
| 136 | ) |
| 137 | |
| 138 | for leftCodecIdx := len(leftCodecs) - 1; leftCodecIdx >= 0; leftCodecIdx-- { |
| 139 | leftCodec := leftCodecs[leftCodecIdx] |
| 140 | leftCodecFmtp := fmtp.Parse( |
| 141 | leftCodec.RTPCodecCapability.MimeType, |
| 142 | leftCodec.RTPCodecCapability.ClockRate, |
| 143 | leftCodec.RTPCodecCapability.Channels, |
| 144 | leftCodec.RTPCodecCapability.SDPFmtpLine, |
| 145 | ) |
| 146 | |
| 147 | if needleFmtp.Match(leftCodecFmtp) { |
| 148 | leftCodecs = append(leftCodecs[:leftCodecIdx], leftCodecs[leftCodecIdx+1:]...) |
| 149 | |
| 150 | break |
| 151 | } |
| 152 | } |
| 153 | } |
| 154 | } |
no test coverage detected