| 26 | ) |
| 27 | |
| 28 | func registerCodecs(me *webrtc.MediaEngine, codecs []*livekit.Codec, rtcpFeedback RTCPFeedbackConfig, filterOutH264HighProfile bool) error { |
| 29 | // audio codecs |
| 30 | if IsCodecEnabled(codecs, protoCodecs.OpusCodecParameters.RTPCodecCapability) { |
| 31 | cp := protoCodecs.OpusCodecParameters |
| 32 | cp.RTPCodecCapability.RTCPFeedback = rtcpFeedback.Audio |
| 33 | if err := me.RegisterCodec(cp, webrtc.RTPCodecTypeAudio); err != nil { |
| 34 | return err |
| 35 | } |
| 36 | |
| 37 | if IsCodecEnabled(codecs, protoCodecs.RedCodecParameters.RTPCodecCapability) { |
| 38 | if err := me.RegisterCodec(protoCodecs.RedCodecParameters, webrtc.RTPCodecTypeAudio); err != nil { |
| 39 | return err |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | for _, codec := range []webrtc.RTPCodecParameters{protoCodecs.PCMUCodecParameters, protoCodecs.PCMACodecParameters} { |
| 45 | if !IsCodecEnabled(codecs, codec.RTPCodecCapability) { |
| 46 | continue |
| 47 | } |
| 48 | |
| 49 | cp := codec |
| 50 | cp.RTPCodecCapability.RTCPFeedback = rtcpFeedback.Audio |
| 51 | if err := me.RegisterCodec(cp, webrtc.RTPCodecTypeAudio); err != nil { |
| 52 | return err |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | // video codecs |
| 57 | rtxEnabled := IsCodecEnabled(codecs, protoCodecs.VideoRTXCodecParameters.RTPCodecCapability) |
| 58 | for _, codec := range protoCodecs.VideoCodecsParameters { |
| 59 | if filterOutH264HighProfile && codec.RTPCodecCapability.SDPFmtpLine == protoCodecs.H264HighProfileFmtp { |
| 60 | continue |
| 61 | } |
| 62 | if mime.IsMimeTypeStringRTX(codec.MimeType) { |
| 63 | continue |
| 64 | } |
| 65 | if !IsCodecEnabled(codecs, codec.RTPCodecCapability) { |
| 66 | continue |
| 67 | } |
| 68 | |
| 69 | cp := codec |
| 70 | cp.RTPCodecCapability.RTCPFeedback = rtcpFeedback.Video |
| 71 | if err := me.RegisterCodec(cp, webrtc.RTPCodecTypeVideo); err != nil { |
| 72 | return err |
| 73 | } |
| 74 | |
| 75 | if !rtxEnabled { |
| 76 | continue |
| 77 | } |
| 78 | |
| 79 | cp = protoCodecs.VideoRTXCodecParameters |
| 80 | cp.RTPCodecCapability.SDPFmtpLine = fmt.Sprintf("apt=%d", codec.PayloadType) |
| 81 | cp.PayloadType = codec.PayloadType + 1 |
| 82 | if err := me.RegisterCodec(cp, webrtc.RTPCodecTypeVideo); err != nil { |
| 83 | return err |
| 84 | } |
| 85 | } |