2013-09-10 12:10:01 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2013 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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// This test doesn't actually verify the output since it's just printed
|
|
|
|
|
// to stdout by void functions, but it's still useful as it executes the code.
|
|
|
|
|
|
2016-11-29 02:00:52 -08:00
|
|
|
#include <stdio.h>
|
2018-11-28 16:47:49 +01:00
|
|
|
#include <cstddef>
|
2013-09-10 12:10:01 +00:00
|
|
|
#include <fstream>
|
|
|
|
|
#include <string>
|
|
|
|
|
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "rtc_tools/frame_analyzer/video_quality_analysis.h"
|
|
|
|
|
#include "test/gtest.h"
|
2019-01-11 09:11:00 -08:00
|
|
|
#include "test/testsupport/file_utils.h"
|
2013-09-10 12:10:01 +00:00
|
|
|
|
|
|
|
|
namespace webrtc {
|
|
|
|
|
namespace test {
|
|
|
|
|
|
2018-09-05 16:11:48 +02:00
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
void VerifyLogOutput(const std::string& log_filename,
|
|
|
|
|
const std::vector<std::string>& expected_out) {
|
|
|
|
|
std::ifstream logf(log_filename);
|
|
|
|
|
std::string line;
|
|
|
|
|
|
|
|
|
|
std::size_t i;
|
|
|
|
|
for (i = 0; i < expected_out.size() && getline(logf, line); ++i) {
|
|
|
|
|
ASSERT_EQ(expected_out.at(i), line);
|
|
|
|
|
}
|
|
|
|
|
ASSERT_TRUE(i == expected_out.size()) << "Not enough input data";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
2013-11-03 18:34:51 +00:00
|
|
|
// Setup a log file to write the output to instead of stdout because we don't
|
|
|
|
|
// want those numbers to be picked up as perf numbers.
|
|
|
|
|
class VideoQualityAnalysisTest : public ::testing::Test {
|
|
|
|
|
protected:
|
2017-02-16 01:36:43 -08:00
|
|
|
void SetUp() {
|
|
|
|
|
std::string log_filename = TempFilename(webrtc::test::OutputPath(),
|
|
|
|
|
"VideoQualityAnalysisTest.log");
|
2013-11-03 18:34:51 +00:00
|
|
|
logfile_ = fopen(log_filename.c_str(), "w");
|
|
|
|
|
ASSERT_TRUE(logfile_ != NULL);
|
|
|
|
|
}
|
2017-02-16 01:36:43 -08:00
|
|
|
void TearDown() { ASSERT_EQ(0, fclose(logfile_)); }
|
|
|
|
|
FILE* logfile_;
|
2013-11-03 18:34:51 +00:00
|
|
|
};
|
2013-09-10 12:10:01 +00:00
|
|
|
|
2013-11-03 18:34:51 +00:00
|
|
|
TEST_F(VideoQualityAnalysisTest, PrintAnalysisResultsEmpty) {
|
2013-09-10 12:10:01 +00:00
|
|
|
ResultsContainer result;
|
2013-11-03 18:34:51 +00:00
|
|
|
PrintAnalysisResults(logfile_, "Empty", &result);
|
2013-09-10 12:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
2013-11-03 18:34:51 +00:00
|
|
|
TEST_F(VideoQualityAnalysisTest, PrintAnalysisResultsOneFrame) {
|
2013-09-10 12:10:01 +00:00
|
|
|
ResultsContainer result;
|
|
|
|
|
result.frames.push_back(AnalysisResult(0, 35.0, 0.9));
|
2013-11-03 18:34:51 +00:00
|
|
|
PrintAnalysisResults(logfile_, "OneFrame", &result);
|
2013-09-10 12:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
2013-11-03 18:34:51 +00:00
|
|
|
TEST_F(VideoQualityAnalysisTest, PrintAnalysisResultsThreeFrames) {
|
2013-09-10 12:10:01 +00:00
|
|
|
ResultsContainer result;
|
|
|
|
|
result.frames.push_back(AnalysisResult(0, 35.0, 0.9));
|
|
|
|
|
result.frames.push_back(AnalysisResult(1, 34.0, 0.8));
|
|
|
|
|
result.frames.push_back(AnalysisResult(2, 33.0, 0.7));
|
2013-11-03 18:34:51 +00:00
|
|
|
PrintAnalysisResults(logfile_, "ThreeFrames", &result);
|
2013-09-10 12:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
2017-02-16 01:36:43 -08:00
|
|
|
TEST_F(VideoQualityAnalysisTest,
|
|
|
|
|
PrintMaxRepeatedAndSkippedFramesSkippedFrames) {
|
2018-01-30 15:33:02 +01:00
|
|
|
ResultsContainer result;
|
2017-02-16 01:36:43 -08:00
|
|
|
|
|
|
|
|
std::string log_filename =
|
|
|
|
|
TempFilename(webrtc::test::OutputPath(), "log.log");
|
|
|
|
|
FILE* logfile = fopen(log_filename.c_str(), "w");
|
|
|
|
|
ASSERT_TRUE(logfile != NULL);
|
2018-09-05 16:11:48 +02:00
|
|
|
|
|
|
|
|
result.max_repeated_frames = 2;
|
|
|
|
|
result.max_skipped_frames = 2;
|
|
|
|
|
result.total_skipped_frames = 3;
|
|
|
|
|
result.decode_errors_ref = 0;
|
|
|
|
|
result.decode_errors_test = 0;
|
|
|
|
|
|
2018-01-30 15:33:02 +01:00
|
|
|
PrintAnalysisResults(logfile, "NormalStatsFile", &result);
|
2017-02-16 01:36:43 -08:00
|
|
|
ASSERT_EQ(0, fclose(logfile));
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> expected_out = {
|
2018-01-30 15:33:02 +01:00
|
|
|
"RESULT Max_repeated: NormalStatsFile= 2 ",
|
|
|
|
|
"RESULT Max_skipped: NormalStatsFile= 2 ",
|
|
|
|
|
"RESULT Total_skipped: NormalStatsFile= 3 ",
|
|
|
|
|
"RESULT Decode_errors_reference: NormalStatsFile= 0 ",
|
|
|
|
|
"RESULT Decode_errors_test: NormalStatsFile= 0 "};
|
2017-02-16 01:36:43 -08:00
|
|
|
VerifyLogOutput(log_filename, expected_out);
|
2013-09-10 12:10:01 +00:00
|
|
|
}
|
|
|
|
|
|
2017-02-16 01:36:43 -08:00
|
|
|
TEST_F(VideoQualityAnalysisTest,
|
|
|
|
|
PrintMaxRepeatedAndSkippedFramesDecodeErrorInTest) {
|
2018-01-30 15:33:02 +01:00
|
|
|
ResultsContainer result;
|
2017-02-16 01:36:43 -08:00
|
|
|
|
|
|
|
|
std::string log_filename =
|
|
|
|
|
TempFilename(webrtc::test::OutputPath(), "log.log");
|
|
|
|
|
FILE* logfile = fopen(log_filename.c_str(), "w");
|
|
|
|
|
ASSERT_TRUE(logfile != NULL);
|
2018-09-05 16:11:48 +02:00
|
|
|
|
|
|
|
|
result.max_repeated_frames = 1;
|
|
|
|
|
result.max_skipped_frames = 0;
|
|
|
|
|
result.total_skipped_frames = 0;
|
|
|
|
|
result.decode_errors_ref = 0;
|
|
|
|
|
result.decode_errors_test = 3;
|
2018-01-30 15:33:02 +01:00
|
|
|
PrintAnalysisResults(logfile, "NormalStatsFile", &result);
|
2017-02-16 01:36:43 -08:00
|
|
|
ASSERT_EQ(0, fclose(logfile));
|
|
|
|
|
|
|
|
|
|
std::vector<std::string> expected_out = {
|
2018-01-30 15:33:02 +01:00
|
|
|
"RESULT Max_repeated: NormalStatsFile= 1 ",
|
|
|
|
|
"RESULT Max_skipped: NormalStatsFile= 0 ",
|
|
|
|
|
"RESULT Total_skipped: NormalStatsFile= 0 ",
|
|
|
|
|
"RESULT Decode_errors_reference: NormalStatsFile= 0 ",
|
|
|
|
|
"RESULT Decode_errors_test: NormalStatsFile= 3 "};
|
2017-02-16 01:36:43 -08:00
|
|
|
VerifyLogOutput(log_filename, expected_out);
|
|
|
|
|
}
|
|
|
|
|
|
2018-08-27 17:58:13 +02:00
|
|
|
TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersOneValue) {
|
2018-09-05 16:11:48 +02:00
|
|
|
const std::vector<Cluster> result = CalculateFrameClusters({1});
|
|
|
|
|
EXPECT_EQ(1u, result.size());
|
|
|
|
|
EXPECT_EQ(1u, result[0].index);
|
|
|
|
|
EXPECT_EQ(1, result[0].number_of_repeated_frames);
|
|
|
|
|
}
|
2017-02-16 01:36:43 -08:00
|
|
|
|
2018-09-05 16:11:48 +02:00
|
|
|
TEST_F(VideoQualityAnalysisTest, GetMaxRepeatedFramesOneValue) {
|
|
|
|
|
EXPECT_EQ(1, GetMaxRepeatedFrames(CalculateFrameClusters({1})));
|
|
|
|
|
}
|
2017-02-16 01:36:43 -08:00
|
|
|
|
2018-09-05 16:11:48 +02:00
|
|
|
TEST_F(VideoQualityAnalysisTest, GetMaxSkippedFramesOneValue) {
|
|
|
|
|
EXPECT_EQ(0, GetMaxSkippedFrames(CalculateFrameClusters({1})));
|
|
|
|
|
}
|
2017-02-16 01:36:43 -08:00
|
|
|
|
2018-09-05 16:11:48 +02:00
|
|
|
TEST_F(VideoQualityAnalysisTest, GetTotalNumberOfSkippedFramesOneValue) {
|
|
|
|
|
EXPECT_EQ(0, GetTotalNumberOfSkippedFrames(CalculateFrameClusters({1})));
|
2018-08-24 10:56:05 +02:00
|
|
|
}
|
2017-02-16 01:36:43 -08:00
|
|
|
|
2018-08-27 17:58:13 +02:00
|
|
|
TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersOneOneTwo) {
|
2018-09-05 16:11:48 +02:00
|
|
|
const std::vector<Cluster> result = CalculateFrameClusters({1, 1, 2});
|
|
|
|
|
EXPECT_EQ(2u, result.size());
|
|
|
|
|
EXPECT_EQ(1u, result[0].index);
|
|
|
|
|
EXPECT_EQ(2, result[0].number_of_repeated_frames);
|
|
|
|
|
EXPECT_EQ(2u, result[1].index);
|
|
|
|
|
EXPECT_EQ(1, result[1].number_of_repeated_frames);
|
2018-08-24 14:56:03 +02:00
|
|
|
}
|
2018-08-24 12:44:59 +00:00
|
|
|
|
2018-09-05 16:11:48 +02:00
|
|
|
TEST_F(VideoQualityAnalysisTest, GetMaxRepeatedFramesOneOneTwo) {
|
|
|
|
|
EXPECT_EQ(2, GetMaxRepeatedFrames(CalculateFrameClusters({1, 1, 2})));
|
2018-08-24 14:56:03 +02:00
|
|
|
}
|
2018-08-24 12:44:59 +00:00
|
|
|
|
2018-09-05 16:11:48 +02:00
|
|
|
TEST_F(VideoQualityAnalysisTest, GetMaxSkippedFramesOneOneTwo) {
|
|
|
|
|
EXPECT_EQ(0, GetMaxSkippedFrames(CalculateFrameClusters({1, 1, 2})));
|
2018-08-24 14:56:03 +02:00
|
|
|
}
|
2018-08-24 12:44:59 +00:00
|
|
|
|
2018-09-05 16:11:48 +02:00
|
|
|
TEST_F(VideoQualityAnalysisTest, GetTotalNumberOfSkippedFramesOneOneTwo) {
|
|
|
|
|
EXPECT_EQ(0,
|
|
|
|
|
GetTotalNumberOfSkippedFrames(CalculateFrameClusters({1, 1, 2})));
|
2018-08-24 12:44:59 +00:00
|
|
|
}
|
2018-08-24 14:56:03 +02:00
|
|
|
|
2018-08-27 17:58:13 +02:00
|
|
|
TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersEmpty) {
|
2018-09-05 16:11:48 +02:00
|
|
|
EXPECT_TRUE(CalculateFrameClusters({}).empty());
|
|
|
|
|
}
|
2018-08-27 17:58:13 +02:00
|
|
|
|
2018-09-05 16:11:48 +02:00
|
|
|
TEST_F(VideoQualityAnalysisTest, GetMaxRepeatedFramesEmpty) {
|
|
|
|
|
EXPECT_EQ(0, GetMaxRepeatedFrames({}));
|
|
|
|
|
}
|
2018-08-27 17:58:13 +02:00
|
|
|
|
2018-09-05 16:11:48 +02:00
|
|
|
TEST_F(VideoQualityAnalysisTest, GetMaxSkippedFramesEmpty) {
|
|
|
|
|
EXPECT_EQ(0, GetMaxSkippedFrames({}));
|
|
|
|
|
}
|
2018-08-27 17:58:13 +02:00
|
|
|
|
2018-09-05 16:11:48 +02:00
|
|
|
TEST_F(VideoQualityAnalysisTest, GetTotalNumberOfSkippedFramesEmpty) {
|
|
|
|
|
EXPECT_EQ(0, GetTotalNumberOfSkippedFrames({}));
|
2018-08-27 17:58:13 +02:00
|
|
|
}
|
2018-09-05 16:11:48 +02:00
|
|
|
|
2013-09-10 12:10:01 +00:00
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|