blob: d39ce5864ac9f7a1b5cd02be649e2c36603b1769 [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,
Sebastian Janssonef86d142019-04-15 14:42:42 +020018 NetworkSimulationConfig network_config,
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020019 VideoQualityAnalyzer* analyzer,
20 CallStatsCollectors* collectors) {
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010021 VideoStreamConfig config;
22 config.encoder.codec = VideoStreamConfig::Encoder::Codec::kVideoCodecVP8;
23 config.encoder.implementation =
24 VideoStreamConfig::Encoder::Implementation::kSoftware;
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020025 config.hooks.frame_pair_handlers = {analyzer->Handler()};
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020026 auto* caller = s->CreateClient("caller", CallClientConfig());
27 auto route =
28 s->CreateRoutes(caller, {s->CreateSimulationNode(network_config)},
29 s->CreateClient("callee", CallClientConfig()),
Sebastian Janssonef86d142019-04-15 14:42:42 +020030 {s->CreateSimulationNode(NetworkSimulationConfig())});
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020031 auto* video = s->CreateVideoStream(route->forward(), config);
32 auto* audio = s->CreateAudioStream(route->forward(), AudioStreamConfig());
Sebastian Janssondab21c62019-05-13 11:48:40 +020033 s->Every(TimeDelta::seconds(1), [=] {
34 collectors->call.AddStats(caller->GetStats());
35 collectors->audio_receive.AddStats(audio->receive()->GetStats());
36 collectors->video_send.AddStats(video->send()->GetStats(), s->Now());
37 collectors->video_receive.AddStats(video->receive()->GetStats());
38 });
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010039}
40} // namespace
41
42TEST(ScenarioAnalyzerTest, PsnrIsHighWhenNetworkIsGood) {
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020043 VideoQualityAnalyzer analyzer;
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020044 CallStatsCollectors stats;
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010045 {
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020046 Scenario s;
Sebastian Janssonef86d142019-04-15 14:42:42 +020047 NetworkSimulationConfig good_network;
48 good_network.bandwidth = DataRate::kbps(1000);
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020049 CreateAnalyzedStream(&s, good_network, &analyzer, &stats);
50 s.RunFor(TimeDelta::seconds(3));
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010051 }
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020052 // This is a change detecting test, the targets are based on previous runs and
53 // might change due to changes in configuration and encoder etc. The main
54 // purpose is to show how the stats can be used. To avoid being overly
55 // sensistive to change, the ranges are chosen to be quite large.
Sebastian Janssone9cac4f2019-06-24 17:10:55 +020056 EXPECT_NEAR(analyzer.stats().psnr_with_freeze.Mean(), 43, 10);
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020057 EXPECT_NEAR(stats.call.stats().target_rate.Mean().kbps(), 700, 300);
58 EXPECT_NEAR(stats.video_send.stats().media_bitrate.Mean().kbps(), 500, 200);
59 EXPECT_NEAR(stats.video_receive.stats().resolution.Mean(), 180, 10);
60 EXPECT_NEAR(stats.audio_receive.stats().jitter_buffer.Mean().ms(), 40, 20);
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010061}
62
63TEST(ScenarioAnalyzerTest, PsnrIsLowWhenNetworkIsBad) {
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020064 VideoQualityAnalyzer analyzer;
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020065 CallStatsCollectors stats;
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010066 {
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020067 Scenario s;
Sebastian Janssonef86d142019-04-15 14:42:42 +020068 NetworkSimulationConfig bad_network;
69 bad_network.bandwidth = DataRate::kbps(100);
70 bad_network.loss_rate = 0.02;
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020071 CreateAnalyzedStream(&s, bad_network, &analyzer, &stats);
72 s.RunFor(TimeDelta::seconds(3));
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010073 }
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020074 // This is a change detecting test, the targets are based on previous runs and
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020075 // might change due to changes in configuration and encoder etc.
Sebastian Janssone9cac4f2019-06-24 17:10:55 +020076 EXPECT_NEAR(analyzer.stats().psnr_with_freeze.Mean(), 16, 10);
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020077 EXPECT_NEAR(stats.call.stats().target_rate.Mean().kbps(), 75, 50);
78 EXPECT_NEAR(stats.video_send.stats().media_bitrate.Mean().kbps(), 100, 50);
79 EXPECT_NEAR(stats.video_receive.stats().resolution.Mean(), 180, 10);
80 EXPECT_NEAR(stats.audio_receive.stats().jitter_buffer.Mean().ms(), 45, 20);
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010081}
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020082
Sebastian Janssondab21c62019-05-13 11:48:40 +020083TEST(ScenarioAnalyzerTest, CountsCapturedButNotRendered) {
84 VideoQualityAnalyzer analyzer;
85 CallStatsCollectors stats;
86 {
87 Scenario s;
88 NetworkSimulationConfig long_delays;
89 long_delays.delay = TimeDelta::seconds(5);
90 CreateAnalyzedStream(&s, long_delays, &analyzer, &stats);
91 // Enough time to send frames but not enough to deliver.
92 s.RunFor(TimeDelta::ms(100));
93 }
94 EXPECT_GE(analyzer.stats().capture.count, 1);
95 EXPECT_EQ(analyzer.stats().render.count, 0);
96}
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010097} // namespace test
98} // namespace webrtc