Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include <deque> | 5 #include <deque> |
| 6 #include <stdlib.h> | 6 #include <stdlib.h> |
| 7 | 7 |
| 8 #include "base/bind.h" | 8 #include "base/bind.h" |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 | 140 |
| 141 if (result == Decoder::DECODE_DONE) { | 141 if (result == Decoder::DECODE_DONE) { |
| 142 decoder_->RenderFrame(SkISize::Make(kWidth, kHeight), | 142 decoder_->RenderFrame(SkISize::Make(kWidth, kHeight), |
| 143 SkIRect::MakeXYWH(0, 0, kWidth, kHeight), | 143 SkIRect::MakeXYWH(0, 0, kWidth, kHeight), |
| 144 image_data_.get(), | 144 image_data_.get(), |
| 145 kWidth * kBytesPerPixel, | 145 kWidth * kBytesPerPixel, |
| 146 &update_region_); | 146 &update_region_); |
| 147 } | 147 } |
| 148 } | 148 } |
| 149 | 149 |
| 150 void ReceivedScopedPacket(scoped_ptr<VideoPacket> packet) { | |
| 151 ReceivedPacket(packet.get()); | |
| 152 } | |
| 153 | |
| 150 void set_strict(bool strict) { | 154 void set_strict(bool strict) { |
| 151 strict_ = strict; | 155 strict_ = strict; |
| 152 } | 156 } |
| 153 | 157 |
| 154 void set_capture_data(scoped_refptr<CaptureData> data) { | 158 void set_capture_data(scoped_refptr<CaptureData> data) { |
| 155 capture_data_ = data; | 159 capture_data_ = data; |
| 156 } | 160 } |
| 157 | 161 |
| 158 void AddRects(const SkIRect* rects, int count) { | 162 void AddRects(const SkIRect* rects, int count) { |
| 159 SkRegion new_rects; | 163 SkRegion new_rects; |
| 160 new_rects.setRects(rects, count); | 164 new_rects.setRects(rects, count); |
| 161 expected_region_.op(new_rects, SkRegion::kUnion_Op); | 165 AddRegion(new_rects); |
| 166 } | |
| 167 | |
| 168 void AddRegion(const SkRegion& region) { | |
| 169 expected_region_.op(region, SkRegion::kUnion_Op); | |
| 162 } | 170 } |
| 163 | 171 |
| 164 void VerifyResults() { | 172 void VerifyResults() { |
| 165 if (!strict_) | 173 if (!strict_) |
| 166 return; | 174 return; |
| 167 | 175 |
| 168 ASSERT_TRUE(capture_data_.get()); | 176 ASSERT_TRUE(capture_data_.get()); |
| 169 | 177 |
| 170 // Test the content of the update region. | 178 // Test the content of the update region. |
| 171 EXPECT_EQ(expected_region_, update_region_); | 179 EXPECT_EQ(expected_region_, update_region_); |
| 172 for (SkRegion::Iterator i(update_region_); !i.done(); i.next()) { | 180 for (SkRegion::Iterator i(update_region_); !i.done(); i.next()) { |
| 173 const int stride = kWidth * kBytesPerPixel; | 181 const int stride = kWidth * kBytesPerPixel; |
| 174 EXPECT_EQ(stride, capture_data_->data_planes().strides[0]); | 182 EXPECT_EQ(stride, capture_data_->data_planes().strides[0]); |
| 175 const int offset = stride * i.rect().top() + | 183 const int offset = stride * i.rect().top() + |
| 176 kBytesPerPixel * i.rect().left(); | 184 kBytesPerPixel * i.rect().left(); |
| 177 const uint8* original = capture_data_->data_planes().data[0] + offset; | 185 const uint8* original = capture_data_->data_planes().data[0] + offset; |
| 178 const uint8* decoded = image_data_.get() + offset; | 186 const uint8* decoded = image_data_.get() + offset; |
| 179 const int row_size = kBytesPerPixel * i.rect().width(); | 187 const int row_size = kBytesPerPixel * i.rect().width(); |
| 180 for (int y = 0; y < i.rect().height(); ++y) { | 188 for (int y = 0; y < i.rect().height(); ++y) { |
| 181 EXPECT_EQ(0, memcmp(original, decoded, row_size)) | 189 EXPECT_EQ(0, memcmp(original, decoded, row_size)) |
| 182 << "Row " << y << " is different"; | 190 << "Row " << y << " is different"; |
| 183 original += stride; | 191 original += stride; |
| 184 decoded += stride; | 192 decoded += stride; |
| 185 } | 193 } |
| 186 } | 194 } |
| 187 } | 195 } |
| 188 | 196 |
| 197 void VerifyResultsApprox(double max_error_limit, double mean_error_limit) { | |
|
Sergey Ulanov
2012/07/27 02:55:01
add short description of how the error is calculat
simonmorris
2012/07/27 16:42:24
Done.
| |
| 198 ASSERT_TRUE(capture_data_.get()); | |
| 199 | |
| 200 // Test the content of the update region. | |
| 201 EXPECT_EQ(expected_region_, update_region_); | |
| 202 double max_error = 0.0; | |
| 203 double sum_error = 0.0; | |
| 204 int error_num = 0; | |
| 205 for (SkRegion::Iterator i(update_region_); !i.done(); i.next()) { | |
| 206 const int stride = kWidth * kBytesPerPixel; | |
| 207 EXPECT_EQ(stride, capture_data_->data_planes().strides[0]); | |
| 208 const int offset = stride * i.rect().top() + | |
| 209 kBytesPerPixel * i.rect().left(); | |
| 210 const uint8* original = capture_data_->data_planes().data[0] + offset; | |
| 211 const uint8* decoded = image_data_.get() + offset; | |
| 212 for (int y = 0; y < i.rect().height(); ++y) { | |
| 213 for (int x = 0; x < i.rect().width(); ++x) { | |
| 214 double error_sum_squares = 0.0; | |
| 215 for (int i = 0; i < 3; i++) { | |
| 216 double error = static_cast<double>(*original++) - | |
| 217 static_cast<double>(*decoded++); | |
| 218 error /= 255.0; | |
| 219 error_sum_squares += error * error; | |
| 220 } | |
| 221 original++; | |
| 222 decoded++; | |
| 223 double error = sqrt(error_sum_squares / 3.0); | |
| 224 max_error = std::max(max_error, error); | |
| 225 sum_error += error; | |
| 226 ++error_num; | |
| 227 } | |
| 228 } | |
| 229 } | |
| 230 EXPECT_LE(max_error, max_error_limit); | |
| 231 double mean_error = sum_error / error_num; | |
| 232 EXPECT_LE(mean_error, mean_error_limit); | |
| 233 LOG(INFO) << "Max error: " << max_error; | |
| 234 LOG(INFO) << "Mean error: " << mean_error; | |
| 235 } | |
| 236 | |
| 189 private: | 237 private: |
| 190 bool strict_; | 238 bool strict_; |
| 191 SkRegion expected_region_; | 239 SkRegion expected_region_; |
| 192 SkRegion update_region_; | 240 SkRegion update_region_; |
| 193 Decoder* decoder_; | 241 Decoder* decoder_; |
| 194 scoped_array<uint8> image_data_; | 242 scoped_array<uint8> image_data_; |
| 195 scoped_refptr<CaptureData> capture_data_; | 243 scoped_refptr<CaptureData> capture_data_; |
| 196 | 244 |
| 197 DISALLOW_COPY_AND_ASSIGN(DecoderTester); | 245 DISALLOW_COPY_AND_ASSIGN(DecoderTester); |
| 198 }; | 246 }; |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 341 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, | 389 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, |
| 342 kTestRects, 1); | 390 kTestRects, 1); |
| 343 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, | 391 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, |
| 344 kTestRects + 1, 1); | 392 kTestRects + 1, 1); |
| 345 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, | 393 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, |
| 346 kTestRects + 2, 1); | 394 kTestRects + 2, 1); |
| 347 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, | 395 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, |
| 348 kTestRects + 3, 2); | 396 kTestRects + 3, 2); |
| 349 } | 397 } |
| 350 | 398 |
| 399 static void FillWithGradient(uint8* memory, const SkISize& frame_size, | |
| 400 const SkIRect& rect) { | |
| 401 for (int j = rect.top(); j < rect.bottom(); ++j) { | |
| 402 for (int i = rect.left(); i < rect.right(); ++i) { | |
| 403 uint8* p = memory + ((j * frame_size.width()) + i) * 4; | |
|
Sergey Ulanov
2012/07/27 02:55:01
nit: move this outside of the inner loop. Or alter
simonmorris
2012/07/27 16:42:24
Done.
| |
| 404 *p++ = static_cast<uint8>((255.0 * i) / frame_size.width()); | |
| 405 *p++ = static_cast<uint8>((164.0 * j) / frame_size.height()); | |
| 406 *p++ = static_cast<uint8>((82.0 * (i + j)) / | |
| 407 (frame_size.width() + frame_size.height())); | |
| 408 *p++ = 0; | |
| 409 } | |
| 410 } | |
| 411 } | |
| 412 | |
| 413 void TestEncoderDecoderGradient(Encoder* encoder, Decoder* decoder, | |
|
Sergey Ulanov
2012/07/27 02:55:01
nit: move second parameter to a separate line
simonmorris
2012/07/27 16:42:24
Done.
| |
| 414 double max_error_limit, | |
| 415 double mean_error_limit) { | |
| 416 SkIRect full_frame = SkIRect::MakeWH(kWidth, kHeight); | |
| 417 scoped_array<uint8> frame_data(new uint8[kWidth * kHeight * kBytesPerPixel]); | |
| 418 FillWithGradient(frame_data.get(), SkISize::Make(kWidth, kHeight), | |
| 419 full_frame); | |
| 420 | |
| 421 DataPlanes planes; | |
| 422 memset(planes.data, 0, sizeof(planes.data)); | |
| 423 memset(planes.strides, 0, sizeof(planes.strides)); | |
| 424 planes.data[0] = frame_data.get(); | |
| 425 planes.strides[0] = kWidth * kBytesPerPixel; | |
| 426 | |
| 427 scoped_refptr<CaptureData> capture_data = | |
| 428 new CaptureData(planes, SkISize::Make(kWidth, kHeight), | |
| 429 media::VideoFrame::RGB32); | |
| 430 capture_data->mutable_dirty_region().op(full_frame, SkRegion::kUnion_Op); | |
| 431 | |
| 432 DecoderTester decoder_tester(decoder); | |
| 433 decoder_tester.set_capture_data(capture_data); | |
| 434 decoder_tester.AddRegion(capture_data->dirty_region()); | |
| 435 | |
| 436 encoder->Encode(capture_data, true, | |
| 437 base::Bind(&DecoderTester::ReceivedScopedPacket, | |
| 438 base::Unretained(&decoder_tester))); | |
| 439 | |
| 440 decoder_tester.VerifyResultsApprox(max_error_limit, mean_error_limit); | |
| 441 } | |
| 442 | |
| 351 } // namespace remoting | 443 } // namespace remoting |
| OLD | NEW |