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

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: 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 | « 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]; 327 memory->reset(new uint8[memory_size]);
328
328 srand(0); 329 srand(0);
329 for (int i = 0; i < memory_size; ++i) { 330 for (int i = 0; i < memory_size; ++i) {
330 (*memory)[i] = rand() % 256; 331 (*memory)[i] = rand() % 256;
331 } 332 }
332 333
333 DataPlanes planes; 334 DataPlanes planes;
334 memset(planes.data, 0, sizeof(planes.data)); 335 memset(planes.data, 0, sizeof(planes.data));
335 memset(planes.strides, 0, sizeof(planes.strides)); 336 memset(planes.strides, 0, sizeof(planes.strides));
336 planes.data[0] = *memory; 337 planes.data[0] = memory->get();
337 planes.strides[0] = size.width() * kBytesPerPixel; 338 planes.strides[0] = size.width() * kBytesPerPixel;
338 339
339 scoped_refptr<CaptureData> data = 340 scoped_refptr<CaptureData> data =
340 new CaptureData(planes, size, format); 341 new CaptureData(planes, size, format);
341 return data; 342 return data;
342 } 343 }
343 344
344 static void TestEncodingRects(VideoEncoder* encoder, 345 static void TestEncodingRects(VideoEncoder* encoder,
345 VideoEncoderTester* tester, 346 VideoEncoderTester* tester,
346 scoped_refptr<CaptureData> data, 347 scoped_refptr<CaptureData> data,
347 const SkIRect* rects, int count) { 348 const SkIRect* rects, int count) {
348 data->mutable_dirty_region().setEmpty(); 349 data->mutable_dirty_region().setEmpty();
349 for (int i = 0; i < count; ++i) { 350 for (int i = 0; i < count; ++i) {
350 data->mutable_dirty_region().op(rects[i], SkRegion::kUnion_Op); 351 data->mutable_dirty_region().op(rects[i], SkRegion::kUnion_Op);
351 } 352 }
352 tester->AddRects(rects, count); 353 tester->AddRects(rects, count);
353 354
354 encoder->Encode(data, true, base::Bind( 355 encoder->Encode(data, true, base::Bind(
355 &VideoEncoderTester::DataAvailable, base::Unretained(tester))); 356 &VideoEncoderTester::DataAvailable, base::Unretained(tester)));
356 } 357 }
357 358
358 void TestVideoEncoder(VideoEncoder* encoder, bool strict) { 359 void TestVideoEncoder(VideoEncoder* encoder, bool strict) {
359 SkISize kSize = SkISize::Make(320, 240); 360 SkISize kSize = SkISize::Make(320, 240);
360 361
361 VideoEncoderMessageTester message_tester; 362 VideoEncoderMessageTester message_tester;
362 message_tester.set_strict(strict); 363 message_tester.set_strict(strict);
363 364
364 VideoEncoderTester tester(&message_tester); 365 VideoEncoderTester tester(&message_tester);
365 366
366 uint8* memory; 367 scoped_array<uint8> memory;
367 scoped_refptr<CaptureData> data = 368 scoped_refptr<CaptureData> data =
368 PrepareEncodeData(kSize, media::VideoFrame::RGB32, &memory); 369 PrepareEncodeData(kSize, media::VideoFrame::RGB32, &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(VideoEncoder* encoder, 379 static void TestEncodeDecodeRects(VideoEncoder* encoder,
(...skipping 29 matching lines...) Expand all
409 409
410 void TestVideoEncoderDecoder( 410 void TestVideoEncoderDecoder(
411 VideoEncoder* encoder, VideoDecoder* decoder, bool strict) { 411 VideoEncoder* encoder, VideoDecoder* decoder, bool strict) {
412 SkISize kSize = SkISize::Make(320, 240); 412 SkISize kSize = SkISize::Make(320, 240);
413 413
414 VideoEncoderMessageTester message_tester; 414 VideoEncoderMessageTester message_tester;
415 message_tester.set_strict(strict); 415 message_tester.set_strict(strict);
416 416
417 VideoEncoderTester encoder_tester(&message_tester); 417 VideoEncoderTester encoder_tester(&message_tester);
418 418
419 uint8* memory; 419 scoped_array<uint8> memory;
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