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