blob: 273723cd89bf58ce6012265db64d229045375b9a [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 {
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020016void CreateAnalyzedStream(Scenario* s,
17 NetworkNodeConfig network_config,
18 VideoQualityAnalyzer* analyzer) {
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010019 VideoStreamConfig config;
20 config.encoder.codec = VideoStreamConfig::Encoder::Codec::kVideoCodecVP8;
21 config.encoder.implementation =
22 VideoStreamConfig::Encoder::Implementation::kSoftware;
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020023 config.hooks.frame_pair_handlers = {analyzer->Handler()};
24 auto route = s->CreateRoutes(s->CreateClient("caller", CallClientConfig()),
25 {s->CreateSimulationNode(network_config)},
26 s->CreateClient("callee", CallClientConfig()),
27 {s->CreateSimulationNode(NetworkNodeConfig())});
28 s->CreateVideoStream(route->forward(), config);
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010029}
30} // namespace
31
32TEST(ScenarioAnalyzerTest, PsnrIsHighWhenNetworkIsGood) {
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020033 VideoQualityAnalyzer analyzer;
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010034 {
35 Scenario s;
36 NetworkNodeConfig good_network;
37 good_network.simulation.bandwidth = DataRate::kbps(1000);
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020038 CreateAnalyzedStream(&s, good_network, &analyzer);
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010039 s.RunFor(TimeDelta::seconds(1));
40 }
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020041 // This is mainty a regression test, the target is based on previous runs and
42 // might change due to changes in configuration and encoder etc.
43 EXPECT_GT(analyzer.stats().psnr.Mean(), 45);
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010044}
45
46TEST(ScenarioAnalyzerTest, PsnrIsLowWhenNetworkIsBad) {
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020047 VideoQualityAnalyzer analyzer;
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010048 {
49 Scenario s;
50 NetworkNodeConfig bad_network;
51 bad_network.simulation.bandwidth = DataRate::kbps(100);
52 bad_network.simulation.loss_rate = 0.02;
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020053 CreateAnalyzedStream(&s, bad_network, &analyzer);
54 s.RunFor(TimeDelta::seconds(1));
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010055 }
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020056 // This is mainty a regression test, the target is based on previous runs and
57 // might change due to changes in configuration and encoder etc.
58 EXPECT_LT(analyzer.stats().psnr.Mean(), 43);
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010059}
60} // namespace test
61} // namespace webrtc