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 | |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 14 | #include "test/gtest.h" |
Sebastian Jansson | 58c71db | 2019-05-22 16:20:56 +0200 | [diff] [blame] | 15 | #include "test/logging/memory_log_writer.h" |
Sebastian Jansson | 7150d8c | 2019-04-09 14:18:09 +0200 | [diff] [blame] | 16 | #include "test/scenario/stats_collection.h" |
| 17 | |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 18 | namespace webrtc { |
| 19 | namespace test { |
| 20 | TEST(ScenarioTest, StartsAndStopsWithoutErrors) { |
Sebastian Jansson | 105a10a | 2019-04-01 09:18:14 +0200 | [diff] [blame] | 21 | std::atomic<bool> packet_received(false); |
| 22 | std::atomic<bool> bitrate_changed(false); |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 23 | Scenario s; |
| 24 | CallClientConfig call_client_config; |
| 25 | call_client_config.transport.rates.start_rate = DataRate::kbps(300); |
| 26 | auto* alice = s.CreateClient("alice", call_client_config); |
| 27 | auto* bob = s.CreateClient("bob", call_client_config); |
Sebastian Jansson | ef86d14 | 2019-04-15 14:42:42 +0200 | [diff] [blame] | 28 | NetworkSimulationConfig network_config; |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 29 | auto alice_net = s.CreateSimulationNode(network_config); |
| 30 | auto bob_net = s.CreateSimulationNode(network_config); |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 31 | auto route = s.CreateRoutes(alice, {alice_net}, bob, {bob_net}); |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 32 | |
| 33 | VideoStreamConfig video_stream_config; |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 34 | s.CreateVideoStream(route->forward(), video_stream_config); |
| 35 | s.CreateVideoStream(route->reverse(), video_stream_config); |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 36 | |
| 37 | AudioStreamConfig audio_stream_config; |
Sebastian Jansson | 8285841 | 2018-10-11 19:48:05 +0200 | [diff] [blame] | 38 | audio_stream_config.encoder.min_rate = DataRate::kbps(6); |
| 39 | audio_stream_config.encoder.max_rate = DataRate::kbps(64); |
| 40 | audio_stream_config.encoder.allocate_bitrate = true; |
| 41 | audio_stream_config.stream.in_bandwidth_estimation = false; |
Sebastian Jansson | 800e121 | 2018-10-22 11:49:03 +0200 | [diff] [blame] | 42 | s.CreateAudioStream(route->forward(), audio_stream_config); |
| 43 | s.CreateAudioStream(route->reverse(), audio_stream_config); |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 44 | |
Sebastian Jansson | a4c22b9 | 2019-04-15 21:10:00 +0200 | [diff] [blame] | 45 | RandomWalkConfig cross_traffic_config; |
| 46 | s.net()->CreateRandomWalkCrossTraffic( |
| 47 | s.net()->CreateTrafficRoute({alice_net}), cross_traffic_config); |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 48 | |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 49 | s.NetworkDelayedAction({alice_net, bob_net}, 100, |
| 50 | [&packet_received] { packet_received = true; }); |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 51 | s.Every(TimeDelta::ms(10), [alice, bob, &bitrate_changed] { |
| 52 | if (alice->GetStats().send_bandwidth_bps != 300000 && |
| 53 | bob->GetStats().send_bandwidth_bps != 300000) |
| 54 | bitrate_changed = true; |
| 55 | }); |
| 56 | s.RunUntil(TimeDelta::seconds(2), TimeDelta::ms(5), |
| 57 | [&bitrate_changed, &packet_received] { |
| 58 | return packet_received && bitrate_changed; |
| 59 | }); |
| 60 | EXPECT_TRUE(packet_received); |
| 61 | EXPECT_TRUE(bitrate_changed); |
| 62 | } |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 63 | namespace { |
| 64 | void SetupVideoCall(Scenario& s, VideoQualityAnalyzer* analyzer) { |
| 65 | CallClientConfig call_config; |
| 66 | auto* alice = s.CreateClient("alice", call_config); |
| 67 | auto* bob = s.CreateClient("bob", call_config); |
Sebastian Jansson | ef86d14 | 2019-04-15 14:42:42 +0200 | [diff] [blame] | 68 | NetworkSimulationConfig network_config; |
| 69 | network_config.bandwidth = DataRate::kbps(1000); |
| 70 | network_config.delay = TimeDelta::ms(50); |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 71 | auto alice_net = s.CreateSimulationNode(network_config); |
| 72 | auto bob_net = s.CreateSimulationNode(network_config); |
| 73 | auto route = s.CreateRoutes(alice, {alice_net}, bob, {bob_net}); |
| 74 | VideoStreamConfig video; |
| 75 | if (analyzer) { |
| 76 | video.source.capture = VideoStreamConfig::Source::Capture::kVideoFile; |
| 77 | video.source.video_file.name = "foreman_cif"; |
| 78 | video.source.video_file.width = 352; |
| 79 | video.source.video_file.height = 288; |
| 80 | video.source.framerate = 30; |
| 81 | video.encoder.codec = VideoStreamConfig::Encoder::Codec::kVideoCodecVP8; |
| 82 | video.encoder.implementation = |
| 83 | VideoStreamConfig::Encoder::Implementation::kSoftware; |
| 84 | video.hooks.frame_pair_handlers = {analyzer->Handler()}; |
| 85 | } |
| 86 | s.CreateVideoStream(route->forward(), video); |
| 87 | s.CreateAudioStream(route->forward(), AudioStreamConfig()); |
| 88 | } |
| 89 | } // namespace |
| 90 | |
Sebastian Jansson | 8694118 | 2019-04-09 15:15:24 +0200 | [diff] [blame] | 91 | // TODO(bugs.webrtc.org/10515): Remove this when performance has been improved. |
| 92 | #if defined(WEBRTC_IOS) && defined(WEBRTC_ARCH_ARM64) && !defined(NDEBUG) |
| 93 | #define MAYBE_SimTimeEncoding DISABLED_SimTimeEncoding |
| 94 | #else |
| 95 | #define MAYBE_SimTimeEncoding SimTimeEncoding |
| 96 | #endif |
Sebastian Jansson | 7237c15 | 2019-04-08 16:47:49 +0200 | [diff] [blame] | 97 | TEST(ScenarioTest, MAYBE_SimTimeEncoding) { |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 98 | VideoQualityAnalyzerConfig analyzer_config; |
| 99 | analyzer_config.psnr_coverage = 0.1; |
| 100 | VideoQualityAnalyzer analyzer(analyzer_config); |
| 101 | { |
| 102 | Scenario s("scenario/encode_sim", false); |
| 103 | SetupVideoCall(s, &analyzer); |
| 104 | s.RunFor(TimeDelta::seconds(60)); |
| 105 | } |
| 106 | // Regression tests based on previous runs. |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 107 | EXPECT_EQ(analyzer.stats().lost_count, 0); |
Sebastian Jansson | e9cac4f | 2019-06-24 17:10:55 +0200 | [diff] [blame] | 108 | EXPECT_NEAR(analyzer.stats().psnr_with_freeze.Mean(), 38, 2); |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 109 | } |
| 110 | |
Sebastian Jansson | 8694118 | 2019-04-09 15:15:24 +0200 | [diff] [blame] | 111 | // TODO(bugs.webrtc.org/10515): Remove this when performance has been improved. |
Sebastian Jansson | 7237c15 | 2019-04-08 16:47:49 +0200 | [diff] [blame] | 112 | #if defined(WEBRTC_IOS) && defined(WEBRTC_ARCH_ARM64) && !defined(NDEBUG) |
| 113 | #define MAYBE_RealTimeEncoding DISABLED_RealTimeEncoding |
| 114 | #else |
| 115 | #define MAYBE_RealTimeEncoding RealTimeEncoding |
| 116 | #endif |
| 117 | TEST(ScenarioTest, MAYBE_RealTimeEncoding) { |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 118 | VideoQualityAnalyzerConfig analyzer_config; |
| 119 | analyzer_config.psnr_coverage = 0.1; |
| 120 | VideoQualityAnalyzer analyzer(analyzer_config); |
| 121 | { |
| 122 | Scenario s("scenario/encode_real", true); |
| 123 | SetupVideoCall(s, &analyzer); |
| 124 | s.RunFor(TimeDelta::seconds(10)); |
| 125 | } |
| 126 | // Regression tests based on previous runs. |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 127 | EXPECT_LT(analyzer.stats().lost_count, 2); |
Sebastian Jansson | e9cac4f | 2019-06-24 17:10:55 +0200 | [diff] [blame] | 128 | EXPECT_NEAR(analyzer.stats().psnr_with_freeze.Mean(), 38, 10); |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | TEST(ScenarioTest, SimTimeFakeing) { |
| 132 | Scenario s("scenario/encode_sim", false); |
| 133 | SetupVideoCall(s, nullptr); |
| 134 | s.RunFor(TimeDelta::seconds(10)); |
| 135 | } |
| 136 | |
Sebastian Jansson | 58c71db | 2019-05-22 16:20:56 +0200 | [diff] [blame] | 137 | TEST(ScenarioTest, WritesToRtcEventLog) { |
| 138 | MemoryLogStorage storage; |
| 139 | { |
| 140 | Scenario s(storage.CreateFactory(), false); |
| 141 | SetupVideoCall(s, nullptr); |
| 142 | s.RunFor(TimeDelta::seconds(1)); |
| 143 | } |
| 144 | auto logs = storage.logs(); |
| 145 | // We expect that a rtc event log has been created and that it has some data. |
| 146 | EXPECT_GE(storage.logs().at("alice.rtc.dat").size(), 1u); |
| 147 | } |
| 148 | |
Sebastian Jansson | 98b07e9 | 2018-09-27 13:47:01 +0200 | [diff] [blame] | 149 | } // namespace test |
| 150 | } // namespace webrtc |