OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // For each sample vp9 test video, $filename, there is a file of golden value | |
6 // of frame entropy, named $filename.context. These values are dumped from | |
7 // libvpx. | |
8 // | |
9 // The syntax of these context dump is described as following. For every | |
10 // frames, there are corresponding data in context file, | |
11 // 1. [initial] [current] [should_update=0], or | |
12 // 2. [initial] [current] [should_update=1] [update] | |
13 // The first two are expected frame entropy, fhdr->initial_frame_context and | |
14 // fhdr->frame_context. | |
15 // If |should_update| is true, it follows by the frame context to update. | |
5 #include <stdint.h> | 16 #include <stdint.h> |
17 #include <string.h> | |
6 | 18 |
7 #include "base/files/memory_mapped_file.h" | 19 #include "base/files/memory_mapped_file.h" |
8 #include "base/logging.h" | 20 #include "base/logging.h" |
9 #include "media/base/test_data_util.h" | 21 #include "media/base/test_data_util.h" |
10 #include "media/filters/ivf_parser.h" | 22 #include "media/filters/ivf_parser.h" |
11 #include "media/filters/vp9_parser.h" | 23 #include "media/filters/vp9_parser.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 24 #include "testing/gtest/include/gtest/gtest.h" |
13 | 25 |
14 namespace media { | 26 namespace media { |
15 | 27 |
16 class Vp9ParserTest : public ::testing::Test { | 28 class Vp9ParserTest : public ::testing::Test { |
17 protected: | 29 protected: |
18 void SetUp() override { | 30 void TearDown() override { |
19 base::FilePath file_path = GetTestDataFilePath("test-25fps.vp9"); | 31 stream_.reset(); |
32 vp9_parser_.reset(); | |
33 context_file_.Close(); | |
34 } | |
35 | |
36 void Initialize(const std::string& filename, bool parsing_compressed_header) { | |
37 base::FilePath file_path = GetTestDataFilePath(filename); | |
20 | 38 |
21 stream_.reset(new base::MemoryMappedFile()); | 39 stream_.reset(new base::MemoryMappedFile()); |
22 ASSERT_TRUE(stream_->Initialize(file_path)) << "Couldn't open stream file: " | 40 ASSERT_TRUE(stream_->Initialize(file_path)) << "Couldn't open stream file: " |
23 << file_path.MaybeAsASCII(); | 41 << file_path.MaybeAsASCII(); |
24 | 42 |
25 IvfFileHeader ivf_file_header; | 43 IvfFileHeader ivf_file_header; |
26 ASSERT_TRUE(ivf_parser_.Initialize(stream_->data(), stream_->length(), | 44 ASSERT_TRUE(ivf_parser_.Initialize(stream_->data(), stream_->length(), |
27 &ivf_file_header)); | 45 &ivf_file_header)); |
28 ASSERT_EQ(ivf_file_header.fourcc, 0x30395056u); // VP90 | 46 ASSERT_EQ(ivf_file_header.fourcc, 0x30395056u); // VP90 |
47 | |
48 vp9_parser_.reset(new Vp9Parser(parsing_compressed_header)); | |
49 | |
50 if (parsing_compressed_header) { | |
51 base::FilePath context_path = GetTestDataFilePath(filename + ".context"); | |
52 context_file_.Initialize(context_path, | |
53 base::File::FLAG_OPEN | base::File::FLAG_READ); | |
54 ASSERT_TRUE(context_file_.IsValid()); | |
55 } | |
29 } | 56 } |
30 | 57 |
31 void TearDown() override { stream_.reset(); } | 58 bool ReadShouldContextUpdate() { |
32 | 59 char should_update; |
33 bool ParseNextFrame(struct Vp9FrameHeader* frame_hdr); | 60 int read_num = context_file_.ReadAtCurrentPos(&should_update, 1); |
34 | 61 CHECK_EQ(1, read_num); |
35 const Vp9Segmentation& GetSegmentation() const { | 62 return static_cast<bool>(should_update); |
36 return vp9_parser_.GetSegmentation(); | |
37 } | 63 } |
38 | 64 |
39 const Vp9LoopFilter& GetLoopFilter() const { | 65 void ReadContext(Vp9FrameContext* frame_context) { |
40 return vp9_parser_.GetLoopFilter(); | 66 ASSERT_EQ( |
67 static_cast<int>(sizeof(*frame_context)), | |
68 context_file_.ReadAtCurrentPos(reinterpret_cast<char*>(frame_context), | |
69 sizeof(*frame_context))); | |
70 } | |
71 | |
72 Vp9Parser::Result ParseNextFrame( | |
73 struct Vp9FrameHeader* frame_hdr, | |
74 Vp9FrameContextManager::ContextRefreshCallback* context_refresh_cb); | |
75 | |
76 const Vp9SegmentationParams& GetSegmentation() const { | |
77 return vp9_parser_->GetSegmentation(); | |
78 } | |
79 | |
80 const Vp9LoopFilterParams& GetLoopFilter() const { | |
81 return vp9_parser_->GetLoopFilter(); | |
41 } | 82 } |
42 | 83 |
43 IvfParser ivf_parser_; | 84 IvfParser ivf_parser_; |
44 std::unique_ptr<base::MemoryMappedFile> stream_; | 85 std::unique_ptr<base::MemoryMappedFile> stream_; |
45 | 86 |
46 Vp9Parser vp9_parser_; | 87 std::unique_ptr<Vp9Parser> vp9_parser_; |
88 base::File context_file_; | |
47 }; | 89 }; |
48 | 90 |
49 bool Vp9ParserTest::ParseNextFrame(Vp9FrameHeader* fhdr) { | 91 Vp9Parser::Result Vp9ParserTest::ParseNextFrame( |
92 Vp9FrameHeader* fhdr, | |
93 Vp9FrameContextManager::ContextRefreshCallback* context_refresh_cb) { | |
50 while (1) { | 94 while (1) { |
51 Vp9Parser::Result res = vp9_parser_.ParseNextFrame(fhdr); | 95 Vp9Parser::Result res = |
96 vp9_parser_->ParseNextFrame(fhdr, context_refresh_cb); | |
52 if (res == Vp9Parser::kEOStream) { | 97 if (res == Vp9Parser::kEOStream) { |
53 IvfFrameHeader ivf_frame_header; | 98 IvfFrameHeader ivf_frame_header; |
54 const uint8_t* ivf_payload; | 99 const uint8_t* ivf_payload; |
55 | 100 |
56 if (!ivf_parser_.ParseNextFrame(&ivf_frame_header, &ivf_payload)) | 101 if (!ivf_parser_.ParseNextFrame(&ivf_frame_header, &ivf_payload)) |
57 return false; | 102 return Vp9Parser::kEOStream; |
58 | 103 |
59 vp9_parser_.SetStream(ivf_payload, ivf_frame_header.frame_size); | 104 vp9_parser_->SetStream(ivf_payload, ivf_frame_header.frame_size); |
60 continue; | 105 continue; |
61 } | 106 } |
62 | 107 |
63 return res == Vp9Parser::kOk; | 108 return res; |
64 } | 109 } |
65 } | 110 } |
66 | 111 |
67 TEST_F(Vp9ParserTest, StreamFileParsing) { | 112 TEST_F(Vp9ParserTest, StreamFileParsingWithoutCompressedHeader) { |
113 Initialize("test-25fps.vp9", false); | |
114 | |
68 // Number of frames in the test stream to be parsed. | 115 // Number of frames in the test stream to be parsed. |
69 const int num_frames = 250; | 116 const int num_expected_frames = 269; |
70 int num_parsed_frames = 0; | 117 int num_parsed_frames = 0; |
71 | 118 |
72 while (num_parsed_frames < num_frames) { | 119 // Allow to parse double frames in order to detect extra frames parsed. |
120 while (num_parsed_frames < num_expected_frames * 2) { | |
73 Vp9FrameHeader fhdr; | 121 Vp9FrameHeader fhdr; |
74 if (!ParseNextFrame(&fhdr)) | 122 if (ParseNextFrame(&fhdr, nullptr) != Vp9Parser::kOk) |
75 break; | 123 break; |
76 | 124 |
77 ++num_parsed_frames; | 125 ++num_parsed_frames; |
78 } | 126 } |
79 | 127 |
80 DVLOG(1) << "Number of successfully parsed frames before EOS: " | 128 DVLOG(1) << "Number of successfully parsed frames before EOS: " |
81 << num_parsed_frames; | 129 << num_parsed_frames; |
82 | 130 |
83 EXPECT_EQ(num_frames, num_parsed_frames); | 131 EXPECT_EQ(num_expected_frames, num_parsed_frames); |
132 } | |
133 | |
134 void DumpContext(const char* fmt, int idx, const Vp9FrameContext& context) { | |
Pawel Osciak
2016/08/05 10:09:39
Do we want to keep this?
kcwu
2016/08/05 11:38:48
Done.
| |
135 return; | |
136 char filename[1024]; | |
137 sprintf(filename, fmt, idx); | |
138 FILE* fp = fopen(filename, "wb"); | |
139 fwrite(&context, sizeof(context), 1, fp); | |
140 fclose(fp); | |
141 } | |
142 | |
143 TEST_F(Vp9ParserTest, StreamFileParsingWithCompressedHeader) { | |
144 Initialize("test-25fps.vp9", true); | |
145 | |
146 // Number of frames in the test stream to be parsed. | |
147 const int num_expected_frames = 269; | |
148 int num_parsed_frames = 0; | |
149 | |
150 // Allow to parse double frames in order to detect extra frames parsed. | |
151 while (num_parsed_frames < num_expected_frames * 2) { | |
152 Vp9FrameHeader fhdr; | |
153 Vp9FrameContextManager::ContextRefreshCallback context_refresh_cb; | |
154 if (ParseNextFrame(&fhdr, &context_refresh_cb) != Vp9Parser::kOk) | |
155 break; | |
156 | |
157 Vp9FrameContext frame_context; | |
158 ReadContext(&frame_context); | |
159 EXPECT_TRUE(memcmp(&frame_context, &fhdr.initial_frame_context, | |
160 sizeof(frame_context)) == 0); | |
161 DumpContext("test.%03d.initial", num_parsed_frames, frame_context); | |
162 ReadContext(&frame_context); | |
163 EXPECT_TRUE(memcmp(&frame_context, &fhdr.frame_context, | |
164 sizeof(frame_context)) == 0); | |
165 DumpContext("test.%03d.current", num_parsed_frames, frame_context); | |
166 | |
167 // test-25fps.vp9 doesn't need frame update from driver. | |
168 EXPECT_TRUE(context_refresh_cb.is_null()); | |
169 ASSERT_FALSE(ReadShouldContextUpdate()); | |
170 | |
171 ++num_parsed_frames; | |
172 } | |
173 | |
174 DVLOG(1) << "Number of successfully parsed frames before EOS: " | |
175 << num_parsed_frames; | |
176 | |
177 EXPECT_EQ(num_expected_frames, num_parsed_frames); | |
178 } | |
179 | |
180 TEST_F(Vp9ParserTest, StreamFileParsingWithContextUpdate) { | |
181 Initialize("bear-vp9.ivf", true); | |
182 | |
183 // Number of frames in the test stream to be parsed. | |
184 const int num_expected_frames = 82; | |
185 int num_parsed_frames = 0; | |
186 | |
187 // Allow to parse double frames in order to detect extra frames parsed. | |
188 while (num_parsed_frames < num_expected_frames * 2) { | |
189 Vp9FrameHeader fhdr; | |
190 Vp9FrameContextManager::ContextRefreshCallback context_refresh_cb; | |
191 if (ParseNextFrame(&fhdr, &context_refresh_cb) != Vp9Parser::kOk) | |
192 break; | |
193 | |
194 Vp9FrameContext frame_context; | |
195 ReadContext(&frame_context); | |
196 EXPECT_TRUE(memcmp(&frame_context, &fhdr.initial_frame_context, | |
197 sizeof(frame_context)) == 0); | |
198 DumpContext("bear.%03d.initial", num_parsed_frames, frame_context); | |
199 ReadContext(&frame_context); | |
200 EXPECT_TRUE(memcmp(&frame_context, &fhdr.frame_context, | |
201 sizeof(frame_context)) == 0); | |
202 DumpContext("bear.%03d.current", num_parsed_frames, frame_context); | |
203 | |
204 bool should_update = ReadShouldContextUpdate(); | |
205 if (context_refresh_cb.is_null()) { | |
206 EXPECT_FALSE(should_update); | |
207 } else { | |
208 EXPECT_TRUE(should_update); | |
209 ReadContext(&frame_context); | |
210 DumpContext("bear.%03d.update", num_parsed_frames, frame_context); | |
211 context_refresh_cb.Run(frame_context); | |
212 } | |
213 | |
214 ++num_parsed_frames; | |
215 } | |
216 | |
217 DVLOG(1) << "Number of successfully parsed frames before EOS: " | |
218 << num_parsed_frames; | |
219 | |
220 EXPECT_EQ(num_expected_frames, num_parsed_frames); | |
221 } | |
222 | |
223 TEST_F(Vp9ParserTest, AwaitingContextUpdate) { | |
224 Initialize("bear-vp9.ivf", true); | |
225 | |
226 Vp9FrameHeader fhdr; | |
227 Vp9FrameContextManager::ContextRefreshCallback context_refresh_cb; | |
228 ASSERT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr, &context_refresh_cb)); | |
229 EXPECT_FALSE(context_refresh_cb.is_null()); | |
230 | |
231 Vp9FrameContext frame_context; | |
232 ReadContext(&frame_context); | |
233 ReadContext(&frame_context); | |
234 bool should_update = ReadShouldContextUpdate(); | |
235 ASSERT_TRUE(should_update); | |
236 ReadContext(&frame_context); | |
237 | |
238 // Not update yet. Should return kAwaitingRefresh. | |
239 Vp9FrameContextManager::ContextRefreshCallback unused_cb; | |
240 EXPECT_EQ(Vp9Parser::kAwaitingRefresh, ParseNextFrame(&fhdr, &unused_cb)); | |
241 EXPECT_EQ(Vp9Parser::kAwaitingRefresh, ParseNextFrame(&fhdr, &unused_cb)); | |
242 | |
243 // After update, parse should be ok. | |
244 context_refresh_cb.Run(frame_context); | |
245 EXPECT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr, &unused_cb)); | |
246 | |
247 // Make sure it parsed the 2nd frame. | |
248 EXPECT_EQ(9u, fhdr.header_size_in_bytes); | |
84 } | 249 } |
85 | 250 |
86 TEST_F(Vp9ParserTest, VerifyFirstFrame) { | 251 TEST_F(Vp9ParserTest, VerifyFirstFrame) { |
252 Initialize("test-25fps.vp9", false); | |
87 Vp9FrameHeader fhdr; | 253 Vp9FrameHeader fhdr; |
88 | 254 |
89 ASSERT_TRUE(ParseNextFrame(&fhdr)); | 255 ASSERT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr, nullptr)); |
90 | 256 |
91 EXPECT_EQ(0, fhdr.profile); | 257 EXPECT_EQ(0, fhdr.profile); |
92 EXPECT_FALSE(fhdr.show_existing_frame); | 258 EXPECT_FALSE(fhdr.show_existing_frame); |
93 EXPECT_EQ(Vp9FrameHeader::KEYFRAME, fhdr.frame_type); | 259 EXPECT_EQ(Vp9FrameHeader::KEYFRAME, fhdr.frame_type); |
94 EXPECT_TRUE(fhdr.show_frame); | 260 EXPECT_TRUE(fhdr.show_frame); |
95 EXPECT_FALSE(fhdr.error_resilient_mode); | 261 EXPECT_FALSE(fhdr.error_resilient_mode); |
96 | 262 |
97 EXPECT_EQ(8, fhdr.bit_depth); | 263 EXPECT_EQ(8, fhdr.bit_depth); |
98 EXPECT_EQ(Vp9ColorSpace::UNKNOWN, fhdr.color_space); | 264 EXPECT_EQ(Vp9ColorSpace::UNKNOWN, fhdr.color_space); |
99 EXPECT_FALSE(fhdr.yuv_range); | 265 EXPECT_FALSE(fhdr.color_range); |
100 EXPECT_EQ(1, fhdr.subsampling_x); | 266 EXPECT_EQ(1, fhdr.subsampling_x); |
101 EXPECT_EQ(1, fhdr.subsampling_y); | 267 EXPECT_EQ(1, fhdr.subsampling_y); |
102 | 268 |
103 EXPECT_EQ(320u, fhdr.width); | 269 EXPECT_EQ(320u, fhdr.frame_width); |
104 EXPECT_EQ(240u, fhdr.height); | 270 EXPECT_EQ(240u, fhdr.frame_height); |
105 EXPECT_EQ(320u, fhdr.display_width); | 271 EXPECT_EQ(320u, fhdr.render_width); |
106 EXPECT_EQ(240u, fhdr.display_height); | 272 EXPECT_EQ(240u, fhdr.render_height); |
107 | 273 |
108 EXPECT_TRUE(fhdr.refresh_frame_context); | 274 EXPECT_TRUE(fhdr.refresh_frame_context); |
109 EXPECT_TRUE(fhdr.frame_parallel_decoding_mode); | 275 EXPECT_TRUE(fhdr.frame_parallel_decoding_mode); |
110 EXPECT_EQ(0, fhdr.frame_context_idx); | 276 EXPECT_EQ(0, fhdr.frame_context_idx_backup); |
111 | 277 |
112 const Vp9LoopFilter& lf = GetLoopFilter(); | 278 const Vp9LoopFilterParams& lf = GetLoopFilter(); |
113 EXPECT_EQ(9, lf.filter_level); | 279 EXPECT_EQ(9, lf.level); |
114 EXPECT_EQ(0, lf.sharpness_level); | 280 EXPECT_EQ(0, lf.sharpness); |
115 EXPECT_TRUE(lf.mode_ref_delta_enabled); | 281 EXPECT_TRUE(lf.delta_enabled); |
116 EXPECT_TRUE(lf.mode_ref_delta_update); | 282 EXPECT_TRUE(lf.delta_update); |
117 EXPECT_TRUE(lf.update_ref_deltas[0]); | 283 EXPECT_TRUE(lf.update_ref_deltas[0]); |
118 EXPECT_EQ(1, lf.ref_deltas[0]); | 284 EXPECT_EQ(1, lf.ref_deltas[0]); |
119 EXPECT_EQ(-1, lf.ref_deltas[2]); | 285 EXPECT_EQ(-1, lf.ref_deltas[2]); |
120 EXPECT_EQ(-1, lf.ref_deltas[3]); | 286 EXPECT_EQ(-1, lf.ref_deltas[3]); |
121 | 287 |
122 const Vp9QuantizationParams& qp = fhdr.quant_params; | 288 const Vp9QuantizationParams& qp = fhdr.quant_params; |
123 EXPECT_EQ(65, qp.base_qindex); | 289 EXPECT_EQ(65, qp.base_q_idx); |
124 EXPECT_FALSE(qp.y_dc_delta); | 290 EXPECT_FALSE(qp.delta_q_y_dc); |
125 EXPECT_FALSE(qp.uv_dc_delta); | 291 EXPECT_FALSE(qp.delta_q_uv_dc); |
126 EXPECT_FALSE(qp.uv_ac_delta); | 292 EXPECT_FALSE(qp.delta_q_uv_ac); |
127 EXPECT_FALSE(qp.IsLossless()); | 293 EXPECT_FALSE(qp.IsLossless()); |
128 | 294 |
129 const Vp9Segmentation& seg = GetSegmentation(); | 295 const Vp9SegmentationParams& seg = GetSegmentation(); |
130 EXPECT_FALSE(seg.enabled); | 296 EXPECT_FALSE(seg.enabled); |
131 | 297 |
132 EXPECT_EQ(0, fhdr.log2_tile_cols); | 298 EXPECT_EQ(0, fhdr.tile_cols_log2); |
133 EXPECT_EQ(0, fhdr.log2_tile_rows); | 299 EXPECT_EQ(0, fhdr.tile_rows_log2); |
134 | 300 |
135 EXPECT_EQ(120u, fhdr.first_partition_size); | 301 EXPECT_EQ(120u, fhdr.header_size_in_bytes); |
136 EXPECT_EQ(18u, fhdr.uncompressed_header_size); | 302 EXPECT_EQ(18u, fhdr.uncompressed_header_size); |
137 } | 303 } |
138 | 304 |
139 TEST_F(Vp9ParserTest, VerifyInterFrame) { | 305 TEST_F(Vp9ParserTest, VerifyInterFrame) { |
306 Initialize("test-25fps.vp9", false); | |
140 Vp9FrameHeader fhdr; | 307 Vp9FrameHeader fhdr; |
141 | 308 |
142 // To verify the second frame. | 309 // To verify the second frame. |
143 for (int i = 0; i < 2; i++) | 310 for (int i = 0; i < 2; i++) |
144 ASSERT_TRUE(ParseNextFrame(&fhdr)); | 311 ASSERT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr, nullptr)); |
145 | 312 |
146 EXPECT_EQ(Vp9FrameHeader::INTERFRAME, fhdr.frame_type); | 313 EXPECT_EQ(Vp9FrameHeader::INTERFRAME, fhdr.frame_type); |
147 EXPECT_FALSE(fhdr.show_frame); | 314 EXPECT_FALSE(fhdr.show_frame); |
148 EXPECT_FALSE(fhdr.intra_only); | 315 EXPECT_FALSE(fhdr.intra_only); |
149 EXPECT_FALSE(fhdr.reset_context); | 316 EXPECT_FALSE(fhdr.reset_frame_context); |
150 EXPECT_TRUE(fhdr.RefreshFlag(2)); | 317 EXPECT_TRUE(fhdr.RefreshFlag(2)); |
151 EXPECT_EQ(0, fhdr.frame_refs[0]); | 318 EXPECT_EQ(0, fhdr.ref_frame_idx[0]); |
152 EXPECT_EQ(1, fhdr.frame_refs[1]); | 319 EXPECT_EQ(1, fhdr.ref_frame_idx[1]); |
153 EXPECT_EQ(2, fhdr.frame_refs[2]); | 320 EXPECT_EQ(2, fhdr.ref_frame_idx[2]); |
154 EXPECT_TRUE(fhdr.allow_high_precision_mv); | 321 EXPECT_TRUE(fhdr.allow_high_precision_mv); |
155 EXPECT_EQ(Vp9InterpFilter::EIGHTTAP, fhdr.interp_filter); | 322 EXPECT_EQ(Vp9InterpolationFilter::EIGHTTAP, fhdr.interpolation_filter); |
156 | 323 |
157 EXPECT_EQ(48u, fhdr.first_partition_size); | 324 EXPECT_EQ(48u, fhdr.header_size_in_bytes); |
158 EXPECT_EQ(11u, fhdr.uncompressed_header_size); | 325 EXPECT_EQ(11u, fhdr.uncompressed_header_size); |
159 } | 326 } |
160 | 327 |
161 } // namespace media | 328 } // namespace media |
OLD | NEW |