Chromium Code Reviews| Index: webrtc/media/base/codec.cc |
| diff --git a/webrtc/media/base/codec.cc b/webrtc/media/base/codec.cc |
| index 01350f7123695276b735166a6517769c69d14a42..3570ef65271f11a502fb27097d70bbc034dc500d 100644 |
| --- a/webrtc/media/base/codec.cc |
| +++ b/webrtc/media/base/codec.cc |
| @@ -18,6 +18,19 @@ |
| #include "webrtc/base/stringencode.h" |
| #include "webrtc/base/stringutils.h" |
| +namespace { |
| + |
| +// Return the contained value for |key| if available, and |default_value| |
| +// otherwise. |
| +std::string GetParamOrDefault(const cricket::Codec& codec, |
| + const std::string& key, |
| + const std::string& default_value) { |
| + cricket::CodecParameterMap::const_iterator iter = codec.params.find(key); |
| + return (iter == codec.params.end()) ? default_value : iter->second; |
|
tommi
2016/10/25 09:19:58
nit:
this function should just return |const char
magjed_webrtc
2016/10/25 10:58:01
The reason for not returning char* was that CodecP
|
| +} |
| + |
| +} // anonymous namespace |
| + |
| namespace cricket { |
| const int kMaxPayloadId = 127; |
| @@ -245,6 +258,31 @@ bool VideoCodec::operator==(const VideoCodec& c) const { |
| Codec::operator==(c); |
| } |
| +bool VideoCodec::Matches(const VideoCodec& codec) const { |
| + if (!Codec::Matches(codec)) |
| + return false; |
| + // TODO(magjed): It would be better to have this logic in a H264 subclass. See |
| + // http://crbug/webrtc/6385 for more info. |
| + if (!CodecNamesEq(name, kH264CodecName)) |
| + return true; |
| + // H264 codecs need to have matching profile-level-id. |
| + const std::string our_profile_level_id = GetParamOrDefault( |
| + *this, kH264FmtpProfileLevelId, kH264FmtpDefaultProfileLevelId); |
| + const std::string their_profile_level_id = GetParamOrDefault( |
| + codec, kH264FmtpProfileLevelId, kH264FmtpDefaultProfileLevelId); |
| + if (our_profile_level_id == their_profile_level_id) |
| + return true; |
| + // At this point, profile-level-id is not an exact match, but that is still ok |
| + // if only level_idc differs and level asymmetry is allowed. |
| + const bool level_asymmetry_allowed = |
| + GetParamOrDefault(*this, kH264FmtpLevelAsymmetryAllowed, "0") == "1" && |
| + GetParamOrDefault(codec, kH264FmtpLevelAsymmetryAllowed, "0") == "1"; |
|
tommi
2016/10/25 09:19:58
nit: "0" -> "" (or nullptr?)
magjed_webrtc
2016/10/25 10:58:01
Yes, should be possible. I wanted to be clear here
|
| + // Ignore level_idc and compare only profile_idc and profile_iop. |
| + const bool is_profile_match = (our_profile_level_id.substr(0, 4) == |
| + their_profile_level_id.substr(0, 4)); |
|
tommi
2016/10/25 09:19:58
three nits:
* do you know if our_profile_level_id
hta-webrtc
2016/10/25 09:36:25
1) profile-level-id is always six characters; anyt
magjed_webrtc
2016/10/25 10:58:01
I will add explicit functionality for parsing the
|
| + return level_asymmetry_allowed && is_profile_match; |
|
tommi
2016/10/25 09:19:58
nit: if level_asymmetry_allowed is required, you m
magjed_webrtc
2016/10/25 10:58:01
Sure. As long as the code is as clear as possible.
|
| +} |
| + |
| VideoCodec VideoCodec::CreateRtxCodec(int rtx_payload_type, |
| int associated_payload_type) { |
| VideoCodec rtx_codec(rtx_payload_type, kRtxCodecName, 0, 0, 0); |