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

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

Issue 10871068: Cleaned up codec_test.cc (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 | « no previous file | no next file » | 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 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 private: 312 private:
313 VideoEncoderMessageTester* 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(VideoEncoderTester); 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 scoped_array<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];
Wez 2012/08/24 20:57:31 This allocates a buffer of the necessary size; you
kxing 2012/08/24 21:28:30 Done.
328 srand(0); 327 srand(0);
329 for (int i = 0; i < memory_size; ++i) { 328 for (int i = 0; i < memory_size; ++i) {
330 (*memory)[i] = rand() % 256; 329 (*memory)[i] = rand() % 256;
331 } 330 }
332 331
333 DataPlanes planes; 332 DataPlanes planes;
334 memset(planes.data, 0, sizeof(planes.data)); 333 memset(planes.data, 0, sizeof(planes.data));
335 memset(planes.strides, 0, sizeof(planes.strides)); 334 memset(planes.strides, 0, sizeof(planes.strides));
336 planes.data[0] = *memory; 335 planes.data[0] = memory->get();
337 planes.strides[0] = size.width() * kBytesPerPixel; 336 planes.strides[0] = size.width() * kBytesPerPixel;
338 337
339 scoped_refptr<CaptureData> data = 338 scoped_refptr<CaptureData> data =
340 new CaptureData(planes, size, format); 339 new CaptureData(planes, size, format);
341 return data; 340 return data;
342 } 341 }
343 342
344 static void TestEncodingRects(VideoEncoder* encoder, 343 static void TestEncodingRects(VideoEncoder* encoder,
345 VideoEncoderTester* tester, 344 VideoEncoderTester* tester,
346 scoped_refptr<CaptureData> data, 345 scoped_refptr<CaptureData> data,
347 const SkIRect* rects, int count) { 346 const SkIRect* rects, int count) {
348 data->mutable_dirty_region().setEmpty(); 347 data->mutable_dirty_region().setEmpty();
349 for (int i = 0; i < count; ++i) { 348 for (int i = 0; i < count; ++i) {
350 data->mutable_dirty_region().op(rects[i], SkRegion::kUnion_Op); 349 data->mutable_dirty_region().op(rects[i], SkRegion::kUnion_Op);
351 } 350 }
352 tester->AddRects(rects, count); 351 tester->AddRects(rects, count);
353 352
354 encoder->Encode(data, true, base::Bind( 353 encoder->Encode(data, true, base::Bind(
355 &VideoEncoderTester::DataAvailable, base::Unretained(tester))); 354 &VideoEncoderTester::DataAvailable, base::Unretained(tester)));
356 } 355 }
357 356
358 void TestVideoEncoder(VideoEncoder* encoder, bool strict) { 357 void TestVideoEncoder(VideoEncoder* encoder, bool strict) {
359 SkISize kSize = SkISize::Make(320, 240); 358 SkISize kSize = SkISize::Make(320, 240);
360 359
361 VideoEncoderMessageTester message_tester; 360 VideoEncoderMessageTester message_tester;
362 message_tester.set_strict(strict); 361 message_tester.set_strict(strict);
363 362
364 VideoEncoderTester tester(&message_tester); 363 VideoEncoderTester tester(&message_tester);
365 364
366 uint8* memory; 365 scoped_array<uint8> memory(
366 new uint8[kSize.width() * kSize.height() * kBytesPerPixel]);
Wez 2012/08/24 20:57:31 Move this back into PrepareEncodeData, as per prev
kxing 2012/08/24 21:28:30 Done.
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);
370 369
371 std::vector<std::vector<SkIRect> > test_rect_lists = MakeTestRectLists(kSize); 370 std::vector<std::vector<SkIRect> > test_rect_lists = MakeTestRectLists(kSize);
372 for (size_t i = 0; i < test_rect_lists.size(); ++i) { 371 for (size_t i = 0; i < test_rect_lists.size(); ++i) {
373 const std::vector<SkIRect>& test_rects = test_rect_lists[i]; 372 const std::vector<SkIRect>& test_rects = test_rect_lists[i];
374 TestEncodingRects(encoder, &tester, data, 373 TestEncodingRects(encoder, &tester, data,
375 &test_rects[0], test_rects.size()); 374 &test_rects[0], test_rects.size());
376 } 375 }
377 } 376 }
378 377
379 static void TestEncodeDecodeRects(VideoEncoder* encoder, 378 static void TestEncodeDecodeRects(VideoEncoder* encoder,
(...skipping 29 matching lines...) Expand all
409 408
410 void TestVideoEncoderDecoder( 409 void TestVideoEncoderDecoder(
411 VideoEncoder* encoder, VideoDecoder* decoder, bool strict) { 410 VideoEncoder* encoder, VideoDecoder* decoder, bool strict) {
412 SkISize kSize = SkISize::Make(320, 240); 411 SkISize kSize = SkISize::Make(320, 240);
413 412
414 VideoEncoderMessageTester message_tester; 413 VideoEncoderMessageTester message_tester;
415 message_tester.set_strict(strict); 414 message_tester.set_strict(strict);
416 415
417 VideoEncoderTester encoder_tester(&message_tester); 416 VideoEncoderTester encoder_tester(&message_tester);
418 417
419 uint8* memory; 418 scoped_array<uint8> memory(
419 new uint8[kSize.width() * kSize.height() * kBytesPerPixel]);
420 scoped_refptr<CaptureData> data = 420 scoped_refptr<CaptureData> data =
421 PrepareEncodeData(kSize, media::VideoFrame::RGB32, &memory); 421 PrepareEncodeData(kSize, media::VideoFrame::RGB32, &memory);
422 scoped_array<uint8> memory_wrapper(memory);
423 422
424 VideoDecoderTester decoder_tester(decoder, kSize, kSize); 423 VideoDecoderTester decoder_tester(decoder, kSize, kSize);
425 decoder_tester.set_strict(strict); 424 decoder_tester.set_strict(strict);
426 decoder_tester.set_capture_data(data); 425 decoder_tester.set_capture_data(data);
427 encoder_tester.set_decoder_tester(&decoder_tester); 426 encoder_tester.set_decoder_tester(&decoder_tester);
428 427
429 std::vector<std::vector<SkIRect> > test_rect_lists = MakeTestRectLists(kSize); 428 std::vector<std::vector<SkIRect> > test_rect_lists = MakeTestRectLists(kSize);
430 for (size_t i = 0; i < test_rect_lists.size(); ++i) { 429 for (size_t i = 0; i < test_rect_lists.size(); ++i) {
431 const std::vector<SkIRect> test_rects = test_rect_lists[i]; 430 const std::vector<SkIRect> test_rects = test_rect_lists[i];
432 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data, 431 TestEncodeDecodeRects(encoder, &encoder_tester, &decoder_tester, data,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 // Check that the decoder correctly re-renders the frame if its client 487 // Check that the decoder correctly re-renders the frame if its client
489 // invalidates the frame. 488 // invalidates the frame.
490 decoder_tester.ResetRenderedData(); 489 decoder_tester.ResetRenderedData();
491 decoder->Invalidate(view_size, SkRegion(view_rect)); 490 decoder->Invalidate(view_size, SkRegion(view_rect));
492 decoder_tester.RenderFrame(); 491 decoder_tester.RenderFrame();
493 decoder_tester.VerifyResultsApprox(expected_view_data.get(), 492 decoder_tester.VerifyResultsApprox(expected_view_data.get(),
494 max_error_limit, mean_error_limit); 493 max_error_limit, mean_error_limit);
495 } 494 }
496 495
497 } // namespace remoting 496 } // namespace remoting
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698