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 { |
| 16 | VideoStreamConfig 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 | |
| 28 | TEST(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 | |
| 44 | TEST(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 |