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