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, |
Sebastian Jansson | 9a2ca0a | 2019-04-15 13:18:19 +0200 | [diff] [blame^] | 19 | VideoQualityAnalyzer* analyzer, |
| 20 | CallStatsCollectors* collectors) { |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 21 | VideoStreamConfig config; |
| 22 | config.encoder.codec = VideoStreamConfig::Encoder::Codec::kVideoCodecVP8; |
| 23 | config.encoder.implementation = |
| 24 | VideoStreamConfig::Encoder::Implementation::kSoftware; |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 25 | config.hooks.frame_pair_handlers = {analyzer->Handler()}; |
Sebastian Jansson | 9a2ca0a | 2019-04-15 13:18:19 +0200 | [diff] [blame^] | 26 | auto* caller = s->CreateClient("caller", CallClientConfig()); |
| 27 | auto route = |
| 28 | s->CreateRoutes(caller, {s->CreateSimulationNode(network_config)}, |
| 29 | s->CreateClient("callee", CallClientConfig()), |
| 30 | {s->CreateSimulationNode(NetworkNodeConfig())}); |
| 31 | auto* video = s->CreateVideoStream(route->forward(), config); |
| 32 | auto* audio = s->CreateAudioStream(route->forward(), AudioStreamConfig()); |
| 33 | if (collectors) { |
| 34 | s->Every(TimeDelta::seconds(1), [=] { |
| 35 | collectors->call.AddStats(caller->GetStats()); |
| 36 | collectors->audio_receive.AddStats(audio->receive()->GetStats()); |
| 37 | collectors->video_send.AddStats(video->send()->GetStats(), s->Now()); |
| 38 | collectors->video_receive.AddStats(video->receive()->GetStats()); |
| 39 | }); |
| 40 | } |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 41 | } |
| 42 | } // namespace |
| 43 | |
| 44 | TEST(ScenarioAnalyzerTest, PsnrIsHighWhenNetworkIsGood) { |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 45 | VideoQualityAnalyzer analyzer; |
Sebastian Jansson | 9a2ca0a | 2019-04-15 13:18:19 +0200 | [diff] [blame^] | 46 | CallStatsCollectors stats; |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 47 | { |
Sebastian Jansson | 9a2ca0a | 2019-04-15 13:18:19 +0200 | [diff] [blame^] | 48 | Scenario s; |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 49 | NetworkNodeConfig good_network; |
| 50 | good_network.simulation.bandwidth = DataRate::kbps(1000); |
Sebastian Jansson | 9a2ca0a | 2019-04-15 13:18:19 +0200 | [diff] [blame^] | 51 | CreateAnalyzedStream(&s, good_network, &analyzer, &stats); |
| 52 | s.RunFor(TimeDelta::seconds(3)); |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 53 | } |
Sebastian Jansson | 9a2ca0a | 2019-04-15 13:18:19 +0200 | [diff] [blame^] | 54 | // This is a change detecting test, the targets are based on previous runs and |
| 55 | // might change due to changes in configuration and encoder etc. The main |
| 56 | // purpose is to show how the stats can be used. To avoid being overly |
| 57 | // sensistive to change, the ranges are chosen to be quite large. |
| 58 | EXPECT_NEAR(analyzer.stats().psnr.Mean(), 43, 10); |
| 59 | EXPECT_NEAR(stats.call.stats().target_rate.Mean().kbps(), 700, 300); |
| 60 | EXPECT_NEAR(stats.video_send.stats().media_bitrate.Mean().kbps(), 500, 200); |
| 61 | EXPECT_NEAR(stats.video_receive.stats().resolution.Mean(), 180, 10); |
| 62 | EXPECT_NEAR(stats.audio_receive.stats().jitter_buffer.Mean().ms(), 40, 20); |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | TEST(ScenarioAnalyzerTest, PsnrIsLowWhenNetworkIsBad) { |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 66 | VideoQualityAnalyzer analyzer; |
Sebastian Jansson | 9a2ca0a | 2019-04-15 13:18:19 +0200 | [diff] [blame^] | 67 | CallStatsCollectors stats; |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 68 | { |
Sebastian Jansson | 9a2ca0a | 2019-04-15 13:18:19 +0200 | [diff] [blame^] | 69 | Scenario s; |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 70 | NetworkNodeConfig bad_network; |
| 71 | bad_network.simulation.bandwidth = DataRate::kbps(100); |
| 72 | bad_network.simulation.loss_rate = 0.02; |
Sebastian Jansson | 9a2ca0a | 2019-04-15 13:18:19 +0200 | [diff] [blame^] | 73 | CreateAnalyzedStream(&s, bad_network, &analyzer, &stats); |
| 74 | s.RunFor(TimeDelta::seconds(3)); |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 75 | } |
Sebastian Jansson | 9a2ca0a | 2019-04-15 13:18:19 +0200 | [diff] [blame^] | 76 | // This is a change detecting test, the targets are based on previous runs and |
Sebastian Jansson | cf2df2f | 2019-04-02 11:51:28 +0200 | [diff] [blame] | 77 | // might change due to changes in configuration and encoder etc. |
Sebastian Jansson | 9a2ca0a | 2019-04-15 13:18:19 +0200 | [diff] [blame^] | 78 | EXPECT_NEAR(analyzer.stats().psnr.Mean(), 16, 10); |
| 79 | EXPECT_NEAR(stats.call.stats().target_rate.Mean().kbps(), 75, 50); |
| 80 | EXPECT_NEAR(stats.video_send.stats().media_bitrate.Mean().kbps(), 100, 50); |
| 81 | EXPECT_NEAR(stats.video_receive.stats().resolution.Mean(), 180, 10); |
| 82 | EXPECT_NEAR(stats.audio_receive.stats().jitter_buffer.Mean().ms(), 45, 20); |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 83 | } |
Sebastian Jansson | 9a2ca0a | 2019-04-15 13:18:19 +0200 | [diff] [blame^] | 84 | |
Sebastian Jansson | 9a4f38e | 2018-12-19 13:14:41 +0100 | [diff] [blame] | 85 | } // namespace test |
| 86 | } // namespace webrtc |