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

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: Implement VP9 compressed header parsing 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
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 following. For every
Pawel Osciak 2016/08/04 10:20:20 s/following/follows/
kcwu 2016/08/05 11:38:48 Done.
10 // frames, there are corresponding data in context file,
Pawel Osciak 2016/08/04 10:20:20 s/frames/frame/
kcwu 2016/08/05 11:38:48 Done.
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);
Pawel Osciak 2016/08/04 10:20:20 return should_update == 1?
kcwu 2016/08/05 11:38:48 Done.
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 bool 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 bool 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 false;
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 == Vp9Parser::kOk;
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.
Pawel Osciak 2016/08/04 10:20:20 s/double/twice as many/ s/extra/any extra/
kcwu 2016/08/05 11:38:48 Done.
120 while (num_parsed_frames < num_expected_frames * 2) {
73 Vp9FrameHeader fhdr; 121 Vp9FrameHeader fhdr;
74 if (!ParseNextFrame(&fhdr)) 122 if (!ParseNextFrame(&fhdr, nullptr))
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 TEST_F(Vp9ParserTest, StreamFileParsingWithCompressedHeader) {
135 Initialize("test-25fps.vp9", true);
136
137 // Number of frames in the test stream to be parsed.
138 const int num_expected_frames = 269;
139 int num_parsed_frames = 0;
140
141 // Allow to parse double frames in order to detect extra frames parsed.
142 while (num_parsed_frames < num_expected_frames * 2) {
143 Vp9FrameHeader fhdr;
144 Vp9FrameContextManager::ContextRefreshCallback context_refresh_cb;
145 if (!ParseNextFrame(&fhdr, &context_refresh_cb))
146 break;
147
148 Vp9FrameContext frame_context;
149 ReadContext(&frame_context);
150 EXPECT_TRUE(memcmp(&frame_context, &fhdr.initial_frame_context,
151 sizeof(frame_context)) == 0);
152 ReadContext(&frame_context);
153 EXPECT_TRUE(memcmp(&frame_context, &fhdr.frame_context,
154 sizeof(frame_context)) == 0);
155
156 // test-25fps.vp9 doesn't need frame update from driver.
157 EXPECT_TRUE(context_refresh_cb.is_null());
158 ASSERT_FALSE(ReadShouldContextUpdate());
159
160 ++num_parsed_frames;
161 }
162
163 DVLOG(1) << "Number of successfully parsed frames before EOS: "
164 << num_parsed_frames;
165
166 EXPECT_EQ(num_expected_frames, num_parsed_frames);
167 }
168
169 TEST_F(Vp9ParserTest, StreamFileParsingWithContextUpdate) {
170 Initialize("bear-vp9.ivf", true);
171
172 // Number of frames in the test stream to be parsed.
173 const int num_expected_frames = 82;
174 int num_parsed_frames = 0;
175
176 // Allow to parse double frames in order to detect extra frames parsed.
177 while (num_parsed_frames < num_expected_frames * 2) {
178 Vp9FrameHeader fhdr;
179 Vp9FrameContextManager::ContextRefreshCallback context_refresh_cb;
180 if (!ParseNextFrame(&fhdr, &context_refresh_cb))
181 break;
182
183 Vp9FrameContext frame_context;
184 ReadContext(&frame_context);
185 EXPECT_TRUE(memcmp(&frame_context, &fhdr.initial_frame_context,
186 sizeof(frame_context)) == 0);
187 ReadContext(&frame_context);
188 EXPECT_TRUE(memcmp(&frame_context, &fhdr.frame_context,
189 sizeof(frame_context)) == 0);
190
191 int should_update = ReadShouldContextUpdate();
192 if (context_refresh_cb.is_null()) {
193 EXPECT_FALSE(should_update);
194 } else {
195 EXPECT_TRUE(should_update);
196 ReadContext(&frame_context);
197 context_refresh_cb.Run(frame_context);
198 }
199
200 ++num_parsed_frames;
201 }
202
203 DVLOG(1) << "Number of successfully parsed frames before EOS: "
204 << num_parsed_frames;
205
206 EXPECT_EQ(num_expected_frames, num_parsed_frames);
84 } 207 }
85 208
86 TEST_F(Vp9ParserTest, VerifyFirstFrame) { 209 TEST_F(Vp9ParserTest, VerifyFirstFrame) {
210 Initialize("test-25fps.vp9", false);
87 Vp9FrameHeader fhdr; 211 Vp9FrameHeader fhdr;
88 212
89 ASSERT_TRUE(ParseNextFrame(&fhdr)); 213 ASSERT_TRUE(ParseNextFrame(&fhdr, nullptr));
90 214
91 EXPECT_EQ(0, fhdr.profile); 215 EXPECT_EQ(0, fhdr.profile);
92 EXPECT_FALSE(fhdr.show_existing_frame); 216 EXPECT_FALSE(fhdr.show_existing_frame);
93 EXPECT_EQ(Vp9FrameHeader::KEYFRAME, fhdr.frame_type); 217 EXPECT_EQ(Vp9FrameHeader::KEYFRAME, fhdr.frame_type);
94 EXPECT_TRUE(fhdr.show_frame); 218 EXPECT_TRUE(fhdr.show_frame);
95 EXPECT_FALSE(fhdr.error_resilient_mode); 219 EXPECT_FALSE(fhdr.error_resilient_mode);
96 220
97 EXPECT_EQ(8, fhdr.bit_depth); 221 EXPECT_EQ(8, fhdr.bit_depth);
98 EXPECT_EQ(Vp9ColorSpace::UNKNOWN, fhdr.color_space); 222 EXPECT_EQ(Vp9ColorSpace::UNKNOWN, fhdr.color_space);
99 EXPECT_FALSE(fhdr.yuv_range); 223 EXPECT_FALSE(fhdr.color_range);
100 EXPECT_EQ(1, fhdr.subsampling_x); 224 EXPECT_EQ(1, fhdr.subsampling_x);
101 EXPECT_EQ(1, fhdr.subsampling_y); 225 EXPECT_EQ(1, fhdr.subsampling_y);
102 226
103 EXPECT_EQ(320u, fhdr.width); 227 EXPECT_EQ(320u, fhdr.frame_width);
104 EXPECT_EQ(240u, fhdr.height); 228 EXPECT_EQ(240u, fhdr.frame_height);
105 EXPECT_EQ(320u, fhdr.display_width); 229 EXPECT_EQ(320u, fhdr.render_width);
106 EXPECT_EQ(240u, fhdr.display_height); 230 EXPECT_EQ(240u, fhdr.render_height);
107 231
108 EXPECT_TRUE(fhdr.refresh_frame_context); 232 EXPECT_TRUE(fhdr.refresh_frame_context);
109 EXPECT_TRUE(fhdr.frame_parallel_decoding_mode); 233 EXPECT_TRUE(fhdr.frame_parallel_decoding_mode);
110 EXPECT_EQ(0, fhdr.frame_context_idx); 234 EXPECT_EQ(0, fhdr.frame_context_idx_backup);
111 235
112 const Vp9LoopFilter& lf = GetLoopFilter(); 236 const Vp9LoopFilterParams& lf = GetLoopFilter();
113 EXPECT_EQ(9, lf.filter_level); 237 EXPECT_EQ(9, lf.level);
114 EXPECT_EQ(0, lf.sharpness_level); 238 EXPECT_EQ(0, lf.sharpness);
115 EXPECT_TRUE(lf.mode_ref_delta_enabled); 239 EXPECT_TRUE(lf.delta_enabled);
116 EXPECT_TRUE(lf.mode_ref_delta_update); 240 EXPECT_TRUE(lf.delta_update);
117 EXPECT_TRUE(lf.update_ref_deltas[0]); 241 EXPECT_TRUE(lf.update_ref_deltas[0]);
118 EXPECT_EQ(1, lf.ref_deltas[0]); 242 EXPECT_EQ(1, lf.ref_deltas[0]);
119 EXPECT_EQ(-1, lf.ref_deltas[2]); 243 EXPECT_EQ(-1, lf.ref_deltas[2]);
120 EXPECT_EQ(-1, lf.ref_deltas[3]); 244 EXPECT_EQ(-1, lf.ref_deltas[3]);
121 245
122 const Vp9QuantizationParams& qp = fhdr.quant_params; 246 const Vp9QuantizationParams& qp = fhdr.quant_params;
123 EXPECT_EQ(65, qp.base_qindex); 247 EXPECT_EQ(65, qp.base_q_idx);
124 EXPECT_FALSE(qp.y_dc_delta); 248 EXPECT_FALSE(qp.delta_q_y_dc);
125 EXPECT_FALSE(qp.uv_dc_delta); 249 EXPECT_FALSE(qp.delta_q_uv_dc);
126 EXPECT_FALSE(qp.uv_ac_delta); 250 EXPECT_FALSE(qp.delta_q_uv_ac);
127 EXPECT_FALSE(qp.IsLossless()); 251 EXPECT_FALSE(qp.IsLossless());
128 252
129 const Vp9Segmentation& seg = GetSegmentation(); 253 const Vp9SegmentationParams& seg = GetSegmentation();
130 EXPECT_FALSE(seg.enabled); 254 EXPECT_FALSE(seg.enabled);
131 255
132 EXPECT_EQ(0, fhdr.log2_tile_cols); 256 EXPECT_EQ(0, fhdr.tile_cols_log2);
133 EXPECT_EQ(0, fhdr.log2_tile_rows); 257 EXPECT_EQ(0, fhdr.tile_rows_log2);
134 258
135 EXPECT_EQ(120u, fhdr.first_partition_size); 259 EXPECT_EQ(120u, fhdr.header_size_in_bytes);
136 EXPECT_EQ(18u, fhdr.uncompressed_header_size); 260 EXPECT_EQ(18u, fhdr.uncompressed_header_size);
137 } 261 }
138 262
139 TEST_F(Vp9ParserTest, VerifyInterFrame) { 263 TEST_F(Vp9ParserTest, VerifyInterFrame) {
264 Initialize("test-25fps.vp9", false);
140 Vp9FrameHeader fhdr; 265 Vp9FrameHeader fhdr;
141 266
142 // To verify the second frame. 267 // To verify the second frame.
143 for (int i = 0; i < 2; i++) 268 for (int i = 0; i < 2; i++)
144 ASSERT_TRUE(ParseNextFrame(&fhdr)); 269 ASSERT_TRUE(ParseNextFrame(&fhdr, nullptr));
145 270
146 EXPECT_EQ(Vp9FrameHeader::INTERFRAME, fhdr.frame_type); 271 EXPECT_EQ(Vp9FrameHeader::INTERFRAME, fhdr.frame_type);
147 EXPECT_FALSE(fhdr.show_frame); 272 EXPECT_FALSE(fhdr.show_frame);
148 EXPECT_FALSE(fhdr.intra_only); 273 EXPECT_FALSE(fhdr.intra_only);
149 EXPECT_FALSE(fhdr.reset_context); 274 EXPECT_FALSE(fhdr.reset_frame_context);
150 EXPECT_TRUE(fhdr.RefreshFlag(2)); 275 EXPECT_TRUE(fhdr.RefreshFlag(2));
151 EXPECT_EQ(0, fhdr.frame_refs[0]); 276 EXPECT_EQ(0, fhdr.ref_frame_idx[0]);
152 EXPECT_EQ(1, fhdr.frame_refs[1]); 277 EXPECT_EQ(1, fhdr.ref_frame_idx[1]);
153 EXPECT_EQ(2, fhdr.frame_refs[2]); 278 EXPECT_EQ(2, fhdr.ref_frame_idx[2]);
154 EXPECT_TRUE(fhdr.allow_high_precision_mv); 279 EXPECT_TRUE(fhdr.allow_high_precision_mv);
155 EXPECT_EQ(Vp9InterpFilter::EIGHTTAP, fhdr.interp_filter); 280 EXPECT_EQ(Vp9InterpolationFilter::EIGHTTAP, fhdr.interpolation_filter);
156 281
157 EXPECT_EQ(48u, fhdr.first_partition_size); 282 EXPECT_EQ(48u, fhdr.header_size_in_bytes);
158 EXPECT_EQ(11u, fhdr.uncompressed_header_size); 283 EXPECT_EQ(11u, fhdr.uncompressed_header_size);
159 } 284 }
160 285
161 } // namespace media 286 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698