Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(61)

Side by Side Diff: media/filters/vp9_parser_unittest.cc

Issue 2133993002: Parse VP9 compressed header (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: reset curr_frame_info_ when Reset Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/filters/vp9_parser_fuzzertest.cc ('k') | media/filters/vp9_raw_bits_reader.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 follows. For every
10 // frame, 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 should_update != 0;
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 twice as many frames in order to detect any extra frames
120 // parsed.
121 while (num_parsed_frames < num_expected_frames * 2) {
73 Vp9FrameHeader fhdr; 122 Vp9FrameHeader fhdr;
74 if (!ParseNextFrame(&fhdr)) 123 if (ParseNextFrame(&fhdr, nullptr) != Vp9Parser::kOk)
75 break; 124 break;
76 125
77 ++num_parsed_frames; 126 ++num_parsed_frames;
78 } 127 }
79 128
80 DVLOG(1) << "Number of successfully parsed frames before EOS: " 129 DVLOG(1) << "Number of successfully parsed frames before EOS: "
81 << num_parsed_frames; 130 << num_parsed_frames;
82 131
83 EXPECT_EQ(num_frames, num_parsed_frames); 132 EXPECT_EQ(num_expected_frames, num_parsed_frames);
133 }
134
135 TEST_F(Vp9ParserTest, StreamFileParsingWithCompressedHeader) {
136 Initialize("test-25fps.vp9", true);
137
138 // Number of frames in the test stream to be parsed.
139 const int num_expected_frames = 269;
140 int num_parsed_frames = 0;
141
142 // Allow to parse twice as many frames in order to detect any extra frames
143 // parsed.
144 while (num_parsed_frames < num_expected_frames * 2) {
145 Vp9FrameHeader fhdr;
146 Vp9FrameContextManager::ContextRefreshCallback context_refresh_cb;
147 if (ParseNextFrame(&fhdr, &context_refresh_cb) != Vp9Parser::kOk)
148 break;
149
150 Vp9FrameContext frame_context;
151 ReadContext(&frame_context);
152 EXPECT_TRUE(memcmp(&frame_context, &fhdr.initial_frame_context,
153 sizeof(frame_context)) == 0);
154 ReadContext(&frame_context);
155 EXPECT_TRUE(memcmp(&frame_context, &fhdr.frame_context,
156 sizeof(frame_context)) == 0);
157
158 // test-25fps.vp9 doesn't need frame update from driver.
159 EXPECT_TRUE(context_refresh_cb.is_null());
160 ASSERT_FALSE(ReadShouldContextUpdate());
161
162 ++num_parsed_frames;
163 }
164
165 DVLOG(1) << "Number of successfully parsed frames before EOS: "
166 << num_parsed_frames;
167
168 EXPECT_EQ(num_expected_frames, num_parsed_frames);
169 }
170
171 TEST_F(Vp9ParserTest, StreamFileParsingWithContextUpdate) {
172 Initialize("bear-vp9.ivf", true);
173
174 // Number of frames in the test stream to be parsed.
175 const int num_expected_frames = 82;
176 int num_parsed_frames = 0;
177
178 // Allow to parse twice as many frames in order to detect any extra frames
179 // parsed.
180 while (num_parsed_frames < num_expected_frames * 2) {
181 Vp9FrameHeader fhdr;
182 Vp9FrameContextManager::ContextRefreshCallback context_refresh_cb;
183 if (ParseNextFrame(&fhdr, &context_refresh_cb) != Vp9Parser::kOk)
184 break;
185
186 Vp9FrameContext frame_context;
187 ReadContext(&frame_context);
188 EXPECT_TRUE(memcmp(&frame_context, &fhdr.initial_frame_context,
189 sizeof(frame_context)) == 0);
190 ReadContext(&frame_context);
191 EXPECT_TRUE(memcmp(&frame_context, &fhdr.frame_context,
192 sizeof(frame_context)) == 0);
193
194 bool should_update = ReadShouldContextUpdate();
195 if (context_refresh_cb.is_null()) {
196 EXPECT_FALSE(should_update);
197 } else {
198 EXPECT_TRUE(should_update);
199 ReadContext(&frame_context);
200 context_refresh_cb.Run(frame_context);
201 }
202
203 ++num_parsed_frames;
204 }
205
206 DVLOG(1) << "Number of successfully parsed frames before EOS: "
207 << num_parsed_frames;
208
209 EXPECT_EQ(num_expected_frames, num_parsed_frames);
210 }
211
212 TEST_F(Vp9ParserTest, AwaitingContextUpdate) {
213 Initialize("bear-vp9.ivf", true);
214
215 Vp9FrameHeader fhdr;
216 Vp9FrameContextManager::ContextRefreshCallback context_refresh_cb;
217 ASSERT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr, &context_refresh_cb));
218 EXPECT_FALSE(context_refresh_cb.is_null());
219
220 Vp9FrameContext frame_context;
221 ReadContext(&frame_context);
222 ReadContext(&frame_context);
223 bool should_update = ReadShouldContextUpdate();
224 ASSERT_TRUE(should_update);
225 ReadContext(&frame_context);
226
227 // Not update yet. Should return kAwaitingRefresh.
228 Vp9FrameContextManager::ContextRefreshCallback unused_cb;
229 EXPECT_EQ(Vp9Parser::kAwaitingRefresh, ParseNextFrame(&fhdr, &unused_cb));
230 EXPECT_EQ(Vp9Parser::kAwaitingRefresh, ParseNextFrame(&fhdr, &unused_cb));
231
232 // After update, parse should be ok.
233 context_refresh_cb.Run(frame_context);
234 EXPECT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr, &unused_cb));
235
236 // Make sure it parsed the 2nd frame.
237 EXPECT_EQ(9u, fhdr.header_size_in_bytes);
84 } 238 }
85 239
86 TEST_F(Vp9ParserTest, VerifyFirstFrame) { 240 TEST_F(Vp9ParserTest, VerifyFirstFrame) {
241 Initialize("test-25fps.vp9", false);
87 Vp9FrameHeader fhdr; 242 Vp9FrameHeader fhdr;
88 243
89 ASSERT_TRUE(ParseNextFrame(&fhdr)); 244 ASSERT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr, nullptr));
90 245
91 EXPECT_EQ(0, fhdr.profile); 246 EXPECT_EQ(0, fhdr.profile);
92 EXPECT_FALSE(fhdr.show_existing_frame); 247 EXPECT_FALSE(fhdr.show_existing_frame);
93 EXPECT_EQ(Vp9FrameHeader::KEYFRAME, fhdr.frame_type); 248 EXPECT_EQ(Vp9FrameHeader::KEYFRAME, fhdr.frame_type);
94 EXPECT_TRUE(fhdr.show_frame); 249 EXPECT_TRUE(fhdr.show_frame);
95 EXPECT_FALSE(fhdr.error_resilient_mode); 250 EXPECT_FALSE(fhdr.error_resilient_mode);
96 251
97 EXPECT_EQ(8, fhdr.bit_depth); 252 EXPECT_EQ(8, fhdr.bit_depth);
98 EXPECT_EQ(Vp9ColorSpace::UNKNOWN, fhdr.color_space); 253 EXPECT_EQ(Vp9ColorSpace::UNKNOWN, fhdr.color_space);
99 EXPECT_FALSE(fhdr.yuv_range); 254 EXPECT_FALSE(fhdr.color_range);
100 EXPECT_EQ(1, fhdr.subsampling_x); 255 EXPECT_EQ(1, fhdr.subsampling_x);
101 EXPECT_EQ(1, fhdr.subsampling_y); 256 EXPECT_EQ(1, fhdr.subsampling_y);
102 257
103 EXPECT_EQ(320u, fhdr.width); 258 EXPECT_EQ(320u, fhdr.frame_width);
104 EXPECT_EQ(240u, fhdr.height); 259 EXPECT_EQ(240u, fhdr.frame_height);
105 EXPECT_EQ(320u, fhdr.display_width); 260 EXPECT_EQ(320u, fhdr.render_width);
106 EXPECT_EQ(240u, fhdr.display_height); 261 EXPECT_EQ(240u, fhdr.render_height);
107 262
108 EXPECT_TRUE(fhdr.refresh_frame_context); 263 EXPECT_TRUE(fhdr.refresh_frame_context);
109 EXPECT_TRUE(fhdr.frame_parallel_decoding_mode); 264 EXPECT_TRUE(fhdr.frame_parallel_decoding_mode);
110 EXPECT_EQ(0, fhdr.frame_context_idx); 265 EXPECT_EQ(0, fhdr.frame_context_idx_to_save_probs);
111 266
112 const Vp9LoopFilter& lf = GetLoopFilter(); 267 const Vp9LoopFilterParams& lf = GetLoopFilter();
113 EXPECT_EQ(9, lf.filter_level); 268 EXPECT_EQ(9, lf.level);
114 EXPECT_EQ(0, lf.sharpness_level); 269 EXPECT_EQ(0, lf.sharpness);
115 EXPECT_TRUE(lf.mode_ref_delta_enabled); 270 EXPECT_TRUE(lf.delta_enabled);
116 EXPECT_TRUE(lf.mode_ref_delta_update); 271 EXPECT_TRUE(lf.delta_update);
117 EXPECT_TRUE(lf.update_ref_deltas[0]); 272 EXPECT_TRUE(lf.update_ref_deltas[0]);
118 EXPECT_EQ(1, lf.ref_deltas[0]); 273 EXPECT_EQ(1, lf.ref_deltas[0]);
119 EXPECT_EQ(-1, lf.ref_deltas[2]); 274 EXPECT_EQ(-1, lf.ref_deltas[2]);
120 EXPECT_EQ(-1, lf.ref_deltas[3]); 275 EXPECT_EQ(-1, lf.ref_deltas[3]);
121 276
122 const Vp9QuantizationParams& qp = fhdr.quant_params; 277 const Vp9QuantizationParams& qp = fhdr.quant_params;
123 EXPECT_EQ(65, qp.base_qindex); 278 EXPECT_EQ(65, qp.base_q_idx);
124 EXPECT_FALSE(qp.y_dc_delta); 279 EXPECT_FALSE(qp.delta_q_y_dc);
125 EXPECT_FALSE(qp.uv_dc_delta); 280 EXPECT_FALSE(qp.delta_q_uv_dc);
126 EXPECT_FALSE(qp.uv_ac_delta); 281 EXPECT_FALSE(qp.delta_q_uv_ac);
127 EXPECT_FALSE(qp.IsLossless()); 282 EXPECT_FALSE(qp.IsLossless());
128 283
129 const Vp9Segmentation& seg = GetSegmentation(); 284 const Vp9SegmentationParams& seg = GetSegmentation();
130 EXPECT_FALSE(seg.enabled); 285 EXPECT_FALSE(seg.enabled);
131 286
132 EXPECT_EQ(0, fhdr.log2_tile_cols); 287 EXPECT_EQ(0, fhdr.tile_cols_log2);
133 EXPECT_EQ(0, fhdr.log2_tile_rows); 288 EXPECT_EQ(0, fhdr.tile_rows_log2);
134 289
135 EXPECT_EQ(120u, fhdr.first_partition_size); 290 EXPECT_EQ(120u, fhdr.header_size_in_bytes);
136 EXPECT_EQ(18u, fhdr.uncompressed_header_size); 291 EXPECT_EQ(18u, fhdr.uncompressed_header_size);
137 } 292 }
138 293
139 TEST_F(Vp9ParserTest, VerifyInterFrame) { 294 TEST_F(Vp9ParserTest, VerifyInterFrame) {
295 Initialize("test-25fps.vp9", false);
140 Vp9FrameHeader fhdr; 296 Vp9FrameHeader fhdr;
141 297
142 // To verify the second frame. 298 // To verify the second frame.
143 for (int i = 0; i < 2; i++) 299 for (int i = 0; i < 2; i++)
144 ASSERT_TRUE(ParseNextFrame(&fhdr)); 300 ASSERT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr, nullptr));
145 301
146 EXPECT_EQ(Vp9FrameHeader::INTERFRAME, fhdr.frame_type); 302 EXPECT_EQ(Vp9FrameHeader::INTERFRAME, fhdr.frame_type);
147 EXPECT_FALSE(fhdr.show_frame); 303 EXPECT_FALSE(fhdr.show_frame);
148 EXPECT_FALSE(fhdr.intra_only); 304 EXPECT_FALSE(fhdr.intra_only);
149 EXPECT_FALSE(fhdr.reset_context); 305 EXPECT_FALSE(fhdr.reset_frame_context);
150 EXPECT_TRUE(fhdr.RefreshFlag(2)); 306 EXPECT_TRUE(fhdr.RefreshFlag(2));
151 EXPECT_EQ(0, fhdr.frame_refs[0]); 307 EXPECT_EQ(0, fhdr.ref_frame_idx[0]);
152 EXPECT_EQ(1, fhdr.frame_refs[1]); 308 EXPECT_EQ(1, fhdr.ref_frame_idx[1]);
153 EXPECT_EQ(2, fhdr.frame_refs[2]); 309 EXPECT_EQ(2, fhdr.ref_frame_idx[2]);
154 EXPECT_TRUE(fhdr.allow_high_precision_mv); 310 EXPECT_TRUE(fhdr.allow_high_precision_mv);
155 EXPECT_EQ(Vp9InterpFilter::EIGHTTAP, fhdr.interp_filter); 311 EXPECT_EQ(Vp9InterpolationFilter::EIGHTTAP, fhdr.interpolation_filter);
156 312
157 EXPECT_EQ(48u, fhdr.first_partition_size); 313 EXPECT_EQ(48u, fhdr.header_size_in_bytes);
158 EXPECT_EQ(11u, fhdr.uncompressed_header_size); 314 EXPECT_EQ(11u, fhdr.uncompressed_header_size);
159 } 315 }
160 316
161 } // namespace media 317 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/vp9_parser_fuzzertest.cc ('k') | media/filters/vp9_raw_bits_reader.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698