Add sync group validation in pc level test framework

Bug: webrtc:11381
Change-Id: I4ef62675c0cb688abccc130fb91a69c3c78bf837
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/178383
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Reviewed-by: Artem Titov <titovartem@webrtc.org>
Commit-Queue: Andrey Logvin <landrey@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#31587}
diff --git a/api/test/peerconnection_quality_test_fixture.h b/api/test/peerconnection_quality_test_fixture.h
index 3573687..4cdca81 100644
--- a/api/test/peerconnection_quality_test_fixture.h
+++ b/api/test/peerconnection_quality_test_fixture.h
@@ -229,8 +229,7 @@
     bool show_on_screen = false;
     // If specified, determines a sync group to which this video stream belongs.
     // According to bugs.webrtc.org/4762 WebRTC supports synchronization only
-    // for pair of single audio and single video stream. Framework won't do any
-    // enforcements on this field.
+    // for pair of single audio and single video stream.
     absl::optional<std::string> sync_group;
   };
 
@@ -257,8 +256,7 @@
     int sampling_frequency_in_hz = 48000;
     // If specified, determines a sync group to which this audio stream belongs.
     // According to bugs.webrtc.org/4762 WebRTC supports synchronization only
-    // for pair of single audio and single video stream. Framework won't do any
-    // enforcements on this field.
+    // for pair of single audio and single video stream.
     absl::optional<std::string> sync_group;
   };
 
diff --git a/test/pc/e2e/peer_configurer.cc b/test/pc/e2e/peer_configurer.cc
index d1d5b7f..b5616b5 100644
--- a/test/pc/e2e/peer_configurer.cc
+++ b/test/pc/e2e/peer_configurer.cc
@@ -107,6 +107,8 @@
   std::set<std::string> peer_names;
   std::set<std::string> video_labels;
   std::set<std::string> audio_labels;
+  std::set<std::string> video_sync_groups;
+  std::set<std::string> audio_sync_groups;
   int media_streams_count = 0;
 
   for (size_t i = 0; i < peers.size(); ++i) {
@@ -123,7 +125,8 @@
     }
     media_streams_count += p->video_configs.size();
 
-    // Validate that all video stream labels are unique.
+    // Validate that all video stream labels are unique and sync groups are
+    // valid.
     for (const VideoConfig& video_config : p->video_configs) {
       RTC_CHECK(video_config.stream_label);
       bool inserted =
@@ -131,6 +134,17 @@
       RTC_CHECK(inserted) << "Duplicate video_config.stream_label="
                           << video_config.stream_label.value();
 
+      // TODO(bugs.webrtc.org/4762): remove this check after synchronization of
+      // more than two streams is supported.
+      if (video_config.sync_group.has_value()) {
+        bool sync_group_inserted =
+            video_sync_groups.insert(video_config.sync_group.value()).second;
+        RTC_CHECK(sync_group_inserted)
+            << "Sync group shouldn't consist of more than two streams (one "
+               "video and one audio). Duplicate video_config.sync_group="
+            << video_config.sync_group.value();
+      }
+
       if (video_config.simulcast_config) {
         if (video_config.simulcast_config->target_spatial_index) {
           RTC_CHECK_GE(*video_config.simulcast_config->target_spatial_index, 0);
@@ -158,6 +172,17 @@
           audio_labels.insert(p->audio_config->stream_label.value()).second;
       RTC_CHECK(inserted) << "Duplicate audio_config.stream_label="
                           << p->audio_config->stream_label.value();
+      // TODO(bugs.webrtc.org/4762): remove this check after synchronization of
+      // more than two streams is supported.
+      if (p->audio_config->sync_group.has_value()) {
+        bool sync_group_inserted =
+            audio_sync_groups.insert(p->audio_config->sync_group.value())
+                .second;
+        RTC_CHECK(sync_group_inserted)
+            << "Sync group shouldn't consist of more than two streams (one "
+               "video and one audio). Duplicate audio_config.sync_group="
+            << p->audio_config->sync_group.value();
+      }
       // Check that if mode input file name specified only if mode is kFile.
       if (p->audio_config.value().mode == AudioConfig::Mode::kGenerated) {
         RTC_CHECK(!p->audio_config.value().input_file_name);