• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3  *
4  * This source code is subject to the terms of the BSD 2 Clause License and
5  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6  * was not distributed with this source code in the LICENSE file, you can
7  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8  * Media Patent License 1.0 was not distributed with this source code in the
9  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10  */
11 
12 #include <string>
13 
14 #include "config/aom_config.h"
15 
16 #include "common/y4menc.h"
17 #include "test/md5_helper.h"
18 #include "test/util.h"
19 #include "test/y4m_video_source.h"
20 #include "third_party/googletest/src/googletest/include/gtest/gtest.h"
21 
22 namespace {
23 
24 using std::string;
25 
26 static const unsigned int kWidth = 160;
27 static const unsigned int kHeight = 90;
28 static const unsigned int kFrames = 10;
29 
30 struct Y4mTestParam {
31   const char *filename;
32   unsigned int bit_depth;
33   aom_img_fmt format;
34   const char *md5raw;
35 };
36 
37 const Y4mTestParam kY4mTestVectors[] = {
38   { "park_joy_90p_8_420.y4m", 8, AOM_IMG_FMT_I420,
39     "e5406275b9fc6bb3436c31d4a05c1cab" },
40   { "park_joy_90p_8_420_monochrome.y4m", 8, AOM_IMG_FMT_I420,
41     "95ef5bf6218580588be24a5271bb6a7f" },
42   { "park_joy_90p_8_420_vertical_csp.y4m", 8, AOM_IMG_FMT_I420,
43     "f53a40fec15254ac312527339d9c686b" },
44   { "park_joy_90p_8_422.y4m", 8, AOM_IMG_FMT_I422,
45     "284a47a47133b12884ec3a14e959a0b6" },
46   { "park_joy_90p_8_444.y4m", 8, AOM_IMG_FMT_I444,
47     "90517ff33843d85de712fd4fe60dbed0" },
48   { "park_joy_90p_10_420.y4m", 10, AOM_IMG_FMT_I42016,
49     "63f21f9f717d8b8631bd2288ee87137b" },
50   { "park_joy_90p_10_422.y4m", 10, AOM_IMG_FMT_I42216,
51     "48ab51fb540aed07f7ff5af130c9b605" },
52   { "park_joy_90p_10_444.y4m", 10, AOM_IMG_FMT_I44416,
53     "067bfd75aa85ff9bae91fa3e0edd1e3e" },
54   { "park_joy_90p_12_420.y4m", 12, AOM_IMG_FMT_I42016,
55     "9e6d8f6508c6e55625f6b697bc461cef" },
56   { "park_joy_90p_12_422.y4m", 12, AOM_IMG_FMT_I42216,
57     "b239c6b301c0b835485be349ca83a7e3" },
58   { "park_joy_90p_12_444.y4m", 12, AOM_IMG_FMT_I44416,
59     "5a6481a550821dab6d0192f5c63845e9" },
60 };
61 
62 static const int PLANES_YUV[] = { AOM_PLANE_Y, AOM_PLANE_U, AOM_PLANE_V };
63 
64 class Y4mVideoSourceTest : public ::testing::TestWithParam<Y4mTestParam>,
65                            public ::libaom_test::Y4mVideoSource {
66  protected:
Y4mVideoSourceTest()67   Y4mVideoSourceTest() : Y4mVideoSource("", 0, 0) {}
68 
~Y4mVideoSourceTest()69   virtual ~Y4mVideoSourceTest() { CloseSource(); }
70 
Init(const std::string & file_name,int limit)71   virtual void Init(const std::string &file_name, int limit) {
72     file_name_ = file_name;
73     start_ = 0;
74     limit_ = limit;
75     frame_ = 0;
76     Begin();
77   }
78 
79   // Checks y4m header information
HeaderChecks(unsigned int bit_depth,aom_img_fmt_t fmt)80   void HeaderChecks(unsigned int bit_depth, aom_img_fmt_t fmt) {
81     ASSERT_TRUE(input_file_ != NULL);
82     ASSERT_EQ(y4m_.pic_w, (int)kWidth);
83     ASSERT_EQ(y4m_.pic_h, (int)kHeight);
84     ASSERT_EQ(img()->d_w, kWidth);
85     ASSERT_EQ(img()->d_h, kHeight);
86     ASSERT_EQ(y4m_.bit_depth, bit_depth);
87     ASSERT_EQ(y4m_.aom_fmt, fmt);
88     if (fmt == AOM_IMG_FMT_I420 || fmt == AOM_IMG_FMT_I42016) {
89       ASSERT_EQ(y4m_.bps, (int)y4m_.bit_depth * 3 / 2);
90       ASSERT_EQ(img()->x_chroma_shift, 1U);
91       ASSERT_EQ(img()->y_chroma_shift, 1U);
92     }
93     if (fmt == AOM_IMG_FMT_I422 || fmt == AOM_IMG_FMT_I42216) {
94       ASSERT_EQ(y4m_.bps, (int)y4m_.bit_depth * 2);
95       ASSERT_EQ(img()->x_chroma_shift, 1U);
96       ASSERT_EQ(img()->y_chroma_shift, 0U);
97     }
98     if (fmt == AOM_IMG_FMT_I444 || fmt == AOM_IMG_FMT_I44416) {
99       ASSERT_EQ(y4m_.bps, (int)y4m_.bit_depth * 3);
100       ASSERT_EQ(img()->x_chroma_shift, 0U);
101       ASSERT_EQ(img()->y_chroma_shift, 0U);
102     }
103   }
104 
105   // Checks MD5 of the raw frame data
Md5Check(const string & expected_md5)106   void Md5Check(const string &expected_md5) {
107     ASSERT_TRUE(input_file_ != NULL);
108     libaom_test::MD5 md5;
109     for (unsigned int i = start_; i < limit_; i++) {
110       md5.Add(img());
111       Next();
112     }
113     ASSERT_EQ(string(md5.Get()), expected_md5);
114   }
115 };
116 
TEST_P(Y4mVideoSourceTest,SourceTest)117 TEST_P(Y4mVideoSourceTest, SourceTest) {
118   const Y4mTestParam t = GetParam();
119   Init(t.filename, kFrames);
120   HeaderChecks(t.bit_depth, t.format);
121   Md5Check(t.md5raw);
122 }
123 
124 INSTANTIATE_TEST_CASE_P(C, Y4mVideoSourceTest,
125                         ::testing::ValuesIn(kY4mTestVectors));
126 
127 class Y4mVideoWriteTest : public Y4mVideoSourceTest {
128  protected:
Y4mVideoWriteTest()129   Y4mVideoWriteTest() : tmpfile_(NULL) {}
130 
~Y4mVideoWriteTest()131   virtual ~Y4mVideoWriteTest() {
132     delete tmpfile_;
133     input_file_ = NULL;
134   }
135 
ReplaceInputFile(FILE * input_file)136   void ReplaceInputFile(FILE *input_file) {
137     CloseSource();
138     frame_ = 0;
139     input_file_ = input_file;
140     rewind(input_file_);
141     ReadSourceToStart();
142   }
143 
144   // Writes out a y4m file and then reads it back
WriteY4mAndReadBack()145   void WriteY4mAndReadBack() {
146     ASSERT_TRUE(input_file_ != NULL);
147     char buf[Y4M_BUFFER_SIZE] = { 0 };
148     const struct AvxRational framerate = { y4m_.fps_n, y4m_.fps_d };
149     tmpfile_ = new libaom_test::TempOutFile;
150     ASSERT_TRUE(tmpfile_->file() != NULL);
151     y4m_write_file_header(buf, sizeof(buf), kWidth, kHeight, &framerate,
152                           img()->monochrome, img()->csp, y4m_.aom_fmt,
153                           y4m_.bit_depth);
154     fputs(buf, tmpfile_->file());
155     for (unsigned int i = start_; i < limit_; i++) {
156       y4m_write_frame_header(buf, sizeof(buf));
157       fputs(buf, tmpfile_->file());
158       y4m_write_image_file(img(), PLANES_YUV, tmpfile_->file());
159       Next();
160     }
161     ReplaceInputFile(tmpfile_->file());
162   }
163 
Init(const std::string & file_name,int limit)164   virtual void Init(const std::string &file_name, int limit) {
165     Y4mVideoSourceTest::Init(file_name, limit);
166     WriteY4mAndReadBack();
167   }
168   libaom_test::TempOutFile *tmpfile_;
169 };
170 
TEST_P(Y4mVideoWriteTest,WriteTest)171 TEST_P(Y4mVideoWriteTest, WriteTest) {
172   const Y4mTestParam t = GetParam();
173   Init(t.filename, kFrames);
174   HeaderChecks(t.bit_depth, t.format);
175   Md5Check(t.md5raw);
176 }
177 
178 INSTANTIATE_TEST_CASE_P(C, Y4mVideoWriteTest,
179                         ::testing::ValuesIn(kY4mTestVectors));
180 }  // namespace
181