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