webrtc Codec生成相關

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<VideoCodec>& input_codecs,
                              std::vector<VideoCodec>* unified_codecs) {
  for (VideoCodec codec : input_codecs) {
    const rtc::Optional<int> 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<int> rtx_payload_type =
          NextFreePayloadType(*unified_codecs);
      if (!rtx_payload_type)
        return;
      unified_codecs->push_back(
          VideoCodec::CreateRtxCodec(*rtx_payload_type, codec.id));
    }
  }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章