Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2018 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 | */ |
Jonas Olsson | a4d8737 | 2019-07-05 19:08:33 +0200 | [diff] [blame] | 10 | #include "test/scenario/scenario.h" |
| 11 | |
Sebastian Jansson | 105a10a | 2019-04-01 09:18:14 +0200 | [diff] [blame] | 12 | #include <atomic> |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 13 | |
Andrey Logvin | f9ee0e0 | 2021-01-14 09:50:32 +0000 | [diff] [blame] | 14 | #include "api/test/network_emulation/create_cross_traffic.h" |
| 15 | #include "api/test/network_emulation/cross_traffic.h" |
Erik Språng | 000953c | 2020-06-26 17:03:19 +0200 | [diff] [blame] | 16 | #include "test/field_trial.h" |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 17 | #include "test/gtest.h" |
Sebastian Jansson | 58c71db | 2019-05-22 16:20:56 +0200 | [diff] [blame] | 18 | #include "test/logging/memory_log_writer.h" |
Sebastian Jansson | 7150d8c | 2019-04-09 14:18:09 +0200 | [diff] [blame] | 19 | #include "test/scenario/stats_collection.h" |
| 20 | |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 21 | namespace webrtc { |
| 22 | namespace test { |
| 23 | TEST(ScenarioTest, StartsAndStopsWithoutErrors) { |
Sebastian Jansson | 105a10a | 2019-04-01 09:18:14 +0200 | [diff] [blame] | 24 | std::atomic<bool> packet_received(false); |
| 25 | std::atomic<bool> bitrate_changed(false); |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 26 | Scenario s; |
| 27 | CallClientConfig call_client_config; |
Danil Chapovalov | cad3e0e | 2020-02-17 18:46:07 +0100 | [diff] [blame] | 28 | call_client_config.transport.rates.start_rate = DataRate::KilobitsPerSec(300); |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 29 | auto* alice = s.CreateClient("alice", call_client_config); |
| 30 | auto* bob = s.CreateClient("bob", call_client_config); |
Sebastian Jansson | ef86d14 | 2019-04-15 14:42:42 +0200 | [diff] [blame] | 31 | NetworkSimulationConfig network_config; |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 32 | auto alice_net = s.CreateSimulationNode(network_config); |
| 33 | auto bob_net = s.CreateSimulationNode(network_config); |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 34 | auto route = s.CreateRoutes(alice, {alice_net}, bob, {bob_net}); |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 35 | |
| 36 | VideoStreamConfig video_stream_config; |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 37 | s.CreateVideoStream(route->forward(), video_stream_config); |
| 38 | s.CreateVideoStream(route->reverse(), video_stream_config); |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 39 | |
| 40 | AudioStreamConfig audio_stream_config; |
Danil Chapovalov | cad3e0e | 2020-02-17 18:46:07 +0100 | [diff] [blame] | 41 | audio_stream_config.encoder.min_rate = DataRate::KilobitsPerSec(6); |
| 42 | audio_stream_config.encoder.max_rate = DataRate::KilobitsPerSec(64); |
Sebastian Jansson | 8285841 | 2018-10-11 19:48:05 +0200 | [diff] [blame] | 43 | audio_stream_config.encoder.allocate_bitrate = true; |
| 44 | audio_stream_config.stream.in_bandwidth_estimation = false; |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 45 | s.CreateAudioStream(route->forward(), audio_stream_config); |
| 46 | s.CreateAudioStream(route->reverse(), audio_stream_config); |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 47 | |
Sebastian Jansson | a4c22b9 | 2019-04-15 21:10:00 +0200 | [diff] [blame] | 48 | RandomWalkConfig cross_traffic_config; |
Andrey Logvin | f9ee0e0 | 2021-01-14 09:50:32 +0000 | [diff] [blame] | 49 | s.net()->StartCrossTraffic(CreateRandomWalkCrossTraffic( |
| 50 | s.net()->CreateCrossTrafficRoute({alice_net}), cross_traffic_config)); |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 51 | |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 52 | s.NetworkDelayedAction({alice_net, bob_net}, 100, |
| 53 | [&packet_received] { packet_received = true; }); |
Danil Chapovalov | 0c626af | 2020-02-10 11:16:00 +0100 | [diff] [blame] | 54 | s.Every(TimeDelta::Millis(10), [alice, bob, &bitrate_changed] { |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 55 | if (alice->GetStats().send_bandwidth_bps != 300000 && |
| 56 | bob->GetStats().send_bandwidth_bps != 300000) |
| 57 | bitrate_changed = true; |
| 58 | }); |
Danil Chapovalov | 0c626af | 2020-02-10 11:16:00 +0100 | [diff] [blame] | 59 | s.RunUntil(TimeDelta::Seconds(2), TimeDelta::Millis(5), |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 60 | [&bitrate_changed, &packet_received] { |
| 61 | return packet_received && bitrate_changed; |
| 62 | }); |
| 63 | EXPECT_TRUE(packet_received); |
| 64 | EXPECT_TRUE(bitrate_changed); |
| 65 | } |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 66 | namespace { |
| 67 | void SetupVideoCall(Scenario& s, VideoQualityAnalyzer* analyzer) { |
| 68 | CallClientConfig call_config; |
| 69 | auto* alice = s.CreateClient("alice", call_config); |
| 70 | auto* bob = s.CreateClient("bob", call_config); |
Sebastian Jansson | ef86d14 | 2019-04-15 14:42:42 +0200 | [diff] [blame] | 71 | NetworkSimulationConfig network_config; |
Danil Chapovalov | cad3e0e | 2020-02-17 18:46:07 +0100 | [diff] [blame] | 72 | network_config.bandwidth = DataRate::KilobitsPerSec(1000); |
Danil Chapovalov | 0c626af | 2020-02-10 11:16:00 +0100 | [diff] [blame] | 73 | network_config.delay = TimeDelta::Millis(50); |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 74 | auto alice_net = s.CreateSimulationNode(network_config); |
| 75 | auto bob_net = s.CreateSimulationNode(network_config); |
| 76 | auto route = s.CreateRoutes(alice, {alice_net}, bob, {bob_net}); |
| 77 | VideoStreamConfig video; |
| 78 | if (analyzer) { |
| 79 | video.source.capture = VideoStreamConfig::Source::Capture::kVideoFile; |
| 80 | video.source.video_file.name = "foreman_cif"; |
| 81 | video.source.video_file.width = 352; |
| 82 | video.source.video_file.height = 288; |
| 83 | video.source.framerate = 30; |
| 84 | video.encoder.codec = VideoStreamConfig::Encoder::Codec::kVideoCodecVP8; |
| 85 | video.encoder.implementation = |
| 86 | VideoStreamConfig::Encoder::Implementation::kSoftware; |
| 87 | video.hooks.frame_pair_handlers = {analyzer->Handler()}; |
| 88 | } |
| 89 | s.CreateVideoStream(route->forward(), video); |
| 90 | s.CreateAudioStream(route->forward(), AudioStreamConfig()); |
| 91 | } |
| 92 | } // namespace |
| 93 | |
Patrik Höglund | 7d3f602 | 2020-03-02 14:45:21 +0100 | [diff] [blame] | 94 | TEST(ScenarioTest, SimTimeEncoding) { |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 95 | VideoQualityAnalyzerConfig analyzer_config; |
| 96 | analyzer_config.psnr_coverage = 0.1; |
| 97 | VideoQualityAnalyzer analyzer(analyzer_config); |
| 98 | { |
| 99 | Scenario s("scenario/encode_sim", false); |
| 100 | SetupVideoCall(s, &analyzer); |
Patrik Höglund | cdda76d | 2020-02-20 12:07:29 +0100 | [diff] [blame] | 101 | s.RunFor(TimeDelta::Seconds(2)); |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 102 | } |
| 103 | // Regression tests based on previous runs. |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 104 | EXPECT_EQ(analyzer.stats().lost_count, 0); |
Patrik Höglund | 7d3f602 | 2020-03-02 14:45:21 +0100 | [diff] [blame] | 105 | EXPECT_NEAR(analyzer.stats().psnr_with_freeze.Mean(), 38, 5); |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 106 | } |
| 107 | |
Sebastian Jansson | 8694118 | 2019-04-09 15:15:24 +0200 | [diff] [blame] | 108 | // TODO(bugs.webrtc.org/10515): Remove this when performance has been improved. |
Sebastian Jansson | 7237c15 | 2019-04-08 16:47:49 +0200 | [diff] [blame] | 109 | #if defined(WEBRTC_IOS) && defined(WEBRTC_ARCH_ARM64) && !defined(NDEBUG) |
| 110 | #define MAYBE_RealTimeEncoding DISABLED_RealTimeEncoding |
| 111 | #else |
| 112 | #define MAYBE_RealTimeEncoding RealTimeEncoding |
| 113 | #endif |
| 114 | TEST(ScenarioTest, MAYBE_RealTimeEncoding) { |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 115 | VideoQualityAnalyzerConfig analyzer_config; |
| 116 | analyzer_config.psnr_coverage = 0.1; |
| 117 | VideoQualityAnalyzer analyzer(analyzer_config); |
| 118 | { |
| 119 | Scenario s("scenario/encode_real", true); |
| 120 | SetupVideoCall(s, &analyzer); |
Patrik Höglund | cdda76d | 2020-02-20 12:07:29 +0100 | [diff] [blame] | 121 | s.RunFor(TimeDelta::Seconds(2)); |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 122 | } |
| 123 | // Regression tests based on previous runs. |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 124 | EXPECT_LT(analyzer.stats().lost_count, 2); |
Sebastian Jansson | f72de7b | 2020-06-11 14:09:17 +0200 | [diff] [blame] | 125 | // This far below expected but ensures that we get something. |
| 126 | EXPECT_GT(analyzer.stats().psnr_with_freeze.Mean(), 10); |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | TEST(ScenarioTest, SimTimeFakeing) { |
| 130 | Scenario s("scenario/encode_sim", false); |
| 131 | SetupVideoCall(s, nullptr); |
Patrik Höglund | cdda76d | 2020-02-20 12:07:29 +0100 | [diff] [blame] | 132 | s.RunFor(TimeDelta::Seconds(2)); |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 133 | } |
| 134 | |
Sebastian Jansson | 58c71db | 2019-05-22 16:20:56 +0200 | [diff] [blame] | 135 | TEST(ScenarioTest, WritesToRtcEventLog) { |
| 136 | MemoryLogStorage storage; |
| 137 | { |
| 138 | Scenario s(storage.CreateFactory(), false); |
| 139 | SetupVideoCall(s, nullptr); |
Danil Chapovalov | 0c626af | 2020-02-10 11:16:00 +0100 | [diff] [blame] | 140 | s.RunFor(TimeDelta::Seconds(1)); |
Sebastian Jansson | 58c71db | 2019-05-22 16:20:56 +0200 | [diff] [blame] | 141 | } |
| 142 | auto logs = storage.logs(); |
| 143 | // We expect that a rtc event log has been created and that it has some data. |
| 144 | EXPECT_GE(storage.logs().at("alice.rtc.dat").size(), 1u); |
| 145 | } |
| 146 | |
Erik Språng | 000953c | 2020-06-26 17:03:19 +0200 | [diff] [blame] | 147 | TEST(ScenarioTest, |
| 148 | RetransmitsVideoPacketsInAudioAndVideoCallWithSendSideBweAndLoss) { |
| 149 | // Make sure audio packets are included in transport feedback. |
| 150 | test::ScopedFieldTrials override_field_trials( |
Jakob Ivarsson | 47a03e8 | 2020-11-23 15:05:44 +0100 | [diff] [blame] | 151 | "WebRTC-Audio-ABWENoTWCC/Disabled/"); |
Erik Språng | 000953c | 2020-06-26 17:03:19 +0200 | [diff] [blame] | 152 | |
| 153 | Scenario s; |
| 154 | CallClientConfig call_client_config; |
| 155 | call_client_config.transport.rates.start_rate = DataRate::KilobitsPerSec(300); |
| 156 | auto* alice = s.CreateClient("alice", call_client_config); |
| 157 | auto* bob = s.CreateClient("bob", call_client_config); |
| 158 | NetworkSimulationConfig network_config; |
| 159 | // Add some loss and delay. |
| 160 | network_config.delay = TimeDelta::Millis(200); |
| 161 | network_config.loss_rate = 0.05; |
| 162 | auto alice_net = s.CreateSimulationNode(network_config); |
| 163 | auto bob_net = s.CreateSimulationNode(network_config); |
| 164 | auto route = s.CreateRoutes(alice, {alice_net}, bob, {bob_net}); |
| 165 | |
| 166 | // First add an audio stream, then a video stream. |
| 167 | // Needed to make sure audio RTP module is selected first when sending |
| 168 | // transport feedback message. |
| 169 | AudioStreamConfig audio_stream_config; |
| 170 | audio_stream_config.encoder.min_rate = DataRate::KilobitsPerSec(6); |
| 171 | audio_stream_config.encoder.max_rate = DataRate::KilobitsPerSec(64); |
| 172 | audio_stream_config.encoder.allocate_bitrate = true; |
| 173 | audio_stream_config.stream.in_bandwidth_estimation = true; |
| 174 | s.CreateAudioStream(route->forward(), audio_stream_config); |
| 175 | s.CreateAudioStream(route->reverse(), audio_stream_config); |
| 176 | |
| 177 | VideoStreamConfig video_stream_config; |
| 178 | auto video = s.CreateVideoStream(route->forward(), video_stream_config); |
| 179 | s.CreateVideoStream(route->reverse(), video_stream_config); |
| 180 | |
| 181 | // Run for 10 seconds. |
| 182 | s.RunFor(TimeDelta::Seconds(10)); |
| 183 | // Make sure retransmissions have happened. |
| 184 | int retransmit_packets = 0; |
Tomas Gunnarsson | 788d805 | 2021-05-03 16:23:08 +0200 | [diff] [blame] | 185 | |
| 186 | VideoSendStream::Stats stats; |
| 187 | alice->SendTask([&]() { stats = video->send()->GetStats(); }); |
| 188 | |
| 189 | for (const auto& substream : stats.substreams) { |
Erik Språng | 000953c | 2020-06-26 17:03:19 +0200 | [diff] [blame] | 190 | retransmit_packets += substream.second.rtp_stats.retransmitted.packets; |
| 191 | } |
| 192 | EXPECT_GT(retransmit_packets, 0); |
| 193 | } |
| 194 | |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 195 | } // namespace test |
| 196 | } // namespace webrtc |