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