1. sdp video codec生成
InternalEncoderFactory::InternalEncoderFactory() { supported_codecs_.push_back(cricket::VideoCodec(kVp8CodecName)); if (webrtc::VP9Encoder::IsSupported()) supported_codecs_.push_back(cricket::VideoCodec(kVp9CodecName)); if (webrtc::H264Encoder::IsSupported()) { cricket::VideoCodec codec(kH264CodecName); // TODO(magjed): Move setting these parameters into webrtc::H264Encoder // instead. codec.SetParam(kH264FmtpProfileLevelId, kH264ProfileLevelConstrainedBaseline); codec.SetParam(kH264FmtpLevelAsymmetryAllowed, "1"); supported_codecs_.push_back(std::move(codec)); } supported_codecs_.push_back(cricket::VideoCodec(kRedCodecName)); supported_codecs_.push_back(cricket::VideoCodec(kUlpfecCodecName)); if (IsFlexfecAdvertisedFieldTrialEnabled()) { cricket::VideoCodec flexfec_codec(kFlexfecCodecName); // This value is currently arbitrarily set to 10 seconds. (The unit // is microseconds.) This parameter MUST be present in the SDP, but // we never use the actual value anywhere in our code however. // TODO(brandtr): Consider honouring this value in the sender and receiver. flexfec_codec.SetParam(kFlexfecFmtpRepairWindow, "10000000"); flexfec_codec.AddFeedbackParam( FeedbackParam(kRtcpFbParamTransportCc, kParamValueEmpty)); flexfec_codec.AddFeedbackParam( FeedbackParam(kRtcpFbParamRemb, kParamValueEmpty)); supported_codecs_.push_back(flexfec_codec); }}
以上是生成sdp中支持的codec,除此之外还会生成rtx codec,创建的函数为CreateRtxCode,代码如下:
static void AppendVideoCodecs(const std::vector& input_codecs, std::vector * unified_codecs) { for (VideoCodec codec : input_codecs) { const rtc::Optional payload_type = NextFreePayloadType(*unified_codecs, codec.name); if (!payload_type) return; codec.id = *payload_type; // TODO(magjed): Move the responsibility of setting these parameters to the // encoder factories instead. if (codec.name != kRedCodecName && codec.name != kUlpfecCodecName && codec.name != kFlexfecCodecName) AddDefaultFeedbackParams(&codec); // Don't add same codec twice. if (FindMatchingCodec(*unified_codecs, codec)) continue; unified_codecs->push_back(codec); // Add associated RTX codec for recognized codecs. // TODO(deadbeef): Should we add RTX codecs for external codecs whose names // we don't recognize? if (CodecNamesEq(codec.name, kVp8CodecName) || CodecNamesEq(codec.name, kVp9CodecName) || CodecNamesEq(codec.name, kH264CodecName) || CodecNamesEq(codec.name, kRedCodecName)) { const rtc::Optional rtx_payload_type = NextFreePayloadType(*unified_codecs); if (!rtx_payload_type) return; unified_codecs->push_back( VideoCodec::CreateRtxCodec(*rtx_payload_type, codec.id)); } }}