OLD | NEW |
1 // Copyright (c) 2012 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" |
11 #include "media/base/video_frame.h" | 11 #include "media/base/video_frame.h" |
(...skipping 113 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 expected_region_.setEmpty(); | 135 rects_.clear(); |
136 update_region_.setEmpty(); | 136 update_rects_.clear(); |
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_->GetUpdatedRegion(&update_region_); | 145 decoder_->GetUpdatedRects(&update_rects_); |
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 SkRegion new_rects; | 158 rects_.insert(rects_.begin() + rects_.size(), rects, rects + count); |
159 new_rects.setRects(rects, count); | |
160 expected_region_.op(new_rects, SkRegion::kUnion_Op); | |
161 } | 159 } |
162 | 160 |
163 void VerifyResults() { | 161 void VerifyResults() { |
164 if (!strict_) | 162 if (!strict_) |
165 return; | 163 return; |
166 | 164 |
167 ASSERT_TRUE(capture_data_.get()); | 165 ASSERT_TRUE(capture_data_.get()); |
168 | 166 |
169 // Test the content of the update region. | 167 // Test the content of the update rect. |
170 EXPECT_EQ(expected_region_, update_region_); | 168 ASSERT_EQ(rects_.size(), update_rects_.size()); |
171 for (SkRegion::Iterator i(update_region_); !i.done(); i.next()) { | 169 for (size_t i = 0; i < update_rects_.size(); ++i) { |
| 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 * i.rect().top() + | 174 const int offset = stride * update_rects_[i].fTop + |
175 kBytesPerPixel * i.rect().left(); | 175 kBytesPerPixel * update_rects_[i].fLeft; |
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 * i.rect().width(); | 178 const int row_size = kBytesPerPixel * update_rects_[i].width(); |
179 for (int y = 0; y < i.rect().height(); ++y) { | 179 for (int y = 0; y < update_rects_[i].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 SkRegion expected_region_; | 190 std::deque<SkIRect> rects_; |
191 SkRegion update_region_; | 191 RectVector update_rects_; |
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 TestEncodeDecodeRects(Encoder* encoder, | 295 static void TestEncodingRects(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().setRects(rects, count); | 300 data->mutable_dirty_region().setEmpty(); |
| 301 for (int i = 0; i < count; ++i) { |
| 302 data->mutable_dirty_region().op(rects[i], SkRegion::kUnion_Op); |
| 303 } |
301 encoder_tester->AddRects(rects, count); | 304 encoder_tester->AddRects(rects, count); |
302 decoder_tester->AddRects(rects, count); | 305 decoder_tester->AddRects(rects, count); |
303 | 306 |
304 // Generate random data for the updated region. | 307 // Generate random data for the updated rects. |
305 srand(0); | 308 srand(0); |
306 for (int i = 0; i < count; ++i) { | 309 for (int i = 0; i < count; ++i) { |
| 310 const SkIRect& rect = rects[i]; |
307 const int bytes_per_pixel = GetBytesPerPixel(data->pixel_format()); | 311 const int bytes_per_pixel = GetBytesPerPixel(data->pixel_format()); |
308 const int row_size = bytes_per_pixel * rects[i].width(); | 312 const int row_size = bytes_per_pixel * rect.width(); |
309 uint8* memory = data->data_planes().data[0] + | 313 uint8* memory = data->data_planes().data[0] + |
310 data->data_planes().strides[0] * rects[i].top() + | 314 data->data_planes().strides[0] * rect.fTop + |
311 bytes_per_pixel * rects[i].left(); | 315 bytes_per_pixel * rect.fLeft; |
312 for (int y = 0; y < rects[i].height(); ++y) { | 316 for (int y = 0; y < rect.height(); ++y) { |
313 for (int x = 0; x < row_size; ++x) | 317 for (int x = 0; x < row_size; ++x) |
314 memory[x] = rand() % 256; | 318 memory[x] = rand() % 256; |
315 memory += data->data_planes().strides[0]; | 319 memory += data->data_planes().strides[0]; |
316 } | 320 } |
317 } | 321 } |
318 | 322 |
319 encoder->Encode(data, true, base::Bind(&EncoderTester::DataAvailable, | 323 encoder->Encode(data, true, base::Bind(&EncoderTester::DataAvailable, |
320 base::Unretained(encoder_tester))); | 324 base::Unretained(encoder_tester))); |
321 decoder_tester->VerifyResults(); | 325 decoder_tester->VerifyResults(); |
322 decoder_tester->Reset(); | 326 decoder_tester->Reset(); |
323 } | 327 } |
324 | 328 |
325 void TestEncoderDecoder(Encoder* encoder, Decoder* decoder, bool strict) { | 329 void TestEncoderDecoder(Encoder* encoder, Decoder* decoder, bool strict) { |
326 EncoderMessageTester message_tester; | 330 EncoderMessageTester message_tester; |
327 message_tester.set_strict(strict); | 331 message_tester.set_strict(strict); |
328 | 332 |
329 EncoderTester encoder_tester(&message_tester); | 333 EncoderTester encoder_tester(&message_tester); |
330 | 334 |
331 uint8* memory; | 335 uint8* memory; |
332 scoped_refptr<CaptureData> data = | 336 scoped_refptr<CaptureData> data = |
333 PrepareEncodeData(media::VideoFrame::RGB32, &memory); | 337 PrepareEncodeData(media::VideoFrame::RGB32, &memory); |
334 scoped_array<uint8> memory_wrapper(memory); | 338 scoped_array<uint8> memory_wrapper(memory); |
335 | 339 |
336 DecoderTester decoder_tester(decoder); | 340 DecoderTester decoder_tester(decoder); |
337 decoder_tester.set_strict(strict); | 341 decoder_tester.set_strict(strict); |
338 decoder_tester.set_capture_data(data); | 342 decoder_tester.set_capture_data(data); |
339 encoder_tester.set_decoder_tester(&decoder_tester); | 343 encoder_tester.set_decoder_tester(&decoder_tester); |
340 | 344 |
341 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, | 345 TestEncodingRects(encoder, &encoder_tester, &decoder_tester, data, |
342 kTestRects, 1); | 346 kTestRects, 1); |
343 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, | 347 TestEncodingRects(encoder, &encoder_tester, &decoder_tester, data, |
344 kTestRects + 1, 1); | 348 kTestRects + 1, 1); |
345 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, | 349 TestEncodingRects(encoder, &encoder_tester, &decoder_tester, data, |
346 kTestRects + 2, 1); | 350 kTestRects + 2, 1); |
347 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, | 351 TestEncodingRects(encoder, &encoder_tester, &decoder_tester, data, |
348 kTestRects + 3, 2); | 352 kTestRects + 3, 2); |
349 } | 353 } |
350 | 354 |
351 } // namespace remoting | 355 } // namespace remoting |
OLD | NEW |