blob: 177ac27373bcedccf2d409252197cec4b2be0142 [file] [log] [blame]
Sebastian Jansson98b07e92018-09-27 13:47:01 +02001/*
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 Olssona4d87372019-07-05 19:08:33 +020010#include "test/scenario/scenario.h"
11
Sebastian Jansson105a10a2019-04-01 09:18:14 +020012#include <atomic>
Sebastian Jansson98b07e92018-09-27 13:47:01 +020013
Erik Språng000953c2020-06-26 17:03:19 +020014#include "test/field_trial.h"
Sebastian Jansson98b07e92018-09-27 13:47:01 +020015#include "test/gtest.h"
Sebastian Jansson58c71db2019-05-22 16:20:56 +020016#include "test/logging/memory_log_writer.h"
Sebastian Jansson7150d8c2019-04-09 14:18:09 +020017#include "test/scenario/stats_collection.h"
18
Sebastian Jansson98b07e92018-09-27 13:47:01 +020019namespace webrtc {
20namespace test {
21TEST(ScenarioTest, StartsAndStopsWithoutErrors) {
Sebastian Jansson105a10a2019-04-01 09:18:14 +020022 std::atomic<bool> packet_received(false);
23 std::atomic<bool> bitrate_changed(false);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020024 Scenario s;
25 CallClientConfig call_client_config;
Danil Chapovalovcad3e0e2020-02-17 18:46:07 +010026 call_client_config.transport.rates.start_rate = DataRate::KilobitsPerSec(300);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020027 auto* alice = s.CreateClient("alice", call_client_config);
28 auto* bob = s.CreateClient("bob", call_client_config);
Sebastian Janssonef86d142019-04-15 14:42:42 +020029 NetworkSimulationConfig network_config;
Sebastian Jansson98b07e92018-09-27 13:47:01 +020030 auto alice_net = s.CreateSimulationNode(network_config);
31 auto bob_net = s.CreateSimulationNode(network_config);
Sebastian Jansson800e1212018-10-22 11:49:03 +020032 auto route = s.CreateRoutes(alice, {alice_net}, bob, {bob_net});
Sebastian Jansson98b07e92018-09-27 13:47:01 +020033
34 VideoStreamConfig video_stream_config;
Sebastian Jansson800e1212018-10-22 11:49:03 +020035 s.CreateVideoStream(route->forward(), video_stream_config);
36 s.CreateVideoStream(route->reverse(), video_stream_config);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020037
38 AudioStreamConfig audio_stream_config;
Danil Chapovalovcad3e0e2020-02-17 18:46:07 +010039 audio_stream_config.encoder.min_rate = DataRate::KilobitsPerSec(6);
40 audio_stream_config.encoder.max_rate = DataRate::KilobitsPerSec(64);
Sebastian Jansson82858412018-10-11 19:48:05 +020041 audio_stream_config.encoder.allocate_bitrate = true;
42 audio_stream_config.stream.in_bandwidth_estimation = false;
Sebastian Jansson800e1212018-10-22 11:49:03 +020043 s.CreateAudioStream(route->forward(), audio_stream_config);
44 s.CreateAudioStream(route->reverse(), audio_stream_config);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020045
Sebastian Janssona4c22b92019-04-15 21:10:00 +020046 RandomWalkConfig cross_traffic_config;
47 s.net()->CreateRandomWalkCrossTraffic(
48 s.net()->CreateTrafficRoute({alice_net}), cross_traffic_config);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020049
Sebastian Jansson98b07e92018-09-27 13:47:01 +020050 s.NetworkDelayedAction({alice_net, bob_net}, 100,
51 [&packet_received] { packet_received = true; });
Danil Chapovalov0c626af2020-02-10 11:16:00 +010052 s.Every(TimeDelta::Millis(10), [alice, bob, &bitrate_changed] {
Sebastian Jansson98b07e92018-09-27 13:47:01 +020053 if (alice->GetStats().send_bandwidth_bps != 300000 &&
54 bob->GetStats().send_bandwidth_bps != 300000)
55 bitrate_changed = true;
56 });
Danil Chapovalov0c626af2020-02-10 11:16:00 +010057 s.RunUntil(TimeDelta::Seconds(2), TimeDelta::Millis(5),
Sebastian Jansson98b07e92018-09-27 13:47:01 +020058 [&bitrate_changed, &packet_received] {
59 return packet_received && bitrate_changed;
60 });
61 EXPECT_TRUE(packet_received);
62 EXPECT_TRUE(bitrate_changed);
63}
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020064namespace {
65void 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 Janssonef86d142019-04-15 14:42:42 +020069 NetworkSimulationConfig network_config;
Danil Chapovalovcad3e0e2020-02-17 18:46:07 +010070 network_config.bandwidth = DataRate::KilobitsPerSec(1000);
Danil Chapovalov0c626af2020-02-10 11:16:00 +010071 network_config.delay = TimeDelta::Millis(50);
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020072 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öglund7d3f6022020-03-02 14:45:21 +010092TEST(ScenarioTest, SimTimeEncoding) {
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020093 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öglundcdda76d2020-02-20 12:07:29 +010099 s.RunFor(TimeDelta::Seconds(2));
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +0200100 }
101 // Regression tests based on previous runs.
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +0200102 EXPECT_EQ(analyzer.stats().lost_count, 0);
Patrik Höglund7d3f6022020-03-02 14:45:21 +0100103 EXPECT_NEAR(analyzer.stats().psnr_with_freeze.Mean(), 38, 5);
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +0200104}
105
Sebastian Jansson86941182019-04-09 15:15:24 +0200106// TODO(bugs.webrtc.org/10515): Remove this when performance has been improved.
Sebastian Jansson7237c152019-04-08 16:47:49 +0200107#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
112TEST(ScenarioTest, MAYBE_RealTimeEncoding) {
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +0200113 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öglundcdda76d2020-02-20 12:07:29 +0100119 s.RunFor(TimeDelta::Seconds(2));
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +0200120 }
121 // Regression tests based on previous runs.
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +0200122 EXPECT_LT(analyzer.stats().lost_count, 2);
Sebastian Janssonf72de7b2020-06-11 14:09:17 +0200123 // This far below expected but ensures that we get something.
124 EXPECT_GT(analyzer.stats().psnr_with_freeze.Mean(), 10);
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +0200125}
126
127TEST(ScenarioTest, SimTimeFakeing) {
128 Scenario s("scenario/encode_sim", false);
129 SetupVideoCall(s, nullptr);
Patrik Höglundcdda76d2020-02-20 12:07:29 +0100130 s.RunFor(TimeDelta::Seconds(2));
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +0200131}
132
Sebastian Jansson58c71db2019-05-22 16:20:56 +0200133TEST(ScenarioTest, WritesToRtcEventLog) {
134 MemoryLogStorage storage;
135 {
136 Scenario s(storage.CreateFactory(), false);
137 SetupVideoCall(s, nullptr);
Danil Chapovalov0c626af2020-02-10 11:16:00 +0100138 s.RunFor(TimeDelta::Seconds(1));
Sebastian Jansson58c71db2019-05-22 16:20:56 +0200139 }
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ång000953c2020-06-26 17:03:19 +0200145TEST(ScenarioTest,
146 RetransmitsVideoPacketsInAudioAndVideoCallWithSendSideBweAndLoss) {
147 // Make sure audio packets are included in transport feedback.
148 test::ScopedFieldTrials override_field_trials(
Jakob Ivarsson47a03e82020-11-23 15:05:44 +0100149 "WebRTC-Audio-ABWENoTWCC/Disabled/");
Erik Språng000953c2020-06-26 17:03:19 +0200150
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 Jansson98b07e92018-09-27 13:47:01 +0200189} // namespace test
190} // namespace webrtc