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

Side by Side Diff: remoting/codec/codec_test.cc

Issue 23440046: Remove dependency on Skia from chromoting client. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « remoting/client/rectangle_update_decoder.cc ('k') | remoting/codec/video_decoder.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 ASSERT_TRUE(decoder_->DecodePacket(*packet)); 81 ASSERT_TRUE(decoder_->DecodePacket(*packet));
82 82
83 RenderFrame(); 83 RenderFrame();
84 } 84 }
85 85
86 void RenderFrame() { 86 void RenderFrame() {
87 decoder_->RenderFrame( 87 decoder_->RenderFrame(
88 SkISize::Make(view_size_.width(), view_size_.height()), 88 webrtc::DesktopSize(view_size_.width(), view_size_.height()),
89 SkIRect::MakeWH(view_size_.width(), view_size_.height()), 89 webrtc::DesktopRect::MakeWH(view_size_.width(), view_size_.height()),
90 image_data_.get(), 90 image_data_.get(), view_size_.width() * kBytesPerPixel,
91 view_size_.width() * kBytesPerPixel,
92 &update_region_); 91 &update_region_);
93 } 92 }
94 93
95 void ReceivedScopedPacket(scoped_ptr<VideoPacket> packet) { 94 void ReceivedScopedPacket(scoped_ptr<VideoPacket> packet) {
96 ReceivedPacket(packet.get()); 95 ReceivedPacket(packet.get());
97 } 96 }
98 97
99 void set_strict(bool strict) { 98 void set_strict(bool strict) {
100 strict_ = strict; 99 strict_ = strict;
101 } 100 }
(...skipping 12 matching lines...) Expand all
114 expected_region_.AddRegion(region); 113 expected_region_.AddRegion(region);
115 } 114 }
116 115
117 void VerifyResults() { 116 void VerifyResults() {
118 if (!strict_) 117 if (!strict_)
119 return; 118 return;
120 119
121 ASSERT_TRUE(frame_); 120 ASSERT_TRUE(frame_);
122 121
123 // Test the content of the update region. 122 // Test the content of the update region.
124 webrtc::DesktopRegion update_region; 123 EXPECT_TRUE(expected_region_.Equals(update_region_));
125 for (SkRegion::Iterator i(update_region_); !i.done(); i.next()) {
126 update_region.AddRect(webrtc::DesktopRect::MakeXYWH(
127 i.rect().x(), i.rect().y(), i.rect().width(), i.rect().height()));
128 }
129 EXPECT_TRUE(expected_region_.Equals(update_region));
130 124
131 for (SkRegion::Iterator i(update_region_); !i.done(); i.next()) { 125 for (webrtc::DesktopRegion::Iterator i(update_region_); !i.IsAtEnd();
126 i.Advance()) {
132 const int stride = view_size_.width() * kBytesPerPixel; 127 const int stride = view_size_.width() * kBytesPerPixel;
133 EXPECT_EQ(stride, frame_->stride()); 128 EXPECT_EQ(stride, frame_->stride());
134 const int offset = stride * i.rect().top() + 129 const int offset = stride * i.rect().top() +
135 kBytesPerPixel * i.rect().left(); 130 kBytesPerPixel * i.rect().left();
136 const uint8* original = frame_->data() + offset; 131 const uint8* original = frame_->data() + offset;
137 const uint8* decoded = image_data_.get() + offset; 132 const uint8* decoded = image_data_.get() + offset;
138 const int row_size = kBytesPerPixel * i.rect().width(); 133 const int row_size = kBytesPerPixel * i.rect().width();
139 for (int y = 0; y < i.rect().height(); ++y) { 134 for (int y = 0; y < i.rect().height(); ++y) {
140 EXPECT_EQ(0, memcmp(original, decoded, row_size)) 135 EXPECT_EQ(0, memcmp(original, decoded, row_size))
141 << "Row " << y << " is different"; 136 << "Row " << y << " is different";
142 original += stride; 137 original += stride;
143 decoded += stride; 138 decoded += stride;
144 } 139 }
145 } 140 }
146 } 141 }
147 142
148 // The error at each pixel is the root mean square of the errors in 143 // The error at each pixel is the root mean square of the errors in
149 // the R, G, and B components, each normalized to [0, 1]. This routine 144 // the R, G, and B components, each normalized to [0, 1]. This routine
150 // checks that the maximum and mean pixel errors do not exceed given limits. 145 // checks that the maximum and mean pixel errors do not exceed given limits.
151 void VerifyResultsApprox(const uint8* expected_view_data, 146 void VerifyResultsApprox(const uint8* expected_view_data,
152 double max_error_limit, double mean_error_limit) { 147 double max_error_limit, double mean_error_limit) {
153 double max_error = 0.0; 148 double max_error = 0.0;
154 double sum_error = 0.0; 149 double sum_error = 0.0;
155 int error_num = 0; 150 int error_num = 0;
156 for (SkRegion::Iterator i(update_region_); !i.done(); i.next()) { 151 for (webrtc::DesktopRegion::Iterator i(update_region_); !i.IsAtEnd();
152 i.Advance()) {
157 const int stride = view_size_.width() * kBytesPerPixel; 153 const int stride = view_size_.width() * kBytesPerPixel;
158 const int offset = stride * i.rect().top() + 154 const int offset = stride * i.rect().top() +
159 kBytesPerPixel * i.rect().left(); 155 kBytesPerPixel * i.rect().left();
160 const uint8* expected = expected_view_data + offset; 156 const uint8* expected = expected_view_data + offset;
161 const uint8* actual = image_data_.get() + offset; 157 const uint8* actual = image_data_.get() + offset;
162 for (int y = 0; y < i.rect().height(); ++y) { 158 for (int y = 0; y < i.rect().height(); ++y) {
163 for (int x = 0; x < i.rect().width(); ++x) { 159 for (int x = 0; x < i.rect().width(); ++x) {
164 double error = CalculateError(expected, actual); 160 double error = CalculateError(expected, actual);
165 max_error = std::max(max_error, error); 161 max_error = std::max(max_error, error);
166 sum_error += error; 162 sum_error += error;
(...skipping 21 matching lines...) Expand all
188 original++; 184 original++;
189 decoded++; 185 decoded++;
190 return sqrt(error_sum_squares / 3.0); 186 return sqrt(error_sum_squares / 3.0);
191 } 187 }
192 188
193 private: 189 private:
194 DesktopSize screen_size_; 190 DesktopSize screen_size_;
195 DesktopSize view_size_; 191 DesktopSize view_size_;
196 bool strict_; 192 bool strict_;
197 webrtc::DesktopRegion expected_region_; 193 webrtc::DesktopRegion expected_region_;
198 SkRegion update_region_; 194 webrtc::DesktopRegion update_region_;
199 VideoDecoder* decoder_; 195 VideoDecoder* decoder_;
200 scoped_ptr<uint8[]> image_data_; 196 scoped_ptr<uint8[]> image_data_;
201 webrtc::DesktopFrame* frame_; 197 webrtc::DesktopFrame* frame_;
202 198
203 DISALLOW_COPY_AND_ASSIGN(VideoDecoderTester); 199 DISALLOW_COPY_AND_ASSIGN(VideoDecoderTester);
204 }; 200 };
205 201
206 // The VideoEncoderTester provides a hook for retrieving the data, and passing 202 // The VideoEncoderTester provides a hook for retrieving the data, and passing
207 // the message to other subprograms for validaton. 203 // the message to other subprograms for validaton.
208 class VideoEncoderTester { 204 class VideoEncoderTester {
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 scoped_ptr<VideoPacket> packet = encoder->Encode(*frame); 366 scoped_ptr<VideoPacket> packet = encoder->Encode(*frame);
371 decoder_tester.ReceivedScopedPacket(packet.Pass()); 367 decoder_tester.ReceivedScopedPacket(packet.Pass());
372 368
373 decoder_tester.VerifyResultsApprox(expected_result->data(), 369 decoder_tester.VerifyResultsApprox(expected_result->data(),
374 max_error_limit, mean_error_limit); 370 max_error_limit, mean_error_limit);
375 371
376 // Check that the decoder correctly re-renders the frame if its client 372 // Check that the decoder correctly re-renders the frame if its client
377 // invalidates the frame. 373 // invalidates the frame.
378 decoder_tester.ResetRenderedData(); 374 decoder_tester.ResetRenderedData();
379 decoder->Invalidate( 375 decoder->Invalidate(
380 SkISize::Make(view_size.width(), view_size.height()), 376 webrtc::DesktopSize(view_size.width(), view_size.height()),
381 SkRegion(SkIRect::MakeWH(view_size.width(), view_size.height()))); 377 webrtc::DesktopRegion(
378 webrtc::DesktopRect::MakeWH(view_size.width(), view_size.height())));
382 decoder_tester.RenderFrame(); 379 decoder_tester.RenderFrame();
383 decoder_tester.VerifyResultsApprox(expected_result->data(), 380 decoder_tester.VerifyResultsApprox(expected_result->data(),
384 max_error_limit, mean_error_limit); 381 max_error_limit, mean_error_limit);
385 } 382 }
386 383
387 } // namespace remoting 384 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/client/rectangle_update_decoder.cc ('k') | remoting/codec/video_decoder.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698