Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(13)

Side by Side Diff: webrtc/tools/frame_analyzer/video_quality_analysis_unittest.cc

Issue 2965593002: Move webrtc/{tools => rtc_tools} (Closed)
Patch Set: Adding back root changes Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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 <stdio.h>
15 #include <fstream>
16 #include <string>
17
18 #include "webrtc/test/gtest.h"
19 #include "webrtc/test/testsupport/fileutils.h"
20 #include "webrtc/tools/frame_analyzer/video_quality_analysis.h"
21
22 namespace webrtc {
23 namespace test {
24
25 // Setup a log file to write the output to instead of stdout because we don't
26 // want those numbers to be picked up as perf numbers.
27 class VideoQualityAnalysisTest : public ::testing::Test {
28 protected:
29 void SetUp() {
30 std::string log_filename = TempFilename(webrtc::test::OutputPath(),
31 "VideoQualityAnalysisTest.log");
32 logfile_ = fopen(log_filename.c_str(), "w");
33 ASSERT_TRUE(logfile_ != NULL);
34
35 stats_filename_ref_ = TempFilename(OutputPath(), "stats-1.txt");
36 stats_filename_ = TempFilename(OutputPath(), "stats-2.txt");
37 }
38 void TearDown() { ASSERT_EQ(0, fclose(logfile_)); }
39 FILE* logfile_;
40 std::string stats_filename_ref_;
41 std::string stats_filename_;
42 };
43
44 TEST_F(VideoQualityAnalysisTest, MatchExtractedY4mFrame) {
45 std::string video_file =
46 webrtc::test::ResourcePath("reference_less_video_test_file", "y4m");
47
48 std::string extracted_frame_from_video_file =
49 webrtc::test::ResourcePath("video_quality_analysis_frame", "txt");
50
51 int frame_height = 720, frame_width = 1280;
52 int frame_number = 2;
53 int size = GetI420FrameSize(frame_width, frame_height);
54 uint8_t* result_frame = new uint8_t[size];
55 uint8_t* expected_frame = new uint8_t[size];
56
57 FILE* input_file = fopen(extracted_frame_from_video_file.c_str(), "rb");
58 fread(expected_frame, 1, size, input_file);
59
60 ExtractFrameFromY4mFile(video_file.c_str(),
61 frame_width, frame_height,
62 frame_number, result_frame);
63
64 EXPECT_EQ(*expected_frame, *result_frame);
65 fclose(input_file);
66 delete[] result_frame;
67 delete[] expected_frame;
68 }
69
70 TEST_F(VideoQualityAnalysisTest, PrintAnalysisResultsEmpty) {
71 ResultsContainer result;
72 PrintAnalysisResults(logfile_, "Empty", &result);
73 }
74
75 TEST_F(VideoQualityAnalysisTest, PrintAnalysisResultsOneFrame) {
76 ResultsContainer result;
77 result.frames.push_back(AnalysisResult(0, 35.0, 0.9));
78 PrintAnalysisResults(logfile_, "OneFrame", &result);
79 }
80
81 TEST_F(VideoQualityAnalysisTest, PrintAnalysisResultsThreeFrames) {
82 ResultsContainer result;
83 result.frames.push_back(AnalysisResult(0, 35.0, 0.9));
84 result.frames.push_back(AnalysisResult(1, 34.0, 0.8));
85 result.frames.push_back(AnalysisResult(2, 33.0, 0.7));
86 PrintAnalysisResults(logfile_, "ThreeFrames", &result);
87 }
88
89 TEST_F(VideoQualityAnalysisTest, PrintMaxRepeatedAndSkippedFramesInvalidFile) {
90 remove(stats_filename_.c_str());
91 PrintMaxRepeatedAndSkippedFrames(logfile_, "NonExistingStatsFile",
92 stats_filename_ref_, stats_filename_);
93 }
94
95 TEST_F(VideoQualityAnalysisTest,
96 PrintMaxRepeatedAndSkippedFramesEmptyStatsFile) {
97 std::ofstream stats_file;
98 stats_file.open(stats_filename_ref_.c_str());
99 stats_file.close();
100 stats_file.open(stats_filename_.c_str());
101 stats_file.close();
102 PrintMaxRepeatedAndSkippedFrames(logfile_, "EmptyStatsFile",
103 stats_filename_ref_, stats_filename_);
104 }
105
106 TEST_F(VideoQualityAnalysisTest, PrintMaxRepeatedAndSkippedFramesNormalFile) {
107 std::ofstream stats_file;
108
109 stats_file.open(stats_filename_ref_.c_str());
110 stats_file << "frame_0001 0100\n";
111 stats_file << "frame_0002 0101\n";
112 stats_file << "frame_0003 0102\n";
113 stats_file << "frame_0004 0103\n";
114 stats_file << "frame_0005 0106\n";
115 stats_file << "frame_0006 0107\n";
116 stats_file << "frame_0007 0108\n";
117 stats_file.close();
118
119 stats_file.open(stats_filename_.c_str());
120 stats_file << "frame_0001 0100\n";
121 stats_file << "frame_0002 0101\n";
122 stats_file << "frame_0003 0101\n";
123 stats_file << "frame_0004 0106\n";
124 stats_file.close();
125
126 PrintMaxRepeatedAndSkippedFrames(logfile_, "NormalStatsFile",
127 stats_filename_ref_, stats_filename_);
128 }
129
130 namespace {
131 void VerifyLogOutput(const std::string& log_filename,
132 const std::vector<std::string>& expected_out) {
133 std::ifstream logf(log_filename);
134 std::string line;
135
136 std::size_t i;
137 for (i = 0; i < expected_out.size() && getline(logf, line); ++i) {
138 ASSERT_EQ(expected_out.at(i), line);
139 }
140 ASSERT_TRUE(i == expected_out.size()) << "Not enough input data";
141 }
142 } // unnamed namespace
143
144 TEST_F(VideoQualityAnalysisTest,
145 PrintMaxRepeatedAndSkippedFramesSkippedFrames) {
146 std::ofstream stats_file;
147
148 std::string log_filename =
149 TempFilename(webrtc::test::OutputPath(), "log.log");
150 FILE* logfile = fopen(log_filename.c_str(), "w");
151 ASSERT_TRUE(logfile != NULL);
152 stats_file.open(stats_filename_ref_.c_str());
153 stats_file << "frame_0001 0100\n";
154 stats_file << "frame_0002 0101\n";
155 stats_file << "frame_0002 0101\n";
156 stats_file << "frame_0003 0103\n";
157 stats_file << "frame_0004 0103\n";
158 stats_file << "frame_0005 0106\n";
159 stats_file << "frame_0006 0106\n";
160 stats_file << "frame_0007 0108\n";
161 stats_file << "frame_0008 0110\n";
162 stats_file << "frame_0009 0112\n";
163 stats_file.close();
164
165 stats_file.open(stats_filename_.c_str());
166 stats_file << "frame_0001 0101\n";
167 stats_file << "frame_0002 0101\n";
168 stats_file << "frame_0003 0101\n";
169 stats_file << "frame_0004 0108\n";
170 stats_file << "frame_0005 0108\n";
171 stats_file << "frame_0006 0112\n";
172 stats_file.close();
173
174 PrintMaxRepeatedAndSkippedFrames(logfile, "NormalStatsFile",
175 stats_filename_ref_, stats_filename_);
176 ASSERT_EQ(0, fclose(logfile));
177
178 std::vector<std::string> expected_out = {
179 "RESULT Max_repeated: NormalStatsFile= 2",
180 "RESULT Max_skipped: NormalStatsFile= 2",
181 "RESULT Total_skipped: NormalStatsFile= 3",
182 "RESULT Decode_errors_reference: NormalStatsFile= 0",
183 "RESULT Decode_errors_test: NormalStatsFile= 0"};
184 VerifyLogOutput(log_filename, expected_out);
185 }
186
187 TEST_F(VideoQualityAnalysisTest,
188 PrintMaxRepeatedAndSkippedFramesDecodeErrorInTest) {
189 std::ofstream stats_file;
190
191 std::string log_filename =
192 TempFilename(webrtc::test::OutputPath(), "log.log");
193 FILE* logfile = fopen(log_filename.c_str(), "w");
194 ASSERT_TRUE(logfile != NULL);
195 stats_file.open(stats_filename_ref_.c_str());
196 stats_file << "frame_0001 0100\n";
197 stats_file << "frame_0002 0100\n";
198 stats_file << "frame_0002 0101\n";
199 stats_file << "frame_0003 0103\n";
200 stats_file << "frame_0004 0103\n";
201 stats_file << "frame_0005 0106\n";
202 stats_file << "frame_0006 0107\n";
203 stats_file << "frame_0007 0107\n";
204 stats_file << "frame_0008 0110\n";
205 stats_file << "frame_0009 0112\n";
206 stats_file.close();
207
208 stats_file.open(stats_filename_.c_str());
209 stats_file << "frame_0001 0101\n";
210 stats_file << "frame_0002 Barcode error\n";
211 stats_file << "frame_0003 Barcode error\n";
212 stats_file << "frame_0004 Barcode error\n";
213 stats_file << "frame_0005 0107\n";
214 stats_file << "frame_0006 0110\n";
215 stats_file.close();
216
217 PrintMaxRepeatedAndSkippedFrames(logfile, "NormalStatsFile",
218 stats_filename_ref_, stats_filename_);
219 ASSERT_EQ(0, fclose(logfile));
220
221 std::vector<std::string> expected_out = {
222 "RESULT Max_repeated: NormalStatsFile= 1",
223 "RESULT Max_skipped: NormalStatsFile= 0",
224 "RESULT Total_skipped: NormalStatsFile= 0",
225 "RESULT Decode_errors_reference: NormalStatsFile= 0",
226 "RESULT Decode_errors_test: NormalStatsFile= 3"};
227 VerifyLogOutput(log_filename, expected_out);
228 }
229
230 TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersOneValue) {
231 std::ofstream stats_file;
232
233 stats_file.open(stats_filename_.c_str());
234 stats_file << "frame_0001 0101\n";
235 stats_file.close();
236
237 FILE* stats_filef = fopen(stats_filename_.c_str(), "r");
238 ASSERT_TRUE(stats_filef != NULL);
239
240 auto clusters = CalculateFrameClusters(stats_filef, nullptr);
241 ASSERT_EQ(0, fclose(stats_filef));
242 decltype(clusters) expected = {std::make_pair(101, 1)};
243 ASSERT_EQ(expected, clusters);
244 }
245
246 TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersOneOneTwo) {
247 std::ofstream stats_file;
248
249 stats_file.open(stats_filename_.c_str());
250 stats_file << "frame_0001 0101\n";
251 stats_file << "frame_0002 0101\n";
252 stats_file << "frame_0003 0102\n";
253 stats_file.close();
254
255 FILE* stats_filef = fopen(stats_filename_.c_str(), "r");
256 ASSERT_TRUE(stats_filef != NULL);
257
258 auto clusters = CalculateFrameClusters(stats_filef, nullptr);
259 ASSERT_EQ(0, fclose(stats_filef));
260 decltype(clusters) expected = {std::make_pair(101, 2),
261 std::make_pair(102, 1)};
262 ASSERT_EQ(expected, clusters);
263 }
264
265 TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersOneOneErrErrThree) {
266 std::ofstream stats_file;
267
268 stats_file.open(stats_filename_.c_str());
269 stats_file << "frame_0001 0101\n";
270 stats_file << "frame_0002 0101\n";
271 stats_file << "frame_0003 Barcode error\n";
272 stats_file << "frame_0004 Barcode error\n";
273 stats_file << "frame_0005 0103\n";
274 stats_file.close();
275
276 FILE* stats_filef = fopen(stats_filename_.c_str(), "r");
277 ASSERT_TRUE(stats_filef != NULL);
278
279 auto clusters = CalculateFrameClusters(stats_filef, nullptr);
280 ASSERT_EQ(0, fclose(stats_filef));
281 decltype(clusters) expected = {std::make_pair(101, 2),
282 std::make_pair(DECODE_ERROR, 2),
283 std::make_pair(103, 1)};
284 ASSERT_EQ(expected, clusters);
285 }
286
287 TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersErrErr) {
288 std::ofstream stats_file;
289
290 stats_file.open(stats_filename_.c_str());
291 stats_file << "frame_0001 Barcode error\n";
292 stats_file << "frame_0002 Barcode error\n";
293 stats_file.close();
294
295 FILE* stats_filef = fopen(stats_filename_.c_str(), "r");
296 ASSERT_TRUE(stats_filef != NULL);
297
298 auto clusters = CalculateFrameClusters(stats_filef, nullptr);
299 ASSERT_EQ(0, fclose(stats_filef));
300 decltype(clusters) expected = {std::make_pair(DECODE_ERROR, 2)};
301 ASSERT_EQ(expected, clusters);
302 }
303
304 TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersOneOneErrErrOneOne) {
305 std::ofstream stats_file;
306
307 stats_file.open(stats_filename_.c_str());
308 stats_file << "frame_0001 0101\n";
309 stats_file << "frame_0002 0101\n";
310 stats_file << "frame_0003 Barcode error\n";
311 stats_file << "frame_0004 Barcode error\n";
312 stats_file << "frame_0005 0101\n";
313 stats_file << "frame_0006 0101\n";
314 stats_file.close();
315
316 FILE* stats_filef = fopen(stats_filename_.c_str(), "r");
317 ASSERT_TRUE(stats_filef != NULL);
318
319 auto clusters = CalculateFrameClusters(stats_filef, nullptr);
320 ASSERT_EQ(0, fclose(stats_filef));
321 decltype(clusters) expected = {std::make_pair(101, 6)};
322 ASSERT_EQ(expected, clusters);
323 }
324
325 TEST_F(VideoQualityAnalysisTest, CalculateFrameClustersEmpty) {
326 std::ofstream stats_file;
327
328 stats_file.open(stats_filename_.c_str());
329 stats_file.close();
330
331 FILE* stats_filef = fopen(stats_filename_.c_str(), "r");
332 ASSERT_TRUE(stats_filef != NULL);
333
334 auto clusters = CalculateFrameClusters(stats_filef, nullptr);
335 ASSERT_EQ(0, fclose(stats_filef));
336 decltype(clusters) expected;
337 ASSERT_EQ(expected, clusters);
338 }
339 } // namespace test
340 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/tools/frame_analyzer/video_quality_analysis.cc ('k') | webrtc/tools/frame_editing/frame_editing.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698