blob: af3b9828384e13efb1516550a332aeea6b058402 [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());
Tommi3c9bcc12020-04-15 16:45:47 +020028 auto* callee = s->CreateClient("callee", CallClientConfig());
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020029 auto route =
Tommi3c9bcc12020-04-15 16:45:47 +020030 s->CreateRoutes(caller, {s->CreateSimulationNode(network_config)}, callee,
Sebastian Janssonef86d142019-04-15 14:42:42 +020031 {s->CreateSimulationNode(NetworkSimulationConfig())});
Tommi3c9bcc12020-04-15 16:45:47 +020032 VideoStreamPair* 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());
Artem Titov16cc9ef2020-04-07 18:02:39 +000036 collectors->video_send.AddStats(video->send()->GetStats(), s->Now());
Tommi3c9bcc12020-04-15 16:45:47 +020037 collectors->audio_receive.AddStats(audio->receive()->GetStats());
38
39 // Querying the video stats from within the expected runtime environment
40 // (i.e. the TQ that belongs to the CallClient, not the Scenario TQ that
41 // we're currently on).
42 VideoReceiveStream::Stats video_receive_stats;
43 auto* video_stream = video->receive();
44 callee->SendTask([&video_stream, &video_receive_stats]() {
45 video_receive_stats = video_stream->GetStats();
46 });
47 collectors->video_receive.AddStats(video_receive_stats);
Sebastian Janssondab21c62019-05-13 11:48:40 +020048 });
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010049}
50} // namespace
51
52TEST(ScenarioAnalyzerTest, PsnrIsHighWhenNetworkIsGood) {
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020053 VideoQualityAnalyzer analyzer;
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020054 CallStatsCollectors stats;
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010055 {
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020056 Scenario s;
Sebastian Janssonef86d142019-04-15 14:42:42 +020057 NetworkSimulationConfig good_network;
Danil Chapovalovcad3e0e2020-02-17 18:46:07 +010058 good_network.bandwidth = DataRate::KilobitsPerSec(1000);
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020059 CreateAnalyzedStream(&s, good_network, &analyzer, &stats);
Danil Chapovalov0c626af2020-02-10 11:16:00 +010060 s.RunFor(TimeDelta::Seconds(3));
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010061 }
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020062 // This is a change detecting test, the targets are based on previous runs and
63 // might change due to changes in configuration and encoder etc. The main
64 // purpose is to show how the stats can be used. To avoid being overly
65 // sensistive to change, the ranges are chosen to be quite large.
Sebastian Janssone9cac4f2019-06-24 17:10:55 +020066 EXPECT_NEAR(analyzer.stats().psnr_with_freeze.Mean(), 43, 10);
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020067 EXPECT_NEAR(stats.call.stats().target_rate.Mean().kbps(), 700, 300);
68 EXPECT_NEAR(stats.video_send.stats().media_bitrate.Mean().kbps(), 500, 200);
69 EXPECT_NEAR(stats.video_receive.stats().resolution.Mean(), 180, 10);
70 EXPECT_NEAR(stats.audio_receive.stats().jitter_buffer.Mean().ms(), 40, 20);
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010071}
72
73TEST(ScenarioAnalyzerTest, PsnrIsLowWhenNetworkIsBad) {
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020074 VideoQualityAnalyzer analyzer;
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020075 CallStatsCollectors stats;
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010076 {
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020077 Scenario s;
Sebastian Janssonef86d142019-04-15 14:42:42 +020078 NetworkSimulationConfig bad_network;
Danil Chapovalovcad3e0e2020-02-17 18:46:07 +010079 bad_network.bandwidth = DataRate::KilobitsPerSec(100);
Sebastian Janssonef86d142019-04-15 14:42:42 +020080 bad_network.loss_rate = 0.02;
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020081 CreateAnalyzedStream(&s, bad_network, &analyzer, &stats);
Danil Chapovalov0c626af2020-02-10 11:16:00 +010082 s.RunFor(TimeDelta::Seconds(3));
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010083 }
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020084 // This is a change detecting test, the targets are based on previous runs and
Sebastian Janssoncf2df2f2019-04-02 11:51:28 +020085 // might change due to changes in configuration and encoder etc.
Sebastian Janssone9cac4f2019-06-24 17:10:55 +020086 EXPECT_NEAR(analyzer.stats().psnr_with_freeze.Mean(), 16, 10);
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020087 EXPECT_NEAR(stats.call.stats().target_rate.Mean().kbps(), 75, 50);
88 EXPECT_NEAR(stats.video_send.stats().media_bitrate.Mean().kbps(), 100, 50);
89 EXPECT_NEAR(stats.video_receive.stats().resolution.Mean(), 180, 10);
Sebastian Janssonc9f42ad2020-01-17 11:47:35 +010090 EXPECT_NEAR(stats.audio_receive.stats().jitter_buffer.Mean().ms(), 200, 150);
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +010091}
Sebastian Jansson9a2ca0a2019-04-15 13:18:19 +020092
Sebastian Janssondab21c62019-05-13 11:48:40 +020093TEST(ScenarioAnalyzerTest, CountsCapturedButNotRendered) {
94 VideoQualityAnalyzer analyzer;
95 CallStatsCollectors stats;
96 {
97 Scenario s;
98 NetworkSimulationConfig long_delays;
Danil Chapovalov0c626af2020-02-10 11:16:00 +010099 long_delays.delay = TimeDelta::Seconds(5);
Sebastian Janssondab21c62019-05-13 11:48:40 +0200100 CreateAnalyzedStream(&s, long_delays, &analyzer, &stats);
101 // Enough time to send frames but not enough to deliver.
Danil Chapovalov0c626af2020-02-10 11:16:00 +0100102 s.RunFor(TimeDelta::Millis(100));
Sebastian Janssondab21c62019-05-13 11:48:40 +0200103 }
104 EXPECT_GE(analyzer.stats().capture.count, 1);
105 EXPECT_EQ(analyzer.stats().render.count, 0);
106}
Sebastian Jansson9a4f38e2018-12-19 13:14:41 +0100107} // namespace test
108} // namespace webrtc