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