// Copyright 2013 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef MEDIA_BASE_CONTENT_DECRYPTION_MODULE_H_ #define MEDIA_BASE_CONTENT_DECRYPTION_MODULE_H_ #include <stdint.h> #include <memory> #include <optional> #include <string> #include <vector> #include "base/functional/callback_forward.h" #include "base/memory/ref_counted.h" #include "media/base/cdm_key_information.h" #include "media/base/eme_constants.h" #include "media/base/media_export.h" #include "url/gurl.h" namespace base { class Time; } namespace media { class CdmContext; struct ContentDecryptionModuleTraits; template <typename... T> class CdmPromiseTemplate; NewSessionCdmPromise; SimpleCdmPromise; KeyStatusCdmPromise; CdmKeysInfo; // Type of license required when creating/loading a session. // Must be consistent with the values specified in the spec: // https://w3c.github.io/encrypted-media/#idl-def-MediaKeySessionType enum class CdmSessionType { … }; // Type of message being sent to the application. // Must be consistent with the values specified in the spec: // https://w3c.github.io/encrypted-media/#idl-def-MediaKeyMessageType enum class CdmMessageType { … }; // This enum is reported to UKM. Existing values should NEVER be changed. enum class HdcpVersion { … }; // Reasons for CDM session closed. enum class CdmSessionClosedReason { … }; // An interface that represents the Content Decryption Module (CDM) in the // Encrypted Media Extensions (EME) spec in Chromium. // See http://w3c.github.io/encrypted-media/#cdm // // * Ownership // // This class is ref-counted. However, a ref-count should only be held by: // - The owner of the CDM. This is usually some class in the EME stack, e.g. // CdmSessionAdapter in the render process, or MojoCdmService in a non-render // process. // - The media player that uses the CDM, to prevent the CDM from being // destructed while still being used by the media player. // // When binding class methods into callbacks, prefer WeakPtr to using |this| // directly to avoid having a ref-count held by the callback. // // * Thread Safety // // Most CDM operations happen on one thread. However, it is not uncommon that // the media player lives on a different thread and may call into the CDM from // that thread. For example, if the CDM supports a Decryptor interface, the // Decryptor methods could be called on a different thread. The CDM // implementation should make sure it's thread safe for these situations. class MEDIA_EXPORT ContentDecryptionModule : public base::RefCountedThreadSafe<ContentDecryptionModule, ContentDecryptionModuleTraits> { … }; struct MEDIA_EXPORT ContentDecryptionModuleTraits { … }; // Try to convert `hdcp_version_string` to `HdcpVersion`. Returns std::nullopt // on failure. MEDIA_EXPORT std::optional<media::HdcpVersion> MaybeHdcpVersionFromString( const std::string& hdcp_version_string); // CDM session event callbacks. // Called when the CDM needs to queue a message event to the session object. // See http://w3c.github.io/encrypted-media/#dom-evt-message SessionMessageCB; // Called when the session specified by `session_id` is closed. Note that the // CDM may close a session at any point, such as in response to a CloseSession() // call, when the session is no longer needed, or when system resources are // lost, as specified by `reason`. // See http://w3c.github.io/encrypted-media/#session-closed SessionClosedCB; // Called when there has been a change in the keys in the session or their // status. See http://w3c.github.io/encrypted-media/#dom-evt-keystatuseschange SessionKeysChangeCB; // Called when the CDM changes the expiration time of a session. // See http://w3c.github.io/encrypted-media/#update-expiration // A null base::Time() will be translated to NaN in Javascript, which means "no // such time exists or if the license explicitly never expires, as determined // by the CDM", according to the EME spec. SessionExpirationUpdateCB; } // namespace media #endif // MEDIA_BASE_CONTENT_DECRYPTION_MODULE_H_