Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license |
| 5 | * that can be found in the LICENSE file in the root of the source |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | #include "test/pc/e2e/peer_connection_quality_test.h" |
| 11 | |
Mirko Bonadei | 7131880 | 2019-02-18 18:52:43 +0100 | [diff] [blame] | 12 | #include <algorithm> |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 13 | #include <set> |
| 14 | #include <utility> |
| 15 | |
| 16 | #include "absl/memory/memory.h" |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 17 | #include "api/media_stream_interface.h" |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 18 | #include "api/peer_connection_interface.h" |
| 19 | #include "api/scoped_refptr.h" |
| 20 | #include "api/units/time_delta.h" |
Mirko Bonadei | ce7a4fb | 2019-02-25 11:45:07 +0100 | [diff] [blame] | 21 | #include "logging/rtc_event_log/output/rtc_event_log_output_file.h" |
| 22 | #include "logging/rtc_event_log/rtc_event_log.h" |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 23 | #include "pc/test/mock_peer_connection_observers.h" |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 24 | #include "rtc_base/bind.h" |
| 25 | #include "rtc_base/gunit.h" |
Mirko Bonadei | 7131880 | 2019-02-18 18:52:43 +0100 | [diff] [blame] | 26 | #include "rtc_base/numerics/safe_conversions.h" |
Artem Titov | 9f97c9a | 2019-02-08 00:35:13 +0100 | [diff] [blame] | 27 | #include "system_wrappers/include/cpu_info.h" |
Mirko Bonadei | 3830d9b | 2019-02-28 14:07:56 +0100 | [diff] [blame] | 28 | #include "test/pc/e2e/analyzer/audio/default_audio_quality_analyzer.h" |
Artem Titov | 859abef | 2019-03-01 11:11:09 +0100 | [diff] [blame] | 29 | #include "test/pc/e2e/analyzer/video/default_video_quality_analyzer.h" |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 30 | #include "test/pc/e2e/api/video_quality_analyzer_interface.h" |
Mirko Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +0100 | [diff] [blame] | 31 | #include "test/pc/e2e/stats_poller.h" |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 32 | #include "test/testsupport/file_utils.h" |
| 33 | |
| 34 | namespace webrtc { |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame^] | 35 | namespace webrtc_pc_e2e { |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 36 | namespace { |
| 37 | |
| 38 | using VideoConfig = PeerConnectionE2EQualityTestFixture::VideoConfig; |
| 39 | |
| 40 | constexpr int kDefaultTimeoutMs = 10000; |
| 41 | constexpr char kSignalThreadName[] = "signaling_thread"; |
Artem Titov | 9f97c9a | 2019-02-08 00:35:13 +0100 | [diff] [blame] | 42 | // 1 signaling, 2 network, 2 worker and 2 extra for codecs etc. |
| 43 | constexpr int kPeerConnectionUsedThreads = 7; |
| 44 | // Framework has extra thread for network layer and extra thread for peer |
| 45 | // connection stats polling. |
| 46 | constexpr int kFrameworkUsedThreads = 2; |
| 47 | constexpr int kMaxVideoAnalyzerThreads = 8; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 48 | |
Mirko Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +0100 | [diff] [blame] | 49 | constexpr TimeDelta kStatsUpdateInterval = TimeDelta::Seconds<1>(); |
| 50 | constexpr TimeDelta kStatsPollingStopTimeout = TimeDelta::Seconds<1>(); |
| 51 | |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 52 | std::string VideoConfigSourcePresenceToString(const VideoConfig& video_config) { |
| 53 | char buf[1024]; |
| 54 | rtc::SimpleStringBuilder builder(buf); |
| 55 | builder << "video_config.generator=" << video_config.generator.has_value() |
| 56 | << "; video_config.input_file_name=" |
| 57 | << video_config.input_file_name.has_value() |
| 58 | << "; video_config.screen_share_config=" |
| 59 | << video_config.screen_share_config.has_value() << ";"; |
| 60 | return builder.str(); |
| 61 | } |
| 62 | |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 63 | class FixturePeerConnectionObserver : public MockPeerConnectionObserver { |
| 64 | public: |
| 65 | // |on_track_callback| will be called when any new track will be added to peer |
| 66 | // connection. |
| 67 | // |on_connected_callback| will be called when peer connection will come to |
| 68 | // either connected or completed state. Client should notice that in the case |
| 69 | // of reconnect this callback can be called again, so it should be tolerant |
| 70 | // to such behavior. |
| 71 | FixturePeerConnectionObserver( |
| 72 | std::function<void(rtc::scoped_refptr<RtpTransceiverInterface>)> |
| 73 | on_track_callback, |
| 74 | std::function<void()> on_connected_callback) |
| 75 | : on_track_callback_(std::move(on_track_callback)), |
| 76 | on_connected_callback_(std::move(on_connected_callback)) {} |
| 77 | |
| 78 | void OnTrack( |
| 79 | rtc::scoped_refptr<RtpTransceiverInterface> transceiver) override { |
| 80 | MockPeerConnectionObserver::OnTrack(transceiver); |
| 81 | on_track_callback_(transceiver); |
| 82 | } |
| 83 | |
| 84 | void OnIceConnectionChange( |
| 85 | PeerConnectionInterface::IceConnectionState new_state) override { |
| 86 | MockPeerConnectionObserver::OnIceConnectionChange(new_state); |
| 87 | if (ice_connected_) { |
| 88 | on_connected_callback_(); |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | private: |
| 93 | std::function<void(rtc::scoped_refptr<RtpTransceiverInterface>)> |
| 94 | on_track_callback_; |
| 95 | std::function<void()> on_connected_callback_; |
| 96 | }; |
| 97 | |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 98 | } // namespace |
| 99 | |
| 100 | PeerConnectionE2EQualityTest::PeerConnectionE2EQualityTest( |
Artem Titov | 5983585 | 2019-02-27 17:44:13 +0100 | [diff] [blame] | 101 | std::string test_case_name, |
Mirko Bonadei | f5d8808 | 2019-02-20 16:16:54 +0100 | [diff] [blame] | 102 | std::unique_ptr<AudioQualityAnalyzerInterface> audio_quality_analyzer, |
| 103 | std::unique_ptr<VideoQualityAnalyzerInterface> video_quality_analyzer) |
Artem Titov | 5983585 | 2019-02-27 17:44:13 +0100 | [diff] [blame] | 104 | : clock_(Clock::GetRealTimeClock()), |
Artem Titov | ba82e00 | 2019-03-15 15:57:53 +0100 | [diff] [blame] | 105 | test_case_name_(std::move(test_case_name)) { |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 106 | // Create default video quality analyzer. We will always create an analyzer, |
| 107 | // even if there are no video streams, because it will be installed into video |
| 108 | // encoder/decoder factories. |
Mirko Bonadei | f5d8808 | 2019-02-20 16:16:54 +0100 | [diff] [blame] | 109 | if (video_quality_analyzer == nullptr) { |
Artem Titov | 859abef | 2019-03-01 11:11:09 +0100 | [diff] [blame] | 110 | video_quality_analyzer = absl::make_unique<DefaultVideoQualityAnalyzer>(); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 111 | } |
| 112 | encoded_image_id_controller_ = |
Artem Titov | 32232e9 | 2019-02-20 21:13:14 +0100 | [diff] [blame] | 113 | absl::make_unique<SingleProcessEncodedImageDataInjector>(); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 114 | video_quality_analyzer_injection_helper_ = |
| 115 | absl::make_unique<VideoQualityAnalyzerInjectionHelper>( |
Mirko Bonadei | f5d8808 | 2019-02-20 16:16:54 +0100 | [diff] [blame] | 116 | std::move(video_quality_analyzer), encoded_image_id_controller_.get(), |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 117 | encoded_image_id_controller_.get()); |
Mirko Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +0100 | [diff] [blame] | 118 | |
| 119 | if (audio_quality_analyzer == nullptr) { |
| 120 | audio_quality_analyzer = absl::make_unique<DefaultAudioQualityAnalyzer>(); |
| 121 | } |
| 122 | audio_quality_analyzer_.swap(audio_quality_analyzer); |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 123 | } |
| 124 | |
Artem Titov | ba82e00 | 2019-03-15 15:57:53 +0100 | [diff] [blame] | 125 | void PeerConnectionE2EQualityTest::ExecuteAt( |
| 126 | TimeDelta target_time_since_start, |
| 127 | std::function<void(TimeDelta)> func) { |
| 128 | ExecuteTask(target_time_since_start, absl::nullopt, func); |
| 129 | } |
| 130 | |
| 131 | void PeerConnectionE2EQualityTest::ExecuteEvery( |
| 132 | TimeDelta initial_delay_since_start, |
| 133 | TimeDelta interval, |
| 134 | std::function<void(TimeDelta)> func) { |
| 135 | ExecuteTask(initial_delay_since_start, interval, func); |
| 136 | } |
| 137 | |
| 138 | void PeerConnectionE2EQualityTest::ExecuteTask( |
| 139 | TimeDelta initial_delay_since_start, |
| 140 | absl::optional<TimeDelta> interval, |
| 141 | std::function<void(TimeDelta)> func) { |
| 142 | RTC_CHECK(initial_delay_since_start.IsFinite() && |
| 143 | initial_delay_since_start >= TimeDelta::Zero()); |
| 144 | RTC_CHECK(!interval || |
| 145 | (interval->IsFinite() && *interval > TimeDelta::Zero())); |
| 146 | rtc::CritScope crit(&lock_); |
| 147 | ScheduledActivity activity(initial_delay_since_start, interval, func); |
| 148 | if (start_time_.IsInfinite()) { |
| 149 | scheduled_activities_.push(std::move(activity)); |
| 150 | } else { |
| 151 | PostTask(std::move(activity)); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | void PeerConnectionE2EQualityTest::PostTask(ScheduledActivity activity) { |
| 156 | // Because start_time_ will never change at this point copy it to local |
| 157 | // variable to capture in in lambda without requirement to hold a lock. |
| 158 | Timestamp start_time = start_time_; |
| 159 | |
| 160 | TimeDelta remaining_delay = |
| 161 | activity.initial_delay_since_start == TimeDelta::Zero() |
| 162 | ? TimeDelta::Zero() |
| 163 | : activity.initial_delay_since_start - (Now() - start_time_); |
| 164 | if (remaining_delay < TimeDelta::Zero()) { |
| 165 | RTC_LOG(WARNING) << "Executing late task immediately, late by=" |
| 166 | << ToString(remaining_delay.Abs()); |
| 167 | remaining_delay = TimeDelta::Zero(); |
| 168 | } |
| 169 | |
| 170 | if (activity.interval) { |
| 171 | if (remaining_delay == TimeDelta::Zero()) { |
| 172 | repeating_task_handles_.push_back(RepeatingTaskHandle::Start( |
| 173 | task_queue_->Get(), [activity, start_time, this]() { |
| 174 | activity.func(Now() - start_time); |
| 175 | return *activity.interval; |
| 176 | })); |
| 177 | return; |
| 178 | } |
| 179 | repeating_task_handles_.push_back(RepeatingTaskHandle::DelayedStart( |
| 180 | task_queue_->Get(), remaining_delay, [activity, start_time, this]() { |
| 181 | activity.func(Now() - start_time); |
| 182 | return *activity.interval; |
| 183 | })); |
| 184 | return; |
| 185 | } |
| 186 | |
| 187 | if (remaining_delay == TimeDelta::Zero()) { |
| 188 | task_queue_->PostTask( |
| 189 | [activity, start_time, this]() { activity.func(Now() - start_time); }); |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | task_queue_->PostDelayedTask( |
| 194 | [activity, start_time, this]() { activity.func(Now() - start_time); }, |
| 195 | remaining_delay.ms()); |
| 196 | } |
| 197 | |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 198 | void PeerConnectionE2EQualityTest::Run( |
| 199 | std::unique_ptr<InjectableComponents> alice_components, |
| 200 | std::unique_ptr<Params> alice_params, |
| 201 | std::unique_ptr<InjectableComponents> bob_components, |
| 202 | std::unique_ptr<Params> bob_params, |
| 203 | RunParams run_params) { |
| 204 | RTC_CHECK(alice_components); |
| 205 | RTC_CHECK(alice_params); |
| 206 | RTC_CHECK(bob_components); |
| 207 | RTC_CHECK(bob_params); |
| 208 | |
Artem Titov | 9a7e721 | 2019-02-28 16:34:17 +0100 | [diff] [blame] | 209 | SetDefaultValuesForMissingParams({alice_params.get(), bob_params.get()}); |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 210 | ValidateParams({alice_params.get(), bob_params.get()}); |
| 211 | |
| 212 | // Print test summary |
| 213 | RTC_LOG(INFO) |
| 214 | << "Media quality test: Alice will make a call to Bob with media video=" |
| 215 | << !alice_params->video_configs.empty() |
| 216 | << "; audio=" << alice_params->audio_config.has_value() |
| 217 | << ". Bob will respond with media video=" |
| 218 | << !bob_params->video_configs.empty() |
| 219 | << "; audio=" << bob_params->audio_config.has_value(); |
| 220 | |
| 221 | const std::unique_ptr<rtc::Thread> signaling_thread = rtc::Thread::Create(); |
| 222 | signaling_thread->SetName(kSignalThreadName, nullptr); |
| 223 | signaling_thread->Start(); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 224 | |
| 225 | // Create call participants: Alice and Bob. |
| 226 | // Audio streams are intercepted in AudioDeviceModule, so if it is required to |
| 227 | // catch output of Alice's stream, Alice's output_dump_file_name should be |
| 228 | // passed to Bob's TestPeer setup as audio output file name. |
| 229 | absl::optional<std::string> alice_audio_output_dump_file_name = |
| 230 | bob_params->audio_config ? bob_params->audio_config->output_dump_file_name |
| 231 | : absl::nullopt; |
| 232 | absl::optional<std::string> bob_audio_output_dump_file_name = |
| 233 | alice_params->audio_config |
| 234 | ? alice_params->audio_config->output_dump_file_name |
| 235 | : absl::nullopt; |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 236 | // Copy Alice and Bob video configs to correctly pass them into lambdas. |
| 237 | std::vector<VideoConfig> alice_video_configs = alice_params->video_configs; |
| 238 | std::vector<VideoConfig> bob_video_configs = bob_params->video_configs; |
| 239 | |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 240 | alice_ = TestPeer::CreateTestPeer( |
| 241 | std::move(alice_components), std::move(alice_params), |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 242 | absl::make_unique<FixturePeerConnectionObserver>( |
| 243 | [this, bob_video_configs]( |
| 244 | rtc::scoped_refptr<RtpTransceiverInterface> transceiver) { |
| 245 | SetupVideoSink(transceiver, bob_video_configs); |
| 246 | }, |
| 247 | [this]() { StartVideo(alice_video_sources_); }), |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 248 | video_quality_analyzer_injection_helper_.get(), signaling_thread.get(), |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 249 | alice_audio_output_dump_file_name); |
| 250 | bob_ = TestPeer::CreateTestPeer( |
| 251 | std::move(bob_components), std::move(bob_params), |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 252 | absl::make_unique<FixturePeerConnectionObserver>( |
| 253 | [this, alice_video_configs]( |
| 254 | rtc::scoped_refptr<RtpTransceiverInterface> transceiver) { |
| 255 | SetupVideoSink(transceiver, alice_video_configs); |
| 256 | }, |
| 257 | [this]() { StartVideo(bob_video_sources_); }), |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 258 | video_quality_analyzer_injection_helper_.get(), signaling_thread.get(), |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 259 | bob_audio_output_dump_file_name); |
Artem Titov | 9f97c9a | 2019-02-08 00:35:13 +0100 | [diff] [blame] | 260 | |
| 261 | int num_cores = CpuInfo::DetectNumberOfCores(); |
| 262 | RTC_DCHECK_GE(num_cores, 1); |
| 263 | |
| 264 | int video_analyzer_threads = |
| 265 | num_cores - kPeerConnectionUsedThreads - kFrameworkUsedThreads; |
| 266 | if (video_analyzer_threads <= 0) { |
| 267 | video_analyzer_threads = 1; |
| 268 | } |
| 269 | video_analyzer_threads = |
| 270 | std::min(video_analyzer_threads, kMaxVideoAnalyzerThreads); |
| 271 | RTC_LOG(INFO) << "video_analyzer_threads=" << video_analyzer_threads; |
| 272 | |
Artem Titov | 5983585 | 2019-02-27 17:44:13 +0100 | [diff] [blame] | 273 | video_quality_analyzer_injection_helper_->Start(test_case_name_, |
| 274 | video_analyzer_threads); |
| 275 | audio_quality_analyzer_->Start(test_case_name_); |
Mirko Bonadei | ce7a4fb | 2019-02-25 11:45:07 +0100 | [diff] [blame] | 276 | |
| 277 | // Start RTCEventLog recording if requested. |
| 278 | if (alice_->params()->rtc_event_log_path) { |
| 279 | auto alice_rtc_event_log = absl::make_unique<webrtc::RtcEventLogOutputFile>( |
| 280 | alice_->params()->rtc_event_log_path.value()); |
| 281 | alice_->pc()->StartRtcEventLog(std::move(alice_rtc_event_log), |
| 282 | webrtc::RtcEventLog::kImmediateOutput); |
| 283 | } |
| 284 | if (bob_->params()->rtc_event_log_path) { |
| 285 | auto bob_rtc_event_log = absl::make_unique<webrtc::RtcEventLogOutputFile>( |
| 286 | bob_->params()->rtc_event_log_path.value()); |
| 287 | bob_->pc()->StartRtcEventLog(std::move(bob_rtc_event_log), |
| 288 | webrtc::RtcEventLog::kImmediateOutput); |
| 289 | } |
| 290 | |
Artem Titov | ba82e00 | 2019-03-15 15:57:53 +0100 | [diff] [blame] | 291 | // Create a |task_queue_|. |
| 292 | task_queue_ = absl::make_unique<rtc::TaskQueue>("pc_e2e_quality_test"); |
| 293 | // Setup call. |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 294 | signaling_thread->Invoke<void>( |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 295 | RTC_FROM_HERE, |
Mirko Bonadei | 7131880 | 2019-02-18 18:52:43 +0100 | [diff] [blame] | 296 | rtc::Bind(&PeerConnectionE2EQualityTest::SetupCallOnSignalingThread, |
| 297 | this)); |
Artem Titov | ba82e00 | 2019-03-15 15:57:53 +0100 | [diff] [blame] | 298 | { |
| 299 | rtc::CritScope crit(&lock_); |
| 300 | start_time_ = Now(); |
| 301 | while (!scheduled_activities_.empty()) { |
| 302 | PostTask(std::move(scheduled_activities_.front())); |
| 303 | scheduled_activities_.pop(); |
| 304 | } |
| 305 | } |
Mirko Bonadei | 7131880 | 2019-02-18 18:52:43 +0100 | [diff] [blame] | 306 | |
Mirko Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +0100 | [diff] [blame] | 307 | StatsPoller stats_poller({audio_quality_analyzer_.get(), |
| 308 | video_quality_analyzer_injection_helper_.get()}, |
| 309 | {{"alice", alice_.get()}, {"bob", bob_.get()}}); |
| 310 | |
Artem Titov | ba82e00 | 2019-03-15 15:57:53 +0100 | [diff] [blame] | 311 | task_queue_->PostTask([&stats_poller, this]() { |
| 312 | RTC_DCHECK_RUN_ON(task_queue_.get()); |
Sebastian Jansson | cda86dd | 2019-03-11 17:26:36 +0100 | [diff] [blame] | 313 | stats_polling_task_ = |
Artem Titov | ba82e00 | 2019-03-15 15:57:53 +0100 | [diff] [blame] | 314 | RepeatingTaskHandle::Start(task_queue_->Get(), [this, &stats_poller]() { |
| 315 | RTC_DCHECK_RUN_ON(task_queue_.get()); |
Sebastian Jansson | cda86dd | 2019-03-11 17:26:36 +0100 | [diff] [blame] | 316 | stats_poller.PollStatsAndNotifyObservers(); |
| 317 | return kStatsUpdateInterval; |
| 318 | }); |
Mirko Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +0100 | [diff] [blame] | 319 | }); |
| 320 | |
Mirko Bonadei | 7131880 | 2019-02-18 18:52:43 +0100 | [diff] [blame] | 321 | rtc::Event done; |
Mirko Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +0100 | [diff] [blame] | 322 | done.Wait(run_params.run_duration.ms()); |
| 323 | |
| 324 | rtc::Event stats_polling_stopped; |
Artem Titov | ba82e00 | 2019-03-15 15:57:53 +0100 | [diff] [blame] | 325 | task_queue_->PostTask([&stats_polling_stopped, this]() { |
| 326 | RTC_DCHECK_RUN_ON(task_queue_.get()); |
Mirko Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +0100 | [diff] [blame] | 327 | stats_polling_task_.Stop(); |
| 328 | stats_polling_stopped.Set(); |
| 329 | }); |
| 330 | bool no_timeout = stats_polling_stopped.Wait(kStatsPollingStopTimeout.ms()); |
| 331 | RTC_CHECK(no_timeout) << "Failed to stop Stats polling after " |
| 332 | << kStatsPollingStopTimeout.seconds() << " seconds."; |
Mirko Bonadei | 7131880 | 2019-02-18 18:52:43 +0100 | [diff] [blame] | 333 | |
Artem Titov | ba82e00 | 2019-03-15 15:57:53 +0100 | [diff] [blame] | 334 | // Destroy |task_queue_|. It is done to stop all running tasks and prevent |
| 335 | // their access to any call related objects after these objects will be |
| 336 | // destroyed during call tear down. |
| 337 | task_queue_.reset(); |
| 338 | // Tear down the call. |
Mirko Bonadei | 7131880 | 2019-02-18 18:52:43 +0100 | [diff] [blame] | 339 | signaling_thread->Invoke<void>( |
| 340 | RTC_FROM_HERE, |
| 341 | rtc::Bind(&PeerConnectionE2EQualityTest::TearDownCallOnSignalingThread, |
| 342 | this)); |
| 343 | |
Artem Titov | 9f97c9a | 2019-02-08 00:35:13 +0100 | [diff] [blame] | 344 | video_quality_analyzer_injection_helper_->Stop(); |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 345 | |
| 346 | // Ensuring that TestPeers have been destroyed in order to correctly close |
| 347 | // Audio dumps. |
| 348 | RTC_CHECK(!alice_); |
| 349 | RTC_CHECK(!bob_); |
| 350 | // Ensuring that FrameGeneratorCapturerVideoTrackSource and VideoFrameWriter |
| 351 | // are destroyed on the right thread. |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 352 | RTC_CHECK(alice_video_sources_.empty()); |
| 353 | RTC_CHECK(bob_video_sources_.empty()); |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 354 | RTC_CHECK(video_writers_.empty()); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 355 | } |
| 356 | |
Artem Titov | 9a7e721 | 2019-02-28 16:34:17 +0100 | [diff] [blame] | 357 | void PeerConnectionE2EQualityTest::SetDefaultValuesForMissingParams( |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 358 | std::vector<Params*> params) { |
Artem Titov | 3481db2 | 2019-02-28 13:13:15 +0100 | [diff] [blame] | 359 | int video_counter = 0; |
| 360 | int audio_counter = 0; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 361 | std::set<std::string> video_labels; |
Artem Titov | 3481db2 | 2019-02-28 13:13:15 +0100 | [diff] [blame] | 362 | std::set<std::string> audio_labels; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 363 | for (auto* p : params) { |
| 364 | for (auto& video_config : p->video_configs) { |
Artem Titov | 9a7e721 | 2019-02-28 16:34:17 +0100 | [diff] [blame] | 365 | if (!video_config.generator && !video_config.input_file_name && |
| 366 | !video_config.screen_share_config) { |
| 367 | video_config.generator = VideoGeneratorType::kDefault; |
| 368 | } |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 369 | if (!video_config.stream_label) { |
| 370 | std::string label; |
| 371 | do { |
Artem Titov | 3481db2 | 2019-02-28 13:13:15 +0100 | [diff] [blame] | 372 | label = "_auto_video_stream_label_" + std::to_string(video_counter); |
| 373 | ++video_counter; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 374 | } while (!video_labels.insert(label).second); |
| 375 | video_config.stream_label = label; |
| 376 | } |
| 377 | } |
Artem Titov | 3481db2 | 2019-02-28 13:13:15 +0100 | [diff] [blame] | 378 | if (p->audio_config) { |
| 379 | if (!p->audio_config->stream_label) { |
| 380 | std::string label; |
| 381 | do { |
| 382 | label = "_auto_audio_stream_label_" + std::to_string(audio_counter); |
| 383 | ++audio_counter; |
| 384 | } while (!audio_labels.insert(label).second); |
| 385 | p->audio_config->stream_label = label; |
| 386 | } |
| 387 | } |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 388 | } |
| 389 | } |
| 390 | |
| 391 | void PeerConnectionE2EQualityTest::ValidateParams(std::vector<Params*> params) { |
| 392 | std::set<std::string> video_labels; |
Artem Titov | 3481db2 | 2019-02-28 13:13:15 +0100 | [diff] [blame] | 393 | std::set<std::string> audio_labels; |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 394 | int media_streams_count = 0; |
| 395 | |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 396 | for (Params* p : params) { |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 397 | if (p->audio_config) { |
| 398 | media_streams_count++; |
| 399 | } |
| 400 | media_streams_count += p->video_configs.size(); |
| 401 | |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 402 | // Validate that each video config has exactly one of |generator|, |
| 403 | // |input_file_name| or |screen_share_config| set. Also validate that all |
| 404 | // video stream labels are unique. |
| 405 | for (auto& video_config : p->video_configs) { |
| 406 | RTC_CHECK(video_config.stream_label); |
| 407 | bool inserted = |
| 408 | video_labels.insert(video_config.stream_label.value()).second; |
| 409 | RTC_CHECK(inserted) << "Duplicate video_config.stream_label=" |
| 410 | << video_config.stream_label.value(); |
| 411 | RTC_CHECK(video_config.generator || video_config.input_file_name || |
| 412 | video_config.screen_share_config) |
| 413 | << VideoConfigSourcePresenceToString(video_config); |
| 414 | RTC_CHECK(!(video_config.input_file_name && video_config.generator)) |
| 415 | << VideoConfigSourcePresenceToString(video_config); |
| 416 | RTC_CHECK( |
| 417 | !(video_config.input_file_name && video_config.screen_share_config)) |
| 418 | << VideoConfigSourcePresenceToString(video_config); |
| 419 | RTC_CHECK(!(video_config.screen_share_config && video_config.generator)) |
| 420 | << VideoConfigSourcePresenceToString(video_config); |
| 421 | } |
| 422 | if (p->audio_config) { |
Artem Titov | 3481db2 | 2019-02-28 13:13:15 +0100 | [diff] [blame] | 423 | bool inserted = |
| 424 | audio_labels.insert(p->audio_config->stream_label.value()).second; |
| 425 | RTC_CHECK(inserted) << "Duplicate audio_config.stream_label=" |
| 426 | << p->audio_config->stream_label.value(); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 427 | // Check that if mode input file name specified only if mode is kFile. |
| 428 | if (p->audio_config.value().mode == AudioConfig::Mode::kGenerated) { |
| 429 | RTC_CHECK(!p->audio_config.value().input_file_name); |
| 430 | } |
| 431 | if (p->audio_config.value().mode == AudioConfig::Mode::kFile) { |
| 432 | RTC_CHECK(p->audio_config.value().input_file_name); |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame^] | 433 | RTC_CHECK( |
| 434 | test::FileExists(p->audio_config.value().input_file_name.value())); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 435 | } |
| 436 | } |
| 437 | } |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 438 | |
| 439 | RTC_CHECK_GT(media_streams_count, 0) << "No media in the call."; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 440 | } |
| 441 | |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 442 | void PeerConnectionE2EQualityTest::SetupVideoSink( |
| 443 | rtc::scoped_refptr<RtpTransceiverInterface> transceiver, |
| 444 | std::vector<VideoConfig> remote_video_configs) { |
| 445 | const rtc::scoped_refptr<MediaStreamTrackInterface>& track = |
| 446 | transceiver->receiver()->track(); |
| 447 | if (track->kind() != MediaStreamTrackInterface::kVideoKind) { |
| 448 | return; |
| 449 | } |
| 450 | |
Artem Titov | 7c55415 | 2019-02-28 10:25:52 +0100 | [diff] [blame] | 451 | RTC_CHECK_EQ(transceiver->receiver()->stream_ids().size(), 1); |
| 452 | std::string stream_label = transceiver->receiver()->stream_ids().front(); |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 453 | VideoConfig* video_config = nullptr; |
| 454 | for (auto& config : remote_video_configs) { |
Artem Titov | 7c55415 | 2019-02-28 10:25:52 +0100 | [diff] [blame] | 455 | if (config.stream_label == stream_label) { |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 456 | video_config = &config; |
| 457 | break; |
| 458 | } |
| 459 | } |
| 460 | RTC_CHECK(video_config); |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame^] | 461 | test::VideoFrameWriter* writer = MaybeCreateVideoWriter( |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 462 | video_config->output_dump_file_name, *video_config); |
| 463 | // It is safe to cast here, because it is checked above that |
| 464 | // track->kind() is kVideoKind. |
| 465 | auto* video_track = static_cast<VideoTrackInterface*>(track.get()); |
| 466 | std::unique_ptr<rtc::VideoSinkInterface<VideoFrame>> video_sink = |
| 467 | video_quality_analyzer_injection_helper_->CreateVideoSink(writer); |
| 468 | video_track->AddOrUpdateSink(video_sink.get(), rtc::VideoSinkWants()); |
| 469 | output_video_sinks_.push_back(std::move(video_sink)); |
| 470 | } |
| 471 | |
Mirko Bonadei | 7131880 | 2019-02-18 18:52:43 +0100 | [diff] [blame] | 472 | void PeerConnectionE2EQualityTest::SetupCallOnSignalingThread() { |
Artem Titov | 7c55415 | 2019-02-28 10:25:52 +0100 | [diff] [blame] | 473 | // We need receive-only transceivers for Bob's media stream, so there will |
| 474 | // be media section in SDP for that streams in Alice's offer, because it is |
| 475 | // forbidden to add new media sections in answer in Unified Plan. |
| 476 | RtpTransceiverInit receive_only_transceiver_init; |
| 477 | receive_only_transceiver_init.direction = RtpTransceiverDirection::kRecvOnly; |
| 478 | if (bob_->params()->audio_config) { |
| 479 | // Setup receive audio transceiver if Bob has audio to send. If we'll need |
| 480 | // multiple audio streams, then we need transceiver for each Bob's audio |
| 481 | // stream. |
| 482 | alice_->AddTransceiver(cricket::MediaType::MEDIA_TYPE_AUDIO, |
| 483 | receive_only_transceiver_init); |
| 484 | } |
| 485 | for (size_t i = 0; i < bob_->params()->video_configs.size(); ++i) { |
| 486 | alice_->AddTransceiver(cricket::MediaType::MEDIA_TYPE_VIDEO, |
| 487 | receive_only_transceiver_init); |
| 488 | } |
| 489 | // Then add media for Alice and Bob |
| 490 | alice_video_sources_ = MaybeAddMedia(alice_.get()); |
| 491 | bob_video_sources_ = MaybeAddMedia(bob_.get()); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 492 | |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 493 | SetupCall(); |
Mirko Bonadei | 7131880 | 2019-02-18 18:52:43 +0100 | [diff] [blame] | 494 | } |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 495 | |
Mirko Bonadei | 7131880 | 2019-02-18 18:52:43 +0100 | [diff] [blame] | 496 | void PeerConnectionE2EQualityTest::TearDownCallOnSignalingThread() { |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 497 | TearDownCall(); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 498 | } |
| 499 | |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 500 | std::vector<rtc::scoped_refptr<FrameGeneratorCapturerVideoTrackSource>> |
Artem Titov | 7c55415 | 2019-02-28 10:25:52 +0100 | [diff] [blame] | 501 | PeerConnectionE2EQualityTest::MaybeAddMedia(TestPeer* peer) { |
| 502 | MaybeAddAudio(peer); |
| 503 | return MaybeAddVideo(peer); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 504 | } |
| 505 | |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 506 | std::vector<rtc::scoped_refptr<FrameGeneratorCapturerVideoTrackSource>> |
Artem Titov | 7c55415 | 2019-02-28 10:25:52 +0100 | [diff] [blame] | 507 | PeerConnectionE2EQualityTest::MaybeAddVideo(TestPeer* peer) { |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 508 | // Params here valid because of pre-run validation. |
| 509 | Params* params = peer->params(); |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 510 | std::vector<rtc::scoped_refptr<FrameGeneratorCapturerVideoTrackSource>> out; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 511 | for (auto video_config : params->video_configs) { |
| 512 | // Create video generator. |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame^] | 513 | std::unique_ptr<test::FrameGenerator> frame_generator = |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 514 | CreateFrameGenerator(video_config); |
| 515 | |
| 516 | // Wrap it to inject video quality analyzer and enable dump of input video |
| 517 | // if required. |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame^] | 518 | test::VideoFrameWriter* writer = |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 519 | MaybeCreateVideoWriter(video_config.input_dump_file_name, video_config); |
| 520 | frame_generator = |
| 521 | video_quality_analyzer_injection_helper_->WrapFrameGenerator( |
| 522 | video_config.stream_label.value(), std::move(frame_generator), |
| 523 | writer); |
| 524 | |
| 525 | // Setup FrameGenerator into peer connection. |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame^] | 526 | std::unique_ptr<test::FrameGeneratorCapturer> capturer = |
| 527 | absl::WrapUnique(test::FrameGeneratorCapturer::Create( |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 528 | std::move(frame_generator), video_config.fps, clock_)); |
| 529 | rtc::scoped_refptr<FrameGeneratorCapturerVideoTrackSource> source = |
| 530 | new rtc::RefCountedObject<FrameGeneratorCapturerVideoTrackSource>( |
| 531 | move(capturer)); |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 532 | out.push_back(source); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 533 | RTC_LOG(INFO) << "Adding video with video_config.stream_label=" |
| 534 | << video_config.stream_label.value(); |
| 535 | rtc::scoped_refptr<VideoTrackInterface> track = |
| 536 | peer->pc_factory()->CreateVideoTrack(video_config.stream_label.value(), |
| 537 | source); |
Artem Titov | 7c55415 | 2019-02-28 10:25:52 +0100 | [diff] [blame] | 538 | peer->AddTrack(track, {video_config.stream_label.value()}); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 539 | } |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 540 | return out; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 541 | } |
| 542 | |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame^] | 543 | std::unique_ptr<test::FrameGenerator> |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 544 | PeerConnectionE2EQualityTest::CreateFrameGenerator( |
| 545 | const VideoConfig& video_config) { |
| 546 | if (video_config.generator) { |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame^] | 547 | absl::optional<test::FrameGenerator::OutputType> frame_generator_type = |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 548 | absl::nullopt; |
| 549 | if (video_config.generator == VideoGeneratorType::kDefault) { |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame^] | 550 | frame_generator_type = test::FrameGenerator::OutputType::I420; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 551 | } else if (video_config.generator == VideoGeneratorType::kI420A) { |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame^] | 552 | frame_generator_type = test::FrameGenerator::OutputType::I420A; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 553 | } else if (video_config.generator == VideoGeneratorType::kI010) { |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame^] | 554 | frame_generator_type = test::FrameGenerator::OutputType::I010; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 555 | } |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame^] | 556 | return test::FrameGenerator::CreateSquareGenerator( |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 557 | static_cast<int>(video_config.width), |
| 558 | static_cast<int>(video_config.height), frame_generator_type, |
| 559 | absl::nullopt); |
| 560 | } |
| 561 | if (video_config.input_file_name) { |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame^] | 562 | return test::FrameGenerator::CreateFromYuvFile( |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 563 | std::vector<std::string>(/*count=*/1, |
| 564 | video_config.input_file_name.value()), |
| 565 | video_config.width, video_config.height, /*frame_repeat_count=*/1); |
| 566 | } |
| 567 | if (video_config.screen_share_config) { |
| 568 | // TODO(titovartem) implement screen share support |
| 569 | // (http://bugs.webrtc.org/10138) |
| 570 | RTC_NOTREACHED() << "Screen share is not implemented"; |
| 571 | return nullptr; |
| 572 | } |
| 573 | RTC_NOTREACHED() << "Unsupported video_config input source"; |
| 574 | return nullptr; |
| 575 | } |
| 576 | |
Artem Titov | 7c55415 | 2019-02-28 10:25:52 +0100 | [diff] [blame] | 577 | void PeerConnectionE2EQualityTest::MaybeAddAudio(TestPeer* peer) { |
| 578 | if (!peer->params()->audio_config) { |
| 579 | return; |
| 580 | } |
Artem Titov | 3481db2 | 2019-02-28 13:13:15 +0100 | [diff] [blame] | 581 | const AudioConfig& audio_config = peer->params()->audio_config.value(); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 582 | rtc::scoped_refptr<webrtc::AudioSourceInterface> source = |
Artem Titov | 3481db2 | 2019-02-28 13:13:15 +0100 | [diff] [blame] | 583 | peer->pc_factory()->CreateAudioSource(audio_config.audio_options); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 584 | rtc::scoped_refptr<AudioTrackInterface> track = |
Artem Titov | 3481db2 | 2019-02-28 13:13:15 +0100 | [diff] [blame] | 585 | peer->pc_factory()->CreateAudioTrack(*audio_config.stream_label, source); |
| 586 | peer->AddTrack(track, {*audio_config.stream_label}); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 587 | } |
| 588 | |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 589 | void PeerConnectionE2EQualityTest::SetupCall() { |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 590 | // Connect peers. |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 591 | ASSERT_TRUE(alice_->ExchangeOfferAnswerWith(bob_.get())); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 592 | // Do the SDP negotiation, and also exchange ice candidates. |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 593 | ASSERT_EQ_WAIT(alice_->signaling_state(), PeerConnectionInterface::kStable, |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 594 | kDefaultTimeoutMs); |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 595 | ASSERT_TRUE_WAIT(alice_->IsIceGatheringDone(), kDefaultTimeoutMs); |
| 596 | ASSERT_TRUE_WAIT(bob_->IsIceGatheringDone(), kDefaultTimeoutMs); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 597 | |
| 598 | // Connect an ICE candidate pairs. |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 599 | ASSERT_TRUE(bob_->AddIceCandidates(alice_->observer()->GetAllCandidates())); |
| 600 | ASSERT_TRUE(alice_->AddIceCandidates(bob_->observer()->GetAllCandidates())); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 601 | // This means that ICE and DTLS are connected. |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 602 | ASSERT_TRUE_WAIT(bob_->IsIceConnected(), kDefaultTimeoutMs); |
| 603 | ASSERT_TRUE_WAIT(alice_->IsIceConnected(), kDefaultTimeoutMs); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 604 | } |
| 605 | |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 606 | void PeerConnectionE2EQualityTest::StartVideo( |
| 607 | const std::vector< |
| 608 | rtc::scoped_refptr<FrameGeneratorCapturerVideoTrackSource>>& sources) { |
| 609 | for (auto& source : sources) { |
| 610 | if (source->state() != MediaSourceInterface::SourceState::kLive) { |
| 611 | source->Start(); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 612 | } |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 613 | } |
| 614 | } |
| 615 | |
| 616 | void PeerConnectionE2EQualityTest::TearDownCall() { |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 617 | for (const auto& video_source : alice_video_sources_) { |
| 618 | video_source->Stop(); |
| 619 | } |
| 620 | for (const auto& video_source : bob_video_sources_) { |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 621 | video_source->Stop(); |
| 622 | } |
| 623 | |
| 624 | alice_->pc()->Close(); |
| 625 | bob_->pc()->Close(); |
| 626 | |
| 627 | for (const auto& video_writer : video_writers_) { |
| 628 | video_writer->Close(); |
| 629 | } |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 630 | |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 631 | alice_video_sources_.clear(); |
| 632 | bob_video_sources_.clear(); |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 633 | video_writers_.clear(); |
| 634 | alice_.reset(); |
| 635 | bob_.reset(); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 636 | } |
| 637 | |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame^] | 638 | test::VideoFrameWriter* PeerConnectionE2EQualityTest::MaybeCreateVideoWriter( |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 639 | absl::optional<std::string> file_name, |
| 640 | const VideoConfig& config) { |
| 641 | if (!file_name) { |
| 642 | return nullptr; |
| 643 | } |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame^] | 644 | auto video_writer = absl::make_unique<test::VideoFrameWriter>( |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 645 | file_name.value(), config.width, config.height, config.fps); |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame^] | 646 | test::VideoFrameWriter* out = video_writer.get(); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 647 | video_writers_.push_back(std::move(video_writer)); |
| 648 | return out; |
| 649 | } |
| 650 | |
Artem Titov | ba82e00 | 2019-03-15 15:57:53 +0100 | [diff] [blame] | 651 | Timestamp PeerConnectionE2EQualityTest::Now() const { |
| 652 | return Timestamp::us(clock_->TimeInMicroseconds()); |
| 653 | } |
| 654 | |
| 655 | PeerConnectionE2EQualityTest::ScheduledActivity::ScheduledActivity( |
| 656 | TimeDelta initial_delay_since_start, |
| 657 | absl::optional<TimeDelta> interval, |
| 658 | std::function<void(TimeDelta)> func) |
| 659 | : initial_delay_since_start(initial_delay_since_start), |
| 660 | interval(std::move(interval)), |
| 661 | func(std::move(func)) {} |
| 662 | |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame^] | 663 | } // namespace webrtc_pc_e2e |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 664 | } // namespace webrtc |