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