Look up a codec and enable if it exists. nolint:cyclop
( remoteCodec RTPCodecParameters, typ RTPCodecType, exactMatches, partialMatches []RTPCodecParameters, )
| 461 | // |
| 462 | //nolint:cyclop |
| 463 | func (m *MediaEngine) matchRemoteCodec( |
| 464 | remoteCodec RTPCodecParameters, |
| 465 | typ RTPCodecType, |
| 466 | exactMatches, partialMatches []RTPCodecParameters, |
| 467 | ) (RTPCodecParameters, codecMatchType, error) { |
| 468 | codecs := m.videoCodecs |
| 469 | if typ == RTPCodecTypeAudio { |
| 470 | codecs = m.audioCodecs |
| 471 | } |
| 472 | |
| 473 | remoteFmtp := fmtp.Parse( |
| 474 | remoteCodec.RTPCodecCapability.MimeType, |
| 475 | remoteCodec.RTPCodecCapability.ClockRate, |
| 476 | remoteCodec.RTPCodecCapability.Channels, |
| 477 | remoteCodec.RTPCodecCapability.SDPFmtpLine) |
| 478 | |
| 479 | if apt, hasApt := remoteFmtp.Parameter("apt"); hasApt { //nolint:nestif |
| 480 | payloadType, err := strconv.ParseUint(apt, 10, 8) |
| 481 | if err != nil { |
| 482 | return RTPCodecParameters{}, codecMatchNone, err |
| 483 | } |
| 484 | |
| 485 | aptMatch := codecMatchNone |
| 486 | var aptCodec RTPCodecParameters |
| 487 | for _, codec := range exactMatches { |
| 488 | if codec.PayloadType == PayloadType(payloadType) { |
| 489 | aptMatch = codecMatchExact |
| 490 | aptCodec = codec |
| 491 | |
| 492 | break |
| 493 | } |
| 494 | } |
| 495 | |
| 496 | if aptMatch == codecMatchNone { |
| 497 | for _, codec := range partialMatches { |
| 498 | if codec.PayloadType == PayloadType(payloadType) { |
| 499 | aptMatch = codecMatchPartial |
| 500 | aptCodec = codec |
| 501 | |
| 502 | break |
| 503 | } |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | if aptMatch == codecMatchNone { |
| 508 | return RTPCodecParameters{}, codecMatchNone, nil // not an error, we just ignore this codec we don't support |
| 509 | } |
| 510 | |
| 511 | // replace the apt value with the original codec's payload type |
| 512 | toMatchCodec := remoteCodec |
| 513 | if aptMatched, mt := codecParametersFuzzySearch(aptCodec, codecs); mt == aptMatch { |
| 514 | toMatchCodec.SDPFmtpLine = strings.Replace( |
| 515 | toMatchCodec.SDPFmtpLine, |
| 516 | fmt.Sprintf("apt=%d", payloadType), |
| 517 | fmt.Sprintf("apt=%d", aptMatched.PayloadType), |
| 518 | 1, |
| 519 | ) |
| 520 | } |
no test coverage detected