Don't block the signaling thread during the call.

Since WebRTC stats are collected on the signaling thread, this CL moves
the wait from the signaling thread to the main thread.

Bug: webrtc:10138
Change-Id: I0e554fe82e3a4afe66b45e53032b06d533f54a39
Reviewed-on: https://webrtc-review.googlesource.com/c/123228
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Artem Titov <titovartem@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26746}
diff --git a/test/pc/e2e/BUILD.gn b/test/pc/e2e/BUILD.gn
index 27955a3..8cede70 100644
--- a/test/pc/e2e/BUILD.gn
+++ b/test/pc/e2e/BUILD.gn
@@ -216,6 +216,7 @@
       "../../../rtc_base:gunit_helpers",
       "../../../rtc_base:rtc_base",
       "../../../rtc_base:rtc_base_approved",
+      "../../../rtc_base:safe_conversions",
       "../../../system_wrappers:system_wrappers",
       "../../../test:fileutils",
       "../../../test:video_test_support",
diff --git a/test/pc/e2e/peer_connection_quality_test.cc b/test/pc/e2e/peer_connection_quality_test.cc
index 4f293fa..7efb811 100644
--- a/test/pc/e2e/peer_connection_quality_test.cc
+++ b/test/pc/e2e/peer_connection_quality_test.cc
@@ -11,6 +11,7 @@
  */
 #include "test/pc/e2e/peer_connection_quality_test.h"
 
+#include <algorithm>
 #include <set>
 #include <utility>
 
@@ -22,6 +23,7 @@
 #include "pc/test/mock_peer_connection_observers.h"
 #include "rtc_base/bind.h"
 #include "rtc_base/gunit.h"
+#include "rtc_base/numerics/safe_conversions.h"
 #include "system_wrappers/include/cpu_info.h"
 #include "test/pc/e2e/analyzer/video/example_video_quality_analyzer.h"
 #include "test/pc/e2e/api/video_quality_analyzer_interface.h"
@@ -189,8 +191,19 @@
   video_quality_analyzer_injection_helper_->Start(video_analyzer_threads);
   signaling_thread->Invoke<void>(
       RTC_FROM_HERE,
-      rtc::Bind(&PeerConnectionE2EQualityTest::RunOnSignalingThread, this,
-                run_params));
+      rtc::Bind(&PeerConnectionE2EQualityTest::SetupCallOnSignalingThread,
+                this));
+
+  // TODO(bugs.webrtc.org/10138): Implement stats collection and send stats
+  // reports to analyzers every 1 second.
+  rtc::Event done;
+  done.Wait(rtc::checked_cast<int>(run_params.run_duration.ms()));
+
+  signaling_thread->Invoke<void>(
+      RTC_FROM_HERE,
+      rtc::Bind(&PeerConnectionE2EQualityTest::TearDownCallOnSignalingThread,
+                this));
+
   video_quality_analyzer_injection_helper_->Stop();
 
   // Ensuring that TestPeers have been destroyed in order to correctly close
@@ -296,15 +309,14 @@
   output_video_sinks_.push_back(std::move(video_sink));
 }
 
-void PeerConnectionE2EQualityTest::RunOnSignalingThread(RunParams run_params) {
+void PeerConnectionE2EQualityTest::SetupCallOnSignalingThread() {
   alice_video_sources_ = AddMedia(alice_.get());
   bob_video_sources_ = AddMedia(bob_.get());
 
   SetupCall();
+}
 
-  rtc::Event done;
-  done.Wait(static_cast<int>(run_params.run_duration.ms()));
-
+void PeerConnectionE2EQualityTest::TearDownCallOnSignalingThread() {
   TearDownCall();
 }
 
diff --git a/test/pc/e2e/peer_connection_quality_test.h b/test/pc/e2e/peer_connection_quality_test.h
index b19a4fe..be146f7 100644
--- a/test/pc/e2e/peer_connection_quality_test.h
+++ b/test/pc/e2e/peer_connection_quality_test.h
@@ -58,7 +58,8 @@
   void SetupVideoSink(rtc::scoped_refptr<RtpTransceiverInterface> transceiver,
                       std::vector<VideoConfig> remote_video_configs);
   // Have to be run on the signaling thread.
-  void RunOnSignalingThread(RunParams run_params);
+  void SetupCallOnSignalingThread();
+  void TearDownCallOnSignalingThread();
   std::vector<rtc::scoped_refptr<FrameGeneratorCapturerVideoTrackSource>>
   AddMedia(TestPeer* peer);
   std::vector<rtc::scoped_refptr<FrameGeneratorCapturerVideoTrackSource>>