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 <stddef.h> | 5 #include <stddef.h> |
6 #include <stdint.h> | 6 #include <stdint.h> |
7 | 7 |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
11 #include "base/scoped_native_library.h" | 11 #include "base/scoped_native_library.h" |
12 #include "base/strings/utf_string_conversions.h" | 12 #include "base/strings/utf_string_conversions.h" |
13 #include "base/time/time.h" | 13 #include "base/time/time.h" |
14 #include "build/build_config.h" | 14 #include "build/build_config.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 #include "testing/perf/perf_test.h" | 16 #include "testing/perf/perf_test.h" |
| 17 |
17 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | 18 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. |
18 | 19 |
| 20 #if defined(ENABLE_PEPPER_CDMS) |
| 21 #include "chrome/browser/media/pepper_cdm_test_helper.h" |
| 22 #include "media/cdm/cdm_paths.h" |
| 23 #endif |
| 24 |
| 25 namespace { |
| 26 |
19 // Measures the size (bytes) and time to load (sec) of a native library. | 27 // Measures the size (bytes) and time to load (sec) of a native library. |
20 void MeasureSizeAndTimeToLoadNativeLibrary(const base::FilePath& library_name) { | 28 // |library_relative_dir| is the relative path based on DIR_MODULE. |
| 29 void MeasureSizeAndTimeToLoadNativeLibrary( |
| 30 const base::FilePath& library_relative_dir, |
| 31 const base::FilePath& library_name) { |
21 base::FilePath output_dir; | 32 base::FilePath output_dir; |
22 ASSERT_TRUE(PathService::Get(base::DIR_MODULE, &output_dir)); | 33 ASSERT_TRUE(PathService::Get(base::DIR_MODULE, &output_dir)); |
| 34 output_dir = output_dir.Append(library_relative_dir); |
23 base::FilePath library_path = output_dir.Append(library_name); | 35 base::FilePath library_path = output_dir.Append(library_name); |
24 ASSERT_TRUE(base::PathExists(library_path)) << library_path.value(); | 36 ASSERT_TRUE(base::PathExists(library_path)) << library_path.value(); |
25 | 37 |
26 int64_t size = 0; | 38 int64_t size = 0; |
27 ASSERT_TRUE(base::GetFileSize(library_path, &size)); | 39 ASSERT_TRUE(base::GetFileSize(library_path, &size)); |
28 perf_test::PrintResult("library_size", | 40 perf_test::PrintResult("library_size", |
29 "", | 41 "", |
30 library_name.AsUTF8Unsafe(), | 42 library_name.AsUTF8Unsafe(), |
31 static_cast<size_t>(size), | 43 static_cast<size_t>(size), |
32 "bytes", | 44 "bytes", |
33 true); | 45 true); |
34 | 46 |
35 base::NativeLibraryLoadError error; | 47 base::NativeLibraryLoadError error; |
36 base::TimeTicks start = base::TimeTicks::Now(); | 48 base::TimeTicks start = base::TimeTicks::Now(); |
37 base::NativeLibrary native_library = | 49 base::NativeLibrary native_library = |
38 base::LoadNativeLibrary(library_path, &error); | 50 base::LoadNativeLibrary(library_path, &error); |
39 double delta = (base::TimeTicks::Now() - start).InMillisecondsF(); | 51 double delta = (base::TimeTicks::Now() - start).InMillisecondsF(); |
40 ASSERT_TRUE(native_library) << "Error loading library: " << error.ToString(); | 52 ASSERT_TRUE(native_library) << "Error loading library: " << error.ToString(); |
41 base::UnloadNativeLibrary(native_library); | 53 base::UnloadNativeLibrary(native_library); |
42 perf_test::PrintResult("time_to_load_library", | 54 perf_test::PrintResult("time_to_load_library", |
43 "", | 55 "", |
44 library_name.AsUTF8Unsafe(), | 56 library_name.AsUTF8Unsafe(), |
45 delta, | 57 delta, |
46 "ms", | 58 "ms", |
47 true); | 59 true); |
48 } | 60 } |
49 | 61 |
50 // Use the base name of the library to dynamically get the platform specific | 62 #if defined(ENABLE_PEPPER_CDMS) |
51 // name. See base::GetNativeLibraryName() for details. | 63 |
52 void MeasureSizeAndTimeToLoadNativeLibraryByBaseName( | 64 // File name of the ClearKey CDM on different platforms. |
53 const std::string& base_library_name) { | 65 // TODO(xhwang): Consolidate this with external_clear_key_test_helper.cc. |
54 MeasureSizeAndTimeToLoadNativeLibrary(base::FilePath::FromUTF16Unsafe( | 66 const char kClearKeyCdmFileName[] = |
55 base::GetNativeLibraryName(base::ASCIIToUTF16(base_library_name)))); | 67 #if defined(OS_MACOSX) |
| 68 "libclearkeycdm.dylib"; |
| 69 #elif defined(OS_WIN) |
| 70 "clearkeycdm.dll"; |
| 71 #else // OS_LINUX, etc. |
| 72 "libclearkeycdm.so"; |
| 73 #endif |
| 74 |
| 75 void MeasureSizeAndTimeToLoadCdm(const std::string& cdm_base_dir, |
| 76 const std::string& cdm_name) { |
| 77 MeasureSizeAndTimeToLoadNativeLibrary( |
| 78 media::GetPlatformSpecificDirectory(cdm_base_dir), |
| 79 base::FilePath::FromUTF8Unsafe(cdm_name)); |
56 } | 80 } |
57 | 81 |
| 82 #endif // defined(ENABLE_PEPPER_CDMS) |
| 83 |
| 84 } // namespace |
| 85 |
58 #if defined(ENABLE_PEPPER_CDMS) | 86 #if defined(ENABLE_PEPPER_CDMS) |
59 #if defined(WIDEVINE_CDM_AVAILABLE) | 87 #if defined(WIDEVINE_CDM_AVAILABLE) |
60 TEST(LoadCDMPerfTest, Widevine) { | 88 TEST(LoadCDMPerfTest, Widevine) { |
61 MeasureSizeAndTimeToLoadNativeLibrary( | 89 MeasureSizeAndTimeToLoadCdm(kWidevineCdmBaseDirectory, kWidevineCdmFileName); |
62 base::FilePath::FromUTF8Unsafe(kWidevineCdmFileName)); | |
63 } | 90 } |
64 | 91 |
65 TEST(LoadCDMPerfTest, WidevineAdapter) { | 92 TEST(LoadCDMPerfTest, WidevineAdapter) { |
66 MeasureSizeAndTimeToLoadNativeLibrary( | 93 MeasureSizeAndTimeToLoadCdm(kWidevineCdmBaseDirectory, |
67 base::FilePath::FromUTF8Unsafe(kWidevineCdmAdapterFileName)); | 94 kWidevineCdmAdapterFileName); |
68 } | 95 } |
69 #endif // defined(WIDEVINE_CDM_AVAILABLE) | 96 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
70 | 97 |
71 TEST(LoadCDMPerfTest, ExternalClearKey) { | 98 TEST(LoadCDMPerfTest, ExternalClearKey) { |
72 #if defined(OS_MACOSX) | 99 MeasureSizeAndTimeToLoadCdm(kClearKeyCdmBaseDirectory, kClearKeyCdmFileName); |
73 MeasureSizeAndTimeToLoadNativeLibrary( | |
74 base::FilePath::FromUTF8Unsafe("libclearkeycdm.dylib")); | |
75 #else | |
76 MeasureSizeAndTimeToLoadNativeLibraryByBaseName("clearkeycdm"); | |
77 #endif // defined(OS_MACOSX) | |
78 } | 100 } |
79 | 101 |
80 TEST(LoadCDMPerfTest, ExternalClearKeyAdapter) { | 102 TEST(LoadCDMPerfTest, ExternalClearKeyAdapter) { |
81 #if defined(OS_MACOSX) | 103 MeasureSizeAndTimeToLoadCdm(kClearKeyCdmBaseDirectory, |
82 MeasureSizeAndTimeToLoadNativeLibrary( | 104 kClearKeyCdmAdapterFileName); |
83 base::FilePath::FromUTF8Unsafe("clearkeycdmadapter.plugin")); | |
84 #else | |
85 MeasureSizeAndTimeToLoadNativeLibraryByBaseName("clearkeycdmadapter"); | |
86 #endif // defined(OS_MACOSX) | |
87 } | 105 } |
88 #endif // defined(ENABLE_PEPPER_CDMS) | 106 #endif // defined(ENABLE_PEPPER_CDMS) |
OLD | NEW |