| 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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 57 const DesktopSize& view_size) | 57 const DesktopSize& view_size) |
| 58 : screen_size_(screen_size), | 58 : screen_size_(screen_size), |
| 59 view_size_(view_size), | 59 view_size_(view_size), |
| 60 strict_(false), | 60 strict_(false), |
| 61 decoder_(decoder), | 61 decoder_(decoder), |
| 62 frame_(NULL) { | 62 frame_(NULL) { |
| 63 image_data_.reset(new uint8[ | 63 image_data_.reset(new uint8[ |
| 64 view_size_.width() * view_size_.height() * kBytesPerPixel]); | 64 view_size_.width() * view_size_.height() * kBytesPerPixel]); |
| 65 EXPECT_TRUE(image_data_.get()); | 65 EXPECT_TRUE(image_data_.get()); |
| 66 decoder_->Initialize( | 66 decoder_->Initialize( |
| 67 webrtc::DesktopSize(screen_size_.width(), screen_size_.height())); | 67 SkISize::Make(screen_size_.width(), screen_size_.height())); |
| 68 } | 68 } |
| 69 | 69 |
| 70 void Reset() { | 70 void Reset() { |
| 71 expected_region_.Clear(); | 71 expected_region_.Clear(); |
| 72 update_region_.Clear(); | 72 update_region_.setEmpty(); |
| 73 } | 73 } |
| 74 | 74 |
| 75 void ResetRenderedData() { | 75 void ResetRenderedData() { |
| 76 memset(image_data_.get(), 0, | 76 memset(image_data_.get(), 0, |
| 77 view_size_.width() * view_size_.height() * kBytesPerPixel); | 77 view_size_.width() * view_size_.height() * kBytesPerPixel); |
| 78 } | 78 } |
| 79 | 79 |
| 80 void ReceivedPacket(VideoPacket* packet) { | 80 void ReceivedPacket(VideoPacket* packet) { |
| 81 VideoDecoder::DecodeResult result = decoder_->DecodePacket(packet); | 81 VideoDecoder::DecodeResult result = decoder_->DecodePacket(packet); |
| 82 | 82 |
| 83 ASSERT_NE(VideoDecoder::DECODE_ERROR, result); | 83 ASSERT_NE(VideoDecoder::DECODE_ERROR, result); |
| 84 | 84 |
| 85 if (result == VideoDecoder::DECODE_DONE) { | 85 if (result == VideoDecoder::DECODE_DONE) { |
| 86 RenderFrame(); | 86 RenderFrame(); |
| 87 } | 87 } |
| 88 } | 88 } |
| 89 | 89 |
| 90 void RenderFrame() { | 90 void RenderFrame() { |
| 91 decoder_->RenderFrame( | 91 decoder_->RenderFrame( |
| 92 webrtc::DesktopSize(view_size_.width(), view_size_.height()), | 92 SkISize::Make(view_size_.width(), view_size_.height()), |
| 93 webrtc::DesktopRect::MakeWH(view_size_.width(), view_size_.height()), | 93 SkIRect::MakeWH(view_size_.width(), view_size_.height()), |
| 94 image_data_.get(), view_size_.width() * kBytesPerPixel, | 94 image_data_.get(), |
| 95 view_size_.width() * kBytesPerPixel, |
| 95 &update_region_); | 96 &update_region_); |
| 96 } | 97 } |
| 97 | 98 |
| 98 void ReceivedScopedPacket(scoped_ptr<VideoPacket> packet) { | 99 void ReceivedScopedPacket(scoped_ptr<VideoPacket> packet) { |
| 99 ReceivedPacket(packet.get()); | 100 ReceivedPacket(packet.get()); |
| 100 } | 101 } |
| 101 | 102 |
| 102 void set_strict(bool strict) { | 103 void set_strict(bool strict) { |
| 103 strict_ = strict; | 104 strict_ = strict; |
| 104 } | 105 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 117 expected_region_.AddRegion(region); | 118 expected_region_.AddRegion(region); |
| 118 } | 119 } |
| 119 | 120 |
| 120 void VerifyResults() { | 121 void VerifyResults() { |
| 121 if (!strict_) | 122 if (!strict_) |
| 122 return; | 123 return; |
| 123 | 124 |
| 124 ASSERT_TRUE(frame_); | 125 ASSERT_TRUE(frame_); |
| 125 | 126 |
| 126 // Test the content of the update region. | 127 // Test the content of the update region. |
| 127 EXPECT_TRUE(expected_region_.Equals(update_region_)); | 128 webrtc::DesktopRegion update_region; |
| 129 for (SkRegion::Iterator i(update_region_); !i.done(); i.next()) { |
| 130 update_region.AddRect(webrtc::DesktopRect::MakeXYWH( |
| 131 i.rect().x(), i.rect().y(), i.rect().width(), i.rect().height())); |
| 132 } |
| 133 EXPECT_TRUE(expected_region_.Equals(update_region)); |
| 128 | 134 |
| 129 for (webrtc::DesktopRegion::Iterator i(update_region_); !i.IsAtEnd(); | 135 for (SkRegion::Iterator i(update_region_); !i.done(); i.next()) { |
| 130 i.Advance()) { | |
| 131 const int stride = view_size_.width() * kBytesPerPixel; | 136 const int stride = view_size_.width() * kBytesPerPixel; |
| 132 EXPECT_EQ(stride, frame_->stride()); | 137 EXPECT_EQ(stride, frame_->stride()); |
| 133 const int offset = stride * i.rect().top() + | 138 const int offset = stride * i.rect().top() + |
| 134 kBytesPerPixel * i.rect().left(); | 139 kBytesPerPixel * i.rect().left(); |
| 135 const uint8* original = frame_->data() + offset; | 140 const uint8* original = frame_->data() + offset; |
| 136 const uint8* decoded = image_data_.get() + offset; | 141 const uint8* decoded = image_data_.get() + offset; |
| 137 const int row_size = kBytesPerPixel * i.rect().width(); | 142 const int row_size = kBytesPerPixel * i.rect().width(); |
| 138 for (int y = 0; y < i.rect().height(); ++y) { | 143 for (int y = 0; y < i.rect().height(); ++y) { |
| 139 EXPECT_EQ(0, memcmp(original, decoded, row_size)) | 144 EXPECT_EQ(0, memcmp(original, decoded, row_size)) |
| 140 << "Row " << y << " is different"; | 145 << "Row " << y << " is different"; |
| 141 original += stride; | 146 original += stride; |
| 142 decoded += stride; | 147 decoded += stride; |
| 143 } | 148 } |
| 144 } | 149 } |
| 145 } | 150 } |
| 146 | 151 |
| 147 // The error at each pixel is the root mean square of the errors in | 152 // The error at each pixel is the root mean square of the errors in |
| 148 // the R, G, and B components, each normalized to [0, 1]. This routine | 153 // the R, G, and B components, each normalized to [0, 1]. This routine |
| 149 // checks that the maximum and mean pixel errors do not exceed given limits. | 154 // checks that the maximum and mean pixel errors do not exceed given limits. |
| 150 void VerifyResultsApprox(const uint8* expected_view_data, | 155 void VerifyResultsApprox(const uint8* expected_view_data, |
| 151 double max_error_limit, double mean_error_limit) { | 156 double max_error_limit, double mean_error_limit) { |
| 152 double max_error = 0.0; | 157 double max_error = 0.0; |
| 153 double sum_error = 0.0; | 158 double sum_error = 0.0; |
| 154 int error_num = 0; | 159 int error_num = 0; |
| 155 for (webrtc::DesktopRegion::Iterator i(update_region_); !i.IsAtEnd(); | 160 for (SkRegion::Iterator i(update_region_); !i.done(); i.next()) { |
| 156 i.Advance()) { | |
| 157 const int stride = view_size_.width() * kBytesPerPixel; | 161 const int stride = view_size_.width() * kBytesPerPixel; |
| 158 const int offset = stride * i.rect().top() + | 162 const int offset = stride * i.rect().top() + |
| 159 kBytesPerPixel * i.rect().left(); | 163 kBytesPerPixel * i.rect().left(); |
| 160 const uint8* expected = expected_view_data + offset; | 164 const uint8* expected = expected_view_data + offset; |
| 161 const uint8* actual = image_data_.get() + offset; | 165 const uint8* actual = image_data_.get() + offset; |
| 162 for (int y = 0; y < i.rect().height(); ++y) { | 166 for (int y = 0; y < i.rect().height(); ++y) { |
| 163 for (int x = 0; x < i.rect().width(); ++x) { | 167 for (int x = 0; x < i.rect().width(); ++x) { |
| 164 double error = CalculateError(expected, actual); | 168 double error = CalculateError(expected, actual); |
| 165 max_error = std::max(max_error, error); | 169 max_error = std::max(max_error, error); |
| 166 sum_error += error; | 170 sum_error += error; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 188 original++; | 192 original++; |
| 189 decoded++; | 193 decoded++; |
| 190 return sqrt(error_sum_squares / 3.0); | 194 return sqrt(error_sum_squares / 3.0); |
| 191 } | 195 } |
| 192 | 196 |
| 193 private: | 197 private: |
| 194 DesktopSize screen_size_; | 198 DesktopSize screen_size_; |
| 195 DesktopSize view_size_; | 199 DesktopSize view_size_; |
| 196 bool strict_; | 200 bool strict_; |
| 197 webrtc::DesktopRegion expected_region_; | 201 webrtc::DesktopRegion expected_region_; |
| 198 webrtc::DesktopRegion update_region_; | 202 SkRegion update_region_; |
| 199 VideoDecoder* decoder_; | 203 VideoDecoder* decoder_; |
| 200 scoped_ptr<uint8[]> image_data_; | 204 scoped_ptr<uint8[]> image_data_; |
| 201 webrtc::DesktopFrame* frame_; | 205 webrtc::DesktopFrame* frame_; |
| 202 | 206 |
| 203 DISALLOW_COPY_AND_ASSIGN(VideoDecoderTester); | 207 DISALLOW_COPY_AND_ASSIGN(VideoDecoderTester); |
| 204 }; | 208 }; |
| 205 | 209 |
| 206 // The VideoEncoderTester provides a hook for retrieving the data, and passing | 210 // The VideoEncoderTester provides a hook for retrieving the data, and passing |
| 207 // the message to other subprograms for validaton. | 211 // the message to other subprograms for validaton. |
| 208 class VideoEncoderTester { | 212 class VideoEncoderTester { |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 scoped_ptr<VideoPacket> packet = encoder->Encode(*frame); | 374 scoped_ptr<VideoPacket> packet = encoder->Encode(*frame); |
| 371 decoder_tester.ReceivedScopedPacket(packet.Pass()); | 375 decoder_tester.ReceivedScopedPacket(packet.Pass()); |
| 372 | 376 |
| 373 decoder_tester.VerifyResultsApprox(expected_result->data(), | 377 decoder_tester.VerifyResultsApprox(expected_result->data(), |
| 374 max_error_limit, mean_error_limit); | 378 max_error_limit, mean_error_limit); |
| 375 | 379 |
| 376 // Check that the decoder correctly re-renders the frame if its client | 380 // Check that the decoder correctly re-renders the frame if its client |
| 377 // invalidates the frame. | 381 // invalidates the frame. |
| 378 decoder_tester.ResetRenderedData(); | 382 decoder_tester.ResetRenderedData(); |
| 379 decoder->Invalidate( | 383 decoder->Invalidate( |
| 380 webrtc::DesktopSize(view_size.width(), view_size.height()), | 384 SkISize::Make(view_size.width(), view_size.height()), |
| 381 webrtc::DesktopRegion( | 385 SkRegion(SkIRect::MakeWH(view_size.width(), view_size.height()))); |
| 382 webrtc::DesktopRect::MakeWH(view_size.width(), view_size.height()))); | |
| 383 decoder_tester.RenderFrame(); | 386 decoder_tester.RenderFrame(); |
| 384 decoder_tester.VerifyResultsApprox(expected_result->data(), | 387 decoder_tester.VerifyResultsApprox(expected_result->data(), |
| 385 max_error_limit, mean_error_limit); | 388 max_error_limit, mean_error_limit); |
| 386 } | 389 } |
| 387 | 390 |
| 388 } // namespace remoting | 391 } // namespace remoting |
| OLD | NEW |