OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // This has to be included first. | 5 // This has to be included first. |
6 // See http://code.google.com/p/googletest/issues/detail?id=371 | 6 // See http://code.google.com/p/googletest/issues/detail?id=371 |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 #include <string.h> | 11 #include <string.h> |
12 | 12 |
13 #include <memory> | 13 #include <memory> |
14 | 14 |
15 #include "base/at_exit.h" | 15 #include "base/at_exit.h" |
16 #include "base/bind.h" | 16 #include "base/bind.h" |
17 #include "base/command_line.h" | 17 #include "base/command_line.h" |
18 #include "base/files/file_util.h" | 18 #include "base/files/file_util.h" |
19 #include "base/logging.h" | 19 #include "base/logging.h" |
20 #include "base/macros.h" | 20 #include "base/macros.h" |
21 #include "base/memory/scoped_vector.h" | 21 #include "base/memory/ptr_util.h" |
22 #include "base/path_service.h" | 22 #include "base/path_service.h" |
23 #include "base/strings/string_piece.h" | 23 #include "base/strings/string_piece.h" |
24 #include "base/strings/string_split.h" | 24 #include "base/strings/string_split.h" |
25 #include "base/threading/thread_task_runner_handle.h" | 25 #include "base/threading/thread_task_runner_handle.h" |
26 #include "build/build_config.h" | 26 #include "build/build_config.h" |
27 #include "media/base/test_data_util.h" | 27 #include "media/base/test_data_util.h" |
28 #include "media/filters/jpeg_parser.h" | 28 #include "media/filters/jpeg_parser.h" |
29 #include "media/gpu/video_accelerator_unittest_helpers.h" | 29 #include "media/gpu/video_accelerator_unittest_helpers.h" |
30 #include "media/video/jpeg_decode_accelerator.h" | 30 #include "media/video/jpeg_decode_accelerator.h" |
31 #include "third_party/libyuv/include/libyuv.h" | 31 #include "third_party/libyuv/include/libyuv.h" |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 std::unique_ptr<TestImageFile> image_data_1280x720_black_; | 317 std::unique_ptr<TestImageFile> image_data_1280x720_black_; |
318 // Parsed data of |test_640x368_jpeg_file_|. | 318 // Parsed data of |test_640x368_jpeg_file_|. |
319 std::unique_ptr<TestImageFile> image_data_640x368_black_; | 319 std::unique_ptr<TestImageFile> image_data_640x368_black_; |
320 // Parsed data of |test_640x360_jpeg_file_|. | 320 // Parsed data of |test_640x360_jpeg_file_|. |
321 std::unique_ptr<TestImageFile> image_data_640x360_black_; | 321 std::unique_ptr<TestImageFile> image_data_640x360_black_; |
322 // Parsed data of "peach_pi-1280x720.jpg". | 322 // Parsed data of "peach_pi-1280x720.jpg". |
323 std::unique_ptr<TestImageFile> image_data_1280x720_default_; | 323 std::unique_ptr<TestImageFile> image_data_1280x720_default_; |
324 // Parsed data of failure image. | 324 // Parsed data of failure image. |
325 std::unique_ptr<TestImageFile> image_data_invalid_; | 325 std::unique_ptr<TestImageFile> image_data_invalid_; |
326 // Parsed data from command line. | 326 // Parsed data from command line. |
327 ScopedVector<TestImageFile> image_data_user_; | 327 std::vector<std::unique_ptr<TestImageFile>> image_data_user_; |
328 | 328 |
329 private: | 329 private: |
330 const base::FilePath::CharType* user_jpeg_filenames_; | 330 const base::FilePath::CharType* user_jpeg_filenames_; |
331 | 331 |
332 // Used for InputSizeChange test case. The image size should be smaller than | 332 // Used for InputSizeChange test case. The image size should be smaller than |
333 // |kDefaultJpegFilename|. | 333 // |kDefaultJpegFilename|. |
334 base::FilePath test_1280x720_jpeg_file_; | 334 base::FilePath test_1280x720_jpeg_file_; |
335 // Used for ResolutionChange test case. | 335 // Used for ResolutionChange test case. |
336 base::FilePath test_640x368_jpeg_file_; | 336 base::FilePath test_640x368_jpeg_file_; |
337 // Used for testing some drivers which will align the output resolution to a | 337 // Used for testing some drivers which will align the output resolution to a |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
369 image_data_invalid_->visible_size.SetSize(1280, 720); | 369 image_data_invalid_->visible_size.SetSize(1280, 720); |
370 image_data_invalid_->output_size = VideoFrame::AllocationSize( | 370 image_data_invalid_->output_size = VideoFrame::AllocationSize( |
371 PIXEL_FORMAT_I420, image_data_invalid_->visible_size); | 371 PIXEL_FORMAT_I420, image_data_invalid_->visible_size); |
372 | 372 |
373 // |user_jpeg_filenames_| may include many files and use ';' as delimiter. | 373 // |user_jpeg_filenames_| may include many files and use ';' as delimiter. |
374 std::vector<base::FilePath::StringType> filenames = base::SplitString( | 374 std::vector<base::FilePath::StringType> filenames = base::SplitString( |
375 user_jpeg_filenames_, base::FilePath::StringType(1, ';'), | 375 user_jpeg_filenames_, base::FilePath::StringType(1, ';'), |
376 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 376 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
377 for (const auto& filename : filenames) { | 377 for (const auto& filename : filenames) { |
378 base::FilePath input_file = GetTestDataFilePath(filename); | 378 base::FilePath input_file = GetTestDataFilePath(filename); |
379 TestImageFile* image_data = new TestImageFile(filename); | 379 auto image_data = base::MakeUnique<TestImageFile>(filename); |
380 ASSERT_NO_FATAL_FAILURE(ReadTestJpegImage(input_file, image_data)); | 380 ASSERT_NO_FATAL_FAILURE(ReadTestJpegImage(input_file, image_data.get())); |
381 image_data_user_.push_back(image_data); | 381 image_data_user_.push_back(std::move(image_data)); |
382 } | 382 } |
383 } | 383 } |
384 | 384 |
385 void JpegDecodeAcceleratorTestEnvironment::TearDown() { | 385 void JpegDecodeAcceleratorTestEnvironment::TearDown() { |
386 base::DeleteFile(test_1280x720_jpeg_file_, false); | 386 base::DeleteFile(test_1280x720_jpeg_file_, false); |
387 base::DeleteFile(test_640x368_jpeg_file_, false); | 387 base::DeleteFile(test_640x368_jpeg_file_, false); |
388 base::DeleteFile(test_640x360_jpeg_file_, false); | 388 base::DeleteFile(test_640x360_jpeg_file_, false); |
389 } | 389 } |
390 | 390 |
391 bool JpegDecodeAcceleratorTestEnvironment::CreateTestJpegImage( | 391 bool JpegDecodeAcceleratorTestEnvironment::CreateTestJpegImage( |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 | 436 |
437 protected: | 437 protected: |
438 DISALLOW_COPY_AND_ASSIGN(JpegDecodeAcceleratorTest); | 438 DISALLOW_COPY_AND_ASSIGN(JpegDecodeAcceleratorTest); |
439 }; | 439 }; |
440 | 440 |
441 void JpegDecodeAcceleratorTest::TestDecode(size_t num_concurrent_decoders) { | 441 void JpegDecodeAcceleratorTest::TestDecode(size_t num_concurrent_decoders) { |
442 LOG_ASSERT(test_image_files_.size() >= expected_status_.size()); | 442 LOG_ASSERT(test_image_files_.size() >= expected_status_.size()); |
443 base::Thread decoder_thread("DecoderThread"); | 443 base::Thread decoder_thread("DecoderThread"); |
444 ASSERT_TRUE(decoder_thread.Start()); | 444 ASSERT_TRUE(decoder_thread.Start()); |
445 | 445 |
446 ScopedVector<ClientStateNotification<ClientState>> notes; | 446 std::vector<std::unique_ptr<ClientStateNotification<ClientState>>> notes; |
447 ScopedVector<JpegClient> clients; | 447 std::vector<std::unique_ptr<JpegClient>> clients; |
448 | 448 |
449 for (size_t i = 0; i < num_concurrent_decoders; i++) { | 449 for (size_t i = 0; i < num_concurrent_decoders; i++) { |
450 notes.push_back(new ClientStateNotification<ClientState>()); | 450 notes.push_back(base::MakeUnique<ClientStateNotification<ClientState>>()); |
451 clients.push_back(new JpegClient(test_image_files_, notes.back())); | 451 clients.push_back( |
| 452 base::MakeUnique<JpegClient>(test_image_files_, notes.back().get())); |
452 decoder_thread.task_runner()->PostTask( | 453 decoder_thread.task_runner()->PostTask( |
453 FROM_HERE, base::Bind(&JpegClient::CreateJpegDecoder, | 454 FROM_HERE, base::Bind(&JpegClient::CreateJpegDecoder, |
454 base::Unretained(clients.back()))); | 455 base::Unretained(clients.back().get()))); |
455 ASSERT_EQ(notes[i]->Wait(), CS_INITIALIZED); | 456 ASSERT_EQ(notes[i]->Wait(), CS_INITIALIZED); |
456 } | 457 } |
457 | 458 |
458 for (size_t index = 0; index < test_image_files_.size(); index++) { | 459 for (size_t index = 0; index < test_image_files_.size(); index++) { |
459 for (size_t i = 0; i < num_concurrent_decoders; i++) { | 460 for (size_t i = 0; i < num_concurrent_decoders; i++) { |
460 decoder_thread.task_runner()->PostTask( | 461 decoder_thread.task_runner()->PostTask( |
461 FROM_HERE, base::Bind(&JpegClient::StartDecode, | 462 FROM_HERE, base::Bind(&JpegClient::StartDecode, |
462 base::Unretained(clients[i]), index)); | 463 base::Unretained(clients[i].get()), index)); |
463 } | 464 } |
464 if (index < expected_status_.size()) { | 465 if (index < expected_status_.size()) { |
465 for (size_t i = 0; i < num_concurrent_decoders; i++) { | 466 for (size_t i = 0; i < num_concurrent_decoders; i++) { |
466 ASSERT_EQ(notes[i]->Wait(), expected_status_[index]); | 467 ASSERT_EQ(notes[i]->Wait(), expected_status_[index]); |
467 } | 468 } |
468 } | 469 } |
469 } | 470 } |
470 | 471 |
471 for (size_t i = 0; i < num_concurrent_decoders; i++) { | 472 for (size_t i = 0; i < num_concurrent_decoders; i++) { |
472 decoder_thread.task_runner()->PostTask( | 473 decoder_thread.task_runner()->PostTask( |
473 FROM_HERE, base::Bind(&JpegClient::DestroyJpegDecoder, | 474 FROM_HERE, base::Bind(&JpegClient::DestroyJpegDecoder, |
474 base::Unretained(clients[i]))); | 475 base::Unretained(clients[i].get()))); |
475 } | 476 } |
476 decoder_thread.Stop(); | 477 decoder_thread.Stop(); |
477 } | 478 } |
478 | 479 |
479 TEST_F(JpegDecodeAcceleratorTest, SimpleDecode) { | 480 TEST_F(JpegDecodeAcceleratorTest, SimpleDecode) { |
480 for (auto* image : g_env->image_data_user_) { | 481 for (auto& image : g_env->image_data_user_) { |
481 test_image_files_.push_back(image); | 482 test_image_files_.push_back(image.get()); |
482 expected_status_.push_back(CS_DECODE_PASS); | 483 expected_status_.push_back(CS_DECODE_PASS); |
483 } | 484 } |
484 TestDecode(1); | 485 TestDecode(1); |
485 } | 486 } |
486 | 487 |
487 TEST_F(JpegDecodeAcceleratorTest, MultipleDecoders) { | 488 TEST_F(JpegDecodeAcceleratorTest, MultipleDecoders) { |
488 for (auto* image : g_env->image_data_user_) { | 489 for (auto& image : g_env->image_data_user_) { |
489 test_image_files_.push_back(image); | 490 test_image_files_.push_back(image.get()); |
490 expected_status_.push_back(CS_DECODE_PASS); | 491 expected_status_.push_back(CS_DECODE_PASS); |
491 } | 492 } |
492 TestDecode(3); | 493 TestDecode(3); |
493 } | 494 } |
494 | 495 |
495 TEST_F(JpegDecodeAcceleratorTest, InputSizeChange) { | 496 TEST_F(JpegDecodeAcceleratorTest, InputSizeChange) { |
496 // The size of |image_data_1280x720_black_| is smaller than | 497 // The size of |image_data_1280x720_black_| is smaller than |
497 // |image_data_1280x720_default_|. | 498 // |image_data_1280x720_default_|. |
498 test_image_files_.push_back(g_env->image_data_1280x720_black_.get()); | 499 test_image_files_.push_back(g_env->image_data_1280x720_black_.get()); |
499 test_image_files_.push_back(g_env->image_data_1280x720_default_.get()); | 500 test_image_files_.push_back(g_env->image_data_1280x720_default_.get()); |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | 583 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
583 media::VaapiWrapper::PreSandboxInitialization(); | 584 media::VaapiWrapper::PreSandboxInitialization(); |
584 #endif | 585 #endif |
585 | 586 |
586 media::g_env = reinterpret_cast<media::JpegDecodeAcceleratorTestEnvironment*>( | 587 media::g_env = reinterpret_cast<media::JpegDecodeAcceleratorTestEnvironment*>( |
587 testing::AddGlobalTestEnvironment( | 588 testing::AddGlobalTestEnvironment( |
588 new media::JpegDecodeAcceleratorTestEnvironment(jpeg_filenames))); | 589 new media::JpegDecodeAcceleratorTestEnvironment(jpeg_filenames))); |
589 | 590 |
590 return RUN_ALL_TESTS(); | 591 return RUN_ALL_TESTS(); |
591 } | 592 } |
OLD | NEW |