OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2012 The WebM project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include <string> | 11 #include <string> |
12 #include "test/md5_helper.h" | 12 #include "test/md5_helper.h" |
13 #include "test/util.h" | 13 #include "test/util.h" |
14 #include "test/y4m_video_source.h" | 14 #include "test/y4m_video_source.h" |
15 #include "third_party/googletest/src/include/gtest/gtest.h" | 15 #include "third_party/googletest/src/include/gtest/gtest.h" |
16 #include "./vpx_config.h" | 16 #include "./vpx_config.h" |
17 #include "./y4menc.h" | 17 #include "./y4menc.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 using std::string; | 21 using std::string; |
22 | 22 |
23 static const unsigned int kWidth = 160; | 23 static const unsigned int kWidth = 160; |
24 static const unsigned int kHeight = 90; | 24 static const unsigned int kHeight = 90; |
25 static const unsigned int kFrames = 10; | 25 static const unsigned int kFrames = 10; |
26 | 26 |
27 typedef struct { | 27 struct Y4mTestParam { |
28 const char *filename; | 28 const char *filename; |
29 unsigned int bit_depth; | 29 unsigned int bit_depth; |
30 vpx_img_fmt format; | 30 vpx_img_fmt format; |
31 const char *md5raw; | 31 const char *md5raw; |
32 } test_entry_type; | 32 }; |
33 | 33 |
34 const test_entry_type kY4mTestVectors[] = { | 34 const Y4mTestParam kY4mTestVectors[] = { |
35 {"park_joy_90p_8_420.y4m", 8, VPX_IMG_FMT_I420, | 35 {"park_joy_90p_8_420.y4m", 8, VPX_IMG_FMT_I420, |
36 "e5406275b9fc6bb3436c31d4a05c1cab"}, | 36 "e5406275b9fc6bb3436c31d4a05c1cab"}, |
37 {"park_joy_90p_8_422.y4m", 8, VPX_IMG_FMT_I422, | 37 {"park_joy_90p_8_422.y4m", 8, VPX_IMG_FMT_I422, |
38 "284a47a47133b12884ec3a14e959a0b6"}, | 38 "284a47a47133b12884ec3a14e959a0b6"}, |
39 {"park_joy_90p_8_444.y4m", 8, VPX_IMG_FMT_I444, | 39 {"park_joy_90p_8_444.y4m", 8, VPX_IMG_FMT_I444, |
40 "90517ff33843d85de712fd4fe60dbed0"}, | 40 "90517ff33843d85de712fd4fe60dbed0"}, |
41 {"park_joy_90p_10_420.y4m", 10, VPX_IMG_FMT_I42016, | 41 {"park_joy_90p_10_420.y4m", 10, VPX_IMG_FMT_I42016, |
42 "63f21f9f717d8b8631bd2288ee87137b"}, | 42 "63f21f9f717d8b8631bd2288ee87137b"}, |
43 {"park_joy_90p_10_422.y4m", 10, VPX_IMG_FMT_I42216, | 43 {"park_joy_90p_10_422.y4m", 10, VPX_IMG_FMT_I42216, |
44 "48ab51fb540aed07f7ff5af130c9b605"}, | 44 "48ab51fb540aed07f7ff5af130c9b605"}, |
(...skipping 18 matching lines...) Expand all Loading... |
63 const int w = (plane ? (img->d_w + img->x_chroma_shift) >> | 63 const int w = (plane ? (img->d_w + img->x_chroma_shift) >> |
64 img->x_chroma_shift : img->d_w); | 64 img->x_chroma_shift : img->d_w); |
65 for (y = 0; y < h; ++y) { | 65 for (y = 0; y < h; ++y) { |
66 fwrite(buf, bytes_per_sample, w, file); | 66 fwrite(buf, bytes_per_sample, w, file); |
67 buf += stride; | 67 buf += stride; |
68 } | 68 } |
69 } | 69 } |
70 } | 70 } |
71 | 71 |
72 class Y4mVideoSourceTest | 72 class Y4mVideoSourceTest |
73 : public ::testing::TestWithParam<test_entry_type>, | 73 : public ::testing::TestWithParam<Y4mTestParam>, |
74 public ::libvpx_test::Y4mVideoSource { | 74 public ::libvpx_test::Y4mVideoSource { |
75 protected: | 75 protected: |
76 Y4mVideoSourceTest() : Y4mVideoSource("", 0, 0) {} | 76 Y4mVideoSourceTest() : Y4mVideoSource("", 0, 0) {} |
77 | 77 |
78 virtual ~Y4mVideoSourceTest() { | 78 virtual ~Y4mVideoSourceTest() { |
79 CloseSource(); | 79 CloseSource(); |
80 } | 80 } |
81 | 81 |
82 virtual void Init(const std::string &file_name, int limit) { | 82 virtual void Init(const std::string &file_name, int limit) { |
83 file_name_ = file_name; | 83 file_name_ = file_name; |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 libvpx_test::MD5 md5; | 119 libvpx_test::MD5 md5; |
120 for (unsigned int i = start_; i < limit_; i++) { | 120 for (unsigned int i = start_; i < limit_; i++) { |
121 md5.Add(img()); | 121 md5.Add(img()); |
122 Next(); | 122 Next(); |
123 } | 123 } |
124 ASSERT_EQ(string(md5.Get()), expected_md5); | 124 ASSERT_EQ(string(md5.Get()), expected_md5); |
125 } | 125 } |
126 }; | 126 }; |
127 | 127 |
128 TEST_P(Y4mVideoSourceTest, SourceTest) { | 128 TEST_P(Y4mVideoSourceTest, SourceTest) { |
129 const test_entry_type t = GetParam(); | 129 const Y4mTestParam t = GetParam(); |
130 Init(t.filename, kFrames); | 130 Init(t.filename, kFrames); |
131 HeaderChecks(t.bit_depth, t.format); | 131 HeaderChecks(t.bit_depth, t.format); |
132 Md5Check(t.md5raw); | 132 Md5Check(t.md5raw); |
133 } | 133 } |
134 | 134 |
135 INSTANTIATE_TEST_CASE_P(C, Y4mVideoSourceTest, | 135 INSTANTIATE_TEST_CASE_P(C, Y4mVideoSourceTest, |
136 ::testing::ValuesIn(kY4mTestVectors)); | 136 ::testing::ValuesIn(kY4mTestVectors)); |
137 | 137 |
138 class Y4mVideoWriteTest | 138 class Y4mVideoWriteTest |
139 : public Y4mVideoSourceTest { | 139 : public Y4mVideoSourceTest { |
140 protected: | 140 protected: |
141 Y4mVideoWriteTest() : Y4mVideoSourceTest() {} | 141 Y4mVideoWriteTest() {} |
142 | 142 |
143 virtual void ReplaceInputFp(FILE *input_file) { | 143 virtual ~Y4mVideoWriteTest() { |
144 CloseSource(); | 144 CloseSource(); |
145 frame_ = 0; | 145 delete tmpfile_; |
146 input_file_ = input_file; | |
147 rewind(input_file_); | |
148 ReadSourceToStart(); | |
149 } | 146 } |
150 | 147 |
151 // Writes out a y4m file and then reads it back | 148 // Writes out a y4m file and then reads it back |
152 void WriteY4mAndReadBack() { | 149 void WriteY4mAndReadBack() { |
153 ASSERT_TRUE(input_file_ != NULL); | 150 ASSERT_TRUE(input_file_ != NULL); |
154 char buf[Y4M_BUFFER_SIZE] = {0}; | 151 char buf[Y4M_BUFFER_SIZE] = {0}; |
155 const struct VpxRational framerate = {y4m_.fps_n, y4m_.fps_d}; | 152 const struct VpxRational framerate = {y4m_.fps_n, y4m_.fps_d}; |
156 FILE *out_file = libvpx_test::OpenTempOutFile(); | 153 tmpfile_ = new libvpx_test::TempOutFile; |
157 ASSERT_TRUE(out_file != NULL); | 154 ASSERT_TRUE(tmpfile_->file() != NULL); |
158 y4m_write_file_header(buf, sizeof(buf), | 155 y4m_write_file_header(buf, sizeof(buf), |
159 kWidth, kHeight, | 156 kWidth, kHeight, |
160 &framerate, y4m_.vpx_fmt, | 157 &framerate, y4m_.vpx_fmt, |
161 y4m_.bit_depth); | 158 y4m_.bit_depth); |
162 fputs(buf, out_file); | 159 fputs(buf, tmpfile_->file()); |
163 for (unsigned int i = start_; i < limit_; i++) { | 160 for (unsigned int i = start_; i < limit_; i++) { |
164 y4m_write_frame_header(buf, sizeof(buf)); | 161 y4m_write_frame_header(buf, sizeof(buf)); |
165 fputs(buf, out_file); | 162 fputs(buf, tmpfile_->file()); |
166 write_image_file(img(), out_file); | 163 write_image_file(img(), tmpfile_->file()); |
167 Next(); | 164 Next(); |
168 } | 165 } |
169 ReplaceInputFp(out_file); | 166 tmpfile_->CloseFile(); |
| 167 Y4mVideoSourceTest::Init(tmpfile_->file_name(), limit_); |
170 } | 168 } |
171 | 169 |
172 virtual void Init(const std::string &file_name, int limit) { | 170 virtual void Init(const std::string &file_name, int limit) { |
173 Y4mVideoSourceTest::Init(file_name, limit); | 171 Y4mVideoSourceTest::Init(file_name, limit); |
174 WriteY4mAndReadBack(); | 172 WriteY4mAndReadBack(); |
175 } | 173 } |
| 174 libvpx_test::TempOutFile *tmpfile_; |
176 }; | 175 }; |
177 | 176 |
178 TEST_P(Y4mVideoWriteTest, WriteTest) { | 177 TEST_P(Y4mVideoWriteTest, WriteTest) { |
179 const test_entry_type t = GetParam(); | 178 const Y4mTestParam t = GetParam(); |
180 Init(t.filename, kFrames); | 179 Init(t.filename, kFrames); |
181 HeaderChecks(t.bit_depth, t.format); | 180 HeaderChecks(t.bit_depth, t.format); |
182 Md5Check(t.md5raw); | 181 Md5Check(t.md5raw); |
183 } | 182 } |
184 | 183 |
185 INSTANTIATE_TEST_CASE_P(C, Y4mVideoWriteTest, | 184 INSTANTIATE_TEST_CASE_P(C, Y4mVideoWriteTest, |
186 ::testing::ValuesIn(kY4mTestVectors)); | 185 ::testing::ValuesIn(kY4mTestVectors)); |
187 } // namespace | 186 } // namespace |
OLD | NEW |