Chromium Code Reviews| 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 | 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 Loading... | |
| 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 double frames in order to detect extra frames parsed. | 142 // Allow to parse double frames in order to detect extra frames parsed. |
| 143 while (num_parsed_frames < num_expected_frames * 2) { | 143 while (num_parsed_frames < num_expected_frames * 2) { |
| 144 Vp9FrameHeader fhdr; | 144 Vp9FrameHeader fhdr; |
| 145 Vp9FrameContextManager::ContextRefreshCallback context_refresh_cb; | 145 if (ParseNextFrame(&fhdr) != Vp9Parser::kOk) |
| 146 if (ParseNextFrame(&fhdr, &context_refresh_cb) != Vp9Parser::kOk) | |
| 147 break; | 146 break; |
| 148 | 147 |
| 149 Vp9FrameContext frame_context; | 148 Vp9FrameContext frame_context; |
| 150 ReadContext(&frame_context); | 149 ReadContext(&frame_context); |
| 151 EXPECT_TRUE(memcmp(&frame_context, &fhdr.initial_frame_context, | 150 EXPECT_TRUE(memcmp(&frame_context, &fhdr.initial_frame_context, |
| 152 sizeof(frame_context)) == 0); | 151 sizeof(frame_context)) == 0); |
| 153 ReadContext(&frame_context); | 152 ReadContext(&frame_context); |
| 154 EXPECT_TRUE(memcmp(&frame_context, &fhdr.frame_context, | 153 EXPECT_TRUE(memcmp(&frame_context, &fhdr.frame_context, |
| 155 sizeof(frame_context)) == 0); | 154 sizeof(frame_context)) == 0); |
| 156 | 155 |
| 157 // test-25fps.vp9 doesn't need frame update from driver. | 156 // test-25fps.vp9 doesn't need frame update from driver. |
| 157 Vp9Parser::ContextRefreshCallback context_refresh_cb = | |
|
kcwu
2016/08/17 04:06:09
Since we don't care the detail type here, use "aut
Pawel Osciak
2016/08/19 08:22:44
Done.
| |
| 158 GetContextRefreshCb(fhdr); | |
| 158 EXPECT_TRUE(context_refresh_cb.is_null()); | 159 EXPECT_TRUE(context_refresh_cb.is_null()); |
| 159 ASSERT_FALSE(ReadShouldContextUpdate()); | 160 ASSERT_FALSE(ReadShouldContextUpdate()); |
| 160 | 161 |
| 161 ++num_parsed_frames; | 162 ++num_parsed_frames; |
| 162 } | 163 } |
| 163 | 164 |
| 164 DVLOG(1) << "Number of successfully parsed frames before EOS: " | 165 DVLOG(1) << "Number of successfully parsed frames before EOS: " |
| 165 << num_parsed_frames; | 166 << num_parsed_frames; |
| 166 | 167 |
| 167 EXPECT_EQ(num_expected_frames, num_parsed_frames); | 168 EXPECT_EQ(num_expected_frames, num_parsed_frames); |
| 168 } | 169 } |
| 169 | 170 |
| 170 TEST_F(Vp9ParserTest, StreamFileParsingWithContextUpdate) { | 171 TEST_F(Vp9ParserTest, StreamFileParsingWithContextUpdate) { |
| 171 Initialize("bear-vp9.ivf", true); | 172 Initialize("bear-vp9.ivf", true); |
| 172 | 173 |
| 173 // Number of frames in the test stream to be parsed. | 174 // Number of frames in the test stream to be parsed. |
| 174 const int num_expected_frames = 82; | 175 const int num_expected_frames = 82; |
| 175 int num_parsed_frames = 0; | 176 int num_parsed_frames = 0; |
| 176 | 177 |
| 177 // Allow to parse double frames in order to detect extra frames parsed. | 178 // Allow to parse double frames in order to detect extra frames parsed. |
| 178 while (num_parsed_frames < num_expected_frames * 2) { | 179 while (num_parsed_frames < num_expected_frames * 2) { |
| 179 Vp9FrameHeader fhdr; | 180 Vp9FrameHeader fhdr; |
| 180 Vp9FrameContextManager::ContextRefreshCallback context_refresh_cb; | 181 if (ParseNextFrame(&fhdr) != Vp9Parser::kOk) |
| 181 if (ParseNextFrame(&fhdr, &context_refresh_cb) != Vp9Parser::kOk) | |
| 182 break; | 182 break; |
| 183 | 183 |
| 184 Vp9FrameContext frame_context; | 184 Vp9FrameContext frame_context; |
| 185 ReadContext(&frame_context); | 185 ReadContext(&frame_context); |
| 186 EXPECT_TRUE(memcmp(&frame_context, &fhdr.initial_frame_context, | 186 EXPECT_TRUE(memcmp(&frame_context, &fhdr.initial_frame_context, |
| 187 sizeof(frame_context)) == 0); | 187 sizeof(frame_context)) == 0); |
| 188 ReadContext(&frame_context); | 188 ReadContext(&frame_context); |
| 189 EXPECT_TRUE(memcmp(&frame_context, &fhdr.frame_context, | 189 EXPECT_TRUE(memcmp(&frame_context, &fhdr.frame_context, |
| 190 sizeof(frame_context)) == 0); | 190 sizeof(frame_context)) == 0); |
| 191 | 191 |
| 192 bool should_update = ReadShouldContextUpdate(); | 192 bool should_update = ReadShouldContextUpdate(); |
| 193 Vp9Parser::ContextRefreshCallback context_refresh_cb = | |
| 194 GetContextRefreshCb(fhdr); | |
| 193 if (context_refresh_cb.is_null()) { | 195 if (context_refresh_cb.is_null()) { |
| 194 EXPECT_FALSE(should_update); | 196 EXPECT_FALSE(should_update); |
| 195 } else { | 197 } else { |
| 196 EXPECT_TRUE(should_update); | 198 EXPECT_TRUE(should_update); |
| 197 ReadContext(&frame_context); | 199 ReadContext(&frame_context); |
| 198 context_refresh_cb.Run(frame_context); | 200 context_refresh_cb.Run(frame_context); |
| 199 } | 201 } |
| 200 | 202 |
| 201 ++num_parsed_frames; | 203 ++num_parsed_frames; |
| 202 } | 204 } |
| 203 | 205 |
| 204 DVLOG(1) << "Number of successfully parsed frames before EOS: " | 206 DVLOG(1) << "Number of successfully parsed frames before EOS: " |
| 205 << num_parsed_frames; | 207 << num_parsed_frames; |
| 206 | 208 |
| 207 EXPECT_EQ(num_expected_frames, num_parsed_frames); | 209 EXPECT_EQ(num_expected_frames, num_parsed_frames); |
| 208 } | 210 } |
| 209 | 211 |
| 210 TEST_F(Vp9ParserTest, AwaitingContextUpdate) { | 212 TEST_F(Vp9ParserTest, AwaitingContextUpdate) { |
| 211 Initialize("bear-vp9.ivf", true); | 213 Initialize("bear-vp9.ivf", true); |
| 212 | 214 |
| 213 Vp9FrameHeader fhdr; | 215 Vp9FrameHeader fhdr; |
| 214 Vp9FrameContextManager::ContextRefreshCallback context_refresh_cb; | 216 ASSERT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr)); |
| 215 ASSERT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr, &context_refresh_cb)); | |
| 216 EXPECT_FALSE(context_refresh_cb.is_null()); | |
| 217 | 217 |
| 218 Vp9FrameContext frame_context; | 218 Vp9FrameContext frame_context; |
| 219 ReadContext(&frame_context); | 219 ReadContext(&frame_context); |
| 220 ReadContext(&frame_context); | 220 ReadContext(&frame_context); |
| 221 bool should_update = ReadShouldContextUpdate(); | 221 bool should_update = ReadShouldContextUpdate(); |
| 222 ASSERT_TRUE(should_update); | 222 ASSERT_TRUE(should_update); |
| 223 ReadContext(&frame_context); | 223 ReadContext(&frame_context); |
| 224 | 224 |
| 225 // Not update yet. Should return kAwaitingRefresh. | 225 // Not update yet. Should return kAwaitingRefresh. |
| 226 Vp9FrameContextManager::ContextRefreshCallback unused_cb; | 226 EXPECT_EQ(Vp9Parser::kAwaitingRefresh, ParseNextFrame(&fhdr)); |
| 227 EXPECT_EQ(Vp9Parser::kAwaitingRefresh, ParseNextFrame(&fhdr, &unused_cb)); | 227 EXPECT_EQ(Vp9Parser::kAwaitingRefresh, ParseNextFrame(&fhdr)); |
| 228 EXPECT_EQ(Vp9Parser::kAwaitingRefresh, ParseNextFrame(&fhdr, &unused_cb)); | |
| 229 | 228 |
| 230 // After update, parse should be ok. | 229 // After update, parse should be ok. |
| 230 Vp9Parser::ContextRefreshCallback context_refresh_cb = | |
| 231 GetContextRefreshCb(fhdr); | |
| 232 EXPECT_FALSE(context_refresh_cb.is_null()); | |
| 231 context_refresh_cb.Run(frame_context); | 233 context_refresh_cb.Run(frame_context); |
| 232 EXPECT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr, &unused_cb)); | 234 EXPECT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr)); |
| 233 | 235 |
| 234 // Make sure it parsed the 2nd frame. | 236 // Make sure it parsed the 2nd frame. |
| 235 EXPECT_EQ(9u, fhdr.header_size_in_bytes); | 237 EXPECT_EQ(9u, fhdr.header_size_in_bytes); |
| 236 } | 238 } |
| 237 | 239 |
| 238 TEST_F(Vp9ParserTest, VerifyFirstFrame) { | 240 TEST_F(Vp9ParserTest, VerifyFirstFrame) { |
| 239 Initialize("test-25fps.vp9", false); | 241 Initialize("test-25fps.vp9", false); |
| 240 Vp9FrameHeader fhdr; | 242 Vp9FrameHeader fhdr; |
| 241 | 243 |
| 242 ASSERT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr, nullptr)); | 244 ASSERT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr)); |
| 243 | 245 |
| 244 EXPECT_EQ(0, fhdr.profile); | 246 EXPECT_EQ(0, fhdr.profile); |
| 245 EXPECT_FALSE(fhdr.show_existing_frame); | 247 EXPECT_FALSE(fhdr.show_existing_frame); |
| 246 EXPECT_EQ(Vp9FrameHeader::KEYFRAME, fhdr.frame_type); | 248 EXPECT_EQ(Vp9FrameHeader::KEYFRAME, fhdr.frame_type); |
| 247 EXPECT_TRUE(fhdr.show_frame); | 249 EXPECT_TRUE(fhdr.show_frame); |
| 248 EXPECT_FALSE(fhdr.error_resilient_mode); | 250 EXPECT_FALSE(fhdr.error_resilient_mode); |
| 249 | 251 |
| 250 EXPECT_EQ(8, fhdr.bit_depth); | 252 EXPECT_EQ(8, fhdr.bit_depth); |
| 251 EXPECT_EQ(Vp9ColorSpace::UNKNOWN, fhdr.color_space); | 253 EXPECT_EQ(Vp9ColorSpace::UNKNOWN, fhdr.color_space); |
| 252 EXPECT_FALSE(fhdr.color_range); | 254 EXPECT_FALSE(fhdr.color_range); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 288 EXPECT_EQ(120u, fhdr.header_size_in_bytes); | 290 EXPECT_EQ(120u, fhdr.header_size_in_bytes); |
| 289 EXPECT_EQ(18u, fhdr.uncompressed_header_size); | 291 EXPECT_EQ(18u, fhdr.uncompressed_header_size); |
| 290 } | 292 } |
| 291 | 293 |
| 292 TEST_F(Vp9ParserTest, VerifyInterFrame) { | 294 TEST_F(Vp9ParserTest, VerifyInterFrame) { |
| 293 Initialize("test-25fps.vp9", false); | 295 Initialize("test-25fps.vp9", false); |
| 294 Vp9FrameHeader fhdr; | 296 Vp9FrameHeader fhdr; |
| 295 | 297 |
| 296 // To verify the second frame. | 298 // To verify the second frame. |
| 297 for (int i = 0; i < 2; i++) | 299 for (int i = 0; i < 2; i++) |
| 298 ASSERT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr, nullptr)); | 300 ASSERT_EQ(Vp9Parser::kOk, ParseNextFrame(&fhdr)); |
| 299 | 301 |
| 300 EXPECT_EQ(Vp9FrameHeader::INTERFRAME, fhdr.frame_type); | 302 EXPECT_EQ(Vp9FrameHeader::INTERFRAME, fhdr.frame_type); |
| 301 EXPECT_FALSE(fhdr.show_frame); | 303 EXPECT_FALSE(fhdr.show_frame); |
| 302 EXPECT_FALSE(fhdr.intra_only); | 304 EXPECT_FALSE(fhdr.intra_only); |
| 303 EXPECT_FALSE(fhdr.reset_frame_context); | 305 EXPECT_FALSE(fhdr.reset_frame_context); |
| 304 EXPECT_TRUE(fhdr.RefreshFlag(2)); | 306 EXPECT_TRUE(fhdr.RefreshFlag(2)); |
| 305 EXPECT_EQ(0, fhdr.ref_frame_idx[0]); | 307 EXPECT_EQ(0, fhdr.ref_frame_idx[0]); |
| 306 EXPECT_EQ(1, fhdr.ref_frame_idx[1]); | 308 EXPECT_EQ(1, fhdr.ref_frame_idx[1]); |
| 307 EXPECT_EQ(2, fhdr.ref_frame_idx[2]); | 309 EXPECT_EQ(2, fhdr.ref_frame_idx[2]); |
| 308 EXPECT_TRUE(fhdr.allow_high_precision_mv); | 310 EXPECT_TRUE(fhdr.allow_high_precision_mv); |
| 309 EXPECT_EQ(Vp9InterpolationFilter::EIGHTTAP, fhdr.interpolation_filter); | 311 EXPECT_EQ(Vp9InterpolationFilter::EIGHTTAP, fhdr.interpolation_filter); |
| 310 | 312 |
| 311 EXPECT_EQ(48u, fhdr.header_size_in_bytes); | 313 EXPECT_EQ(48u, fhdr.header_size_in_bytes); |
| 312 EXPECT_EQ(11u, fhdr.uncompressed_header_size); | 314 EXPECT_EQ(11u, fhdr.uncompressed_header_size); |
| 313 } | 315 } |
| 314 | 316 |
| 315 } // namespace media | 317 } // namespace media |
| OLD | NEW |