blob: 0cfe3d98d1d1a0dd2397f5f29d1ed17967c49be1 [file] [log] [blame]
Artem Titova6a273d2019-02-07 16:43:51 +01001/*
2 * Copyright (c) 2019 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 */
10
11#include <cstdint>
12#include <memory>
13
14#include "absl/memory/memory.h"
15#include "call/simulated_network.h"
16#include "rtc_base/async_invoker.h"
17#include "rtc_base/fake_network.h"
18#include "test/gtest.h"
Artem Titov6b88a8f2019-02-13 22:15:04 +010019#include "test/pc/e2e/analyzer/video/default_video_quality_analyzer.h"
Artem Titova6a273d2019-02-07 16:43:51 +010020#include "test/pc/e2e/api/create_peerconnection_quality_test_fixture.h"
21#include "test/pc/e2e/api/peerconnection_quality_test_fixture.h"
22#include "test/scenario/network/network_emulation.h"
23#include "test/scenario/network/network_emulation_manager.h"
24#include "test/testsupport/file_utils.h"
25
26namespace webrtc {
27namespace test {
28namespace {
29
30std::unique_ptr<rtc::NetworkManager> CreateFakeNetworkManager(
31 std::vector<EndpointNode*> endpoints) {
32 auto network_manager = absl::make_unique<rtc::FakeNetworkManager>();
33 for (auto* endpoint : endpoints) {
34 network_manager->AddInterface(
35 rtc::SocketAddress(endpoint->GetPeerLocalAddress(), /*port=*/0));
36 }
37 return network_manager;
38}
39
40} // namespace
41
42TEST(PeerConnectionE2EQualityTestSmokeTest, RunWithEmulatedNetwork) {
43 using Params = PeerConnectionE2EQualityTestFixture::Params;
44 using RunParams = PeerConnectionE2EQualityTestFixture::RunParams;
45 using VideoGeneratorType =
46 PeerConnectionE2EQualityTestFixture::VideoGeneratorType;
47 using Analyzers = PeerConnectionE2EQualityTestFixture::Analyzers;
48 using VideoConfig = PeerConnectionE2EQualityTestFixture::VideoConfig;
49 using AudioConfig = PeerConnectionE2EQualityTestFixture::AudioConfig;
50 using InjectableComponents =
51 PeerConnectionE2EQualityTestFixture::InjectableComponents;
52
53 auto alice_params = absl::make_unique<Params>();
54 VideoConfig alice_video_config;
55 alice_video_config.width = 1280;
56 alice_video_config.height = 720;
57 alice_video_config.fps = 30;
58 alice_video_config.stream_label = "alice-video";
59 alice_video_config.generator = VideoGeneratorType::kDefault;
60
61 alice_params->video_configs.push_back(alice_video_config);
62 alice_params->audio_config = AudioConfig{
63 AudioConfig::Mode::kGenerated,
64 /*input_file_name=*/absl::nullopt,
65 /*input_dump_file_name=*/absl::nullopt,
66 /*output_dump_file_name=*/absl::nullopt, cricket::AudioOptions()};
67
68 // Setup emulated network
Sebastian Janssonb00eb192019-02-11 09:13:01 +010069 NetworkEmulationManager network_emulation_manager;
Artem Titova6a273d2019-02-07 16:43:51 +010070
71 EmulatedNetworkNode* alice_node =
72 network_emulation_manager.CreateEmulatedNode(
73 absl::make_unique<SimulatedNetwork>(BuiltInNetworkBehaviorConfig()));
74 EmulatedNetworkNode* bob_node = network_emulation_manager.CreateEmulatedNode(
75 absl::make_unique<SimulatedNetwork>(BuiltInNetworkBehaviorConfig()));
76 EndpointNode* alice_endpoint =
77 network_emulation_manager.CreateEndpoint(rtc::IPAddress(1));
78 EndpointNode* bob_endpoint =
79 network_emulation_manager.CreateEndpoint(rtc::IPAddress(2));
80 network_emulation_manager.CreateRoute(alice_endpoint, {alice_node},
81 bob_endpoint);
82 network_emulation_manager.CreateRoute(bob_endpoint, {bob_node},
83 alice_endpoint);
84
85 rtc::Thread* alice_network_thread =
86 network_emulation_manager.CreateNetworkThread({alice_endpoint});
87 rtc::Thread* bob_network_thread =
88 network_emulation_manager.CreateNetworkThread({bob_endpoint});
89
90 // Setup components. We need to provide rtc::NetworkManager compatible with
91 // emulated network layer.
92 auto alice_components =
93 absl::make_unique<InjectableComponents>(alice_network_thread);
94 alice_components->pc_dependencies->network_manager =
95 CreateFakeNetworkManager({alice_endpoint});
96 auto bob_components =
97 absl::make_unique<InjectableComponents>(bob_network_thread);
98 bob_components->pc_dependencies->network_manager =
99 CreateFakeNetworkManager({bob_endpoint});
100
101 // Create analyzers.
102 auto analyzers = absl::make_unique<Analyzers>();
103 analyzers->video_quality_analyzer =
Artem Titov6b88a8f2019-02-13 22:15:04 +0100104 absl::make_unique<DefaultVideoQualityAnalyzer>("smoke_test");
105 auto* video_analyzer = static_cast<DefaultVideoQualityAnalyzer*>(
Artem Titova6a273d2019-02-07 16:43:51 +0100106 analyzers->video_quality_analyzer.get());
107
Mirko Bonadei2bd54a12019-02-13 09:07:55 +0100108 auto fixture =
109 CreatePeerConnectionE2EQualityTestFixture(std::move(analyzers));
110 fixture->Run(std::move(alice_components), std::move(alice_params),
111 std::move(bob_components), absl::make_unique<Params>(),
112 RunParams{TimeDelta::seconds(5)});
Artem Titova6a273d2019-02-07 16:43:51 +0100113
Artem Titov6b88a8f2019-02-13 22:15:04 +0100114 // 150 = 30fps * 5s. On some devices pipeline can be too slow, so it can
115 // happen, that frames will stuck in the middle, so we actually can't force
116 // real constraints here, so lets just check, that at least 1 frame passed
117 // whole pipeline.
118 EXPECT_GE(video_analyzer->GetGlobalCounters().captured, 150);
119 EXPECT_GE(video_analyzer->GetGlobalCounters().pre_encoded, 1);
120 EXPECT_GE(video_analyzer->GetGlobalCounters().encoded, 1);
121 EXPECT_GE(video_analyzer->GetGlobalCounters().received, 1);
122 EXPECT_GE(video_analyzer->GetGlobalCounters().decoded, 1);
123 EXPECT_GE(video_analyzer->GetGlobalCounters().rendered, 1);
Artem Titova6a273d2019-02-07 16:43:51 +0100124}
125
126} // namespace test
127} // namespace webrtc