Adds optional video quality metrics to scenario tests.
Bug: webrtc:9510
Change-Id: I448e7156cc8f56930f58c4d25bd167df83a2ba85
Reviewed-on: https://webrtc-review.googlesource.com/c/114885
Commit-Queue: Sebastian Jansson <srte@webrtc.org>
Reviewed-by: Erik Språng <sprang@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#26065}
diff --git a/test/scenario/quality_stats_unittest.cc b/test/scenario/quality_stats_unittest.cc
new file mode 100644
index 0000000..e3806cf
--- /dev/null
+++ b/test/scenario/quality_stats_unittest.cc
@@ -0,0 +1,62 @@
+/*
+ * Copyright 2018 The WebRTC project authors. All Rights Reserved.
+ *
+ * Use of this source code is governed by a BSD-style license
+ * that can be found in the LICENSE file in the root of the source
+ * tree. An additional intellectual property rights grant can be found
+ * in the file PATENTS. All contributing project authors may
+ * be found in the AUTHORS file in the root of the source tree.
+ */
+#include "test/gtest.h"
+#include "test/scenario/scenario.h"
+
+namespace webrtc {
+namespace test {
+namespace {
+VideoStreamConfig AnalyzerVideoConfig(VideoQualityStats* stats) {
+ VideoStreamConfig config;
+ config.encoder.codec = VideoStreamConfig::Encoder::Codec::kVideoCodecVP8;
+ config.encoder.implementation =
+ VideoStreamConfig::Encoder::Implementation::kSoftware;
+ config.analyzer.frame_quality_handler = [stats](VideoFrameQualityInfo info) {
+ stats->HandleFrameInfo(info);
+ };
+ return config;
+}
+} // namespace
+
+TEST(ScenarioAnalyzerTest, PsnrIsHighWhenNetworkIsGood) {
+ VideoQualityStats stats;
+ {
+ Scenario s;
+ NetworkNodeConfig good_network;
+ good_network.simulation.bandwidth = DataRate::kbps(1000);
+ auto route = s.CreateRoutes(s.CreateClient("caller", CallClientConfig()),
+ {s.CreateSimulationNode(good_network)},
+ s.CreateClient("callee", CallClientConfig()),
+ {s.CreateSimulationNode(NetworkNodeConfig())});
+ s.CreateVideoStream(route->forward(), AnalyzerVideoConfig(&stats));
+ s.RunFor(TimeDelta::seconds(1));
+ }
+ EXPECT_GT(stats.psnr.Mean(), 46);
+}
+
+TEST(ScenarioAnalyzerTest, PsnrIsLowWhenNetworkIsBad) {
+ VideoQualityStats stats;
+ {
+ Scenario s;
+ NetworkNodeConfig bad_network;
+ bad_network.simulation.bandwidth = DataRate::kbps(100);
+ bad_network.simulation.loss_rate = 0.02;
+ auto route = s.CreateRoutes(s.CreateClient("caller", CallClientConfig()),
+ {s.CreateSimulationNode(bad_network)},
+ s.CreateClient("callee", CallClientConfig()),
+ {s.CreateSimulationNode(NetworkNodeConfig())});
+
+ s.CreateVideoStream(route->forward(), AnalyzerVideoConfig(&stats));
+ s.RunFor(TimeDelta::seconds(2));
+ }
+ EXPECT_LT(stats.psnr.Mean(), 40);
+}
+} // namespace test
+} // namespace webrtc