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> |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 13 | #include <memory> |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 14 | #include <set> |
| 15 | #include <utility> |
| 16 | |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 17 | #include "api/jsep.h" |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 18 | #include "api/media_stream_interface.h" |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 19 | #include "api/peer_connection_interface.h" |
Danil Chapovalov | 83bbe91 | 2019-08-07 12:24:53 +0200 | [diff] [blame] | 20 | #include "api/rtc_event_log/rtc_event_log.h" |
Niels Möller | d8b9ed7 | 2019-05-08 13:53:51 +0200 | [diff] [blame] | 21 | #include "api/rtc_event_log_output_file.h" |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 22 | #include "api/scoped_refptr.h" |
Danil Chapovalov | d0e0ed8 | 2019-04-18 14:48:24 +0200 | [diff] [blame] | 23 | #include "api/task_queue/default_task_queue_factory.h" |
Artem Titov | d57628f | 2019-03-22 12:34:25 +0100 | [diff] [blame] | 24 | #include "api/test/video_quality_analyzer_interface.h" |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 25 | #include "api/units/time_delta.h" |
Artem Titov | f65a89b | 2019-05-07 11:56:44 +0200 | [diff] [blame] | 26 | #include "pc/sdp_utils.h" |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 27 | #include "pc/test/mock_peer_connection_observers.h" |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 28 | #include "rtc_base/bind.h" |
| 29 | #include "rtc_base/gunit.h" |
Mirko Bonadei | 7131880 | 2019-02-18 18:52:43 +0100 | [diff] [blame] | 30 | #include "rtc_base/numerics/safe_conversions.h" |
Artem Titov | 9f97c9a | 2019-02-08 00:35:13 +0100 | [diff] [blame] | 31 | #include "system_wrappers/include/cpu_info.h" |
Artem Titov | 2370242 | 2019-05-27 15:28:30 +0200 | [diff] [blame] | 32 | #include "system_wrappers/include/field_trial.h" |
Artem Titov | 9afdddf | 2019-10-10 13:29:03 +0200 | [diff] [blame] | 33 | #include "test/frame_generator_capturer.h" |
Mirko Bonadei | 3830d9b | 2019-02-28 14:07:56 +0100 | [diff] [blame] | 34 | #include "test/pc/e2e/analyzer/audio/default_audio_quality_analyzer.h" |
Artem Titov | 859abef | 2019-03-01 11:11:09 +0100 | [diff] [blame] | 35 | #include "test/pc/e2e/analyzer/video/default_video_quality_analyzer.h" |
Mirko Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +0100 | [diff] [blame] | 36 | #include "test/pc/e2e/stats_poller.h" |
Artem Titov | 9afdddf | 2019-10-10 13:29:03 +0200 | [diff] [blame] | 37 | #include "test/platform_video_capturer.h" |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 38 | #include "test/testsupport/file_utils.h" |
| 39 | |
| 40 | namespace webrtc { |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame] | 41 | namespace webrtc_pc_e2e { |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 42 | namespace { |
| 43 | |
| 44 | using VideoConfig = PeerConnectionE2EQualityTestFixture::VideoConfig; |
| 45 | |
| 46 | constexpr int kDefaultTimeoutMs = 10000; |
| 47 | constexpr char kSignalThreadName[] = "signaling_thread"; |
Artem Titov | 9f97c9a | 2019-02-08 00:35:13 +0100 | [diff] [blame] | 48 | // 1 signaling, 2 network, 2 worker and 2 extra for codecs etc. |
| 49 | constexpr int kPeerConnectionUsedThreads = 7; |
| 50 | // Framework has extra thread for network layer and extra thread for peer |
| 51 | // connection stats polling. |
| 52 | constexpr int kFrameworkUsedThreads = 2; |
| 53 | constexpr int kMaxVideoAnalyzerThreads = 8; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 54 | |
Mirko Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +0100 | [diff] [blame] | 55 | constexpr TimeDelta kStatsUpdateInterval = TimeDelta::Seconds<1>(); |
Mirko Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +0100 | [diff] [blame] | 56 | |
Artem Titov | 4d29ef0 | 2019-05-20 10:43:16 +0200 | [diff] [blame] | 57 | constexpr TimeDelta kAliveMessageLogInterval = TimeDelta::Seconds<30>(); |
| 58 | |
Artem Titov | 1685059 | 2019-07-10 14:34:02 +0200 | [diff] [blame] | 59 | constexpr int kQuickTestModeRunDurationMs = 100; |
| 60 | |
Artem Titov | 2370242 | 2019-05-27 15:28:30 +0200 | [diff] [blame] | 61 | // Field trials to enable Flex FEC advertising and receiving. |
| 62 | constexpr char kFlexFecEnabledFieldTrials[] = |
| 63 | "WebRTC-FlexFEC-03-Advertised/Enabled/WebRTC-FlexFEC-03/Enabled/"; |
| 64 | |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 65 | std::string VideoConfigSourcePresenceToString(const VideoConfig& video_config) { |
| 66 | char buf[1024]; |
| 67 | rtc::SimpleStringBuilder builder(buf); |
| 68 | builder << "video_config.generator=" << video_config.generator.has_value() |
| 69 | << "; video_config.input_file_name=" |
| 70 | << video_config.input_file_name.has_value() |
| 71 | << "; video_config.screen_share_config=" |
Artem Titov | 9afdddf | 2019-10-10 13:29:03 +0200 | [diff] [blame] | 72 | << video_config.screen_share_config.has_value() |
| 73 | << "; video_config.capturing_device_index=" |
| 74 | << video_config.capturing_device_index.has_value() << ";"; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 75 | return builder.str(); |
| 76 | } |
| 77 | |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 78 | class FixturePeerConnectionObserver : public MockPeerConnectionObserver { |
| 79 | public: |
| 80 | // |on_track_callback| will be called when any new track will be added to peer |
| 81 | // connection. |
| 82 | // |on_connected_callback| will be called when peer connection will come to |
| 83 | // either connected or completed state. Client should notice that in the case |
| 84 | // of reconnect this callback can be called again, so it should be tolerant |
| 85 | // to such behavior. |
| 86 | FixturePeerConnectionObserver( |
| 87 | std::function<void(rtc::scoped_refptr<RtpTransceiverInterface>)> |
| 88 | on_track_callback, |
| 89 | std::function<void()> on_connected_callback) |
| 90 | : on_track_callback_(std::move(on_track_callback)), |
| 91 | on_connected_callback_(std::move(on_connected_callback)) {} |
| 92 | |
| 93 | void OnTrack( |
| 94 | rtc::scoped_refptr<RtpTransceiverInterface> transceiver) override { |
| 95 | MockPeerConnectionObserver::OnTrack(transceiver); |
| 96 | on_track_callback_(transceiver); |
| 97 | } |
| 98 | |
| 99 | void OnIceConnectionChange( |
| 100 | PeerConnectionInterface::IceConnectionState new_state) override { |
| 101 | MockPeerConnectionObserver::OnIceConnectionChange(new_state); |
| 102 | if (ice_connected_) { |
| 103 | on_connected_callback_(); |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | private: |
| 108 | std::function<void(rtc::scoped_refptr<RtpTransceiverInterface>)> |
| 109 | on_track_callback_; |
| 110 | std::function<void()> on_connected_callback_; |
| 111 | }; |
| 112 | |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 113 | } // namespace |
| 114 | |
| 115 | PeerConnectionE2EQualityTest::PeerConnectionE2EQualityTest( |
Artem Titov | 5983585 | 2019-02-27 17:44:13 +0100 | [diff] [blame] | 116 | std::string test_case_name, |
Mirko Bonadei | f5d8808 | 2019-02-20 16:16:54 +0100 | [diff] [blame] | 117 | std::unique_ptr<AudioQualityAnalyzerInterface> audio_quality_analyzer, |
| 118 | std::unique_ptr<VideoQualityAnalyzerInterface> video_quality_analyzer) |
Artem Titov | 5983585 | 2019-02-27 17:44:13 +0100 | [diff] [blame] | 119 | : clock_(Clock::GetRealTimeClock()), |
Danil Chapovalov | d0e0ed8 | 2019-04-18 14:48:24 +0200 | [diff] [blame] | 120 | task_queue_factory_(CreateDefaultTaskQueueFactory()), |
Artem Titov | ba82e00 | 2019-03-15 15:57:53 +0100 | [diff] [blame] | 121 | test_case_name_(std::move(test_case_name)) { |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 122 | // Create default video quality analyzer. We will always create an analyzer, |
| 123 | // even if there are no video streams, because it will be installed into video |
| 124 | // encoder/decoder factories. |
Mirko Bonadei | f5d8808 | 2019-02-20 16:16:54 +0100 | [diff] [blame] | 125 | if (video_quality_analyzer == nullptr) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 126 | video_quality_analyzer = std::make_unique<DefaultVideoQualityAnalyzer>(); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 127 | } |
| 128 | encoded_image_id_controller_ = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 129 | std::make_unique<SingleProcessEncodedImageDataInjector>(); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 130 | video_quality_analyzer_injection_helper_ = |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 131 | std::make_unique<VideoQualityAnalyzerInjectionHelper>( |
Mirko Bonadei | f5d8808 | 2019-02-20 16:16:54 +0100 | [diff] [blame] | 132 | std::move(video_quality_analyzer), encoded_image_id_controller_.get(), |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 133 | encoded_image_id_controller_.get()); |
Mirko Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +0100 | [diff] [blame] | 134 | |
| 135 | if (audio_quality_analyzer == nullptr) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 136 | audio_quality_analyzer = std::make_unique<DefaultAudioQualityAnalyzer>(); |
Mirko Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +0100 | [diff] [blame] | 137 | } |
| 138 | audio_quality_analyzer_.swap(audio_quality_analyzer); |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 139 | } |
| 140 | |
Artem Titov | ba82e00 | 2019-03-15 15:57:53 +0100 | [diff] [blame] | 141 | void PeerConnectionE2EQualityTest::ExecuteAt( |
| 142 | TimeDelta target_time_since_start, |
| 143 | std::function<void(TimeDelta)> func) { |
| 144 | ExecuteTask(target_time_since_start, absl::nullopt, func); |
| 145 | } |
| 146 | |
| 147 | void PeerConnectionE2EQualityTest::ExecuteEvery( |
| 148 | TimeDelta initial_delay_since_start, |
| 149 | TimeDelta interval, |
| 150 | std::function<void(TimeDelta)> func) { |
| 151 | ExecuteTask(initial_delay_since_start, interval, func); |
| 152 | } |
| 153 | |
| 154 | void PeerConnectionE2EQualityTest::ExecuteTask( |
| 155 | TimeDelta initial_delay_since_start, |
| 156 | absl::optional<TimeDelta> interval, |
| 157 | std::function<void(TimeDelta)> func) { |
| 158 | RTC_CHECK(initial_delay_since_start.IsFinite() && |
| 159 | initial_delay_since_start >= TimeDelta::Zero()); |
| 160 | RTC_CHECK(!interval || |
| 161 | (interval->IsFinite() && *interval > TimeDelta::Zero())); |
| 162 | rtc::CritScope crit(&lock_); |
| 163 | ScheduledActivity activity(initial_delay_since_start, interval, func); |
| 164 | if (start_time_.IsInfinite()) { |
| 165 | scheduled_activities_.push(std::move(activity)); |
| 166 | } else { |
| 167 | PostTask(std::move(activity)); |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | void PeerConnectionE2EQualityTest::PostTask(ScheduledActivity activity) { |
| 172 | // Because start_time_ will never change at this point copy it to local |
| 173 | // variable to capture in in lambda without requirement to hold a lock. |
| 174 | Timestamp start_time = start_time_; |
| 175 | |
| 176 | TimeDelta remaining_delay = |
| 177 | activity.initial_delay_since_start == TimeDelta::Zero() |
| 178 | ? TimeDelta::Zero() |
| 179 | : activity.initial_delay_since_start - (Now() - start_time_); |
| 180 | if (remaining_delay < TimeDelta::Zero()) { |
| 181 | RTC_LOG(WARNING) << "Executing late task immediately, late by=" |
| 182 | << ToString(remaining_delay.Abs()); |
| 183 | remaining_delay = TimeDelta::Zero(); |
| 184 | } |
| 185 | |
| 186 | if (activity.interval) { |
| 187 | if (remaining_delay == TimeDelta::Zero()) { |
| 188 | repeating_task_handles_.push_back(RepeatingTaskHandle::Start( |
| 189 | task_queue_->Get(), [activity, start_time, this]() { |
| 190 | activity.func(Now() - start_time); |
| 191 | return *activity.interval; |
| 192 | })); |
| 193 | return; |
| 194 | } |
| 195 | repeating_task_handles_.push_back(RepeatingTaskHandle::DelayedStart( |
| 196 | task_queue_->Get(), remaining_delay, [activity, start_time, this]() { |
| 197 | activity.func(Now() - start_time); |
| 198 | return *activity.interval; |
| 199 | })); |
| 200 | return; |
| 201 | } |
| 202 | |
| 203 | if (remaining_delay == TimeDelta::Zero()) { |
| 204 | task_queue_->PostTask( |
| 205 | [activity, start_time, this]() { activity.func(Now() - start_time); }); |
| 206 | return; |
| 207 | } |
| 208 | |
| 209 | task_queue_->PostDelayedTask( |
| 210 | [activity, start_time, this]() { activity.func(Now() - start_time); }, |
| 211 | remaining_delay.ms()); |
| 212 | } |
| 213 | |
Artem Titov | 1845922 | 2019-04-24 11:09:35 +0200 | [diff] [blame] | 214 | void PeerConnectionE2EQualityTest::AddQualityMetricsReporter( |
| 215 | std::unique_ptr<QualityMetricsReporter> quality_metrics_reporter) { |
| 216 | quality_metrics_reporters_.push_back(std::move(quality_metrics_reporter)); |
| 217 | } |
| 218 | |
Artem Titov | d09bc55 | 2019-03-20 11:18:58 +0100 | [diff] [blame] | 219 | void PeerConnectionE2EQualityTest::AddPeer( |
| 220 | rtc::Thread* network_thread, |
| 221 | rtc::NetworkManager* network_manager, |
| 222 | rtc::FunctionView<void(PeerConfigurer*)> configurer) { |
| 223 | peer_configurations_.push_back( |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 224 | std::make_unique<PeerConfigurerImpl>(network_thread, network_manager)); |
Artem Titov | d09bc55 | 2019-03-20 11:18:58 +0100 | [diff] [blame] | 225 | configurer(peer_configurations_.back().get()); |
| 226 | } |
| 227 | |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 228 | void PeerConnectionE2EQualityTest::Run(RunParams run_params) { |
Artem Titov | d09bc55 | 2019-03-20 11:18:58 +0100 | [diff] [blame] | 229 | RTC_CHECK_EQ(peer_configurations_.size(), 2) |
| 230 | << "Only peer to peer calls are allowed, please add 2 peers"; |
| 231 | |
| 232 | std::unique_ptr<Params> alice_params = |
| 233 | peer_configurations_[0]->ReleaseParams(); |
| 234 | std::unique_ptr<InjectableComponents> alice_components = |
| 235 | peer_configurations_[0]->ReleaseComponents(); |
| 236 | std::unique_ptr<Params> bob_params = peer_configurations_[1]->ReleaseParams(); |
| 237 | std::unique_ptr<InjectableComponents> bob_components = |
| 238 | peer_configurations_[1]->ReleaseComponents(); |
| 239 | peer_configurations_.clear(); |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 240 | |
Artem Titov | 9a7e721 | 2019-02-28 16:34:17 +0100 | [diff] [blame] | 241 | SetDefaultValuesForMissingParams({alice_params.get(), bob_params.get()}); |
Artem Titov | ade945d | 2019-04-02 18:31:48 +0200 | [diff] [blame] | 242 | ValidateParams(run_params, {alice_params.get(), bob_params.get()}); |
Artem Titov | 2370242 | 2019-05-27 15:28:30 +0200 | [diff] [blame] | 243 | SetupRequiredFieldTrials(run_params); |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 244 | |
| 245 | // Print test summary |
| 246 | RTC_LOG(INFO) |
| 247 | << "Media quality test: Alice will make a call to Bob with media video=" |
| 248 | << !alice_params->video_configs.empty() |
| 249 | << "; audio=" << alice_params->audio_config.has_value() |
| 250 | << ". Bob will respond with media video=" |
| 251 | << !bob_params->video_configs.empty() |
| 252 | << "; audio=" << bob_params->audio_config.has_value(); |
| 253 | |
| 254 | const std::unique_ptr<rtc::Thread> signaling_thread = rtc::Thread::Create(); |
| 255 | signaling_thread->SetName(kSignalThreadName, nullptr); |
| 256 | signaling_thread->Start(); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 257 | |
Artem Titov | 70f80e5 | 2019-04-12 13:13:39 +0200 | [diff] [blame] | 258 | // Create a |task_queue_|. |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 259 | task_queue_ = std::make_unique<TaskQueueForTest>("pc_e2e_quality_test"); |
Artem Titov | 70f80e5 | 2019-04-12 13:13:39 +0200 | [diff] [blame] | 260 | |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 261 | // Create call participants: Alice and Bob. |
| 262 | // Audio streams are intercepted in AudioDeviceModule, so if it is required to |
| 263 | // catch output of Alice's stream, Alice's output_dump_file_name should be |
| 264 | // passed to Bob's TestPeer setup as audio output file name. |
Artem Titov | bc558ce | 2019-07-08 19:13:21 +0200 | [diff] [blame] | 265 | absl::optional<TestPeer::RemotePeerAudioConfig> alice_remote_audio_config = |
| 266 | TestPeer::CreateRemoteAudioConfig(bob_params->audio_config); |
| 267 | absl::optional<TestPeer::RemotePeerAudioConfig> bob_remote_audio_config = |
| 268 | TestPeer::CreateRemoteAudioConfig(alice_params->audio_config); |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 269 | // Copy Alice and Bob video configs to correctly pass them into lambdas. |
| 270 | std::vector<VideoConfig> alice_video_configs = alice_params->video_configs; |
| 271 | std::vector<VideoConfig> bob_video_configs = bob_params->video_configs; |
| 272 | |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 273 | alice_ = TestPeer::CreateTestPeer( |
| 274 | std::move(alice_components), std::move(alice_params), |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 275 | std::make_unique<FixturePeerConnectionObserver>( |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 276 | [this, bob_video_configs]( |
| 277 | rtc::scoped_refptr<RtpTransceiverInterface> transceiver) { |
Mirko Bonadei | f948eb6 | 2019-04-05 15:13:23 +0200 | [diff] [blame] | 278 | OnTrackCallback(transceiver, bob_video_configs); |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 279 | }, |
| 280 | [this]() { StartVideo(alice_video_sources_); }), |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 281 | video_quality_analyzer_injection_helper_.get(), signaling_thread.get(), |
Artem Titov | bc558ce | 2019-07-08 19:13:21 +0200 | [diff] [blame] | 282 | alice_remote_audio_config, run_params.video_encoder_bitrate_multiplier, |
Artem Titov | 728a0ee | 2019-08-20 13:36:35 +0200 | [diff] [blame] | 283 | run_params.echo_emulation_config, task_queue_.get()); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 284 | bob_ = TestPeer::CreateTestPeer( |
| 285 | std::move(bob_components), std::move(bob_params), |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 286 | std::make_unique<FixturePeerConnectionObserver>( |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 287 | [this, alice_video_configs]( |
| 288 | rtc::scoped_refptr<RtpTransceiverInterface> transceiver) { |
Mirko Bonadei | f948eb6 | 2019-04-05 15:13:23 +0200 | [diff] [blame] | 289 | OnTrackCallback(transceiver, alice_video_configs); |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 290 | }, |
| 291 | [this]() { StartVideo(bob_video_sources_); }), |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 292 | video_quality_analyzer_injection_helper_.get(), signaling_thread.get(), |
Artem Titov | bc558ce | 2019-07-08 19:13:21 +0200 | [diff] [blame] | 293 | bob_remote_audio_config, run_params.video_encoder_bitrate_multiplier, |
Artem Titov | 728a0ee | 2019-08-20 13:36:35 +0200 | [diff] [blame] | 294 | run_params.echo_emulation_config, task_queue_.get()); |
Artem Titov | 9f97c9a | 2019-02-08 00:35:13 +0100 | [diff] [blame] | 295 | |
| 296 | int num_cores = CpuInfo::DetectNumberOfCores(); |
| 297 | RTC_DCHECK_GE(num_cores, 1); |
| 298 | |
| 299 | int video_analyzer_threads = |
| 300 | num_cores - kPeerConnectionUsedThreads - kFrameworkUsedThreads; |
| 301 | if (video_analyzer_threads <= 0) { |
| 302 | video_analyzer_threads = 1; |
| 303 | } |
| 304 | video_analyzer_threads = |
| 305 | std::min(video_analyzer_threads, kMaxVideoAnalyzerThreads); |
| 306 | RTC_LOG(INFO) << "video_analyzer_threads=" << video_analyzer_threads; |
| 307 | |
Artem Titov | 5983585 | 2019-02-27 17:44:13 +0100 | [diff] [blame] | 308 | video_quality_analyzer_injection_helper_->Start(test_case_name_, |
| 309 | video_analyzer_threads); |
Mirko Bonadei | f948eb6 | 2019-04-05 15:13:23 +0200 | [diff] [blame] | 310 | audio_quality_analyzer_->Start(test_case_name_, &analyzer_helper_); |
Artem Titov | 1845922 | 2019-04-24 11:09:35 +0200 | [diff] [blame] | 311 | for (auto& reporter : quality_metrics_reporters_) { |
| 312 | reporter->Start(test_case_name_); |
| 313 | } |
Mirko Bonadei | ce7a4fb | 2019-02-25 11:45:07 +0100 | [diff] [blame] | 314 | |
| 315 | // Start RTCEventLog recording if requested. |
| 316 | if (alice_->params()->rtc_event_log_path) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 317 | auto alice_rtc_event_log = std::make_unique<webrtc::RtcEventLogOutputFile>( |
Mirko Bonadei | ce7a4fb | 2019-02-25 11:45:07 +0100 | [diff] [blame] | 318 | alice_->params()->rtc_event_log_path.value()); |
| 319 | alice_->pc()->StartRtcEventLog(std::move(alice_rtc_event_log), |
| 320 | webrtc::RtcEventLog::kImmediateOutput); |
| 321 | } |
| 322 | if (bob_->params()->rtc_event_log_path) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 323 | auto bob_rtc_event_log = std::make_unique<webrtc::RtcEventLogOutputFile>( |
Mirko Bonadei | ce7a4fb | 2019-02-25 11:45:07 +0100 | [diff] [blame] | 324 | bob_->params()->rtc_event_log_path.value()); |
| 325 | bob_->pc()->StartRtcEventLog(std::move(bob_rtc_event_log), |
| 326 | webrtc::RtcEventLog::kImmediateOutput); |
| 327 | } |
| 328 | |
Artem Titov | 4d29ef0 | 2019-05-20 10:43:16 +0200 | [diff] [blame] | 329 | // Setup alive logging. It is done to prevent test infra to think that test is |
| 330 | // dead. |
| 331 | RepeatingTaskHandle::DelayedStart(task_queue_->Get(), |
| 332 | kAliveMessageLogInterval, []() { |
| 333 | std::printf("Test is still running...\n"); |
| 334 | return kAliveMessageLogInterval; |
| 335 | }); |
| 336 | |
Artem Titov | 3ab8eb5 | 2019-08-16 16:10:34 +0200 | [diff] [blame] | 337 | RTC_LOG(INFO) << "Configuration is done. Now Alice is calling to Bob..."; |
| 338 | |
Artem Titov | ba82e00 | 2019-03-15 15:57:53 +0100 | [diff] [blame] | 339 | // Setup call. |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 340 | signaling_thread->Invoke<void>( |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 341 | RTC_FROM_HERE, |
Artem Titov | f65a89b | 2019-05-07 11:56:44 +0200 | [diff] [blame] | 342 | rtc::Bind(&PeerConnectionE2EQualityTest::SetupCallOnSignalingThread, this, |
| 343 | run_params)); |
Artem Titov | ba82e00 | 2019-03-15 15:57:53 +0100 | [diff] [blame] | 344 | { |
| 345 | rtc::CritScope crit(&lock_); |
| 346 | start_time_ = Now(); |
| 347 | while (!scheduled_activities_.empty()) { |
| 348 | PostTask(std::move(scheduled_activities_.front())); |
| 349 | scheduled_activities_.pop(); |
| 350 | } |
| 351 | } |
Mirko Bonadei | 7131880 | 2019-02-18 18:52:43 +0100 | [diff] [blame] | 352 | |
Artem Titov | a854921 | 2019-08-19 14:38:06 +0200 | [diff] [blame] | 353 | std::vector<StatsObserverInterface*> observers = { |
| 354 | audio_quality_analyzer_.get(), |
| 355 | video_quality_analyzer_injection_helper_.get()}; |
| 356 | for (auto& reporter : quality_metrics_reporters_) { |
| 357 | observers.push_back(reporter.get()); |
| 358 | } |
| 359 | StatsPoller stats_poller(observers, |
Mirko Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +0100 | [diff] [blame] | 360 | {{"alice", alice_.get()}, {"bob", bob_.get()}}); |
| 361 | |
Artem Titov | ba82e00 | 2019-03-15 15:57:53 +0100 | [diff] [blame] | 362 | task_queue_->PostTask([&stats_poller, this]() { |
| 363 | RTC_DCHECK_RUN_ON(task_queue_.get()); |
Sebastian Jansson | cda86dd | 2019-03-11 17:26:36 +0100 | [diff] [blame] | 364 | stats_polling_task_ = |
Artem Titov | ba82e00 | 2019-03-15 15:57:53 +0100 | [diff] [blame] | 365 | RepeatingTaskHandle::Start(task_queue_->Get(), [this, &stats_poller]() { |
| 366 | RTC_DCHECK_RUN_ON(task_queue_.get()); |
Sebastian Jansson | cda86dd | 2019-03-11 17:26:36 +0100 | [diff] [blame] | 367 | stats_poller.PollStatsAndNotifyObservers(); |
| 368 | return kStatsUpdateInterval; |
| 369 | }); |
Mirko Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +0100 | [diff] [blame] | 370 | }); |
| 371 | |
Mirko Bonadei | 7131880 | 2019-02-18 18:52:43 +0100 | [diff] [blame] | 372 | rtc::Event done; |
Artem Titov | 1685059 | 2019-07-10 14:34:02 +0200 | [diff] [blame] | 373 | bool is_quick_test_enabled = field_trial::IsEnabled("WebRTC-QuickPerfTest"); |
| 374 | if (is_quick_test_enabled) { |
| 375 | done.Wait(kQuickTestModeRunDurationMs); |
| 376 | } else { |
| 377 | done.Wait(run_params.run_duration.ms()); |
| 378 | } |
Mirko Bonadei | 12ae4f4 | 2019-02-26 15:19:07 +0100 | [diff] [blame] | 379 | |
Artem Titov | 3ab8eb5 | 2019-08-16 16:10:34 +0200 | [diff] [blame] | 380 | RTC_LOG(INFO) << "Test is done, initiating disconnect sequence."; |
| 381 | |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 382 | task_queue_->SendTask( |
| 383 | [&stats_poller, this]() { |
| 384 | RTC_DCHECK_RUN_ON(task_queue_.get()); |
| 385 | stats_polling_task_.Stop(); |
| 386 | // Get final end-of-call stats. |
| 387 | stats_poller.PollStatsAndNotifyObservers(); |
| 388 | }, |
| 389 | RTC_FROM_HERE); |
Mirko Bonadei | 7131880 | 2019-02-18 18:52:43 +0100 | [diff] [blame] | 390 | |
Artem Titov | 70f80e5 | 2019-04-12 13:13:39 +0200 | [diff] [blame] | 391 | // We need to detach AEC dumping from peers, because dump uses |task_queue_| |
| 392 | // inside. |
| 393 | alice_->DetachAecDump(); |
| 394 | bob_->DetachAecDump(); |
Artem Titov | 4d29ef0 | 2019-05-20 10:43:16 +0200 | [diff] [blame] | 395 | // Stop all client started tasks on task queue to prevent their access to any |
| 396 | // call related objects after these objects will be destroyed during call tear |
| 397 | // down. |
Danil Chapovalov | eb90e6f | 2019-10-15 10:04:57 +0200 | [diff] [blame] | 398 | task_queue_->SendTask( |
| 399 | [this]() { |
| 400 | rtc::CritScope crit(&lock_); |
| 401 | for (auto& handle : repeating_task_handles_) { |
| 402 | handle.Stop(); |
| 403 | } |
| 404 | }, |
| 405 | RTC_FROM_HERE); |
Artem Titov | ba82e00 | 2019-03-15 15:57:53 +0100 | [diff] [blame] | 406 | // Tear down the call. |
Mirko Bonadei | 7131880 | 2019-02-18 18:52:43 +0100 | [diff] [blame] | 407 | signaling_thread->Invoke<void>( |
| 408 | RTC_FROM_HERE, |
| 409 | rtc::Bind(&PeerConnectionE2EQualityTest::TearDownCallOnSignalingThread, |
| 410 | this)); |
Artem Titov | b93c4e6 | 2019-05-02 10:52:07 +0200 | [diff] [blame] | 411 | Timestamp end_time = Now(); |
Artem Titov | 3ab8eb5 | 2019-08-16 16:10:34 +0200 | [diff] [blame] | 412 | RTC_LOG(INFO) << "All peers are disconnected."; |
Artem Titov | b93c4e6 | 2019-05-02 10:52:07 +0200 | [diff] [blame] | 413 | { |
| 414 | rtc::CritScope crit(&lock_); |
| 415 | real_test_duration_ = end_time - start_time_; |
| 416 | } |
Mirko Bonadei | 7131880 | 2019-02-18 18:52:43 +0100 | [diff] [blame] | 417 | |
Mirko Bonadei | f948eb6 | 2019-04-05 15:13:23 +0200 | [diff] [blame] | 418 | audio_quality_analyzer_->Stop(); |
Artem Titov | 9f97c9a | 2019-02-08 00:35:13 +0100 | [diff] [blame] | 419 | video_quality_analyzer_injection_helper_->Stop(); |
Artem Titov | 1845922 | 2019-04-24 11:09:35 +0200 | [diff] [blame] | 420 | for (auto& reporter : quality_metrics_reporters_) { |
| 421 | reporter->StopAndReportResults(); |
| 422 | } |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 423 | |
Artem Titov | 4d29ef0 | 2019-05-20 10:43:16 +0200 | [diff] [blame] | 424 | // Reset |task_queue_| after test to cleanup. |
| 425 | task_queue_.reset(); |
| 426 | |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 427 | // Ensuring that TestPeers have been destroyed in order to correctly close |
| 428 | // Audio dumps. |
| 429 | RTC_CHECK(!alice_); |
| 430 | RTC_CHECK(!bob_); |
Artem Titov | 9afdddf | 2019-10-10 13:29:03 +0200 | [diff] [blame] | 431 | // Ensuring that TestVideoCapturerVideoTrackSource and VideoFrameWriter |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 432 | // are destroyed on the right thread. |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 433 | RTC_CHECK(alice_video_sources_.empty()); |
| 434 | RTC_CHECK(bob_video_sources_.empty()); |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 435 | RTC_CHECK(video_writers_.empty()); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 436 | } |
| 437 | |
Artem Titov | 9a7e721 | 2019-02-28 16:34:17 +0100 | [diff] [blame] | 438 | void PeerConnectionE2EQualityTest::SetDefaultValuesForMissingParams( |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 439 | std::vector<Params*> params) { |
Artem Titov | 3481db2 | 2019-02-28 13:13:15 +0100 | [diff] [blame] | 440 | int video_counter = 0; |
| 441 | int audio_counter = 0; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 442 | std::set<std::string> video_labels; |
Artem Titov | 3481db2 | 2019-02-28 13:13:15 +0100 | [diff] [blame] | 443 | std::set<std::string> audio_labels; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 444 | for (auto* p : params) { |
| 445 | for (auto& video_config : p->video_configs) { |
Artem Titov | 9a7e721 | 2019-02-28 16:34:17 +0100 | [diff] [blame] | 446 | if (!video_config.generator && !video_config.input_file_name && |
Artem Titov | 9afdddf | 2019-10-10 13:29:03 +0200 | [diff] [blame] | 447 | !video_config.screen_share_config && |
| 448 | !video_config.capturing_device_index) { |
Artem Titov | 9a7e721 | 2019-02-28 16:34:17 +0100 | [diff] [blame] | 449 | video_config.generator = VideoGeneratorType::kDefault; |
| 450 | } |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 451 | if (!video_config.stream_label) { |
| 452 | std::string label; |
| 453 | do { |
Artem Titov | 3481db2 | 2019-02-28 13:13:15 +0100 | [diff] [blame] | 454 | label = "_auto_video_stream_label_" + std::to_string(video_counter); |
| 455 | ++video_counter; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 456 | } while (!video_labels.insert(label).second); |
| 457 | video_config.stream_label = label; |
| 458 | } |
| 459 | } |
Artem Titov | 3481db2 | 2019-02-28 13:13:15 +0100 | [diff] [blame] | 460 | if (p->audio_config) { |
| 461 | if (!p->audio_config->stream_label) { |
| 462 | std::string label; |
| 463 | do { |
| 464 | label = "_auto_audio_stream_label_" + std::to_string(audio_counter); |
| 465 | ++audio_counter; |
| 466 | } while (!audio_labels.insert(label).second); |
| 467 | p->audio_config->stream_label = label; |
| 468 | } |
| 469 | } |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 470 | } |
| 471 | } |
| 472 | |
Artem Titov | ade945d | 2019-04-02 18:31:48 +0200 | [diff] [blame] | 473 | void PeerConnectionE2EQualityTest::ValidateParams(const RunParams& run_params, |
| 474 | std::vector<Params*> params) { |
| 475 | RTC_CHECK_GT(run_params.video_encoder_bitrate_multiplier, 0.0); |
| 476 | |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 477 | std::set<std::string> video_labels; |
Artem Titov | 3481db2 | 2019-02-28 13:13:15 +0100 | [diff] [blame] | 478 | std::set<std::string> audio_labels; |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 479 | int media_streams_count = 0; |
| 480 | |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 481 | for (size_t i = 0; i < params.size(); ++i) { |
| 482 | Params* p = params[i]; |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 483 | if (p->audio_config) { |
| 484 | media_streams_count++; |
| 485 | } |
| 486 | media_streams_count += p->video_configs.size(); |
| 487 | |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 488 | // Validate that each video config has exactly one of |generator|, |
| 489 | // |input_file_name| or |screen_share_config| set. Also validate that all |
| 490 | // video stream labels are unique. |
| 491 | for (auto& video_config : p->video_configs) { |
| 492 | RTC_CHECK(video_config.stream_label); |
| 493 | bool inserted = |
| 494 | video_labels.insert(video_config.stream_label.value()).second; |
| 495 | RTC_CHECK(inserted) << "Duplicate video_config.stream_label=" |
| 496 | << video_config.stream_label.value(); |
Artem Titov | 9afdddf | 2019-10-10 13:29:03 +0200 | [diff] [blame] | 497 | int input_sources_count = 0; |
| 498 | if (video_config.generator) |
| 499 | ++input_sources_count; |
| 500 | if (video_config.input_file_name) |
| 501 | ++input_sources_count; |
| 502 | if (video_config.screen_share_config) |
| 503 | ++input_sources_count; |
| 504 | if (video_config.capturing_device_index) |
| 505 | ++input_sources_count; |
| 506 | RTC_CHECK_EQ(input_sources_count, 1) |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 507 | << VideoConfigSourcePresenceToString(video_config); |
Artem Titov | 7581ff7 | 2019-05-15 15:45:33 +0200 | [diff] [blame] | 508 | |
| 509 | if (video_config.screen_share_config) { |
| 510 | if (video_config.screen_share_config->slides_yuv_file_names.empty()) { |
| 511 | if (video_config.screen_share_config->scrolling_params) { |
| 512 | // If we have scrolling params, then its |source_width| and |
| 513 | // |source_heigh| will be used as width and height of video input, |
| 514 | // so we have to validate it against width and height of default |
| 515 | // input. |
| 516 | RTC_CHECK_EQ(video_config.screen_share_config->scrolling_params |
| 517 | ->source_width, |
| 518 | kDefaultSlidesWidth); |
| 519 | RTC_CHECK_EQ(video_config.screen_share_config->scrolling_params |
| 520 | ->source_height, |
| 521 | kDefaultSlidesHeight); |
| 522 | } else { |
| 523 | RTC_CHECK_EQ(video_config.width, kDefaultSlidesWidth); |
| 524 | RTC_CHECK_EQ(video_config.height, kDefaultSlidesHeight); |
| 525 | } |
| 526 | } |
| 527 | if (video_config.screen_share_config->scrolling_params) { |
| 528 | RTC_CHECK_LE( |
| 529 | video_config.screen_share_config->scrolling_params->duration, |
| 530 | video_config.screen_share_config->slide_change_interval); |
| 531 | RTC_CHECK_GE( |
| 532 | video_config.screen_share_config->scrolling_params->source_width, |
| 533 | video_config.width); |
| 534 | RTC_CHECK_GE( |
| 535 | video_config.screen_share_config->scrolling_params->source_height, |
| 536 | video_config.height); |
| 537 | } |
| 538 | } |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 539 | if (video_config.simulcast_config) { |
Artem Titov | d70d80d | 2019-07-19 11:00:40 +0200 | [diff] [blame] | 540 | // We support simulcast only from caller. |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 541 | RTC_CHECK_EQ(i, 0) |
| 542 | << "Only simulcast stream from first peer is supported"; |
Johannes Kron | ac315b2 | 2019-09-19 14:55:58 +0200 | [diff] [blame] | 543 | RTC_CHECK(!video_config.max_encode_bitrate_bps) |
| 544 | << "Setting max encode bitrate is not implemented for simulcast."; |
| 545 | RTC_CHECK(!video_config.min_encode_bitrate_bps) |
| 546 | << "Setting min encode bitrate is not implemented for simulcast."; |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 547 | } |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 548 | } |
| 549 | if (p->audio_config) { |
Artem Titov | 3481db2 | 2019-02-28 13:13:15 +0100 | [diff] [blame] | 550 | bool inserted = |
| 551 | audio_labels.insert(p->audio_config->stream_label.value()).second; |
| 552 | RTC_CHECK(inserted) << "Duplicate audio_config.stream_label=" |
| 553 | << p->audio_config->stream_label.value(); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 554 | // Check that if mode input file name specified only if mode is kFile. |
| 555 | if (p->audio_config.value().mode == AudioConfig::Mode::kGenerated) { |
| 556 | RTC_CHECK(!p->audio_config.value().input_file_name); |
| 557 | } |
| 558 | if (p->audio_config.value().mode == AudioConfig::Mode::kFile) { |
| 559 | RTC_CHECK(p->audio_config.value().input_file_name); |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame] | 560 | RTC_CHECK( |
Artem Titov | 70f80e5 | 2019-04-12 13:13:39 +0200 | [diff] [blame] | 561 | test::FileExists(p->audio_config.value().input_file_name.value())) |
| 562 | << p->audio_config.value().input_file_name.value() |
| 563 | << " doesn't exist"; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 564 | } |
| 565 | } |
| 566 | } |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 567 | |
| 568 | RTC_CHECK_GT(media_streams_count, 0) << "No media in the call."; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 569 | } |
| 570 | |
Artem Titov | 2370242 | 2019-05-27 15:28:30 +0200 | [diff] [blame] | 571 | void PeerConnectionE2EQualityTest::SetupRequiredFieldTrials( |
| 572 | const RunParams& run_params) { |
| 573 | std::string field_trials = ""; |
| 574 | if (run_params.use_flex_fec) { |
| 575 | field_trials += kFlexFecEnabledFieldTrials; |
| 576 | } |
| 577 | if (!field_trials.empty()) { |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 578 | override_field_trials_ = std::make_unique<test::ScopedFieldTrials>( |
Artem Titov | 2370242 | 2019-05-27 15:28:30 +0200 | [diff] [blame] | 579 | field_trial::GetFieldTrialString() + field_trials); |
| 580 | } |
| 581 | } |
| 582 | |
Mirko Bonadei | f948eb6 | 2019-04-05 15:13:23 +0200 | [diff] [blame] | 583 | void PeerConnectionE2EQualityTest::OnTrackCallback( |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 584 | rtc::scoped_refptr<RtpTransceiverInterface> transceiver, |
| 585 | std::vector<VideoConfig> remote_video_configs) { |
| 586 | const rtc::scoped_refptr<MediaStreamTrackInterface>& track = |
| 587 | transceiver->receiver()->track(); |
Mirko Bonadei | f948eb6 | 2019-04-05 15:13:23 +0200 | [diff] [blame] | 588 | RTC_CHECK_EQ(transceiver->receiver()->stream_ids().size(), 1); |
| 589 | std::string stream_label = transceiver->receiver()->stream_ids().front(); |
| 590 | analyzer_helper_.AddTrackToStreamMapping(track->id(), stream_label); |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 591 | if (track->kind() != MediaStreamTrackInterface::kVideoKind) { |
| 592 | return; |
| 593 | } |
| 594 | |
| 595 | VideoConfig* video_config = nullptr; |
| 596 | for (auto& config : remote_video_configs) { |
Artem Titov | 7c55415 | 2019-02-28 10:25:52 +0100 | [diff] [blame] | 597 | if (config.stream_label == stream_label) { |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 598 | video_config = &config; |
| 599 | break; |
| 600 | } |
| 601 | } |
| 602 | RTC_CHECK(video_config); |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame] | 603 | test::VideoFrameWriter* writer = MaybeCreateVideoWriter( |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 604 | video_config->output_dump_file_name, *video_config); |
| 605 | // It is safe to cast here, because it is checked above that |
| 606 | // track->kind() is kVideoKind. |
| 607 | auto* video_track = static_cast<VideoTrackInterface*>(track.get()); |
| 608 | std::unique_ptr<rtc::VideoSinkInterface<VideoFrame>> video_sink = |
Artem Titov | ddef8d1 | 2019-09-06 14:31:50 +0200 | [diff] [blame] | 609 | video_quality_analyzer_injection_helper_->CreateVideoSink(*video_config, |
| 610 | writer); |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 611 | video_track->AddOrUpdateSink(video_sink.get(), rtc::VideoSinkWants()); |
| 612 | output_video_sinks_.push_back(std::move(video_sink)); |
| 613 | } |
| 614 | |
Artem Titov | f65a89b | 2019-05-07 11:56:44 +0200 | [diff] [blame] | 615 | void PeerConnectionE2EQualityTest::SetupCallOnSignalingThread( |
| 616 | const RunParams& run_params) { |
Artem Titov | 7c55415 | 2019-02-28 10:25:52 +0100 | [diff] [blame] | 617 | // We need receive-only transceivers for Bob's media stream, so there will |
| 618 | // be media section in SDP for that streams in Alice's offer, because it is |
| 619 | // forbidden to add new media sections in answer in Unified Plan. |
| 620 | RtpTransceiverInit receive_only_transceiver_init; |
| 621 | receive_only_transceiver_init.direction = RtpTransceiverDirection::kRecvOnly; |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 622 | int alice_transceivers_counter = 0; |
Artem Titov | 7c55415 | 2019-02-28 10:25:52 +0100 | [diff] [blame] | 623 | if (bob_->params()->audio_config) { |
| 624 | // Setup receive audio transceiver if Bob has audio to send. If we'll need |
| 625 | // multiple audio streams, then we need transceiver for each Bob's audio |
| 626 | // stream. |
Artem Titov | 7f2a67f | 2019-06-13 19:45:55 +0200 | [diff] [blame] | 627 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> result = |
| 628 | alice_->AddTransceiver(cricket::MediaType::MEDIA_TYPE_AUDIO, |
| 629 | receive_only_transceiver_init); |
| 630 | RTC_CHECK(result.ok()); |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 631 | alice_transceivers_counter++; |
| 632 | } |
| 633 | |
Johannes Kron | ac315b2 | 2019-09-19 14:55:58 +0200 | [diff] [blame] | 634 | size_t alice_video_transceivers_non_simulcast_counter = 0; |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 635 | for (auto& video_config : alice_->params()->video_configs) { |
Johannes Kron | ac315b2 | 2019-09-19 14:55:58 +0200 | [diff] [blame] | 636 | RtpTransceiverInit transceiver_params; |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 637 | if (video_config.simulcast_config) { |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 638 | transceiver_params.direction = RtpTransceiverDirection::kSendOnly; |
Artem Titov | d70d80d | 2019-07-19 11:00:40 +0200 | [diff] [blame] | 639 | if (run_params.video_codec_name == cricket::kVp8CodecName) { |
| 640 | // For Vp8 simulcast we need to add as many RtpEncodingParameters to the |
| 641 | // track as many simulcast streams requested. |
| 642 | for (int i = 0; |
| 643 | i < video_config.simulcast_config->simulcast_streams_count; ++i) { |
| 644 | RtpEncodingParameters enc_params; |
| 645 | // We need to be sure, that all rids will be unique with all mids. |
| 646 | enc_params.rid = std::to_string(alice_transceivers_counter) + "000" + |
| 647 | std::to_string(i); |
| 648 | transceiver_params.send_encodings.push_back(enc_params); |
| 649 | } |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 650 | } |
Johannes Kron | ac315b2 | 2019-09-19 14:55:58 +0200 | [diff] [blame] | 651 | } else { |
| 652 | transceiver_params.direction = RtpTransceiverDirection::kSendRecv; |
| 653 | RtpEncodingParameters enc_params; |
| 654 | enc_params.max_bitrate_bps = video_config.max_encode_bitrate_bps; |
| 655 | enc_params.min_bitrate_bps = video_config.min_encode_bitrate_bps; |
| 656 | transceiver_params.send_encodings.push_back(enc_params); |
| 657 | |
| 658 | alice_video_transceivers_non_simulcast_counter++; |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 659 | } |
Johannes Kron | ac315b2 | 2019-09-19 14:55:58 +0200 | [diff] [blame] | 660 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> result = |
| 661 | alice_->AddTransceiver(cricket::MediaType::MEDIA_TYPE_VIDEO, |
| 662 | transceiver_params); |
| 663 | RTC_CHECK(result.ok()); |
| 664 | |
| 665 | alice_transceivers_counter++; |
Artem Titov | 7c55415 | 2019-02-28 10:25:52 +0100 | [diff] [blame] | 666 | } |
Johannes Kron | ac315b2 | 2019-09-19 14:55:58 +0200 | [diff] [blame] | 667 | |
| 668 | // Add receive only transceivers in case Bob has more video_configs than |
| 669 | // Alice. |
| 670 | for (size_t i = alice_video_transceivers_non_simulcast_counter; |
| 671 | i < bob_->params()->video_configs.size(); ++i) { |
Artem Titov | 7f2a67f | 2019-06-13 19:45:55 +0200 | [diff] [blame] | 672 | RTCErrorOr<rtc::scoped_refptr<RtpTransceiverInterface>> result = |
| 673 | alice_->AddTransceiver(cricket::MediaType::MEDIA_TYPE_VIDEO, |
| 674 | receive_only_transceiver_init); |
| 675 | RTC_CHECK(result.ok()); |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 676 | alice_transceivers_counter++; |
Artem Titov | 7c55415 | 2019-02-28 10:25:52 +0100 | [diff] [blame] | 677 | } |
Johannes Kron | ac315b2 | 2019-09-19 14:55:58 +0200 | [diff] [blame] | 678 | |
Artem Titov | 7c55415 | 2019-02-28 10:25:52 +0100 | [diff] [blame] | 679 | // Then add media for Alice and Bob |
| 680 | alice_video_sources_ = MaybeAddMedia(alice_.get()); |
| 681 | bob_video_sources_ = MaybeAddMedia(bob_.get()); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 682 | |
Artem Titov | f65a89b | 2019-05-07 11:56:44 +0200 | [diff] [blame] | 683 | SetPeerCodecPreferences(alice_.get(), run_params); |
| 684 | SetPeerCodecPreferences(bob_.get(), run_params); |
| 685 | |
Artem Titov | d70d80d | 2019-07-19 11:00:40 +0200 | [diff] [blame] | 686 | SetupCall(run_params); |
Mirko Bonadei | 7131880 | 2019-02-18 18:52:43 +0100 | [diff] [blame] | 687 | } |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 688 | |
Mirko Bonadei | 7131880 | 2019-02-18 18:52:43 +0100 | [diff] [blame] | 689 | void PeerConnectionE2EQualityTest::TearDownCallOnSignalingThread() { |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 690 | TearDownCall(); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 691 | } |
| 692 | |
Artem Titov | 9afdddf | 2019-10-10 13:29:03 +0200 | [diff] [blame] | 693 | std::vector<rtc::scoped_refptr<TestVideoCapturerVideoTrackSource>> |
Artem Titov | 7c55415 | 2019-02-28 10:25:52 +0100 | [diff] [blame] | 694 | PeerConnectionE2EQualityTest::MaybeAddMedia(TestPeer* peer) { |
| 695 | MaybeAddAudio(peer); |
| 696 | return MaybeAddVideo(peer); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 697 | } |
| 698 | |
Artem Titov | 9afdddf | 2019-10-10 13:29:03 +0200 | [diff] [blame] | 699 | std::vector<rtc::scoped_refptr<TestVideoCapturerVideoTrackSource>> |
Artem Titov | 7c55415 | 2019-02-28 10:25:52 +0100 | [diff] [blame] | 700 | PeerConnectionE2EQualityTest::MaybeAddVideo(TestPeer* peer) { |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 701 | // Params here valid because of pre-run validation. |
| 702 | Params* params = peer->params(); |
Artem Titov | 9afdddf | 2019-10-10 13:29:03 +0200 | [diff] [blame] | 703 | std::vector<rtc::scoped_refptr<TestVideoCapturerVideoTrackSource>> out; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 704 | for (auto video_config : params->video_configs) { |
Artem Titov | 9afdddf | 2019-10-10 13:29:03 +0200 | [diff] [blame] | 705 | // Setup input video source into peer connection. |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame] | 706 | test::VideoFrameWriter* writer = |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 707 | MaybeCreateVideoWriter(video_config.input_dump_file_name, video_config); |
Artem Titov | 9afdddf | 2019-10-10 13:29:03 +0200 | [diff] [blame] | 708 | std::unique_ptr<test::TestVideoCapturer> capturer = CreateVideoCapturer( |
| 709 | video_config, |
| 710 | video_quality_analyzer_injection_helper_->CreateFramePreprocessor( |
| 711 | video_config, writer)); |
| 712 | rtc::scoped_refptr<TestVideoCapturerVideoTrackSource> source = |
| 713 | new rtc::RefCountedObject<TestVideoCapturerVideoTrackSource>( |
Artem Titov | 89e7fcb | 2019-09-26 11:59:49 +0000 | [diff] [blame] | 714 | std::move(capturer), |
Artem Titov | b3f1487 | 2019-09-09 13:48:21 +0200 | [diff] [blame] | 715 | /*is_screencast=*/video_config.screen_share_config && |
| 716 | video_config.screen_share_config->use_text_content_hint); |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 717 | out.push_back(source); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 718 | RTC_LOG(INFO) << "Adding video with video_config.stream_label=" |
| 719 | << video_config.stream_label.value(); |
| 720 | rtc::scoped_refptr<VideoTrackInterface> track = |
| 721 | peer->pc_factory()->CreateVideoTrack(video_config.stream_label.value(), |
| 722 | source); |
Artem Titov | b3f1487 | 2019-09-09 13:48:21 +0200 | [diff] [blame] | 723 | if (video_config.screen_share_config && |
| 724 | video_config.screen_share_config->use_text_content_hint) { |
Artem Titov | 232b6a1 | 2019-05-29 11:05:01 +0200 | [diff] [blame] | 725 | track->set_content_hint(VideoTrackInterface::ContentHint::kText); |
| 726 | } |
Artem Titov | 1e49ab2 | 2019-07-30 13:17:25 +0200 | [diff] [blame] | 727 | RTCErrorOr<rtc::scoped_refptr<RtpSenderInterface>> sender = |
| 728 | peer->AddTrack(track, {video_config.stream_label.value()}); |
| 729 | RTC_CHECK(sender.ok()); |
| 730 | if (video_config.temporal_layers_count) { |
| 731 | RtpParameters rtp_parameters = sender.value()->GetParameters(); |
| 732 | for (auto& encoding_parameters : rtp_parameters.encodings) { |
| 733 | encoding_parameters.num_temporal_layers = |
| 734 | video_config.temporal_layers_count; |
| 735 | } |
| 736 | RTCError res = sender.value()->SetParameters(rtp_parameters); |
| 737 | RTC_CHECK(res.ok()) << "Failed to set RTP parameters"; |
| 738 | } |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 739 | } |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 740 | return out; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 741 | } |
| 742 | |
Artem Titov | 9afdddf | 2019-10-10 13:29:03 +0200 | [diff] [blame] | 743 | std::unique_ptr<test::TestVideoCapturer> |
| 744 | PeerConnectionE2EQualityTest::CreateVideoCapturer( |
| 745 | const VideoConfig& video_config, |
| 746 | std::unique_ptr<test::TestVideoCapturer::FramePreprocessor> |
| 747 | frame_preprocessor) { |
| 748 | if (video_config.capturing_device_index) { |
| 749 | std::unique_ptr<test::TestVideoCapturer> capturer = |
| 750 | test::CreateVideoCapturer(video_config.width, video_config.height, |
| 751 | video_config.fps, |
| 752 | *video_config.capturing_device_index); |
| 753 | capturer->SetFramePreprocessor(std::move(frame_preprocessor)); |
| 754 | RTC_CHECK(capturer) |
| 755 | << "Failed to obtain input stream from capturing device #" |
| 756 | << *video_config.capturing_device_index; |
| 757 | return capturer; |
| 758 | } |
| 759 | |
| 760 | std::unique_ptr<test::FrameGenerator> frame_generator = nullptr; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 761 | if (video_config.generator) { |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame] | 762 | absl::optional<test::FrameGenerator::OutputType> frame_generator_type = |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 763 | absl::nullopt; |
| 764 | if (video_config.generator == VideoGeneratorType::kDefault) { |
Sebastian Jansson | ed0febf | 2019-07-26 15:58:11 +0200 | [diff] [blame] | 765 | frame_generator_type = test::FrameGenerator::OutputType::kI420; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 766 | } else if (video_config.generator == VideoGeneratorType::kI420A) { |
Sebastian Jansson | ed0febf | 2019-07-26 15:58:11 +0200 | [diff] [blame] | 767 | frame_generator_type = test::FrameGenerator::OutputType::kI420A; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 768 | } else if (video_config.generator == VideoGeneratorType::kI010) { |
Sebastian Jansson | ed0febf | 2019-07-26 15:58:11 +0200 | [diff] [blame] | 769 | frame_generator_type = test::FrameGenerator::OutputType::kI010; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 770 | } |
Artem Titov | 9afdddf | 2019-10-10 13:29:03 +0200 | [diff] [blame] | 771 | frame_generator = test::FrameGenerator::CreateSquareGenerator( |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 772 | static_cast<int>(video_config.width), |
| 773 | static_cast<int>(video_config.height), frame_generator_type, |
| 774 | absl::nullopt); |
| 775 | } |
| 776 | if (video_config.input_file_name) { |
Artem Titov | 9afdddf | 2019-10-10 13:29:03 +0200 | [diff] [blame] | 777 | frame_generator = test::FrameGenerator::CreateFromYuvFile( |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 778 | std::vector<std::string>(/*count=*/1, |
| 779 | video_config.input_file_name.value()), |
| 780 | video_config.width, video_config.height, /*frame_repeat_count=*/1); |
| 781 | } |
| 782 | if (video_config.screen_share_config) { |
Artem Titov | 9afdddf | 2019-10-10 13:29:03 +0200 | [diff] [blame] | 783 | frame_generator = CreateScreenShareFrameGenerator(video_config); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 784 | } |
Artem Titov | 9afdddf | 2019-10-10 13:29:03 +0200 | [diff] [blame] | 785 | RTC_CHECK(frame_generator) << "Unsupported video_config input source"; |
| 786 | |
| 787 | auto capturer = std::make_unique<test::FrameGeneratorCapturer>( |
| 788 | clock_, std::move(frame_generator), video_config.fps, |
| 789 | *task_queue_factory_); |
| 790 | capturer->SetFramePreprocessor(std::move(frame_preprocessor)); |
| 791 | capturer->Init(); |
| 792 | return capturer; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 793 | } |
| 794 | |
Artem Titov | 7581ff7 | 2019-05-15 15:45:33 +0200 | [diff] [blame] | 795 | std::unique_ptr<test::FrameGenerator> |
| 796 | PeerConnectionE2EQualityTest::CreateScreenShareFrameGenerator( |
| 797 | const VideoConfig& video_config) { |
| 798 | RTC_CHECK(video_config.screen_share_config); |
| 799 | if (video_config.screen_share_config->generate_slides) { |
| 800 | return test::FrameGenerator::CreateSlideGenerator( |
| 801 | video_config.width, video_config.height, |
| 802 | video_config.screen_share_config->slide_change_interval.seconds() * |
| 803 | video_config.fps); |
| 804 | } |
| 805 | std::vector<std::string> slides = |
| 806 | video_config.screen_share_config->slides_yuv_file_names; |
| 807 | if (slides.empty()) { |
| 808 | // If slides is empty we need to add default slides as source. In such case |
| 809 | // video width and height is validated to be equal to kDefaultSlidesWidth |
| 810 | // and kDefaultSlidesHeight. |
| 811 | slides.push_back(test::ResourcePath("web_screenshot_1850_1110", "yuv")); |
| 812 | slides.push_back(test::ResourcePath("presentation_1850_1110", "yuv")); |
| 813 | slides.push_back(test::ResourcePath("photo_1850_1110", "yuv")); |
| 814 | slides.push_back(test::ResourcePath("difficult_photo_1850_1110", "yuv")); |
| 815 | } |
| 816 | if (!video_config.screen_share_config->scrolling_params) { |
| 817 | // Cycle image every slide_change_interval seconds. |
| 818 | return test::FrameGenerator::CreateFromYuvFile( |
| 819 | slides, video_config.width, video_config.height, |
| 820 | video_config.screen_share_config->slide_change_interval.seconds() * |
| 821 | video_config.fps); |
| 822 | } |
| 823 | |
| 824 | // |pause_duration| is nonnegative. It is validated in ValidateParams(...). |
| 825 | TimeDelta pause_duration = |
| 826 | video_config.screen_share_config->slide_change_interval - |
| 827 | video_config.screen_share_config->scrolling_params->duration; |
| 828 | |
| 829 | return test::FrameGenerator::CreateScrollingInputFromYuvFiles( |
| 830 | clock_, slides, |
| 831 | video_config.screen_share_config->scrolling_params->source_width, |
| 832 | video_config.screen_share_config->scrolling_params->source_height, |
| 833 | video_config.width, video_config.height, |
| 834 | video_config.screen_share_config->scrolling_params->duration.ms(), |
| 835 | pause_duration.ms()); |
| 836 | } |
| 837 | |
Artem Titov | 7c55415 | 2019-02-28 10:25:52 +0100 | [diff] [blame] | 838 | void PeerConnectionE2EQualityTest::MaybeAddAudio(TestPeer* peer) { |
| 839 | if (!peer->params()->audio_config) { |
| 840 | return; |
| 841 | } |
Artem Titov | 3481db2 | 2019-02-28 13:13:15 +0100 | [diff] [blame] | 842 | const AudioConfig& audio_config = peer->params()->audio_config.value(); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 843 | rtc::scoped_refptr<webrtc::AudioSourceInterface> source = |
Artem Titov | 3481db2 | 2019-02-28 13:13:15 +0100 | [diff] [blame] | 844 | peer->pc_factory()->CreateAudioSource(audio_config.audio_options); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 845 | rtc::scoped_refptr<AudioTrackInterface> track = |
Artem Titov | 3481db2 | 2019-02-28 13:13:15 +0100 | [diff] [blame] | 846 | peer->pc_factory()->CreateAudioTrack(*audio_config.stream_label, source); |
| 847 | peer->AddTrack(track, {*audio_config.stream_label}); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 848 | } |
| 849 | |
Artem Titov | f65a89b | 2019-05-07 11:56:44 +0200 | [diff] [blame] | 850 | void PeerConnectionE2EQualityTest::SetPeerCodecPreferences( |
| 851 | TestPeer* peer, |
| 852 | const RunParams& run_params) { |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 853 | std::vector<RtpCodecCapability> with_rtx_video_capabilities = |
Artem Titov | 7f2a67f | 2019-06-13 19:45:55 +0200 | [diff] [blame] | 854 | FilterVideoCodecCapabilities( |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 855 | run_params.video_codec_name, run_params.video_codec_required_params, |
| 856 | true, run_params.use_ulp_fec, run_params.use_flex_fec, |
| 857 | peer->pc_factory() |
| 858 | ->GetRtpSenderCapabilities(cricket::MediaType::MEDIA_TYPE_VIDEO) |
| 859 | .codecs); |
| 860 | std::vector<RtpCodecCapability> without_rtx_video_capabilities = |
Artem Titov | 7f2a67f | 2019-06-13 19:45:55 +0200 | [diff] [blame] | 861 | FilterVideoCodecCapabilities( |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 862 | run_params.video_codec_name, run_params.video_codec_required_params, |
| 863 | false, run_params.use_ulp_fec, run_params.use_flex_fec, |
| 864 | peer->pc_factory() |
| 865 | ->GetRtpSenderCapabilities(cricket::MediaType::MEDIA_TYPE_VIDEO) |
| 866 | .codecs); |
Artem Titov | f65a89b | 2019-05-07 11:56:44 +0200 | [diff] [blame] | 867 | |
| 868 | // Set codecs for transceivers |
| 869 | for (auto transceiver : peer->pc()->GetTransceivers()) { |
| 870 | if (transceiver->media_type() == cricket::MediaType::MEDIA_TYPE_VIDEO) { |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 871 | if (transceiver->sender()->init_send_encodings().size() > 1) { |
| 872 | // If transceiver's sender has more then 1 send encodings, it means it |
| 873 | // has multiple simulcast streams, so we need disable RTX on it. |
Artem Titov | 7f2a67f | 2019-06-13 19:45:55 +0200 | [diff] [blame] | 874 | RTCError result = |
| 875 | transceiver->SetCodecPreferences(without_rtx_video_capabilities); |
| 876 | RTC_CHECK(result.ok()); |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 877 | } else { |
Artem Titov | 7f2a67f | 2019-06-13 19:45:55 +0200 | [diff] [blame] | 878 | RTCError result = |
| 879 | transceiver->SetCodecPreferences(with_rtx_video_capabilities); |
| 880 | RTC_CHECK(result.ok()); |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 881 | } |
Artem Titov | f65a89b | 2019-05-07 11:56:44 +0200 | [diff] [blame] | 882 | } |
| 883 | } |
| 884 | } |
| 885 | |
Artem Titov | d70d80d | 2019-07-19 11:00:40 +0200 | [diff] [blame] | 886 | void PeerConnectionE2EQualityTest::SetupCall(const RunParams& run_params) { |
Artem Titov | 39483c6 | 2019-07-19 17:03:52 +0200 | [diff] [blame] | 887 | std::map<std::string, int> stream_label_to_simulcast_streams_count; |
Artem Titov | 594597c | 2019-07-18 13:39:41 +0200 | [diff] [blame] | 888 | // We add only Alice here, because simulcast/svc is supported only from the |
| 889 | // first peer. |
| 890 | for (auto& video_config : alice_->params()->video_configs) { |
| 891 | if (video_config.simulcast_config) { |
Artem Titov | 39483c6 | 2019-07-19 17:03:52 +0200 | [diff] [blame] | 892 | stream_label_to_simulcast_streams_count.insert( |
| 893 | {*video_config.stream_label, |
| 894 | video_config.simulcast_config->simulcast_streams_count}); |
Artem Titov | 594597c | 2019-07-18 13:39:41 +0200 | [diff] [blame] | 895 | } |
| 896 | } |
Artem Titov | d70d80d | 2019-07-19 11:00:40 +0200 | [diff] [blame] | 897 | PatchingParams patching_params(run_params.video_codec_name, |
Artem Titov | 39483c6 | 2019-07-19 17:03:52 +0200 | [diff] [blame] | 898 | run_params.use_conference_mode, |
| 899 | stream_label_to_simulcast_streams_count); |
Artem Titov | 594597c | 2019-07-18 13:39:41 +0200 | [diff] [blame] | 900 | SignalingInterceptor signaling_interceptor(patching_params); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 901 | // Connect peers. |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 902 | ExchangeOfferAnswer(&signaling_interceptor); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 903 | // Do the SDP negotiation, and also exchange ice candidates. |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 904 | ASSERT_EQ_WAIT(alice_->signaling_state(), PeerConnectionInterface::kStable, |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 905 | kDefaultTimeoutMs); |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 906 | ASSERT_TRUE_WAIT(alice_->IsIceGatheringDone(), kDefaultTimeoutMs); |
| 907 | ASSERT_TRUE_WAIT(bob_->IsIceGatheringDone(), kDefaultTimeoutMs); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 908 | |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 909 | ExchangeIceCandidates(&signaling_interceptor); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 910 | // This means that ICE and DTLS are connected. |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 911 | ASSERT_TRUE_WAIT(bob_->IsIceConnected(), kDefaultTimeoutMs); |
| 912 | ASSERT_TRUE_WAIT(alice_->IsIceConnected(), kDefaultTimeoutMs); |
Artem Titov | 3ab8eb5 | 2019-08-16 16:10:34 +0200 | [diff] [blame] | 913 | RTC_LOG(INFO) << "Call is started (all peers are connected)."; |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 914 | } |
| 915 | |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 916 | void PeerConnectionE2EQualityTest::ExchangeOfferAnswer( |
| 917 | SignalingInterceptor* signaling_interceptor) { |
| 918 | std::string log_output; |
| 919 | |
| 920 | auto offer = alice_->CreateOffer(); |
| 921 | RTC_CHECK(offer); |
| 922 | offer->ToString(&log_output); |
| 923 | RTC_LOG(INFO) << "Original offer: " << log_output; |
| 924 | LocalAndRemoteSdp patch_result = |
| 925 | signaling_interceptor->PatchOffer(std::move(offer)); |
| 926 | patch_result.local_sdp->ToString(&log_output); |
| 927 | RTC_LOG(INFO) << "Offer to set as local description: " << log_output; |
| 928 | patch_result.remote_sdp->ToString(&log_output); |
| 929 | RTC_LOG(INFO) << "Offer to set as remote description: " << log_output; |
| 930 | |
| 931 | bool set_local_offer = |
| 932 | alice_->SetLocalDescription(std::move(patch_result.local_sdp)); |
| 933 | RTC_CHECK(set_local_offer); |
| 934 | bool set_remote_offer = |
| 935 | bob_->SetRemoteDescription(std::move(patch_result.remote_sdp)); |
| 936 | RTC_CHECK(set_remote_offer); |
| 937 | auto answer = bob_->CreateAnswer(); |
| 938 | RTC_CHECK(answer); |
| 939 | answer->ToString(&log_output); |
| 940 | RTC_LOG(INFO) << "Original answer: " << log_output; |
| 941 | patch_result = signaling_interceptor->PatchAnswer(std::move(answer)); |
| 942 | patch_result.local_sdp->ToString(&log_output); |
| 943 | RTC_LOG(INFO) << "Answer to set as local description: " << log_output; |
| 944 | patch_result.remote_sdp->ToString(&log_output); |
| 945 | RTC_LOG(INFO) << "Answer to set as remote description: " << log_output; |
| 946 | |
| 947 | bool set_local_answer = |
| 948 | bob_->SetLocalDescription(std::move(patch_result.local_sdp)); |
| 949 | RTC_CHECK(set_local_answer); |
| 950 | bool set_remote_answer = |
| 951 | alice_->SetRemoteDescription(std::move(patch_result.remote_sdp)); |
| 952 | RTC_CHECK(set_remote_answer); |
| 953 | } |
| 954 | |
| 955 | void PeerConnectionE2EQualityTest::ExchangeIceCandidates( |
| 956 | SignalingInterceptor* signaling_interceptor) { |
| 957 | // Connect an ICE candidate pairs. |
| 958 | std::vector<std::unique_ptr<IceCandidateInterface>> alice_candidates = |
| 959 | signaling_interceptor->PatchOffererIceCandidates( |
| 960 | alice_->observer()->GetAllCandidates()); |
| 961 | for (auto& candidate : alice_candidates) { |
| 962 | std::string candidate_str; |
| 963 | RTC_CHECK(candidate->ToString(&candidate_str)); |
| 964 | RTC_LOG(INFO) << "Alice ICE candidate(mid= " << candidate->sdp_mid() |
| 965 | << "): " << candidate_str; |
| 966 | } |
| 967 | ASSERT_TRUE(bob_->AddIceCandidates(std::move(alice_candidates))); |
| 968 | std::vector<std::unique_ptr<IceCandidateInterface>> bob_candidates = |
| 969 | signaling_interceptor->PatchAnswererIceCandidates( |
| 970 | bob_->observer()->GetAllCandidates()); |
| 971 | for (auto& candidate : bob_candidates) { |
| 972 | std::string candidate_str; |
| 973 | RTC_CHECK(candidate->ToString(&candidate_str)); |
| 974 | RTC_LOG(INFO) << "Bob ICE candidate(mid= " << candidate->sdp_mid() |
| 975 | << "): " << candidate_str; |
| 976 | } |
| 977 | ASSERT_TRUE(alice_->AddIceCandidates(std::move(bob_candidates))); |
| 978 | } |
| 979 | |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 980 | void PeerConnectionE2EQualityTest::StartVideo( |
Artem Titov | 9afdddf | 2019-10-10 13:29:03 +0200 | [diff] [blame] | 981 | const std::vector<rtc::scoped_refptr<TestVideoCapturerVideoTrackSource>>& |
| 982 | sources) { |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 983 | for (auto& source : sources) { |
| 984 | if (source->state() != MediaSourceInterface::SourceState::kLive) { |
| 985 | source->Start(); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 986 | } |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 987 | } |
| 988 | } |
| 989 | |
| 990 | void PeerConnectionE2EQualityTest::TearDownCall() { |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 991 | for (const auto& video_source : alice_video_sources_) { |
| 992 | video_source->Stop(); |
| 993 | } |
| 994 | for (const auto& video_source : bob_video_sources_) { |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 995 | video_source->Stop(); |
| 996 | } |
| 997 | |
| 998 | alice_->pc()->Close(); |
| 999 | bob_->pc()->Close(); |
| 1000 | |
| 1001 | for (const auto& video_writer : video_writers_) { |
| 1002 | video_writer->Close(); |
| 1003 | } |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 1004 | |
Artem Titov | bf9e01a | 2019-02-14 10:51:27 +0100 | [diff] [blame] | 1005 | alice_video_sources_.clear(); |
| 1006 | bob_video_sources_.clear(); |
Mirko Bonadei | 2bd54a1 | 2019-02-13 09:07:55 +0100 | [diff] [blame] | 1007 | video_writers_.clear(); |
| 1008 | alice_.reset(); |
| 1009 | bob_.reset(); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 1010 | } |
| 1011 | |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame] | 1012 | test::VideoFrameWriter* PeerConnectionE2EQualityTest::MaybeCreateVideoWriter( |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 1013 | absl::optional<std::string> file_name, |
| 1014 | const VideoConfig& config) { |
| 1015 | if (!file_name) { |
| 1016 | return nullptr; |
| 1017 | } |
Artem Titov | ef3fd9c | 2019-06-13 16:36:52 +0200 | [diff] [blame] | 1018 | // TODO(titovartem) create only one file writer for simulcast video track. |
Mirko Bonadei | 317a1f0 | 2019-09-17 17:06:18 +0200 | [diff] [blame] | 1019 | auto video_writer = std::make_unique<test::Y4mVideoFrameWriterImpl>( |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 1020 | file_name.value(), config.width, config.height, config.fps); |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame] | 1021 | test::VideoFrameWriter* out = video_writer.get(); |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 1022 | video_writers_.push_back(std::move(video_writer)); |
| 1023 | return out; |
| 1024 | } |
| 1025 | |
Artem Titov | ba82e00 | 2019-03-15 15:57:53 +0100 | [diff] [blame] | 1026 | Timestamp PeerConnectionE2EQualityTest::Now() const { |
Sebastian Jansson | b64ad0e | 2019-06-19 09:39:34 +0200 | [diff] [blame] | 1027 | return clock_->CurrentTime(); |
Artem Titov | ba82e00 | 2019-03-15 15:57:53 +0100 | [diff] [blame] | 1028 | } |
| 1029 | |
| 1030 | PeerConnectionE2EQualityTest::ScheduledActivity::ScheduledActivity( |
| 1031 | TimeDelta initial_delay_since_start, |
| 1032 | absl::optional<TimeDelta> interval, |
| 1033 | std::function<void(TimeDelta)> func) |
| 1034 | : initial_delay_since_start(initial_delay_since_start), |
Johannes Kron | ac315b2 | 2019-09-19 14:55:58 +0200 | [diff] [blame] | 1035 | interval(interval), |
Artem Titov | ba82e00 | 2019-03-15 15:57:53 +0100 | [diff] [blame] | 1036 | func(std::move(func)) {} |
| 1037 | |
Artem Titov | 0b44314 | 2019-03-20 11:11:08 +0100 | [diff] [blame] | 1038 | } // namespace webrtc_pc_e2e |
Artem Titov | a6a273d | 2019-02-07 16:43:51 +0100 | [diff] [blame] | 1039 | } // namespace webrtc |