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> |
(...skipping 24 matching lines...) Expand all Loading... |
35 #if defined(USE_V4L2_CODEC) | 35 #if defined(USE_V4L2_CODEC) |
36 #include "media/gpu/v4l2_device.h" | 36 #include "media/gpu/v4l2_device.h" |
37 #include "media/gpu/v4l2_jpeg_decode_accelerator.h" | 37 #include "media/gpu/v4l2_jpeg_decode_accelerator.h" |
38 #endif | 38 #endif |
39 #if defined(ARCH_CPU_X86_FAMILY) | 39 #if defined(ARCH_CPU_X86_FAMILY) |
40 #include "media/gpu/vaapi_jpeg_decode_accelerator.h" | 40 #include "media/gpu/vaapi_jpeg_decode_accelerator.h" |
41 #include "media/gpu/vaapi_wrapper.h" | 41 #include "media/gpu/vaapi_wrapper.h" |
42 #endif | 42 #endif |
43 #endif | 43 #endif |
44 | 44 |
45 using media::JpegDecodeAccelerator; | |
46 | |
47 namespace media { | 45 namespace media { |
48 namespace { | 46 namespace { |
49 | 47 |
50 // Default test image file. | 48 // Default test image file. |
51 const base::FilePath::CharType* kDefaultJpegFilename = | 49 const base::FilePath::CharType* kDefaultJpegFilename = |
52 FILE_PATH_LITERAL("peach_pi-1280x720.jpg"); | 50 FILE_PATH_LITERAL("peach_pi-1280x720.jpg"); |
53 // Decide to save decode results to files or not. Output files will be saved | 51 // Decide to save decode results to files or not. Output files will be saved |
54 // in the same directory with unittest. File name is like input file but | 52 // in the same directory with unittest. File name is like input file but |
55 // changing the extension to "yuv". | 53 // changing the extension to "yuv". |
56 bool g_save_to_file = false; | 54 bool g_save_to_file = false; |
57 // Threshold for mean absolute difference of hardware and software decode. | 55 // Threshold for mean absolute difference of hardware and software decode. |
58 // Absolute difference is to calculate the difference between each pixel in two | 56 // Absolute difference is to calculate the difference between each pixel in two |
59 // images. This is used for measuring of the similarity of two images. | 57 // images. This is used for measuring of the similarity of two images. |
60 const double kDecodeSimilarityThreshold = 1.0; | 58 const double kDecodeSimilarityThreshold = 1.0; |
61 | 59 |
62 // Environment to create test data for all test cases. | 60 // Environment to create test data for all test cases. |
63 class JpegDecodeAcceleratorTestEnvironment; | 61 class JpegDecodeAcceleratorTestEnvironment; |
64 JpegDecodeAcceleratorTestEnvironment* g_env; | 62 JpegDecodeAcceleratorTestEnvironment* g_env; |
65 | 63 |
66 struct TestImageFile { | 64 struct TestImageFile { |
67 explicit TestImageFile(const base::FilePath::StringType& filename) | 65 explicit TestImageFile(const base::FilePath::StringType& filename) |
68 : filename(filename) {} | 66 : filename(filename) {} |
69 | 67 |
70 base::FilePath::StringType filename; | 68 base::FilePath::StringType filename; |
71 | 69 |
72 // The input content of |filename|. | 70 // The input content of |filename|. |
73 std::string data_str; | 71 std::string data_str; |
74 | 72 |
75 media::JpegParseResult parse_result; | 73 JpegParseResult parse_result; |
76 gfx::Size visible_size; | 74 gfx::Size visible_size; |
77 size_t output_size; | 75 size_t output_size; |
78 }; | 76 }; |
79 | 77 |
80 enum ClientState { | 78 enum ClientState { |
81 CS_CREATED, | 79 CS_CREATED, |
82 CS_INITIALIZED, | 80 CS_INITIALIZED, |
83 CS_DECODE_PASS, | 81 CS_DECODE_PASS, |
84 CS_ERROR, | 82 CS_ERROR, |
85 }; | 83 }; |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 } | 241 } |
244 | 242 |
245 void JpegClient::StartDecode(int32_t bitstream_buffer_id) { | 243 void JpegClient::StartDecode(int32_t bitstream_buffer_id) { |
246 DCHECK_LT(static_cast<size_t>(bitstream_buffer_id), test_image_files_.size()); | 244 DCHECK_LT(static_cast<size_t>(bitstream_buffer_id), test_image_files_.size()); |
247 TestImageFile* image_file = test_image_files_[bitstream_buffer_id]; | 245 TestImageFile* image_file = test_image_files_[bitstream_buffer_id]; |
248 | 246 |
249 PrepareMemory(bitstream_buffer_id); | 247 PrepareMemory(bitstream_buffer_id); |
250 | 248 |
251 base::SharedMemoryHandle dup_handle; | 249 base::SharedMemoryHandle dup_handle; |
252 dup_handle = base::SharedMemory::DuplicateHandle(in_shm_->handle()); | 250 dup_handle = base::SharedMemory::DuplicateHandle(in_shm_->handle()); |
253 media::BitstreamBuffer bitstream_buffer(bitstream_buffer_id, dup_handle, | 251 BitstreamBuffer bitstream_buffer(bitstream_buffer_id, dup_handle, |
254 image_file->data_str.size()); | 252 image_file->data_str.size()); |
255 scoped_refptr<media::VideoFrame> out_frame_ = | 253 scoped_refptr<VideoFrame> out_frame_ = VideoFrame::WrapExternalSharedMemory( |
256 media::VideoFrame::WrapExternalSharedMemory( | 254 PIXEL_FORMAT_I420, image_file->visible_size, |
257 media::PIXEL_FORMAT_I420, | 255 gfx::Rect(image_file->visible_size), image_file->visible_size, |
258 image_file->visible_size, | 256 static_cast<uint8_t*>(hw_out_shm_->memory()), image_file->output_size, |
259 gfx::Rect(image_file->visible_size), | 257 hw_out_shm_->handle(), 0, base::TimeDelta()); |
260 image_file->visible_size, | |
261 static_cast<uint8_t*>(hw_out_shm_->memory()), | |
262 image_file->output_size, | |
263 hw_out_shm_->handle(), | |
264 0, | |
265 base::TimeDelta()); | |
266 LOG_ASSERT(out_frame_.get()); | 258 LOG_ASSERT(out_frame_.get()); |
267 decoder_->Decode(bitstream_buffer, out_frame_); | 259 decoder_->Decode(bitstream_buffer, out_frame_); |
268 } | 260 } |
269 | 261 |
270 bool JpegClient::GetSoftwareDecodeResult(int32_t bitstream_buffer_id) { | 262 bool JpegClient::GetSoftwareDecodeResult(int32_t bitstream_buffer_id) { |
271 media::VideoPixelFormat format = media::PIXEL_FORMAT_I420; | 263 VideoPixelFormat format = PIXEL_FORMAT_I420; |
272 TestImageFile* image_file = test_image_files_[bitstream_buffer_id]; | 264 TestImageFile* image_file = test_image_files_[bitstream_buffer_id]; |
273 | 265 |
274 uint8_t* yplane = static_cast<uint8_t*>(sw_out_shm_->memory()); | 266 uint8_t* yplane = static_cast<uint8_t*>(sw_out_shm_->memory()); |
275 uint8_t* uplane = | 267 uint8_t* uplane = yplane + |
276 yplane + | 268 VideoFrame::PlaneSize(format, VideoFrame::kYPlane, |
277 media::VideoFrame::PlaneSize(format, media::VideoFrame::kYPlane, | 269 image_file->visible_size) |
278 image_file->visible_size) | 270 .GetArea(); |
279 .GetArea(); | 271 uint8_t* vplane = uplane + |
280 uint8_t* vplane = | 272 VideoFrame::PlaneSize(format, VideoFrame::kUPlane, |
281 uplane + | 273 image_file->visible_size) |
282 media::VideoFrame::PlaneSize(format, media::VideoFrame::kUPlane, | 274 .GetArea(); |
283 image_file->visible_size) | |
284 .GetArea(); | |
285 int yplane_stride = image_file->visible_size.width(); | 275 int yplane_stride = image_file->visible_size.width(); |
286 int uv_plane_stride = yplane_stride / 2; | 276 int uv_plane_stride = yplane_stride / 2; |
287 | 277 |
288 if (libyuv::ConvertToI420( | 278 if (libyuv::ConvertToI420( |
289 static_cast<uint8_t*>(in_shm_->memory()), | 279 static_cast<uint8_t*>(in_shm_->memory()), |
290 image_file->data_str.size(), | 280 image_file->data_str.size(), |
291 yplane, | 281 yplane, |
292 yplane_stride, | 282 yplane_stride, |
293 uplane, | 283 uplane, |
294 uv_plane_stride, | 284 uv_plane_stride, |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 image_data_640x368_black_.reset( | 353 image_data_640x368_black_.reset( |
364 new TestImageFile(test_640x368_jpeg_file_.value())); | 354 new TestImageFile(test_640x368_jpeg_file_.value())); |
365 ASSERT_NO_FATAL_FAILURE(ReadTestJpegImage(test_640x368_jpeg_file_, | 355 ASSERT_NO_FATAL_FAILURE(ReadTestJpegImage(test_640x368_jpeg_file_, |
366 image_data_640x368_black_.get())); | 356 image_data_640x368_black_.get())); |
367 | 357 |
368 image_data_640x360_black_.reset( | 358 image_data_640x360_black_.reset( |
369 new TestImageFile(test_640x360_jpeg_file_.value())); | 359 new TestImageFile(test_640x360_jpeg_file_.value())); |
370 ASSERT_NO_FATAL_FAILURE(ReadTestJpegImage(test_640x360_jpeg_file_, | 360 ASSERT_NO_FATAL_FAILURE(ReadTestJpegImage(test_640x360_jpeg_file_, |
371 image_data_640x360_black_.get())); | 361 image_data_640x360_black_.get())); |
372 | 362 |
373 base::FilePath default_jpeg_file = | 363 base::FilePath default_jpeg_file = GetTestDataFilePath(kDefaultJpegFilename); |
374 media::GetTestDataFilePath(kDefaultJpegFilename); | |
375 image_data_1280x720_default_.reset(new TestImageFile(kDefaultJpegFilename)); | 364 image_data_1280x720_default_.reset(new TestImageFile(kDefaultJpegFilename)); |
376 ASSERT_NO_FATAL_FAILURE( | 365 ASSERT_NO_FATAL_FAILURE( |
377 ReadTestJpegImage(default_jpeg_file, image_data_1280x720_default_.get())); | 366 ReadTestJpegImage(default_jpeg_file, image_data_1280x720_default_.get())); |
378 | 367 |
379 image_data_invalid_.reset(new TestImageFile("failure.jpg")); | 368 image_data_invalid_.reset(new TestImageFile("failure.jpg")); |
380 image_data_invalid_->data_str.resize(100, 0); | 369 image_data_invalid_->data_str.resize(100, 0); |
381 image_data_invalid_->visible_size.SetSize(1280, 720); | 370 image_data_invalid_->visible_size.SetSize(1280, 720); |
382 image_data_invalid_->output_size = media::VideoFrame::AllocationSize( | 371 image_data_invalid_->output_size = VideoFrame::AllocationSize( |
383 media::PIXEL_FORMAT_I420, image_data_invalid_->visible_size); | 372 PIXEL_FORMAT_I420, image_data_invalid_->visible_size); |
384 | 373 |
385 // |user_jpeg_filenames_| may include many files and use ';' as delimiter. | 374 // |user_jpeg_filenames_| may include many files and use ';' as delimiter. |
386 std::vector<base::FilePath::StringType> filenames = base::SplitString( | 375 std::vector<base::FilePath::StringType> filenames = base::SplitString( |
387 user_jpeg_filenames_, base::FilePath::StringType(1, ';'), | 376 user_jpeg_filenames_, base::FilePath::StringType(1, ';'), |
388 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 377 base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
389 for (const auto& filename : filenames) { | 378 for (const auto& filename : filenames) { |
390 base::FilePath input_file = media::GetTestDataFilePath(filename); | 379 base::FilePath input_file = GetTestDataFilePath(filename); |
391 TestImageFile* image_data = new TestImageFile(filename); | 380 TestImageFile* image_data = new TestImageFile(filename); |
392 ASSERT_NO_FATAL_FAILURE(ReadTestJpegImage(input_file, image_data)); | 381 ASSERT_NO_FATAL_FAILURE(ReadTestJpegImage(input_file, image_data)); |
393 image_data_user_.push_back(image_data); | 382 image_data_user_.push_back(image_data); |
394 } | 383 } |
395 } | 384 } |
396 | 385 |
397 void JpegDecodeAcceleratorTestEnvironment::TearDown() { | 386 void JpegDecodeAcceleratorTestEnvironment::TearDown() { |
398 base::DeleteFile(test_1280x720_jpeg_file_, false); | 387 base::DeleteFile(test_1280x720_jpeg_file_, false); |
399 base::DeleteFile(test_640x368_jpeg_file_, false); | 388 base::DeleteFile(test_640x368_jpeg_file_, false); |
400 base::DeleteFile(test_640x360_jpeg_file_, false); | 389 base::DeleteFile(test_640x360_jpeg_file_, false); |
(...skipping 17 matching lines...) Expand all Loading... |
418 EXPECT_TRUE(base::AppendToFile( | 407 EXPECT_TRUE(base::AppendToFile( |
419 *filename, reinterpret_cast<char*>(&encoded[0]), encoded.size())); | 408 *filename, reinterpret_cast<char*>(&encoded[0]), encoded.size())); |
420 return true; | 409 return true; |
421 } | 410 } |
422 | 411 |
423 void JpegDecodeAcceleratorTestEnvironment::ReadTestJpegImage( | 412 void JpegDecodeAcceleratorTestEnvironment::ReadTestJpegImage( |
424 base::FilePath& input_file, | 413 base::FilePath& input_file, |
425 TestImageFile* image_data) { | 414 TestImageFile* image_data) { |
426 ASSERT_TRUE(base::ReadFileToString(input_file, &image_data->data_str)); | 415 ASSERT_TRUE(base::ReadFileToString(input_file, &image_data->data_str)); |
427 | 416 |
428 ASSERT_TRUE(media::ParseJpegPicture( | 417 ASSERT_TRUE(ParseJpegPicture( |
429 reinterpret_cast<const uint8_t*>(image_data->data_str.data()), | 418 reinterpret_cast<const uint8_t*>(image_data->data_str.data()), |
430 image_data->data_str.size(), &image_data->parse_result)); | 419 image_data->data_str.size(), &image_data->parse_result)); |
431 image_data->visible_size.SetSize( | 420 image_data->visible_size.SetSize( |
432 image_data->parse_result.frame_header.visible_width, | 421 image_data->parse_result.frame_header.visible_width, |
433 image_data->parse_result.frame_header.visible_height); | 422 image_data->parse_result.frame_header.visible_height); |
434 image_data->output_size = media::VideoFrame::AllocationSize( | 423 image_data->output_size = |
435 media::PIXEL_FORMAT_I420, image_data->visible_size); | 424 VideoFrame::AllocationSize(PIXEL_FORMAT_I420, image_data->visible_size); |
436 } | 425 } |
437 | 426 |
438 class JpegDecodeAcceleratorTest : public ::testing::Test { | 427 class JpegDecodeAcceleratorTest : public ::testing::Test { |
439 protected: | 428 protected: |
440 JpegDecodeAcceleratorTest() {} | 429 JpegDecodeAcceleratorTest() {} |
441 | 430 |
442 void TestDecode(size_t num_concurrent_decoders); | 431 void TestDecode(size_t num_concurrent_decoders); |
443 | 432 |
444 // The elements of |test_image_files_| are owned by | 433 // The elements of |test_image_files_| are owned by |
445 // JpegDecodeAcceleratorTestEnvironment. | 434 // JpegDecodeAcceleratorTestEnvironment. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
578 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) | 567 #if defined(OS_CHROMEOS) && defined(ARCH_CPU_X86_FAMILY) |
579 media::VaapiWrapper::PreSandboxInitialization(); | 568 media::VaapiWrapper::PreSandboxInitialization(); |
580 #endif | 569 #endif |
581 | 570 |
582 media::g_env = reinterpret_cast<media::JpegDecodeAcceleratorTestEnvironment*>( | 571 media::g_env = reinterpret_cast<media::JpegDecodeAcceleratorTestEnvironment*>( |
583 testing::AddGlobalTestEnvironment( | 572 testing::AddGlobalTestEnvironment( |
584 new media::JpegDecodeAcceleratorTestEnvironment(jpeg_filenames))); | 573 new media::JpegDecodeAcceleratorTestEnvironment(jpeg_filenames))); |
585 | 574 |
586 return RUN_ALL_TESTS(); | 575 return RUN_ALL_TESTS(); |
587 } | 576 } |
OLD | NEW |