cdm_module.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2017 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #ifndef MEDIA_CDM_CDM_MODULE_H_
  5. #define MEDIA_CDM_CDM_MODULE_H_
  6. #include <memory>
  7. #include <vector>
  8. #include "base/files/file_path.h"
  9. #include "base/scoped_native_library.h"
  10. #include "media/base/media_export.h"
  11. #include "media/cdm/api/content_decryption_module.h"
  12. #include "media/media_buildflags.h"
  13. #if !BUILDFLAG(ENABLE_LIBRARY_CDMS)
  14. #error This file only applies to builds that enable_library_cdms.
  15. #endif
  16. #if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
  17. #include "media/cdm/cdm_host_file.h"
  18. #include "media/cdm/cdm_host_files.h"
  19. #endif // BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
  20. namespace media {
  21. class MEDIA_EXPORT CdmModule {
  22. public:
  23. static CdmModule* GetInstance();
  24. // Reset the CdmModule instance so that each test have it's own instance.
  25. static void ResetInstanceForTesting();
  26. CdmModule(const CdmModule&) = delete;
  27. CdmModule& operator=(const CdmModule&) = delete;
  28. ~CdmModule();
  29. using CreateCdmFunc = decltype(&::CreateCdmInstance);
  30. CreateCdmFunc GetCreateCdmFunc();
  31. // Loads the CDM, initialize function pointers and initialize the CDM module.
  32. // This must only be called only once.
  33. #if BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
  34. bool Initialize(const base::FilePath& cdm_path,
  35. std::vector<CdmHostFilePath> cdm_host_file_paths);
  36. #else
  37. bool Initialize(const base::FilePath& cdm_path);
  38. #endif // BUILDFLAG(ENABLE_CDM_HOST_VERIFICATION)
  39. // Calls INITIALIZE_CDM_MODULE on the actually library CDM. Must be called
  40. // within the sandbox!
  41. void InitializeCdmModule();
  42. private:
  43. using InitializeCdmModuleFunc = decltype(&::INITIALIZE_CDM_MODULE);
  44. using DeinitializeCdmModuleFunc = decltype(&::DeinitializeCdmModule);
  45. using GetCdmVersionFunc = decltype(&::GetCdmVersion);
  46. CdmModule();
  47. bool initialized_ = false;
  48. base::FilePath cdm_path_;
  49. base::ScopedNativeLibrary library_;
  50. CreateCdmFunc create_cdm_func_ = nullptr;
  51. InitializeCdmModuleFunc initialize_cdm_module_func_ = nullptr;
  52. DeinitializeCdmModuleFunc deinitialize_cdm_module_func_ = nullptr;
  53. GetCdmVersionFunc get_cdm_version_func_ = nullptr;
  54. };
  55. } // namespace media
  56. #endif // MEDIA_CDM_CDM_MODULE_H_