• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *  Copyright (c) 2013 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  */
10 
11 // This test doesn't actually verify the output since it's just printed
12 // to stdout by void functions, but it's still useful as it executes the code.
13 
14 #include "rtc_tools/frame_analyzer/video_quality_analysis.h"
15 
16 #include <stdio.h>
17 
18 #include <cstddef>
19 #include <fstream>
20 #include <string>
21 
22 #include "test/gtest.h"
23 #include "test/testsupport/file_utils.h"
24 
25 namespace webrtc {
26 namespace test {
27 
28 namespace {
29 
VerifyLogOutput(const std::string & log_filename,const std::vector<std::string> & expected_out)30 void VerifyLogOutput(const std::string& log_filename,
31                      const std::vector<std::string>& expected_out) {
32   std::ifstream logf(log_filename);
33   std::string line;
34 
35   std::size_t i;
36   for (i = 0; i < expected_out.size() && getline(logf, line); ++i) {
37     ASSERT_EQ(expected_out.at(i), line);
38   }
39   ASSERT_TRUE(i == expected_out.size()) << "Not enough input data";
40 }
41 
42 }  // namespace
43 
44 // Setup a log file to write the output to instead of stdout because we don't
45 // want those numbers to be picked up as perf numbers.
46 class VideoQualityAnalysisTest : public ::testing::Test {
47  protected:
SetUp()48   void SetUp() {
49     std::string log_filename = TempFilename(webrtc::test::OutputPath(),
50                                             "VideoQualityAnalysisTest.log");
51     logfile_ = fopen(log_filename.c_str(), "w");
52     ASSERT_TRUE(logfile_ != NULL);
53   }
TearDown()54   void TearDown() { ASSERT_EQ(0, fclose(logfile_)); }
55   FILE* logfile_;
56 };
57 
TEST_F(VideoQualityAnalysisTest,PrintAnalysisResultsEmpty)58 TEST_F(VideoQualityAnalysisTest, PrintAnalysisResultsEmpty) {
59   ResultsContainer result;
60   PrintAnalysisResults(logfile_, "Empty", &result);
61 }
62 
TEST_F(VideoQualityAnalysisTest,PrintAnalysisResultsOneFrame)63 TEST_F(VideoQualityAnalysisTest, PrintAnalysisResultsOneFrame) {
64   ResultsContainer result;
65   result.frames.push_back(AnalysisResult(0, 35.0, 0.9));
66   PrintAnalysisResults(logfile_, "OneFrame", &result);
67 }
68 
TEST_F(VideoQualityAnalysisTest,PrintAnalysisResultsThreeFrames)69 TEST_F(VideoQualityAnalysisTest, PrintAnalysisResultsThreeFrames) {
70   ResultsContainer result;
71   result.frames.push_back(AnalysisResult(0, 35.0, 0.9));
72   result.frames.push_back(AnalysisResult(1, 34.0, 0.8));
73   result.frames.push_back(AnalysisResult(2, 33.0, 0.7));
74   PrintAnalysisResults(logfile_, "ThreeFrames", &result);
75 }
76 
TEST_F(VideoQualityAnalysisTest,PrintMaxRepeatedAndSkippedFramesSkippedFrames)77 TEST_F(VideoQualityAnalysisTest,
78        PrintMaxRepeatedAndSkippedFramesSkippedFrames) {
79   ResultsContainer result;
80 
81   std::string log_filename =
82       TempFilename(webrtc::test::OutputPath(), "log.log");
83   FILE* logfile = fopen(log_filename.c_str(), "w");
84   ASSERT_TRUE(logfile != NULL);
85 
86   result.max_repeated_frames = 2;
87   result.max_skipped_frames = 2;
88   result.total_skipped_frames = 3;
89   result.decode_errors_ref = 0;
90   result.decode_errors_test = 0;
91 
92   PrintAnalysisResults(logfile, "NormalStatsFile", &result);
93   ASSERT_EQ(0, fclose(logfile));
94 
95   std::vector<std::string> expected_out = {
96       "RESULT Max_repeated: NormalStatsFile= 2 ",
97       "RESULT Max_skipped: NormalStatsFile= 2 ",
98       "RESULT Total_skipped: NormalStatsFile= 3 ",
99       "RESULT Decode_errors_reference: NormalStatsFile= 0 ",
100       "RESULT Decode_errors_test: NormalStatsFile= 0 "};
101   VerifyLogOutput(log_filename, expected_out);
102 }
103 
TEST_F(VideoQualityAnalysisTest,PrintMaxRepeatedAndSkippedFramesDecodeErrorInTest)104 TEST_F(VideoQualityAnalysisTest,
105        PrintMaxRepeatedAndSkippedFramesDecodeErrorInTest) {
106   ResultsContainer result;
107 
108   std::string log_filename =
109       TempFilename(webrtc::test::OutputPath(), "log.log");
110   FILE* logfile = fopen(log_filename.c_str(), "w");
111   ASSERT_TRUE(logfile != NULL);
112 
113   result.max_repeated_frames = 1;
114   result.max_skipped_frames = 0;
115   result.total_skipped_frames = 0;
116   result.decode_errors_ref = 0;
117   result.decode_errors_test = 3;
118   PrintAnalysisResults(logfile, "NormalStatsFile", &result);
119   ASSERT_EQ(0, fclose(logfile));
120 
121   std::vector<std::string> expected_out = {
122       "RESULT Max_repeated: NormalStatsFile= 1 ",
123       "RESULT Max_skipped: NormalStatsFile= 0 ",
124       "RESULT Total_skipped: NormalStatsFile= 0 ",
125       "RESULT Decode_errors_reference: NormalStatsFile= 0 ",
126       "RESULT Decode_errors_test: NormalStatsFile= 3 "};
127   VerifyLogOutput(log_filename, expected_out);
128 }
129 
TEST_F(VideoQualityAnalysisTest,CalculateFrameClustersOneValue)130 TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersOneValue) {
131   const std::vector<Cluster> result = CalculateFrameClusters({1});
132   EXPECT_EQ(1u, result.size());
133   EXPECT_EQ(1u, result[0].index);
134   EXPECT_EQ(1, result[0].number_of_repeated_frames);
135 }
136 
TEST_F(VideoQualityAnalysisTest,GetMaxRepeatedFramesOneValue)137 TEST_F(VideoQualityAnalysisTest, GetMaxRepeatedFramesOneValue) {
138   EXPECT_EQ(1, GetMaxRepeatedFrames(CalculateFrameClusters({1})));
139 }
140 
TEST_F(VideoQualityAnalysisTest,GetMaxSkippedFramesOneValue)141 TEST_F(VideoQualityAnalysisTest, GetMaxSkippedFramesOneValue) {
142   EXPECT_EQ(0, GetMaxSkippedFrames(CalculateFrameClusters({1})));
143 }
144 
TEST_F(VideoQualityAnalysisTest,GetTotalNumberOfSkippedFramesOneValue)145 TEST_F(VideoQualityAnalysisTest, GetTotalNumberOfSkippedFramesOneValue) {
146   EXPECT_EQ(0, GetTotalNumberOfSkippedFrames(CalculateFrameClusters({1})));
147 }
148 
TEST_F(VideoQualityAnalysisTest,CalculateFrameClustersOneOneTwo)149 TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersOneOneTwo) {
150   const std::vector<Cluster> result = CalculateFrameClusters({1, 1, 2});
151   EXPECT_EQ(2u, result.size());
152   EXPECT_EQ(1u, result[0].index);
153   EXPECT_EQ(2, result[0].number_of_repeated_frames);
154   EXPECT_EQ(2u, result[1].index);
155   EXPECT_EQ(1, result[1].number_of_repeated_frames);
156 }
157 
TEST_F(VideoQualityAnalysisTest,GetMaxRepeatedFramesOneOneTwo)158 TEST_F(VideoQualityAnalysisTest, GetMaxRepeatedFramesOneOneTwo) {
159   EXPECT_EQ(2, GetMaxRepeatedFrames(CalculateFrameClusters({1, 1, 2})));
160 }
161 
TEST_F(VideoQualityAnalysisTest,GetMaxSkippedFramesOneOneTwo)162 TEST_F(VideoQualityAnalysisTest, GetMaxSkippedFramesOneOneTwo) {
163   EXPECT_EQ(0, GetMaxSkippedFrames(CalculateFrameClusters({1, 1, 2})));
164 }
165 
TEST_F(VideoQualityAnalysisTest,GetTotalNumberOfSkippedFramesOneOneTwo)166 TEST_F(VideoQualityAnalysisTest, GetTotalNumberOfSkippedFramesOneOneTwo) {
167   EXPECT_EQ(0,
168             GetTotalNumberOfSkippedFrames(CalculateFrameClusters({1, 1, 2})));
169 }
170 
TEST_F(VideoQualityAnalysisTest,CalculateFrameClustersEmpty)171 TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersEmpty) {
172   EXPECT_TRUE(CalculateFrameClusters({}).empty());
173 }
174 
TEST_F(VideoQualityAnalysisTest,GetMaxRepeatedFramesEmpty)175 TEST_F(VideoQualityAnalysisTest, GetMaxRepeatedFramesEmpty) {
176   EXPECT_EQ(0, GetMaxRepeatedFrames({}));
177 }
178 
TEST_F(VideoQualityAnalysisTest,GetMaxSkippedFramesEmpty)179 TEST_F(VideoQualityAnalysisTest, GetMaxSkippedFramesEmpty) {
180   EXPECT_EQ(0, GetMaxSkippedFrames({}));
181 }
182 
TEST_F(VideoQualityAnalysisTest,GetTotalNumberOfSkippedFramesEmpty)183 TEST_F(VideoQualityAnalysisTest, GetTotalNumberOfSkippedFramesEmpty) {
184   EXPECT_EQ(0, GetTotalNumberOfSkippedFrames({}));
185 }
186 
187 }  // namespace test
188 }  // namespace webrtc
189