blob: 1a0e1ff2d6b1d06e19698c0b643f8b001913f89e [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 */
Sebastian Jansson105a10a2019-04-01 09:18:14 +020010#include <atomic>
Sebastian Jansson98b07e92018-09-27 13:47:01 +020011
Sebastian Jansson98b07e92018-09-27 13:47:01 +020012#include "test/gtest.h"
Sebastian Jansson58c71db2019-05-22 16:20:56 +020013#include "test/logging/memory_log_writer.h"
Sebastian Jansson7150d8c2019-04-09 14:18:09 +020014#include "test/scenario/scenario.h"
15#include "test/scenario/stats_collection.h"
16
Sebastian Jansson98b07e92018-09-27 13:47:01 +020017namespace webrtc {
18namespace test {
19TEST(ScenarioTest, StartsAndStopsWithoutErrors) {
Sebastian Jansson105a10a2019-04-01 09:18:14 +020020 std::atomic<bool> packet_received(false);
21 std::atomic<bool> bitrate_changed(false);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020022 Scenario s;
23 CallClientConfig call_client_config;
24 call_client_config.transport.rates.start_rate = DataRate::kbps(300);
25 auto* alice = s.CreateClient("alice", call_client_config);
26 auto* bob = s.CreateClient("bob", call_client_config);
Sebastian Janssonef86d142019-04-15 14:42:42 +020027 NetworkSimulationConfig network_config;
Sebastian Jansson98b07e92018-09-27 13:47:01 +020028 auto alice_net = s.CreateSimulationNode(network_config);
29 auto bob_net = s.CreateSimulationNode(network_config);
Sebastian Jansson800e1212018-10-22 11:49:03 +020030 auto route = s.CreateRoutes(alice, {alice_net}, bob, {bob_net});
Sebastian Jansson98b07e92018-09-27 13:47:01 +020031
32 VideoStreamConfig video_stream_config;
Sebastian Jansson800e1212018-10-22 11:49:03 +020033 s.CreateVideoStream(route->forward(), video_stream_config);
34 s.CreateVideoStream(route->reverse(), video_stream_config);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020035
36 AudioStreamConfig audio_stream_config;
Sebastian Jansson82858412018-10-11 19:48:05 +020037 audio_stream_config.encoder.min_rate = DataRate::kbps(6);
38 audio_stream_config.encoder.max_rate = DataRate::kbps(64);
39 audio_stream_config.encoder.allocate_bitrate = true;
40 audio_stream_config.stream.in_bandwidth_estimation = false;
Sebastian Jansson800e1212018-10-22 11:49:03 +020041 s.CreateAudioStream(route->forward(), audio_stream_config);
42 s.CreateAudioStream(route->reverse(), audio_stream_config);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020043
Sebastian Janssona4c22b92019-04-15 21:10:00 +020044 RandomWalkConfig cross_traffic_config;
45 s.net()->CreateRandomWalkCrossTraffic(
46 s.net()->CreateTrafficRoute({alice_net}), cross_traffic_config);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020047
Sebastian Jansson98b07e92018-09-27 13:47:01 +020048 s.NetworkDelayedAction({alice_net, bob_net}, 100,
49 [&packet_received] { packet_received = true; });
Sebastian Jansson98b07e92018-09-27 13:47:01 +020050 s.Every(TimeDelta::ms(10), [alice, bob, &bitrate_changed] {
51 if (alice->GetStats().send_bandwidth_bps != 300000 &&
52 bob->GetStats().send_bandwidth_bps != 300000)
53 bitrate_changed = true;
54 });
55 s.RunUntil(TimeDelta::seconds(2), TimeDelta::ms(5),
56 [&bitrate_changed, &packet_received] {
57 return packet_received && bitrate_changed;
58 });
59 EXPECT_TRUE(packet_received);
60 EXPECT_TRUE(bitrate_changed);
61}
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020062namespace {
63void SetupVideoCall(Scenario& s, VideoQualityAnalyzer* analyzer) {
64 CallClientConfig call_config;
65 auto* alice = s.CreateClient("alice", call_config);
66 auto* bob = s.CreateClient("bob", call_config);
Sebastian Janssonef86d142019-04-15 14:42:42 +020067 NetworkSimulationConfig network_config;
68 network_config.bandwidth = DataRate::kbps(1000);
69 network_config.delay = TimeDelta::ms(50);
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020070 auto alice_net = s.CreateSimulationNode(network_config);
71 auto bob_net = s.CreateSimulationNode(network_config);
72 auto route = s.CreateRoutes(alice, {alice_net}, bob, {bob_net});
73 VideoStreamConfig video;
74 if (analyzer) {
75 video.source.capture = VideoStreamConfig::Source::Capture::kVideoFile;
76 video.source.video_file.name = "foreman_cif";
77 video.source.video_file.width = 352;
78 video.source.video_file.height = 288;
79 video.source.framerate = 30;
80 video.encoder.codec = VideoStreamConfig::Encoder::Codec::kVideoCodecVP8;
81 video.encoder.implementation =
82 VideoStreamConfig::Encoder::Implementation::kSoftware;
83 video.hooks.frame_pair_handlers = {analyzer->Handler()};
84 }
85 s.CreateVideoStream(route->forward(), video);
86 s.CreateAudioStream(route->forward(), AudioStreamConfig());
87}
88} // namespace
89
Sebastian Jansson86941182019-04-09 15:15:24 +020090// TODO(bugs.webrtc.org/10515): Remove this when performance has been improved.
91#if defined(WEBRTC_IOS) && defined(WEBRTC_ARCH_ARM64) && !defined(NDEBUG)
92#define MAYBE_SimTimeEncoding DISABLED_SimTimeEncoding
93#else
94#define MAYBE_SimTimeEncoding SimTimeEncoding
95#endif
Sebastian Jansson7237c152019-04-08 16:47:49 +020096TEST(ScenarioTest, MAYBE_SimTimeEncoding) {
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020097 VideoQualityAnalyzerConfig analyzer_config;
98 analyzer_config.psnr_coverage = 0.1;
99 VideoQualityAnalyzer analyzer(analyzer_config);
100 {
101 Scenario s("scenario/encode_sim", false);
102 SetupVideoCall(s, &analyzer);
103 s.RunFor(TimeDelta::seconds(60));
104 }
105 // Regression tests based on previous runs.
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +0200106 EXPECT_EQ(analyzer.stats().lost_count, 0);
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +0200107 EXPECT_NEAR(analyzer.stats().psnr.Mean(), 38, 2);
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +0200108}
109
Sebastian Jansson86941182019-04-09 15:15:24 +0200110// TODO(bugs.webrtc.org/10515): Remove this when performance has been improved.
Sebastian Jansson7237c152019-04-08 16:47:49 +0200111#if defined(WEBRTC_IOS) && defined(WEBRTC_ARCH_ARM64) && !defined(NDEBUG)
112#define MAYBE_RealTimeEncoding DISABLED_RealTimeEncoding
113#else
114#define MAYBE_RealTimeEncoding RealTimeEncoding
115#endif
116TEST(ScenarioTest, MAYBE_RealTimeEncoding) {
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +0200117 VideoQualityAnalyzerConfig analyzer_config;
118 analyzer_config.psnr_coverage = 0.1;
119 VideoQualityAnalyzer analyzer(analyzer_config);
120 {
121 Scenario s("scenario/encode_real", true);
122 SetupVideoCall(s, &analyzer);
123 s.RunFor(TimeDelta::seconds(10));
124 }
125 // Regression tests based on previous runs.
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +0200126 EXPECT_LT(analyzer.stats().lost_count, 2);
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +0200127 EXPECT_NEAR(analyzer.stats().psnr.Mean(), 38, 10);
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +0200128}
129
130TEST(ScenarioTest, SimTimeFakeing) {
131 Scenario s("scenario/encode_sim", false);
132 SetupVideoCall(s, nullptr);
133 s.RunFor(TimeDelta::seconds(10));
134}
135
Sebastian Jansson58c71db2019-05-22 16:20:56 +0200136TEST(ScenarioTest, WritesToRtcEventLog) {
137 MemoryLogStorage storage;
138 {
139 Scenario s(storage.CreateFactory(), false);
140 SetupVideoCall(s, nullptr);
141 s.RunFor(TimeDelta::seconds(1));
142 }
143 auto logs = storage.logs();
144 // We expect that a rtc event log has been created and that it has some data.
145 EXPECT_GE(storage.logs().at("alice.rtc.dat").size(), 1u);
146}
147
Sebastian Jansson98b07e92018-09-27 13:47:01 +0200148} // namespace test
149} // namespace webrtc