key_systems.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Copyright 2013 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_BASE_KEY_SYSTEMS_H_
  5. #define MEDIA_BASE_KEY_SYSTEMS_H_
  6. #include <stdint.h>
  7. #include <string>
  8. #include <vector>
  9. #include "base/callback.h"
  10. #include "media/base/decrypt_config.h"
  11. #include "media/base/eme_constants.h"
  12. #include "media/base/media_export.h"
  13. #include "media/media_buildflags.h"
  14. #include "third_party/abseil-cpp/absl/types/optional.h"
  15. namespace media {
  16. // Provides an interface for querying registered key systems.
  17. //
  18. // Many of the original static methods are still available, they should be
  19. // migrated into this interface over time (or removed).
  20. //
  21. // TODO(sandersd): Provide GetKeySystem() so that it is not necessary to pass
  22. // |key_system| to every method. http://crbug.com/457438
  23. class MEDIA_EXPORT KeySystems {
  24. public:
  25. // Returns the KeySystems singleton which may or may not be updated yet.
  26. static KeySystems* GetInstance();
  27. // Updates the list of available key systems if it's not initialized or may be
  28. // out of date. Calls the `done_cb` when done.
  29. virtual void UpdateIfNeeded(base::OnceClosure done_cb) = 0;
  30. // Gets the base key system name, e.g. "org.chromium.foo".
  31. virtual std::string GetBaseKeySystemName(
  32. const std::string& key_system) const = 0;
  33. // Returns whether |key_system| is a supported key system.
  34. virtual bool IsSupportedKeySystem(const std::string& key_system) const = 0;
  35. // Whether the base key system name should be used for CDM creation.
  36. virtual bool ShouldUseBaseKeySystemName(
  37. const std::string& key_system) const = 0;
  38. // Returns whether AesDecryptor can be used for the given |key_system|.
  39. virtual bool CanUseAesDecryptor(const std::string& key_system) const = 0;
  40. // Returns whether |init_data_type| is supported by |key_system|.
  41. virtual bool IsSupportedInitDataType(
  42. const std::string& key_system,
  43. EmeInitDataType init_data_type) const = 0;
  44. // Returns the configuration rule for supporting |encryption_scheme|.
  45. virtual EmeConfig::Rule GetEncryptionSchemeConfigRule(
  46. const std::string& key_system,
  47. EncryptionScheme encryption_scheme) const = 0;
  48. // Returns the configuration rule for supporting a container and a list of
  49. // codecs.
  50. virtual EmeConfig::Rule GetContentTypeConfigRule(
  51. const std::string& key_system,
  52. EmeMediaType media_type,
  53. const std::string& container_mime_type,
  54. const std::vector<std::string>& codecs) const = 0;
  55. // Returns the configuration rule for supporting a robustness requirement.
  56. // If `hw_secure_requirement` is true, then the key system already has a HW
  57. // secure requirement, if false then it already has a requirement to disallow
  58. // HW secure; if null then there is no HW secure requirement to apply. This
  59. // does not imply that `requested_robustness` should be ignored, both rules
  60. // must be applied.
  61. // TODO(crbug.com/1204284): Refactor this and remove the
  62. // `hw_secure_requirement` argument.
  63. virtual EmeConfig::Rule GetRobustnessConfigRule(
  64. const std::string& key_system,
  65. EmeMediaType media_type,
  66. const std::string& requested_robustness,
  67. const bool* hw_secure_requirement) const = 0;
  68. // Returns the support |key_system| provides for persistent-license sessions.
  69. virtual EmeConfig::Rule GetPersistentLicenseSessionSupport(
  70. const std::string& key_system) const = 0;
  71. // Returns the support |key_system| provides for persistent state.
  72. virtual EmeFeatureSupport GetPersistentStateSupport(
  73. const std::string& key_system) const = 0;
  74. // Returns the support |key_system| provides for distinctive identifiers.
  75. virtual EmeFeatureSupport GetDistinctiveIdentifierSupport(
  76. const std::string& key_system) const = 0;
  77. protected:
  78. virtual ~KeySystems() {}
  79. };
  80. // TODO(ddorwin): WebContentDecryptionModuleSessionImpl::initializeNewSession()
  81. // is violating this rule! https://crbug.com/249976.
  82. // Use for prefixed EME only!
  83. MEDIA_EXPORT bool IsSupportedKeySystemWithInitDataType(
  84. const std::string& key_system,
  85. EmeInitDataType init_data_type);
  86. // Returns a name for `key_system` for UMA logging. When `use_hw_secure_codecs`
  87. // is specified (non-nullopt), names with robustness will be returned for
  88. // supported key systems.
  89. MEDIA_EXPORT std::string GetKeySystemNameForUMA(
  90. const std::string& key_system,
  91. absl::optional<bool> use_hw_secure_codecs = absl::nullopt);
  92. // Returns an int mapping to `key_system` suitable for UKM reporting. CdmConfig
  93. // is not needed here because we can report CdmConfig fields in UKM directly.
  94. MEDIA_EXPORT int GetKeySystemIntForUKM(const std::string& key_system);
  95. // Returns whether AesDecryptor can be used for the given `key_system`.
  96. MEDIA_EXPORT bool CanUseAesDecryptor(const std::string& key_system);
  97. #if defined(UNIT_TEST)
  98. // Helper functions to add container/codec types for testing purposes.
  99. // Call AddCodecMaskForTesting() first to ensure the mask values passed to
  100. // AddMimeTypeCodecMaskForTesting() already exist.
  101. MEDIA_EXPORT void AddCodecMaskForTesting(EmeMediaType media_type,
  102. const std::string& codec,
  103. uint32_t mask);
  104. MEDIA_EXPORT void AddMimeTypeCodecMaskForTesting(const std::string& mime_type,
  105. uint32_t mask);
  106. #endif // defined(UNIT_TEST)
  107. } // namespace media
  108. #endif // MEDIA_BASE_KEY_SYSTEMS_H_