blob: fae3365d5dbff3b1813ddb99c1b2eb1d9c7e85d2 [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"
Jonas Olssona4d87372019-07-05 19:08:33 +020011
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010012#include "test/gtest.h"
13#include "test/scenario/scenario.h"
14
15namespace webrtc {
16namespace test {
17namespace {
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020018void CreateAnalyzedStream(Scenario* s,
Sebastian Janssonef86d142019-04-15 14:42:42 +020019 NetworkSimulationConfig network_config,
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020020 VideoQualityAnalyzer* analyzer,
21 CallStatsCollectors* collectors) {
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010022 VideoStreamConfig config;
23 config.encoder.codec = VideoStreamConfig::Encoder::Codec::kVideoCodecVP8;
24 config.encoder.implementation =
25 VideoStreamConfig::Encoder::Implementation::kSoftware;
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020026 config.hooks.frame_pair_handlers = {analyzer->Handler()};
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020027 auto* caller = s->CreateClient("caller", CallClientConfig());
28 auto route =
Artem Titov16cc9ef2020-04-07 18:02:39 +000029 s->CreateRoutes(caller, {s->CreateSimulationNode(network_config)},
30 s->CreateClient("callee", CallClientConfig()),
Sebastian Janssonef86d142019-04-15 14:42:42 +020031 {s->CreateSimulationNode(NetworkSimulationConfig())});
Artem Titov16cc9ef2020-04-07 18:02:39 +000032 auto* video = s->CreateVideoStream(route->forward(), config);
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020033 auto* audio = s->CreateAudioStream(route->forward(), AudioStreamConfig());
Danil Chapovalov0c626af2020-02-10 11:16:00 +010034 s->Every(TimeDelta::Seconds(1), [=] {
Sebastian Janssondab21c62019-05-13 11:48:40 +020035 collectors->call.AddStats(caller->GetStats());
Tommi24eed272020-04-06 15:57:08 +020036 collectors->audio_receive.AddStats(audio->receive()->GetStats());
Artem Titov16cc9ef2020-04-07 18:02:39 +000037 collectors->video_send.AddStats(video->send()->GetStats(), s->Now());
38 collectors->video_receive.AddStats(video->receive()->GetStats());
Sebastian Janssondab21c62019-05-13 11:48:40 +020039 });
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010040}
41} // namespace
42
43TEST(ScenarioAnalyzerTest, PsnrIsHighWhenNetworkIsGood) {
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020044 VideoQualityAnalyzer analyzer;
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020045 CallStatsCollectors stats;
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010046 {
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020047 Scenario s;
Sebastian Janssonef86d142019-04-15 14:42:42 +020048 NetworkSimulationConfig good_network;
Danil Chapovalovcad3e0e2020-02-17 18:46:07 +010049 good_network.bandwidth = DataRate::KilobitsPerSec(1000);
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020050 CreateAnalyzedStream(&s, good_network, &analyzer, &stats);
Danil Chapovalov0c626af2020-02-10 11:16:00 +010051 s.RunFor(TimeDelta::Seconds(3));
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010052 }
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020053 // This is a change detecting test, the targets are based on previous runs and
54 // might change due to changes in configuration and encoder etc. The main
55 // purpose is to show how the stats can be used. To avoid being overly
56 // sensistive to change, the ranges are chosen to be quite large.
Sebastian Janssone9cac4f2019-06-24 17:10:55 +020057 EXPECT_NEAR(analyzer.stats().psnr_with_freeze.Mean(), 43, 10);
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020058 EXPECT_NEAR(stats.call.stats().target_rate.Mean().kbps(), 700, 300);
59 EXPECT_NEAR(stats.video_send.stats().media_bitrate.Mean().kbps(), 500, 200);
60 EXPECT_NEAR(stats.video_receive.stats().resolution.Mean(), 180, 10);
61 EXPECT_NEAR(stats.audio_receive.stats().jitter_buffer.Mean().ms(), 40, 20);
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010062}
63
64TEST(ScenarioAnalyzerTest, PsnrIsLowWhenNetworkIsBad) {
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020065 VideoQualityAnalyzer analyzer;
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020066 CallStatsCollectors stats;
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010067 {
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020068 Scenario s;
Sebastian Janssonef86d142019-04-15 14:42:42 +020069 NetworkSimulationConfig bad_network;
Danil Chapovalovcad3e0e2020-02-17 18:46:07 +010070 bad_network.bandwidth = DataRate::KilobitsPerSec(100);
Sebastian Janssonef86d142019-04-15 14:42:42 +020071 bad_network.loss_rate = 0.02;
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020072 CreateAnalyzedStream(&s, bad_network, &analyzer, &stats);
Danil Chapovalov0c626af2020-02-10 11:16:00 +010073 s.RunFor(TimeDelta::Seconds(3));
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010074 }
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020075 // This is a change detecting test, the targets are based on previous runs and
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020076 // might change due to changes in configuration and encoder etc.
Sebastian Janssone9cac4f2019-06-24 17:10:55 +020077 EXPECT_NEAR(analyzer.stats().psnr_with_freeze.Mean(), 16, 10);
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020078 EXPECT_NEAR(stats.call.stats().target_rate.Mean().kbps(), 75, 50);
79 EXPECT_NEAR(stats.video_send.stats().media_bitrate.Mean().kbps(), 100, 50);
80 EXPECT_NEAR(stats.video_receive.stats().resolution.Mean(), 180, 10);
Sebastian Janssonc9f42ad2020-01-17 11:47:35 +010081 EXPECT_NEAR(stats.audio_receive.stats().jitter_buffer.Mean().ms(), 200, 150);
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010082}
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020083
Sebastian Janssondab21c62019-05-13 11:48:40 +020084TEST(ScenarioAnalyzerTest, CountsCapturedButNotRendered) {
85 VideoQualityAnalyzer analyzer;
86 CallStatsCollectors stats;
87 {
88 Scenario s;
89 NetworkSimulationConfig long_delays;
Danil Chapovalov0c626af2020-02-10 11:16:00 +010090 long_delays.delay = TimeDelta::Seconds(5);
Sebastian Janssondab21c62019-05-13 11:48:40 +020091 CreateAnalyzedStream(&s, long_delays, &analyzer, &stats);
92 // Enough time to send frames but not enough to deliver.
Danil Chapovalov0c626af2020-02-10 11:16:00 +010093 s.RunFor(TimeDelta::Millis(100));
Sebastian Janssondab21c62019-05-13 11:48:40 +020094 }
95 EXPECT_GE(analyzer.stats().capture.count, 1);
96 EXPECT_EQ(analyzer.stats().render.count, 0);
97}
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010098} // namespace test
99} // namespace webrtc