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