Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 1 | /* |
| 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 Jansson | 7150d8c | 2019-04-09 14:18:09 +0200 | [diff] [blame^] | 10 | #include "test/scenario/stats_collection.h" |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 11 | #include "test/gtest.h" |
| 12 | #include "test/scenario/scenario.h" |
| 13 | |
| 14 | namespace webrtc { |
| 15 | namespace test { |
| 16 | namespace { |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 17 | void CreateAnalyzedStream(Scenario* s, |
| 18 | NetworkNodeConfig network_config, |
| 19 | VideoQualityAnalyzer* analyzer) { |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 20 | VideoStreamConfig config; |
| 21 | config.encoder.codec = VideoStreamConfig::Encoder::Codec::kVideoCodecVP8; |
| 22 | config.encoder.implementation = |
| 23 | VideoStreamConfig::Encoder::Implementation::kSoftware; |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 24 | 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 Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 30 | } |
| 31 | } // namespace |
| 32 | |
| 33 | TEST(ScenarioAnalyzerTest, PsnrIsHighWhenNetworkIsGood) { |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 34 | VideoQualityAnalyzer analyzer; |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 35 | { |
Sebastian Jansson | 363fb7e | 2019-04-05 12:49:35 +0200 | [diff] [blame] | 36 | Scenario s("", /*real_time*/ false); |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 37 | NetworkNodeConfig good_network; |
| 38 | good_network.simulation.bandwidth = DataRate::kbps(1000); |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 39 | CreateAnalyzedStream(&s, good_network, &analyzer); |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 40 | s.RunFor(TimeDelta::seconds(1)); |
| 41 | } |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 42 | // 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 Jansson | 7237c15 | 2019-04-08 16:47:49 +0200 | [diff] [blame] | 44 | EXPECT_GT(analyzer.stats().psnr.Mean(), 40); |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | TEST(ScenarioAnalyzerTest, PsnrIsLowWhenNetworkIsBad) { |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 48 | VideoQualityAnalyzer analyzer; |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 49 | { |
Sebastian Jansson | 363fb7e | 2019-04-05 12:49:35 +0200 | [diff] [blame] | 50 | Scenario s("", /*real_time*/ false); |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 51 | NetworkNodeConfig bad_network; |
| 52 | bad_network.simulation.bandwidth = DataRate::kbps(100); |
| 53 | bad_network.simulation.loss_rate = 0.02; |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 54 | CreateAnalyzedStream(&s, bad_network, &analyzer); |
| 55 | s.RunFor(TimeDelta::seconds(1)); |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 56 | } |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 57 | // 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 Jansson | 7237c15 | 2019-04-08 16:47:49 +0200 | [diff] [blame] | 59 | EXPECT_LT(analyzer.stats().psnr.Mean(), 30); |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 60 | } |
| 61 | } // namespace test |
| 62 | } // namespace webrtc |