[email protected] | dc454a7c | 2011-08-12 22:01:13 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 542bdfe | 2010-11-30 03:55:47 | [diff] [blame] | 5 | #include <deque> |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 6 | #include <stdlib.h> |
| 7 | |
[email protected] | dc454a7c | 2011-08-12 22:01:13 | [diff] [blame] | 8 | #include "base/memory/scoped_ptr.h" |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 9 | #include "media/base/video_frame.h" |
[email protected] | 28dc421 | 2011-02-08 20:44:00 | [diff] [blame] | 10 | #include "remoting/base/base_mock_objects.h" |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 11 | #include "remoting/base/codec_test.h" |
[email protected] | 8ea7a167 | 2010-10-04 19:48:42 | [diff] [blame] | 12 | #include "remoting/base/decoder.h" |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 13 | #include "remoting/base/encoder.h" |
[email protected] | c3af26f33 | 2010-10-06 22:46:00 | [diff] [blame] | 14 | #include "remoting/base/util.h" |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 15 | #include "testing/gtest/include/gtest/gtest.h" |
| 16 | |
| 17 | static const int kWidth = 320; |
| 18 | static const int kHeight = 240; |
| 19 | static const int kBytesPerPixel = 4; |
| 20 | |
| 21 | // Some sample rects for testing. |
[email protected] | dc454a7c | 2011-08-12 22:01:13 | [diff] [blame] | 22 | static const SkIRect kTestRects[] = { |
| 23 | SkIRect::MakeXYWH(0, 0, kWidth, kHeight), |
| 24 | SkIRect::MakeXYWH(0, 0, kWidth / 2, kHeight / 2), |
| 25 | SkIRect::MakeXYWH(kWidth / 2, kHeight / 2, kWidth / 2, kHeight / 2), |
| 26 | SkIRect::MakeXYWH(16, 16, 16, 16), |
| 27 | SkIRect::MakeXYWH(128, 64, 32, 32), |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 28 | }; |
| 29 | |
| 30 | namespace remoting { |
| 31 | |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 32 | // A class to test the message output of the encoder. |
| 33 | class EncoderMessageTester { |
| 34 | public: |
| 35 | EncoderMessageTester() |
| 36 | : begin_rect_(0), |
| 37 | rect_data_(0), |
| 38 | end_rect_(0), |
[email protected] | 66db1af9 | 2010-07-27 01:42:46 | [diff] [blame] | 39 | added_rects_(0), |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 40 | state_(kWaitingForBeginRect), |
| 41 | strict_(false) { |
| 42 | } |
| 43 | |
| 44 | ~EncoderMessageTester() { |
| 45 | EXPECT_EQ(begin_rect_, end_rect_); |
[email protected] | df10bf1 | 2010-09-28 22:19:48 | [diff] [blame] | 46 | EXPECT_GT(begin_rect_, 0); |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 47 | EXPECT_EQ(kWaitingForBeginRect, state_); |
[email protected] | df10bf1 | 2010-09-28 22:19:48 | [diff] [blame] | 48 | if (strict_) { |
| 49 | EXPECT_EQ(added_rects_, begin_rect_); |
[email protected] | 66db1af9 | 2010-07-27 01:42:46 | [diff] [blame] | 50 | } |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 51 | } |
| 52 | |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 53 | // Test that we received the correct packet. |
| 54 | void ReceivedPacket(VideoPacket* packet) { |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 55 | if (state_ == kWaitingForBeginRect) { |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 56 | EXPECT_TRUE((packet->flags() & VideoPacket::FIRST_PACKET) != 0); |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 57 | state_ = kWaitingForRectData; |
| 58 | ++begin_rect_; |
| 59 | |
| 60 | if (strict_) { |
[email protected] | dc454a7c | 2011-08-12 22:01:13 | [diff] [blame] | 61 | SkIRect rect = rects_.front(); |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 62 | rects_.pop_front(); |
[email protected] | dc454a7c | 2011-08-12 22:01:13 | [diff] [blame] | 63 | EXPECT_EQ(rect.fLeft, packet->format().x()); |
| 64 | EXPECT_EQ(rect.fTop, packet->format().y()); |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 65 | EXPECT_EQ(rect.width(), packet->format().width()); |
| 66 | EXPECT_EQ(rect.height(), packet->format().height()); |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 67 | } |
| 68 | } else { |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 69 | EXPECT_FALSE((packet->flags() & VideoPacket::FIRST_PACKET) != 0); |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | if (state_ == kWaitingForRectData) { |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 73 | if (packet->has_data()) { |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 74 | ++rect_data_; |
| 75 | } |
| 76 | |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 77 | if ((packet->flags() & VideoPacket::LAST_PACKET) != 0) { |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 78 | // Expect that we have received some data. |
| 79 | EXPECT_GT(rect_data_, 0); |
| 80 | rect_data_ = 0; |
| 81 | state_ = kWaitingForBeginRect; |
| 82 | ++end_rect_; |
| 83 | } |
[email protected] | 5bc7183 | 2010-12-09 01:34:08 | [diff] [blame] | 84 | |
| 85 | if ((packet->flags() & VideoPacket::LAST_PARTITION) != 0) { |
| 86 | // LAST_PARTITION must always be marked with LAST_PACKET. |
| 87 | EXPECT_TRUE((packet->flags() & VideoPacket::LAST_PACKET) != 0); |
| 88 | } |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | |
| 92 | void set_strict(bool strict) { |
| 93 | strict_ = strict; |
| 94 | } |
| 95 | |
[email protected] | dc454a7c | 2011-08-12 22:01:13 | [diff] [blame] | 96 | void AddRects(const SkIRect* rects, int count) { |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 97 | rects_.insert(rects_.begin() + rects_.size(), rects, rects + count); |
[email protected] | 66db1af9 | 2010-07-27 01:42:46 | [diff] [blame] | 98 | added_rects_ += count; |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | private: |
| 102 | enum State { |
| 103 | kWaitingForBeginRect, |
| 104 | kWaitingForRectData, |
| 105 | }; |
| 106 | |
| 107 | int begin_rect_; |
| 108 | int rect_data_; |
| 109 | int end_rect_; |
[email protected] | 66db1af9 | 2010-07-27 01:42:46 | [diff] [blame] | 110 | int added_rects_; |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 111 | State state_; |
| 112 | bool strict_; |
| 113 | |
[email protected] | dc454a7c | 2011-08-12 22:01:13 | [diff] [blame] | 114 | std::deque<SkIRect> rects_; |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 115 | |
| 116 | DISALLOW_COPY_AND_ASSIGN(EncoderMessageTester); |
| 117 | }; |
| 118 | |
| 119 | class DecoderTester { |
| 120 | public: |
[email protected] | 542bdfe | 2010-11-30 03:55:47 | [diff] [blame] | 121 | DecoderTester(Decoder* decoder) |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 122 | : strict_(false), |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 123 | decoder_(decoder) { |
[email protected] | 54370ef | 2011-07-18 22:53:05 | [diff] [blame] | 124 | frame_ = media::VideoFrame::CreateFrame(media::VideoFrame::RGB32, |
| 125 | kWidth, kHeight, |
| 126 | base::TimeDelta(), |
| 127 | base::TimeDelta()); |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 128 | EXPECT_TRUE(frame_.get()); |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 129 | decoder_->Initialize(frame_); |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 130 | } |
| 131 | |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 132 | void Reset() { |
| 133 | rects_.clear(); |
| 134 | update_rects_.clear(); |
| 135 | } |
[email protected] | cee5dba | 2010-12-07 03:19:48 | [diff] [blame] | 136 | |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 137 | void ReceivedPacket(VideoPacket* packet) { |
| 138 | Decoder::DecodeResult result = decoder_->DecodePacket(packet); |
[email protected] | cee5dba | 2010-12-07 03:19:48 | [diff] [blame] | 139 | |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 140 | ASSERT_NE(Decoder::DECODE_ERROR, result); |
| 141 | |
| 142 | if (result == Decoder::DECODE_DONE) { |
| 143 | decoder_->GetUpdatedRects(&update_rects_); |
[email protected] | cee5dba | 2010-12-07 03:19:48 | [diff] [blame] | 144 | } |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | void set_strict(bool strict) { |
| 148 | strict_ = strict; |
| 149 | } |
| 150 | |
| 151 | void set_capture_data(scoped_refptr<CaptureData> data) { |
| 152 | capture_data_ = data; |
| 153 | } |
| 154 | |
[email protected] | dc454a7c | 2011-08-12 22:01:13 | [diff] [blame] | 155 | void AddRects(const SkIRect* rects, int count) { |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 156 | rects_.insert(rects_.begin() + rects_.size(), rects, rects + count); |
| 157 | } |
| 158 | |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 159 | void VerifyResults() { |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 160 | if (!strict_) |
| 161 | return; |
[email protected] | 66db1af9 | 2010-07-27 01:42:46 | [diff] [blame] | 162 | |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 163 | ASSERT_TRUE(capture_data_.get()); |
| 164 | |
[email protected] | 66db1af9 | 2010-07-27 01:42:46 | [diff] [blame] | 165 | // Test the content of the update rect. |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 166 | ASSERT_EQ(rects_.size(), update_rects_.size()); |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 167 | for (size_t i = 0; i < update_rects_.size(); ++i) { |
[email protected] | bcad268 | 2011-09-30 20:35:26 | [diff] [blame^] | 168 | EXPECT_EQ(rects_[i], update_rects_[i]); |
[email protected] | 66db1af9 | 2010-07-27 01:42:46 | [diff] [blame] | 169 | |
| 170 | EXPECT_EQ(frame_->stride(0), capture_data_->data_planes().strides[0]); |
| 171 | const int stride = frame_->stride(0); |
[email protected] | bcad268 | 2011-09-30 20:35:26 | [diff] [blame^] | 172 | const int offset = stride * update_rects_[i].fTop + |
| 173 | kBytesPerPixel * update_rects_[i].fLeft; |
[email protected] | 66db1af9 | 2010-07-27 01:42:46 | [diff] [blame] | 174 | const uint8* original = capture_data_->data_planes().data[0] + offset; |
| 175 | const uint8* decoded = frame_->data(0) + offset; |
| 176 | const int row_size = kBytesPerPixel * update_rects_[i].width(); |
| 177 | for (int y = 0; y < update_rects_[i].height(); ++y) { |
| 178 | EXPECT_EQ(0, memcmp(original, decoded, row_size)) |
| 179 | << "Row " << y << " is different"; |
| 180 | original += stride; |
| 181 | decoded += stride; |
| 182 | } |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 183 | } |
| 184 | } |
| 185 | |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 186 | private: |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 187 | bool strict_; |
[email protected] | dc454a7c | 2011-08-12 22:01:13 | [diff] [blame] | 188 | std::deque<SkIRect> rects_; |
[email protected] | bcad268 | 2011-09-30 20:35:26 | [diff] [blame^] | 189 | RectVector update_rects_; |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 190 | Decoder* decoder_; |
| 191 | scoped_refptr<media::VideoFrame> frame_; |
| 192 | scoped_refptr<CaptureData> capture_data_; |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 193 | |
| 194 | DISALLOW_COPY_AND_ASSIGN(DecoderTester); |
| 195 | }; |
| 196 | |
[email protected] | 8ea7a167 | 2010-10-04 19:48:42 | [diff] [blame] | 197 | // The EncoderTester provides a hook for retrieving the data, and passing the |
| 198 | // message to other subprograms for validaton. |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 199 | class EncoderTester { |
| 200 | public: |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 201 | EncoderTester(EncoderMessageTester* message_tester) |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 202 | : message_tester_(message_tester), |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 203 | decoder_tester_(NULL), |
| 204 | data_available_(0) { |
| 205 | } |
| 206 | |
| 207 | ~EncoderTester() { |
| 208 | EXPECT_GT(data_available_, 0); |
| 209 | } |
| 210 | |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 211 | void DataAvailable(VideoPacket *packet) { |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 212 | ++data_available_; |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 213 | message_tester_->ReceivedPacket(packet); |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 214 | |
| 215 | // Send the message to the DecoderTester. |
| 216 | if (decoder_tester_) { |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 217 | decoder_tester_->ReceivedPacket(packet); |
[email protected] | cee5dba | 2010-12-07 03:19:48 | [diff] [blame] | 218 | } |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 219 | |
| 220 | delete packet; |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 221 | } |
| 222 | |
[email protected] | dc454a7c | 2011-08-12 22:01:13 | [diff] [blame] | 223 | void AddRects(const SkIRect* rects, int count) { |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 224 | message_tester_->AddRects(rects, count); |
| 225 | } |
| 226 | |
| 227 | void set_decoder_tester(DecoderTester* decoder_tester) { |
| 228 | decoder_tester_ = decoder_tester; |
| 229 | } |
| 230 | |
| 231 | private: |
| 232 | EncoderMessageTester* message_tester_; |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 233 | DecoderTester* decoder_tester_; |
| 234 | int data_available_; |
| 235 | |
| 236 | DISALLOW_COPY_AND_ASSIGN(EncoderTester); |
| 237 | }; |
| 238 | |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 239 | scoped_refptr<CaptureData> PrepareEncodeData(media::VideoFrame::Format format, |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 240 | uint8** memory) { |
| 241 | // TODO(hclam): Support also YUV format. |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 242 | CHECK_EQ(format, media::VideoFrame::RGB32); |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 243 | int size = kWidth * kHeight * kBytesPerPixel; |
| 244 | |
| 245 | *memory = new uint8[size]; |
| 246 | srand(0); |
| 247 | for (int i = 0; i < size; ++i) { |
| 248 | (*memory)[i] = rand() % 256; |
| 249 | } |
| 250 | |
| 251 | DataPlanes planes; |
| 252 | memset(planes.data, 0, sizeof(planes.data)); |
| 253 | memset(planes.strides, 0, sizeof(planes.strides)); |
| 254 | planes.data[0] = *memory; |
| 255 | planes.strides[0] = kWidth * kBytesPerPixel; |
| 256 | |
| 257 | scoped_refptr<CaptureData> data = |
[email protected] | bcad268 | 2011-09-30 20:35:26 | [diff] [blame^] | 258 | new CaptureData(planes, SkISize::Make(kWidth, kHeight), format); |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 259 | return data; |
| 260 | } |
| 261 | |
| 262 | static void TestEncodingRects(Encoder* encoder, |
| 263 | EncoderTester* tester, |
| 264 | scoped_refptr<CaptureData> data, |
[email protected] | dc454a7c | 2011-08-12 22:01:13 | [diff] [blame] | 265 | const SkIRect* rects, int count) { |
| 266 | data->mutable_dirty_region().setEmpty(); |
[email protected] | 88552a9 | 2010-08-06 22:50:00 | [diff] [blame] | 267 | for (int i = 0; i < count; ++i) { |
[email protected] | dc454a7c | 2011-08-12 22:01:13 | [diff] [blame] | 268 | data->mutable_dirty_region().op(rects[i], SkRegion::kUnion_Op); |
[email protected] | 88552a9 | 2010-08-06 22:50:00 | [diff] [blame] | 269 | } |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 270 | tester->AddRects(rects, count); |
| 271 | |
| 272 | encoder->Encode(data, true, |
| 273 | NewCallback(tester, &EncoderTester::DataAvailable)); |
| 274 | } |
| 275 | |
| 276 | void TestEncoder(Encoder* encoder, bool strict) { |
| 277 | EncoderMessageTester message_tester; |
| 278 | message_tester.set_strict(strict); |
| 279 | |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 280 | EncoderTester tester(&message_tester); |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 281 | |
| 282 | uint8* memory; |
| 283 | scoped_refptr<CaptureData> data = |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 284 | PrepareEncodeData(media::VideoFrame::RGB32, &memory); |
[email protected] | dc454a7c | 2011-08-12 22:01:13 | [diff] [blame] | 285 | scoped_array<uint8> memory_wrapper(memory); |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 286 | |
| 287 | TestEncodingRects(encoder, &tester, data, kTestRects, 1); |
| 288 | TestEncodingRects(encoder, &tester, data, kTestRects + 1, 1); |
| 289 | TestEncodingRects(encoder, &tester, data, kTestRects + 2, 1); |
| 290 | TestEncodingRects(encoder, &tester, data, kTestRects + 3, 2); |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | static void TestEncodingRects(Encoder* encoder, |
| 294 | EncoderTester* encoder_tester, |
| 295 | DecoderTester* decoder_tester, |
| 296 | scoped_refptr<CaptureData> data, |
[email protected] | dc454a7c | 2011-08-12 22:01:13 | [diff] [blame] | 297 | const SkIRect* rects, int count) { |
| 298 | data->mutable_dirty_region().setEmpty(); |
[email protected] | 88552a9 | 2010-08-06 22:50:00 | [diff] [blame] | 299 | for (int i = 0; i < count; ++i) { |
[email protected] | dc454a7c | 2011-08-12 22:01:13 | [diff] [blame] | 300 | data->mutable_dirty_region().op(rects[i], SkRegion::kUnion_Op); |
[email protected] | 88552a9 | 2010-08-06 22:50:00 | [diff] [blame] | 301 | } |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 302 | encoder_tester->AddRects(rects, count); |
| 303 | decoder_tester->AddRects(rects, count); |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 304 | |
[email protected] | 66db1af9 | 2010-07-27 01:42:46 | [diff] [blame] | 305 | // Generate random data for the updated rects. |
| 306 | srand(0); |
| 307 | for (int i = 0; i < count; ++i) { |
[email protected] | dc454a7c | 2011-08-12 22:01:13 | [diff] [blame] | 308 | const SkIRect& rect = rects[i]; |
[email protected] | 66db1af9 | 2010-07-27 01:42:46 | [diff] [blame] | 309 | const int bytes_per_pixel = GetBytesPerPixel(data->pixel_format()); |
| 310 | const int row_size = bytes_per_pixel * rect.width(); |
| 311 | uint8* memory = data->data_planes().data[0] + |
[email protected] | dc454a7c | 2011-08-12 22:01:13 | [diff] [blame] | 312 | data->data_planes().strides[0] * rect.fTop + |
| 313 | bytes_per_pixel * rect.fLeft; |
[email protected] | 66db1af9 | 2010-07-27 01:42:46 | [diff] [blame] | 314 | for (int y = 0; y < rect.height(); ++y) { |
| 315 | for (int x = 0; x < row_size; ++x) |
| 316 | memory[x] = rand() % 256; |
| 317 | memory += data->data_planes().strides[0]; |
| 318 | } |
| 319 | } |
| 320 | |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 321 | encoder->Encode(data, true, |
| 322 | NewCallback(encoder_tester, &EncoderTester::DataAvailable)); |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 323 | decoder_tester->VerifyResults(); |
| 324 | decoder_tester->Reset(); |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 325 | } |
| 326 | |
| 327 | void TestEncoderDecoder(Encoder* encoder, Decoder* decoder, bool strict) { |
| 328 | EncoderMessageTester message_tester; |
| 329 | message_tester.set_strict(strict); |
| 330 | |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 331 | EncoderTester encoder_tester(&message_tester); |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 332 | |
| 333 | uint8* memory; |
| 334 | scoped_refptr<CaptureData> data = |
[email protected] | 137e58f1 | 2010-12-07 19:35:43 | [diff] [blame] | 335 | PrepareEncodeData(media::VideoFrame::RGB32, &memory); |
[email protected] | dc454a7c | 2011-08-12 22:01:13 | [diff] [blame] | 336 | scoped_array<uint8> memory_wrapper(memory); |
| 337 | |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 338 | DecoderTester decoder_tester(decoder); |
| 339 | decoder_tester.set_strict(strict); |
| 340 | decoder_tester.set_capture_data(data); |
| 341 | encoder_tester.set_decoder_tester(&decoder_tester); |
| 342 | |
| 343 | TestEncodingRects(encoder, &encoder_tester, &decoder_tester, data, |
| 344 | kTestRects, 1); |
| 345 | TestEncodingRects(encoder, &encoder_tester, &decoder_tester, data, |
| 346 | kTestRects + 1, 1); |
| 347 | TestEncodingRects(encoder, &encoder_tester, &decoder_tester, data, |
| 348 | kTestRects + 2, 1); |
| 349 | TestEncodingRects(encoder, &encoder_tester, &decoder_tester, data, |
| 350 | kTestRects + 3, 2); |
[email protected] | fb13c76 | 2010-07-24 02:22:07 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | } // namespace remoting |
| 354 | |
| 355 | DISABLE_RUNNABLE_METHOD_REFCOUNT(remoting::DecoderTester); |