av1: (partially) follow spec fmtp parameter comparisons

as stated in
https://aomediacodec.github.io/av1-rtp-spec/#723-usage-with-the-sdp-offeranswer-model
for SDP negotiation purposes, level-idx, profile and tier are
asymmetrical and the answerer MAY declare its own media configuration if
the answerer receiving capabilities are different from the offerer.

For backward-compat reasons we continue to compare the profile.

BUG=webrtc:396434695

Change-Id: Icf0cf150ce10a0aa83000a8ec68d191dd6e717a7
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/377221
Commit-Queue: Philipp Hancke <phancke@meta.com>
Reviewed-by: Sergey Silkin <ssilkin@webrtc.org>
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Cr-Commit-Position: refs/heads/main@{#45018}
diff --git a/media/base/codec_comparators.cc b/media/base/codec_comparators.cc
index e71c52d..9da9d4a 100644
--- a/media/base/codec_comparators.cc
+++ b/media/base/codec_comparators.cc
@@ -71,22 +71,12 @@
   return GetFmtpParameterOrDefault(params, kAv1FmtpTier, "0");
 }
 
-bool AV1IsSameTier(const CodecParameterMap& left,
-                   const CodecParameterMap& right) {
-  return AV1GetTierOrDefault(left) == AV1GetTierOrDefault(right);
-}
-
 std::string AV1GetLevelIdxOrDefault(const CodecParameterMap& params) {
   // If the parameter is not present, it MUST be inferred to be 5 (level 3.1).
   // https://aomediacodec.github.io/av1-rtp-spec/#72-sdp-parameters
   return GetFmtpParameterOrDefault(params, kAv1FmtpLevelIdx, "5");
 }
 
-bool AV1IsSameLevelIdx(const CodecParameterMap& left,
-                       const CodecParameterMap& right) {
-  return AV1GetLevelIdxOrDefault(left) == AV1GetLevelIdxOrDefault(right);
-}
-
 #ifdef RTC_ENABLE_H265
 std::string GetH265TxModeOrDefault(const CodecParameterMap& params) {
   // If TxMode is not present, a value of "SRST" must be inferred.
@@ -117,10 +107,13 @@
            H264IsSamePacketizationMode(params1, params2);
   if (either_name_matches(kVp9CodecName))
     return VP9IsSameProfile(params1, params2);
+  // https://aomediacodec.github.io/av1-rtp-spec/#723-usage-with-the-sdp-offeranswer-model
+  //   These media configuration parameters are asymmetrical and the answerer
+  //   MAY declare its own media configuration
+  // TODO(bugs.webrtc.org/396434695): for backward compability we currently
+  // compare profile.
   if (either_name_matches(kAv1CodecName))
-    return AV1IsSameProfile(params1, params2) &&
-           AV1IsSameTier(params1, params2) &&
-           AV1IsSameLevelIdx(params1, params2);
+    return AV1IsSameProfile(params1, params2);
 #ifdef RTC_ENABLE_H265
   if (either_name_matches(kH265CodecName)) {
     return H265IsSameProfile(params1, params2) &&
diff --git a/media/base/codec_comparators_unittest.cc b/media/base/codec_comparators_unittest.cc
index 67b630a..2f78042 100644
--- a/media/base/codec_comparators_unittest.cc
+++ b/media/base/codec_comparators_unittest.cc
@@ -425,7 +425,7 @@
   EXPECT_TRUE(c1.Matches(c0));
 }
 
-// AV1 codecs compare profile information.
+// AV1 codecs do not compare profile information.
 TEST(CodecTest, TestAV1CodecMatches) {
   const char kProfile0[] = "0";
   const char kProfile1[] = "1";
@@ -469,6 +469,24 @@
   // AV1 entries with different profiles (0 and 2) are seen as distinct.
   EXPECT_FALSE(c_profile0.Matches(c_profile2));
   EXPECT_FALSE(c_no_profile.Matches(c_profile2));
+
+  // AV1 entries with same profile and different tier are seen as equal.
+  Codec c_tier0 = CreateVideoCodec(95, kAv1CodecName);
+  c_tier0.params[kAv1FmtpProfile] = kProfile0;
+  c_tier0.params[kAv1FmtpTier] = "0";
+  Codec c_tier1 = CreateVideoCodec(95, kAv1CodecName);
+  c_tier1.params[kAv1FmtpProfile] = kProfile0;
+  c_tier1.params[kAv1FmtpTier] = "1";
+  EXPECT_TRUE(c_tier0.Matches(c_tier1));
+
+  // AV1 entries with profile and different level are seen as equal.
+  Codec c_level0 = CreateVideoCodec(95, kAv1CodecName);
+  c_level0.params[kAv1FmtpProfile] = kProfile0;
+  c_level0.params[kAv1FmtpLevelIdx] = "0";
+  Codec c_level1 = CreateVideoCodec(95, kAv1CodecName);
+  c_level1.params[kAv1FmtpProfile] = kProfile0;
+  c_level1.params[kAv1FmtpLevelIdx] = "1";
+  EXPECT_TRUE(c_level0.Matches(c_level1));
 }
 
 // VP9 codecs compare profile information.