1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
/*
* Copyright 2017 The WebRTC project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#include "pc/rtp_parameters_conversion.h"
#include <optional>
#include <string>
#include <vector>
#include "api/media_types.h"
#include "api/rtp_parameters.h"
#include "media/base/codec.h"
#include "media/base/media_constants.h"
#include "pc/session_description.h"
#include "rtc_base/logging.h"
namespace webrtc {
std::optional<RtcpFeedback> ToRtcpFeedback(
const FeedbackParam& cricket_feedback) {
if (cricket_feedback.id() == kRtcpFbParamCcm) {
if (cricket_feedback.param() == kRtcpFbCcmParamFir) {
return RtcpFeedback(RtcpFeedbackType::CCM, RtcpFeedbackMessageType::FIR);
} else {
RTC_LOG(LS_WARNING) << "Unsupported parameter for CCM RTCP feedback: "
<< cricket_feedback.param();
return std::nullopt;
}
} else if (cricket_feedback.id() == kRtcpFbParamLntf) {
if (cricket_feedback.param().empty()) {
return RtcpFeedback(RtcpFeedbackType::LNTF);
} else {
RTC_LOG(LS_WARNING) << "Unsupported parameter for LNTF RTCP feedback: "
<< cricket_feedback.param();
return std::nullopt;
}
} else if (cricket_feedback.id() == kRtcpFbParamNack) {
if (cricket_feedback.param().empty()) {
return RtcpFeedback(RtcpFeedbackType::NACK,
RtcpFeedbackMessageType::GENERIC_NACK);
} else if (cricket_feedback.param() == kRtcpFbNackParamPli) {
return RtcpFeedback(RtcpFeedbackType::NACK, RtcpFeedbackMessageType::PLI);
} else {
RTC_LOG(LS_WARNING) << "Unsupported parameter for NACK RTCP feedback: "
<< cricket_feedback.param();
return std::nullopt;
}
} else if (cricket_feedback.id() == kRtcpFbParamRemb) {
if (!cricket_feedback.param().empty()) {
RTC_LOG(LS_WARNING) << "Unsupported parameter for REMB RTCP feedback: "
<< cricket_feedback.param();
return std::nullopt;
} else {
return RtcpFeedback(RtcpFeedbackType::REMB);
}
} else if (cricket_feedback.id() == kRtcpFbParamTransportCc) {
if (!cricket_feedback.param().empty()) {
RTC_LOG(LS_WARNING)
<< "Unsupported parameter for transport-cc RTCP feedback: "
<< cricket_feedback.param();
return std::nullopt;
} else {
return RtcpFeedback(RtcpFeedbackType::TRANSPORT_CC);
}
}
RTC_LOG(LS_WARNING) << "Unsupported RTCP feedback type: "
<< cricket_feedback.id();
return std::nullopt;
}
RtpCodecCapability ToRtpCodecCapability(const Codec& cricket_codec) {
RtpCodecCapability codec;
codec.name = cricket_codec.name;
codec.kind = cricket_codec.type == Codec::Type::kAudio ? MediaType::AUDIO
: MediaType::VIDEO;
codec.clock_rate.emplace(cricket_codec.clockrate);
codec.preferred_payload_type.emplace(cricket_codec.id);
for (const FeedbackParam& cricket_feedback :
cricket_codec.feedback_params.params()) {
std::optional<RtcpFeedback> feedback = ToRtcpFeedback(cricket_feedback);
if (feedback) {
codec.rtcp_feedback.push_back(feedback.value());
}
}
switch (cricket_codec.type) {
case Codec::Type::kAudio:
codec.num_channels = static_cast<int>(cricket_codec.channels);
break;
case Codec::Type::kVideo:
codec.scalability_modes = cricket_codec.scalability_modes;
break;
}
codec.parameters.insert(cricket_codec.params.begin(),
cricket_codec.params.end());
return codec;
}
RtpCapabilities ToRtpCapabilities(
const std::vector<Codec>& cricket_codecs,
const RtpHeaderExtensions& cricket_extensions) {
RtpCapabilities capabilities;
bool have_red = false;
bool have_ulpfec = false;
bool have_flexfec = false;
bool have_rtx = false;
for (const Codec& cricket_codec : cricket_codecs) {
if (cricket_codec.name == kRedCodecName) {
if (have_red) {
// There should only be one RED codec entry in caps.
continue;
}
have_red = true;
} else if (cricket_codec.name == kUlpfecCodecName) {
have_ulpfec = true;
} else if (cricket_codec.name == kFlexfecCodecName) {
have_flexfec = true;
} else if (cricket_codec.name == kRtxCodecName) {
if (have_rtx) {
// There should only be one RTX codec entry in caps.
continue;
}
have_rtx = true;
}
auto codec_capability = ToRtpCodecCapability(cricket_codec);
if (cricket_codec.name == kRtxCodecName ||
cricket_codec.name == kRedCodecName) {
// For RTX this removes the APT which points to a payload type.
// For RED this removes the redundancy spec which points to a payload
// type.
codec_capability.parameters.clear();
}
capabilities.codecs.push_back(codec_capability);
}
for (const RtpExtension& cricket_extension : cricket_extensions) {
capabilities.header_extensions.emplace_back(cricket_extension.uri,
cricket_extension.id);
}
if (have_red) {
capabilities.fec.push_back(FecMechanism::RED);
}
if (have_red && have_ulpfec) {
capabilities.fec.push_back(FecMechanism::RED_AND_ULPFEC);
}
if (have_flexfec) {
capabilities.fec.push_back(FecMechanism::FLEXFEC);
}
return capabilities;
}
} // namespace webrtc
|