| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 125 decoder_(decoder) { | 125 decoder_(decoder) { |
| 126 frame_ = media::VideoFrame::CreateFrame(media::VideoFrame::RGB32, | 126 frame_ = media::VideoFrame::CreateFrame(media::VideoFrame::RGB32, |
| 127 kWidth, kHeight, | 127 kWidth, kHeight, |
| 128 base::TimeDelta(), | 128 base::TimeDelta(), |
| 129 base::TimeDelta()); | 129 base::TimeDelta()); |
| 130 EXPECT_TRUE(frame_.get()); | 130 EXPECT_TRUE(frame_.get()); |
| 131 decoder_->Initialize(frame_); | 131 decoder_->Initialize(frame_); |
| 132 } | 132 } |
| 133 | 133 |
| 134 void Reset() { | 134 void Reset() { |
| 135 rects_.clear(); | 135 expected_region_.setEmpty(); |
| 136 update_rects_.clear(); | 136 update_region_.setEmpty(); |
| 137 } | 137 } |
| 138 | 138 |
| 139 void ReceivedPacket(VideoPacket* packet) { | 139 void ReceivedPacket(VideoPacket* packet) { |
| 140 Decoder::DecodeResult result = decoder_->DecodePacket(packet); | 140 Decoder::DecodeResult result = decoder_->DecodePacket(packet); |
| 141 | 141 |
| 142 ASSERT_NE(Decoder::DECODE_ERROR, result); | 142 ASSERT_NE(Decoder::DECODE_ERROR, result); |
| 143 | 143 |
| 144 if (result == Decoder::DECODE_DONE) { | 144 if (result == Decoder::DECODE_DONE) { |
| 145 decoder_->GetUpdatedRects(&update_rects_); | 145 decoder_->GetUpdatedRegion(&update_region_); |
| 146 } | 146 } |
| 147 } | 147 } |
| 148 | 148 |
| 149 void set_strict(bool strict) { | 149 void set_strict(bool strict) { |
| 150 strict_ = strict; | 150 strict_ = strict; |
| 151 } | 151 } |
| 152 | 152 |
| 153 void set_capture_data(scoped_refptr<CaptureData> data) { | 153 void set_capture_data(scoped_refptr<CaptureData> data) { |
| 154 capture_data_ = data; | 154 capture_data_ = data; |
| 155 } | 155 } |
| 156 | 156 |
| 157 void AddRects(const SkIRect* rects, int count) { | 157 void AddRects(const SkIRect* rects, int count) { |
| 158 rects_.insert(rects_.begin() + rects_.size(), rects, rects + count); | 158 SkRegion new_rects; |
| 159 new_rects.setRects(rects, count); |
| 160 expected_region_.op(new_rects, SkRegion::kUnion_Op); |
| 159 } | 161 } |
| 160 | 162 |
| 161 void VerifyResults() { | 163 void VerifyResults() { |
| 162 if (!strict_) | 164 if (!strict_) |
| 163 return; | 165 return; |
| 164 | 166 |
| 165 ASSERT_TRUE(capture_data_.get()); | 167 ASSERT_TRUE(capture_data_.get()); |
| 166 | 168 |
| 167 // Test the content of the update rect. | 169 // Test the content of the update region. |
| 168 ASSERT_EQ(rects_.size(), update_rects_.size()); | 170 EXPECT_EQ(expected_region_, update_region_); |
| 169 for (size_t i = 0; i < update_rects_.size(); ++i) { | 171 for (SkRegion::Iterator i(update_region_); !i.done(); i.next()) { |
| 170 EXPECT_EQ(rects_[i], update_rects_[i]); | |
| 171 | |
| 172 EXPECT_EQ(frame_->stride(0), capture_data_->data_planes().strides[0]); | 172 EXPECT_EQ(frame_->stride(0), capture_data_->data_planes().strides[0]); |
| 173 const int stride = frame_->stride(0); | 173 const int stride = frame_->stride(0); |
| 174 const int offset = stride * update_rects_[i].fTop + | 174 const int offset = stride * i.rect().top() + |
| 175 kBytesPerPixel * update_rects_[i].fLeft; | 175 kBytesPerPixel * i.rect().left(); |
| 176 const uint8* original = capture_data_->data_planes().data[0] + offset; | 176 const uint8* original = capture_data_->data_planes().data[0] + offset; |
| 177 const uint8* decoded = frame_->data(0) + offset; | 177 const uint8* decoded = frame_->data(0) + offset; |
| 178 const int row_size = kBytesPerPixel * update_rects_[i].width(); | 178 const int row_size = kBytesPerPixel * i.rect().width(); |
| 179 for (int y = 0; y < update_rects_[i].height(); ++y) { | 179 for (int y = 0; y < i.rect().height(); ++y) { |
| 180 EXPECT_EQ(0, memcmp(original, decoded, row_size)) | 180 EXPECT_EQ(0, memcmp(original, decoded, row_size)) |
| 181 << "Row " << y << " is different"; | 181 << "Row " << y << " is different"; |
| 182 original += stride; | 182 original += stride; |
| 183 decoded += stride; | 183 decoded += stride; |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 } | 186 } |
| 187 | 187 |
| 188 private: | 188 private: |
| 189 bool strict_; | 189 bool strict_; |
| 190 std::deque<SkIRect> rects_; | 190 SkRegion expected_region_; |
| 191 RectVector update_rects_; | 191 SkRegion update_region_; |
| 192 Decoder* decoder_; | 192 Decoder* decoder_; |
| 193 scoped_refptr<media::VideoFrame> frame_; | 193 scoped_refptr<media::VideoFrame> frame_; |
| 194 scoped_refptr<CaptureData> capture_data_; | 194 scoped_refptr<CaptureData> capture_data_; |
| 195 | 195 |
| 196 DISALLOW_COPY_AND_ASSIGN(DecoderTester); | 196 DISALLOW_COPY_AND_ASSIGN(DecoderTester); |
| 197 }; | 197 }; |
| 198 | 198 |
| 199 // The EncoderTester provides a hook for retrieving the data, and passing the | 199 // The EncoderTester provides a hook for retrieving the data, and passing the |
| 200 // message to other subprograms for validaton. | 200 // message to other subprograms for validaton. |
| 201 class EncoderTester { | 201 class EncoderTester { |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 scoped_refptr<CaptureData> data = | 285 scoped_refptr<CaptureData> data = |
| 286 PrepareEncodeData(media::VideoFrame::RGB32, &memory); | 286 PrepareEncodeData(media::VideoFrame::RGB32, &memory); |
| 287 scoped_array<uint8> memory_wrapper(memory); | 287 scoped_array<uint8> memory_wrapper(memory); |
| 288 | 288 |
| 289 TestEncodingRects(encoder, &tester, data, kTestRects, 1); | 289 TestEncodingRects(encoder, &tester, data, kTestRects, 1); |
| 290 TestEncodingRects(encoder, &tester, data, kTestRects + 1, 1); | 290 TestEncodingRects(encoder, &tester, data, kTestRects + 1, 1); |
| 291 TestEncodingRects(encoder, &tester, data, kTestRects + 2, 1); | 291 TestEncodingRects(encoder, &tester, data, kTestRects + 2, 1); |
| 292 TestEncodingRects(encoder, &tester, data, kTestRects + 3, 2); | 292 TestEncodingRects(encoder, &tester, data, kTestRects + 3, 2); |
| 293 } | 293 } |
| 294 | 294 |
| 295 static void TestEncodingRects(Encoder* encoder, | 295 static void TestEncodeDecodeRects(Encoder* encoder, |
| 296 EncoderTester* encoder_tester, | 296 EncoderTester* encoder_tester, |
| 297 DecoderTester* decoder_tester, | 297 DecoderTester* decoder_tester, |
| 298 scoped_refptr<CaptureData> data, | 298 scoped_refptr<CaptureData> data, |
| 299 const SkIRect* rects, int count) { | 299 const SkIRect* rects, int count) { |
| 300 data->mutable_dirty_region().setEmpty(); | 300 data->mutable_dirty_region().setRects(rects, count); |
| 301 for (int i = 0; i < count; ++i) { | |
| 302 data->mutable_dirty_region().op(rects[i], SkRegion::kUnion_Op); | |
| 303 } | |
| 304 encoder_tester->AddRects(rects, count); | 301 encoder_tester->AddRects(rects, count); |
| 305 decoder_tester->AddRects(rects, count); | 302 decoder_tester->AddRects(rects, count); |
| 306 | 303 |
| 307 // Generate random data for the updated rects. | 304 // Generate random data for the updated region. |
| 308 srand(0); | 305 srand(0); |
| 309 for (int i = 0; i < count; ++i) { | 306 for (int i = 0; i < count; ++i) { |
| 310 const SkIRect& rect = rects[i]; | |
| 311 const int bytes_per_pixel = GetBytesPerPixel(data->pixel_format()); | 307 const int bytes_per_pixel = GetBytesPerPixel(data->pixel_format()); |
| 312 const int row_size = bytes_per_pixel * rect.width(); | 308 const int row_size = bytes_per_pixel * rects[i].width(); |
| 313 uint8* memory = data->data_planes().data[0] + | 309 uint8* memory = data->data_planes().data[0] + |
| 314 data->data_planes().strides[0] * rect.fTop + | 310 data->data_planes().strides[0] * rects[i].top() + |
| 315 bytes_per_pixel * rect.fLeft; | 311 bytes_per_pixel * rects[i].left(); |
| 316 for (int y = 0; y < rect.height(); ++y) { | 312 for (int y = 0; y < rects[i].height(); ++y) { |
| 317 for (int x = 0; x < row_size; ++x) | 313 for (int x = 0; x < row_size; ++x) |
| 318 memory[x] = rand() % 256; | 314 memory[x] = rand() % 256; |
| 319 memory += data->data_planes().strides[0]; | 315 memory += data->data_planes().strides[0]; |
| 320 } | 316 } |
| 321 } | 317 } |
| 322 | 318 |
| 323 encoder->Encode(data, true, base::Bind(&EncoderTester::DataAvailable, | 319 encoder->Encode(data, true, base::Bind(&EncoderTester::DataAvailable, |
| 324 base::Unretained(encoder_tester))); | 320 base::Unretained(encoder_tester))); |
| 325 decoder_tester->VerifyResults(); | 321 decoder_tester->VerifyResults(); |
| 326 decoder_tester->Reset(); | 322 decoder_tester->Reset(); |
| 327 } | 323 } |
| 328 | 324 |
| 329 void TestEncoderDecoder(Encoder* encoder, Decoder* decoder, bool strict) { | 325 void TestEncoderDecoder(Encoder* encoder, Decoder* decoder, bool strict) { |
| 330 EncoderMessageTester message_tester; | 326 EncoderMessageTester message_tester; |
| 331 message_tester.set_strict(strict); | 327 message_tester.set_strict(strict); |
| 332 | 328 |
| 333 EncoderTester encoder_tester(&message_tester); | 329 EncoderTester encoder_tester(&message_tester); |
| 334 | 330 |
| 335 uint8* memory; | 331 uint8* memory; |
| 336 scoped_refptr<CaptureData> data = | 332 scoped_refptr<CaptureData> data = |
| 337 PrepareEncodeData(media::VideoFrame::RGB32, &memory); | 333 PrepareEncodeData(media::VideoFrame::RGB32, &memory); |
| 338 scoped_array<uint8> memory_wrapper(memory); | 334 scoped_array<uint8> memory_wrapper(memory); |
| 339 | 335 |
| 340 DecoderTester decoder_tester(decoder); | 336 DecoderTester decoder_tester(decoder); |
| 341 decoder_tester.set_strict(strict); | 337 decoder_tester.set_strict(strict); |
| 342 decoder_tester.set_capture_data(data); | 338 decoder_tester.set_capture_data(data); |
| 343 encoder_tester.set_decoder_tester(&decoder_tester); | 339 encoder_tester.set_decoder_tester(&decoder_tester); |
| 344 | 340 |
| 345 TestEncodingRects(encoder, &encoder_tester, &decoder_tester, data, | 341 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, |
| 346 kTestRects, 1); | 342 kTestRects, 1); |
| 347 TestEncodingRects(encoder, &encoder_tester, &decoder_tester, data, | 343 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, |
| 348 kTestRects + 1, 1); | 344 kTestRects + 1, 1); |
| 349 TestEncodingRects(encoder, &encoder_tester, &decoder_tester, data, | 345 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, |
| 350 kTestRects + 2, 1); | 346 kTestRects + 2, 1); |
| 351 TestEncodingRects(encoder, &encoder_tester, &decoder_tester, data, | 347 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, |
| 352 kTestRects + 3, 2); | 348 kTestRects + 3, 2); |
| 353 } | 349 } |
| 354 | 350 |
| 355 } // namespace remoting | 351 } // namespace remoting |
| OLD | NEW |