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

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

Issue 10870071: Renamed Encoder -> VideoEncoder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed comments Created 8 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/codec/codec_test.h ('k') | remoting/codec/video_decoder_vp8_unittest.cc » ('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 26 matching lines...) Expand all
37 rects.push_back(SkIRect::MakeXYWH(128, 64, 32, 32)); 37 rects.push_back(SkIRect::MakeXYWH(128, 64, 32, 32));
38 rect_lists.push_back(rects); 38 rect_lists.push_back(rects);
39 return rect_lists; 39 return rect_lists;
40 } 40 }
41 41
42 } // namespace 42 } // namespace
43 43
44 namespace remoting { 44 namespace remoting {
45 45
46 // A class to test the message output of the encoder. 46 // A class to test the message output of the encoder.
47 class EncoderMessageTester { 47 class VideoEncoderMessageTester {
48 public: 48 public:
49 EncoderMessageTester() 49 VideoEncoderMessageTester()
50 : begin_rect_(0), 50 : begin_rect_(0),
51 rect_data_(0), 51 rect_data_(0),
52 end_rect_(0), 52 end_rect_(0),
53 added_rects_(0), 53 added_rects_(0),
54 state_(kWaitingForBeginRect), 54 state_(kWaitingForBeginRect),
55 strict_(false) { 55 strict_(false) {
56 } 56 }
57 57
58 ~EncoderMessageTester() { 58 ~VideoEncoderMessageTester() {
59 EXPECT_EQ(begin_rect_, end_rect_); 59 EXPECT_EQ(begin_rect_, end_rect_);
60 EXPECT_GT(begin_rect_, 0); 60 EXPECT_GT(begin_rect_, 0);
61 EXPECT_EQ(kWaitingForBeginRect, state_); 61 EXPECT_EQ(kWaitingForBeginRect, state_);
62 if (strict_) { 62 if (strict_) {
63 EXPECT_EQ(added_rects_, begin_rect_); 63 EXPECT_EQ(added_rects_, begin_rect_);
64 } 64 }
65 } 65 }
66 66
67 // Test that we received the correct packet. 67 // Test that we received the correct packet.
68 void ReceivedPacket(VideoPacket* packet) { 68 void ReceivedPacket(VideoPacket* packet) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 120
121 int begin_rect_; 121 int begin_rect_;
122 int rect_data_; 122 int rect_data_;
123 int end_rect_; 123 int end_rect_;
124 int added_rects_; 124 int added_rects_;
125 State state_; 125 State state_;
126 bool strict_; 126 bool strict_;
127 127
128 std::deque<SkIRect> rects_; 128 std::deque<SkIRect> rects_;
129 129
130 DISALLOW_COPY_AND_ASSIGN(EncoderMessageTester); 130 DISALLOW_COPY_AND_ASSIGN(VideoEncoderMessageTester);
131 }; 131 };
132 132
133 class VideoDecoderTester { 133 class VideoDecoderTester {
134 public: 134 public:
135 VideoDecoderTester(VideoDecoder* decoder, const SkISize& screen_size, 135 VideoDecoderTester(VideoDecoder* decoder, const SkISize& screen_size,
136 const SkISize& view_size) 136 const SkISize& view_size)
137 : screen_size_(screen_size), 137 : screen_size_(screen_size),
138 view_size_(view_size), 138 view_size_(view_size),
139 strict_(false), 139 strict_(false),
140 decoder_(decoder) { 140 decoder_(decoder) {
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 bool strict_; 270 bool strict_;
271 SkRegion expected_region_; 271 SkRegion expected_region_;
272 SkRegion update_region_; 272 SkRegion update_region_;
273 VideoDecoder* decoder_; 273 VideoDecoder* decoder_;
274 scoped_array<uint8> image_data_; 274 scoped_array<uint8> image_data_;
275 scoped_refptr<CaptureData> capture_data_; 275 scoped_refptr<CaptureData> capture_data_;
276 276
277 DISALLOW_COPY_AND_ASSIGN(VideoDecoderTester); 277 DISALLOW_COPY_AND_ASSIGN(VideoDecoderTester);
278 }; 278 };
279 279
280 // The EncoderTester provides a hook for retrieving the data, and passing the 280 // The VideoEncoderTester provides a hook for retrieving the data, and passing
281 // message to other subprograms for validaton. 281 // the message to other subprograms for validaton.
282 class EncoderTester { 282 class VideoEncoderTester {
283 public: 283 public:
284 EncoderTester(EncoderMessageTester* message_tester) 284 VideoEncoderTester(VideoEncoderMessageTester* message_tester)
285 : message_tester_(message_tester), 285 : message_tester_(message_tester),
286 decoder_tester_(NULL), 286 decoder_tester_(NULL),
287 data_available_(0) { 287 data_available_(0) {
288 } 288 }
289 289
290 ~EncoderTester() { 290 ~VideoEncoderTester() {
291 EXPECT_GT(data_available_, 0); 291 EXPECT_GT(data_available_, 0);
292 } 292 }
293 293
294 void DataAvailable(scoped_ptr<VideoPacket> packet) { 294 void DataAvailable(scoped_ptr<VideoPacket> packet) {
295 ++data_available_; 295 ++data_available_;
296 message_tester_->ReceivedPacket(packet.get()); 296 message_tester_->ReceivedPacket(packet.get());
297 297
298 // Send the message to the VideoDecoderTester. 298 // Send the message to the VideoDecoderTester.
299 if (decoder_tester_) { 299 if (decoder_tester_) {
300 decoder_tester_->ReceivedPacket(packet.get()); 300 decoder_tester_->ReceivedPacket(packet.get());
301 } 301 }
302 } 302 }
303 303
304 void AddRects(const SkIRect* rects, int count) { 304 void AddRects(const SkIRect* rects, int count) {
305 message_tester_->AddRects(rects, count); 305 message_tester_->AddRects(rects, count);
306 } 306 }
307 307
308 void set_decoder_tester(VideoDecoderTester* decoder_tester) { 308 void set_decoder_tester(VideoDecoderTester* decoder_tester) {
309 decoder_tester_ = decoder_tester; 309 decoder_tester_ = decoder_tester;
310 } 310 }
311 311
312 private: 312 private:
313 EncoderMessageTester* message_tester_; 313 VideoEncoderMessageTester* message_tester_;
314 VideoDecoderTester* decoder_tester_; 314 VideoDecoderTester* decoder_tester_;
315 int data_available_; 315 int data_available_;
316 316
317 DISALLOW_COPY_AND_ASSIGN(EncoderTester); 317 DISALLOW_COPY_AND_ASSIGN(VideoEncoderTester);
318 }; 318 };
319 319
320 scoped_refptr<CaptureData> PrepareEncodeData(const SkISize& size, 320 scoped_refptr<CaptureData> PrepareEncodeData(const SkISize& size,
321 media::VideoFrame::Format format, 321 media::VideoFrame::Format format,
322 uint8** memory) { 322 uint8** memory) {
323 // TODO(hclam): Support also YUV format. 323 // TODO(hclam): Support also YUV format.
324 CHECK_EQ(format, media::VideoFrame::RGB32); 324 CHECK_EQ(format, media::VideoFrame::RGB32);
325 int memory_size = size.width() * size.height() * kBytesPerPixel; 325 int memory_size = size.width() * size.height() * kBytesPerPixel;
326 326
327 *memory = new uint8[memory_size]; 327 *memory = new uint8[memory_size];
328 srand(0); 328 srand(0);
329 for (int i = 0; i < memory_size; ++i) { 329 for (int i = 0; i < memory_size; ++i) {
330 (*memory)[i] = rand() % 256; 330 (*memory)[i] = rand() % 256;
331 } 331 }
332 332
333 DataPlanes planes; 333 DataPlanes planes;
334 memset(planes.data, 0, sizeof(planes.data)); 334 memset(planes.data, 0, sizeof(planes.data));
335 memset(planes.strides, 0, sizeof(planes.strides)); 335 memset(planes.strides, 0, sizeof(planes.strides));
336 planes.data[0] = *memory; 336 planes.data[0] = *memory;
337 planes.strides[0] = size.width() * kBytesPerPixel; 337 planes.strides[0] = size.width() * kBytesPerPixel;
338 338
339 scoped_refptr<CaptureData> data = 339 scoped_refptr<CaptureData> data =
340 new CaptureData(planes, size, format); 340 new CaptureData(planes, size, format);
341 return data; 341 return data;
342 } 342 }
343 343
344 static void TestEncodingRects(Encoder* encoder, 344 static void TestEncodingRects(VideoEncoder* encoder,
345 EncoderTester* tester, 345 VideoEncoderTester* tester,
346 scoped_refptr<CaptureData> data, 346 scoped_refptr<CaptureData> data,
347 const SkIRect* rects, int count) { 347 const SkIRect* rects, int count) {
348 data->mutable_dirty_region().setEmpty(); 348 data->mutable_dirty_region().setEmpty();
349 for (int i = 0; i < count; ++i) { 349 for (int i = 0; i < count; ++i) {
350 data->mutable_dirty_region().op(rects[i], SkRegion::kUnion_Op); 350 data->mutable_dirty_region().op(rects[i], SkRegion::kUnion_Op);
351 } 351 }
352 tester->AddRects(rects, count); 352 tester->AddRects(rects, count);
353 353
354 encoder->Encode(data, true, base::Bind( 354 encoder->Encode(data, true, base::Bind(
355 &EncoderTester::DataAvailable, base::Unretained(tester))); 355 &VideoEncoderTester::DataAvailable, base::Unretained(tester)));
356 } 356 }
357 357
358 void TestEncoder(Encoder* encoder, bool strict) { 358 void TestVideoEncoder(VideoEncoder* encoder, bool strict) {
359 SkISize kSize = SkISize::Make(320, 240); 359 SkISize kSize = SkISize::Make(320, 240);
360 360
361 EncoderMessageTester message_tester; 361 VideoEncoderMessageTester message_tester;
362 message_tester.set_strict(strict); 362 message_tester.set_strict(strict);
363 363
364 EncoderTester tester(&message_tester); 364 VideoEncoderTester tester(&message_tester);
365 365
366 uint8* memory; 366 uint8* memory;
367 scoped_refptr<CaptureData> data = 367 scoped_refptr<CaptureData> data =
368 PrepareEncodeData(kSize, media::VideoFrame::RGB32, &memory); 368 PrepareEncodeData(kSize, media::VideoFrame::RGB32, &memory);
369 scoped_array<uint8> memory_wrapper(memory); 369 scoped_array<uint8> memory_wrapper(memory);
370 370
371 std::vector<std::vector<SkIRect> > test_rect_lists = MakeTestRectLists(kSize); 371 std::vector<std::vector<SkIRect> > test_rect_lists = MakeTestRectLists(kSize);
372 for (size_t i = 0; i < test_rect_lists.size(); ++i) { 372 for (size_t i = 0; i < test_rect_lists.size(); ++i) {
373 const std::vector<SkIRect>& test_rects = test_rect_lists[i]; 373 const std::vector<SkIRect>& test_rects = test_rect_lists[i];
374 TestEncodingRects(encoder, &tester, data, 374 TestEncodingRects(encoder, &tester, data,
375 &test_rects[0], test_rects.size()); 375 &test_rects[0], test_rects.size());
376 } 376 }
377 } 377 }
378 378
379 static void TestEncodeDecodeRects(Encoder* encoder, 379 static void TestEncodeDecodeRects(VideoEncoder* encoder,
380 EncoderTester* encoder_tester, 380 VideoEncoderTester* encoder_tester,
381 VideoDecoderTester* decoder_tester, 381 VideoDecoderTester* decoder_tester,
382 scoped_refptr<CaptureData> data, 382 scoped_refptr<CaptureData> data,
383 const SkIRect* rects, int count) { 383 const SkIRect* rects, int count) {
384 data->mutable_dirty_region().setRects(rects, count); 384 data->mutable_dirty_region().setRects(rects, count);
385 encoder_tester->AddRects(rects, count); 385 encoder_tester->AddRects(rects, count);
386 decoder_tester->AddRects(rects, count); 386 decoder_tester->AddRects(rects, count);
387 387
388 // Generate random data for the updated region. 388 // Generate random data for the updated region.
389 srand(0); 389 srand(0);
390 for (int i = 0; i < count; ++i) { 390 for (int i = 0; i < count; ++i) {
391 CHECK_EQ(data->pixel_format(), media::VideoFrame::RGB32); 391 CHECK_EQ(data->pixel_format(), media::VideoFrame::RGB32);
392 const int bytes_per_pixel = 4; // Because of RGB32 on previous line. 392 const int bytes_per_pixel = 4; // Because of RGB32 on previous line.
393 const int row_size = bytes_per_pixel * rects[i].width(); 393 const int row_size = bytes_per_pixel * rects[i].width();
394 uint8* memory = data->data_planes().data[0] + 394 uint8* memory = data->data_planes().data[0] +
395 data->data_planes().strides[0] * rects[i].top() + 395 data->data_planes().strides[0] * rects[i].top() +
396 bytes_per_pixel * rects[i].left(); 396 bytes_per_pixel * rects[i].left();
397 for (int y = 0; y < rects[i].height(); ++y) { 397 for (int y = 0; y < rects[i].height(); ++y) {
398 for (int x = 0; x < row_size; ++x) 398 for (int x = 0; x < row_size; ++x)
399 memory[x] = rand() % 256; 399 memory[x] = rand() % 256;
400 memory += data->data_planes().strides[0]; 400 memory += data->data_planes().strides[0];
401 } 401 }
402 } 402 }
403 403
404 encoder->Encode(data, true, base::Bind(&EncoderTester::DataAvailable, 404 encoder->Encode(data, true, base::Bind(&VideoEncoderTester::DataAvailable,
405 base::Unretained(encoder_tester))); 405 base::Unretained(encoder_tester)));
406 decoder_tester->VerifyResults(); 406 decoder_tester->VerifyResults();
407 decoder_tester->Reset(); 407 decoder_tester->Reset();
408 } 408 }
409 409
410 void TestEncoderDecoder(Encoder* encoder, VideoDecoder* decoder, bool strict) { 410 void TestVideoEncoderDecoder(
411 VideoEncoder* encoder, VideoDecoder* decoder, bool strict) {
411 SkISize kSize = SkISize::Make(320, 240); 412 SkISize kSize = SkISize::Make(320, 240);
412 413
413 EncoderMessageTester message_tester; 414 VideoEncoderMessageTester message_tester;
414 message_tester.set_strict(strict); 415 message_tester.set_strict(strict);
415 416
416 EncoderTester encoder_tester(&message_tester); 417 VideoEncoderTester encoder_tester(&message_tester);
417 418
418 uint8* memory; 419 uint8* memory;
419 scoped_refptr<CaptureData> data = 420 scoped_refptr<CaptureData> data =
420 PrepareEncodeData(kSize, media::VideoFrame::RGB32, &memory); 421 PrepareEncodeData(kSize, media::VideoFrame::RGB32, &memory);
421 scoped_array<uint8> memory_wrapper(memory); 422 scoped_array<uint8> memory_wrapper(memory);
422 423
423 VideoDecoderTester decoder_tester(decoder, kSize, kSize); 424 VideoDecoderTester decoder_tester(decoder, kSize, kSize);
424 decoder_tester.set_strict(strict); 425 decoder_tester.set_strict(strict);
425 decoder_tester.set_capture_data(data); 426 decoder_tester.set_capture_data(data);
426 encoder_tester.set_decoder_tester(&decoder_tester); 427 encoder_tester.set_decoder_tester(&decoder_tester);
(...skipping 13 matching lines...) Expand all
440 for (int i = rect.left(); i < rect.right(); ++i) { 441 for (int i = rect.left(); i < rect.right(); ++i) {
441 *p++ = static_cast<uint8>((255.0 * i) / frame_size.width()); 442 *p++ = static_cast<uint8>((255.0 * i) / frame_size.width());
442 *p++ = static_cast<uint8>((164.0 * j) / frame_size.height()); 443 *p++ = static_cast<uint8>((164.0 * j) / frame_size.height());
443 *p++ = static_cast<uint8>((82.0 * (i + j)) / 444 *p++ = static_cast<uint8>((82.0 * (i + j)) /
444 (frame_size.width() + frame_size.height())); 445 (frame_size.width() + frame_size.height()));
445 *p++ = 0; 446 *p++ = 0;
446 } 447 }
447 } 448 }
448 } 449 }
449 450
450 void TestEncoderDecoderGradient(Encoder* encoder, 451 void TestVideoEncoderDecoderGradient(VideoEncoder* encoder,
451 VideoDecoder* decoder, 452 VideoDecoder* decoder,
452 const SkISize& screen_size, 453 const SkISize& screen_size,
453 const SkISize& view_size, 454 const SkISize& view_size,
454 double max_error_limit, 455 double max_error_limit,
455 double mean_error_limit) { 456 double mean_error_limit) {
456 SkIRect screen_rect = SkIRect::MakeSize(screen_size); 457 SkIRect screen_rect = SkIRect::MakeSize(screen_size);
457 scoped_array<uint8> screen_data(new uint8[ 458 scoped_array<uint8> screen_data(new uint8[
458 screen_size.width() * screen_size.height() * kBytesPerPixel]); 459 screen_size.width() * screen_size.height() * kBytesPerPixel]);
459 FillWithGradient(screen_data.get(), screen_size, screen_rect); 460 FillWithGradient(screen_data.get(), screen_size, screen_rect);
460 461
461 SkIRect view_rect = SkIRect::MakeSize(view_size); 462 SkIRect view_rect = SkIRect::MakeSize(view_size);
462 scoped_array<uint8> expected_view_data(new uint8[ 463 scoped_array<uint8> expected_view_data(new uint8[
463 view_size.width() * view_size.height() * kBytesPerPixel]); 464 view_size.width() * view_size.height() * kBytesPerPixel]);
464 FillWithGradient(expected_view_data.get(), view_size, view_rect); 465 FillWithGradient(expected_view_data.get(), view_size, view_rect);
465 466
(...skipping 21 matching lines...) Expand all
487 // Check that the decoder correctly re-renders the frame if its client 488 // Check that the decoder correctly re-renders the frame if its client
488 // invalidates the frame. 489 // invalidates the frame.
489 decoder_tester.ResetRenderedData(); 490 decoder_tester.ResetRenderedData();
490 decoder->Invalidate(view_size, SkRegion(view_rect)); 491 decoder->Invalidate(view_size, SkRegion(view_rect));
491 decoder_tester.RenderFrame(); 492 decoder_tester.RenderFrame();
492 decoder_tester.VerifyResultsApprox(expected_view_data.get(), 493 decoder_tester.VerifyResultsApprox(expected_view_data.get(),
493 max_error_limit, mean_error_limit); 494 max_error_limit, mean_error_limit);
494 } 495 }
495 496
496 } // namespace remoting 497 } // namespace remoting
OLDNEW
« no previous file with comments | « remoting/codec/codec_test.h ('k') | remoting/codec/video_decoder_vp8_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698