blob: 168e7a7829770744b0ca2fd56d8aeeaa2b509f45 [file] [log] [blame]
henrike@webrtc.org28e20752013-07-10 00:45:36 +00001/*
kjellander1afca732016-02-07 20:46:45 -08002 * Copyright (c) 2004 The WebRTC project authors. All Rights Reserved.
henrike@webrtc.org28e20752013-07-10 00:45:36 +00003 *
kjellander1afca732016-02-07 20:46:45 -08004 * 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.org28e20752013-07-10 00:45:36 +00009 */
10
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020011#include "media/base/codec.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000012
Steve Anton2c9ebef2019-01-28 17:27:58 -080013#include "absl/algorithm/container.h"
Niels Möller3c7d5992018-10-19 15:29:54 +020014#include "absl/strings/match.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020015#include "media/base/h264_profile_level_id.h"
Emircan Uysaler98badbc2018-06-28 10:59:02 -070016#include "media/base/vp9_profile.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020017#include "rtc_base/checks.h"
18#include "rtc_base/logging.h"
Steve Anton10542f22019-01-11 09:11:00 -080019#include "rtc_base/string_encode.h"
Jonas Olsson88c99562018-05-03 11:45:33 +020020#include "rtc_base/strings/string_builder.h"
henrike@webrtc.org28e20752013-07-10 00:45:36 +000021
22namespace cricket {
Steve Anton2dbc6272019-05-31 13:08:58 -070023namespace {
24
25std::string GetH264PacketizationModeOrDefault(const CodecParameterMap& params) {
26 auto it = params.find(kH264FmtpPacketizationMode);
27 if (it != params.end()) {
28 return it->second;
29 }
30 // If packetization-mode is not present, default to "0".
31 // https://tools.ietf.org/html/rfc6184#section-6.2
32 return "0";
33}
34
35bool IsSameH264PacketizationMode(const CodecParameterMap& left,
36 const CodecParameterMap& right) {
37 return GetH264PacketizationModeOrDefault(left) ==
38 GetH264PacketizationModeOrDefault(right);
39}
40
41// Some (video) codecs are actually families of codecs and rely on parameters
42// to distinguish different incompatible family members.
43bool IsSameCodecSpecific(const std::string& name1,
44 const CodecParameterMap& params1,
45 const std::string& name2,
46 const CodecParameterMap& params2) {
47 // The names might not necessarily match, so check both.
48 auto either_name_matches = [&](const std::string name) {
49 return absl::EqualsIgnoreCase(name, name1) ||
50 absl::EqualsIgnoreCase(name, name2);
51 };
52 if (either_name_matches(kH264CodecName))
53 return webrtc::H264::IsSameH264Profile(params1, params2) &&
54 IsSameH264PacketizationMode(params1, params2);
55 if (either_name_matches(kVp9CodecName))
56 return webrtc::IsSameVP9Profile(params1, params2);
57 return true;
58}
59
60} // namespace
henrike@webrtc.org28e20752013-07-10 00:45:36 +000061
Magnus Jedvert244ad802017-09-28 21:19:18 +020062FeedbackParams::FeedbackParams() = default;
Paulina Hensmana680a6a2018-04-05 11:42:24 +020063FeedbackParams::~FeedbackParams() = default;
Magnus Jedvert244ad802017-09-28 21:19:18 +020064
henrike@webrtc.org28e20752013-07-10 00:45:36 +000065bool FeedbackParam::operator==(const FeedbackParam& other) const {
Niels Möller3c7d5992018-10-19 15:29:54 +020066 return absl::EqualsIgnoreCase(other.id(), id()) &&
67 absl::EqualsIgnoreCase(other.param(), param());
henrike@webrtc.org28e20752013-07-10 00:45:36 +000068}
69
70bool FeedbackParams::operator==(const FeedbackParams& other) const {
71 return params_ == other.params_;
72}
73
74bool FeedbackParams::Has(const FeedbackParam& param) const {
Steve Anton2c9ebef2019-01-28 17:27:58 -080075 return absl::c_linear_search(params_, param);
henrike@webrtc.org28e20752013-07-10 00:45:36 +000076}
77
78void FeedbackParams::Add(const FeedbackParam& param) {
79 if (param.id().empty()) {
80 return;
81 }
82 if (Has(param)) {
83 // Param already in |this|.
84 return;
85 }
86 params_.push_back(param);
magjed0928a3c2016-11-25 00:40:18 -080087 RTC_CHECK(!HasDuplicateEntries());
henrike@webrtc.org28e20752013-07-10 00:45:36 +000088}
89
90void FeedbackParams::Intersect(const FeedbackParams& from) {
91 std::vector<FeedbackParam>::iterator iter_to = params_.begin();
92 while (iter_to != params_.end()) {
93 if (!from.Has(*iter_to)) {
94 iter_to = params_.erase(iter_to);
95 } else {
96 ++iter_to;
97 }
98 }
99}
100
101bool FeedbackParams::HasDuplicateEntries() const {
102 for (std::vector<FeedbackParam>::const_iterator iter = params_.begin();
103 iter != params_.end(); ++iter) {
104 for (std::vector<FeedbackParam>::const_iterator found = iter + 1;
105 found != params_.end(); ++found) {
106 if (*found == *iter) {
107 return true;
108 }
109 }
110 }
111 return false;
112}
113
deadbeef67cf2c12016-04-13 10:07:16 -0700114Codec::Codec(int id, const std::string& name, int clockrate)
115 : id(id), name(name), clockrate(clockrate) {}
guoweis@webrtc.orgbc6961f2015-02-19 17:55:18 +0000116
deadbeef67cf2c12016-04-13 10:07:16 -0700117Codec::Codec() : id(0), clockrate(0) {}
guoweis@webrtc.orgbc6961f2015-02-19 17:55:18 +0000118
119Codec::Codec(const Codec& c) = default;
magjed3663c522016-11-07 10:14:36 -0800120Codec::Codec(Codec&& c) = default;
guoweis@webrtc.orgbc6961f2015-02-19 17:55:18 +0000121Codec::~Codec() = default;
magjed3663c522016-11-07 10:14:36 -0800122Codec& Codec::operator=(const Codec& c) = default;
123Codec& Codec::operator=(Codec&& c) = default;
guoweis@webrtc.orgbc6961f2015-02-19 17:55:18 +0000124
125bool Codec::operator==(const Codec& c) const {
126 return this->id == c.id && // id is reserved in objective-c
deadbeef67cf2c12016-04-13 10:07:16 -0700127 name == c.name && clockrate == c.clockrate && params == c.params &&
guoweis@webrtc.orgbc6961f2015-02-19 17:55:18 +0000128 feedback_params == c.feedback_params;
129}
130
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000131bool Codec::Matches(const Codec& codec) const {
132 // Match the codec id/name based on the typical static/dynamic name rules.
133 // Matching is case-insensitive.
pkasting@chromium.orgd3245462015-02-23 21:28:22 +0000134 const int kMaxStaticPayloadId = 95;
magjed3663c522016-11-07 10:14:36 -0800135 return (id <= kMaxStaticPayloadId || codec.id <= kMaxStaticPayloadId)
136 ? (id == codec.id)
Niels Möller3c7d5992018-10-19 15:29:54 +0200137 : (absl::EqualsIgnoreCase(name, codec.name));
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000138}
139
Florent Castelli2d9d82e2019-04-23 19:25:51 +0200140bool Codec::MatchesCapability(
141 const webrtc::RtpCodecCapability& codec_capability) const {
142 webrtc::RtpCodecParameters codec_parameters = ToCodecParameters();
143
144 return codec_parameters.name == codec_capability.name &&
145 codec_parameters.kind == codec_capability.kind &&
146 (codec_parameters.name == cricket::kRtxCodecName ||
147 (codec_parameters.num_channels == codec_capability.num_channels &&
148 codec_parameters.clock_rate == codec_capability.clock_rate &&
149 codec_parameters.parameters == codec_capability.parameters));
150}
151
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000152bool Codec::GetParam(const std::string& name, std::string* out) const {
153 CodecParameterMap::const_iterator iter = params.find(name);
154 if (iter == params.end())
155 return false;
156 *out = iter->second;
157 return true;
158}
159
160bool Codec::GetParam(const std::string& name, int* out) const {
161 CodecParameterMap::const_iterator iter = params.find(name);
162 if (iter == params.end())
163 return false;
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000164 return rtc::FromString(iter->second, out);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000165}
166
167void Codec::SetParam(const std::string& name, const std::string& value) {
168 params[name] = value;
169}
170
Yves Gerey665174f2018-06-19 15:03:05 +0200171void Codec::SetParam(const std::string& name, int value) {
buildbot@webrtc.orgd4e598d2014-07-29 17:36:52 +0000172 params[name] = rtc::ToString(value);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000173}
174
buildbot@webrtc.orgfbd13282014-06-19 19:50:55 +0000175bool Codec::RemoveParam(const std::string& name) {
176 return params.erase(name) == 1;
177}
178
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000179void Codec::AddFeedbackParam(const FeedbackParam& param) {
180 feedback_params.Add(param);
181}
182
183bool Codec::HasFeedbackParam(const FeedbackParam& param) const {
184 return feedback_params.Has(param);
185}
186
187void Codec::IntersectFeedbackParams(const Codec& other) {
188 feedback_params.Intersect(other.feedback_params);
189}
190
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700191webrtc::RtpCodecParameters Codec::ToCodecParameters() const {
192 webrtc::RtpCodecParameters codec_params;
193 codec_params.payload_type = id;
deadbeefe702b302017-02-04 12:09:01 -0800194 codec_params.name = name;
Oskar Sundbom78807582017-11-16 11:09:55 +0100195 codec_params.clock_rate = clockrate;
Florent Castellib7d9d832018-05-15 18:14:14 +0200196 codec_params.parameters.insert(params.begin(), params.end());
Taylor Brandstetter0cd086b2016-04-20 16:23:10 -0700197 return codec_params;
198}
199
pkasting25702cb2016-01-08 13:50:27 -0800200AudioCodec::AudioCodec(int id,
201 const std::string& name,
202 int clockrate,
203 int bitrate,
deadbeef67cf2c12016-04-13 10:07:16 -0700204 size_t channels)
205 : Codec(id, name, clockrate), bitrate(bitrate), channels(channels) {}
guoweis@webrtc.orgbc6961f2015-02-19 17:55:18 +0000206
Yves Gerey665174f2018-06-19 15:03:05 +0200207AudioCodec::AudioCodec() : Codec(), bitrate(0), channels(0) {}
guoweis@webrtc.orgbc6961f2015-02-19 17:55:18 +0000208
209AudioCodec::AudioCodec(const AudioCodec& c) = default;
magjed3663c522016-11-07 10:14:36 -0800210AudioCodec::AudioCodec(AudioCodec&& c) = default;
211AudioCodec& AudioCodec::operator=(const AudioCodec& c) = default;
212AudioCodec& AudioCodec::operator=(AudioCodec&& c) = default;
guoweis@webrtc.orgbc6961f2015-02-19 17:55:18 +0000213
214bool AudioCodec::operator==(const AudioCodec& c) const {
guoweis@webrtc.orgcce874b2015-02-19 18:14:36 +0000215 return bitrate == c.bitrate && channels == c.channels && Codec::operator==(c);
guoweis@webrtc.orgbc6961f2015-02-19 17:55:18 +0000216}
217
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000218bool AudioCodec::Matches(const AudioCodec& codec) const {
219 // If a nonzero clockrate is specified, it must match the actual clockrate.
220 // If a nonzero bitrate is specified, it must match the actual bitrate,
221 // unless the codec is VBR (0), where we just force the supplied value.
222 // The number of channels must match exactly, with the exception
223 // that channels=0 is treated synonymously as channels=1, per RFC
224 // 4566 section 6: " [The channels] parameter is OPTIONAL and may be
225 // omitted if the number of channels is one."
226 // Preference is ignored.
227 // TODO(juberti): Treat a zero clockrate as 8000Hz, the RTP default clockrate.
228 return Codec::Matches(codec) &&
Yves Gerey665174f2018-06-19 15:03:05 +0200229 ((codec.clockrate == 0 /*&& clockrate == 8000*/) ||
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000230 clockrate == codec.clockrate) &&
Yves Gerey665174f2018-06-19 15:03:05 +0200231 (codec.bitrate == 0 || bitrate <= 0 || bitrate == codec.bitrate) &&
232 ((codec.channels < 2 && channels < 2) || channels == codec.channels);
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000233}
234
235std::string AudioCodec::ToString() const {
Jonas Olsson88c99562018-05-03 11:45:33 +0200236 char buf[256];
237 rtc::SimpleStringBuilder sb(buf);
238 sb << "AudioCodec[" << id << ":" << name << ":" << clockrate << ":" << bitrate
deadbeef67cf2c12016-04-13 10:07:16 -0700239 << ":" << channels << "]";
Jonas Olsson88c99562018-05-03 11:45:33 +0200240 return sb.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000241}
242
deadbeefe702b302017-02-04 12:09:01 -0800243webrtc::RtpCodecParameters AudioCodec::ToCodecParameters() const {
244 webrtc::RtpCodecParameters codec_params = Codec::ToCodecParameters();
Oskar Sundbom78807582017-11-16 11:09:55 +0100245 codec_params.num_channels = static_cast<int>(channels);
deadbeefe702b302017-02-04 12:09:01 -0800246 codec_params.kind = MEDIA_TYPE_AUDIO;
247 return codec_params;
248}
249
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000250std::string VideoCodec::ToString() const {
Jonas Olsson88c99562018-05-03 11:45:33 +0200251 char buf[256];
252 rtc::SimpleStringBuilder sb(buf);
253 sb << "VideoCodec[" << id << ":" << name << "]";
254 return sb.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000255}
256
deadbeefe702b302017-02-04 12:09:01 -0800257webrtc::RtpCodecParameters VideoCodec::ToCodecParameters() const {
258 webrtc::RtpCodecParameters codec_params = Codec::ToCodecParameters();
259 codec_params.kind = MEDIA_TYPE_VIDEO;
260 return codec_params;
261}
262
pkasting25702cb2016-01-08 13:50:27 -0800263VideoCodec::VideoCodec(int id, const std::string& name)
hta9aa96882016-12-06 05:36:03 -0800264 : Codec(id, name, kVideoCodecClockrate) {
265 SetDefaultParameters();
266}
Shao Changbine62202f2015-04-21 20:24:50 +0800267
hta9aa96882016-12-06 05:36:03 -0800268VideoCodec::VideoCodec(const std::string& name) : VideoCodec(0 /* id */, name) {
269 SetDefaultParameters();
270}
magjed1e45cc62016-10-28 07:43:45 -0700271
perkj26752742016-10-24 01:21:16 -0700272VideoCodec::VideoCodec() : Codec() {
guoweis@webrtc.orgbc6961f2015-02-19 17:55:18 +0000273 clockrate = kVideoCodecClockrate;
274}
275
Magnus Jedvert024d8972017-09-29 15:00:29 +0200276VideoCodec::VideoCodec(const webrtc::SdpVideoFormat& c)
277 : Codec(0 /* id */, c.name, kVideoCodecClockrate) {
278 params = c.parameters;
279}
280
guoweis@webrtc.orgbc6961f2015-02-19 17:55:18 +0000281VideoCodec::VideoCodec(const VideoCodec& c) = default;
magjed3663c522016-11-07 10:14:36 -0800282VideoCodec::VideoCodec(VideoCodec&& c) = default;
283VideoCodec& VideoCodec::operator=(const VideoCodec& c) = default;
284VideoCodec& VideoCodec::operator=(VideoCodec&& c) = default;
guoweis@webrtc.orgbc6961f2015-02-19 17:55:18 +0000285
hta9aa96882016-12-06 05:36:03 -0800286void VideoCodec::SetDefaultParameters() {
Niels Möller3c7d5992018-10-19 15:29:54 +0200287 if (absl::EqualsIgnoreCase(kH264CodecName, name)) {
hta9aa96882016-12-06 05:36:03 -0800288 // This default is set for all H.264 codecs created because
289 // that was the default before packetization mode support was added.
290 // TODO(hta): Move this to the places that create VideoCodecs from
291 // SDP or from knowledge of implementation capabilities.
292 SetParam(kH264FmtpPacketizationMode, "1");
293 }
294}
295
guoweis@webrtc.orgbc6961f2015-02-19 17:55:18 +0000296bool VideoCodec::operator==(const VideoCodec& c) const {
Mirta Dvornicic479a3c02019-06-04 15:38:50 +0200297 return Codec::operator==(c) && packetization == c.packetization;
guoweis@webrtc.orgbc6961f2015-02-19 17:55:18 +0000298}
299
magjedf823ede2016-11-12 09:53:04 -0800300bool VideoCodec::Matches(const VideoCodec& other) const {
Steve Anton2dbc6272019-05-31 13:08:58 -0700301 return Codec::Matches(other) &&
302 IsSameCodecSpecific(name, params, other.name, other.params);
magjedf823ede2016-11-12 09:53:04 -0800303}
304
Mirta Dvornicic479a3c02019-06-04 15:38:50 +0200305absl::optional<std::string> VideoCodec::IntersectPacketization(
306 const VideoCodec& local_codec,
307 const VideoCodec& remote_codec) {
308 if (local_codec.packetization == remote_codec.packetization) {
309 return local_codec.packetization;
310 }
311 return absl::nullopt;
312}
313
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000314VideoCodec VideoCodec::CreateRtxCodec(int rtx_payload_type,
315 int associated_payload_type) {
perkj26752742016-10-24 01:21:16 -0700316 VideoCodec rtx_codec(rtx_payload_type, kRtxCodecName);
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000317 rtx_codec.SetParam(kCodecParamAssociatedPayloadType, associated_payload_type);
318 return rtx_codec;
319}
320
321VideoCodec::CodecType VideoCodec::GetCodecType() const {
Steve Anton2dbc6272019-05-31 13:08:58 -0700322 if (absl::EqualsIgnoreCase(name, kRedCodecName)) {
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000323 return CODEC_RED;
324 }
Steve Anton2dbc6272019-05-31 13:08:58 -0700325 if (absl::EqualsIgnoreCase(name, kUlpfecCodecName)) {
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000326 return CODEC_ULPFEC;
327 }
Steve Anton2dbc6272019-05-31 13:08:58 -0700328 if (absl::EqualsIgnoreCase(name, kFlexfecCodecName)) {
brandtr87d7d772016-11-07 03:03:41 -0800329 return CODEC_FLEXFEC;
330 }
Steve Anton2dbc6272019-05-31 13:08:58 -0700331 if (absl::EqualsIgnoreCase(name, kRtxCodecName)) {
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000332 return CODEC_RTX;
333 }
334
335 return CODEC_VIDEO;
336}
337
338bool VideoCodec::ValidateCodecFormat() const {
339 if (id < 0 || id > 127) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100340 RTC_LOG(LS_ERROR) << "Codec with invalid payload type: " << ToString();
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000341 return false;
342 }
343 if (GetCodecType() != CODEC_VIDEO) {
344 return true;
345 }
346
347 // Video validation from here on.
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000348 int min_bitrate = -1;
349 int max_bitrate = -1;
350 if (GetParam(kCodecParamMinBitrate, &min_bitrate) &&
351 GetParam(kCodecParamMaxBitrate, &max_bitrate)) {
352 if (max_bitrate < min_bitrate) {
Mirko Bonadei675513b2017-11-09 11:09:25 +0100353 RTC_LOG(LS_ERROR) << "Codec with max < min bitrate: " << ToString();
pbos@webrtc.orgb5a22b12014-05-13 11:07:01 +0000354 return false;
355 }
356 }
357 return true;
358}
359
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200360RtpDataCodec::RtpDataCodec(int id, const std::string& name)
deadbeef67cf2c12016-04-13 10:07:16 -0700361 : Codec(id, name, kDataCodecClockrate) {}
guoweis@webrtc.orgbc6961f2015-02-19 17:55:18 +0000362
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200363RtpDataCodec::RtpDataCodec() : Codec() {
guoweis@webrtc.orgbc6961f2015-02-19 17:55:18 +0000364 clockrate = kDataCodecClockrate;
365}
366
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200367RtpDataCodec::RtpDataCodec(const RtpDataCodec& c) = default;
368RtpDataCodec::RtpDataCodec(RtpDataCodec&& c) = default;
369RtpDataCodec& RtpDataCodec::operator=(const RtpDataCodec& c) = default;
370RtpDataCodec& RtpDataCodec::operator=(RtpDataCodec&& c) = default;
guoweis@webrtc.orgbc6961f2015-02-19 17:55:18 +0000371
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200372std::string RtpDataCodec::ToString() const {
Jonas Olsson88c99562018-05-03 11:45:33 +0200373 char buf[256];
374 rtc::SimpleStringBuilder sb(buf);
Harald Alvestrand5fc28b12019-05-13 13:36:16 +0200375 sb << "RtpDataCodec[" << id << ":" << name << "]";
Jonas Olsson88c99562018-05-03 11:45:33 +0200376 return sb.str();
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000377}
378
Elad Alonfadb1812019-05-24 13:40:02 +0200379bool HasLntf(const Codec& codec) {
380 return codec.HasFeedbackParam(
381 FeedbackParam(kRtcpFbParamLntf, kParamValueEmpty));
382}
383
stefanba4c0e42016-02-04 04:12:24 -0800384bool HasNack(const Codec& codec) {
Shao Changbine62202f2015-04-21 20:24:50 +0800385 return codec.HasFeedbackParam(
386 FeedbackParam(kRtcpFbParamNack, kParamValueEmpty));
387}
388
stefanba4c0e42016-02-04 04:12:24 -0800389bool HasRemb(const Codec& codec) {
Shao Changbine62202f2015-04-21 20:24:50 +0800390 return codec.HasFeedbackParam(
391 FeedbackParam(kRtcpFbParamRemb, kParamValueEmpty));
392}
393
Ilya Nikolaevskiy634a7772018-04-04 16:33:49 +0200394bool HasRrtr(const Codec& codec) {
395 return codec.HasFeedbackParam(
396 FeedbackParam(kRtcpFbParamRrtr, kParamValueEmpty));
397}
398
stefanba4c0e42016-02-04 04:12:24 -0800399bool HasTransportCc(const Codec& codec) {
stefan43edf0f2015-11-20 18:05:48 -0800400 return codec.HasFeedbackParam(
401 FeedbackParam(kRtcpFbParamTransportCc, kParamValueEmpty));
402}
403
magjedf823ede2016-11-12 09:53:04 -0800404const VideoCodec* FindMatchingCodec(
405 const std::vector<VideoCodec>& supported_codecs,
406 const VideoCodec& codec) {
407 for (const VideoCodec& supported_codec : supported_codecs) {
Magnus Jedvert523589d2017-11-23 13:24:53 +0100408 if (IsSameCodec(codec.name, codec.params, supported_codec.name,
409 supported_codec.params)) {
410 return &supported_codec;
magjedf823ede2016-11-12 09:53:04 -0800411 }
magjedf823ede2016-11-12 09:53:04 -0800412 }
413 return nullptr;
Shao Changbine62202f2015-04-21 20:24:50 +0800414}
415
Magnus Jedvert523589d2017-11-23 13:24:53 +0100416bool IsSameCodec(const std::string& name1,
417 const CodecParameterMap& params1,
418 const std::string& name2,
419 const CodecParameterMap& params2) {
Steve Anton2dbc6272019-05-31 13:08:58 -0700420 // Two codecs are considered the same if the name matches (case insensitive)
421 // and certain codec-specific parameters match.
422 return absl::EqualsIgnoreCase(name1, name2) &&
423 IsSameCodecSpecific(name1, params1, name2, params2);
Magnus Jedvert523589d2017-11-23 13:24:53 +0100424}
425
henrike@webrtc.org28e20752013-07-10 00:45:36 +0000426} // namespace cricket