blob: ee01ad53c201ffded5d686974be2a0c5e964cf2a [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 */
Sebastian Jansson7150d8c2019-04-09 14:18:09 +020010#include "test/scenario/stats_collection.h"
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010011#include "test/gtest.h"
12#include "test/scenario/scenario.h"
13
14namespace webrtc {
15namespace test {
16namespace {
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020017void CreateAnalyzedStream(Scenario* s,
18 NetworkNodeConfig network_config,
19 VideoQualityAnalyzer* analyzer) {
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010020 VideoStreamConfig config;
21 config.encoder.codec = VideoStreamConfig::Encoder::Codec::kVideoCodecVP8;
22 config.encoder.implementation =
23 VideoStreamConfig::Encoder::Implementation::kSoftware;
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020024 config.hooks.frame_pair_handlers = {analyzer->Handler()};
25 auto route = s->CreateRoutes(s->CreateClient("caller", CallClientConfig()),
26 {s->CreateSimulationNode(network_config)},
27 s->CreateClient("callee", CallClientConfig()),
28 {s->CreateSimulationNode(NetworkNodeConfig())});
29 s->CreateVideoStream(route->forward(), config);
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010030}
31} // namespace
32
33TEST(ScenarioAnalyzerTest, PsnrIsHighWhenNetworkIsGood) {
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020034 VideoQualityAnalyzer analyzer;
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010035 {
Sebastian Jansson363fb7e2019-04-05 12:49:35 +020036 Scenario s("", /*real_time*/ false);
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010037 NetworkNodeConfig good_network;
38 good_network.simulation.bandwidth = DataRate::kbps(1000);
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020039 CreateAnalyzedStream(&s, good_network, &analyzer);
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010040 s.RunFor(TimeDelta::seconds(1));
41 }
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020042 // This is mainty a regression test, the target is based on previous runs and
43 // might change due to changes in configuration and encoder etc.
Sebastian Jansson7237c152019-04-08 16:47:49 +020044 EXPECT_GT(analyzer.stats().psnr.Mean(), 40);
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010045}
46
47TEST(ScenarioAnalyzerTest, PsnrIsLowWhenNetworkIsBad) {
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020048 VideoQualityAnalyzer analyzer;
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010049 {
Sebastian Jansson363fb7e2019-04-05 12:49:35 +020050 Scenario s("", /*real_time*/ false);
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010051 NetworkNodeConfig bad_network;
52 bad_network.simulation.bandwidth = DataRate::kbps(100);
53 bad_network.simulation.loss_rate = 0.02;
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020054 CreateAnalyzedStream(&s, bad_network, &analyzer);
55 s.RunFor(TimeDelta::seconds(1));
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010056 }
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020057 // This is mainty a regression test, the target is based on previous runs and
58 // might change due to changes in configuration and encoder etc.
Sebastian Jansson7237c152019-04-08 16:47:49 +020059 EXPECT_LT(analyzer.stats().psnr.Mean(), 30);
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010060}
61} // namespace test
62} // namespace webrtc