| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "content/common/media/cdm_host_files.h" | 5 #include "content/common/media/cdm_host_files.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 // static | 127 // static |
| 128 std::unique_ptr<CdmHostFiles> CdmHostFiles::Create( | 128 std::unique_ptr<CdmHostFiles> CdmHostFiles::Create( |
| 129 const base::FilePath& cdm_adapter_path) { | 129 const base::FilePath& cdm_adapter_path) { |
| 130 DVLOG(1) << __func__; | 130 DVLOG(1) << __func__; |
| 131 std::unique_ptr<CdmHostFiles> cdm_host_files = | 131 std::unique_ptr<CdmHostFiles> cdm_host_files = |
| 132 base::MakeUnique<CdmHostFiles>(); | 132 base::MakeUnique<CdmHostFiles>(); |
| 133 cdm_host_files->OpenFiles(cdm_adapter_path); | 133 cdm_host_files->OpenFiles(cdm_adapter_path); |
| 134 return cdm_host_files; | 134 return cdm_host_files; |
| 135 } | 135 } |
| 136 | 136 |
| 137 bool CdmHostFiles::VerifyFiles(base::NativeLibrary cdm_adapter_library, | 137 bool CdmHostFiles::InitVerification(base::NativeLibrary cdm_adapter_library, |
| 138 const base::FilePath& cdm_adapter_path) { | 138 const base::FilePath& cdm_adapter_path) { |
| 139 DVLOG(1) << __func__; | 139 DVLOG(1) << __func__; |
| 140 DCHECK(cdm_adapter_library); | 140 DCHECK(cdm_adapter_library); |
| 141 | 141 |
| 142 // Get function pointer exported by the CDM. | 142 // Get function pointer exported by the CDM. |
| 143 // See media/cdm/api/content_decryption_module_ext.h. | 143 // See media/cdm/api/content_decryption_module_ext.h. |
| 144 using VerifyCdmHostFunc = | 144 using InitVerificationFunc = |
| 145 bool (*)(const cdm::HostFile* cdm_host_files, uint32_t num_files); | 145 bool (*)(const cdm::HostFile* cdm_host_files, uint32_t num_files); |
| 146 static const char kVerifyCdmHostFuncName[] = "VerifyCdmHost_0"; | 146 static const char kInitVerificationFuncName[] = "VerifyCdmHost_0"; |
| 147 | 147 |
| 148 base::NativeLibrary cdm_library; | 148 base::NativeLibrary cdm_library; |
| 149 #if defined(OS_LINUX) || defined(OS_MACOSX) | 149 #if defined(OS_LINUX) || defined(OS_MACOSX) |
| 150 // On POSIX, "the dlsym() function shall search for the named symbol in all | 150 // On POSIX, "the dlsym() function shall search for the named symbol in all |
| 151 // objects loaded automatically as a result of loading the object referenced | 151 // objects loaded automatically as a result of loading the object referenced |
| 152 // by handle". Since the CDM is loaded automatically as a result of loading | 152 // by handle". Since the CDM is loaded automatically as a result of loading |
| 153 // the CDM adapter, we can just use the adapter to look for CDM symbols. | 153 // the CDM adapter, we can just use the adapter to look for CDM symbols. |
| 154 cdm_library = cdm_adapter_library; | 154 cdm_library = cdm_adapter_library; |
| 155 #elif defined(OS_WIN) | 155 #elif defined(OS_WIN) |
| 156 // On Windows, we have manually load the CDM. | 156 // On Windows, we have manually load the CDM. |
| 157 base::ScopedNativeLibrary scoped_cdm_library; | 157 base::ScopedNativeLibrary scoped_cdm_library; |
| 158 base::NativeLibraryLoadError error; | 158 base::NativeLibraryLoadError error; |
| 159 scoped_cdm_library.Reset( | 159 scoped_cdm_library.Reset( |
| 160 base::LoadNativeLibrary(GetCdmPath(cdm_adapter_path), &error)); | 160 base::LoadNativeLibrary(GetCdmPath(cdm_adapter_path), &error)); |
| 161 if (!scoped_cdm_library.is_valid()) { | 161 if (!scoped_cdm_library.is_valid()) { |
| 162 LOG(ERROR) << "Failed to load CDM (error: " << error.ToString() << ")"; | 162 LOG(ERROR) << "Failed to load CDM (error: " << error.ToString() << ")"; |
| 163 CloseAllFiles(); | 163 CloseAllFiles(); |
| 164 return true; | 164 return true; |
| 165 } | 165 } |
| 166 cdm_library = scoped_cdm_library.get(); | 166 cdm_library = scoped_cdm_library.get(); |
| 167 #endif | 167 #endif |
| 168 | 168 |
| 169 VerifyCdmHostFunc verify_cdm_host_func = reinterpret_cast<VerifyCdmHostFunc>( | 169 InitVerificationFunc init_verification_func = |
| 170 base::GetFunctionPointerFromNativeLibrary(cdm_library, | 170 reinterpret_cast<InitVerificationFunc>( |
| 171 kVerifyCdmHostFuncName)); | 171 base::GetFunctionPointerFromNativeLibrary(cdm_library, |
| 172 if (!verify_cdm_host_func) { | 172 kInitVerificationFuncName)); |
| 173 LOG(ERROR) << "Function " << kVerifyCdmHostFuncName << " not found."; | 173 if (!init_verification_func) { |
| 174 LOG(ERROR) << "Function " << kInitVerificationFuncName << " not found."; |
| 174 CloseAllFiles(); | 175 CloseAllFiles(); |
| 175 return true; | 176 return true; |
| 176 } | 177 } |
| 177 | 178 |
| 178 // Fills |cdm_host_files| with common and CDM specific files for | 179 // Fills |cdm_host_files| with common and CDM specific files for |
| 179 // |cdm_adapter_path|. | 180 // |cdm_adapter_path|. |
| 180 std::vector<cdm::HostFile> cdm_host_files; | 181 std::vector<cdm::HostFile> cdm_host_files; |
| 181 TakePlatformFiles(cdm_adapter_path, &cdm_host_files); | 182 TakePlatformFiles(cdm_adapter_path, &cdm_host_files); |
| 182 | 183 |
| 183 // std::vector::data() is not guaranteed to be nullptr when empty(). | 184 // std::vector::data() is not guaranteed to be nullptr when empty(). |
| 184 const cdm::HostFile* cdm_host_files_ptr = | 185 const cdm::HostFile* cdm_host_files_ptr = |
| 185 cdm_host_files.empty() ? nullptr : cdm_host_files.data(); | 186 cdm_host_files.empty() ? nullptr : cdm_host_files.data(); |
| 186 | 187 |
| 187 // Call |verify_cdm_host_func| on the CDM with |cdm_host_files|. Note that | 188 // Call |init_verification_func| on the CDM with |cdm_host_files|. Note that |
| 188 // the ownership of these files are transferred to the CDM, which will close | 189 // the ownership of these files are transferred to the CDM, which will close |
| 189 // the files immediately after use. | 190 // the files immediately after use. |
| 190 DVLOG(1) << __func__ << ": Calling " << kVerifyCdmHostFuncName << "() with " | 191 DVLOG(1) << __func__ << ": Calling " << kInitVerificationFuncName |
| 191 << cdm_host_files.size() << " files."; | 192 << "() with " << cdm_host_files.size() << " files."; |
| 192 for (const auto& host_file : cdm_host_files) { | 193 for (const auto& host_file : cdm_host_files) { |
| 193 DVLOG(1) << " - File Path: " << host_file.file_path; | 194 DVLOG(1) << " - File Path: " << host_file.file_path; |
| 194 DVLOG(1) << " - File: " << host_file.file; | 195 DVLOG(1) << " - File: " << host_file.file; |
| 195 DVLOG(1) << " - Sig File: " << host_file.sig_file; | 196 DVLOG(1) << " - Sig File: " << host_file.sig_file; |
| 196 } | 197 } |
| 197 | 198 |
| 198 if (!verify_cdm_host_func(cdm_host_files_ptr, cdm_host_files.size())) { | 199 if (!init_verification_func(cdm_host_files_ptr, cdm_host_files.size())) { |
| 199 DVLOG(1) << "Failed to verify CDM host."; | 200 DVLOG(1) << "Failed to verify CDM host."; |
| 200 CloseAllFiles(); | 201 CloseAllFiles(); |
| 201 return false; | 202 return false; |
| 202 } | 203 } |
| 203 | 204 |
| 204 // Close all files not passed to the CDM. | 205 // Close all files not passed to the CDM. |
| 205 CloseAllFiles(); | 206 CloseAllFiles(); |
| 206 return true; | 207 return true; |
| 207 } | 208 } |
| 208 | 209 |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 284 cdm_specific_files_map_.clear(); | 285 cdm_specific_files_map_.clear(); |
| 285 } | 286 } |
| 286 | 287 |
| 287 // Question(xhwang): Any better way to check whether a plugin is a CDM? Maybe | 288 // Question(xhwang): Any better way to check whether a plugin is a CDM? Maybe |
| 288 // when we register the plugin we can set some flag explicitly? | 289 // when we register the plugin we can set some flag explicitly? |
| 289 bool IsCdm(const base::FilePath& cdm_adapter_path) { | 290 bool IsCdm(const base::FilePath& cdm_adapter_path) { |
| 290 return !GetCdmPath(cdm_adapter_path).empty(); | 291 return !GetCdmPath(cdm_adapter_path).empty(); |
| 291 } | 292 } |
| 292 | 293 |
| 293 } // namespace content | 294 } // namespace content |
| OLD | NEW |