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