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