[M124] Use predefined SdpVideoFormats when returning supported formats

The predefined SdpVideoFormats were not used everywhere,
which caused a discrepancy between send/receive capabilities
for AV1. This CL solves the immediate problems by making sure
send/receive capabilities for AV1 are reported the same way.

(cherry picked from commit 82598402e095ec6638b6cf3dc8e7f6d35cc3d737)

Fixed: chromium:331565934
Change-Id: I073091b7b5f987c7f434c17276fd84047ec723c2
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/344681
Reviewed-by: Harald Alvestrand <hta@webrtc.org>
Commit-Queue: Johannes Kron <kron@webrtc.org>
Cr-Original-Commit-Position: refs/heads/main@{#41991}
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/348720
Cr-Commit-Position: refs/branch-heads/6367@{#3}
Cr-Branched-From: 802552a8030d82ad07b72aa738f814f3a0030810-refs/heads/main@{#41921}
diff --git a/api/video_codecs/sdp_video_format.cc b/api/video_codecs/sdp_video_format.cc
index 7921064..fc26ac9 100644
--- a/api/video_codecs/sdp_video_format.cc
+++ b/api/video_codecs/sdp_video_format.cc
@@ -138,6 +138,13 @@
       parameters(parameters),
       scalability_modes(scalability_modes) {}
 
+SdpVideoFormat::SdpVideoFormat(
+    const SdpVideoFormat& format,
+    const absl::InlinedVector<ScalabilityMode, kScalabilityModeCount>& modes)
+    : SdpVideoFormat(format) {
+  scalability_modes = modes;
+}
+
 SdpVideoFormat::SdpVideoFormat(const SdpVideoFormat&) = default;
 SdpVideoFormat::SdpVideoFormat(SdpVideoFormat&&) = default;
 SdpVideoFormat& SdpVideoFormat::operator=(const SdpVideoFormat&) = default;
diff --git a/api/video_codecs/sdp_video_format.h b/api/video_codecs/sdp_video_format.h
index 112f53f..e7da486 100644
--- a/api/video_codecs/sdp_video_format.h
+++ b/api/video_codecs/sdp_video_format.h
@@ -36,6 +36,14 @@
       const CodecParameterMap& parameters,
       const absl::InlinedVector<ScalabilityMode, kScalabilityModeCount>&
           scalability_modes);
+  // Creates a new SdpVideoFormat object identical to the supplied
+  // SdpVideoFormat except the scalability_modes that are set to be the same as
+  // the supplied scalability modes.
+  SdpVideoFormat(
+      const SdpVideoFormat& format,
+      const absl::InlinedVector<ScalabilityMode, kScalabilityModeCount>&
+          scalability_modes);
+
   SdpVideoFormat(const SdpVideoFormat&);
   SdpVideoFormat(SdpVideoFormat&&);
   SdpVideoFormat& operator=(const SdpVideoFormat&);
diff --git a/api/video_codecs/video_decoder_factory_template_dav1d_adapter.h b/api/video_codecs/video_decoder_factory_template_dav1d_adapter.h
index f38d469..7bc0bbb 100644
--- a/api/video_codecs/video_decoder_factory_template_dav1d_adapter.h
+++ b/api/video_codecs/video_decoder_factory_template_dav1d_adapter.h
@@ -21,10 +21,7 @@
 namespace webrtc {
 struct Dav1dDecoderTemplateAdapter {
   static std::vector<SdpVideoFormat> SupportedFormats() {
-    return {SdpVideoFormat("AV1"),
-            SdpVideoFormat(
-                "AV1", {{"profile",
-                         AV1ProfileToString(AV1Profile::kProfile1).data()}})};
+    return {SdpVideoFormat::AV1Profile0(), SdpVideoFormat::AV1Profile1()};
   }
 
   static std::unique_ptr<VideoDecoder> CreateDecoder(
diff --git a/api/video_codecs/video_encoder_factory_template_libaom_av1_adapter.h b/api/video_codecs/video_encoder_factory_template_libaom_av1_adapter.h
index 0f801ad..3f551de 100644
--- a/api/video_codecs/video_encoder_factory_template_libaom_av1_adapter.h
+++ b/api/video_codecs/video_encoder_factory_template_libaom_av1_adapter.h
@@ -24,7 +24,7 @@
   static std::vector<SdpVideoFormat> SupportedFormats() {
     absl::InlinedVector<ScalabilityMode, kScalabilityModeCount>
         scalability_modes = LibaomAv1EncoderSupportedScalabilityModes();
-    return {SdpVideoFormat("AV1", CodecParameterMap(), scalability_modes)};
+    return {SdpVideoFormat(SdpVideoFormat::AV1Profile0(), scalability_modes)};
   }
 
   static std::unique_ptr<VideoEncoder> CreateEncoder(
diff --git a/api/video_codecs/video_encoder_factory_template_libvpx_vp8_adapter.h b/api/video_codecs/video_encoder_factory_template_libvpx_vp8_adapter.h
index c60aa04..de6d975 100644
--- a/api/video_codecs/video_encoder_factory_template_libvpx_vp8_adapter.h
+++ b/api/video_codecs/video_encoder_factory_template_libvpx_vp8_adapter.h
@@ -28,7 +28,7 @@
       scalability_modes.push_back(scalability_mode);
     }
 
-    return {SdpVideoFormat("VP8", CodecParameterMap(), scalability_modes)};
+    return {SdpVideoFormat(SdpVideoFormat::VP8(), scalability_modes)};
   }
 
   static std::unique_ptr<VideoEncoder> CreateEncoder(
diff --git a/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc b/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc
index dae3997..2abeb05 100644
--- a/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc
+++ b/modules/video_coding/codecs/test/videocodec_test_fixture_impl.cc
@@ -178,7 +178,9 @@
 
     return SdpVideoFormat(config.codec_name, codec_params);
   } else if (config.codec_settings.codecType == kVideoCodecVP9) {
-    return SdpVideoFormat(config.codec_name, {{"profile-id", "0"}});
+    return SdpVideoFormat::VP9Profile0();
+  } else if (config.codec_settings.codecType == kVideoCodecAV1) {
+    return SdpVideoFormat::AV1Profile0();
   }
 
   return SdpVideoFormat(config.codec_name);
diff --git a/modules/video_coding/codecs/vp9/vp9.cc b/modules/video_coding/codecs/vp9/vp9.cc
index 8799f2c..d2cbd52 100644
--- a/modules/video_coding/codecs/vp9/vp9.cc
+++ b/modules/video_coding/codecs/vp9/vp9.cc
@@ -46,15 +46,11 @@
       }
     }
   }
-  std::vector<SdpVideoFormat> supported_formats{SdpVideoFormat(
-      cricket::kVp9CodecName,
-      {{kVP9FmtpProfileId, VP9ProfileToString(VP9Profile::kProfile0)}},
-      scalability_modes)};
+  std::vector<SdpVideoFormat> supported_formats{
+      SdpVideoFormat(SdpVideoFormat::VP9Profile0(), scalability_modes)};
   if (vpx_supports_high_bit_depth) {
-    supported_formats.push_back(SdpVideoFormat(
-        cricket::kVp9CodecName,
-        {{kVP9FmtpProfileId, VP9ProfileToString(VP9Profile::kProfile2)}},
-        scalability_modes));
+    supported_formats.push_back(
+        SdpVideoFormat(SdpVideoFormat::VP9Profile2(), scalability_modes));
   }
 
   return supported_formats;
@@ -69,12 +65,8 @@
   // The WebRTC internal decoder supports VP9 profile 1 and 3. However, there's
   // currently no way of sending VP9 profile 1 or 3 using the internal encoder.
   // It would require extended support for I444, I422, and I440 buffers.
-  supported_formats.push_back(SdpVideoFormat(
-      cricket::kVp9CodecName,
-      {{kVP9FmtpProfileId, VP9ProfileToString(VP9Profile::kProfile1)}}));
-  supported_formats.push_back(SdpVideoFormat(
-      cricket::kVp9CodecName,
-      {{kVP9FmtpProfileId, VP9ProfileToString(VP9Profile::kProfile3)}}));
+  supported_formats.push_back(SdpVideoFormat::VP9Profile1());
+  supported_formats.push_back(SdpVideoFormat::VP9Profile3());
   return supported_formats;
 #else
   return std::vector<SdpVideoFormat>();