Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 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. |
Johann | 123e8a6 | 2017-12-28 14:40:49 -0800 | [diff] [blame] | 10 | */ |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 11 | |
| 12 | #include <string> |
Jingning Han | 097d59c | 2015-07-29 14:51:36 -0700 | [diff] [blame] | 13 | |
Tom Finegan | 7a07ece | 2017-02-07 17:14:05 -0800 | [diff] [blame] | 14 | #include "third_party/googletest/src/googletest/include/gtest/gtest.h" |
Jingning Han | 097d59c | 2015-07-29 14:51:36 -0700 | [diff] [blame] | 15 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 16 | #include "./aom_config.h" |
Jingning Han | 097d59c | 2015-07-29 14:51:36 -0700 | [diff] [blame] | 17 | #include "./y4menc.h" |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 18 | #include "test/md5_helper.h" |
| 19 | #include "test/util.h" |
| 20 | #include "test/y4m_video_source.h" |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 21 | |
| 22 | namespace { |
| 23 | |
| 24 | using std::string; |
| 25 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 26 | static const unsigned int kWidth = 160; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 27 | static const unsigned int kHeight = 90; |
| 28 | static const unsigned int kFrames = 10; |
| 29 | |
James Zern | 1cfaaf6 | 2014-07-16 19:03:08 -0700 | [diff] [blame] | 30 | struct Y4mTestParam { |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 31 | const char *filename; |
| 32 | unsigned int bit_depth; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 33 | aom_img_fmt format; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 34 | const char *md5raw; |
James Zern | 1cfaaf6 | 2014-07-16 19:03:08 -0700 | [diff] [blame] | 35 | }; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 36 | |
James Zern | 1cfaaf6 | 2014-07-16 19:03:08 -0700 | [diff] [blame] | 37 | const Y4mTestParam kY4mTestVectors[] = { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 38 | { "park_joy_90p_8_420.y4m", 8, AOM_IMG_FMT_I420, |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 39 | "e5406275b9fc6bb3436c31d4a05c1cab" }, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 40 | { "park_joy_90p_8_422.y4m", 8, AOM_IMG_FMT_I422, |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 41 | "284a47a47133b12884ec3a14e959a0b6" }, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 42 | { "park_joy_90p_8_444.y4m", 8, AOM_IMG_FMT_I444, |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 43 | "90517ff33843d85de712fd4fe60dbed0" }, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 44 | { "park_joy_90p_10_420.y4m", 10, AOM_IMG_FMT_I42016, |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 45 | "63f21f9f717d8b8631bd2288ee87137b" }, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 46 | { "park_joy_90p_10_422.y4m", 10, AOM_IMG_FMT_I42216, |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 47 | "48ab51fb540aed07f7ff5af130c9b605" }, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 48 | { "park_joy_90p_10_444.y4m", 10, AOM_IMG_FMT_I44416, |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 49 | "067bfd75aa85ff9bae91fa3e0edd1e3e" }, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 50 | { "park_joy_90p_12_420.y4m", 12, AOM_IMG_FMT_I42016, |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 51 | "9e6d8f6508c6e55625f6b697bc461cef" }, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 52 | { "park_joy_90p_12_422.y4m", 12, AOM_IMG_FMT_I42216, |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 53 | "b239c6b301c0b835485be349ca83a7e3" }, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 54 | { "park_joy_90p_12_444.y4m", 12, AOM_IMG_FMT_I44416, |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 55 | "5a6481a550821dab6d0192f5c63845e9" }, |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 56 | }; |
| 57 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 58 | static void write_image_file(const aom_image_t *img, FILE *file) { |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 59 | int plane, y; |
| 60 | for (plane = 0; plane < 3; ++plane) { |
| 61 | const unsigned char *buf = img->planes[plane]; |
| 62 | const int stride = img->stride[plane]; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 63 | const int bytes_per_sample = (img->fmt & AOM_IMG_FMT_HIGHBITDEPTH) ? 2 : 1; |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 64 | const int h = |
| 65 | (plane ? (img->d_h + img->y_chroma_shift) >> img->y_chroma_shift |
| 66 | : img->d_h); |
| 67 | const int w = |
| 68 | (plane ? (img->d_w + img->x_chroma_shift) >> img->x_chroma_shift |
| 69 | : img->d_w); |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 70 | for (y = 0; y < h; ++y) { |
| 71 | fwrite(buf, bytes_per_sample, w, file); |
| 72 | buf += stride; |
| 73 | } |
| 74 | } |
| 75 | } |
| 76 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 77 | class Y4mVideoSourceTest : public ::testing::TestWithParam<Y4mTestParam>, |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 78 | public ::libaom_test::Y4mVideoSource { |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 79 | protected: |
| 80 | Y4mVideoSourceTest() : Y4mVideoSource("", 0, 0) {} |
| 81 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 82 | virtual ~Y4mVideoSourceTest() { CloseSource(); } |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 83 | |
| 84 | virtual void Init(const std::string &file_name, int limit) { |
| 85 | file_name_ = file_name; |
| 86 | start_ = 0; |
| 87 | limit_ = limit; |
| 88 | frame_ = 0; |
| 89 | Begin(); |
| 90 | } |
| 91 | |
| 92 | // Checks y4m header information |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 93 | void HeaderChecks(unsigned int bit_depth, aom_img_fmt_t fmt) { |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 94 | ASSERT_TRUE(input_file_ != NULL); |
| 95 | ASSERT_EQ(y4m_.pic_w, (int)kWidth); |
| 96 | ASSERT_EQ(y4m_.pic_h, (int)kHeight); |
| 97 | ASSERT_EQ(img()->d_w, kWidth); |
| 98 | ASSERT_EQ(img()->d_h, kHeight); |
| 99 | ASSERT_EQ(y4m_.bit_depth, bit_depth); |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 100 | ASSERT_EQ(y4m_.aom_fmt, fmt); |
| 101 | if (fmt == AOM_IMG_FMT_I420 || fmt == AOM_IMG_FMT_I42016) { |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 102 | ASSERT_EQ(y4m_.bps, (int)y4m_.bit_depth * 3 / 2); |
| 103 | ASSERT_EQ(img()->x_chroma_shift, 1U); |
| 104 | ASSERT_EQ(img()->y_chroma_shift, 1U); |
| 105 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 106 | if (fmt == AOM_IMG_FMT_I422 || fmt == AOM_IMG_FMT_I42216) { |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 107 | ASSERT_EQ(y4m_.bps, (int)y4m_.bit_depth * 2); |
| 108 | ASSERT_EQ(img()->x_chroma_shift, 1U); |
| 109 | ASSERT_EQ(img()->y_chroma_shift, 0U); |
| 110 | } |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 111 | if (fmt == AOM_IMG_FMT_I444 || fmt == AOM_IMG_FMT_I44416) { |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 112 | ASSERT_EQ(y4m_.bps, (int)y4m_.bit_depth * 3); |
| 113 | ASSERT_EQ(img()->x_chroma_shift, 0U); |
| 114 | ASSERT_EQ(img()->y_chroma_shift, 0U); |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | // Checks MD5 of the raw frame data |
| 119 | void Md5Check(const string &expected_md5) { |
| 120 | ASSERT_TRUE(input_file_ != NULL); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 121 | libaom_test::MD5 md5; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 122 | for (unsigned int i = start_; i < limit_; i++) { |
| 123 | md5.Add(img()); |
| 124 | Next(); |
| 125 | } |
| 126 | ASSERT_EQ(string(md5.Get()), expected_md5); |
| 127 | } |
| 128 | }; |
| 129 | |
| 130 | TEST_P(Y4mVideoSourceTest, SourceTest) { |
James Zern | 1cfaaf6 | 2014-07-16 19:03:08 -0700 | [diff] [blame] | 131 | const Y4mTestParam t = GetParam(); |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 132 | Init(t.filename, kFrames); |
| 133 | HeaderChecks(t.bit_depth, t.format); |
| 134 | Md5Check(t.md5raw); |
| 135 | } |
| 136 | |
| 137 | INSTANTIATE_TEST_CASE_P(C, Y4mVideoSourceTest, |
| 138 | ::testing::ValuesIn(kY4mTestVectors)); |
| 139 | |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 140 | class Y4mVideoWriteTest : public Y4mVideoSourceTest { |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 141 | protected: |
Tristan Matthews | 46940a8 | 2016-01-22 18:05:48 -0500 | [diff] [blame] | 142 | Y4mVideoWriteTest() : tmpfile_(NULL) {} |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 143 | |
Deb Mukherjee | 096224f | 2014-07-14 13:31:29 -0700 | [diff] [blame] | 144 | virtual ~Y4mVideoWriteTest() { |
Deb Mukherjee | 096224f | 2014-07-14 13:31:29 -0700 | [diff] [blame] | 145 | delete tmpfile_; |
Deb Mukherjee | 4851b99 | 2014-08-14 14:59:50 -0700 | [diff] [blame] | 146 | input_file_ = NULL; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Deb Mukherjee | 4851b99 | 2014-08-14 14:59:50 -0700 | [diff] [blame] | 149 | void ReplaceInputFile(FILE *input_file) { |
Deb Mukherjee | a463513 | 2014-08-11 13:44:27 -0700 | [diff] [blame] | 150 | CloseSource(); |
| 151 | frame_ = 0; |
| 152 | input_file_ = input_file; |
| 153 | rewind(input_file_); |
| 154 | ReadSourceToStart(); |
| 155 | } |
| 156 | |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 157 | // Writes out a y4m file and then reads it back |
| 158 | void WriteY4mAndReadBack() { |
| 159 | ASSERT_TRUE(input_file_ != NULL); |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 160 | char buf[Y4M_BUFFER_SIZE] = { 0 }; |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 161 | const struct AvxRational framerate = { y4m_.fps_n, y4m_.fps_d }; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 162 | tmpfile_ = new libaom_test::TempOutFile; |
Deb Mukherjee | 096224f | 2014-07-14 13:31:29 -0700 | [diff] [blame] | 163 | ASSERT_TRUE(tmpfile_->file() != NULL); |
clang-format | 3a826f1 | 2016-08-11 17:46:05 -0700 | [diff] [blame] | 164 | y4m_write_file_header(buf, sizeof(buf), kWidth, kHeight, &framerate, |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 165 | y4m_.aom_fmt, y4m_.bit_depth); |
Deb Mukherjee | 096224f | 2014-07-14 13:31:29 -0700 | [diff] [blame] | 166 | fputs(buf, tmpfile_->file()); |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 167 | for (unsigned int i = start_; i < limit_; i++) { |
| 168 | y4m_write_frame_header(buf, sizeof(buf)); |
Deb Mukherjee | 096224f | 2014-07-14 13:31:29 -0700 | [diff] [blame] | 169 | fputs(buf, tmpfile_->file()); |
| 170 | write_image_file(img(), tmpfile_->file()); |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 171 | Next(); |
| 172 | } |
Deb Mukherjee | a463513 | 2014-08-11 13:44:27 -0700 | [diff] [blame] | 173 | ReplaceInputFile(tmpfile_->file()); |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | virtual void Init(const std::string &file_name, int limit) { |
| 177 | Y4mVideoSourceTest::Init(file_name, limit); |
| 178 | WriteY4mAndReadBack(); |
| 179 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 180 | libaom_test::TempOutFile *tmpfile_; |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 181 | }; |
| 182 | |
| 183 | TEST_P(Y4mVideoWriteTest, WriteTest) { |
James Zern | 1cfaaf6 | 2014-07-16 19:03:08 -0700 | [diff] [blame] | 184 | const Y4mTestParam t = GetParam(); |
Deb Mukherjee | 5820c5d | 2014-06-12 16:53:13 -0700 | [diff] [blame] | 185 | Init(t.filename, kFrames); |
| 186 | HeaderChecks(t.bit_depth, t.format); |
| 187 | Md5Check(t.md5raw); |
| 188 | } |
| 189 | |
| 190 | INSTANTIATE_TEST_CASE_P(C, Y4mVideoWriteTest, |
| 191 | ::testing::ValuesIn(kY4mTestVectors)); |
| 192 | } // namespace |