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

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

Issue 2229353002: V4L2SVDA: Add a VP9Accelerator implementation utilizing the V4L2 VP9 frame API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: compilation fixes Created 4 years, 3 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_uncompressed_header_parser.cc » ('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 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 6 // of frame entropy, named $filename.context. These values are dumped from
7 // libvpx. 7 // libvpx.
8 // 8 //
9 // The syntax of these context dump is described as follows. For every 9 // The syntax of these context dump is described as follows. For every
10 // frame, there are corresponding data in context file, 10 // frame, there are corresponding data in context file,
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 return should_update != 0; 62 return should_update != 0;
63 } 63 }
64 64
65 void ReadContext(Vp9FrameContext* frame_context) { 65 void ReadContext(Vp9FrameContext* frame_context) {
66 ASSERT_EQ( 66 ASSERT_EQ(
67 static_cast<int>(sizeof(*frame_context)), 67 static_cast<int>(sizeof(*frame_context)),
68 context_file_.ReadAtCurrentPos(reinterpret_cast<char*>(frame_context), 68 context_file_.ReadAtCurrentPos(reinterpret_cast<char*>(frame_context),
69 sizeof(*frame_context))); 69 sizeof(*frame_context)));
70 } 70 }
71 71
72 Vp9Parser::Result ParseNextFrame( 72 Vp9Parser::Result ParseNextFrame(struct Vp9FrameHeader* frame_hdr);
73 struct Vp9FrameHeader* frame_hdr,
74 Vp9FrameContextManager::ContextRefreshCallback* context_refresh_cb);
75 73
76 const Vp9SegmentationParams& GetSegmentation() const { 74 const Vp9SegmentationParams& GetSegmentation() const {
77 return vp9_parser_->GetSegmentation(); 75 return vp9_parser_->context().segmentation();
78 } 76 }
79 77
80 const Vp9LoopFilterParams& GetLoopFilter() const { 78 const Vp9LoopFilterParams& GetLoopFilter() const {
81 return vp9_parser_->GetLoopFilter(); 79 return vp9_parser_->context().loop_filter();
80 }
81
82 Vp9Parser::ContextRefreshCallback GetContextRefreshCb(
83 const Vp9FrameHeader& frame_hdr) const {
84 return vp9_parser_->GetContextRefreshCb(frame_hdr.frame_context_idx);
82 } 85 }
83 86
84 IvfParser ivf_parser_; 87 IvfParser ivf_parser_;
85 std::unique_ptr<base::MemoryMappedFile> stream_; 88 std::unique_ptr<base::MemoryMappedFile> stream_;
86 89
87 std::unique_ptr<Vp9Parser> vp9_parser_; 90 std::unique_ptr<Vp9Parser> vp9_parser_;
88 base::File context_file_; 91 base::File context_file_;
89 }; 92 };
90 93
91 Vp9Parser::Result Vp9ParserTest::ParseNextFrame( 94 Vp9Parser::Result Vp9ParserTest::ParseNextFrame(Vp9FrameHeader* fhdr) {
92 Vp9FrameHeader* fhdr,
93 Vp9FrameContextManager::ContextRefreshCallback* context_refresh_cb) {
94 while (1) { 95 while (1) {
95 Vp9Parser::Result res = 96 Vp9Parser::Result res = vp9_parser_->ParseNextFrame(fhdr);
96 vp9_parser_->ParseNextFrame(fhdr, context_refresh_cb);
97 if (res == Vp9Parser::kEOStream) { 97 if (res == Vp9Parser::kEOStream) {
98 IvfFrameHeader ivf_frame_header; 98 IvfFrameHeader ivf_frame_header;
99 const uint8_t* ivf_payload; 99 const uint8_t* ivf_payload;
100 100
101 if (!ivf_parser_.ParseNextFrame(&ivf_frame_header, &ivf_payload)) 101 if (!ivf_parser_.ParseNextFrame(&ivf_frame_header, &ivf_payload))
102 return Vp9Parser::kEOStream; 102 return Vp9Parser::kEOStream;
103 103
104 vp9_parser_->SetStream(ivf_payload, ivf_frame_header.frame_size); 104 vp9_parser_->SetStream(ivf_payload, ivf_frame_header.frame_size);
105 continue; 105 continue;
106 } 106 }
107 107
108 return res; 108 return res;
109 } 109 }
110 } 110 }
111 111
112 TEST_F(Vp9ParserTest, StreamFileParsingWithoutCompressedHeader) { 112 TEST_F(Vp9ParserTest, StreamFileParsingWithoutCompressedHeader) {
113 Initialize("test-25fps.vp9", false); 113 Initialize("test-25fps.vp9", false);
114 114
115 // Number of frames in the test stream to be parsed. 115 // Number of frames in the test stream to be parsed.
116 const int num_expected_frames = 269; 116 const int num_expected_frames = 269;
117 int num_parsed_frames = 0; 117 int num_parsed_frames = 0;
118 118
119 // Allow to parse twice as many frames in order to detect any extra frames 119 // Allow to parse twice as many frames in order to detect any extra frames
120 // parsed. 120 // parsed.
121 while (num_parsed_frames < num_expected_frames * 2) { 121 while (num_parsed_frames < num_expected_frames * 2) {
122 Vp9FrameHeader fhdr; 122 Vp9FrameHeader fhdr;
123 if (ParseNextFrame(&fhdr, nullptr) != Vp9Parser::kOk) 123 if (ParseNextFrame(&fhdr) != Vp9Parser::kOk)
124 break; 124 break;
125 125
126 ++num_parsed_frames; 126 ++num_parsed_frames;
127 } 127 }
128 128
129 DVLOG(1) << "Number of successfully parsed frames before EOS: " 129 DVLOG(1) << "Number of successfully parsed frames before EOS: "
130 << num_parsed_frames; 130 << num_parsed_frames;
131 131
132 EXPECT_EQ(num_expected_frames, num_parsed_frames); 132 EXPECT_EQ(num_expected_frames, num_parsed_frames);
133 } 133 }
134 134
135 TEST_F(Vp9ParserTest, StreamFileParsingWithCompressedHeader) { 135 TEST_F(Vp9ParserTest, StreamFileParsingWithCompressedHeader) {
136 Initialize("test-25fps.vp9", true); 136 Initialize("test-25fps.vp9", true);
137 137
138 // Number of frames in the test stream to be parsed. 138 // Number of frames in the test stream to be parsed.
139 const int num_expected_frames = 269; 139 const int num_expected_frames = 269;
140 int num_parsed_frames = 0; 140 int num_parsed_frames = 0;
141 141
142 // Allow to parse twice as many frames in order to detect any extra frames 142 // Allow to parse twice as many frames in order to detect any extra frames
143 // parsed. 143 // parsed.
144 while (num_parsed_frames < num_expected_frames * 2) { 144 while (num_parsed_frames < num_expected_frames * 2) {
145 Vp9FrameHeader fhdr; 145 Vp9FrameHeader fhdr;
146 Vp9FrameContextManager::ContextRefreshCallback context_refresh_cb; 146 if (ParseNextFrame(&fhdr) != Vp9Parser::kOk)
147 if (ParseNextFrame(&fhdr, &context_refresh_cb) != Vp9Parser::kOk)
148 break; 147 break;
149 148
150 Vp9FrameContext frame_context; 149 Vp9FrameContext frame_context;
151 ReadContext(&frame_context); 150 ReadContext(&frame_context);
152 EXPECT_TRUE(memcmp(&frame_context, &fhdr.initial_frame_context, 151 EXPECT_TRUE(memcmp(&frame_context, &fhdr.initial_frame_context,
153 sizeof(frame_context)) == 0); 152 sizeof(frame_context)) == 0);
154 ReadContext(&frame_context); 153 ReadContext(&frame_context);
155 EXPECT_TRUE(memcmp(&frame_context, &fhdr.frame_context, 154 EXPECT_TRUE(memcmp(&frame_context, &fhdr.frame_context,
156 sizeof(frame_context)) == 0); 155 sizeof(frame_context)) == 0);
157 156
158 // test-25fps.vp9 doesn't need frame update from driver. 157 // test-25fps.vp9 doesn't need frame update from driver.
158 auto context_refresh_cb = GetContextRefreshCb(fhdr);
159 EXPECT_TRUE(context_refresh_cb.is_null()); 159 EXPECT_TRUE(context_refresh_cb.is_null());
160 ASSERT_FALSE(ReadShouldContextUpdate()); 160 ASSERT_FALSE(ReadShouldContextUpdate());
161 161
162 ++num_parsed_frames; 162 ++num_parsed_frames;
163 } 163 }
164 164
165 DVLOG(1) << "Number of successfully parsed frames before EOS: " 165 DVLOG(1) << "Number of successfully parsed frames before EOS: "
166 << num_parsed_frames; 166 << num_parsed_frames;
167 167
168 EXPECT_EQ(num_expected_frames, num_parsed_frames); 168 EXPECT_EQ(num_expected_frames, num_parsed_frames);
169 } 169 }
170 170
171 TEST_F(Vp9ParserTest, StreamFileParsingWithContextUpdate) { 171 TEST_F(Vp9ParserTest, StreamFileParsingWithContextUpdate) {
172 Initialize("bear-vp9.ivf", true); 172 Initialize("bear-vp9.ivf", true);
173 173
174 // Number of frames in the test stream to be parsed. 174 // Number of frames in the test stream to be parsed.
175 const int num_expected_frames = 82; 175 const int num_expected_frames = 82;
176 int num_parsed_frames = 0; 176 int num_parsed_frames = 0;
177 177
178 // Allow to parse twice as many frames in order to detect any extra frames 178 // Allow to parse twice as many frames in order to detect any extra frames
179 // parsed. 179 // parsed.
180 while (num_parsed_frames < num_expected_frames * 2) { 180 while (num_parsed_frames < num_expected_frames * 2) {
181 Vp9FrameHeader fhdr; 181 Vp9FrameHeader fhdr;
182 Vp9FrameContextManager::ContextRefreshCallback context_refresh_cb; 182 if (ParseNextFrame(&fhdr) != Vp9Parser::kOk)
183 if (ParseNextFrame(&fhdr, &context_refresh_cb) != Vp9Parser::kOk)
184 break; 183 break;
185 184
186 Vp9FrameContext frame_context; 185 Vp9FrameContext frame_context;
187 ReadContext(&frame_context); 186 ReadContext(&frame_context);
188 EXPECT_TRUE(memcmp(&frame_context, &fhdr.initial_frame_context, 187 EXPECT_TRUE(memcmp(&frame_context, &fhdr.initial_frame_context,
189 sizeof(frame_context)) == 0); 188 sizeof(frame_context)) == 0);
190 ReadContext(&frame_context); 189 ReadContext(&frame_context);
191 EXPECT_TRUE(memcmp(&frame_context, &fhdr.frame_context, 190 EXPECT_TRUE(memcmp(&frame_context, &fhdr.frame_context,
192 sizeof(frame_context)) == 0); 191 sizeof(frame_context)) == 0);
193 192
194 bool should_update = ReadShouldContextUpdate(); 193 bool should_update = ReadShouldContextUpdate();
194 auto context_refresh_cb = GetContextRefreshCb(fhdr);
195 if (context_refresh_cb.is_null()) { 195 if (context_refresh_cb.is_null()) {
196 EXPECT_FALSE(should_update); 196 EXPECT_FALSE(should_update);
197 } else { 197 } else {
198 EXPECT_TRUE(should_update); 198 EXPECT_TRUE(should_update);
199 ReadContext(&frame_context); 199 ReadContext(&frame_context);
200 context_refresh_cb.Run(frame_context); 200 context_refresh_cb.Run(frame_context);
201 } 201 }
202 202
203 ++num_parsed_frames; 203 ++num_parsed_frames;
204 } 204 }
205 205
206 DVLOG(1) << "Number of successfully parsed frames before EOS: " 206 DVLOG(1) << "Number of successfully parsed frames before EOS: "
207 << num_parsed_frames; 207 << num_parsed_frames;
208 208
209 EXPECT_EQ(num_expected_frames, num_parsed_frames); 209 EXPECT_EQ(num_expected_frames, num_parsed_frames);
210 } 210 }
211 211
212 TEST_F(Vp9ParserTest, AwaitingContextUpdate) { 212 TEST_F(Vp9ParserTest, AwaitingContextUpdate) {
213 Initialize("bear-vp9.ivf", true); 213 Initialize("bear-vp9.ivf", true);
214 214
215 Vp9FrameHeader fhdr; 215 Vp9FrameHeader fhdr;
216 Vp9FrameContextManager::ContextRefreshCallback context_refresh_cb; 216 ASSERT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr));
217 ASSERT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr, &context_refresh_cb));
218 EXPECT_FALSE(context_refresh_cb.is_null());
219 217
220 Vp9FrameContext frame_context; 218 Vp9FrameContext frame_context;
221 ReadContext(&frame_context); 219 ReadContext(&frame_context);
222 ReadContext(&frame_context); 220 ReadContext(&frame_context);
223 bool should_update = ReadShouldContextUpdate(); 221 bool should_update = ReadShouldContextUpdate();
224 ASSERT_TRUE(should_update); 222 ASSERT_TRUE(should_update);
225 ReadContext(&frame_context); 223 ReadContext(&frame_context);
226 224
227 // Not update yet. Should return kAwaitingRefresh. 225 // Not update yet. Should return kAwaitingRefresh.
228 Vp9FrameContextManager::ContextRefreshCallback unused_cb; 226 EXPECT_EQ(Vp9Parser::kAwaitingRefresh, ParseNextFrame(&fhdr));
229 EXPECT_EQ(Vp9Parser::kAwaitingRefresh, ParseNextFrame(&fhdr, &unused_cb)); 227 EXPECT_EQ(Vp9Parser::kAwaitingRefresh, ParseNextFrame(&fhdr));
230 EXPECT_EQ(Vp9Parser::kAwaitingRefresh, ParseNextFrame(&fhdr, &unused_cb));
231 228
232 // After update, parse should be ok. 229 // After update, parse should be ok.
230 auto context_refresh_cb = GetContextRefreshCb(fhdr);
231 EXPECT_FALSE(context_refresh_cb.is_null());
233 context_refresh_cb.Run(frame_context); 232 context_refresh_cb.Run(frame_context);
234 EXPECT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr, &unused_cb)); 233 EXPECT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr));
235 234
236 // Make sure it parsed the 2nd frame. 235 // Make sure it parsed the 2nd frame.
237 EXPECT_EQ(9u, fhdr.header_size_in_bytes); 236 EXPECT_EQ(9u, fhdr.header_size_in_bytes);
238 } 237 }
239 238
240 TEST_F(Vp9ParserTest, VerifyFirstFrame) { 239 TEST_F(Vp9ParserTest, VerifyFirstFrame) {
241 Initialize("test-25fps.vp9", false); 240 Initialize("test-25fps.vp9", false);
242 Vp9FrameHeader fhdr; 241 Vp9FrameHeader fhdr;
243 242
244 ASSERT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr, nullptr)); 243 ASSERT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr));
245 244
246 EXPECT_EQ(0, fhdr.profile); 245 EXPECT_EQ(0, fhdr.profile);
247 EXPECT_FALSE(fhdr.show_existing_frame); 246 EXPECT_FALSE(fhdr.show_existing_frame);
248 EXPECT_EQ(Vp9FrameHeader::KEYFRAME, fhdr.frame_type); 247 EXPECT_EQ(Vp9FrameHeader::KEYFRAME, fhdr.frame_type);
249 EXPECT_TRUE(fhdr.show_frame); 248 EXPECT_TRUE(fhdr.show_frame);
250 EXPECT_FALSE(fhdr.error_resilient_mode); 249 EXPECT_FALSE(fhdr.error_resilient_mode);
251 250
252 EXPECT_EQ(8, fhdr.bit_depth); 251 EXPECT_EQ(8, fhdr.bit_depth);
253 EXPECT_EQ(Vp9ColorSpace::UNKNOWN, fhdr.color_space); 252 EXPECT_EQ(Vp9ColorSpace::UNKNOWN, fhdr.color_space);
254 EXPECT_FALSE(fhdr.color_range); 253 EXPECT_FALSE(fhdr.color_range);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 EXPECT_EQ(120u, fhdr.header_size_in_bytes); 289 EXPECT_EQ(120u, fhdr.header_size_in_bytes);
291 EXPECT_EQ(18u, fhdr.uncompressed_header_size); 290 EXPECT_EQ(18u, fhdr.uncompressed_header_size);
292 } 291 }
293 292
294 TEST_F(Vp9ParserTest, VerifyInterFrame) { 293 TEST_F(Vp9ParserTest, VerifyInterFrame) {
295 Initialize("test-25fps.vp9", false); 294 Initialize("test-25fps.vp9", false);
296 Vp9FrameHeader fhdr; 295 Vp9FrameHeader fhdr;
297 296
298 // To verify the second frame. 297 // To verify the second frame.
299 for (int i = 0; i < 2; i++) 298 for (int i = 0; i < 2; i++)
300 ASSERT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr, nullptr)); 299 ASSERT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr));
301 300
302 EXPECT_EQ(Vp9FrameHeader::INTERFRAME, fhdr.frame_type); 301 EXPECT_EQ(Vp9FrameHeader::INTERFRAME, fhdr.frame_type);
303 EXPECT_FALSE(fhdr.show_frame); 302 EXPECT_FALSE(fhdr.show_frame);
304 EXPECT_FALSE(fhdr.intra_only); 303 EXPECT_FALSE(fhdr.intra_only);
305 EXPECT_FALSE(fhdr.reset_frame_context); 304 EXPECT_FALSE(fhdr.reset_frame_context);
306 EXPECT_TRUE(fhdr.RefreshFlag(2)); 305 EXPECT_TRUE(fhdr.RefreshFlag(2));
307 EXPECT_EQ(0, fhdr.ref_frame_idx[0]); 306 EXPECT_EQ(0, fhdr.ref_frame_idx[0]);
308 EXPECT_EQ(1, fhdr.ref_frame_idx[1]); 307 EXPECT_EQ(1, fhdr.ref_frame_idx[1]);
309 EXPECT_EQ(2, fhdr.ref_frame_idx[2]); 308 EXPECT_EQ(2, fhdr.ref_frame_idx[2]);
310 EXPECT_TRUE(fhdr.allow_high_precision_mv); 309 EXPECT_TRUE(fhdr.allow_high_precision_mv);
311 EXPECT_EQ(Vp9InterpolationFilter::EIGHTTAP, fhdr.interpolation_filter); 310 EXPECT_EQ(Vp9InterpolationFilter::EIGHTTAP, fhdr.interpolation_filter);
312 311
313 EXPECT_EQ(48u, fhdr.header_size_in_bytes); 312 EXPECT_EQ(48u, fhdr.header_size_in_bytes);
314 EXPECT_EQ(11u, fhdr.uncompressed_header_size); 313 EXPECT_EQ(11u, fhdr.uncompressed_header_size);
315 } 314 }
316 315
317 } // namespace media 316 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/vp9_parser_fuzzertest.cc ('k') | media/filters/vp9_uncompressed_header_parser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698