blob: c0f850801c655b2560f0c3827052289a55f388d8 [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 Jansson7150d8c2019-04-09 14:18:09 +020013#include "test/scenario/scenario.h"
14#include "test/scenario/stats_collection.h"
15
Sebastian Jansson98b07e92018-09-27 13:47:01 +020016namespace webrtc {
17namespace test {
18TEST(ScenarioTest, StartsAndStopsWithoutErrors) {
Sebastian Jansson105a10a2019-04-01 09:18:14 +020019 std::atomic<bool> packet_received(false);
20 std::atomic<bool> bitrate_changed(false);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020021 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);
26 NetworkNodeConfig network_config;
27 auto alice_net = s.CreateSimulationNode(network_config);
28 auto bob_net = s.CreateSimulationNode(network_config);
Sebastian Jansson800e1212018-10-22 11:49:03 +020029 auto route = s.CreateRoutes(alice, {alice_net}, bob, {bob_net});
Sebastian Jansson98b07e92018-09-27 13:47:01 +020030
31 VideoStreamConfig video_stream_config;
Sebastian Jansson800e1212018-10-22 11:49:03 +020032 s.CreateVideoStream(route->forward(), video_stream_config);
33 s.CreateVideoStream(route->reverse(), video_stream_config);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020034
35 AudioStreamConfig audio_stream_config;
Sebastian Jansson82858412018-10-11 19:48:05 +020036 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 Jansson800e1212018-10-22 11:49:03 +020040 s.CreateAudioStream(route->forward(), audio_stream_config);
41 s.CreateAudioStream(route->reverse(), audio_stream_config);
Sebastian Jansson98b07e92018-09-27 13:47:01 +020042
43 CrossTrafficConfig cross_traffic_config;
44 s.CreateCrossTraffic({alice_net}, cross_traffic_config);
45
Sebastian Jansson98b07e92018-09-27 13:47:01 +020046 s.NetworkDelayedAction({alice_net, bob_net}, 100,
47 [&packet_received] { packet_received = true; });
Sebastian Jansson98b07e92018-09-27 13:47:01 +020048 s.Every(TimeDelta::ms(10), [alice, bob, &bitrate_changed] {
49 if (alice->GetStats().send_bandwidth_bps != 300000 &&
50 bob->GetStats().send_bandwidth_bps != 300000)
51 bitrate_changed = true;
52 });
53 s.RunUntil(TimeDelta::seconds(2), TimeDelta::ms(5),
54 [&bitrate_changed, &packet_received] {
55 return packet_received && bitrate_changed;
56 });
57 EXPECT_TRUE(packet_received);
58 EXPECT_TRUE(bitrate_changed);
59}
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020060namespace {
61void SetupVideoCall(Scenario& s, VideoQualityAnalyzer* analyzer) {
62 CallClientConfig call_config;
63 auto* alice = s.CreateClient("alice", call_config);
64 auto* bob = s.CreateClient("bob", call_config);
65 NetworkNodeConfig network_config;
66 network_config.simulation.bandwidth = DataRate::kbps(1000);
67 network_config.simulation.delay = TimeDelta::ms(50);
68 auto alice_net = s.CreateSimulationNode(network_config);
69 auto bob_net = s.CreateSimulationNode(network_config);
70 auto route = s.CreateRoutes(alice, {alice_net}, bob, {bob_net});
71 VideoStreamConfig video;
72 if (analyzer) {
73 video.source.capture = VideoStreamConfig::Source::Capture::kVideoFile;
74 video.source.video_file.name = "foreman_cif";
75 video.source.video_file.width = 352;
76 video.source.video_file.height = 288;
77 video.source.framerate = 30;
78 video.encoder.codec = VideoStreamConfig::Encoder::Codec::kVideoCodecVP8;
79 video.encoder.implementation =
80 VideoStreamConfig::Encoder::Implementation::kSoftware;
81 video.hooks.frame_pair_handlers = {analyzer->Handler()};
82 }
83 s.CreateVideoStream(route->forward(), video);
84 s.CreateAudioStream(route->forward(), AudioStreamConfig());
85}
86} // namespace
87
Sebastian Jansson86941182019-04-09 15:15:24 +020088// TODO(bugs.webrtc.org/10515): Remove this when performance has been improved.
89#if defined(WEBRTC_IOS) && defined(WEBRTC_ARCH_ARM64) && !defined(NDEBUG)
90#define MAYBE_SimTimeEncoding DISABLED_SimTimeEncoding
91#else
92#define MAYBE_SimTimeEncoding SimTimeEncoding
93#endif
Sebastian Jansson7237c152019-04-08 16:47:49 +020094TEST(ScenarioTest, MAYBE_SimTimeEncoding) {
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020095 VideoQualityAnalyzerConfig analyzer_config;
96 analyzer_config.psnr_coverage = 0.1;
97 VideoQualityAnalyzer analyzer(analyzer_config);
98 {
99 Scenario s("scenario/encode_sim", false);
100 SetupVideoCall(s, &analyzer);
101 s.RunFor(TimeDelta::seconds(60));
102 }
103 // Regression tests based on previous runs.
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +0200104 EXPECT_EQ(analyzer.stats().lost_count, 0);
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +0200105 EXPECT_NEAR(analyzer.stats().psnr.Mean(), 38, 2);
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +0200106}
107
Sebastian Jansson86941182019-04-09 15:15:24 +0200108// TODO(bugs.webrtc.org/10515): Remove this when performance has been improved.
Sebastian Jansson7237c152019-04-08 16:47:49 +0200109#if defined(WEBRTC_IOS) && defined(WEBRTC_ARCH_ARM64) && !defined(NDEBUG)
110#define MAYBE_RealTimeEncoding DISABLED_RealTimeEncoding
111#else
112#define MAYBE_RealTimeEncoding RealTimeEncoding
113#endif
114TEST(ScenarioTest, MAYBE_RealTimeEncoding) {
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +0200115 VideoQualityAnalyzerConfig analyzer_config;
116 analyzer_config.psnr_coverage = 0.1;
117 VideoQualityAnalyzer analyzer(analyzer_config);
118 {
119 Scenario s("scenario/encode_real", true);
120 SetupVideoCall(s, &analyzer);
121 s.RunFor(TimeDelta::seconds(10));
122 }
123 // Regression tests based on previous runs.
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +0200124 EXPECT_LT(analyzer.stats().lost_count, 2);
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +0200125 EXPECT_NEAR(analyzer.stats().psnr.Mean(), 38, 10);
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +0200126}
127
128TEST(ScenarioTest, SimTimeFakeing) {
129 Scenario s("scenario/encode_sim", false);
130 SetupVideoCall(s, nullptr);
131 s.RunFor(TimeDelta::seconds(10));
132}
133
Sebastian Jansson98b07e92018-09-27 13:47:01 +0200134} // namespace test
135} // namespace webrtc