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