Xiaohan Wang | 5f25cb6 | 2017-12-04 14:33:11 -0800 | [diff] [blame] | 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 | |
| 5 | #ifndef CDM_CONTENT_DECRYPTION_MODULE_PROXY_H_ |
| 6 | #define CDM_CONTENT_DECRYPTION_MODULE_PROXY_H_ |
| 7 | |
| 8 | #include "content_decryption_module_export.h" |
| 9 | |
| 10 | #if defined(_MSC_VER) |
| 11 | typedef unsigned char uint8_t; |
| 12 | typedef unsigned int uint32_t; |
| 13 | typedef unsigned __int64 uint64_t; |
| 14 | #else |
| 15 | #include <stdint.h> |
| 16 | #endif |
| 17 | |
| 18 | namespace cdm { |
| 19 | |
| 20 | class CDM_CLASS_API CdmProxyClient; |
| 21 | |
| 22 | // A proxy class for the CDM. |
| 23 | // In general, the interpretation of the CdmProxy and CdmProxyClient method |
| 24 | // parameters are protocol dependent. For enum parameters, values outside the |
| 25 | // enum range may not work. |
| 26 | class CDM_CLASS_API CdmProxy { |
| 27 | public: |
Xiaohan Wang | 1a21842 | 2018-02-09 14:29:11 -0800 | [diff] [blame] | 28 | enum Function : uint32_t { |
Xiaohan Wang | 5f25cb6 | 2017-12-04 14:33:11 -0800 | [diff] [blame] | 29 | // For Intel Negotiate Crypto SessionKey Exchange (CSME) path to call |
| 30 | // ID3D11VideoContext::NegotiateCryptoSessionKeyExchange. |
Xiaohan Wang | 1a21842 | 2018-02-09 14:29:11 -0800 | [diff] [blame] | 31 | kIntelNegotiateCryptoSessionKeyExchange = 1, |
Xiaohan Wang | 5f25cb6 | 2017-12-04 14:33:11 -0800 | [diff] [blame] | 32 | // There will be more values in the future e.g. for D3D11 RSA method. |
| 33 | }; |
| 34 | |
Xiaohan Wang | 3894802 | 2018-09-13 10:44:17 -0700 | [diff] [blame] | 35 | enum KeyType : uint32_t { |
| 36 | kDecryptOnly = 0, |
| 37 | kDecryptAndDecode = 1, |
| 38 | }; |
| 39 | |
Xiaohan Wang | a4cb09b | 2017-12-21 14:51:26 -0800 | [diff] [blame] | 40 | // Initializes the proxy. The results will be returned in |
Xiaohan Wang | 5f25cb6 | 2017-12-04 14:33:11 -0800 | [diff] [blame] | 41 | // CdmProxyClient::OnInitialized(). |
Xiaohan Wang | a4cb09b | 2017-12-21 14:51:26 -0800 | [diff] [blame] | 42 | virtual void Initialize() = 0; |
Xiaohan Wang | 5f25cb6 | 2017-12-04 14:33:11 -0800 | [diff] [blame] | 43 | |
| 44 | // Processes and updates the state of the proxy. |
| 45 | // |output_data_size| is required by some protocol to set up the output data. |
| 46 | // The operation may fail if the |output_data_size| is wrong. The results will |
| 47 | // be returned in CdmProxyClient::OnProcessed(). |
| 48 | virtual void Process(Function function, |
| 49 | uint32_t crypto_session_id, |
| 50 | const uint8_t* input_data, |
| 51 | uint32_t input_data_size, |
| 52 | uint32_t output_data_size) = 0; |
| 53 | |
| 54 | // Creates a crypto session for handling media. |
| 55 | // If extra data has to be passed to further setup the media crypto session, |
| 56 | // pass the data as |input_data|. The results will be returned in |
| 57 | // CdmProxyClient::OnMediaCryptoSessionCreated(). |
| 58 | virtual void CreateMediaCryptoSession(const uint8_t* input_data, |
| 59 | uint32_t input_data_size) = 0; |
| 60 | |
| 61 | // Sets a key for the session identified by |crypto_session_id|. |
| 62 | virtual void SetKey(uint32_t crypto_session_id, |
| 63 | const uint8_t* key_id, |
| 64 | uint32_t key_id_size, |
Xiaohan Wang | 3894802 | 2018-09-13 10:44:17 -0700 | [diff] [blame] | 65 | KeyType key_type, |
Xiaohan Wang | 5f25cb6 | 2017-12-04 14:33:11 -0800 | [diff] [blame] | 66 | const uint8_t* key_blob, |
| 67 | uint32_t key_blob_size) = 0; |
| 68 | |
| 69 | // Removes a key for the session identified by |crypto_session_id|. |
| 70 | virtual void RemoveKey(uint32_t crypto_session_id, |
| 71 | const uint8_t* key_id, |
| 72 | uint32_t key_id_size) = 0; |
| 73 | |
Xiaohan Wang | 5f25cb6 | 2017-12-04 14:33:11 -0800 | [diff] [blame] | 74 | protected: |
| 75 | CdmProxy() {} |
| 76 | virtual ~CdmProxy() {} |
| 77 | }; |
| 78 | |
| 79 | // Responses to CdmProxy calls. All responses will be called asynchronously. |
| 80 | class CDM_CLASS_API CdmProxyClient { |
| 81 | public: |
Xiaohan Wang | 1a21842 | 2018-02-09 14:29:11 -0800 | [diff] [blame] | 82 | enum Status : uint32_t { |
Xiaohan Wang | 5f25cb6 | 2017-12-04 14:33:11 -0800 | [diff] [blame] | 83 | kOk, |
| 84 | kFail, |
| 85 | }; |
| 86 | |
Xiaohan Wang | 1a21842 | 2018-02-09 14:29:11 -0800 | [diff] [blame] | 87 | enum Protocol : uint32_t { |
| 88 | kNone = 0, // No protocol supported. Can be used in failure cases. |
Xiaohan Wang | bd20cfc | 2018-06-21 00:42:18 -0700 | [diff] [blame] | 89 | kIntel, // Method using Intel CSME. |
Xiaohan Wang | 5f25cb6 | 2017-12-04 14:33:11 -0800 | [diff] [blame] | 90 | // There will be more values in the future e.g. kD3D11RsaHardware, |
| 91 | // kD3D11RsaSoftware to use the D3D11 RSA method. |
| 92 | }; |
| 93 | |
| 94 | // Callback for Initialize(). If the proxy created a crypto session, then the |
| 95 | // ID for the crypto session is |crypto_session_id|. |
| 96 | virtual void OnInitialized(Status status, |
| 97 | Protocol protocol, |
| 98 | uint32_t crypto_session_id) = 0; |
| 99 | |
| 100 | // Callback for Process(). |output_data| is the output of processing. |
| 101 | virtual void OnProcessed(Status status, |
| 102 | const uint8_t* output_data, |
| 103 | uint32_t output_data_size) = 0; |
| 104 | |
| 105 | // Callback for CreateMediaCryptoSession(). On success: |
| 106 | // - |crypto_session_id| is the ID for the created crypto session. |
| 107 | // - |output_data| is extra value, if any. |
| 108 | // Otherwise, |crypto_session_id| and |output_data| should be ignored. |
| 109 | virtual void OnMediaCryptoSessionCreated(Status status, |
| 110 | uint32_t crypto_session_id, |
| 111 | uint64_t output_data) = 0; |
| 112 | |
Xiaohan Wang | bf6d8e0 | 2018-09-21 17:07:59 -0700 | [diff] [blame] | 113 | // Callback for SetKey(). |
| 114 | virtual void OnKeySet(Status status) = 0; |
| 115 | |
| 116 | // Callback for RemoveKey(). |
| 117 | virtual void OnKeyRemoved(Status status) = 0; |
| 118 | |
Xiaohan Wang | 5f25cb6 | 2017-12-04 14:33:11 -0800 | [diff] [blame] | 119 | // Called when there is a hardware reset and all the hardware context is lost. |
| 120 | virtual void NotifyHardwareReset() = 0; |
| 121 | |
| 122 | protected: |
| 123 | CdmProxyClient() {} |
| 124 | virtual ~CdmProxyClient() {} |
| 125 | }; |
| 126 | |
| 127 | } // namespace cdm |
| 128 | |
| 129 | #endif // CDM_CONTENT_DECRYPTION_MODULE_PROXY_H_ |