Move firtpass read into helper func
Add data path to the file name
Bug: b/221916304
Change-Id: I658a882dcc7e58691b26e6709ca027a706546663
diff --git a/test/ratectrl_qmode_test.cc b/test/ratectrl_qmode_test.cc
index 62239f6..e9eb257 100644
--- a/test/ratectrl_qmode_test.cc
+++ b/test/ratectrl_qmode_test.cc
@@ -20,8 +20,86 @@
#include "av1/ratectrl_qmode.h"
#include "av1/reference_manager.h"
#include "test/mock_ratectrl_qmode.h"
+#include "test/video_source.h"
#include "third_party/googletest/src/googletest/include/gtest/gtest.h"
+namespace {
+
+// Reads a whitespace-delimited string from stream, and parses it as a double.
+// Returns an empty string if the entire string was successfully parsed as a
+// double, or an error messaage if not.
+std::string ReadDouble(std::istream &stream, double *value) {
+ std::string word;
+ stream >> word;
+ if (word.empty()) {
+ return "Unexpectedly reached end of input";
+ }
+ char *end;
+ *value = std::strtod(word.c_str(), &end);
+ if (*end != '\0') {
+ return "Unexpected characters found: " + word;
+ }
+ return "";
+}
+
+void ReadFirstpassInfo(const std::string &filename,
+ aom::FirstpassInfo *firstpass_info) {
+ // These golden files are generated by the following command line:
+ // ./aomenc --width=352 --height=288 --fps=30/1 --limit=250 --codec=av1
+ // --cpu-used=3 --end-usage=q --cq-level=36 --threads=0 --profile=0
+ // --lag-in-frames=35 --min-q=0 --max-q=63 --auto-alt-ref=1 --passes=2
+ // --kf-max-dist=160 --kf-min-dist=0 --drop-frame=0
+ // --static-thresh=0 --minsection-pct=0 --maxsection-pct=2000
+ // --arnr-maxframes=7
+ // --arnr-strength=5 --sharpness=0 --undershoot-pct=100 --overshoot-pct=100
+ // --frame-parallel=0
+ // --tile-columns=0 -o output.webm hantro_collage_w352h288.yuv
+ // First pass stats are written out in av1_get_second_pass_params right after
+ // calculate_gf_length.
+ std::ifstream firstpass_stats_file(libaom_test::GetDataPath() + "/" +
+ filename);
+ firstpass_info->num_mbs_16x16 = (352 / 16 + 1) * (288 / 16 + 1);
+ std::string newline;
+ while (std::getline(firstpass_stats_file, newline)) {
+ std::istringstream iss(newline);
+ FIRSTPASS_STATS firstpass_stats_input = {};
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.frame), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.weight), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.intra_error), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.frame_avg_wavelet_energy),
+ "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.coded_error), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.sr_coded_error), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.pcnt_inter), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.pcnt_motion), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.pcnt_second_ref), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.pcnt_neutral), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.intra_skip_pct), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.inactive_zone_rows), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.inactive_zone_cols), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.MVr), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.mvr_abs), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.MVc), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.mvc_abs), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.MVrv), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.MVcv), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.mv_in_out_count), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.new_mv_count), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.duration), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.count), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.raw_error_stdev), "");
+ iss >> firstpass_stats_input.is_flash;
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.noise_var), "");
+ ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.cor_coeff), "");
+ ASSERT_TRUE(iss.eof()) << "Too many fields on line "
+ << firstpass_info->stats_list.size() + 1 << "\n"
+ << newline;
+ firstpass_info->stats_list.push_back(firstpass_stats_input);
+ }
+}
+
+} // namespace
+
namespace aom {
using ::testing::ElementsAre;
@@ -662,76 +740,10 @@
}
}
-// Reads a whitespace-delimited string from stream, and parses it as a double.
-// Returns an empty string if the entire string was successfully parsed as a
-// double, or an error messaage if not.
-std::string ReadDouble(std::istream &stream, double *value) {
- std::string word;
- stream >> word;
- if (word.empty()) {
- return "Unexpectedly reached end of input";
- }
- char *end;
- *value = std::strtod(word.c_str(), &end);
- if (*end != '\0') {
- return "Unexpected characters found: " + word;
- }
- return "";
-}
-
TEST(RateControlQModeTest, TestKeyframeDetection) {
FirstpassInfo firstpass_info;
- // These golden files are generated by the following command line:
- // ./aomenc --width=352 --height=288 --fps=30/1 --limit=250 --codec=av1
- // --cpu-used=3 --end-usage=q --cq-level=36 --threads=0 --profile=0
- // --lag-in-frames=35 --min-q=0 --max-q=63 --auto-alt-ref=1 --passes=2
- // --kf-max-dist=160 --kf-min-dist=0 --drop-frame=0
- // --static-thresh=0 --minsection-pct=0 --maxsection-pct=2000
- // --arnr-maxframes=7
- // --arnr-strength=5 --sharpness=0 --undershoot-pct=100 --overshoot-pct=100
- // --frame-parallel=0
- // --tile-columns=0 -o output.webm hantro_collage_w352h288.yuv
- // First pass stats are written out in av1_get_second_pass_params right after
- // calculate_gf_length.
- std::ifstream firstpass_stats_file("firstpass_stats");
- firstpass_info.num_mbs_16x16 = (352 / 16 + 1) * (288 / 16 + 1);
- std::string newline;
- while (std::getline(firstpass_stats_file, newline)) {
- std::istringstream iss(newline);
- FIRSTPASS_STATS firstpass_stats_input = {};
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.frame), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.weight), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.intra_error), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.frame_avg_wavelet_energy),
- "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.coded_error), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.sr_coded_error), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.pcnt_inter), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.pcnt_motion), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.pcnt_second_ref), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.pcnt_neutral), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.intra_skip_pct), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.inactive_zone_rows), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.inactive_zone_cols), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.MVr), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.mvr_abs), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.MVc), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.mvc_abs), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.MVrv), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.MVcv), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.mv_in_out_count), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.new_mv_count), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.duration), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.count), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.raw_error_stdev), "");
- iss >> firstpass_stats_input.is_flash;
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.noise_var), "");
- ASSERT_EQ(ReadDouble(iss, &firstpass_stats_input.cor_coeff), "");
- ASSERT_TRUE(iss.eof()) << "Too many fields on line "
- << firstpass_info.stats_list.size() + 1 << "\n"
- << newline;
- firstpass_info.stats_list.push_back(firstpass_stats_input);
- }
+ const std::string kFirstpassStatsFile = "firstpass_stats";
+ ReadFirstpassInfo(kFirstpassStatsFile, &firstpass_info);
EXPECT_THAT(GetKeyFrameList(firstpass_info),
ElementsAre(0, 30, 60, 90, 120, 150, 180, 210, 240));
}