OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 <stdint.h> |
| 6 |
5 #include "base/base_paths.h" | 7 #include "base/base_paths.h" |
6 #include "base/cpu.h" | 8 #include "base/cpu.h" |
7 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
| 11 #include "base/macros.h" |
9 #include "base/path_service.h" | 12 #include "base/path_service.h" |
10 #include "base/time/time.h" | 13 #include "base/time/time.h" |
| 14 #include "build/build_config.h" |
11 #include "media/base/simd/convert_yuv_to_rgb.h" | 15 #include "media/base/simd/convert_yuv_to_rgb.h" |
12 #include "media/base/yuv_convert.h" | 16 #include "media/base/yuv_convert.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "testing/perf/perf_test.h" | 18 #include "testing/perf/perf_test.h" |
15 #include "third_party/libyuv/include/libyuv/row.h" | 19 #include "third_party/libyuv/include/libyuv/row.h" |
16 | 20 |
17 namespace media { | 21 namespace media { |
18 #if !defined(ARCH_CPU_ARM_FAMILY) && !defined(ARCH_CPU_MIPS_FAMILY) | 22 #if !defined(ARCH_CPU_ARM_FAMILY) && !defined(ARCH_CPU_MIPS_FAMILY) |
19 // Size of raw image. | 23 // Size of raw image. |
20 static const int kSourceWidth = 640; | 24 static const int kSourceWidth = 640; |
21 static const int kSourceHeight = 360; | 25 static const int kSourceHeight = 360; |
22 static const int kSourceYSize = kSourceWidth * kSourceHeight; | 26 static const int kSourceYSize = kSourceWidth * kSourceHeight; |
23 static const int kSourceUOffset = kSourceYSize; | 27 static const int kSourceUOffset = kSourceYSize; |
24 static const int kSourceVOffset = kSourceYSize * 5 / 4; | 28 static const int kSourceVOffset = kSourceYSize * 5 / 4; |
25 static const int kBpp = 4; | 29 static const int kBpp = 4; |
26 | 30 |
27 // Width of the row to convert. Odd so that we exercise the ending | 31 // Width of the row to convert. Odd so that we exercise the ending |
28 // one-pixel-leftover case. | 32 // one-pixel-leftover case. |
29 static const int kWidth = 639; | 33 static const int kWidth = 639; |
30 | 34 |
31 // Surface sizes for various test files. | 35 // Surface sizes for various test files. |
32 static const int kYUV12Size = kSourceYSize * 12 / 8; | 36 static const int kYUV12Size = kSourceYSize * 12 / 8; |
33 static const int kRGBSize = kSourceYSize * kBpp; | 37 static const int kRGBSize = kSourceYSize * kBpp; |
34 | 38 |
35 static const int kPerfTestIterations = 2000; | 39 static const int kPerfTestIterations = 2000; |
36 | 40 |
37 class YUVConvertPerfTest : public testing::Test { | 41 class YUVConvertPerfTest : public testing::Test { |
38 public: | 42 public: |
39 YUVConvertPerfTest() | 43 YUVConvertPerfTest() |
40 : yuv_bytes_(new uint8[kYUV12Size]), | 44 : yuv_bytes_(new uint8_t[kYUV12Size]), |
41 rgb_bytes_converted_(new uint8[kRGBSize]) { | 45 rgb_bytes_converted_(new uint8_t[kRGBSize]) { |
42 base::FilePath path; | 46 base::FilePath path; |
43 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &path)); | 47 CHECK(PathService::Get(base::DIR_SOURCE_ROOT, &path)); |
44 path = path.Append(FILE_PATH_LITERAL("media")) | 48 path = path.Append(FILE_PATH_LITERAL("media")) |
45 .Append(FILE_PATH_LITERAL("test")) | 49 .Append(FILE_PATH_LITERAL("test")) |
46 .Append(FILE_PATH_LITERAL("data")) | 50 .Append(FILE_PATH_LITERAL("data")) |
47 .Append(FILE_PATH_LITERAL("bali_640x360_P420.yuv")); | 51 .Append(FILE_PATH_LITERAL("bali_640x360_P420.yuv")); |
48 | 52 |
49 // Verify file size is correct. | 53 // Verify file size is correct. |
50 int64 actual_size = 0; | 54 int64_t actual_size = 0; |
51 base::GetFileSize(path, &actual_size); | 55 base::GetFileSize(path, &actual_size); |
52 CHECK_EQ(actual_size, kYUV12Size); | 56 CHECK_EQ(actual_size, kYUV12Size); |
53 | 57 |
54 // Verify bytes read are correct. | 58 // Verify bytes read are correct. |
55 int bytes_read = base::ReadFile( | 59 int bytes_read = base::ReadFile( |
56 path, reinterpret_cast<char*>(yuv_bytes_.get()), kYUV12Size); | 60 path, reinterpret_cast<char*>(yuv_bytes_.get()), kYUV12Size); |
57 | 61 |
58 CHECK_EQ(bytes_read, kYUV12Size); | 62 CHECK_EQ(bytes_read, kYUV12Size); |
59 } | 63 } |
60 | 64 |
61 scoped_ptr<uint8[]> yuv_bytes_; | 65 scoped_ptr<uint8_t[]> yuv_bytes_; |
62 scoped_ptr<uint8[]> rgb_bytes_converted_; | 66 scoped_ptr<uint8_t[]> rgb_bytes_converted_; |
63 | 67 |
64 private: | 68 private: |
65 DISALLOW_COPY_AND_ASSIGN(YUVConvertPerfTest); | 69 DISALLOW_COPY_AND_ASSIGN(YUVConvertPerfTest); |
66 }; | 70 }; |
67 | 71 |
68 TEST_F(YUVConvertPerfTest, ConvertYUVToRGB32Row_SSE) { | 72 TEST_F(YUVConvertPerfTest, ConvertYUVToRGB32Row_SSE) { |
69 ASSERT_TRUE(base::CPU().has_sse()); | 73 ASSERT_TRUE(base::CPU().has_sse()); |
70 | 74 |
71 base::TimeTicks start = base::TimeTicks::Now(); | 75 base::TimeTicks start = base::TimeTicks::Now(); |
72 for (int i = 0; i < kPerfTestIterations; ++i) { | 76 for (int i = 0; i < kPerfTestIterations; ++i) { |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 double total_time_seconds = (base::TimeTicks::Now() - start).InSecondsF(); | 211 double total_time_seconds = (base::TimeTicks::Now() - start).InSecondsF(); |
208 perf_test::PrintResult( | 212 perf_test::PrintResult( |
209 "yuv_convert_perftest", "", "LinearScaleYUVToRGB32Row_SSE", | 213 "yuv_convert_perftest", "", "LinearScaleYUVToRGB32Row_SSE", |
210 kPerfTestIterations / total_time_seconds, "runs/s", true); | 214 kPerfTestIterations / total_time_seconds, "runs/s", true); |
211 } | 215 } |
212 #endif // defined(OS_WIN) && (ARCH_CPU_X86 || COMPONENT_BUILD) | 216 #endif // defined(OS_WIN) && (ARCH_CPU_X86 || COMPONENT_BUILD) |
213 | 217 |
214 #endif // !defined(ARCH_CPU_ARM_FAMILY) && !defined(ARCH_CPU_MIPS_FAMILY) | 218 #endif // !defined(ARCH_CPU_ARM_FAMILY) && !defined(ARCH_CPU_MIPS_FAMILY) |
215 | 219 |
216 } // namespace media | 220 } // namespace media |
OLD | NEW |