blob: e3806cfedf4e8f85b3a38e86adc2c11eef2cc86e [file] [log] [blame]
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +01001/*
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 */
10#include "test/gtest.h"
11#include "test/scenario/scenario.h"
12
13namespace webrtc {
14namespace test {
15namespace {
16VideoStreamConfig AnalyzerVideoConfig(VideoQualityStats* stats) {
17 VideoStreamConfig config;
18 config.encoder.codec = VideoStreamConfig::Encoder::Codec::kVideoCodecVP8;
19 config.encoder.implementation =
20 VideoStreamConfig::Encoder::Implementation::kSoftware;
21 config.analyzer.frame_quality_handler = [stats](VideoFrameQualityInfo info) {
22 stats->HandleFrameInfo(info);
23 };
24 return config;
25}
26} // namespace
27
28TEST(ScenarioAnalyzerTest, PsnrIsHighWhenNetworkIsGood) {
29 VideoQualityStats stats;
30 {
31 Scenario s;
32 NetworkNodeConfig good_network;
33 good_network.simulation.bandwidth = DataRate::kbps(1000);
34 auto route = s.CreateRoutes(s.CreateClient("caller", CallClientConfig()),
35 {s.CreateSimulationNode(good_network)},
36 s.CreateClient("callee", CallClientConfig()),
37 {s.CreateSimulationNode(NetworkNodeConfig())});
38 s.CreateVideoStream(route->forward(), AnalyzerVideoConfig(&stats));
39 s.RunFor(TimeDelta::seconds(1));
40 }
41 EXPECT_GT(stats.psnr.Mean(), 46);
42}
43
44TEST(ScenarioAnalyzerTest, PsnrIsLowWhenNetworkIsBad) {
45 VideoQualityStats stats;
46 {
47 Scenario s;
48 NetworkNodeConfig bad_network;
49 bad_network.simulation.bandwidth = DataRate::kbps(100);
50 bad_network.simulation.loss_rate = 0.02;
51 auto route = s.CreateRoutes(s.CreateClient("caller", CallClientConfig()),
52 {s.CreateSimulationNode(bad_network)},
53 s.CreateClient("callee", CallClientConfig()),
54 {s.CreateSimulationNode(NetworkNodeConfig())});
55
56 s.CreateVideoStream(route->forward(), AnalyzerVideoConfig(&stats));
57 s.RunFor(TimeDelta::seconds(2));
58 }
59 EXPECT_LT(stats.psnr.Mean(), 40);
60}
61} // namespace test
62} // namespace webrtc