henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 1 | /* |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 2 | * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 3 | * |
kjellander | 1afca73 | 2016-02-07 20:46:45 -0800 | [diff] [blame] | 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #include "media/base/codec.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 12 | |
| 13 | #include <algorithm> |
| 14 | #include <sstream> |
| 15 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 16 | #include "media/base/h264_profile_level_id.h" |
| 17 | #include "rtc_base/checks.h" |
| 18 | #include "rtc_base/logging.h" |
| 19 | #include "rtc_base/stringencode.h" |
| 20 | #include "rtc_base/stringutils.h" |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 21 | |
| 22 | namespace cricket { |
| 23 | |
Magnus Jedvert | 244ad80 | 2017-09-28 21:19:18 +0200 | [diff] [blame] | 24 | FeedbackParams::FeedbackParams() = default; |
| 25 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 26 | bool FeedbackParam::operator==(const FeedbackParam& other) const { |
| 27 | return _stricmp(other.id().c_str(), id().c_str()) == 0 && |
| 28 | _stricmp(other.param().c_str(), param().c_str()) == 0; |
| 29 | } |
| 30 | |
| 31 | bool FeedbackParams::operator==(const FeedbackParams& other) const { |
| 32 | return params_ == other.params_; |
| 33 | } |
| 34 | |
| 35 | bool FeedbackParams::Has(const FeedbackParam& param) const { |
| 36 | return std::find(params_.begin(), params_.end(), param) != params_.end(); |
| 37 | } |
| 38 | |
| 39 | void FeedbackParams::Add(const FeedbackParam& param) { |
| 40 | if (param.id().empty()) { |
| 41 | return; |
| 42 | } |
| 43 | if (Has(param)) { |
| 44 | // Param already in |this|. |
| 45 | return; |
| 46 | } |
| 47 | params_.push_back(param); |
magjed | 0928a3c | 2016-11-25 00:40:18 -0800 | [diff] [blame] | 48 | RTC_CHECK(!HasDuplicateEntries()); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | void FeedbackParams::Intersect(const FeedbackParams& from) { |
| 52 | std::vector<FeedbackParam>::iterator iter_to = params_.begin(); |
| 53 | while (iter_to != params_.end()) { |
| 54 | if (!from.Has(*iter_to)) { |
| 55 | iter_to = params_.erase(iter_to); |
| 56 | } else { |
| 57 | ++iter_to; |
| 58 | } |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | bool FeedbackParams::HasDuplicateEntries() const { |
| 63 | for (std::vector<FeedbackParam>::const_iterator iter = params_.begin(); |
| 64 | iter != params_.end(); ++iter) { |
| 65 | for (std::vector<FeedbackParam>::const_iterator found = iter + 1; |
| 66 | found != params_.end(); ++found) { |
| 67 | if (*found == *iter) { |
| 68 | return true; |
| 69 | } |
| 70 | } |
| 71 | } |
| 72 | return false; |
| 73 | } |
| 74 | |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 75 | Codec::Codec(int id, const std::string& name, int clockrate) |
| 76 | : id(id), name(name), clockrate(clockrate) {} |
guoweis@webrtc.org | bc6961f | 2015-02-19 17:55:18 +0000 | [diff] [blame] | 77 | |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 78 | Codec::Codec() : id(0), clockrate(0) {} |
guoweis@webrtc.org | bc6961f | 2015-02-19 17:55:18 +0000 | [diff] [blame] | 79 | |
| 80 | Codec::Codec(const Codec& c) = default; |
magjed | 3663c52 | 2016-11-07 10:14:36 -0800 | [diff] [blame] | 81 | Codec::Codec(Codec&& c) = default; |
guoweis@webrtc.org | bc6961f | 2015-02-19 17:55:18 +0000 | [diff] [blame] | 82 | Codec::~Codec() = default; |
magjed | 3663c52 | 2016-11-07 10:14:36 -0800 | [diff] [blame] | 83 | Codec& Codec::operator=(const Codec& c) = default; |
| 84 | Codec& Codec::operator=(Codec&& c) = default; |
guoweis@webrtc.org | bc6961f | 2015-02-19 17:55:18 +0000 | [diff] [blame] | 85 | |
| 86 | bool Codec::operator==(const Codec& c) const { |
| 87 | return this->id == c.id && // id is reserved in objective-c |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 88 | name == c.name && clockrate == c.clockrate && params == c.params && |
guoweis@webrtc.org | bc6961f | 2015-02-19 17:55:18 +0000 | [diff] [blame] | 89 | feedback_params == c.feedback_params; |
| 90 | } |
| 91 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 92 | bool Codec::Matches(const Codec& codec) const { |
| 93 | // Match the codec id/name based on the typical static/dynamic name rules. |
| 94 | // Matching is case-insensitive. |
pkasting@chromium.org | d324546 | 2015-02-23 21:28:22 +0000 | [diff] [blame] | 95 | const int kMaxStaticPayloadId = 95; |
magjed | 3663c52 | 2016-11-07 10:14:36 -0800 | [diff] [blame] | 96 | return (id <= kMaxStaticPayloadId || codec.id <= kMaxStaticPayloadId) |
| 97 | ? (id == codec.id) |
| 98 | : (_stricmp(name.c_str(), codec.name.c_str()) == 0); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | bool Codec::GetParam(const std::string& name, std::string* out) const { |
| 102 | CodecParameterMap::const_iterator iter = params.find(name); |
| 103 | if (iter == params.end()) |
| 104 | return false; |
| 105 | *out = iter->second; |
| 106 | return true; |
| 107 | } |
| 108 | |
| 109 | bool Codec::GetParam(const std::string& name, int* out) const { |
| 110 | CodecParameterMap::const_iterator iter = params.find(name); |
| 111 | if (iter == params.end()) |
| 112 | return false; |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 113 | return rtc::FromString(iter->second, out); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | void Codec::SetParam(const std::string& name, const std::string& value) { |
| 117 | params[name] = value; |
| 118 | } |
| 119 | |
| 120 | void Codec::SetParam(const std::string& name, int value) { |
buildbot@webrtc.org | d4e598d | 2014-07-29 17:36:52 +0000 | [diff] [blame] | 121 | params[name] = rtc::ToString(value); |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 122 | } |
| 123 | |
buildbot@webrtc.org | fbd1328 | 2014-06-19 19:50:55 +0000 | [diff] [blame] | 124 | bool Codec::RemoveParam(const std::string& name) { |
| 125 | return params.erase(name) == 1; |
| 126 | } |
| 127 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 128 | void Codec::AddFeedbackParam(const FeedbackParam& param) { |
| 129 | feedback_params.Add(param); |
| 130 | } |
| 131 | |
| 132 | bool Codec::HasFeedbackParam(const FeedbackParam& param) const { |
| 133 | return feedback_params.Has(param); |
| 134 | } |
| 135 | |
| 136 | void Codec::IntersectFeedbackParams(const Codec& other) { |
| 137 | feedback_params.Intersect(other.feedback_params); |
| 138 | } |
| 139 | |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 140 | webrtc::RtpCodecParameters Codec::ToCodecParameters() const { |
| 141 | webrtc::RtpCodecParameters codec_params; |
| 142 | codec_params.payload_type = id; |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 143 | codec_params.name = name; |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 144 | codec_params.clock_rate = clockrate; |
Taylor Brandstetter | 0cd086b | 2016-04-20 16:23:10 -0700 | [diff] [blame] | 145 | return codec_params; |
| 146 | } |
| 147 | |
pkasting | 25702cb | 2016-01-08 13:50:27 -0800 | [diff] [blame] | 148 | AudioCodec::AudioCodec(int id, |
| 149 | const std::string& name, |
| 150 | int clockrate, |
| 151 | int bitrate, |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 152 | size_t channels) |
| 153 | : Codec(id, name, clockrate), bitrate(bitrate), channels(channels) {} |
guoweis@webrtc.org | bc6961f | 2015-02-19 17:55:18 +0000 | [diff] [blame] | 154 | |
guoweis@webrtc.org | cce874b | 2015-02-19 18:14:36 +0000 | [diff] [blame] | 155 | AudioCodec::AudioCodec() : Codec(), bitrate(0), channels(0) { |
guoweis@webrtc.org | bc6961f | 2015-02-19 17:55:18 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | AudioCodec::AudioCodec(const AudioCodec& c) = default; |
magjed | 3663c52 | 2016-11-07 10:14:36 -0800 | [diff] [blame] | 159 | AudioCodec::AudioCodec(AudioCodec&& c) = default; |
| 160 | AudioCodec& AudioCodec::operator=(const AudioCodec& c) = default; |
| 161 | AudioCodec& AudioCodec::operator=(AudioCodec&& c) = default; |
guoweis@webrtc.org | bc6961f | 2015-02-19 17:55:18 +0000 | [diff] [blame] | 162 | |
| 163 | bool AudioCodec::operator==(const AudioCodec& c) const { |
guoweis@webrtc.org | cce874b | 2015-02-19 18:14:36 +0000 | [diff] [blame] | 164 | return bitrate == c.bitrate && channels == c.channels && Codec::operator==(c); |
guoweis@webrtc.org | bc6961f | 2015-02-19 17:55:18 +0000 | [diff] [blame] | 165 | } |
| 166 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 167 | bool AudioCodec::Matches(const AudioCodec& codec) const { |
| 168 | // If a nonzero clockrate is specified, it must match the actual clockrate. |
| 169 | // If a nonzero bitrate is specified, it must match the actual bitrate, |
| 170 | // unless the codec is VBR (0), where we just force the supplied value. |
| 171 | // The number of channels must match exactly, with the exception |
| 172 | // that channels=0 is treated synonymously as channels=1, per RFC |
| 173 | // 4566 section 6: " [The channels] parameter is OPTIONAL and may be |
| 174 | // omitted if the number of channels is one." |
| 175 | // Preference is ignored. |
| 176 | // TODO(juberti): Treat a zero clockrate as 8000Hz, the RTP default clockrate. |
| 177 | return Codec::Matches(codec) && |
| 178 | ((codec.clockrate == 0 /*&& clockrate == 8000*/) || |
| 179 | clockrate == codec.clockrate) && |
| 180 | (codec.bitrate == 0 || bitrate <= 0 || bitrate == codec.bitrate) && |
| 181 | ((codec.channels < 2 && channels < 2) || channels == codec.channels); |
| 182 | } |
| 183 | |
| 184 | std::string AudioCodec::ToString() const { |
| 185 | std::ostringstream os; |
| 186 | os << "AudioCodec[" << id << ":" << name << ":" << clockrate << ":" << bitrate |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 187 | << ":" << channels << "]"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 188 | return os.str(); |
| 189 | } |
| 190 | |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 191 | webrtc::RtpCodecParameters AudioCodec::ToCodecParameters() const { |
| 192 | webrtc::RtpCodecParameters codec_params = Codec::ToCodecParameters(); |
Oskar Sundbom | 7880758 | 2017-11-16 11:09:55 +0100 | [diff] [blame] | 193 | codec_params.num_channels = static_cast<int>(channels); |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 194 | codec_params.kind = MEDIA_TYPE_AUDIO; |
| 195 | return codec_params; |
| 196 | } |
| 197 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 198 | std::string VideoCodec::ToString() const { |
| 199 | std::ostringstream os; |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 200 | os << "VideoCodec[" << id << ":" << name << "]"; |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 201 | return os.str(); |
| 202 | } |
| 203 | |
deadbeef | e702b30 | 2017-02-04 12:09:01 -0800 | [diff] [blame] | 204 | webrtc::RtpCodecParameters VideoCodec::ToCodecParameters() const { |
| 205 | webrtc::RtpCodecParameters codec_params = Codec::ToCodecParameters(); |
| 206 | codec_params.kind = MEDIA_TYPE_VIDEO; |
| 207 | return codec_params; |
| 208 | } |
| 209 | |
pkasting | 25702cb | 2016-01-08 13:50:27 -0800 | [diff] [blame] | 210 | VideoCodec::VideoCodec(int id, const std::string& name) |
hta | 9aa9688 | 2016-12-06 05:36:03 -0800 | [diff] [blame] | 211 | : Codec(id, name, kVideoCodecClockrate) { |
| 212 | SetDefaultParameters(); |
| 213 | } |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 214 | |
hta | 9aa9688 | 2016-12-06 05:36:03 -0800 | [diff] [blame] | 215 | VideoCodec::VideoCodec(const std::string& name) : VideoCodec(0 /* id */, name) { |
| 216 | SetDefaultParameters(); |
| 217 | } |
magjed | 1e45cc6 | 2016-10-28 07:43:45 -0700 | [diff] [blame] | 218 | |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 219 | VideoCodec::VideoCodec() : Codec() { |
guoweis@webrtc.org | bc6961f | 2015-02-19 17:55:18 +0000 | [diff] [blame] | 220 | clockrate = kVideoCodecClockrate; |
| 221 | } |
| 222 | |
Magnus Jedvert | 024d897 | 2017-09-29 15:00:29 +0200 | [diff] [blame] | 223 | VideoCodec::VideoCodec(const webrtc::SdpVideoFormat& c) |
| 224 | : Codec(0 /* id */, c.name, kVideoCodecClockrate) { |
| 225 | params = c.parameters; |
| 226 | } |
| 227 | |
guoweis@webrtc.org | bc6961f | 2015-02-19 17:55:18 +0000 | [diff] [blame] | 228 | VideoCodec::VideoCodec(const VideoCodec& c) = default; |
magjed | 3663c52 | 2016-11-07 10:14:36 -0800 | [diff] [blame] | 229 | VideoCodec::VideoCodec(VideoCodec&& c) = default; |
| 230 | VideoCodec& VideoCodec::operator=(const VideoCodec& c) = default; |
| 231 | VideoCodec& VideoCodec::operator=(VideoCodec&& c) = default; |
guoweis@webrtc.org | bc6961f | 2015-02-19 17:55:18 +0000 | [diff] [blame] | 232 | |
hta | 9aa9688 | 2016-12-06 05:36:03 -0800 | [diff] [blame] | 233 | void VideoCodec::SetDefaultParameters() { |
| 234 | if (_stricmp(kH264CodecName, name.c_str()) == 0) { |
| 235 | // This default is set for all H.264 codecs created because |
| 236 | // that was the default before packetization mode support was added. |
| 237 | // TODO(hta): Move this to the places that create VideoCodecs from |
| 238 | // SDP or from knowledge of implementation capabilities. |
| 239 | SetParam(kH264FmtpPacketizationMode, "1"); |
| 240 | } |
| 241 | } |
| 242 | |
guoweis@webrtc.org | bc6961f | 2015-02-19 17:55:18 +0000 | [diff] [blame] | 243 | bool VideoCodec::operator==(const VideoCodec& c) const { |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 244 | return Codec::operator==(c); |
guoweis@webrtc.org | bc6961f | 2015-02-19 17:55:18 +0000 | [diff] [blame] | 245 | } |
| 246 | |
magjed | f823ede | 2016-11-12 09:53:04 -0800 | [diff] [blame] | 247 | bool VideoCodec::Matches(const VideoCodec& other) const { |
| 248 | if (!Codec::Matches(other)) |
| 249 | return false; |
| 250 | if (CodecNamesEq(name.c_str(), kH264CodecName)) |
Magnus Jedvert | 523589d | 2017-11-23 13:24:53 +0100 | [diff] [blame^] | 251 | return webrtc::H264::IsSameH264Profile(params, other.params); |
magjed | f823ede | 2016-11-12 09:53:04 -0800 | [diff] [blame] | 252 | return true; |
| 253 | } |
| 254 | |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 255 | VideoCodec VideoCodec::CreateRtxCodec(int rtx_payload_type, |
| 256 | int associated_payload_type) { |
perkj | 2675274 | 2016-10-24 01:21:16 -0700 | [diff] [blame] | 257 | VideoCodec rtx_codec(rtx_payload_type, kRtxCodecName); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 258 | rtx_codec.SetParam(kCodecParamAssociatedPayloadType, associated_payload_type); |
| 259 | return rtx_codec; |
| 260 | } |
| 261 | |
| 262 | VideoCodec::CodecType VideoCodec::GetCodecType() const { |
| 263 | const char* payload_name = name.c_str(); |
| 264 | if (_stricmp(payload_name, kRedCodecName) == 0) { |
| 265 | return CODEC_RED; |
| 266 | } |
| 267 | if (_stricmp(payload_name, kUlpfecCodecName) == 0) { |
| 268 | return CODEC_ULPFEC; |
| 269 | } |
brandtr | 87d7d77 | 2016-11-07 03:03:41 -0800 | [diff] [blame] | 270 | if (_stricmp(payload_name, kFlexfecCodecName) == 0) { |
| 271 | return CODEC_FLEXFEC; |
| 272 | } |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 273 | if (_stricmp(payload_name, kRtxCodecName) == 0) { |
| 274 | return CODEC_RTX; |
| 275 | } |
| 276 | |
| 277 | return CODEC_VIDEO; |
| 278 | } |
| 279 | |
| 280 | bool VideoCodec::ValidateCodecFormat() const { |
| 281 | if (id < 0 || id > 127) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 282 | RTC_LOG(LS_ERROR) << "Codec with invalid payload type: " << ToString(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 283 | return false; |
| 284 | } |
| 285 | if (GetCodecType() != CODEC_VIDEO) { |
| 286 | return true; |
| 287 | } |
| 288 | |
| 289 | // Video validation from here on. |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 290 | int min_bitrate = -1; |
| 291 | int max_bitrate = -1; |
| 292 | if (GetParam(kCodecParamMinBitrate, &min_bitrate) && |
| 293 | GetParam(kCodecParamMaxBitrate, &max_bitrate)) { |
| 294 | if (max_bitrate < min_bitrate) { |
Mirko Bonadei | 675513b | 2017-11-09 11:09:25 +0100 | [diff] [blame] | 295 | RTC_LOG(LS_ERROR) << "Codec with max < min bitrate: " << ToString(); |
pbos@webrtc.org | b5a22b1 | 2014-05-13 11:07:01 +0000 | [diff] [blame] | 296 | return false; |
| 297 | } |
| 298 | } |
| 299 | return true; |
| 300 | } |
| 301 | |
deadbeef | 67cf2c1 | 2016-04-13 10:07:16 -0700 | [diff] [blame] | 302 | DataCodec::DataCodec(int id, const std::string& name) |
| 303 | : Codec(id, name, kDataCodecClockrate) {} |
guoweis@webrtc.org | bc6961f | 2015-02-19 17:55:18 +0000 | [diff] [blame] | 304 | |
| 305 | DataCodec::DataCodec() : Codec() { |
| 306 | clockrate = kDataCodecClockrate; |
| 307 | } |
| 308 | |
| 309 | DataCodec::DataCodec(const DataCodec& c) = default; |
magjed | 3663c52 | 2016-11-07 10:14:36 -0800 | [diff] [blame] | 310 | DataCodec::DataCodec(DataCodec&& c) = default; |
guoweis@webrtc.org | bc6961f | 2015-02-19 17:55:18 +0000 | [diff] [blame] | 311 | DataCodec& DataCodec::operator=(const DataCodec& c) = default; |
magjed | 3663c52 | 2016-11-07 10:14:36 -0800 | [diff] [blame] | 312 | DataCodec& DataCodec::operator=(DataCodec&& c) = default; |
guoweis@webrtc.org | bc6961f | 2015-02-19 17:55:18 +0000 | [diff] [blame] | 313 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 314 | std::string DataCodec::ToString() const { |
| 315 | std::ostringstream os; |
| 316 | os << "DataCodec[" << id << ":" << name << "]"; |
| 317 | return os.str(); |
| 318 | } |
| 319 | |
stefan | ba4c0e4 | 2016-02-04 04:12:24 -0800 | [diff] [blame] | 320 | bool HasNack(const Codec& codec) { |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 321 | return codec.HasFeedbackParam( |
| 322 | FeedbackParam(kRtcpFbParamNack, kParamValueEmpty)); |
| 323 | } |
| 324 | |
stefan | ba4c0e4 | 2016-02-04 04:12:24 -0800 | [diff] [blame] | 325 | bool HasRemb(const Codec& codec) { |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 326 | return codec.HasFeedbackParam( |
| 327 | FeedbackParam(kRtcpFbParamRemb, kParamValueEmpty)); |
| 328 | } |
| 329 | |
stefan | ba4c0e4 | 2016-02-04 04:12:24 -0800 | [diff] [blame] | 330 | bool HasTransportCc(const Codec& codec) { |
stefan | 43edf0f | 2015-11-20 18:05:48 -0800 | [diff] [blame] | 331 | return codec.HasFeedbackParam( |
| 332 | FeedbackParam(kRtcpFbParamTransportCc, kParamValueEmpty)); |
| 333 | } |
| 334 | |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 335 | bool CodecNamesEq(const std::string& name1, const std::string& name2) { |
magjed | 1e45cc6 | 2016-10-28 07:43:45 -0700 | [diff] [blame] | 336 | return CodecNamesEq(name1.c_str(), name2.c_str()); |
| 337 | } |
| 338 | |
| 339 | bool CodecNamesEq(const char* name1, const char* name2) { |
| 340 | return _stricmp(name1, name2) == 0; |
| 341 | } |
| 342 | |
magjed | f823ede | 2016-11-12 09:53:04 -0800 | [diff] [blame] | 343 | const VideoCodec* FindMatchingCodec( |
| 344 | const std::vector<VideoCodec>& supported_codecs, |
| 345 | const VideoCodec& codec) { |
| 346 | for (const VideoCodec& supported_codec : supported_codecs) { |
Magnus Jedvert | 523589d | 2017-11-23 13:24:53 +0100 | [diff] [blame^] | 347 | if (IsSameCodec(codec.name, codec.params, supported_codec.name, |
| 348 | supported_codec.params)) { |
| 349 | return &supported_codec; |
magjed | f823ede | 2016-11-12 09:53:04 -0800 | [diff] [blame] | 350 | } |
magjed | f823ede | 2016-11-12 09:53:04 -0800 | [diff] [blame] | 351 | } |
| 352 | return nullptr; |
Shao Changbin | e62202f | 2015-04-21 20:24:50 +0800 | [diff] [blame] | 353 | } |
| 354 | |
Magnus Jedvert | 523589d | 2017-11-23 13:24:53 +0100 | [diff] [blame^] | 355 | bool IsSameCodec(const std::string& name1, |
| 356 | const CodecParameterMap& params1, |
| 357 | const std::string& name2, |
| 358 | const CodecParameterMap& params2) { |
| 359 | // If different names (case insensitive), then not same formats. |
| 360 | if (!CodecNamesEq(name1, name2)) |
| 361 | return false; |
| 362 | // For every format besides H264, comparing names is enough. |
| 363 | return !CodecNamesEq(name1.c_str(), kH264CodecName) || |
| 364 | webrtc::H264::IsSameH264Profile(params1, params2); |
| 365 | } |
| 366 | |
henrike@webrtc.org | 28e2075 | 2013-07-10 00:45:36 +0000 | [diff] [blame] | 367 | } // namespace cricket |