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 #include "media/cdm/external_clear_key_test_helper.h" | 5 #include "media/cdm/external_clear_key_test_helper.h" |
6 | 6 |
7 #include "base/files/file_path.h" | 7 #include "base/files/file_path.h" |
8 #include "base/files/file_util.h" | 8 #include "base/files/file_util.h" |
| 9 #include "base/native_library.h" |
9 #include "base/path_service.h" | 10 #include "base/path_service.h" |
10 #include "build/build_config.h" | |
11 #include "media/cdm/api/content_decryption_module.h" | 11 #include "media/cdm/api/content_decryption_module.h" |
12 #include "media/cdm/cdm_paths.h" | 12 #include "media/cdm/cdm_paths.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
14 | 14 |
15 namespace media { | 15 namespace media { |
16 | 16 |
17 // INITIALIZE_CDM_MODULE is a macro in api/content_decryption_module.h. | 17 // INITIALIZE_CDM_MODULE is a macro in api/content_decryption_module.h. |
18 // However, we need to pass it as a string to GetFunctionPointer() once it | 18 // However, we need to pass it as a string to GetFunctionPointer() once it |
19 // is expanded. | 19 // is expanded. |
20 #define STRINGIFY(X) #X | 20 #define STRINGIFY(X) #X |
21 #define MAKE_STRING(X) STRINGIFY(X) | 21 #define MAKE_STRING(X) STRINGIFY(X) |
22 | 22 |
23 const char kClearKeyCdmBaseDirectory[] = "ClearKeyCdm"; | 23 const char kClearKeyCdmBaseDirectory[] = "ClearKeyCdm"; |
24 | 24 |
25 // File name of the External ClearKey CDM on different platforms. | |
26 const base::FilePath::CharType kExternalClearKeyCdmFileName[] = | |
27 #if defined(OS_MACOSX) | |
28 FILE_PATH_LITERAL("libclearkeycdm.dylib"); | |
29 #elif defined(OS_WIN) | |
30 FILE_PATH_LITERAL("clearkeycdm.dll"); | |
31 #else // OS_LINUX, etc. | |
32 FILE_PATH_LITERAL("libclearkeycdm.so"); | |
33 #endif | |
34 | |
35 ExternalClearKeyTestHelper::ExternalClearKeyTestHelper() { | 25 ExternalClearKeyTestHelper::ExternalClearKeyTestHelper() { |
36 LoadLibrary(); | 26 LoadLibrary(); |
37 } | 27 } |
38 | 28 |
39 ExternalClearKeyTestHelper::~ExternalClearKeyTestHelper() { | 29 ExternalClearKeyTestHelper::~ExternalClearKeyTestHelper() { |
40 UnloadLibrary(); | 30 UnloadLibrary(); |
41 } | 31 } |
42 | 32 |
43 void ExternalClearKeyTestHelper::LoadLibrary() { | 33 void ExternalClearKeyTestHelper::LoadLibrary() { |
44 // Determine the location of the CDM. It is expected to be in the same | 34 // Determine the location of the CDM. It is expected to be in the same |
45 // directory as the current module. | 35 // directory as the current module. |
46 base::FilePath cdm_base_path; | 36 base::FilePath cdm_base_path; |
47 ASSERT_TRUE(PathService::Get(base::DIR_MODULE, &cdm_base_path)); | 37 ASSERT_TRUE(PathService::Get(base::DIR_MODULE, &cdm_base_path)); |
48 cdm_base_path = cdm_base_path.Append( | 38 cdm_base_path = cdm_base_path.Append( |
49 GetPlatformSpecificDirectory(kClearKeyCdmBaseDirectory)); | 39 GetPlatformSpecificDirectory(kClearKeyCdmBaseDirectory)); |
50 library_path_ = | 40 library_path_ = cdm_base_path.AppendASCII( |
51 cdm_base_path.Append(base::FilePath(kExternalClearKeyCdmFileName)); | 41 base::GetNativeLibraryName(kClearKeyCdmLibraryName)); |
52 ASSERT_TRUE(base::PathExists(library_path_)) << library_path_.value(); | 42 ASSERT_TRUE(base::PathExists(library_path_)) << library_path_.value(); |
53 | 43 |
54 // Now load the CDM library. | 44 // Now load the CDM library. |
55 base::NativeLibraryLoadError error; | 45 base::NativeLibraryLoadError error; |
56 library_.Reset(base::LoadNativeLibrary(library_path_, &error)); | 46 library_.Reset(base::LoadNativeLibrary(library_path_, &error)); |
57 ASSERT_TRUE(library_.is_valid()) << error.ToString(); | 47 ASSERT_TRUE(library_.is_valid()) << error.ToString(); |
58 | 48 |
59 // Call INITIALIZE_CDM_MODULE() | 49 // Call INITIALIZE_CDM_MODULE() |
60 typedef void (*InitializeCdmFunc)(); | 50 typedef void (*InitializeCdmFunc)(); |
61 InitializeCdmFunc initialize_cdm_func = reinterpret_cast<InitializeCdmFunc>( | 51 InitializeCdmFunc initialize_cdm_func = reinterpret_cast<InitializeCdmFunc>( |
62 library_.GetFunctionPointer(MAKE_STRING(INITIALIZE_CDM_MODULE))); | 52 library_.GetFunctionPointer(MAKE_STRING(INITIALIZE_CDM_MODULE))); |
63 ASSERT_TRUE(initialize_cdm_func) << "No INITIALIZE_CDM_MODULE in library"; | 53 ASSERT_TRUE(initialize_cdm_func) << "No INITIALIZE_CDM_MODULE in library"; |
64 initialize_cdm_func(); | 54 initialize_cdm_func(); |
65 } | 55 } |
66 | 56 |
67 void ExternalClearKeyTestHelper::UnloadLibrary() { | 57 void ExternalClearKeyTestHelper::UnloadLibrary() { |
68 // Call DeinitializeCdmModule() | 58 // Call DeinitializeCdmModule() |
69 typedef void (*DeinitializeCdmFunc)(); | 59 typedef void (*DeinitializeCdmFunc)(); |
70 DeinitializeCdmFunc deinitialize_cdm_func = | 60 DeinitializeCdmFunc deinitialize_cdm_func = |
71 reinterpret_cast<DeinitializeCdmFunc>( | 61 reinterpret_cast<DeinitializeCdmFunc>( |
72 library_.GetFunctionPointer("DeinitializeCdmModule")); | 62 library_.GetFunctionPointer("DeinitializeCdmModule")); |
73 ASSERT_TRUE(deinitialize_cdm_func) << "No DeinitializeCdmModule() in library"; | 63 ASSERT_TRUE(deinitialize_cdm_func) << "No DeinitializeCdmModule() in library"; |
74 deinitialize_cdm_func(); | 64 deinitialize_cdm_func(); |
75 } | 65 } |
76 | 66 |
77 } // namespace media | 67 } // namespace media |
OLD | NEW |